akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

struct UnionFind {
    vector<int> par, rnk, cnt;
    UnionFind(int N) : par(N), rnk(N), cnt(N) {
        for (int i = 0; i < N; ++i)
            par[i] = i, cnt[i] = 1;
    }

    int root(int x) {
        return (par[x] == x ? x : par[x] = root(par[x]));
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y)
            return;
        if (rnk[x] < rnk[y])
            swap(x, y);
        if (rnk[x] == rnk[y])
            rnk[x]++;
        par[y] = x;
        cnt[x] += cnt[y];
    }

    int rcnt(int x) {
        return cnt[root(x)];
    }
};

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

    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    vector<int> fcnt(N), bcnt(N);

    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        uf.unite(A, B);
        fcnt[A]++;
        fcnt[B]++;
    }

    for (int i = 0; i < K; ++i) {
        int C, D;
        cin >> C >> D;
        C--, D--;
        if (uf.issame(C, D))
            bcnt[C]++, bcnt[D]++;
    }

    for (int i = 0; i < N; ++i)
        cout << uf.rcnt(i) - 1 - fcnt[i] - bcnt[i] << ' ';
    cout << endl;
    return 0;
}


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

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

int main(){
    int N;
    cin >> N;
    //各ロボットの右端、左端の情報を入れる配列
    vector<pair<ll, ll>> p(N);
    rep(i, N){
        ll x, l;
        cin >> x >> l;
        //右端の情報をfirstに、左端の情報をsecondに入れる
        p[i] = make_pair(x + l, x - l);
    }

    //右端の位置が小さい順にソート
    sort(p.begin(), p.end());

    //残すロボットの個数
    int val = 0;
    //残すと決めたロボットの中の、最も右端の情報
    ll cur = -pow(10, 9);
    rep(i, N){
        if(cur <= p[i].second){
            val++;
            cur = p[i].first;
        }
    }
    cout << val << endl;
    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  string s;
  int a=0,un=0;
  int okflag=true;
  for(int i=0;i<n;i++){
    cin >> s;
    if(s=="A"){
      a++;
    }else{
      un++;
    }
    if(un>a){
      okflag=false;
    }
  }
  if(okflag&&(a==un)) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}



Measured memory_bytes: 3140
import math

if __name__ =="__main__":

    param = input()

    param = input().split(" ")
    x = [int(a) for a in param]

    param = input().split(" ")
    y = [int(a) for a in param]

    #p = 1
    d1 = math.pow(sum([math.fabs(xi - yi) for xi, yi in zip(x, y)]), 1/1.0)

    #p = 2
    d2 = math.pow(sum([math.fabs(xi - yi)**2 for xi, yi in zip(x, y)]), 1/2.0)

    #p = 3
    d3 = math.pow(sum([math.fabs(xi - yi)**3 for xi, yi in zip(x, y)]), 1/3.0)

    #p = ∞
    dm = max([math.fabs(xi - yi) for xi, yi in zip(x, y)])

    print(d1)
    print(d2)
    print(d3)
    print(dm)



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

int main() {
    int N, D, X;
    cin >> N >> D >> X;
    int A[N];
    for (int i=0; i<N; i++) cin >> A[i];
    int count=X;
    for (int i=0; i<N; i++){
        count+=(D-1)/A[i]+1;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
public class Main {

    private static void solver(InputReader sc, PrintWriter out) throws Exception {
       int n = sc.nextInt(); int k = sc.nextInt();
       int arr[] = new int[n];
       for(int i=0; i<n; i++) arr[i] = sc.nextInt();
       Arrays.sort(arr);
       int sum=0;
       for(int i=0; i<k; i++) sum += arr[i];
       out.println(sum);
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    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 int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
class Pair implements Comparable<Pair>{
    int x,y;
    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair p){
        return (int)(this.x - p.x);
    }
}
class Tuple{
    String s;
    int x, y;

    public Tuple(String s, int x, int y) {
        this.s = s;
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Tuple tuple = (Tuple) o;
        return x == tuple.x &&
                y == tuple.y &&
                s.equals(tuple.s);
    }

    @Override
    public int hashCode() {
        return Objects.hash(s, x, y);
    }
}

Measured memory_bytes: 33364
c = %{.,!? abc def ghi jkl mno pqrs tuv wxyz}.split
c[0] += ' '
gets.to_i.times do
  gets.chomp.split('').map(&:to_i).push('/').each_cons(2).reduce(0) do |t, (a, b)|
    if a != b
      print c[a-1][t % c[a-1].size] if a != 0
      t = 0
    else t += 1
    end
  end
  puts
end

Measured memory_bytes: 8972
#include <iostream>

using namespace std;


int main(){
  
  char c;
  cin >> c;
  
  switch(c){
    case 'A':
      cout << 'T' << endl;
      break;
    case 'T':
      cout << 'A' << endl;
      break;
    case 'G':
      cout << 'C' << endl;
      break;
    case 'C':
      cout << 'G' << endl;
  }
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define INF 1e16+1
#define se second
#define fi first

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector< vector<pll> > vvpll;

ll i,j,n,m,x,a,b,w,k,c;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	ll dp[3][n+1];
	memset(dp,0,sizeof(dp));
	for(i=1;i<=n;i++){
		cin>>a>>b>>c;
		dp[0][i] = a + max(dp[1][i-1],dp[2][i-1]);
		dp[1][i] = b + max(dp[0][i-1],dp[2][i-1]);
		dp[2][i] = c + max(dp[1][i-1],dp[0][i-1]);
	}
	x = max(dp[0][n],max(dp[1][n],dp[2][n]));
	cout<<x<<'\n';
}


Measured memory_bytes: 2560
#abc177 c
import sys,math,collections,itertools
input = sys.stdin.readline
m=10**9+7

N=int(input())
A=list(map(int,input().split()))
Asum = sum(A)
Asum_list = []
for i in range(N):
    Asum -=A[i]
    Asum_list.append(Asum)
ans = 0
for a,b in zip(A,Asum_list):
    ans = (ans + a*b)%m
print(ans)



Measured memory_bytes: 32636
n = int(input())
import string
alphabets = string.ascii_letters # a-z+A-Zをロード
characters = alphabets[:26]
def base_cvt(value, n=26):
    tmp = int(value)
 
    result = ''
    tmp = int(value)
    while tmp >= n:
        idx = tmp%n
        result = characters[idx] + result
        tmp = int(tmp / n) -1
    idx = tmp%n
    result = characters[idx] + result
    return result
print(base_cvt(value= n -1))

Measured memory_bytes: 9964
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>


int main() {
    int n, m;

    std::cin >> n >> m;

    std::vector<std::vector<long long> > v(n, std::vector<long long>(n, 100000000000000LL));
    std::vector<std::vector<long long> > vv(n, std::vector<long long>(n, 100000000000000LL));

    for (int i = 0; i < m; i++) {
        int from, to, cost;

        std::cin >> from >> to >> cost;
        from--;
        to--;
        v[from][to] = cost;
        v[to][from] = cost;
    }

    vv = v;

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[i][j] = std::min(v[i][j], v[i][k] + v[k][j]);
            }
        }
    }

    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (vv[i][j] != 100000000000000 && vv[i][j] != v[i][j]) c++;
        }
    }

    std::cout << c << std::endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, x, N) for (int i = x; i < (N); i++)
using namespace std;
int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	rep(i, 0, N)
	{
		a[i] = 0;
	}
	rep(i, 0, K)
	{
		int d;
		cin >> d;
		rep(j, 0, d)
		{
			int x;
			cin >> x;
			a[x - 1] = 1;
		}
	}
	int count = 0;
	rep(i, 0, N)
	{
		if (a[i] == 0)
		{
			count++;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
int n, a, b;
signed main() {
	cin >> n >> a >> b;
	if (a > b) {
		puts("0");
		END;
	}
	if (n == 1) {
		if (a == b)puts("1");
		else puts("0");
		END;
	}
	n -= 2;
	int c = a * n;
	int d = b * n;
	cout<<d - c + 1 << endl;
	END;
}


Measured memory_bytes: 504
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	static long mod = 1000000007;
	static int[] ans;
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		string res = "";

		int n = int.Parse(Console.ReadLine());
		string t = "0 "+ Console.ReadLine();
		int[] vals = parseAry(t.Split(cs));

		int[] resBall=new int[n+1];



		for ( int i = n; i > 0; i-- ) {
			int total = 0;
			for ( int k = 1; i * k <= n; k++ ) {
				total += resBall[i * k];
			}
			if ( ( total & 1 ) == 1 ) {

				if ( vals[i] == 0 ) { resBall[i] = 1; }
			} else {
				if ( vals[i] == 1 ) { resBall[i] = 1; }

			}			

		}


		Console.WriteLine(resBall.Sum());
		StringBuilder sb = new StringBuilder();
		
		for ( int i = 1; i <= n;i++ ) {
			if ( resBall[i] == 1 ) { sb.Append(i+" "); }
		}
		if ( sb.Length > 1 ) {
			sb = sb.Remove(sb.Length - 1, 1);
			Console.WriteLine(sb);
		}
			return;

	}



	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}


}

Measured memory_bytes: 34644
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define ll long long int
#define ld long double
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define mod(n) (n) % 1000000007
#define sp << " "
#define precision(n) cout << fixed << setprecision(n);
#define startTime time_t start, end;time(&start);
#define endTime time(&end);double tt = double(end-start);cout<<"Time taken : "<<fixed<<tt<<setprecision(5);cout <<" sec"<< endl;
 
using namespace std;
 
int main() { 
    IOS;
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < 3; i++) {
    	if (s[i] == 'S') cnt = 0;
    	else {cnt++; ans = max(ans, cnt);}
    }
    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  string line;
  vector<string> W;
  for(int i=0; i < N; i++){
    cin >> line;
    W.push_back(line);
  }
  bool ans = true;
  for(int i=1; i < N; i++){
    for(int j=0; j < i; j++){
      if(W[i] == W[j]) ans = false;
    }
    if(W[i][0] != W[i-1][W[i-1].length()-1]) ans = false;
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby
@h, @w, @k = gets.chomp.split.map(&:to_i)
@c = []

@h.times do
  @c << gets.chomp.split('')
end

@ans = 0
def check(arr)
  black_num = 0

  @h.times do |i|
    next if arr[i] == 0
    @w.times do |j|
      next if arr[@h + j] == 0
      black_num += 1 if @c[i][j] == '#'
    end
  end
  @ans += 1 if black_num == @k
end

def dfs(arr, n)
  return check(arr) if arr.length == n

  dfs(arr + [0], n)
  dfs(arr + [1], n)
end

dfs([], @w + @h)

puts @ans


Measured memory_bytes: 14340
#include<stdio.h>
int main()
{
    int A, B, C, D, j, k;
    scanf("%d %d %d %d", &A, &B, &C, &D);
    j=A*B;
    k=C*D;
    if(j<=k)
    {
        printf("%d", k);
    }
    else
        printf("%d", j);
}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

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

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

template<class T>
void chmax(T& a,T b){
	a=max(a,b);
}

template<class T>
void chmin(T& a,T b){
	a=min(a,b);
}

int main(){
	ll w=read(),h=read();
	vector<pair<ll,int>> e;
	REP(i,w)
		e.PB(MP(readLL(),1));
	REP(i,h)
		e.PB(MP(readLL(),2));
	sort(e.begin(),e.end());
	ll ans=0;
	for(auto p:e){
		if(p.second==1){
			if(w>0){
				ans+=p.first*(h+1);
				w--;
			}
		}else{
			if(h>0){
				ans+=p.first*(w+1);
				h--;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s,t;
    
    cin >> s >> t;
    
    //s,tソート
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if(s<t){ 
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, m := scanInt(), scanInt()

	combInit(m)

	ans := perm(m, n)
	for i := 1; i <= n; i++ {
		if i&1 == 1 {
			ans -= comb(n, i) * perm(m-i, n-i)
		} else {
			ans += comb(n, i) * perm(m-i, n-i)
		}
		ans %= mod
	}
	fmt.Fprintln(wr, (ans*perm(m, n)%mod+mod)%mod)
}

const mod = 1000000007

var fac, ifac, inv []int

func combInit(n int) {
	fac = make([]int, n+1)
	ifac = make([]int, n+1)
	inv = make([]int, n+1)

	fac[0], fac[1] = 1, 1
	ifac[0], ifac[1] = 1, 1
	inv[1] = 1

	for i := 1; i < n; i++ {
		fac[i+1] = fac[i] * (i + 1) % mod
		inv[i+1] = mod - inv[mod%(i+1)]*(mod/(i+1))%mod
		ifac[i+1] = ifac[i] * inv[i+1] % mod
	}
}

func comb(a, b int) int { return (fac[a] * ifac[b] % mod) * ifac[a-b] % mod }
func perm(a, b int) int { return fac[a] * ifac[a-b] % mod }


Measured memory_bytes: 13944
#include<iostream>
#include<cstdio>

using namespace std;

int n,s[25];

int solve(int i,int cishi,int key)
{
    if(cishi==key){
        return 1;
    }else if(i>=n){
        return 0;
    }
    if(solve(i+1,cishi,key)){
        return 1;
    }else if(solve(i+1,cishi+s[i],key)){
        return 1;
    }else{
        return 0;
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    int q,key;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&key);
        if(solve(0,0,key)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int k;
    cin >> k;
    vector<ll> a(k + 1);
    rep(i, k) cin >> a[i + 1];
    vector<ll> l(k + 1), r(k + 1);
    l[k] = r[k] = 2;
    bool ok = true;
    if(a[k]!=2){
        ok=false;
    }
    rep(i, k)
    {
        int ite = k - 1 - i;
        //  cout<<ite<<endl;
        l[ite] = (ll)ceil((long double)l[ite + 1] / a[ite + 1]) * a[ite + 1];
        r[ite] = (ll)floor((long double)r[ite + 1] / a[ite + 1]) * a[ite + 1] + a[ite + 1] - 1;
        if (a[ite] != 0)
        {
            if (l[ite] % a[ite] == 0 or r[ite] % a[ite] == 0)
            {
            }
            else if (l[ite] / a[ite] == r[ite] / a[ite])
            {
                ok = false;
            }
        }
    }
    if (ok)
    {
        cout << l[0] << " " << r[0] << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 2560
#ARC078C

INF=float('inf')
n=int(raw_input())
a=map(int,raw_input().split())
ss=sum(a)
res=INF
x=a[0]
y=ss-a[0]
for i in xrange(1,n):
 res=min(res,abs(y-x))
 x+=a[i]
 y-=a[i]
print res


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

ll N, A[200010];
map<ll, ll> mp;

signed main(){
    cin >> N;
    REP(i, N){
        cin >> A[i];
        mp[A[i]]++;
    }
    ll K = 0;
    REP(i, N + 1){
        ll a = mp[i];
        K += a * (a - 1) / 2;
    }
    REP(i, N){
        ll a = max(0LL, mp[A[i]]);
        PRINT(K - (a - 1));
    }
    return 0;
}

Measured memory_bytes: 16640
#include <iostream>

using namespace std;
using ll = long long;

int main(){
  ll n, m;
  cin >> n >> m;
  ll maxl = 1, minr = n;
  for(ll i=0; i<m; ++i){
    ll l, r;
    cin >> l >> r;
    if(maxl < l) maxl = l;
    if(minr > r) minr = r;
  }
  ll res;
  if(minr < maxl) res = 0;
  else res = minr - maxl + 1;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>L(M);
	vector<int>R(M);
	rep(i, M) {
		cin >> L[i] >> R[i];
	}
	vector<int>vec(N+10);
	rep(i, M) {
		vec[L[i] - 1]++;
	}
	rep(i, M) {
			vec[R[i]]--;
	}
	vector<int>sum(N+10);
	int s = 0;
	rep(i, N) {
		s += vec[i];
		sum[i] = s;
	}
	int cnt = 0;
	rep(i, N) {
		if (sum[i] == M)cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define MAX INT_MAX
#define MIN INT_MIN
#define ss second
#define ff first
const int mod = 1e9+7;

int minm(vector<int> &v, int k){
	int n = v.size();
	vector<int> dp(n, MAX);
	dp[0] = 0;
	dp[1] = abs(v[1]-v[0]);
	for(int i = 2; i < n; i++){
		for(int j = ((i-k)>=0?(i-k):0); j < i; j++){
			dp[i] = min(dp[j]+abs(v[j]-v[i]), dp[i]);
		}
	}
	return dp[n-1];
}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	cout << minm(v, k) << endl;
	return 0;
}


Measured memory_bytes: 1792
//答え見ました
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  string s;
  cin >> s;
  ll S = s.size();
  ll ans=0;
  ll key=0;
  
  for(int i=0; i<1<<S-1; i++){
    key=0;
    ans+=s[S-1]-48;
    for(int j=0; j<S-1; j++){
     if(i >> j & 1){
       key=0;
       ans+=s[S-j-2]-48;
     }
      else{
        key++;
        ans+=(s[S-j-2]-48)*pow(10,key);
      }
    }
  }
  
  cout << ans << endl;
  
}

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

int main (){
	int a,b,t;
	cin >> a>>b>>t;
	int sum=0,count=0;
	while(1){
		count +=a;
		if(count >t+0.5){
			break;
		}
		sum += b;
	}

	cout << sum << endl;
}


Measured memory_bytes: 888
import java.util.*;
import java.io.*;
public class Main {
	static long mod = 1000000007;
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		long k = Integer.parseInt(st.nextToken());
		ArrayList<Integer>[] g = new ArrayList[n];
		for(int i = 0; i < n; i++) g[i] = new ArrayList<>();
		for(int i = 0; i < n-1; i++){
			st = new StringTokenizer(br.readLine());
			int u = Integer.parseInt(st.nextToken())-1;
			int v = Integer.parseInt(st.nextToken())-1;
			g[u].add(v); g[v].add(u);
		}
		int[] count = new int[n];
		int[] count1 = new int[n];
		long[] ks = new long[n];
		boolean[] seen = new boolean[n];
		LinkedList<Integer> q = new LinkedList<>();
		seen[0] = true;
		q.add(0);
		while(!q.isEmpty()){
			int u = q.removeFirst();
			ks[u] = k - count[u];
			for(int v: g[u]){
				if(!seen[v]){
					count1[v]++;
					count1[u]++;
					count[v] = count1[u];
					seen[v] = true;
					q.add(v);
				}
			}
		}
		long res = 1;
		for(long p: ks) res = (res*p)%mod;
		System.out.println(res);
	}

}


Measured memory_bytes: 58168
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,n,a;
  scanf("%d %d",&h,&w);
  int maze[h+1][w+1];
  queue<int>que;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    que.push(a);
  }
  int str1,str2,jud;
  str1 = str2 = jud = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<que.front();j++){
      maze[str1][str2] = i+1;
      if(jud == 0) str2++;
      else str2--;
      if(str2 == w){
	jud= ~jud;
	str2--;
	str1++;
      }else if(str2 == -1){
	jud= ~jud;
	str2++;
	str1++;
      }
    }
    que.pop();    
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << maze[i][j];
      if(j+1 != w) cout << " "; 
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    vector<pair<int, string>> p(m);
    for(int i=0; i<m; i++){
        cin >> p.at(i).first >> p.at(i).second;
    }
    
    vector<bool> ac(n+1);
    vector<int> wa(n+1);
    int AC = 0;
    int WA = 0;
    for(int i=0; i<m; i++){
        if(p.at(i).second == "AC"){
            if(ac.at(p.at(i).first) == false){
                AC++;
                WA+=wa.at(p.at(i).first);
            }
            ac.at(p.at(i).first) = true;
        }else{
            if(ac.at(p.at(i).first) == false){
                wa.at(p.at(i).first)++;
            }
        }
    }
    
    cout << AC << " " << WA << endl;
}


Measured memory_bytes: 6912
#include<stdio.h>
#define abs(a) ((x)>=0)?(x):-(x)

int main()
{
    int x1,y1,x2,y2;
    int a,b;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    
    printf("%d %d %d %d",x2-(y2-y1),y2+(x2-x1),x1-(y2-y1),y1+(x2-x1));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
vector<vector<char>> v(1003,vector<char>(1003));
vector<vector<int>> dp(1003,vector<int>(1003,-1));
int n,m;
ll solve(int i,int j)
{
    if(i>n||j>m||v[i][j]=='#')
    return 0;
    if(i==n&&j==m)
    return 1;
    if(dp[i][j]!=-1)
    return dp[i][j];
    
    ll ans =  (solve(i+1,j)%mod + solve(i,j+1)%mod)%mod;
    return dp[i][j] = (int)ans;
}
int main() {
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>v[i][j];
        }
    }
    cout<<solve(1,1)%mod;
}


Measured memory_bytes: 8712
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>

using ll = long long;

int main() {
    int N;
    std::cin >> N;
    std::map<int, int> m;
    for (int i = 0; i < N; i++) {
        int in;
        std::cin >> in;
        m[in]++;
    }

    int ans = 0;
    for (auto& it : m) {
        if (it.second % 2 == 1) {
            ans++;
        }
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 4864
#include<iostream>
using namespace std;
int main()
{
	int a, b, c;
	while (cin >> a,a != 0)
	{	
		int d[10000] = {}, sum[10000] = {};
		for (int i = 0; i < a; i++)
		{
			cin >> d[i] >> b >> c;
			sum[i] = b + c;
			for (int j = 0; j < 1; j++)
			{
				if (sum[0] < sum[i])
				{
					swap(sum[i], sum[0]);
					swap(d[i], d[0]);
				}
			}

		}
		cout << d[0] << " " << sum[0] << endl;
	}
}

Measured memory_bytes: 1244
//By Tushar Gautam
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    n--;k--;
    if(n%k==0) cout<<n/k;
    else cout<< 1+n/k;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x+r <= W && x-r >= 0 && y+r <= H && y-r >= 0){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
    
}


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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int p[n];
    int x=0,y=0,z=0;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        if(p[i] <= a){
            x++;
        }else if (a+1 <= p[i] && p[i] <= b){
            y++;
        }else{
            z++;
        }
    }
    cout << min(x,min(y,z)) << endl;

    return 0;
}

Measured memory_bytes: 256
n, d = map(int, input().split())
l = []
for _ in range(n):
    li = list(map(int, input().split()))
    l.append(li)
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dis = 0
        for di in range(d):
            dis += abs(l[j][di] - l[i][di]) ** 2
        dis_t = dis ** 0.5
        if dis_t.is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;

int main() {
    char s[1000001];

    cin >> s;

    int len = strlen(s);
    char tmp[1000001];
    strcpy(tmp, s);
    int ans1 = 0;

    for (int i=1; i<len; i++) {
        if (s[i-1] == '0' && s[i] == '0') {
            s[i] = '1';
            ans1++;
        }
        else if (s[i-1] == '1' && s[i] == '1') {
            s[i] = '0';
            ans1++;
        }
    }

    strcpy(s, tmp);
    if (s[0] == '0')  s[0] = '1';
    else                s[0] = '0';
    int ans2 = 1;
    
    for (int i=1; i<len; i++) {
        if (s[i-1] == '0' && s[i] == '0') {
            s[i] = '1';
            ans2++;
        }
        else if (s[i-1] == '1' && s[i] == '1') {
            s[i] = '0';
            ans2++;
        }
    }

    cout << min(ans1, ans2) << endl;


    return 0;
}

Measured memory_bytes: 512
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"3"# => "2",
r#"1"# => "Hello World",
r#"2 4 5"# => "9",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
    }

    if n == 1 {
        "Hello World".to_string()
    } else {
        input! {
            source = src,
            _n: usize,
            a: usize,
            b: usize,
        }
        (a + b).to_string()
    }
}

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

int main() {
    int n, m;
    cin >> n >> m;
    int food[31] = {};

    rep(aa, n) {
        int k;
        cin >> k;

        rep(bb, k) {
            int a;
            cin >> a;
            food[a]++;
        }
    }
    int ans = 0;
    rep(i, 31) if (food[i] == n) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),T=sc.nextInt();
		int minCost = 1001;
		for(int i =0; i<N; i++) {
			int cost = sc.nextInt(),time = sc.nextInt();
			if(time > T) continue;
			if(minCost > cost) minCost = cost;
		}
		System.out.println(minCost == 1001? "TLE":minCost);
	}
}


Measured memory_bytes: 21716
#pragma GCC Optimize("Ofast")
#pragma GCC Optimize "trapv"
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 

using namespace std;
//using namespace boost::multiprecision; 

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define TC int t; cin >> t; while(t--)
#define li long int
#define ll long long
#define ull unsigned long long 
#define Vec(x) vector <x>
#define Pai(x,y) pair <x,y>
#define Map(x,y) map <x,y>
#define UMap(x,y) unordered_map <x,y>
#define Set(x) set <x>
#define Sta(x) stack <x>
#define Qu(x) queue <x>
#define DQ(x) deque(x)
#define PriorQ(x)	priority_queue <x>
#define bg begin()
#define ed end()
#define sz size()
#define ct(x) count(x)
#define len length()
#define F first
#define S second
#define Makep make_pair
#define ins(x) insert(x)
#define ers(x) erase(x)
#define endl "\n";
#define MOD 1000000007
#define PI 2*acos(0.0)
#define clr() clear()
#define fori0(n) for(int i=0;i<n;i++)
#define foriab(a,b) for(int i=a;i<b;i++)
#define mem0(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,1,sizeof(x))
#define autoit(x) for(auto it=x.beg;it!=x.ed;it++)
#define count0(x) __builtin_popcount(x)
#define ret return 
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

const ll Inf=1e9+5;

ll a[100005],freq[1000006],mx=INT_MIN;

namespace funset{
bool checkvow(char x){
	return ((0x208222)>>(x&(0x1f)))&1;
	}
ll highpow2(ll x){
	return (x&~(x-1));
	}
bool chk2(ll x){
		return (x&(x-1));
	}	
}

using namespace funset;

ll n, w;
ll wei[101],val[101],dp[1001][10001];


void solve(){
	ll x;
	cin >> x;
	if(x>=30){
		cout << "Yes" << endl;
		return;
	}
	cout << "No" << endl;
}

int main(){
	auto beg=clock();
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	
	FAST
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
	auto ted=clock();
	#ifndef ONLINE_JUDGE
	cout << (double)(ted-beg)/CLOCKS_PER_SEC << endl;
	#endif
	ret 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
string to_string(const char* s) {
  return to_string((string) s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define  oo 1e15
#define limit (int)(1e9+7)
#define two pair<int,int>
#define ll long long int
#define int long long int
#define double long double
#define mod(x,m) ((x%m+m)%m)
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define fori(x,n) for(int i = x; i < n; i++)
#define forj(y,m) for(int j = y; j < m; j++)
#define fork(z,p) for(int k = z; k < p; k++)
#define speedforces std::ios::sync_with_stdio(false)
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file  freopen("output.txt", "w", stdout);

int dp[500][500];
int sum[500];

int getsum(int l,int r){
  return (sum[r]-sum[l-1]);
}

signed main(){
  //input_from_file;
  int n; cin>>n;
  vector<int> v(n+1);
  for(int i=1;i<=n;i++) cin>>v[i];
  for(int i=1;i<=n;i++) sum[i] = sum[i-1]+v[i];
  for(int len=1;len<=n;len++)
  for(int left=1;left<=n;left++){
    int right = left+len-1;
    if(right > n) continue;
    if(left == right) dp[left][right] = 0;
    else if(left+1 == right) dp[left][right] = v[left]+v[right];
    else{
         int cost = 1e15;
         for(int i=left;i<right;i++)
          cost = min(cost,dp[left][i]+dp[i+1][right]);
         dp[left][right] = cost+getsum(left,right);
    }
  }
  cout<<dp[1][n]<<endl;
}


Measured memory_bytes: 1792
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let it = stdin.lock().bytes().map(|c| c.unwrap() as char);
    let (fs, ft) = (|c: &char| c.is_whitespace(), |c: &char| !c.is_whitespace());
    let token = it.skip_while(fs).take_while(ft).collect::<String>();
    token.parse().ok().unwrap()
}
#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    f(std::io::BufWriter::new(out.lock()));
}
#[allow(unused_macros)]
macro_rules! debug {
    ($($var:expr),*) => { #[cfg(debug_assertions)] {
        $({ match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } })*
        eprintln!();
    }};
}

fn main() {
    let n: usize = input();
    let k: usize = input();
    let q: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut ans = i32::max_value();
    for &x in &a {
        let mut v = vec![];
        let mut t = vec![];
        for i in 0..n {
            if a[i] >= x {
                t.push(a[i]);
            } else {
                if t.len() >= k {
                    t.sort();
                    v.extend(t.iter().cloned().take(t.len() - k + 1));
                }
                t.clear();
            }
        }
        if t.len() >= k {
            t.sort();
            v.extend(t.iter().cloned().take(t.len() - k + 1));
        }
        if v.len() >= q {
            v.sort();
            let u: Vec<i32> = v.iter().cloned().take(q).collect();
            ans = std::cmp::min(ans, u[q - 1] - u[0]);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll dp[1 << 20];
int main() {
	ll sum = 0;
	int n; cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	dp[0] = 1;
	ll out = 0;
	rep(i, n-1) {
		dp[i] += sum; dp[i] %= mod;
		if (i > 1) {
			dp[i] -= dp[i - 2]; dp[i] = (dp[i] + mod) % mod;
		}
		out = (out + dp[i] * (n - 1) % mod*(n - 1) % mod)%mod;
		out = (out + (n+1-max(2,n-i-1))*dp[i]%mod)%mod;
		sum += dp[i]; sum %= mod;
	}
	if (n > 2) {
		sum -= dp[n - 3]; sum = (sum + mod) % mod;
	}
	cout << (out + sum*n) % mod << endl;
	return 0;
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int32_t main(){
	IOS;
	int tt = 1; 
	//cin >> tt;
	while(tt--){
		int n,k; cin >> n >> k;
		int A[n];
		for(int i = 0; i < n; i++) cin >> A[i];
		sort(A, A+ n);
		int sum = 0;
		for (int i = 0; i < k; i++)
		{
			sum += A[i];
		}
		cout << sum ;
		
	
	}
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using uint = uint32_t;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * n; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)


struct Edge{ uint32_t to, id; };
typedef vector<vector<Edge>> Graph;
struct Articulation {
	typedef uint32_t T;
	explicit Articulation(const Graph & g) : is_art(g.size(), 0) {
		T n = g.size(), k = 0;
		vector<T> ord(n, 0), low(n);
		function<void(T, T, T)> dfs = [&](T c, T p, T id) {
			ord[c] = low[c] = ++k;
			for (auto e : g[c]) {
				if (!ord[e.to]) {
					dfs(e.to, c, e.id);
					low[c] = min(low[c], low[e.to]);
					if (ord[c] == 1 && ord[e.to] != 2) is_art[c] = 1;
					if (ord[c] != 1 && ord[c] <= low[e.to]) is_art[c] = 1;
				} else if (e.id != id) {
					low[c] = min(low[c], ord[e.to]);
				}
			}
		};
		for (T i = 0; i < n; ++i) if (!ord[i]) dfs(i, n, T(-1));
	}
	vector<bool> is_art;
};

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	uint n, m; cin >> n >> m;
	Graph g(n);
	REP(i, m){
		uint s, t; cin >> s >> t;
		g[s].push_back({t, i});
		g[t].push_back({s, i});
	}
	Articulation art(g);
	REP(i, art.is_art.size()) if(art.is_art[i]) {
		cout << i << endl;
	}
}

Measured memory_bytes: 5428
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,n,ans=-INF;
  cin >> a >> b >> n;
  ll x=min(b-1,n);
  cout << floor(a*x/b)-a*floor(x/b) << endl;
}

Measured memory_bytes: 3804
INF = 10**9 + 1
cnt = 0


def merge(A, left, mid, right):
    global INF, cnt
    L = []
    R = []
    for i in range(left, mid):
        L.append(A[i])
    L.append(INF)
    for i in range(mid, right):
        R.append(A[i])
    R.append(INF)

    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1


def merge_sort(A, left, right):
    # range: [left, right)
    if right - left <= 1:
        return
    mid = (left + right) / 2
    merge_sort(A, left, mid)
    merge_sort(A, mid, right)
    merge(A, left, mid, right)


if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    merge_sort(A, 0, n)
    for x in A:
        print x,
    print
    print cnt


Measured memory_bytes: 48208
n = int(input())
p = list(map(int, input().split()))

def checkP(int1, int2, int3):
  l = [int1, int2, int3]
  l.sort()
  if l[1] == int2:
    return True
  else:
    return False

ans = 0

for i in range(1, n-1):
  if checkP(p[i-1], p[i], p[i+1]):
    ans +=1
  else:
    pass

print(ans)

Measured memory_bytes: 9084
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
 
namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var dic = new Dictionary<int, int>();
            
            for (int i= 0; i < n; ++i)
            {
                dic.Add(i,int.Parse(Console.ReadLine()));
            }
            int maxProf = dic[1] - dic[0];
            int min = dic[0];
            for (int i = 0; i < n-1; ++i)
            {
                min = min < dic[i] ? min : dic[i];
                maxProf = maxProf > dic[i+1] - min ? maxProf : dic[i+1] - min;
            }
            Console.WriteLine(maxProf);
        }
  
    }
}

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

using namespace std;

using ll = long long;

ll lcm(ll c, ll d){
    return c * d / __gcd(c, d);
}

int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ans = b - a + 1;
    ans -= (b / c - (a - 1) / c);
    ans -= (b / d - (a - 1) / d);
    ans += (b / lcm(c, d) - (a - 1) / lcm(c, d));
    cout << ans;
    return 0;
}


Measured memory_bytes: 256