akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc1 = new Scanner(System.in);
		int [][] cells = new int [10][10];
		while(sc1.hasNext()){
			String temp = sc1.next();
			Scanner sc2 = new Scanner(temp);
			sc2.useDelimiter(",");
			int x = sc2.nextInt();
			int y = sc2.nextInt();
			int ink = sc2.nextInt();
			switch(ink){
			case 3:
				if((x-2) >= 0) cells[y][x-2]++;
				if((x+2) <= 9) cells[y][x+2]++;
				if((y-2) >= 0) cells[y-2][x]++;
				if((y+2) <= 9) cells[y+2][x]++;
			case 2:
				if((y-1) >= 0){
					if((x-1) >= 0) cells[y-1][x-1]++;
					if((x+1) <= 9) cells[y-1][x+1]++;
				}
				if((y+1) <= 9){
					if((x-1) >= 0) cells[y+1][x-1]++;
					if((x+1) <= 9) cells[y+1][x+1]++;
				}
			case 1:
				if((x-1) >= 0) cells[y][x-1]++;
				if((x+1) <= 9) cells[y][x+1]++;
				if((y-1) >= 0) cells[y-1][x]++;
				if((y+1) <= 9) cells[y+1][x]++;
				cells[y][x]++;
				break;
			}
		}

		int count = 0;
		int maxInk = 0;

		//oÍ
		for(int i=0; i < 10; i++){
			for(int j=0; j < 10; j++){
				if(cells[i][j] == 0){
					count++;
				}
				else if(maxInk < cells[i][j]){
					maxInk = cells[i][j];
				}
			}
		}

		System.out.println(count);
		System.out.println(maxInk);

	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

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

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

char sep[2] = {' ', '\n'};

int main() {
  int i, j, k, n, m;
  char s;
  bool card[4][13] = {};
  char suite[5] = "SHCD";

  cin >> n;
  rep(i, n) {
    cin >> s >> m;
    m--;
    if (s == 'S') j = 0;
    else if (s == 'H') j = 1;
    else if (s == 'C') j = 2;
    else j = 3;
    card[j][m] = true;
  }
  rep(i, 4) rep(j, 13) if (!card[i][j]) cout << suite[i] << " " << j + 1 << "\n";
  cout << flush;

  return 0;
}
  

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
struct edge{int from, to;};

int main(){
    int n;
    cin>>n;
    int a[n];
    int upper=0;
    int lower=1000;
    rep(i,n){
        cin>>a[i];
        upper=max(upper,a[i]);
        lower=min(lower, a[i]);
    }
    cout << upper-lower<<endl;
    return 0;
}

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

int main(){
	int N,W;
	cin >> N >> W;
	int v[N],w[N];
	for(int i=0; i<N; i++){
		cin >> v[i];
		cin >> w[i];
	}
//DPテーブル
	int DP[N+1][W+1];

	for(int j=0; j<=W; j++)
		DP[0][j]=0;

	for(int i=1; i<=N; i++){
		for(int j=0; j<=W; j++){
			if(j<w[i-1])
				DP[i][j]=DP[i-1][j];
			else{
				if(DP[i-1][j] > DP[i-1][j-w[i-1]]+v[i-1])
					DP[i][j]=DP[i-1][j];
				else
					DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];

			}
		}
	}

	cout << DP[N][W] << endl;

	return 0;
}

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

using namespace std;

int main() {
  int a, b;
  char op;
  while (true) {
    scanf("%d %c %d", &a, &op, &b);
    if (op == '?') {
      return 0;
    }
    if (op == '+') {
      printf("%d\n", a + b);
    }
    if (op == '-') {
      printf("%d\n", a - b);
    }
    if (op == '*') {
      printf("%d\n", a * b);
    }
    if (op == '/') {
      printf("%d\n", a / b);
    }
  }
}



Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

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

    for(int i=0; i<=25; i++){
        for(int j=0; j<=14; j++){
            if(n == (4*i + 7*j))c++;
        }
    }


    if (c > 0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

vector<int> f(int c, string s)
{
    int n = s.size();
    vector<int> dp(n, 0);
    int current = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'x')
        {
            continue;
        }
        current++;
        dp[i] = current;
        i += c;
    }
    for (int i = 1; i < n; i++)
    {
        dp[i] = max(dp[i], dp[i - 1]);
    }
    return dp;
}

int main()
{
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;

    S = 'x' + S + 'x';

    vector<int> l = f(C, S);
    reverse(S.begin(), S.end());
    vector<int> r = f(C, S);
    reverse(r.begin(), r.end());
    reverse(S.begin(), S.end());

    for (int i = 1; i <= N; i++)
    {
        if (S[i] == 'x')
        {
            continue;
        }
        if (l[i - 1] + r[i + 1] < K)
        {
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,num,val,counter_1=0,counter=0;
    vector<long long int>vec;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        cin>>n;
        vec.push_back(n);
    }
    val=vec[0];
    for(int u=1;u<vec.size();u++)
    {
        if(val>=vec[u])
        {
            counter_1+=1;
            val=vec[u];
        }
        else
        {
            counter=max(counter,counter_1);
            counter_1=0;
            val=vec[u];
        }
    }
    cout<<max(counter,counter_1)<<endl;
    return 0;
}


Measured memory_bytes: 1400
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var lenS = S.Length;
            long ret = 1;
            for (int i = 1; i <= lenS - 1; i++)
            {
                if (S[i - 1] != S[i])
                {
                    ret += 1;
                }
            }
            Console.Write(ret);
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

Measured memory_bytes: 13136
N=int(input())
A=input()
ans=0
lindex=0
rindex=N-1
flag=0#0:左進行,1:右進行,2:両どまり
while(1):
    if lindex>=rindex:
        break
    if flag==0:
        if A[lindex]=="W":
            flag=1
        else:
            lindex+=1

    elif flag==1:
        if A[rindex]=="R":
            flag=2
        else:
            rindex-=1
    
    else:
        ans+=1
        flag=0
        lindex+=1
        rindex-=1
#if flag==1 :
#    ans+=1
print(ans)

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

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

    double l = L / 3.0;
    printf("%f\n", l*l*l);
    
    return 0;
}

Measured memory_bytes: 256
using System;

class project{
static void Main(){
  int n = Convert.ToInt32(Console.ReadLine());
  int wm = n.ToString().Length;

  int result = 0;
  for(int i = 0; i < wm;i++){
    result += ((i+1) %2 != 0) ? 9*(Convert.ToInt32(Math.Pow(10,i))) : 0;
  }

  if(wm %2 != 0)
    result += (n+1) - (Convert.ToInt32(Math.Pow(10,wm)));
  
  Console.WriteLine(result);
}
}


Measured memory_bytes: 13268
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		List<Integer> red = new ArrayList<Integer>();
		List<Integer> green = new ArrayList<Integer>();
		List<Integer> neet = new ArrayList<Integer>();
		for(int i =0;i < a;i++) {
			red.add(sc.nextInt());
		}
		for(int i =0;i < b;i++) {
			green.add(sc.nextInt());
		}
		for(int i =0;i < c;i++) {
			neet.add(sc.nextInt());
		}
		Collections.sort(red,Comparator.reverseOrder());
		Collections.sort(green,Comparator.reverseOrder());
		Collections.sort(neet,Comparator.reverseOrder());
		List<Integer> answerArray = new ArrayList<Integer>();
		for(int i =0;i < x;i++) {
			answerArray.add(red.get(i));
		}
		for(int i =0;i < y;i++) {
			answerArray.add(green.get(i));
		}
		for(int i =0;i <c;i++) {
			answerArray.add(neet.get(i));
		}
		Collections.sort(answerArray,Comparator.reverseOrder());
		long answer = 0;
		for(int i = 0; i < x +y;i++) {
			answer += answerArray.get(i);
		}
		System.out.println(answer);

	}
}

Measured memory_bytes: 97408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll a,b,c,d,sum=0,ca,cb,da,db,ta,tb,c1,d1;
  cin>>a>>b>>c1>>d1;
  c=min(c1,d1);
  d=max(c1,d1);
  a--;
  
  ca=a/c; cb=b/c;
  da=a/d; db=b/d;

  ll gc=__gcd(c,d);
  ll lc=(c/gc)*d;
  ta=a/lc; tb=b/lc;
  sum=(b-a)-((cb-ca)+(db-da)-(tb-ta));
  cout<<sum<<endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, K;
    cin >> N >> K;

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vec.push_back(t);
    }

    ll sum = 0;

    //ロボットAとBで交互にボールを取っていってその最小をだす
    for(ll i = 0; i < N; i++){
        sum += min(vec[i] * 2, (K-vec[i]) * 2);
    }


    cout << sum << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  map<string, int> S;
  for (int i = 0; i < N; i++) {
  	string key;
    cin >> key;
    S[key] += 1;
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 19184
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>

#define size 210000

int c(const void* a, const void* b){
    return *(int*)a - *(int*)b;
}
int main(){
    int n,temp,ml,mr;
    int x[size], y[size];
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d", &temp);
        y[i] = x[i] = temp;
        // printf("%d ", x[i]);
    }
    qsort(y, n, sizeof(int), c);
    for(int i = 0; i < n; i++)
        // printf("%d", y[i]);
    // printf("\n");
    ml = y[n/2 -1];
    mr = y[n/2 ];
    // printf("%d %d\n",ml, mr);
    for(int i = 0; i < n; i++){
        if(x[i] <= ml)
            printf("%d\n", mr);
        else
            printf("%d\n", ml);
    }
    return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
	ll n,i;cin>>n>>i;
  cout<<n-i+1<<endl;
  return 0;
}

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

template <typename T>
using matrix = vector<vector<T>>;

struct PrefixSums
{
    matrix<int> data;

    PrefixSums(const matrix<bool>& A)
    {
        const int R = int(A.size()), C = int(A[0].size());
        data = matrix<int>(R+1, vector<int>(C+1));
        for (int r = 0; r < R; r++)
            for (int c = 0; c < C; c++)
                data[r+1][c+1] = A[r][c];
        for (int r = 0; r <= R; r++)
            for (int c = 1; c <= C; c++)
                data[r][c] += data[r][c-1];
        for (int c = 0; c <= C; c++)
            for (int r = 1; r <= R; r++)
                data[r][c] += data[r-1][c];
    }

    int query(const int r1, const int r2, const int c1, const int c2)
    {
        return data[r2][c2] - data[r1][c2] - data[r2][c1] + data[r1][c1];
    }
};

int main()
{
    ios::sync_with_stdio(false);

    int R, C, Q; cin >> R >> C >> Q;

    vector<string> grid(R);
    for (string& row : grid)
        cin >> row;

    matrix<bool> vertices(R, vector<bool>(C));
    for (int r = 0; r < R; r++)
        for (int c = 0; c < C; c++)
            vertices[r][c] = grid[r][c] == '1';
    PrefixSums ps_vertices(vertices);

    matrix<bool> horizontal(R, vector<bool>(C));
    for (int r = 0; r < R-1; r++)
        for (int c = 0; c < C; c++)
            horizontal[r][c] = vertices[r][c] && vertices[r+1][c];
    PrefixSums ps_horizontal(horizontal);

    matrix<bool> vertical(R, vector<bool>(C));
    for (int r = 0; r < R; r++)
        for (int c = 0; c < C-1; c++)
            vertical[r][c] = vertices[r][c] && vertices[r][c+1];
    PrefixSums ps_vertical(vertical);

    while (Q--)
    {
        int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
        r1--; c1--; r2--; c2--;
        r2++; c2++;

        const auto v = ps_vertices.query(r1, r2, c1, c2);
        const auto e = ps_horizontal.query(r1, r2-1, c1, c2) +
                       ps_vertical.query(r1, r2, c1, c2-1);
        cout << v-e << endl;
    }
}


Measured memory_bytes: 55424
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

/*
1≤k≤n≤10^7
p は素数 (上の実装ではさらに p>n を仮定している)
*/

const int MAX = 510000;//階乗の配列数
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
  ll n;
  cin >> n;
  vector<int> c(n);
  rep(i, n){
    cin >> c[i];
  }
  ssort(c);
   ll ans=0;
  rep(i, n){
    ll num=(c[i]*modpow(4, (ll)i, mod))%mod;
    num*=modpow(2, n-i,mod);
    num%=mod;
    /*
    rep(j, n-i){
      num+=COM(n-1-i, j)*(j+1);
      num%=mod;
    }
    */
    num*=(modpow(2, n-1-i, mod)+((n-1-i)*modpow(2, n-2-i, mod)))%mod;
    num%=mod;
    ans+=num;
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


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

#define MAX 50

int N, M;
int path[MAX];

int main()
{
	cin >> N >> M;
	for( int i = 0; i < M; i++ ) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		path[a]++;
		path[b]++;
	}

	for( int i = 0; i < N; i++ ) {
		cout << path[i] << endl;
	}

	return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, m;
    cin >> n >> m;
    ll x[n], y[n], z[n];
    rep(i, n) { cin >> x[i] >> y[i] >> z[i]; }

    ll ans = 0;
    rep(i, 8) {
        bool sign[3];
        rep(j, 3) { sign[j] = i & (1 << j); }
        ll temp[n] = {};
        rep(l0, n) {
            if (sign[0]) {
                temp[l0] += x[l0];
            } else {
                temp[l0] -= x[l0];
            }
            if (sign[1]) {
                temp[l0] += y[l0];
            } else {
                temp[l0] -= y[l0];
            }
            if (sign[2]) {
                temp[l0] += z[l0];
            } else {
                temp[l0] -= z[l0];
            }
        }
        sort(temp, temp + n, greater<ll>());
        ll ans_temp = 0;
        rep(l0, m) { ans_temp += temp[l0]; }
        ans = max(ans, ans_temp);
    }
    cout << ans << endl;

    return 0;
}



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

using namespace std;
const int INF = numeric_limits<int>::max() / 2;

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

  int n,m;cin>>n>>m;
  int e[n+1][n+1],d[n+1][n+1],used[n+1][n+1]={0};
  for(int i=0;i<n+1;i++)for(int j=0;j<n+1;j++){
      if(i==j)d[i][j]=0;
      else d[i][j]=INF;
      e[i][j]=-1;
  }
  for(int i=0;i<m;i++){
      int a,b,c;cin>>a>>b>>c;
      e[a][b]=c;e[b][a]=c;
      d[a][b]=c;d[b][a]=c;
  }
  for(int k=1;k<=n;k++){
      for(int i=1;i<=n;i++){
          for(int j=1;j<=n;j++){
              d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
          }
      }
  }
  for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
          for(int s=1;s<=n;s++){
              if(e[i][j]>0){
                  if(d[s][j]==d[s][i]+e[i][j]){
                      used[i][j]=1;used[j][i]=1;
                  }
              }
          }
      }
  }
  int res=0;
  for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
      if(e[i][j]>0)if(!used[i][j]) res++;
      //cout<<i<<" "<<j<<" "<<used[i][j]<<endl;
  }
  cout<<res/2<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<map> 
using namespace std;

const int N=100005;

int n,x,y,m,ans;
int a[N],fa[N];

int find(int k){
	if (fa[k]!=k) fa[k]=find(fa[k]);
	return fa[k];
}

int main(){
	int i,j,k;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) fa[i]=i;
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		x=find(x); y=find(y);
		fa[x]=y;
	}
	for (i=1;i<=n;i++)
		if (find(a[i])==find(i)) ans++;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n / 2] - a[n / 2 - 1];
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> arr;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(a);
	}
	int fir = arr[0];
	int curr=0;
	int best = 0;
	for(int i = 1; i<arr.size();i++)
	{
		if(fir >=arr[i])
		{
			curr++;
			fir = arr[i];
		}
		else
		{
			best = max(best,curr);
			curr=0;
			fir = arr[i];
		}
	}
	best = max(best, curr);
	cout<<best<<endl;
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ll long long
#define f(i,l,r) for(int i=l;i<=r;i++)
#define debug(x) cout<<#x<<'='<<(x)<<endl
using namespace std;
template<class T> bool maxs(T& a,T& b)
{
	if(a<b)
	{
		T t;
		t=a;
		a=b;
		b=t;
		return true;
	}
	return false;
}
template<class T> bool maxi(T& a,T& b)
{
	if(a<b)
	{
		a=b;
		return true;
	}
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int h[n+1];
	f(i,1,n)
		cin>>h[i];
	ll dp[n+1];
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	dp[3]=min(dp[2]+abs(h[3]-h[2]),dp[1]+abs(h[3]-h[1]));
	f(i,4,n)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n];
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, ans = 0; cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    vector<ll> sum(n, 0);
    rep(i, n) {
        if(i == 0) {
            auto iter = lower_bound(ALL(a), b[i]);
            sum[i] += iter - a.begin();
        }
        else {
            auto iter = lower_bound(ALL(a), b[i]);
            sum[i] += (sum[i-1] + iter - a.begin());
        }
    }
    rep(i, n) {
        auto iter = lower_bound(ALL(b), c[i]);
        if(iter - b.begin() - 1 >= 0) {
            ans += sum[iter-b.begin()-1];
        }

    }
    cout << ans << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 6400
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int x,y;cin>>x>>y;
    if(abs(x-y)<=1)cout<<"Brown"<<endl;
    else cout<<"Alice"<<endl;
}


Measured memory_bytes: 256
import heapq
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
count=0
Q=[]
heapq.heapify(Q) 
heapq.heappush(Q, (-A[0],-A[0],0))
for i in range(1,N):
    B=heapq.heappop(Q)
    count+=-B[0]
    heapq.heappush(Q, (-A[i],-A[i],B[1]))
    heapq.heappush(Q, (-A[i],-A[i],B[2]))
print(count)

Measured memory_bytes: 132060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    string a, b;
    cin >> a >> b;
    string c = a + b;

    int x  = atoi(c.c_str());

    for(int i = 1; i < 317; ++i){
        if(i * i ==x){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]

sm = {"M":0, "A":0, "R":0, "C":0, "H":0}
for s in S:
	if s[0] in sm:
		sm[s[0]] += 1

psum = 0
psum += sm["M"] * sm["A"] * sm["R"]
psum += sm["M"] * sm["A"] * sm["C"]
psum += sm["M"] * sm["A"] * sm["H"]
psum += sm["M"] * sm["R"] * sm["C"]
psum += sm["M"] * sm["R"] * sm["H"]
psum += sm["M"] * sm["C"] * sm["H"]
psum += sm["A"] * sm["R"] * sm["C"]
psum += sm["A"] * sm["R"] * sm["H"]
psum += sm["A"] * sm["C"] * sm["H"]
psum += sm["R"] * sm["C"] * sm["H"]

#print(sm)
print(psum)


Measured memory_bytes: 9772
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			list.add(a);
		}

		int[] result = new int[n];
		int resultCount =0;
		for (int i = n-1; i >= 0; i--) {
			int a = list.get(i);

			int count = 0;
			// System.out.println("a " + a);

			for (int j = 1; j * (i+1) <= n; j++) {
				// System.out.println("(i+1)* j " + (i+1)* j );
				count += result[j * (i+1) - 1];
			}

			if(count % 2 == a){
				result[i] = 0;
			}else{
				result[i] = 1;
				resultCount++;
			}

		}
			// System.out.println(Arrays.toString(result));

		System.out.println(resultCount);
		for (int i = 0; i < n; i++) {
			if(result[i] == 1){
				System.out.print(i+1);
				System.out.print(" ");

			}
		}





	}

}


Measured memory_bytes: 60068
a = [int(e) for e in input().split()]

if(a[0]<=a[1]):
    tmp=a[1]
    a[1]=a[1]-1
else:
    tmp=a[0]
    a[0]=a[0]-1

if(a[0]<=a[1]):
    tmp1=a[1]
    a[1]=a[1]-1
else:
    tmp1=a[0]
    a[0]=a[0]-1

print(tmp+tmp1)


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

constexpr int MAX_SIZE = 50;
constexpr int MAX_D = 10;
constexpr int dx[4] = {1, -1, 0, 0};
constexpr int dy[4] = {0, 0, 1, -1};

typedef pair<int, int> point;

int h, w, d, n;
string field[MAX_SIZE];
int r[MAX_D];
bool visited[MAX_SIZE][MAX_SIZE];

set<point> get_area() {
	int x, y, s;
	cin >> x >> y >> s;

	int lower, upper;
	if(s == 0) {
		lower = -1;
		upper = r[0];
	}
	else if(s == d) {
		lower = r[d - 1];
		upper = INT_MAX;
	}
	else {
		lower = r[s - 1];
		upper = r[s];
	}

	set<point> res;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			const int len = max(abs(y - i), abs(x - j));
			if(len <= lower || len > upper) continue;
			if(field[i][j] == '#') continue;
			res.insert({j, i});
		}
	}
	return res;
}

template<class T>
set<T> intersect(const set<T> &a, const set<T> &b) {
	set<T> res;
	for(const auto &e : a) {
		if(b.count(e)) res.insert(e);
	}
	return res;
}

bool out(int x, int y) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

void bfs(int sx, int sy) {
	memset(visited, false, sizeof(visited));
	visited[sy][sx] = true;
	queue<point> que;
	que.push({sx, sy});

	while(!que.empty()) {
		const int x = que.front().first;
		const int y = que.front().second;
		que.pop();

		for(int d = 0; d < 4; ++d) {
			const int nx = x + dx[d];
			const int ny = y + dy[d];
			if(out(nx, ny)) continue;
			if(field[ny][nx] == '#') continue;

			if(!visited[ny][nx]) {
				que.push({nx, ny});
				visited[ny][nx] = true;
			}
		}
	}
}

int main() {
	cin >> h >> w >> d >> n;

	int sx, sy;
	for(int i = 0; i < h; ++i) {
		cin >> field[i];
		int pos;
		if((pos = field[i].find('D')) != string::npos) {
			sx = pos;
			sy = i;
		}
	}

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

	auto common_area = get_area();
	for(int i = 1; i < n; ++i) {
		common_area = intersect(common_area, get_area());
	}

	if(common_area.size() == 0) {
		cout << "Broken" << endl;
		return 0;
	}

	bfs(sx, sy);

	int cnt = 0;
	for(const auto g : common_area) {
		if(visited[g.second][g.first]) ++cnt;
	}
	if(cnt == 0) {
		cout << "No" << endl;
	}
	else if(cnt == common_area.size()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "Unknown" << endl;
	}

	return 0;
}

Measured memory_bytes: 1472
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int A,B,M;
    cin >> A >> B >> M;

    vector<int> a(A),b(B);
    int amin=inf,bmin=inf;
    for(auto &x:a){
        cin >> x;
        amin=min(amin,x);
    }
    for(auto &x:b){
        cin >> x;
        bmin=min(bmin,x);
    }

    int minval=amin+bmin;

    for(int i=0;i<M;i++){
        int x,y,c;
        cin >> x >> y >> c;

        minval=min(minval,(a[x-1]+b[y-1]-c));
    }

    cout << minval << endl;

    return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
ll lcm(int a,int b){
    return (ll)a*(ll)b/(ll)gcd(a,b);
}

int main(){
    int a,b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i ,n,a[20],sum=0,ma=-111;
	cin>>n;
	for(i=0;i<n;i++)
	{
	cin>>a[i];
	sum+=a[i];  
	if(a[i]>ma)
	{
		ma=a[i];
	}
    }
    if (sum-ma>ma)
    {
    	cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	
}

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

using namespace std;
int dp[500010];
int main(){
	int n,i;
	string s;
	cin >> n;
	cin >> s;
	dp[0] = 0,dp[1] = 0;
	s = "0"+s+"0";
	for(i=1;i<n+1;i++){
		dp[i+1] = max(dp[i+1],dp[i]);
		if(s[i-1]=='1' && s[i]=='0' && s[i+1]=='1'){
			int prev = i-1,next = i+1;
			while(s[prev]=='1'){
				dp[i+1] = max(dp[i+1],dp[prev-1]+i-prev);
				prev--;
			}
			while(s[next]=='1'){
				dp[next] = max(dp[next],dp[i-2]+next-i);
				next++;
			}
		}
	}
	cout << dp[n+1] << endl;
}

Measured memory_bytes: 2840
def main():
    import sys
    input = sys.stdin.readline

    N, K, S = map(int, input().split())

    if S < 10**9:
        ans = [10**9] * N
        for i in range(K):
            ans[i] = S
    else:
        ans = [1] * N
        for i in range(K):
            ans[i] = S
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46268
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c=0,d=0,e,f,g,h,m,n,ans=0;
  string s,t;
  int x[3];
  cin>>x[0]>>x[1]>>x[2];
  sort(x,x+3);
  if(x[0]==x[1] && x[1]!=x[2]) co("Yes");
  else if(x[0]!=x[1] && x[1]==x[2]) co("Yes");
  else co("No");
    
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b, c;
    cin>>a>>b>>c;
    if(a+b>=c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};
vector<double> hako;
int main(){
  int n;
  cin >> n;
  rep(i,0,n){
    double a;
    cin >> a;
    hako.push_back(a);
  }
  sort(hako.begin(),hako.end());
  rep(i,0,n-1){
    hako[i+1] = (hako[i]+hako[i+1])/2;
  }
  cout << hako[n-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i,j,k;


int main(){
    ll N,M;
    cin>>N>>M;
    V A(M);
    rep(i,M)cin>>A[i];
    ll sum=0;
    rep(i,M)sum+=A[i];
    if(sum>N)cout<<-1<<endl;
    else cout<<N-sum<<endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
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
void main() {
    int x = readln.chomp.to!int;

    int d = x / 100, r = x % 100;

    writeln(d >= (r + 4) / 5 ? 1 : 0);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

ll dp[3005][3005], comb[3005][3005];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	string s;
	cin >> n >> m >> s;

	vector<int> l, r;
	int rmax = 0;
	for (int i = 0; i < m; i++) {
		int tl, tr;
		cin >> tl >> tr;
		tl--;
		rmax = max(rmax, tr);
		l.push_back(tl);
		r.push_back(rmax);
	}

	vector<int> sum(n + 1, 0);
	for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + s[i] - '0';

	for (int i = 0; i <= n; i++) comb[i][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD;
		}
	}
	
	dp[0][sum[l[0]]] = 1;
	l.push_back(n);
	for (int i = 0; i < m; i++) {
		if (i > 0 && l[i] == l[i - 1] && r[i] < r[i - 1]) {
			for (int j = 0; j <= n; j++) {
				dp[i + 1][j] = dp[i][j];
			}
		}
		for (int j = 0; j <= sum[r[i]]; j++) {
			if (dp[i][j] == 0) continue;
			int rest = sum[r[i]] - j;
			int plus = max(sum[l[i + 1]] - sum[r[i]], 0);
			int L = min(r[i], l[i + 1]) - l[i];
			for (int k = max(L - (r[i] - l[i] - rest), 0); k <= min(L, rest); k++) {
				(dp[i + 1][j + k + plus] += dp[i][j] * comb[L][k] % MOD) %= MOD;
			}
		}
	}

	cout << dp[m][sum[n]] << endl;
	return 0;
}

Measured memory_bytes: 138240
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll dp[1001000][2];
int main(void){
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    s += '0';
    for(int i = 0; i <= s.size(); i++){
        for(int j = 0; j < 2; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    for(int i = 0; i < s.size(); i++){
        int now = s[i] - '0';
        for(int j = 0; j < 2; j++){
            if(j) now++;
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + now);
            dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + 10 - now);
        }
    }

    cout << dp[s.size()][0] << endl;
}

Measured memory_bytes: 17028
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(long testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n+1];
            long[] freq = new long[n+1];
            for (int i = 1; i <= n; i++) {
                arr[i] = in.nextInt();
                freq[arr[i]]++;
            }
            long sum = 0;
            for (int i = 1; i <= n; i++) {
                sum += nCr(freq[i]);
            }
            for (int i = 1; i <= n; i++) {
                long ans = sum + 1 - freq[arr[i]];
                out.println(ans);
            }
        }

        private long nCr(long n) {
            return n * (n-1) / 2;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 51128
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

bool comp(std::vector<ll> a, std::vector<ll> b)
{
    if(a[1]==b[1]&&a[2]==b[2])
        return a[0]<b[0];
    else if(a[1]==b[1])
        return a[2]>b[2];
    else
        return a[1]<b[1];
}

void add_self(ll &a, ll b)
{
    a = (a+b);
    if(a>=mod)
        a-=mod;
}
int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll dp[n+5][n+5]={};
    ll pre[n+5][n+5]={};
    dp[1][1] = 1;
    pre[1][1] = 1;
    for(ll i=2;i<=n;i++)
    {
        for(ll val = 1; val<=i;val++)
        {
            if(s[i-2]=='<')
            {
                dp[i][val] = (dp[i][val] + pre[i-1][val-1])%mod;
            }
            else
            {
                dp[i][val] = (dp[i][val] + pre[i-1][i-1] -  pre[i-1][val-1] + mod)%mod;
            }
        }
        for(ll val=1;val<=i;val++)
        {
            pre[i][val] = (pre[i][val-1] + dp[i][val])%mod;
        }
    }
    cout<<pre[n][n]<<endl;
}

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

int ctoi(const char c){
    switch(c){
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default : return -1;
    }
}

int main(){
    string S;
    cin >> S;
    vector<int> sa_753(0);
    int len = S.size();
    for (int i = 0; i < len - 2; i++){
        int n = ctoi(S.at(i)) * 100 + ctoi(S.at(i + 1)) * 10 + ctoi(S.at(i + 2));
        int sa = max(n - 753, 753 - n);
        sa_753.push_back(sa);
    }
    int min_sa = sa_753.at(0);
    for (int i = 1; i < len - 2; i++){
        min_sa = min(min_sa, sa_753.at(i));
    }
    cout << min_sa << endl;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
l = ["."]*w
while l in a:
  a.remove(l)
  
for j in range(w):
    s = 0
    for m in a:
        if m[j]=="#":
            s = 1
            break
    if s == 0:
        for m in a:
            m[j]=""
for i in a:
    print("".join(i))

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;


namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);

            if (a < b && a < c && b < c)
            {
                 Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 8988
#include<bits/stdc++.h>
using namespace std;
int main (){
  int n;
  cin>>n;
  vector<int>v(n);
  int s=0;
  for(int i=0;i<n;i++){
    cin>>v[i];
    s+=(v[i]-1);
    }
  cout<<s<<endl;
  return 0;
  }





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

int main(void){

  int a, b, re;
  char op;

  while(1){
    scanf("%d %c %d", &a, &op, &b);
    if(op == '?'){
      break;
    }
    if(op == '+'){
      re = a+b;
      printf("%d\n", re);
    }else if(op == '-'){
      re = a-b;
      printf("%d\n", re);
    }else if(op == '*'){
      re = a*b;
      printf("%d\n", re);
    }else if(op == '/'){
      re = a/b;
      printf("%d\n", re);
    }
  }

  return 0;

}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define MOD 1000000007
#define PI acos(-1)
int main()
{
	IOS
	int n,k;
	cin>>n>>k;
	int dp[k+1];
	int i;
	int a[n+1];
	int minm=INT_MAX;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		minm=min(minm,a[i]);
	}
	for(i=0;i<minm;i++)
	dp[i]=0;
	int j;
	for(i=minm;i<=k;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(i>=a[j])
			{
				if(dp[i-a[j]]==0){
				dp[i]=1;
				break;
			}
			}
		}
		if(j==n+1)
		dp[i]=0;
	}
	if(dp[k])
	cout<<"First";
	else
	cout<<"Second";
}

Measured memory_bytes: 640
<?PHP
  $n=trim(fgets(STDIN));
for($i=0;$i<$n;++$i){
	fscanf(STDIN,"%d %d %d",$x,$y,$z);
	$a[$i]=$x;
	$b[$i]=$y;
	$c[$i]=$z;
}
		$a_history=[];
		$b_history=[];
		$c_history=[];
foreach (range(0, $n-1) as $i) {
	if($i==0){
		$a_history[$i]=$a[$i];
		$b_history[$i]=$b[$i];
		$c_history[$i]=$c[$i];
	}
	$a_history[$i]=$a[$i]+($b_history[$i-1]>$c_history[$i-1] ? $b_history[$i-1] : $c_history[$i-1]);
	$b_history[$i]=$b[$i]+($a_history[$i-1]>$c_history[$i-1] ? $a_history[$i-1] : $c_history[$i-1]);
	$c_history[$i]=$c[$i]+($b_history[$i-1]>$a_history[$i-1] ? $b_history[$i-1] : $a_history[$i-1]);
}
echo max(end($a_history),end($b_history),end($c_history));
 
?>

Measured memory_bytes: 34412
#include<bits/stdc++.h>
using namespace std;
/// Macros ---------------------
#define ll long long
#define sz(a) (int)a.size()
#define int long long
#define pb push_back
#define vi vector<int>
#define f first
#define s second
#define ii pair<int,int>
#define lb lower_bound
#define up upper_bound
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define ld long double
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Constracts -----------------------------------------------
const int maxn=1e5;
const int INF=(1ll)<<(30ll);
const int inf=1000000000000000000;
const int eps=1e-9;
/// Quick Pow ------------------------------------------------
int qpow(int b,int e)
{
    if( !e ) return 1;
    if( e & 1 ) return qpow(b, e - 1) * b;
    int pwur = qpow(b, e >> 1);
    return pwur * pwur;
}

/// My Code ---------------------------------------------------

int a[maxn],mk[maxn];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int cnt=0;
    for(int i=1;i!=2;i=a[i]){
        cnt++;
        if(mk[i]){cout<<"-1\n";return 0;}
        mk[i]=true;
    }
    cout<<cnt<<'\n';

    return 0;
}


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

int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    int hi = max(H, W);
    int answer = N / hi;
    if(N % hi){
        answer++;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 1e6 + 9, M = 1e9 + 7;
int main() {
	int a,b;
	cin>>a>>b;
	if(a+b==15)cout<<"+";
	else if(a*b==15)cout<<"*";
	else cout<<"x";


	return 0;
}

Measured memory_bytes: 256