akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int k;
  cin >> k;
  ll a = 0;
  int ans = 0;
  do {
    ans++;
    a *= 10;
    a += 7;
    a %= k;
    if (ans > k) {
      cout << -1 << endl;
      return 0;
    }
  } while (a != 0);
  cout << ans << endl;
  return 0;
}


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

vector<vector<ll>> to;
vector<ll> cnt;

void dfs(ll n,ll p= -1){
	rep(i,to[n].size()){
		if(to[n][i] == p) continue;
		cnt[to[n][i]] += cnt[n];
		dfs(to[n][i],n);
	}
}

int main(){
	ll n,q;
	cin >> n >> q;
	to.resize(n);
	ll a,b;
	rep(i,n-1){
		cin >> a >> b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ll p,x;
	cnt.resize(n);
	rep(i,q){
		cin >> p >> x;
		p--;
		cnt[p] += x;
	}
	dfs(0,-1);
	rep(i,n) cout << cnt[i] << ' ';
	return 0;
}

Measured memory_bytes: 24320
package main

import (
	"fmt"
)

func main() {

	var card [3][3]int
	var hit [3][3]bool
	for i := 0; i < 3; i ++ {
		var a, b, c int
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		card[i][0] = a
		card[i][1] = b
		card[i][2] = c
	}
	var n int
	fmt.Scanf("%d \n", &n)
	for i := 0; i < n; i ++ {
		var b int
		fmt.Scanf("%d\n", &b)
		for i, row := range card {
			for j, num := range row {
				if num == b {
					hit[i][j] = true
				}
			}
		}
	}
	r := "No"
	for _, row := range hit {
		if row[0] && row[1] && row[2] {
			r = "Yes"
		} 	
	}
	if hit[0][0] && hit[1][1] && hit[2][2] {
		r = "Yes"
	}
	if hit[0][2] && hit[1][1] && hit[2][0] {
		r = "Yes"
	}
	if hit[0][0] && hit[1][0] && hit[2][0] {
		r = "Yes"
	}
	if hit[0][1] && hit[1][1] && hit[2][1] {
		r = "Yes"
	}
	if hit[0][2] && hit[1][2] && hit[2][2] {
		r = "Yes"
	}
	fmt.Println(r)
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 18;
const int INF = 1e6 + 239;

int dp[(1 << N)][2 * N + 1];

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

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> sn;
    for (auto &t : a) {
        cin >> t;
        sn.push_back(t);
    }
    for (auto &t : b) {
        cin >> t;
        sn.push_back(t);
    }
    sort(sn.begin(), sn.end());
    sn.resize(unique(sn.begin(), sn.end()) - sn.begin());
    for (auto &t : a) {
        t = lower_bound(sn.begin(), sn.end(), t) - sn.begin() + 1;
        cerr << t << ' ';
    }
    cerr << endl;
    for (auto &t : b) {
        t = lower_bound(sn.begin(), sn.end(), t) - sn.begin() + 1;
        cerr << t << ' ';
    }
    cerr << endl;
    int m = (int)sn.size() + 1;
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
        for (int j = 0; j < m; j++) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (!((mask >> i) & 1)) {
                    int sp = i;
                    int cp = __builtin_popcount(mask);
                    int val = 0;
                    if (abs(sp - cp) & 1) val = b[i];
                    else val = a[i];
                    if (val >= j) {
                        dp[mask | (1 << i)][val] = min(dp[mask | (1 << i)][val], dp[mask][j] + cnt);
                    }
                    cnt++;
                }
            }
        }
    }
    int ans = INF;
    for (int i = 0; i < m; i++) {
        ans = min(ans, dp[(1 << n) - 1][i]);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    // cerr << dp[1 << 1][1] << endl;
}   


Measured memory_bytes: 38272
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int x; cin >> x;
	x -= 400;
	rep(i, 9){
		if(i * 200 <= x && x < 200 + i * 200){
			cout << 8 - i << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3624
import sys
readline = sys.stdin.readline
import math

def main():
    X = int(readline())
    ans = 1
    for b in range(1, math.floor(X**(1/2))+1):
        for p in range(2, 11):
            if b ** p <= X:
                ans = max(ans, b ** p)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    string s;
    int count=0;
    REP(i,n){
        cin>>s;
        if(s[0]=='A'){
            count++;
        }else {
            count--;
        }
        if(count<0){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    if(count==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3160
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, k = map(int, input().split())
    hl = list(map(int, input().split()))
    print(len(list(filter(lambda h: h >= k, hl))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 51440
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

x, k, d = [int(x) for x in input().split()]

cnt = min(k, abs(x) // d)

if x > 0:
    k -= cnt
    x -= d*cnt
    if abs(x - d) < abs(x) and k > 0:
        k -= 1
        x -= d
else:
    k -= cnt
    x += d*cnt
    if abs(x + d) < abs(x) and k > 0:
        k -= 1
        x += d

if k == 0:
    print(abs(x))
    sys.exit()

if k % 2 == 0:
    print(abs(x))
else:
    print(min(abs(x + d), abs(x - d)))

# if abs(x + d) > abs(x - d):
#     if k % 2 == 1:
#         print(abs(x - d))
#     else:
#         print(abs(x + d))
# else:
#     if k % 2 == 1:
#         print(abs(x + d))
#     else:
#         print(abs(x - d))

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

int main(void){
    string s;
    cin >> s;
    long sum = 0, cnt = 0;
    for(long i=0; i<s.size(); i++){
        if(s[i]=='W'){
            sum += cnt;
        }else{
            cnt++;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 640
a,b=list(map(int,input().split()))
a_list=[a for i in range(b)]
b_list=[b for i in range(a)]

import sys
for i in range(min(a,b)):
  if a_list[i]<b_list[i]:
    print("".join(map(str,a_list)))
    sys.exit()
  elif b_list[i]<a_list[i]:
    print("".join(map(str,b_list)))
    sys.exit()
if a<=b:
  print("".join(map(str,a_list)))
else:
  print("".join(map(str,b_list)))

  
  

Measured memory_bytes: 3064
#include <stdio.h>
int power(int base,int n){
	int i,k=1;
	for(i=0;i<n;i++){
		k*=base;
	}
	return (float)k;
}
main(){
	int a,b,c,d,i=1;
	while(scanf("%d%d",&a,&b)!=EOF){
		i=0;
		c=a+b;
		if(a<0||b<0)break;
		while(1){
			d=c/power(10,i);
			if(!d)break;
			i++;
		}
		printf("%d\n",i);
	}
}

Measured memory_bytes: 0
S = input()

flag = True
while len(S):
    if S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    else:
        flag = False
        break

if flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int c = 0;
        for (int i = 0 ; i < 3 ; i++) {
            if (s.charAt(i) == t.charAt(i)) c++;
        }
        System.out.println(c);

    }

}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s; cin>>s;
    ll q; cin>>q;

    rep(i,q){
        string t;
        ll l,r;
        cin>>t>>l>>r;
        if(t=="print") cout<<s.substr(l,r-l+1)<<endl;
        else if(t=="replace"){
            string u; cin>>u;
            for(int i=l;i<=r;i++) s[i]=u[i-l];
        }else{
            string tmp=s.substr(l,r-l+1);
            reverse(all(tmp));
            s=s.substr(0,l)+tmp+s.substr(r+1,INF);
        }
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  if (n==1||n==2) {
    cout << 0 << endl;
    return 0;
  }

  vector<int>l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  long long ans=0;

  for (int i = 0; i < n-2; i++) {
    for (int j = i+1; j < n-1; j++) {
      for (int k = j+1; k < n; k++) {
        if (l.at(i)!=l.at(j) && l.at(j)!=l.at(k) && l.at(k)!=l.at(i)) {
          vector<int>table(3);
          table.at(0) = l.at(i);
          table.at(1) = l.at(j);
          table.at(2) = l.at(k);

          sort(table.begin(),table.end());
          if (table.at(0)+table.at(1) > table.at(2)) ans++;
        }
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3628
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    int n , m ; 
    cin >> n >> m; 
    vector<vector<int> > v(n, vector<int>(m));
    for(int i = 0; i < m; i++){
        int x , y ; 
        cin >> x >> y ; 
        x--, y--;
        v[x][y] = 1;
        v[y][x] = 1;
    }
    vector<int> a ; 
    for(int i = 1; i < n; i++){
        a.push_back(i);
    }
    int ans = 0 ;
    do{
        a.insert(a.begin(), 0);
        bool ok = true ;
        for(int i = 1; i < (int) a.size(); i++){
            if ( !v[a[i]][a[i - 1]] ) ok = false;
        }
        a.erase(a.begin());
        if ( ok ) ans++;
    }while(next_permutation(a.begin(),a.end()));
    cout << ans << endl;
    return 0 ;
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e2 + 10;
const int mod = 1e9 + 7;

int gr[N][N];
bool vis[N][N];
int n , a , b , w , m;
pair<int,int> edge[N*10];
int wt[N*10];

int32_t main(){
	boost;

	int a , b , c , d;

	cin >> a >> b >> c >> d;

	cout << max(a*b , c*d);
	return 0;
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 10450555;
const int M = 1155;

void solve() {
    for (int i = 1; i <= 5; i++){
        ll x;
        cin >> x;
        if (x == 0){
            cout << i;
            break;
        }
    }

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

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

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
 
int main(){
    long long n, m, i, j;
    cin >> n >> m;
    long long s[n], t[m], c[n+1][m+1] = {};
    for(i=0; i<n; i++){
        cin >> s[i];
        c[i+1][0] = 1;
    }
    for(i=0; i<m; i++){
        cin >> t[i];
        c[0][i+1] = 1;
    }
    c[0][0] = 1;
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            if(s[i] == t[j]){
                c[i+1][j+1] = c[i][j+1] + c[i+1][j];
            }else{
                c[i+1][j+1] = c[i][j+1] + c[i+1][j] - c[i][j];
            }
            if(c[i+1][j+1] < 0){
                c[i+1][j+1] += MOD;
            }else{
                c[i+1][j+1] %= MOD;
            }
        }
    }
    cout << c[n][m];
    return 0;
}

Measured memory_bytes: 31616
n = int(input())

for i in range(n):
    if (i + 1) % 3 == 0:
        print(" " + str(i+1),end='')
#    elif (i+1) % 10 == 3:
#        print(" " + str(i+1),end='')
    elif "3" in str(i+1):
        print(" " + str(i+1),end='')
        
print()


Measured memory_bytes: 5868
/*
g++ -std=c++14 -o2 -Wall ABC122A.cpp -o .\out\ABC122A.out
.\out\ABC122A.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  char a;
  cin >> a;
  if (a == 'A') cout << "T\n";
  else   if (a == 'T') cout << "A\n";
  else if (a == 'C') cout << "G\n";
  else   if (a == 'G') cout << "C\n";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   int W, H, x, y, r;

   scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

   if((x + r) <= W && (x - r) >= 0){
   	if((y + r) <= H && (y - r) >= 0)
   	printf("Yes\n"); 
   else 
   	printf("No\n");
   } 
   else 
   	printf("No\n");

   return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

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

    int n;
    cin >> n;
    vector <pair <int, int> > a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());

    vector <int> pos(n);
    for (int i = 0; i < n; ++i) {
        pos[a[i].second] = i;
    }

    for (int i = 0; i < n; ++i) {
        int want = (n - 1) / 2;
        if (pos[i] <= want) {
            cout << a[want + 1].first << '\n';
        }
        else {
            cout << a[want].first << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define triplerep(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

int main(void){
    int x;
    bool visited[1009];
    scnd1( x);
    
    memset( visited, false, sizeof(visited));
    visited[1] = true;
    
    for (int i = 2; i*i <= x; i++ ) {
        int n = i*i;
        while (n <= x) {
            visited[n] = true;
            n *= i;
        }
    }
    
    while (true) {
        if (visited[x--]) {
            cout << x+1 << endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 256
N = int(input())

ans = []
# 偶数だったら対角、奇数だったらその一つ左を引く
for i in range(1, N + 1):
  for j in range(1, N + 1):
    if N % 2 == 0:
      if i != j and i + j != N + 1:
        if [j, i] not in ans:
          ans.append([i, j])
    else:
      if i != j and i + j != N:
        if [j, i] not in ans:
          ans.append([i, j])
print(len(ans))
for i, j in ans:
  print(i, j)

Measured memory_bytes: 4124
# coding: utf-8
# Your code here!
import numpy as np
N = int(input())
L = np.array(list(map(int, input().split())))

cnt = 0
while np.any(L > 0):
    for i in range(N):
        if L[i] > 0:
            start = i
            end = i + 1
            for j in range(start+1, N):
                end = j
                if not L[j] > 0:
                    break
                end += 1
            break
        
    
    cnt += L[start:end].min()
    L[start:end] -= L[start:end].min()

print(cnt)

Measured memory_bytes: 12508
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
int main() {
    int N;
    string S;
    cin >> N >> S;


    int ans =0;

    for(int i=1; i< N; i++){
        unordered_map<char, int> kind;
        for(int ii=0; ii<i; ii++){
            kind[S[ii]] = 1;
        }
        for(int k=N; k>=i;k--){
            if(kind[S[k]]>0){
                kind[S[k]] += 1;
            }else{
                kind[S[k]] = 0;
            }
        }

        int tmp =0;
        for(auto itr = kind.begin(); itr != kind.end(); ++itr) {
            if(itr->second > 1){
                tmp++;
            }
        }
        ans = max(ans,tmp);
    }

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

Measured memory_bytes: 256
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID
/*#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define print(o) for(auto it=(o).begin();it!=(o).end();it++) cout<<*it<<" ";
#define vll vector<ll>
#define pb push_back
#define FOR(n) for(ll i=0;i<=n;i++)
#define FORd(n) for(ll i=n;i>=0;i--)
#define FORrd(a,b) for(ll i=a;i>=b;i--)
#define FORr(a,b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(),(x).end()
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ff first
#define ss second
#define w(t) ll t;cin>>t;while(t--)

int main()
{
    FIO;
    string s;
    cin>>s;
    ll n=s.length();
    string ans(n,'x');
    cout<<ans<<'\n';
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 384
#include <iostream>
#include <map>

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

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

  if (P == 2 || P == 5) {
    ll ans = 0;
    rep(i, N) {
      if ((S[i] - '0') % P == 0)
        ans += (ll)i + 1;
    }
    cout << ans << endl;
    return 0;
  }

  ll n = 0, ans = 0, ten = 1;
  map<int, int> m;
  rrep(i, N-1) {
    n = ((S[i] - '0') * ten  + n) % P;
    ten = (10*ten) % P;
    ans += m[n]++;
  }
  cout << ans + m[0] << endl;

  return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e5 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[1005];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    for(ll i = 0; i < s.size(); i ++)
    {
        if(s[i] == '0' and s[i+1] == '0')
        {
            s[i+1] = '1';
            cnt ++;
        }
        if(s[i] == '1' and s[i+1] == '1')
        {
            s[i+1] = '0';
            cnt ++;
        }
    }
    for(ll i = 0; i < s.size(); i ++)
    {
        if(s[i] == s[i+1])
        {
            cnt ++;
        }
    }
    cout << cnt;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, m; cin >> n >> m;
	vector<int> a(m);
	rep(i, 0, m - 1)
	{
		cin >> a[i];
	}
	vector<ll> dp(n + 1, -1);
	dp[0] = 1;
	dp[1] = 1;
	rep(i, 0, m - 1)dp[a[i]] = 0;
	rep(i, 2, n)
	{
		if (dp[i] != 0)dp[i] = (dp[i-1] + dp[i-2]) % 1000000007;
	}
	cout << dp[n] << endl;
}

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

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define mod 1e9+7
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pp pop_back
#define bs binary_search
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector <char>
#define vvll vector<vector<ll>>
#define mod 1e9+7
#define mxn 9e18
#define all(x) x.begin(),x.end()
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define test ll t ; cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve()
{
    string s,t;
    ll ans=1;
    cin>>s>>t;
    loop(i,0,s.length())
    {
        if(s[i]!=t[i])
        {
            ans=0;
            break;
        }
    }
    if(ans)     cout<<"Yes";
    else    cout<<"No";
    cout<<"\n";
}

int main() {
	fast_io;
	
	
	    solve();
	
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <stack>
#include <algorithm>
#include <string>
#include <climits>

typedef std::vector<int> liste;
typedef liste::const_iterator iter;

void print_array(liste list) {
    for(int i = 0; i < list.size(); ++i){
        if(i>0) std::cout << " ";
        std::cout << list[i];
    }
    std::cout << std::endl;
}

bool solve(int i,int m,liste& list) {
    if(m==0) {
        return true;
    }
    if(i>=list.size()||m<0) {
        return false;
    }
    bool res = (solve(i+1,m,list)||solve(i+1,m-list[i],list));
    return res;
} 
    
int main(void){
        
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int value;
    liste list,question;
    int n;
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        list.push_back(value);
    } 
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        question.push_back(value);
    } 

    for(int i=0; i<question.size(); i++) {
        if(solve(0,question[i],list)) {
            std::cout << "yes" << std::endl;            
        } else {
            std::cout << "no" << std::endl;            
        }
    } 
    
    return 0;
}

Measured memory_bytes: 1212
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int a, b;
    cin >> a >> b;
    int ans = max({ a + b,a - b,a*b });
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	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);
		long k = sc.nextLong();
		long x = sc.nextLong();
		if (k * 500 >= x) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

ll modpow(ll a, ll p){
	ll ret = 1;
	while(p){
		if(p&1) ret = ret * a % MOD;
		a = a * a % MOD;
		p >>= 1;
	}
	return ret;
}

int main(){
	int n;
	scanf("%d", &n);
	V a(n);
	SCAN(a);

	std::map<ll,ll> A[n];
	std::map<ll,ll> g;
	REP(i, 0, n){
		ll x = a[i];
		for(ll j=2; j*j<=a[i]; j++){
			while(x%j==0){
				x /= j;
				A[i][j]++;
			}
		}
		if(x>1) A[i][x]++;

		for(P p: A[i]){
			if(g[p.fi]<p.se) g[p.fi] = p.se;
		}
	}

	ll e = 1;
	for(P p: g) e = e * modpow(p.fi, p.se) % MOD;
	ll ans = 0;
	REP(i, 0, n){
		ans += e *  modpow(a[i], MOD-2) % MOD;
		ans %= MOD;
	}
	printf("%ld\n", ans);
	return 0;
}



Measured memory_bytes: 3968
//package atcoderdp;
import java.util.*;
class Main {
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int a[]= new int[n];
    int b[]= new int[n];
    int c[] = new int[n];
        for (int i = 0; i <n ; i++) {
            a[i] = s.nextInt();
            b[i] = s.nextInt();
            c[i] = s.nextInt();
        }
        System.out.println(find(a,b,c,n));
    }
    public static int find(int a[],int b[],int c[],int n){
        int dp[][]= new int[n][3];
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        for (int i = 1; i <n ; i++) {
            dp[i][0] = Math.max(dp[i-1][1],dp[i-1][2])+a[i];
            dp[i][1] = Math.max(dp[i-1][0],dp[i-1][2])+b[i];
            dp[i][2] = Math.max(dp[i-1][0],dp[i-1][1])+c[i];
        }
        return Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    }

}


Measured memory_bytes: 61908
#include <stdio.h>
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
#include <list>
#include <algorithm>
using namespace std;

#define N 100000
unsigned int table(string str)
{
    unsigned int x = 0;
    for (unsigned int i = 0; i < str.length(); i++)
    {
        x += (str[i]-'A');
        x *= 100;
    }
    return x % N;
}
class Hash
{
  private:
    list<string> a[N];

  public:
    Hash()
    {
    }

    void insert(string str)
    {
        a[table(str)].push_back(str);
    }

    bool find(string str)
    {
        unsigned int key = table(str);
        list<string>::iterator itr = a[key].begin();
        for (; itr != a[key].end(); itr++)
            if (str == *itr)
                return true;
        return false;
    }
};

int main()
{
    Hash H;
    int n;
    cin >> n;
    string str;
    for (int i = 0; i < n; i++)
    {
        //cout << i << "\n";
        cin >> str;
        if (str[0] == 'i')
        {
            cin >> str;
            H.insert(str);
        }
        else if (str[0] == 'f')
        {
            cin >> str;
            if (H.find(str))
                cout << "yes\n";
            else
                cout << "no\n";
        }
    }
}


Measured memory_bytes: 54036
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=float('inf')*-1

for i in range(n):
    visited=[i]
    pin=0
    now=i
    for j in range(k):
        now=p[now]-1
        pin+=c[now]
        ans=max(ans,pin)
        visited+=[now]

        if visited[0]==visited[-1]:
            if pin>0:
                pin*=(k//(len(visited)-1)-1)
                ans=max(ans,pin)

                for s in range(k%(len(visited)-1)+len(visited)-1):
                    now=p[now]-1
                    pin+=c[now]
                    ans=max(ans,pin)

                break

            else:
                break

print(ans)

Measured memory_bytes: 82280
/*
ID: duttonl1
TASK: G_Longest_Path.cpp 
LANG: C++
*/
#include <bits/stdc++.h>

#define pb push_back
#define fst first
#define snd second
#define DEBUGA(a, b) cout << "[ "; for (auto _x = (a); _x != (b); _x++) cout << *_x << " "; cout << "]"<< endl
#define DEBUG(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string>_it(_ss); err(_it, args); };cout << endl
#define fr(i,x) for (int i = 0; i < int(x); i++)
#define frab(i,a,b) for (int i = int(a); i < int(b); i++)
#define sz(x) ((int) (x).size())
void run();
int main() {
    std::ios::sync_with_stdio(false);
    run();
    return 0;
}

using namespace std;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "; ";
    err(++it, args...);
}


typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

#define GMAX 100005
#define INF  100000000

int dist[100005], visited[100005];
vector<vi> G;
vi tsort;

void dfs(int node) {
    visited[node] = true;
    for (auto next : G[node])
        if (!visited[next]) dfs(next);
    tsort.pb(node);
}

void run() {
    int n, m, x, y; cin >> n >> m;
    G.assign(n, vi());
    fr(i,n) dist[i] = -INF;
    fr(i,n) visited[i] = false;
    fr(i,m) {
        cin >> x >> y;
        x--; y--;
        G[x].pb(y);
    }
    fr(i,n) {
        if (!visited[i]) {
            dist[i] = 0;
            dfs(i);
        }
    }
    reverse(tsort.begin(), tsort.end());

    for (auto node : tsort) { 
        for (auto next : G[node])
            if (dist[next] < dist[node] + 1)
                dist[next] = dist[node] + 1;
    }
    int ans = 0;
    fr(i,n) ans = max(ans,dist[i]);

    cout << ans << endl;

}




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

using namespace std;
int main() {
	int n, m,sum=0;
	cin >> n;
	cin >> m;
	vector<vector <int> > strA;
	strA.resize(n);
	for (int i = 0; i < n; i++) {
		strA[i].resize(m);
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> strA[i][j];
		}
	}

	vector<int> strb(m);
	for (int i = 0; i < m; i++) {
		cin>>strb[i];
	}

	vector<int> ans(n,0);
	//ans.resize(n);
	

	for (int i = 0; i < n; i++) {
		//sum = 0;
		for (int j = 0; j < m; j++) {
			//sum += strA[i][j] * strb[j];
			ans[i] += strA[i][j] * strb[j];
		}
		//ans[i] = sum;
	}

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

	return 0;

}

Measured memory_bytes: 3152
N = int(input())
S = 0
if N == 1:
  print('0')
else:
  S0 = 10**N - 9**N
  S9 = 10**N - 9**N
  S09 = 8**N
  S = S0 + S9 + S09 - 10**N
  S = S % (10**9 + 7)
  print(S)

Measured memory_bytes: 98780
#include <stdio.h>
typedef long long int ll;
constexpr int kMod = int(1E9 + 7);
ll a[60][60], ans[60][60], tmp[60][60];
int n;

void Pow(ll b) {
	for (int i = 1; i <= n; i++) ans[i][i] = 1;
	while (b) {
		if (b & 1) {
			for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
				tmp[i][j] = ans[i][j];
				ans[i][j] = 0;
			}
			for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) 
				ans[i][j] += tmp[i][k] * a[k][j] % kMod;
			for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) ans[i][j] %= kMod;

		}
		b >>= 1;
		for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
			tmp[i][j] = a[i][j];
			a[i][j] = 0;
		}
		for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) 
			a[i][j] += tmp[i][k] * tmp[k][j] % kMod;
		for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) a[i][j] %= kMod;
	}
}

int main() {
	ll tot = 0, k;
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%lld", &a[i][j]);
	Pow(k);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) tot += ans[i][j];
	printf("%lld\n", tot % kMod);
}


Measured memory_bytes: 1796
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
mint choose(int n,int a){
  mint x = 1,y=1;
  rep(i,a){
    x*= n-i;
    y*= i+1;
  }
  return x/y;
}
int main(){
 int n,a,b;
 cin>>n>>a>>b;
 mint ans =mint(2).pow(n);
 ans-=1;
 ans-=choose(n,a);
 ans-=choose(n,b);
 cout<<ans.x<<endl;

}

Measured memory_bytes: 256
N, D = gets.split(' ').map(&:to_i)
X = []
count = 0

def tf(a, b)
  s = 0
  a.length.times { |i| s = s + ((a[i] - b[i])**2) }
  ans = s**(1 / 2.0)
  return ans.to_s =~ /^[0-9]+.0$/ ? 1 : 0
end

N.times do |i|
  p = gets.chomp.split(' ').map(&:to_i)
  X.push(p)
end
N.times do |n|
  next if n == 0
  a = X[n]
  n.times { |b| count = count + tf(X[b], a) }
end

puts "#{count}"


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

int main() {
  string S;
  cin >> S;
  int counta = 0;
  int countb = 0;

  vector<char> C(S.size());
  for (int i = 0; i < S.size(); i++) {
    C.at(i) = S.at(i);

    if (i % 2 == 0 && C.at(i) == '1'){
      counta++;
    }
    else if (i % 2 == 1 && C.at(i) == '0'){
      counta++;
    }
    else if (i % 2 == 1 && C.at(i) == '1'){
      countb++;
    }
    else if (i % 2 == 0 && C.at(i) == '0'){
      countb++;
    }
  }
 
  if (counta > countb){
    cout << countb << endl;
  }
  else {
    cout << counta << endl;
  }
}
    
  

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int size = sc.nextInt();
            if (size == 0) {
                break;
            }
            boolean left = false;
            boolean right = false;
            boolean last = false;
            int count = 0;
            for (int i = 0; i < size; i++) {
                char[] arr = sc.next().toCharArray();
                if (arr[0] == 'l') {
                    if (arr[1] == 'u') {
                        left = true;
                    } else {
                        left = false;
                    }
                } else {
                    if (arr[1] == 'u') {
                        right = true;
                    } else {
                        right = false;
                    }
                }
                if (left && right && !last) {
                    count++;
                    last = true;
                } else if (!left && !right && last) {
                    count++;
                    last = false;
                }
            }
            sb.append(count).append("\n");
        }
        System.out.print(sb);
    }
}


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

using namespace std;
typedef long long ll;
const int N = 1e5 + 10;


void solved()
{   
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans = n / (a + b) * a;
    ll t = n % (a + b);
    if(t <= a)ans += t;
    else ans += a;
    cout << ans;
}


int main()
{
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#endif 
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solved();
        cout <<"\n";
    }

#ifdef LOCAL
    system("pause");
#endif 
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cassert>
#include <queue>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define fst first
#define snd second
#define SZ(x) ((int)x.size())
typedef long long ll;
#define dforn(i, n) for(int i = n - 1; i >= 0; i--)

const int MAXN = 2048;

ll ans;
int n, k, q, least, A[MAXN];
map<int, vector<int>> M;
int p[MAXN], sz[MAXN];
bool valid[MAXN];
vector<pair<int, int>> V;
int findParent(int a){
  while(a != p[a]){
    p[a] = p[p[a]];
    a = p[a];
  }
  return a;
}
void unir(int a, int b){
  if(a < 0 || a >= n) return;
  if(b < 0 || b >= n) return;
  if(!valid[a] || !valid[b]) return;
  a = findParent(a);
  b = findParent(b);
  if(a == b) return;
  sz[b] += sz[a];
  p[a] = b;
}
void crear(int a){
  if(a < 0 || a >= n) return;
  p[a] = a;
  sz[a] = 1;
  valid[a] = true;
}

void solve(){
  memset(valid, false, sizeof valid);
  //~ printf("Resolviendo con least = %d\n", least);
  forn(i, n){
    if(A[i] > least){
      crear(i);
      //~ printf("Creando at %d\n", i);
    }
  }
  forn(i, n){
    unir(i, i-1);
    unir(i, i+1);
  }
  //~ forn(i, n){
    //~ if(!valid[i]) printf("x ");
    //~ else printf("%d[%d] ", findParent(i), sz[findParent(i)]);
  //~ }
  //~ puts("");
  //~ puts("");
  int t = 0;
  ll mn = (ll)1e18;
  ll mx = 0;
  forn(i, V.size()){
    int p = V[i].snd;
    if(!valid[p]) continue;
    //~ printf("Valor %d en %d, tiene sz %d\n", V[i].fst, p, sz[findParent(p)]);
    if(sz[findParent(p)] >= k){
      sz[findParent(p)]--;
      mx = max(mx, (ll)A[p]);
      mn = min(mn, (ll)A[p]);
      t++;
      //~ printf("T == %d\n", t);
      if(t == q){
        //~ printf("Got there with %lld %lld\n", mn, mx);
        ans = min(ans, mx - mn);
        return;
      }
    }
  }
}

int main() {
  //~ freopen("input.in", "r", stdin);
  while( scanf("%d %d %d", &n, &k, &q) >= 1 ){
    ans = (ll)1e18;
    V.clear();
    forn(i, n){
      scanf("%d", &A[i]);
      V.pb({A[i], i});
    }
    sort(V.begin(), V.end());
    least = -1;
    solve();
    forn(i, V.size()){
      if(V[i].fst != least){
        least = V[i].fst;
        solve();
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define ff fflush(stdout)
using namespace std;
pll num[400005];
ll taken[200005];
int main () {
	ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%lld", &a);
	for (i = 1; i <= a; i++) {
		scanf("%lld %lld", &b, &c);
		num[i * 2 - 1] = {b, i};
		num[i * 2] = {c, i};
	}
	sort(num + 1, num + a + a + 1);
	SET(taken, 0); d = 0; f = 0;
	for (i = 1; i <= a * 2; i++) {
		if (taken[num[i].se]) {
			if (!f) f = i;
			continue;
		}
		taken[num[i].se] = 1; d++;
		if (d == a) break;
	}
	if (!f) f = i + 1;
	e = (num[i].fi - num[1].fi) * (num[a + a].fi - num[f].fi);
	SET(taken, 0); d = 0; f = 0;
	for (i = a * 2; i >= 1; i--) {
		if (taken[num[i].se]) {
			if (!f) f = i;
			continue;
		}
		taken[num[i].se] = 1; d++;
		if (d == a) break;
	}
	if (!f) f = i - 1;
	g = (num[a + a].fi - num[i].fi) * (num[f].fi - num[1].fi);
	e = min(e, g);
	SET(taken, 0); d = 0;
	for (i = 2, j = 2; i <= a * 2; i++) {
		while (d < a && j <= a * 2) {
			taken[num[j].se]++;
			if (taken[num[j].se] == 1) d++;
			j++;
		}
		if (d < a) break;
		e = min(e, (num[a + a].fi - num[1].fi) * (num[j - 1].fi - num[i].fi));
		taken[num[i].se]--;
		if (taken[num[i].se] == 0) d--;
	}
	printf("%lld\n", e);
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
#define fo(i,s,e_ex) for(i=s;i<e_ex;i++)
#define Fo(i,k,n) for(i=k;k<n?i<=n:i>=n;k<n?i+=1:i-=1)
#define endl '\n'
#define MOD 1000000007//998244353
#define pbb push_back
#define mpp make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mset(arr,val) memset(arr,val,sizeof(arr))
ll n;
ll arr[105];
int dp[100005];
bool play(ll k){
	if(dp[k]!=-1) return dp[k];
	bool ans=false;
	ll i;
	fo(i,0,n){
		if(k>=arr[i]){
			bool myans=play(k-arr[i]);
			if(myans==false) ans=true;
		}
	}
	return dp[k]=ans;
}
void solve(ll caseno){
	ll i,j,k;
	cin>>n>>k;
	fo(i,0,n) cin>>arr[i];
	// mset(dp,-1);
	// cout<<(play(k)?"First":"Second")<<endl;
	mset(dp,false);
	fo(i,0,k+1){
		fo(j,0,n){
			if(i>=arr[j]){
				bool myans=dp[i-arr[j]];
				if(myans==false) dp[i]=true;
			}
		}
	}
	cout<<(dp[k]?"First":"Second")<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		solve(i);
	}
	return 0;
}


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

const int maxn = 100010;
int n, m, q, pre1[maxn][20], pre2[maxn][20];
char s[maxn], t[maxn];

int merge(int x, int y) {
    if (x == -1 || y == -1) return ~x ? x : y;
    if (!x && !y) return 1;
    if (x && y) return 0;
    return -1;
}

int main() {
    scanf("%s %s", s + 1, t + 1);
    n = strlen(s + 1), m = strlen(t + 1);
    for (int i = 1; i <= n; i++) {
        pre1[i][0] = s[i] == 'B';
    }
    for (int i = 1; i <= m; i++) {
        pre2[i][0] = t[i] == 'B';
    }
    for (int i = 1; i <= 20; i++) {
        for (int j = 1; j + (1 << i) - 1 <= n; j++) {
            pre1[j][i] = merge(pre1[j][i - 1], pre1[j + (1 << (i - 1))][i - 1]);
        }
    }
    for (int i = 1; i <= 20; i++) {
        for (int j = 1; j + (1 << i) - 1 <= m; j++) {
            pre2[j][i] = merge(pre2[j][i - 1], pre2[j + (1 << (i - 1))][i - 1]);
        }
    }
    scanf("%d", &q);
    for (int i = 1, a, b, c, d; i <= q; i++) {
        scanf("%d %d %d %d", &a, &b, &c, &d);
        int s1 = -1, s2 = -1;
        for (int j = 19; ~j; j--) if (a + (1 << j) - 1 <= b) {
            s1 = merge(s1, pre1[a][j]), a += (1 << j);
        }
        for (int j = 19; ~j; j--) if (c + (1 << j) - 1 <= d) {
            s2 = merge(s2, pre2[c][j]), c += (1 << j);
        }
        printf("%s\n", s1 == s2 ? "YES" : "NO");
    }
    return 0;
}

Measured memory_bytes: 16384
n,t = map(int,input().split())
t_L = list(map(int,input().split()))
t_L.append(t_L[-1]+t)
#before = t_L[0]
ans = 0
for i in range(0,n):
    if t_L[i] + t <= t_L[i+1]:
        ans += t
    else:
        ans += t_L[i+1] - t_L[i]
        #print(t_L[i+1] - t_L[i])

print(ans)


Measured memory_bytes: 85712