akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

int main(void){
    char s[200005];
    scanf("%s", s);
    int len = strlen(s);
    int a;
    int z;
    for (int i = 0; i < len; i++){
        if (s[i] == 'A'){
            a = i;
            break;
        }
    }
    for (int i = len-1; i >= 0; i--){
        if (s[i] == 'Z'){
            z = i;
            break;
        }
    }
    printf("%d\n", z-a+1);
    
}



Measured memory_bytes: 384
N,M = map(int,input().split())
l = []
for i in range(M):
	p,y = map(int,input().split())
	l.append([p,y,i])
l.sort()
p = -1
n = 1
for i in range(M):
	if l[i][0] == p:
		n += 1
		l[i][1] = n
	else:
		n = 1
		l[i][1] = n
	p = l[i][0]
for i in range(M):
	l[i][0],l[i][1],l[i][2]=l[i][2],l[i][0],l[i][1]
l.sort()
for i in range(M):
	print('0'*(6-len(str(l[i][1])))+str(l[i][1])+'0'*(6-len(str(l[i][2])))+str(l[i][2]))

Measured memory_bytes: 24480
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <cassert>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

string check(vector<string> b){
	cout << b[0] << endl;
	cout << b[1] << endl;
	string res;
	cin >> res;
	if( res == "end") exit(0);
	return res;
}


int main(){
	srand(time(NULL));
	int N;
	cin >> N;
	set<vector<string> > used;

	vector<string> c(2);
	int rev = 0;
	while(true){
		if( !rev ){
			vector<vector<string>> lst;
			for(int k = 0 ; k < 4 ; k++){
				vector<string> b = {c[0],c[1]};
				b[0] += (k>>0&1?".":"#");
				b[1] += (k>>1&1?".":"#");
				lst.push_back(b);
			}
			int f = 0;
			for(int i = 0 ; i < 4 ; i++){
				if( check(lst[i]) == "T" ){
					c = lst[i];
					f = 1;
					break;
				}
			}
			if( !f ){
				rev = 1;
			}
		}

		if( rev ){
			vector<vector<string>> lst;
			for(int k = 0 ; k < 4 ; k++){
				vector<string> b = {c[0],c[1]};
				b[0] = (k>>0&1?".":"#") + b[0];
				b[1] = (k>>1&1?".":"#") + b[1];
				lst.push_back(b);
			}
			int f = 0;
			for(int i = 0 ; i < 4 ; i++){
				if( check(lst[i]) == "T" ){
					c = lst[i];
					f = 1;
					break;
				}
			}			
		}
	}




}





























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


void solve(std::string S){
    for (int i = 0; i < S.size(); i++)
    {
        cout << "x";
    }
    cout << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n,int k) {
	//nのk桁目
	rep(i, k-1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N;
	string ans = "Yes";
	cin >> N;
	vector<string>W(N);
	cin >> W[0];
	REP(i, N-1) {
		cin >> W[i];
		if (LAST(W[i - 1]) != W[i][0])
			ans = "No";
		rep(j, i) {
			if (W[j] == W[i] && i != j)
				ans = "No";
		}
	}
	cout << ans;
}


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

int main(){
	long x,y,z,i,h=0,j=0,sum,K,yeah=3000;//���
	cin >> x >> y >> z >> K;
	vector<long> A(x);for(i=0;i<x;i++){
		cin >> A[i];
		
	}
	vector<long> B(y);for(i=0;i<y;i++){
		cin >> B[i];
	}
	vector<long> C(z);for(i=0;i<z;i++){
		cin >> C[i];
	}
	sort(A.begin(),A.end(),greater<long>());//�\�[�g
	sort(B.begin(),B.end(),greater<long>());
	sort(C.begin(),C.end(),greater<long>());
	i=0;
	vector<long> D(x*y);
	for(i=0;i<x;i++){//A��B�𑫂�
		for(h=0;h<y;h++){
			D[y*i+h]=A[i]+B[h];
			//cout << D[y*i+h] << endl;
		}
	}
	sort(D.begin(),D.end(),greater<long>());
	vector<long> E(3000*z);
	if(yeah>x*y)yeah=x*y;
	for(i=0;i<yeah;i++){
		for(h=0;h<z;h++){
			E[z*i+h]=D[i]+C[h];
			//cout << E[z*i+h] << endl;
		}
	}
	sort(E.begin(),E.end(),greater<long>());
	for(i=0;i<K;i++){
		cout << E[i] << endl;
	}
	return 0;
 }

Measured memory_bytes: 31616
package main

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

func main() {
	N := nextInt()

	for {
		strN := fmt.Sprint(N)
		diffRune := rune(strN[0])
		isSame := true
		for _, r := range strN {
			if diffRune != r {
				isSame = false
				break
			}
		}
		if isSame {
			break
		}

		N++
	}

	fmt.Println(N)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

long long dp[52][5004];

int main(){
  int N, A;
  scanf("%d", &N);
  scanf("%d", &A);
  std::vector<long long > x(N);
  for (int i=0; i<N; i++){
    scanf("%lld", &x[i]);
    x[i] -= A;
  }
  dp[0][2500]=1;
  for (int i=0; i<N; i++){
    for (int j=0; j<5004; j++){
      dp[i+1][j] += dp[i][j];
      if (j+x[i] >=0 && j+x[i]<=5000){
        //if (dp[i][j]>0) printf("dp[%d][%lld] += dp[%d][%d]\n", i+1, j+x[i], i, j);
        dp[i+1][j+x[i]] += dp[i][j];
      }
    }
  }
  long long ans = 0;
  for (int i=1; i<=N; i++){
    ans += dp[i][2500];
    //printf("dp[%d][2500]=%lld\n", i, dp[i][2500]);
  }
  std::cout << dp[N][2500]-1 << std::endl;
  return 0;
}

Measured memory_bytes: 5212
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>
#include <tuple>

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (ll (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (ll (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (ll (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (ll (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline '\n'

#define test if(1)if(0)cerr
using namespace std;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;

const int maxn = 1e3+1;
vector<l4> g[maxn];
int n, m;
ll d[maxn];
bool vis[maxn];
struct Edge
{
    ll a, b, c;
};
vector<Edge> E;
int main()
{
    cin >> n >> m;
    rep(i, m)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        E.pb((Edge){a, b, c});
    }
    Reset(vis, false);
    vis[1] = 1;
    d[1] = 0;
    bool change = false;
    bool lastchange = false;
    rep(i, n)
    {
        change = false;
        lastchange = false;
        for (auto e : E)
        {
            if (!vis[e.a])
            {
                continue;
            }
            ll nxtd = d[e.a] + e.c;
            if (!vis[e.b] || nxtd > d[e.b])
            {
                vis[e.b] = true;
                d[e.b] = nxtd;
                change = true;
                if (e.b == n)
                {
                    lastchange = true;
                }
            }
        }
        if (!change)
        {
            break;
        }
    }
    
    if (lastchange)
    {
        cout << "inf\n";
    }
    else
    {
        cout << d[n] << newline;
    }
    
    
    
}

Measured memory_bytes: 384
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = 10 ** 18


def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return

    answer = 1
    for i in range(N):
        answer *= A[i]
        if answer > INF:
            print(-1)
            return

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22328
N=int(input())
Prime=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
Pdict=dict()
D=dict()
X=[0 for i in range(25)]
for i in range(25):
    D[Prime[i]]=0
    Pdict[Prime[i]]=i
for i in range(1,N+1):
    k=i
    for p in Prime:
        while(True):
            if k%p==0:
                k=k//p
                D[p]+=1
            else:
                break
for i in range(25):
    X[i]=D[Prime[i]]
ans=0
for i in range(25):
    for j in range(25):
        for k in range(25):
            if i==j or j==k or k==i:
                continue
            if X[i]>=4 and X[j]>=4 and X[k]>=2:
                #pi^4*pj^4*pk^2
                if i<j:
                    ans+=1
for i in range(25):
    for j in range(25):
        if i==j:
            continue
        if X[i]>=24 and X[j]>=2:
            #pi^24*pj^2
            ans+=1
for i in range(25):
    for j in range(25):
        if i==j:
            continue
        if X[i]>=14 and X[j]>=4:
            #pi^14*pj^4
            ans+=1
for i in range(25):
    if X[i]>=74:
        #pi^74
        ans+=1

print(ans)

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

int main() {
    int N;
    cin >> N;
    int m = N/2;
    int A[N], B[N];
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i] - (i+1);
    }
    sort(B, B+N);

    ll ans = 0;
    rep(i, N) {
        ans += (ll)abs(B[i] - B[m]);
    }

    cout << ans;    

    cout << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
using namespace std;
 
int main(){

  long long int n;
  cin >> n;

  cout << 48-n << endl;

  return 0;
}

Measured memory_bytes: 764
#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 < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
double pi = 3.1415926535;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);

int n;

signed main(){
    cin >> n;
    vector<vector<P>> a(n,vector<P>());
    REP(i,n){
        int t;
        cin >> t;
        REP(j,t){
            int x,y;
            cin >> x >> y;
            x--;
            a[i].push_back(P(x,y));
        }
    }
    int ans1 = 0;
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(i);
            }
        }
        bool ans = true;
        //Debug(S);
        //S内の人物が全て正しい
        REP(i,S.size()){
            REP(j,a[S[i]].size()){
                P p = a[S[i]][j];
                //cout << p.first << " " << p.second << endl;
                if(p.second == 1){
                    int itr = nibul(S,p.first);
                    if(S[itr] != p.first || itr == S.size()){
                        ans = false;
                    }
                }
                else{
                    int itr = nibul(S,p.first);
                    if(S[itr] == p.first){
                        ans = false;
                    }
                }
                //print(ans);
            }
        }
        if(ans){
            ans1 = max(ans1,(int)S.size());
        }
    }
    print(ans1);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


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

typedef long long ll;

int main(){
	static int A,B,M;
	static int a[100010],b[100010],x[100010],y[100010],c[100010];
	scanf("%d%d%d",&A,&B,&M);
	for(int i=1;i<=A;i++)scanf("%d",&a[i]);
	for(int i=1;i<=B;i++)scanf("%d",&b[i]);
	for(int i=1;i<=M;i++)scanf("%d%d%d",&x[i],&y[i],&c[i]);
	
	int ma=100000,mb=100000;
	for(int i=1;i<=A;i++)ma=min(ma,a[i]);
	for(int i=1;i<=B;i++)mb=min(mb,b[i]);
	int ret=ma+mb;
	for(int i=1;i<=M;i++){
		ret=min(ret,a[x[i]]+b[y[i]]-c[i]);
	}
	cout<<ret<<endl;
}



Measured memory_bytes: 2176
use std::io;
use std::str::FromStr;
use std::collections::VecDeque;

type Point = (i32, i32);

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

fn input_int_tuple() -> (i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let n: i32 = input();
    let mut red_vec: Vec<Point> = Vec::new();
    for i in 0..n {
        let point: Point = input_int_tuple();
        red_vec.push(point);
    }
    red_vec.sort_by(|n, m| m.0.cmp(&n.0));

    let mut blue_vec: Vec<Point> = Vec::new();
    for i in 0..n {
        let point: Point = input_int_tuple();
        blue_vec.push(point);
    }
    blue_vec.sort_by(|n, m| n.0.cmp(&m.0));

    let mut count = 0;
    for red in red_vec {
        let mut idx: usize = 1000;
        for i in 0..blue_vec.len() {
            if blue_vec[i].0 > red.0 {
                idx = i as usize;
                break;
            }
        }
        if idx == 1000 {
            continue;
        }
        let mut min = 1000;
        let mut min_idx = 0;

        for i in idx..blue_vec.len() {
            if blue_vec[i].1 > red.1 {
                if blue_vec[i].1 < min {
                    min_idx = i;
                    min = blue_vec[i].1;
                }
            }
        }
        if min != 1000 {
            count += 1;   
            blue_vec.remove(min_idx);
        }
    }
    println!("{}", count);
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
int n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    ll res=0;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j+=i) res+=j;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3196
#include <iostream>
using namespace std;
typedef long long ll;
int a[101][101];
ll dp[101][101];
int N;
int main(){
  cin>>N;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      cin>>a[i][j];
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]+a[i][j];
  ll res=-(1LL<<30);
  for(int miny=0;miny<N;miny++){
    for(int minx=0;minx<N;minx++){
      for(int maxy=miny;maxy<N;maxy++){
        for(int maxx=minx;maxx<N;maxx++){
          res=max(res,dp[maxy+1][maxx+1]-dp[miny][maxx+1]-dp[maxy+1][minx]+dp[miny][minx]);
        }
      }
    }
  }
  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll h,m;
  cin >> h >> m;
  ll s=h*60+m;
  cin >> h >> m;
  ll g=h*60+m;
  ll k;
  cin >> k;
  cout << g-s-k << endl;
}

Measured memory_bytes: 3588
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect


def gcd(a, b):
    """最大公約数"""
    a, b = (a, b) if a >= b else (b, a)
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    """最小公倍数"""
    # from math import gcd
    return (a * b) // gcd(a, b)


# from decorator import stop_watch
#
#
# @stop_watch
def solve(A, B):
    print(lcm(A, B))


if __name__ == '__main__':
    A, B = map(int, input().split())
    solve(A, B)


Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int


def get_fraction_mod(numerator, denominator):
    '''
        returns numerator / denominator (mod MOD)
    '''
    inv = pow(denominator, MOD - 2, MOD)
    return numerator * inv % MOD

def make_comb(n, k):
    k = min(k, n - k)
    a = 1
    b = 1
    for i in range(k):
        a = a * (n - i) % MOD
        b = b * (i + 1) % MOD
    ret = get_fraction_mod(a, b)
    return ret

def make_facts(n):
    '''
        make factorials
        0!(=1), 1!, 2!, 3! .... n!
    '''
    fact = [1]
    for i in range(n):
        fact.append((fact[i] * (i + 1)) % MOD)
    return fact


def make_combs(n, k):
    '''
        make [C(n, 0), C(n, 1), C(n, 2) ..... C(n, k)]
        n! / (n - k)! k!
    '''
    facts = make_facts(n)
    invs = [] # inverted for fraction
    for fact in facts:
        invs.append(pow(fact, MOD - 2, MOD))

    ret = []
    for i in range(0, n + 1):
        a = facts[n]
        ret.append(a * invs[i] * invs[n - i] % MOD)
    return ret

def _solve(n):
    dp = [0] * (n + 1)

def solve(n: int, k: int):
    ret = make_comb(n * 2 - 1, n)
    if k < n - 1:
        combs = make_combs(n - 1, n - 1)
        n_combs = make_combs(n, n)
        for i in range(k + 1, n):
            #tmp = make_comb(n, i)
            tmp = n_combs[i]
            t = combs[n - i - 1]
            ret -= tmp * t
            ret %= MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(n, k)

if __name__ == '__main__':
    main()


Measured memory_bytes: 34824
var lines = [];

var readline = require("readline");
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on("line", function (x) {
    lines.push(x);
});

rl.on("close", function () {

    var N = Number(lines[0].split(" ")[0])
    var K = Number(lines[0].split(" ")[1])
    var V = lines[1].split(" ").map(i => Number(i))

    var result_l = [];
    var ans = 0;

   
    for (var left = 0; left <= Math.min(N, K); left++) {
        // leftが0の時、一個も宝石を取得しない
        if (1 <= left) { result_l.push(V[left - 1]) }
        var result_r = result_l.concat();

        for (var right = 0; left + right <= Math.min(N, K); right++) {
            // rightが0の時、一個も宝石を取得しない
            if (1 <= right) { result_r.push(V[V.length - 1 - right + 1]) }
            var result_t = result_r.concat();
            result_t.sort((a, b) => a - b);

            var trash = K - (left + right);
            for (var index = 0; index < trash; index++) {
                if (result_t[0] < 0) { result_t.shift() }
                else { break; }
            }

            var t = 0;
            for (var index = 0; index < result_t.length; index++) { t += result_t[index]; }
            ans = Math.max(ans, t)

            // console.log(left, right, trash, result_t, ans)
        }
    }
    console.log(ans);

});

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

int main() {
  long long n,k;
  cin>>n>>k;
  long long a=0;
  long long b=0;
  for(long long i=1;i<=n;i++){
    if(i%k==0) a++;
    if(i%k==k/2) b++;
  }
  long long ans=a*a*a;
  if(k%2==0) ans+=b*b*b;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;


int main() {

    int H,N;
    cin >> H >> N;
    int A[N];

    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        ans = ans + A[i];
    }
    //cout << ans << endl;
    if(ans>=H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N=200100;
vector<int> g[N];
char s[N];
bool ban[N],ba[N],in[N];
int d[N],fa[N],vis[N],num[N][2];
bool fl=0;
int cnt;
int find(int x){
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
void unite(int x,int y){
	if (find(x)!=find(y))
	fa[find(x)]=find(y);
}
bool dfs(int x){
	//cerr<<"dfs"<<x<<" "<<s[x]<<endl;
	vis[x]=1;
	if (ban[x]) return 1;
	bool fl1=0;
	for (size_t j=0; j<g[x].size(); ++j) if (g[x][j]=='A'&&dfs(g[x][j])) fl1=1;
	if (!fl1) return 0;
	for (size_t j=0; j<g[x].size(); ++j) if (g[x][j]=='B'&&dfs(g[x][j])) return 1;
}
int main(){
	int n,m; scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for (int i=1; i<=m; ++i){
		int x,y; scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		++num[x][s[y]=='B'];
		++num[y][s[x]=='B'];
	}
	queue<int> q;
	for (int i=1; i<=n; ++i) if (num[i][0]==0||num[i][1]==0) q.push(i),in[i]=1;
	while (!q.empty()){
		int x=q.front(); q.pop();
		for (auto i:g[x])
			if (!in[i]&&!--num[i][s[x]=='B']){
				q.push(i);
				in[i]=1;
			}
	}
	for (int i=1; i<=n; ++i) if (!in[i]) return puts("Yes"),0;
	puts("No");
}


Measured memory_bytes: 14848
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		int ans = 0;
		while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
			int tempA = B / 2 + C / 2;
			int tempB = A / 2 + C / 2;
			int tempC = A / 2 + B / 2;
			if(A == tempA && B == tempB && C == tempC) {
				System.out.println(-1);
				return;
			}
			ans++;
			A = tempA;
			B = tempB;
			C = tempC;
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;


int main() {fio;
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector <int> ax(A), bx(B), cx(C);
	for(int i = 0; i < A; i++) {
		int u;
		cin >> u;
		ax[i] = u;
	}
	for(int i = 0; i < B; i++) {
		int u;
		cin >> u;
		bx[i] = u;
	}
	for(int i = 0; i < C; i++) {
		cin >> cx[i];
	}
	sort(all(ax), greater <int> ());
	sort(all(cx), greater <int> ());
	sort(all(bx), greater <int> ());
	vector <ll> f;
	for(int i = 0; i < X; i++) {
		f.push_back(ax[i]);
	}
	for(int i = 0; i < Y; i++) {
		f.push_back(bx[i]);
	}
	ll ans = accumulate(all(f), 0LL);
	sort(all(f));
	for(int i = 0; i < min(cx.size(), f.size()); i++) {
		ans += max(cx[i] - f[i], 0LL);
	}
	cout << ans;
	return 0;	
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi 3.14159265358979323846
#define fr(i,a,b) for (ll i=a; i<(b);++i)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);--i)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define lsOne(S) (S & (-S))
#define isbitset(S, i) ((S >> i) & 1)
#define sz(a) (ll)a.size()
#define po(a,b) (ll)(pow(a,b)+0.5)
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
const ll M=1e18+7;
const ll MOD=1e9+7;
const int MX=2e5+5;



void solve()
{
  ll ans;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ans=max({a*c,a*d,b*c,b*d});
  cout<<ans<<endl;
  
}




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int t=1;
    //cin >> t;
    while(t--) {

        solve();
    }
    return 0;
}









Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#define N 500005
typedef long long ll;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
   double x=(a+b)/2.0;
   int y=(a+b)/2;
   if (x>=y+0.5)
      cout << y+1 << endl;
   else
    cout << y << endl;

     return 0;
}


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

namespace CSharpSample01
{


    class Program
    {
        
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);
            int X = int.Parse(input[3]);
            int Y = int.Parse(input[4]);

            long cost = 0;
            if(C * 2 <= (A + B))
            {
                if(Y <= X)
                {
                    cost += (C * 2) * Y;
                    X -= Y;
                    if(A > C * 2) cost += X * C * 2;
                    else cost += A * X;
                }
                else
                {                 
                    cost += (C * 2) * X;                    
                    Y -= X;
                    if (B > C * 2) cost += Y * C * 2;
                    else cost += B * Y;
                }
            }
            else
            {
                cost += (A * X + B * Y);
            }

            Console.WriteLine(cost);

        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
// const int N = ;
using ll = long long;
using ii = pair <int , int>;
int k,n;

int main() {
	scanf("%d%d" , &k , &n);
	vector <int> v(n);
	for (int i = 0 ; i < n ; i++) {
		scanf("%d" , &v[i]);
	}
	int sol = INT_MAX;
	for (int i = 0 ; i < n ; i++) {
		int l,r;
		if (i == n - 1) {
			l = k - (abs(v[i] - k) + v[0]);
			r = k - abs(v[i] - v[i - 1]);
		} else if (i == 0) {
			l = k - abs(v[i] - v[i + 1]);
			r = k - (v[i] + abs(k - v[n - 1]));
		} else {
			l = k - abs(v[i] - v[(i + 1) % n]);
			r = k - abs(v[i] - v[(i + n - 1) % n]);
		}
		sol = min(sol , min(l , r));
	}
	printf("%d\n" , sol);
	return 0;
}


Measured memory_bytes: 1024
a=input().split(' ')
A=int(a[0])
B=int(a[1])
K=int(a[2])
if B-A+1<=K*2:
  for i in range(A,B+1):
    print(i)
else:
  for i in range(K):
    print(A+i)
  for i in range(K):
    print(B-K+1+i)
    

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main(){	
	long long a,b,n,r;	
	cin>>a>>b>>n;
	if(n<b){
		r=n;
	}else{
		r=b-1;	
	}
	cout<<r*a/b<<endl;	
	return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, M;
  cin >> N >> M;
  long ans = 1;
  for(long i = 1; i <= sqrt(M); i++){
    if(M % i == 0){
      if(M / i >= N) ans = max(i, ans);
      if(i >= N)ans = max(M / i, ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <bitset>
using namespace std;
const int N=1e5+10;
#define PB push_back
int a[N],p[N];
vector<int> graph[N];
bitset<N> went;
void dfs(int now){
    went[now]=true;
    for(int i:graph[now])if(!went[i]){
        if(a[i]>1)a[i]--;
        else p[i]=now;
    }
    for(int i:graph[now])if(p[i]==now)dfs(i);
    return ;
}
int main(){
    int n,m,l,r;
    scanf("%d%d",&n,&m);
    went.reset();
    for(int i=1;i<=n;i++)a[i]=0;
    m+=n-1;
    while(m--){
        scanf("%d%d",&l,&r);
        graph[l].PB(r);
        a[r]++;
    }
    for(int i=1;i<=n;i++)if(a[i]==0){
        p[i]=0;
        dfs(i);
        break;
    }
    for(int i=1;i<=n;i++)printf("%d\n",p[i]);
}

Measured memory_bytes: 10240
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    int cnt=0;
    cin >> a >> b >>c;
    for (int i=a; i<b+1; i++){
        if (c%i==0){
            cnt+=1;
        }
    }
    cout << cnt <<endl;
    
}


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

int main()
{
int a,b;scanf("%d %d",&a,&b);
int num;string ans="No";
if(b<10)num=a*10+b;
else if(b<100)num=a*100+b;
else num=a*1000+b;
for(int i=4;i<317;i++)if(i*i==num)ans="Yes";
printf("%s\n",ans.c_str());
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
    n = int(input())
    adj = [[]] * n
    for _ in range(0, n):
        U = list(map(int, input().split()))
        adj[U[0]] = zip(U[2::2], U[3::2])
    def dijkstra():
        d = [0] + [INF] * (n - 1)
        hq = [(0, 0)]
        while hq:
            u = heappop(hq)[1]
            for v, c in adj[u]:
                alt = d[u] + c
                if d[v] > alt:
                    d[v] = alt
                    heappush(hq, (alt, v))
        print("\n".join(" ".join(map(str, (i, c))) for i, c in enumerate(d)))
    dijkstra()
MAIN()



Measured memory_bytes: 40028
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
struct era{
  ll s,e;
  string name;
  bool operator<(const era&e)const{
    return s < e.s;
  }
};
int main(){
  ll n,q;
  int i,j,k;
  era e;
  string str;
  ll b,w;
  cin >> n >> q;
  while(n+q!=0){
    vector<era> v;
    for(i=0;i<n;i++){
      cin >> str >> b >> w;
      e.name=str;
      e.s=w-b+1;e.e=w;
      //cout << e.s << " " << e.e  << endl;
      v.push_back(e);
    }
    sort(v.begin(),v.end());
    for(i=0;i<q;i++){
      cin >> b;
      ll st=0,en=v.size(),no;
      no=(st+en)/2;
      for(j=0;j<100;j++){
	if(v[no].s<=b&&b<=v[no].e) break;
	if(v[no].s<=b) st = no;
	else en=no;
	no=(st+en)/2;
      }
      //cout << v[no].s << " " << v[no].e  << endl;
      if(v[no].s<=b&&b<=v[no].e) cout << v[no].name <<" "<<  (b-v[no].s+1) << endl;
      else cout << "Unknown" << endl;
    }
    
    cin >> n >> q;
  }
  return 0;
}

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

static const int MAX_ST = 100;
static const int INFTY  = ( 1 << 20 );

pair< int, int > AdjMt[MAX_ST][MAX_ST];	// UndirectedGraph | first : cost, second : time

int Min( const int& left, const int& right ) { return left > right ? right : left; }

int main()
{

	ios::sync_with_stdio( false );	// for speeding up

	int  info_n, sta_n, query_n, depplc, dest, cost, time;
	bool query_meth;

	while( cin >> info_n >> sta_n, info_n || sta_n ) {

		for( int i = 0; i < MAX_ST; i++ ) {
			for( int j = 0; j < MAX_ST; j++ ) AdjMt[i][j].first = AdjMt[i][j].second = INFTY;
		}

		for( int i = 0; i < info_n; i++ ) {

			cin >> depplc >> dest >> cost >> time;
			AdjMt[--depplc][--dest].first = AdjMt[dest][depplc].first  = cost;
			AdjMt[depplc][dest].second    = AdjMt[dest][depplc].second = time;

		}

		// Warshall-Floyd
		for( int k = 0; k < sta_n; k++ ) {
			for( int i = 0; i < sta_n; i++ ) {
				if( AdjMt[i][k].first == INFTY ) continue;
				for( int j = 0; j < sta_n; j++ ) {

					AdjMt[i][j].first  = Min( AdjMt[i][j].first , AdjMt[i][k].first  + AdjMt[k][j].first );
					AdjMt[i][j].second = Min( AdjMt[i][j].second, AdjMt[i][k].second + AdjMt[k][j].second );

				}
			}
		}

		cin >> query_n;
		for( int i = 0; i < query_n; i++ ) {

			cin >> depplc >> dest >> query_meth;
			depplc--; dest--;
			cout << ( !query_meth ? AdjMt[depplc][dest].first : AdjMt[depplc][dest].second ) << endl;

		}

	}

	return 0;

}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
// 1次元 vector
template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << " ";
        }
        s << vec[i];
    }
    return s << endl;
}
using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

struct Range {
    vector<int> val;
    Range();
    Range(const vector<int> &a, int l, int r) {
        for (int i = l; i < r; i++) {
            val.push_back(a[i]);
        }
    }
};

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<int> S = A;
    sort(ALL(S));

    vector<Range> ranges;
    ranges.push_back(Range(A, 0, N));
    int ans = INF;
    for (int yid = 0; yid < N; yid++) {
        int Y = S[yid];

        vector<Range> next;
        for (auto range : ranges) {
            int now = 0;
            for (int i = 0; i < (int)range.val.size(); i++) {
                if (range.val[i] < Y) {
                    //cout << Range(range.val, now, i).val;
                    if (now != i) next.push_back(Range(range.val, now, i));
                    now = i + 1;
                }
            }
            if (now != (int)range.val.size()) next.push_back(Range(range.val, now, (int)range.val.size()));
        }
        ranges = next;

        vector<int> can;
        for (auto range : ranges) {
            sort(ALL(range.val));
            for (int i = 0; i < (int)range.val.size() - K + 1; i++) {
                can.push_back(range.val[i]);
            }
        }
        sort(ALL(can));
        if ((int)can.size() >= Q) {
            //cout << can[Q - 1] << " " << Y << endl;
            chmin(ans, can[Q - 1] - Y);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

constexpr ll mod = 998244353LL;

// aのb乗を求める.
ll modpow(ll a, ll b) {
	if (a > mod) a %= mod;
	if (b == 0LL) return 1LL;
	ll tmp = modpow(a, b / 2);
	if (b & 1LL)
		return tmp * tmp % mod * a % mod;
	return tmp * tmp % mod;
}

// aの逆元を求める.
ll inverse(ll a) {
	return modpow(a, mod - 2);
}

// 与えられた数列xに対し、
//  y_k = \sum_{i mod k = 0} x_i
// なる変換を行う
void _convert(vector<ll>& x){
    const int sz = x.size();
    for (int k = 1; k < sz; ++k)
        for (int i = k * 2; i < sz; i += k)
            x[k] = (x[k] + x[i]) % mod;
}

// 上記の変換の逆変換を行う
void _inverse(vector<ll>& x){
    const int sz = x.size();
    for (int k = sz - 1; k >= 1; --k)
        for (int i = k * 2; i < sz; i += k)
            x[k] = (x[k] - x[i] + mod) % mod;
}

// 与えられた数列a, bに対し、gcd畳み込みを行う
// すなわち
//  c_k = \sum_{gcd(i, j)=k} a_i \times b_j
// を求める
vector<ll> gcd_convolution(vector<ll> a, vector<ll> b){
    _convert(a); _convert(b);
    vector<ll> c(max(a.size(), b.size()));
    for (int i = 0; i < c.size(); ++i)
        c[i] = (i < (int)a.size() ? a[i] : 0LL) * (i < (int)b.size() ? b[i] : 0LL) % mod;
    _inverse(c);
    return c;
}

#define MAX_A (1000000)

int main(void){
    int N; cin >> N;
    vector<ll> A(N);
    vector<ll> cnt(MAX_A + 1, 0LL);
    for (int i = 0; i < N; ++i){
        cin >> A[i];
        cnt[A[i]]++;
    }
    for (int i = 0; i <= MAX_A; ++i)
        cnt[i] = cnt[i] * i % mod;
    vector<ll> gcd_conv = gcd_convolution(cnt, cnt);
    ll res = 0;
    for (int g = 0; g <= MAX_A; ++g)
        res = (res + gcd_conv[g] * inverse(g) % mod) % mod;
    for (auto Ai : A)
        res = (res - Ai + mod) % mod;
    res = res * inverse(2) % mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 33024
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
int n;
string s;

int main(void){
	cin>>n>>s;
	int cnt=0,sum=0;
	REP(i,n)if(s[i]=='R')cnt++;
	REP(i,cnt)if(s[i]=='W')sum++;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0;i<s.size();i++){
    int cnt = 0;
    for(int j = i;s[j] == 'A' ||s[j] == 'G' ||s[j] == 'T' ||s[j] == 'C';j++){
      cnt++;
      i=j;
    }
    ans = max(cnt,ans);
  }
  cout << ans << endl;
  return 0;
}

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

int x[55], y[55], a[55], b[55];

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

    for (int i = 0; i < n; i++)
    {
        pair<int,int> ans{(int)1e9,(int)1e9};
        for (int j = 0; j < m; j++)
        {
            int dist=abs(x[i]-a[j])+abs(y[i]-b[j]);
            ans = min(ans, make_pair(dist,j));
        }
        cout<<ans.second+1<<endl;
    }
}


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

using namespace std;
struct Node{
    int key;
    Node *parent, *left, *right;
};

Node *root=NULL, *NIL=NULL;

void Preorder(Node *root) {
    if ( root != NIL ) {
    cout << " " << root->key;
    Preorder(root->left);
    Preorder(root->right);
   }
}

void Inorder(Node *root) {
    if ( root != NIL ) {
       Inorder( root->left);
      cout << " " << root->key;
       Inorder( root->right);
     }
}

void Postorder(Node *root) {
    if ( root != NIL ) {
       Postorder( root->left);
       Postorder( root->right);
       cout << " " << root->key;
     }
}
void insert(int key) {
	Node *p=new Node;
	p->key=key;
	p->left=NIL;
	p->right=NIL;

	Node *x = root;
	Node *y = NIL;

	while(x != NIL ){
		y=x;
		if ( p->key > x->key ) x = x->right;
		else x = x->left;

	}
    
    p->parent = y;
    if( y == NIL ) root = p;
    else {
    	if ( p->key > y->key ) y->right = p;
    	else y->left = p;
    }

}

bool find(int key) {
    Node *p = root;
    while ( p != NIL && p->key != key ) {
    	if ( p->key > key ) p = p->left;
    	else p = p->right;
    }
    return p != NIL;
}
int main() {
    int n;
    string op;
    int key;

    cin >> n;
    while ( n-- ) {
    	cin >> op;
    	if ( op == "insert" ) {
    		cin >> key;
    		insert(key);
    	} else if ( op == "print" ){
    		Inorder(root);
    		cout << endl;
    		Preorder(root);
    		cout << endl;
    	} else if ( op == "find" ) {
    		cin>>key;
    		if ( find(key) ) cout << "yes" << endl;
    		else cout << "no" << endl;
    	}
    }
	return 0;
}


Measured memory_bytes: 21976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll X, H = 0;
    cin >> X;
    while (X >= 500){
    X -= 500;
    H += 1000;
    }
    cout << H + (X/5) * 5;
    return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int answer = 0;
	for(int i = 1; answer == 0; ++i){
		int c = 0;
		for(int j = 1; j * j <= i; ++j){
			if(i % j == 0){
				++c;
				if(j * j != i){ ++c; }
			}
		}
		if(c == n){ answer = i; }
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n,k; cin >> n >> k;
  vector<int> H;
  for(int i=0;i<n;i++){
    int h; cin >> h;
    H.push_back(h);
  }
  sort(H.begin(),H.end());
  int ans=2e9;
  for(int i=0;i<=n-k;i++){
    int res = H[i+k-1]-H[i];
    ans = min(ans,res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int num[3];
int main() {
	while(1) {
		int a, b; cin>>a>>b;
		if(a==0&&b==0) break;
		swap(a,b);
		if(a<b) cout<<a<<" "<<b<<"\n";
		else cout<<b<<" "<<a<<"\n";
		//cout<<a<<" "<<b<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
    #define rep(i,a,n) for (int i = a;i < n;i++)
    using namespace std;
     
    long long n, a[90]={2,1};
    int main() {
        cin >> n;
        rep(i, 2, n + 1) {
            a[i] = a[i - 1] + a[i - 2];
        }
        cout << a[n] << endl;
    }

Measured memory_bytes: 256