akhauriyash/Code-Regression huggingface dataset:
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll W,H,x,y;
    cin>>W>>H>>x>>y;
    double are=W*H;
    are/=2.0;
    //x,yがしゅうじょうなら1
    ll ans=0;
    //if(x>0&&x<W&&y>0&&y<H){
    //    ans=1;
    //}
    double w2=(double)W/2.0;
    double h2=(double)H/2.0;
    if (abs(w2-x)<=FLT_EPSILON&&abs(h2-y)<=FLT_EPSILON) {
        ans=1;
    }
    cout<<fixed<<std::setprecision(10)<<are<<" ";
    cout<<ans<<endl;
    return 0;
}

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


int main() {
    int N,M;cin >> N >> M;
    vector<vector<int>> AB(N,vector<int>(2));
    for (int i = 0;i < N;i++){
        int a,b;cin >> a >> b;
        AB.at(i).at(0) = a;
        AB.at(i).at(1) = b;
    }
    vector<vector<int>> CD(M,vector<int>(2));
    for (int i = 0;i < M;i++){
        int c,d;cin >> c >> d;
        CD.at(i).at(0) = c;
        CD.at(i).at(1) = d;
    }

    for (int i = 0;i < N;i++){
        int a,b;
        a = AB.at(i).at(0);
        b = AB.at(i).at(1);
        int MIN,ind;
        MIN = 1000000000;
        ind = 0;
        for (int j = 0;j < M;j++){
            int c,d;
            c = CD.at(j).at(0);
            d = CD.at(j).at(1);
            int dist;dist = abs(a-c)+abs(b-d);
            if (MIN <= dist){
                continue;
            }
            MIN = dist;
            ind = j+1;
        }
        cout << ind << endl;
    }

}       

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (N, M) = readInts()
  val waCnt = Array(N) { 0 }
  val isAc = Array(N) { false }
  repeat(M) {
    val (P, S) = readStrings()
    val p = P.toInt() - 1
    if (S == "AC") {
      isAc[p] = true
    } else {
      if (!isAc[p]) waCnt[p]++
    }
  }
  var ac = 0
  var pn = 0
  for (i in 0 until N) {
    if (isAc[i]) {
      ac++
      pn += waCnt[i]
    }
  }
  println("$ac $pn")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 56116
import java.util.Scanner;
public class Main 
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner (System.in);
        int w=sc.nextInt();
        int h=sc.nextInt();
        int x=sc.nextInt();
        int y=sc.nextInt();
        int r=sc.nextInt();
        
        if(r>x)
        {
         System.out.println("No");
        }
        else if(r>y){
        	System.out.println("No");
        }
        else if((x+r)>w){
        	System.out.println("No");
        }
        else if((y+r)>h){
        	System.out.println("No");
        }
        else{
        	System.out.println("Yes");
        }
        	
        	
        
        	
       sc.close();        
      
    }
}

Measured memory_bytes: 26196
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define line cout<<"----------------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll mx=200009;
int ara[mx]; 
int pre[mx],suf[mx]; 
int main()
{
    int n; 
    cin>>n; 
    for(int i=1;i<=n;i++) 
    {
        cin>>ara[i]; 
        pre[i]=__gcd(pre[i-1],ara[i]);
    }
    for(int i=n;i>=1;i--)
    {
        suf[i]=__gcd(suf[i+1],ara[i]);
    }
    int maxi=0; 
    for(int i=1;i<=n;i++)
    {
        maxi=max(maxi,__gcd(pre[i-1],suf[i+1]));
    }
    cout<<maxi<<endl; 
    
}


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

#define printcharcount for(char c='a'; c<='z'; ++c){ cout << c << ":" << charcount[c-'a'] << ", "; }

int h, w;
char A[101][101];
int charcount[26];   //count['文字' - 'a'] == aの個数
int main()
{
  cin >> h >> w;
  for(int i=0; i<h; ++i){
    for(int j=0; j<w; ++j){
      char c;
      cin >> c;
      A[i][j] = c;
      charcount[c -'a'] ++;
    }
  }
  
  
  // 場合分け even-even, even-odd, odd-odd
  if(h%2==0 && w%2==0){
    //even-even
    //全部4の倍数じゃないとだめ
    for(char c='a'; c<='z'; ++c){
      if(charcount[c-'a'] % 4 != 0){
        goto impossible;
      }
    }
    
  }else if(h%2==1 && w%2==1){
    //odd-odd
    int pivot = h+w-1;
    int nonpivot = h*w-pivot;
    //4個以上ある文字は、ノンピボットに詰めていく
    for(char c='a'; c<='z'; ++c){
      auto& cc = charcount[c-'a'];
      while(nonpivot >= 4 && cc>=4){
        cc -= 4;
        nonpivot -= 4;
      }
    }
    //ノンピボットが埋まっていなければ無理
    if(nonpivot > 0) goto impossible;
    //残りの文字でピボットを埋めていく
    //2個以上ある文字は、ピボットに詰めていく
    for(char c='a'; c<='z'; ++c){
      auto& cc = charcount[c-'a'];
      while(pivot >= 2 && cc>=2){
        cc -= 2;
        pivot -= 2;
      }
    }
    // pivotが1になっていれば可能、1より大きければ不可能
    if(pivot > 1) goto impossible;
    
  }else{
    //even-odd
    int pivot = h%2==0 ? h : w;
    int nonpivot = h*w-pivot;
    //4個以上ある文字は、ノンピボットに詰めていく
    for(char c='a'; c<='z'; ++c){
      auto& cc = charcount[c-'a'];
      while(nonpivot >= 4 && cc>=4){
        cc -= 4;
        nonpivot -= 4;
      }
    }
    //ノンピボットが埋まっていなければ無理
    if(nonpivot > 0) goto impossible;
    //残りの文字でピボットを埋めていく
    //2個以上ある文字は、ピボットに詰めていく
    for(char c='a'; c<='z'; ++c){
      auto& cc = charcount[c-'a'];
      while(pivot >= 2 && cc>=2){
        cc -= 2;
        pivot -= 2;
      }
    }
    // pivotが0で可能、0より大きければ不可能
    if(pivot > 0) goto impossible;
  }
  
  cout << "Yes" << endl;
  return 0;
  impossible:
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k,c=0; cin>>a>>b>>k;
  int i;
  for(i=min(a,b);i>=1;i--){
    if(b%i==0&&a%i==0){c++;}
    if(c==k){cout<<i<<endl;break;}
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iostream>
#include <numeric>
#include <random>
#include <set>
#include <unordered_set>
#include <vector>
#include <list>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;

#define LOCAL 1

#if LOCAL
#define pv(val) cerr << #val << " = " << (val) << endl
#define pvn(name, val) cerr << name << " = " << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#else
#define pv(val)
#define pvn(name, val)
#define pl
#endif

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
  if (vec.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
    os << vec.back() << '}';
  }
  return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
  if (arr.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
    os << arr.back() << '}';
  }
  return os;
}

template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U> const& p){
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

template<class T, class U>
pair<T, U> operator+(pair<T, U> const& lhs, pair<T, U> const& rhs){
  return {lhs.first + rhs.first, lhs.second + rhs.second};
}

template<class T, class U>
pair<T, U> operator-(pair<T, U> const& lhs, pair<T, U> const& rhs){
  return {lhs.first - rhs.first, lhs.second - rhs.second};
}

template<class T, class U>
U lowerBound(function<T(U)> f, T const& val, U l, U r){
  while(l < r){
    auto m = l + (r - l) / 2;
    auto fm = f(m);
    if(fm < val){
      l = m;
    }else{
      r = m;
    }

  }
}


int main(void) {
  int X;
  cin >> X;
  int ans = 1;
  for(int b = 2; b < X; b++){
    int p = 2;
    while(true){
      int bp = (int)(pow(b, p) + 0.5);
      if(bp > X) break;
      ans = max(ans, bp);
      ++p;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int ans = 700 + count(s.begin(), s.end(), 'o') * 100;
	cout << ans << endl;
	return 0;
}


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

int modpow(int a, int b, int mod){
    int x = 1;
    for (; b > 0; b >>= 1){
        if(b & 1) x = (ll)x * a % mod;
        a = (ll)a * a % mod;
        x %= mod;
    }
    return x;
}

int main(){
    int N;
    cin >> N;
    vector<int> cnt(60);
    vector<ll> A(N);
    ll ans = 0;
    rep(i, N) cin >> A[i];
    rep(i, N) rep(j,60) if(A[i]>>j & 1) cnt[j]++;
    int mod = 1e9+7;
    rep(i,60){
        if(cnt[i] == 0) continue;
        ll x = ((ll)modpow(2,i,mod) * (N-cnt[i])) % mod;
        x = x * cnt[i] % mod;
        ans += x;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
n=int(input())
d={i:0 for i in range(n+1)}
for i in range(2,n+1):
    for j in range(2,int(i**0.5)+1):
        while i%j==0:
            i//=j
            d[j]+=1
    if i!=1:
        d[i]+=1
a=1
mod=10**9+7
for i in d.values():
    a=a*(i+1)%mod
print(a)

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

int main() {
	int a , b ;
	int d , e ;
	cin >> a >> b;
	cin >> d >> e;
	
	if (a + b == d + e) {
		cout << "Balanced" << endl;
	}else if(a + b < d +e){
		cout << "Right" << endl;
	}else{
		cout << "Left" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int count = 0;
		int ans = 0;
		for(int i = 0;i < s.length(); ++i){
			if(s.charAt(i) == 'R')count++;
			else{
				ans = Math.max(ans, count);
				count = 0;
			}
		}
		ans = Math.max(ans,count);
		System.out.print(ans);
	}
}


Measured memory_bytes: 35524
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

map<double,int> t;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  t[a+0.5]+=1;
  t[b+0.5]-=1;
  t[c+0.5]+=1;
  t[d+0.5]-=1;
  for(int i=1;i<205;i++){
    t[i+0.5]+=t[i-0.5];
  }
  int ans=0;
  for(int i=0;i<205;i++)if(t[i+0.5]==2)ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
A = getList()
L = max(A)

dp = [1] * (L + 1)
dp[0] = 0
num_list = [0] * (L + 1)

for i in A:
    if num_list[i] == 0:
        for j in range(i * 2, L + 1, i):
            dp[j] = 0
    num_list[i] += 1

ans = 0
for i in range(L + 1):
    if num_list[i] == 1 and dp[i] == 1:
        ans += 1
print(ans)

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,M,Q;
vector<ll> a,b,c,d;
ll res;

void dfs(ll i,ll low,vector<ll>& crt){
  if(i==N){
    ll sum=0;
    rep(j,Q){
      if(crt[b[j]]-crt[a[j]]==c[j])sum+=d[j];
    }
    maxch(res,sum);
    return ;
  }
  repl(v,low,M+1){
    crt.push_back(v);
    dfs(i+1,v,crt);
    crt.pop_back();
  }
}

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

  cin>>N>>M>>Q;
  a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
  rep(i,Q){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;
    b[i]--;
  }

  vector<ll> crt;
  dfs(0,1,crt);
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 3620
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  }
}

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

using namespace std;

int main(){
	int n;
	double students[1000] = {0},sum,m,div;

	while(true){
		scanf("%d",&n);
		if(n == 0) break;
		div = sum = 0;
		for(int i = 0; i < n; i++){
			scanf("%lf",&students[i]);
			sum += students[i];
		}
		m = sum/n;
		for(int i = 0; i < n;i++){
			div += (students[i] - m)*(students[i] - m);
			students[i] = 0;
		}
		printf("%.8lf\n",sqrt(div/n));
	}
}



Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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;
}

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
ll func(ll n)
{
    return n * (n + 1) / 2;
}

int main()
{

    // ABC127-D

    int N,M; cin >> N >> M;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    vector<pair<int, int>> v(M);
    REP(i,M){
        int a,b; cin >> a >> b;
        v[i] = {a,b};
    }

    sort(A.begin(), A.end(), greater<int>());
    sort(v.begin(), v.end(), [](pair<int,int> a, pair<int,int> b){return a.second > b.second;});

    int pos;

    REP(i,M){
        if(A[N-1]>=v[i].second) goto end;
        if(i==0){
            REP(j,N){
                if(v[i].second >= A[j]){
                    pos = j;
                    A.insert(A.begin()+j, v[i].first, v[i].second);
                    goto flag;
                }
            }
        }else{
            FOR(j,pos+v[i-1].first-1,A.size()){
                try{
                    if(v[i].second >= A[j]){
                        pos = j;
                        A.insert(A.begin()+pos, v[i].first, v[i].second);
                        goto flag;
                    }
                }catch(out_of_range){
                    goto flag;
                }
            }
        }
        flag: int here;
        //for(auto &x: A) cout << x << " ";
        //cout << endl;
    }

    end: ll ans=0;
    REP(i,N){
        ans += A[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2680
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            long N = in.nextLong();
            long A = in.nextLong();
            long B = in.nextLong();
            long C = A + B;
            long D = N / C;
            long ans = D * A;
            N -= C * D;
            ans += Math.min(A, N);
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



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

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

  vector<tuple<int, int, int>> YPi(M);
  for (int i = 0; i < M; i++) {
    int P, Y;
    scanf("%d%d", &P, &Y);
    YPi.at(i) = make_tuple(Y, P, i);
  }

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

  vector<int> cnt(N + 1, 1);

  vector<pair<int, int>> ans(M);
  for (int i = 0; i < M; i++) {
    ans.at(get<2>(YPi.at(i))) = make_pair(get<1>(YPi.at(i)), cnt.at(get<1>(YPi.at(i)))++);
  }

  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", ans.at(i).first, ans.at(i).second);
  }
}

Measured memory_bytes: 3840
// https://atcoder.jp/contests/abc106/tasks/abc106_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b;

  cin >> a >> b;

  cout << (a - 1) * (b - 1) << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

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

  vector<uint64_t> A(N);
  N_TIMES(n, N) { cin >> A[n]; }

  vector<uint64_t> C(N, 0);
  N_TIMES(n, N) { ++C[A[n] - 1]; }

  vector<uint64_t> S1(N, 0), S2(N, 0);
  N_TIMES(n, N) {
    S1[n] = (C[n] * (C[n] - 1)) >> 1;
    S2[n] = ((C[n] - 1) * (C[n] - 2)) >> 1;
  }

  uint64_t T = 0;
  N_TIMES(n, N) { T += S1[n]; }

  N_TIMES(n, N) {
    cout << (T - S1[A[n] - 1] + S2[A[n] - 1]) << endl;
  }

  return 0;
}

Measured memory_bytes: 8960
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    int sum = 0;
    rep(i,k) sum += a[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3656
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    A_minus,A_zero,A_plus=[],[],[]
    x=bisect_left(A,0)
    y=bisect_right(A,0)
    A_minus=A[:x]
    A_minus=list(reversed(list(map(lambda x: -x,A_minus))))
    A_zero=A[x:y]
    A_plus=A[y:]
    if K<=len(A_minus)*len(A_plus):
        def nibutan1(ok,ng):
            while abs(ok-ng) > 1:
                mid = (ok + ng) // 2
                if solve1(mid):
                    ok = mid
                else:
                    ng = mid
            return ok
        
        def solve1(mid):
            c=0
            z=bisect_left(A_plus,-(-mid//A_minus[0]))
            c+=len(A_plus)-z
            for x in A_minus[1:]:
                if z>0 and A_plus[z-1] >= -(-mid//x):
                    while z>0 and A_plus[z-1] >= -(-mid//x):
                        z-=1
                c+=len(A_plus)-z
            if c>=K:
                return True
            else:
                return False
        
        print(-nibutan1(0,10**18+1))
    K-=len(A_minus)*len(A_plus)
    if 0<K<=len(A_zero)*(N-len(A_zero))+(len(A_zero)*(len(A_zero)-1))//2:
        print(0)
    K-=len(A_zero)*(N-len(A_zero))+(len(A_zero)*(len(A_zero)-1))//2
    if K>0:
        def nibutan2(ok,ng):
            while abs(ok-ng) > 1:
                mid = (ok + ng) // 2
                if solve2(mid):
                    ok = mid
                else:
                    ng = mid
            return ok
        
        def solve2(mid):
            c=0
            if len(A_minus)>1:
                z=bisect_right(A_minus,mid//A_minus[0])
                c+=z
                if mid//A_minus[0]>=A_minus[0]:
                    c-=1
                for x in A_minus[1:]:
                    if z>0 and A_minus[z-1] > mid//x:
                        while z>0 and A_minus[z-1] > mid//x:
                            z-=1
                    c+=z
                    if mid//x>=x:
                        c-=1
            if len(A_plus)>1:
                z=bisect_right(A_plus,(mid//A_plus[0]))
                c+=z
                if (mid//A_plus[0])>=A_plus[0]:
                    c-=1
                for x in A_plus[1:]:
                    if z>0 and A_plus[z-1] > mid//x:
                        while z>0 and A_plus[z-1] > mid//x:
                            z-=1
                    c+=z
                    if mid//x>=x:
                        c-=1
            c//=2
            if c>=K:
                return True
            else:
                return False
        
        print(nibutan2(10**18+1,0))

    
        
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 118912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N;
    cin >> N;
    int cnt = 0;
    set<int> check, tmp;
    queue<int> que[N];
    rep(i, N){
        rep(j, N-1){
            int A; cin >> A; A--;
            que[i].push(A);
        }
        check.insert(i);
    }
    while(true){
        for(auto &e: check){
            if(que[e].empty()) continue;
            int j = que[e].front();
            if(que[j].front() == e){
                tmp.insert(e), tmp.insert(j);
            }
        }
        for(auto &e: tmp) que[e].pop();
        check.clear();
        swap(check, tmp);
        if(!check.empty()) cnt++;
        else break;
    }
    rep(i, N){
        if(!que[i].empty()){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
}

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

int main(void) {
	const int P[10] = { 0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
	string S;

	cin >> S;
	int len = S.length();
	int N = 0;
	int H = 0;
	for (int i = 1; i <= len; ++i) {
		int c = (int)(S[i - 1] - '0');
		H += c;
		N += P[len - i + 1] * c;
	}

	if (N % H == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int cnt[100002];
int main() {
#define mod 1000000007;
	int N, A;
	int ans = 1;
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A);
		cnt[A]++;
	}
	for (int i = N - 1; i > 0; i -= 2)
	{
		if (cnt[i]!=2)
		{
			puts("0");
			return 0;
		}
		else
		{
			ans = ans * 2 % mod;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  string s = "";

  while(n != 0){
    if(n%2 == 0) s = "0" + s;
    else{
      s = "1" + s;
      n--;
    }
    n /= -2;
  }

  if(s == "") s = "0";

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<functional>
#define all(c) c.begin(),c.end()
#define uni(c) c.erase(unique(c.begin(),c.end()),c.end())
#define pb push_back
using namespace std;
vector<int> uf;
int sum=0;
int n,m,ans;
string s;
int cal(int x){
	return x%10+x/10;
}
void f(int a,int b,int cnt){
	//cout<<a<<"  "<<b<<endl;
	if(a){
		for(int i=0;i<uf.size();i++)
			f(a-1,b,cnt+uf[i]);
	}else if(b){
		for(int i=0;i<uf.size();i++)
			f(a,b-1,cnt+cal(uf[i]*2));
	}else{
		ans+=((cnt+sum)%10==0);
	}
	
}
int main(){
	while(cin>>n>>s>>m){
		uf.resize(m);
		for(int i=0;i<m;i++){
			cin>>uf[i];
		}
		sum=0;
		int a=0,b=0;
		for(int i=1;i<=n;i++){
			if(i&1){
				if(isdigit(s[s.size()-i])){
					sum+=s[s.size()-i]-'0';
				}else{
					a++;
				}
			}else{
				if(isdigit(s[s.size()-i])){
					sum+=cal(2*(s[s.size()-i]-'0'));
				}else{
					b++;
				}
			}
			
		}
		ans=0;
		f(a,b,0);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1336
import itertools
n,m=map(int,input().split())
edges={tuple(sorted(map(int,input().split()))) for i in range(m)}
ans=0

for i in itertools.permutations(range(2,n+1),n-1):
  l=[1]+list(i)
  ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==n-1

print(ans)

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

int main() {
 ll N,K;
 cin >> N >>K;
  if(K%2 ==0){
    ll x = K/2;
    ll c = 0;//N以下の,Kの剰余がK/2の数
    if(N >= K/2){
    while(1){
      c++;
      x += K;
      if(x>N){
        break;
      }
    }
   }

    ll d = N/K;
    cout << c*c*c + d*d*d <<endl;
  }
  else if(K%2 == 1){
    ll e = N/K;
    cout << e*e*e <<endl;
  }

}



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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());
    ll ans = 1000010010;
    ll ai = a[0], aj = a[1];
    ll val = a[0]/2;
    int num = 1;
    rep(i, 1, n) {
        ans = min(abs(val-(a[0]-a[i])), ans);
        if(ans == abs(val-(a[0]-a[i]))) num = i;
        //cout << a[i] << " " << abs(val-(a[0]-a[i])) << endl;
    }
    aj = a[num];
    cout << ai << " " << aj << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    int A, B;
    cin >> A >> B;
    for(int i = (100*1)/10; i <= (100*100)/8; i++) {
        if((i*8)/100 == A && (i*10)/100 == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();
            if (Math.abs(N - M) >= 2) {
                System.out.println(0);
                return;
            }

            long mod = (long) (1e9 + 7);

            if (N < M) {
                int swap = N;
                N = M;
                M = swap;
            }

            long res = 1;
            if (N == M) {
                res = 2;
            }
            int NM = N + M;
            for (int i = 0; i < NM; i++) {
                if (i % 2 == 0) {
                    res *= N;
                    res %= mod;
                    N--;
                } else {
                    res *= M;
                    res %= mod;
                    M--;
                }
            }

            System.out.println(res);
        }
    }
}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double[] X = new double[N];
        double[] Y = new double[N];
        for (int i=0; i<N; i++){
            X[i] = (double)sc.nextInt();
            Y[i] = (double)sc.nextInt();
        }
        double sum = 0;
        double count = 0;
        for (int i=0; i<N; i++){
            for (int j=i+1; j<N; j++){
                sum += Math.sqrt((X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]));
                count += 1;
            }
        }
        System.out.println(sum/count*(N-1));
	}
}

Measured memory_bytes: 27084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,K;
  cin>>N>>K;
  int sum = 1;
  for(int i=0 ; i<N ; i++){
  if(sum >= K){
  sum += K;
  }
  else{
  sum *= 2;
  }
}
  cout<<sum;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	string a;
	int c = 0;
	cin >> a;
	for(int i = 0; i <= 2; i++){
		if(a[i] == '1'){
			c++;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, b, a) for(int i = (b); i >= (a); i--)
using namespace std;
const int N = 1e5 + 9, P = 1e9 + 7;
int n, l, r;
ll A, B, ans, minn, a[N], dp[N], sum[N];//dp[i]:第一个集合最后一个是i的方案数
int main(){
    scanf("%d%lld%lld", &n, &A, &B);
    rep(i, 1, n) scanf("%lld", &a[i]);
    if(B > A) swap(A, B);
    sort(a + 1, a + n + 1);
    rep(i, 1, n - 2) if(a[i + 2] - a[i] < B){
        printf("0");
        return 0;
    }
    dp[1] = sum[1] = 1, minn = a[2] - a[1], dp[2] = a[2] - a[1] >= A ? 2 : 1, sum[2] = dp[2] + 1;
    rep(i, 3, n){
        while(a[i] - a[r + 1] >= A) r++;
        if(a[i - 1] - a[i - 2] < B) l = i - 2;
        if(l == 0) {
            if(r == 0) dp[i] = minn >= B;
            else dp[i] = (sum[r] + 1) % P;
        }
        else dp[i] = l <= r ? (sum[r] - sum[l - 1] + P) % P : 0; 
        sum[i] = (sum[i - 1] + dp[i]) % P, minn = min(minn, a[i] - a[i - 1]);
    }
    per(i, n - 1, 1) {
        ans = (ans + dp[i]) % P;
        if(a[i + 1] - a[i] < B) break;
    }
    bool ok = true;
    rep(i, 2, n) ok = ok && (a[i] - a[i - 1] >= B);
    printf("%lld", (ans + dp[n] + ok) % P);
    return 0;
}

Measured memory_bytes: 2560
#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#define eps 0.01
#define pi acos(-1)
#define e exp(1)
using namespace std;
typedef long long ll;
char s[20];
int main() {
    while (cin >> s) {
        ll cnt = 0;
        ll ans = atoi(s);
        for (int i = 0; s[i]; ++i) {
            cnt += s[i] - '0';
        }
        if (ans%cnt == 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include<algorithm>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i, n) for(int i = 0;i < n;i++)
using namespace std;
using ll = long long;


ll N, A, B, H[101010];

bool check(ll x) {
	ll cnt = 0;

	rep(i, N) {
		ll h = H[i] - B * x;
		if (h <= 0)continue;
		cnt += h / (A - B);
		if (h%(A-B))cnt++;
	}
	return cnt <= x;
}



int main()
{

	cin >> N >> A >> B;
	rep(i, N) 
		cin >> H[i]; 


	ll ng = 0, ok = 1010101010;
	while (ng + 1 != ok) {
		ll x = (ng + ok) / 2;
		if (check(x)) ok = x;
		else ng = x;
	}


	cout << ok << endl;


	return 0;
}



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

using namespace std;

#define ll long long
#define ar array

int a = 0, b = 0, c = 0, d = 0;
string str;
   
void test_case()
{

   cin >> str;
   
   if (str == "AC")
      ++a;
   if (str == "WA")
      ++b;
   if (str == "TLE")
      ++c;
   if (str == "RE")
      ++d;
            
}
   
int main()
{
   int t;
   cin >> t;
   for (int nr = 1; nr <= t; ++nr) {
      test_case();
   }
   cout << "AC x " << a << endl;
   cout << "WA x " << b << endl;
   cout << "TLE x " << c << endl;
   cout << "RE x " << d << endl;
   
   
   return 0;
}

Measured memory_bytes: 3628
using System;
        using System.Collections.Generic;
        using System.Linq;
         
        class ShiftOnly
        {
            static void Main(string[] args)
            {
                int m = 0; // 2で割った回数
                int n = int.Parse(Console.ReadLine()); // 扱うデータの個数
                var blackBoardNum = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
         
                while(blackBoardNum.All(x => (x % 2) == 0))
                {
                    blackBoardNum = blackBoardNum.Select(x => x / 2).ToArray();
                    m++;
                }
         
                Console.WriteLine($"{m}");
         
                return;
            }
        }

Measured memory_bytes: 13396
import sys
read=sys.stdin.readline

class segtree:
    def __init__(self,n,op,e):
        self.e=e
        self.op=op
        self.size=1<<(n-1).bit_length()
        self.SEG=[self.e]*(self.size*2)
    
    def update(self,i,x):
        i+=self.size
        self.SEG[i]=x
        
        while i>0:
            i>>=1
            self.SEG[i]=self.op(self.SEG[i*2],self.SEG[i*2+1])
    
    def get(self,i):
        return self.SEG[i+self.size]
    
    def query(self,l,r):
        l+=self.size
        r+=self.size
        
        lres,rres=self.e,self.e
        
        while l<r:
            if l&1:
                lres=self.op(lres,self.SEG[l])
                l+=1
            
            if r&1:
                r-=1
                rres=self.op(rres,self.SEG[r])
            
            l>>=1
            r>>=1
            
        res=self.op(lres,rres)
        return res

INF=float('inf')
N,M=map(int,read().split())

Q=[]
for i in range(M):
    l,r,c=map(int,read().split())
    Q.append((l-1,r-1,c))
Q.sort(key=lambda x:x[0])

seg=segtree(N,min,INF)
seg.update(0,0)
for L,R,C in Q:
    res=seg.query(L,R)+C
    if seg.get(R)>res:
        seg.update(R,res)
ans=seg.get(N-1)
print(ans if ans!=INF else -1)

Measured memory_bytes: 95496
#include <cstdio>
#include <algorithm>
#define F first
#define S second
using namespace std;
long long n, k;
pair<int,int> a[100005];
int main() {
	int i;
	scanf("%lld%lld", &n, &k);
	for(i=0; i<n; i++) scanf("%d%d", &a[i].F, &a[i].S);
	sort(a, a+n);
	for(i=0; k>0; i++) k -= a[i].S;
	printf("%d", a[--i].F);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(a,s,d) for(int a=s;a<=d;a++)
using namespace std;
typedef long long ll;

int main()
{
    int n,k;cin>>n>>k;
    int ans=(n-k)/(k-1)+1;
    if((n-k)%(k-1)) ans++;
    cout<<ans<<endl;
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000000000000000 // If you use it, make sure not to put in "int" type variable ;(, use long long int
const ll mod=2;

int main()
{
    int nT; nT=1;
    while(nT--)
    {
        ll n; cin>>n;
        ll v[n], c[n];
        rep(i,n) cin>>v[i];
        rep(i,n) cin>>c[i];
        ll x=0, y=0;
        rep(i,n) if(v[i]>=c[i]) 
        {
            x+=v[i];
            y+=c[i];
        }
        cout<<x-y;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll D, T, S;
	cin >> D >> T >> S;
	if ((D + S - 1) / S > T) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int n;
int a[200009];
int dp[200009];
int main()
{
    scanf("%d",&n);
    memset(dp,0xcf, sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        dp[a[i]]=max(dp[a[i]],dp[a[i]-1]+1);
    }
    int ans=-1;
    for(int i=1;i<=n;i++){
        if(dp[i]>0)ans=max(ans,dp[i]);
    }
    if(ans==-1)cout<<-1<<endl;
    else cout<<n-ans<<endl;
    return 0;
}

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

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        long[] t = in.nl(n), a = in.nl(n);
        long[][] range_t = new long[n][2];
        range_t[0][1] = t[0]; range_t[0][0] = t[0];
        for (int i = 1; i < n; i++) {
            if(t[i]>t[i-1]){
                range_t[i][0] = t[i];
                range_t[i][1] = t[i];
            }else{
                range_t[i][0] = 1;
                range_t[i][1] = range_t[i-1][1];
            }
        }
        long[][] range_a = new long[n][2];
        range_a[n-1][1] = a[n-1]; range_a[n-1][0] = a[n-1];
        for (int i = n-2; i >= 0; i--) {
            if(a[i]>a[i+1]){
                range_a[i][0] = a[i];
                range_a[i][1] = a[i];
            }else{
                range_a[i][0] = 1;
                range_a[i][1] = range_a[i+1][1];
            }
        }
        long ans = 1;
        for (int i = 0; i < n; i++) {
            long range = Math.max(Math.min(range_a[i][1], range_t[i][1])-Math.max(range_a[i][0], range_t[i][0])+1, 0);
            ans *= range;
            ans %= mod;
        }
        out.println(ans);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 53600
$cnt = 0;
while(<>){
	chomp;
	if($. == 1){
		@c = split(/ /, $_);
	}elsif($. == 2){
		@b = split(/ /, $_);
	}else{
		@a = split(/ /, $_);
		$t = 0;
		for $i (0 .. $#a){
			$t += $a[$i] * $b[$i];
		}
		$cnt++ if($t + $c[2] > 0);
	}
}

print "$cnt\n";


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		if (a <= 5 && b <= 5){
			if (a > b) for (int i = a; i >= b; i--){
				cout << i;
				if (i != b)cout << ' ';
				else cout << endl;
			}
			else for (int i = a; i <= b; i++){
				cout << i;
				if (i != b)cout << ' ';
				else cout << endl;
			}
		}
		else{
			if (a >= 6){
				if (b >= 6){
					if (a < b){
						for (int i = a; i <= b; i++){
							cout << i;
							if (i != b)cout << ' ';
							else cout << endl;
						}
					}
					else {
						for (int i = a; i < 10; i++) {
							cout << i << ' ';
						}
						cout << "5 4 3 2 1 0 1 2 3 4 5 ";
						for (int i = 6; i <= b; i++) {
							cout << i;
							if (i != b)cout << ' ';
							else cout << endl;
						}
					}
				}
				else{
					for (int i = a; i < 10; i++){
						cout << i << ' ';
					}
					for (int i = 5; i >= b; i--){
						cout << i;
						if (i != b)cout << ' ';
						else cout << endl;
					}
				}
			}
			else{
				for (int i = a; i <= b; i++){
					cout << i;
					if (i != b)cout << ' ';
					else cout << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 2964
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int ave=sc.nextInt();
		int[] num=new int[N];

		for(int i=0; i<N; i++) {
			num[i]=sc.nextInt();
		}

		long[][][] goukei=new long[N+1][N*50+1][N+1];
		boolean[][][] bbnwa=new boolean[N+1][N*50+1][N+1];
		int[][][] maisu=new int[N+1][N*50+1][N+1];

		for(int i=0; i<=N; i++) {
			for(int j=0; j<N*50+1; j++) {
				for(int k=0; k<=N; k++) {
					goukei[i][j][k]=0;
					bbnwa[i][j][k]=false;
					maisu[i][j][k]=0;
				}
			}
		}

		goukei[0][0][0]=1;
		bbnwa[0][0][0]=true;


		for(int i=0; i<N; i++) {
			for(int j=0; j<N*50+1; j++) {
				for(int k=0; k<N; k++) {
					if(bbnwa[i][j][k]==true) {
						bbnwa[i+1][j+num[i]][k+1]=true;		//bbnwa[j]がtrueだと与えられた数字の部分和でjがつくれる
						bbnwa[i+1][j][k]=true;
						goukei[i+1][j+num[i]][k+1]+=goukei[i][j][k];	//goukeiはその部分和の場合の数
						goukei[i+1][j][k]+=goukei[i][j][k];
						maisu[i+1][j][k]=maisu[i][j][k];				//maisuは部分和を達成しているカードの枚数の数
						maisu[i+1][j+num[i]][k+1]=maisu[i][j][k]+1;
					}
				}
			}
		}

		long sousu=0;

		for(int j=1; j<=N; j++) {
			sousu+=goukei[N][j*ave][j];
		}
		System.out.println(sousu);
	}
}

Measured memory_bytes: 165612
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let i: Vec<Vec<i32>> =  read_vec2(3);
    for i1 in 0..i.len() {
        for i2 in 0..i.len() {
            for j1 in 0..i.len() {
                for j2 in 0..i.len() {
                    if i[i1][j1] + i[i2][j2] != i[i1][j2] + i[i2][j1] {
                        println!("No");
                        return;
                    }
                }
            }
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352