akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Numerics;
using System.Diagnostics;

   class Program
    {
        static void Main()
        {
            var args = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var K = args[0];
            var S = args[1];
            var ans = 0;
            for (int i = 0; i <= K; i++)
            {
                for (int j = 0; j <= K; j++)
                {
                    var z = S - i - j;
	                if (S - i - j > K || S - i - j < 0) continue;
    	            if (i + j + z == S) ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }

Measured memory_bytes: 28224
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define int long long

int n, c, X[100010], V[100010], Sm[100010], Mx1[100010], Mx2[100010];

#undef int
int main() {
#define int long long
    scanf("%lld%lld", &n, &c);
    for(int i = 1; i <= n; i++) scanf("%lld%lld", &X[i], &V[i]);
    for(int i = 1; i <= n; i++) Sm[i] = Sm[i - 1] + V[i];
    for(int i = n; i >= 1; i--) Mx1[i] = max(Mx1[i + 1], Sm[n] - Sm[i - 1] - (c - X[i]));
    for(int i = n; i >= 1; i--) Mx2[i] = max(Mx2[i + 1], Sm[n] - Sm[i - 1] - 2 * (c - X[i]));
    int ans = 0;
    for(int i = 0; i <= n; i++) {
        ans = max(ans, Mx1[i + 1] + Sm[i] - 2 * X[i]);
        ans = max(ans, Mx2[i + 1] + Sm[i] - X[i]);
    }
    for(int i = 0; i <= n; i++)
        ans = max(ans, Sm[i] - X[i]);
    for(int i = 0; i <= n; i++)
        ans = max(ans, Sm[n] - Sm[i - 1] - (c - X[i]));
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
const int MAXN=1e6;
int n,fl=-1,now=7;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=MAXN;i++){
        now=now*10%(9*n);
        if(now==7){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
}


Measured memory_bytes: 3824
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>



typedef int64_t int64;
using namespace std;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int64 n,l;
  cin>>n>>l;
  vector<int64> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  int left=0,right;
  bool found=false;
  for(int i=0;i<n-1;i++){
    if(a[i]+a[i+1]>=l){
      left=i;
      right=i+1;
      found=true;
      break;
    }
  }
  if(!found){
    cout<<"Impossible"<<endl;
    return 0;
  }

  cout<<"Possible"<<endl;
  int last=right;
  for(int i=1;i<last;i++){
    cout<<i<<endl;
  }
  for(int i=n-1;i>last;i--){
    cout<<i<<endl;
  }
  cout<<last<<endl;




  return 0;
}

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

lli n;

int main(void){
	cin >> n;
	vector<lli> v(n);
	vector<lli> e(N), o(N);
	rep(i, n) cin >> v[i];
	rep(i, n){
		if(i%2 == 0){
			e[v[i]]++;
		}else{
			o[v[i]]++;
		}
	}
	auto p1 = max_element(e.begin(), e.end())-e.begin();
	auto p2 = max_element(o.begin(), o.end())-o.begin();
	if(p1 != p2){
		cout << n-e[p1]-o[p2] << endl;
	}else{
		if(e[p1] < o[p2]){
			e[p1] = 0;
			lli ne = *max_element(e.begin(), e.end());
			cout << n-ne-o[p2] << endl;
		}else if(e[p1] == o[p2]){
			lli tmp = e[p1];
			e[p1] = o[p2] = 0;
			lli noe = max(*max_element(e.begin(), e.end()), 
			*max_element(o.begin(), o.end()));
			cout << n-tmp-noe << endl;
		}else{
			o[p2] = 0;
			lli no = *max_element(o.begin(), o.end());
			cout << n-e[p1]-no << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 5648
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=3005;
const int mod=998244353;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int f[MAXN][MAXN*2],C[MAXN][MAXN];
void init()
{
	for(int i=0;i<MAXN;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	f[0][0]=1;
	for(int i=1;i<MAXN;i++)
		for(int j=0;j<=2*i;j++)
		{
			if(j-1>=0)ad(f[i][j],f[i-1][j-1]);
			if(j-2>=0)ad(f[i][j],f[i-1][j-2]);
		}
}
int n,X;
int main()
{
	init();
	n=read();X=read();
	int ans=1;
	for(int i=1;i<=n;i++)
	{
		int sum=0;
		for(int j=1;j<X;j++)ad(sum,f[i][j]);
		for(int j=X+1;j<=2*i;j+=2)if(j>=i)
		{
			int a=(j-X+1)/2;
			if(2*a<X-1&&i-2*a>=1)ad(sum,f[i-2*a][X-2*a-1]);
			else if(X&1&&2*a>=i&&j==i*2)ad(sum,1);
		}
		ad(ans,1LL*sum*C[n][i]%mod);
	}
	pr2(ans);
	return 0;
}

Measured memory_bytes: 104704
import sys
input = sys.stdin.readline


def check(W):
    # false -> exist negative cycle
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if W[i][k]+W[k][j]+W[j][i]<0:
                    return False
                W[i][j] = min(W[i][j], W[i][k]+W[k][j])
    return True


if __name__ == "__main__":
    V, E = map(int, input().split())
    inf = float("inf")
    W = [[inf]*V for _ in range(V)]
    for i in range(V):
        W[i][i] = 0

    for _ in range(E):
        s, t, d = map(int, input().split())
        W[s][t] = d

    if check(W):
        for i in W:
            print(*(j if j!=inf else "INF" for j in i))
    else:
        print("NEGATIVE CYCLE")



Measured memory_bytes: 6284
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int m;
int cnt[maxn];
int ans1 = 0;
int ans2 = 0;
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    n = readint();
    m = readint();
    int x;
    char str[23];
    repd(i, 1, m) {
        x = readint();
        scanf("%s", str);
        if (cnt[x] == -1)
            continue;
        if (str[0] == 'A')
        {
            ans1++;
            ans2 += cnt[x];
            cnt[x] = -1;
        } else
        {
            cnt[x]++;
        }
    }
    printf("%d %d\n", ans1, ans2 );
    return 0;
}




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

using namespace std;

struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for (int i = 0; i < N; i++) par[i] = i;
	}

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

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> p(N);
	for (int i = 0; i < N; i++) cin >> p[i];

	UnionFind tree(N);

	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		tree.unite(x - 1, y - 1);
	}

	int count = 0;

	for (int i = 0; i < N; i++) {
		if (tree.same(i, p[i]-1)) count++;
	}

	cout << count << endl;

	return 0;
}


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

using namespace std;

class Solution {
public:
	/* time: O(n + q), space: O(n), where n = # of players, q = # of questions */
	vector<bool> attackSurvival(int n, int k, const vector<int>& questions) {
		const int q = questions.size();
		vector<int> nCorrect(n);
		for (int player : questions)
			++nCorrect[player - 1];

		vector<bool> ans(n);
		for (int i = 0; i < n; ++i)
			ans[i] = (k - (q - nCorrect[i])) > 0;
		return ans;
	}
};

int main() {
	int n, k, q;
	cin >> n >> k >> q;

	vector<int> questions(q);
	for (int i = 0; i < q; ++i)
		cin >> questions[i];

	Solution sol;
	vector<bool> ans = sol.attackSurvival(n, k, questions);
	for (int i = 0; i < n; ++i)
		cout << (ans[i] ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 998244353
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}
ll perm(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (fac[n]*finv[n-k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
ll mpow(ll a, ll b, ll p = -1){
  ll ret = 1, num = a;
  if(p==-1){
    while(b>0){
      if(b%2) ret *= num;
      num = num * num;
      b /= 2;
    }
  }else{
    while(b>0){
      if(b%2) ret = (ret*num)%p;
      num = (num*num)%p;
      b /= 2;
    }
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  init();
  ll n;std::cin >> n;
  ll ans = mpow(3, n, P);
  ll sub = 0;
  for(ll i=n/2+1;i<=n;i++){
    ll tmp = comb(n, i);
    tmp = (tmp * mpow(2, n-i, P))%P;
    sub = (sub + tmp)%P;
  }
  // 3^n -
  std::cout << (ans-(2*sub)%P+P)%P << '\n';
  return 0;
}


Measured memory_bytes: 237472
//BROWNIE TK

#include <bits/stdc++.h>

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{
    return a * b / gcd(a, b);
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
const int N=2e5+5;
lli cnt[N];
int main()
{
    kira;
    lli n;
    cin>>n;
    vector<lli>a(n);
    forz(i,n)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    lli ans=0;
    forz(i,N)
    {
        ans+=cnt[i]*(cnt[i]-1)/2;
    }
    forz(i,n)
    {
        cout<<ans-cnt[a[i]]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 4736
import java.util.ArrayDeque

fun main(args: Array<String>) {
    val n = readInteger()
    val s = readLine()!!
    val deque = ArrayDeque<Char>()
    var leftCount = 0
    repeat(n) {
        when (s[it]) {
            '(' -> {
                deque.addLast('(')
                leftCount++
            }
            ')' -> {
                if (leftCount > 0) {
                    leftCount--
                } else {
                    deque.addFirst('(')
                }

                deque.addLast(')')
            }
        }
    }

    repeat(leftCount) {
        deque.addLast(')')
    }
    println(deque.joinToString(""))
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 33776
import sys
sys.setrecursionlimit(1000000)
def watering(l,a,b):
  if b==a:
    return 0
  if b-a <= 1:
    return l[a]
  
  c = 0
  t = a
  
  mi = min(l[a:b])
  for i in range(a,b):
    l[i] -= mi
    
  for i in range(a,b):
    if l[i]==0:
      c += watering(l,t,i)
      t=i+1
  c += watering(l,t,b)
      
  return c+mi

n = int(input())
h = list(map(int,input().split()))

print(watering(h,0,n))

Measured memory_bytes: 3064
s = gets.chomp

# s = "AtCoder"
# s = "ACoder"
# s = "AcycliC"
# s = "AtCoCo"
# s = "Atcoder"

def accept?(str)
  unless str[0] == "A"
    return false
  end
  # puts "a1"

  c_idx = str.index("C")
  # puts c_idx
  if c_idx.nil? ||  !(2 <= c_idx && c_idx <= str.length - 2)
    return false
  end
  # puts "a2"

  str.slice!(c_idx)
  str.slice!(0)

  unless str == str.downcase
    return false
  end
  # puts "a3"

  return true
end

if accept?(s) == true
  puts "AC"
else
  puts "WA"
end


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

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if((b - 1) % (a - 1) == 0)
    {
        cout << (b - 1) / (a - 1) << endl;
    }
    else if((b - 1) == 1)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << (b - 1) / (a - 1) + 1;

        /*for(int i = 0; i < b; i++)
        {
            if(i * a - (i - 1) >= b)
            {
                cout << i << endl;

                break;
            }
        }*/
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,h,n;cin>>N;
  for(h=1;h<3501;h++){
    for(n=1;n<3501;n++){
      if (4*h*n - N*n - N*h > 0 && N*h*n % (4*h*n - N*n - N*h) == 0) {
                cout << h << " " << n << " " << N*h*n/(4*h*n-N*n-N*h) << endl;
                return 0;
       }
     }
  }
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   
   long long n,x;
   cin>>n>>x;
    cout<<3LL*(n-(__gcd(n, x)))<<'\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
 
int main(){
  string S;
  cin >> S;
  string ans;
  if(S=="Sunny"){ans="Cloudy";}
  else if(S=="Cloudy"){ans="Rainy";}
  else{ans="Sunny";}
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n + 1);
    a[0] = -1;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    vector<int> now(n + 1, 0);
    vector<int> ans;
    for(int i = n; i > 0; --i){
        int sum = 0;
        for(int j = i; j <= n; j += i){
            sum += now[j];
        }
        sum %= 2;
        if(sum == a[i]) continue;
        ans.emplace_back(i);
        ++now[i];
    }
    int sz = ans.size();
    cout << sz << "\n";
    for(int i = 0; i < sz; ++i){
        cout << ans[i];
        cout << ((i == sz - 1) ? "\n" : " ");
    }
}

Measured memory_bytes: 3192
r=range;x,y,z,k=map(int,input().split())
a,b,c=eval("sorted(list(map(int,input().split())),reverse=True),"*3)
abc=[]
for l in r(x):
 for m in r(y):
  if -~l*-~m>k:break
  for n in r(z):
   if -~l*-~m*-~n>k:break
   abc+=[a[l]+b[m]+c[n]]
print(*sorted(abc,reverse=True)[:k])

Measured memory_bytes: 9584
#include<bits/stdc++.h>
using namespace std;
#define ll long long;
int main(){
  int n,m;
  string s[100],t[100];
  cin>>n;
  for(int i=0;i<n;i++)cin>>s[i];
  cin>>m;
  for(int i=0;i<m;i++)cin>>t[i];
  int ans=0;
  for(int i=0;i<n;i++){
    int sum=1;
    for(int j=i+1;j<n;j++)if(s[i]==s[j])sum++;
    for(int j=0;j<m;j++)if(s[i]==t[j])sum--;
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def solve():
    # 標準入力部分
    N = int(input())  # len(person)
    A = []
    x = []
    y = []
    i = 0
    for i in range(N):
        A.append(int(input()))
        x.append([])
        y.append([])
        for j in range(A[i]):
            x_temp, y_temp = list(map(int, input().split()))
            x[i].append(x_temp)
            y[i].append(y_temp)
    
    # N人を正直者，不親切な人と仮定して矛盾せずに存在しうる正直者の最大人数を求める．
    honest_num = 0
    honest_num_new = 0
    for b in range(2**N):
        consistent = True
        case = format(b, '0'+str(N)+'b')
        # 矛盾があるか確認する処理, n-bit目が'1'のとき，n番目の人は正直者
        i = 0
        for i in range(N): # i番目の人の証言を検証
            for z in zip(x[i], y[i]): #z[0]（person[i]）がz[1]（正直者，不親切な人）であるという証言
                if case[i] == "1":
                    if case[z[0]-1] != str(z[1]):
                        consistent = False
        if consistent:
            # 矛盾がないとき，正直者の数を求める処理
            honest_num_new = case.count("1")
        # これまでの最大の人数と比較して，正直者が多いほうを採用
        honest_num = max(honest_num, honest_num_new)
    print(honest_num)



if __name__ == "__main__":
    solve()


Measured memory_bytes: 74096
n, $d = gets.split.map(&:to_i)

def calc_dist(a, b)
    res = 0
    $d.times { |i| res += (b[i] - a[i]) ** 2 }
    return Math.sqrt(res)
end

pos = []
n.times { pos << gets.split.map(&:to_f) }

res = 0

pos.each_with_index do |i, idx_out|
    pos[idx_out..-1].each_with_index do |j, idx_in|
        next if idx_out == (idx_in + idx_out)
        dist = calc_dist(i, j)
        res += 1 if dist == dist.to_i
    end
end

puts res

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstring>

const int MOD=1000000007;
inline void inc(int a,int &b){b=(a+b)%MOD;}

typedef long long ll;
ll qpow(ll a,ll b){ll c=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)c=c*a%MOD;return c;}

ll Num[16];
void GetNum(){Num[1]=9;for(int i=2;i<=15;i++)Num[i]=Num[i-1]*10;}

namespace Worker
{
	ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
	void exgcd(ll a,ll b,ll &x,ll &y){b?exgcd(b,a%b,y,x),y-=x*(a/b):(x=1,y=0);}
	int calc(ll a0,ll a1,ll b0,ll b1,ll x,ll y,ll c)
	{
		ll d=gcd(x,y);
		if(c%d!=0)return 0;
		x/=d,y/=d,c/=d;

		ll oa,ob,L,R;
		exgcd(x,y,oa,ob),oa*=c,ob*=c;

		a0-=oa,a1-=oa,b0=ob-b0,b1=ob-b1;

		L=std::max(a0/y+(a0>0)*(a0%y!=0),b1/x+(b1>0)*(b1%x!=0));
		R=std::min(b0/x-(b0<0)*(b0%x!=0),a1/y-(a1<0)*(a1%y!=0));

		return (L<=R?R-L+1:0)%MOD;
	}
}

namespace Zhidao
{
	const int lim=12;
	ll S;

	int calc(int L,int R)
	{
		ll tmp=0;
		for(int i=L+1;i<R;i++)
			tmp+=Num[i]*i;

		int ret=Worker::calc(1,Num[L],1,Num[R],L,R,S-tmp);

		return ret;
	}

	int calc_p(ll p)
	{
		if(S%p!=0)return 0;
		ll len=S/p;
		if(len>Num[p])return 0;
		return (Num[p]-len+1)%MOD;
	}

	int calc_d(ll len)
	{
		if(len>S/lim)return 1;
		ll p=S/len,num=(qpow(10,p)-qpow(10,p-1))%MOD;
		return (num-len+1)%MOD;
	}

	void solve()
	{
		scanf("%lld",&S);
		int ans=0;
		for(int i=1;i<=lim;i++)
			for(int j=i+1;j<=lim;j++)
				inc(calc(i,j),ans);

		for(int i=1;i<lim;i++)
			inc(calc_p(i),ans);

		inc((S/lim)%MOD,ans);
		
		for(ll i=1;i*i<=S;i++)
			if(S%i==0)
			{
				inc(calc_d(i)-1,ans);
				if(S/i!=i)inc(calc_d(S/i)-1,ans);
			}
		ans=(ans+MOD)%MOD;
		printf("%d\n",ans);
	}
}

int main()
{
	GetNum();
	Zhidao::solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MIN (-(1<<20))
vector<int> dp(5001);
vector<int> v(5001);
int main()
{
	int n;
	while (true) {
		cin >> n;
		if (n == 0) break;
		fill(dp.begin(), dp.end(), MIN);
		for (int i = 0; i < n; ++i) cin >> v[i];
		dp[0] = v[0];
		for (int i = 1; i < n; ++i)
			dp[i] = max(v[i], dp[i-1] + v[i]);
		sort(dp.begin(), dp.begin() + n);
		cout << dp[n-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

// https://atcoder.jp/contests/dp/tasks/dp_a

class Main {
    // Frog 2
    public static int forg2(int[] stones, int K) {
        int[] dp = new int[stones.length];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 1; i < stones.length; i++) {
            for (int j = 1; j <= K; j++) {
                if (i-j >= 0) {
                    dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(stones[i-j] - stones[i]));
                } else break;
            }
        }
        return dp[stones.length-1];
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int K = in.nextInt();

        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = in.nextInt();
        }
        in.close();

        // call function hear
        int ret = forg2(arr, K);
        System.out.println(ret);
    }
}

Measured memory_bytes: 50644
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n, k, s;
        cin >> n >> k >> s;
        if (n == 0 && k == 0 && s == 0) {
            break;
        }

        vector<int> v(n);
        iota(begin(v), end(v), 1);

        int count = 0;

        std::string bitmask(k, 1); // K leading 1's
        bitmask.resize(n, 0);      // N-K trailing 0's

        // print integers and permute bitmask
        do {
            int sum = 0;
            for (int i = 0; i < n; ++i) // [0..N-1] integers
            {
                if (bitmask[i]) {
                    sum += i + 1;
                }

                // std::cout << " " << i;
            }
            if (sum == s) {
                count += 1;
            }
            // std::cout << std::endl;
        } while (std::prev_permutation(bitmask.begin(), bitmask.end()));
        cout << count << endl;
    }
}


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

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

#define end '\n'
#define fi first
#define se second
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a;i<=b;i++)

#define L(x) (x<<1)
#define R(x) ((x<<1)+1)

const int maxN = 200010;

int main() {
	//fast input/output c++
	ios_base::sync_with_stdio(0), cin.tie(NULL);

	ll x, ans = 0LL;
	cin >> x;

	ans = (x / 500)*1000;
	x %= 500;

	ans += (x/5)*5;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;

    scanf("%d",&n);

    if(n/100==7)
    {
        printf("Yes");
    }
    else if(n%10==7)
    {
        printf("Yes");
    }
    else if((n/10)%10==7)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }


}

Measured memory_bytes: 1680
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
//#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const int big=1e8+10;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
int main(void){
	int i,q,n,m;cin>>n>>m;
	vector<int> a(n);
	for(i=0;i<m*2;i++){cin>>q;q--;a[q]++;}
	for(i=0;i<n;i++){if(a[i]%2==1){cout<<"NO"<<endl;return 0;}}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    unsigned long long int n,i,j,min,a[10];
    scanf("%llu",&n);
    scanf("%llu",&a[0]);
    min=a[0];
    for(i=1;i<5;i++)
{
    scanf("%llu",&a[i]);
    if(a[i]<min) min=a[i];
}
if(n%min==0)
    printf("%llu\n",(n/min)+4);
else    printf("%llu\n",(n/min)+5);
return 0;
}


Measured memory_bytes: 128
N, *LR = map(int, open(0).read().split())
L, R = LR[::2], LR[1::2]

Lp = max(L)
Rq = min(R)

A, B = zip(*sorted((max(0, r - Lp + 1), -max(0, Rq - l + 1)) for l, r in zip(L, R)))

mi = float("inf")
ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, Rq - Lp + 1)

for a, b in zip(A[1:], B):
    mi = min(mi, -b)
    ma = max(ma, mi + a)

print(ma)


Measured memory_bytes: 34412
a, b, c, d = map(int, input().split())

if a <= c and c <= b and b <= d:
  print(b-c)
elif c <= a and a <= d and d <= b:
  print(d-a)
elif a <= c and d <= b:
  print(d-c)
elif c <= a and b <= d:
  print(b-a)
else:
  print(0)
  


Measured memory_bytes: 2940
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 1000000007;

#define M 1000000007

vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

ll modpow(const ll a, ll n) {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = (t * t);
    t %= M;
    if (n & 1) t = t * a;
    t %= M;
    return t;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> as(n);
    for (ll i = 0; i < n; ++i) {
        cin >> as[i];
    }
    vector<ll> num(1100000, 0);
    for (ll i = 0; i < n; ++i) {
        cin >> as[i];
        auto pf = prime_factorize(as[i]);
        for (auto p : pf) num[p.first] = max(num[p.first], p.second);
    }

    ll lcm = 1;
    for (int v = 2; v < 1100000; ++v) {
        lcm *= modpow(v, num[v]);
        lcm %= M;
    }

    ll res = 0;
    for (auto a : as) {
        res += lcm * modpow(a, M-2);
        res %= M;
    }
    cout << res << endl;
}


Measured memory_bytes: 8960
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, T = Is()
CT = TIR(n)
ans = INF
for c, t in CT:
    if t <= T:
        ans = min(ans, c)
if ans == INF:
    print('TLE')
else:
    print(ans)

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

using namespace std;

int main() {
	int input[2], numberOfOperations;
	cin >> input[0] >> input[1] >> numberOfOperations;
	bool isFirst = false;

	while (numberOfOperations--) {
		input[isFirst] /= 2;
		input[!isFirst] += input[isFirst];
		isFirst = !isFirst;
	}

	cout << input[0] << " " << input[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  string a; cin >> a;
  ll ans = 0 ;
  rep(i, a.size()){
    if(a[i] == '1')
      ans++;
  }
  cout << ans << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    int r, c, n;
    cin >> r >> c;
    int A[r+1][c+1];
    
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> n;
            A[i][j] = n;
        }
    }
    
    for(int i = 0; i < r; i++){
        int count = 0;
        for(int j = 0; j < c; j++){
            count += A[i][j];
        }
        A[i][c] = count;
    }
    
    
    for(int i = 0; i < c+1; i++){
        int count = 0;
        for(int j = 0; j < r; j++){
            count += A[j][i];
        }
        A[r][i] = count;
    }
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c+1; j++){
            if(j == c){
                cout << A[i][j];
            }
            else{
                cout << A[i][j] << ' ';
            }
        }
        cout << endl;
        
    }
    
    return 0;
}



Measured memory_bytes: 3068
n=int(input())
from collections import deque
d=deque(['a'])
c=[chr(i) for i in range(97, 97+26)]
ans=set([])
while d:
  y=d.pop()
  if len(y)==n:
    ans.add(y)
  now=c.index(sorted(y)[-1])
  for z in range(min(now+2,n+1)):
    if z>-1 and len(y)<n:
      d.append(y+c[z])
for z in sorted(list(ans)):
  print(z)

Measured memory_bytes: 18280
#include <iostream>

using namespace std;

int main(void){
    char a=0;
    char b=0;

    cin >> a >> b;

    if(a=='H')cout << b << endl;
    if(a=='D'){
        if(b=='H')cout << "D" << endl;
        else cout << "H" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<int> l(n+1);
    vector<int> r(n+1);
    for(int i = 0; i < n; i++)
    {
        l[i+1] = gcd(l[i], a[i]);
    }
    for(int i = 0; i < n; i++)
    {
        r[i+1] = gcd(r[i], a[n-i-1]);
    }

    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int g = gcd(l[i], r[n-1-i]);
        ans = max(ans, g);
    }
    cout << ans << endl;
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
using namespace std;
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
  
char s[6];
void solve() {
  if (s[2] == s[3] && s[4] == s[5] ) cout << "Yes";
  else cout << "No";
}
 
void input() {
  cin >> s;
}
 
int main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll bo[200010][100];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll A[N];
    REP(i, 0, N) {
        cin >> A[i];
        A[i]--;
        bo[i][0] = A[i];
    }
    REP(i, 0, 90) {
        REP(j, 0, N) {
            bo[j][i + 1] = bo[bo[j][i]][i];
        }
    }
    ll ans = 0;
    REP(i, 0, 63) {
        if (K & (1LL << i)) {
            ans = bo[ans][i];
        }
    }
    cout << ans + 1 << endl;
}


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

#define MAX_V 305
int graph[MAX_V][MAX_V];
const int INF = 1000000000 + 5;

void warshall_floyd(int N){
    for (int k = 0; k < N; k++){
        for (int i = 0; i < N; i++){
            for (int j = 0; j < N; j++) graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
        }
    }
}

int main(){
    int N, M, L, Q;
    /* N 頂点数*/
    cin >> N;
    N++;
    cin >> M;
    cin >> L;
    int A, B, C;
    fill(graph[0], graph[N], INF);
    for (int m = 0; m < M; m++){
        cin >> A;
        cin >> B;
        cin >> C;
        graph[A - 1][B - 1] = C;
        graph[B - 1][A - 1] = C;

    }
    warshall_floyd(N);
    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++) {
            /*cout << graph[i][j];
            cout << "\t";*/
            if (graph[i][j] <= L){
                graph[i][j] = 1;
            }else{
                graph[i][j] = INF;
            }
        }
    }
    /*for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++) {
            cout << graph[i][j];
            cout << "\t";
        }
        cout << "\n";
    }*/
    warshall_floyd(N);
    /*
    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++) {
            cout << graph[i][j];
            cout << "\t";
        }
        cout << "\n";
    }
    */
    

    cin >> Q;
    int S, T;
    int ans[Q];
    for (int q = 0; q < Q; q++){
        cin >> S;
        cin >> T;
        if (graph[S - 1][T - 1] == INF) ans[q] = -1;
        else ans[q] = graph[S - 1][T - 1] - 1;
    }
    for (int q = 0; q < Q; q++){
        cout << ans[q] << endl;
    }
    return 0;
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    int n,k;
    cin>>n>>k;

    vector<int>p(n);
    rep(i,n)cin>>p[i];


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

    int ans=0;

    rep(i,k)ans+=p[i];

    cout<<ans<<endl;

}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

int a(void);
int b(void);

int main(void) {
	a();
	return 0;
}

int a(void) {
	int N;
	std::cin >> N;
	int res = N * N;
	std::cout << res;
	return 0;
}



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

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

typedef long long ll;

using namespace std;

double Euclid_distance(double x1, double y1, double x2, double y2){
    return sqrt(pow(x1-x2,2)+pow(y1-y2, 2));
}

void solve(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout.precision(10);
    cout << Euclid_distance(x1, y1, x2, y2) << endl;
}

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


Measured memory_bytes: 3316
/*
    And I know I may end up failing too
*/




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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int>pii;

#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF          0x3f3f3f3f

struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};



ll t;
string ss,tt,ans;
ll dp[3005][3005];

ll solve(ll m,ll n)
{
    if(m<=0||n<=0)return 0;
    if(ss[m-1]==tt[n-1])
    {
        if(dp[m][n]==-1)dp[m][n]=1+solve(m-1,n-1);
        return dp[m][n];
    }
    else
    {
        if(dp[m-1][n]==-1)dp[m-1][n]=solve(m-1,n);
        if(dp[m][n-1]==-1)dp[m][n-1]=solve(m,n-1);
        return dp[m][n]=max(dp[m][n-1],dp[m-1][n]);
    }
}
ll d1[]={-1,0};
ll d2[]={0,-1};
void dfs(ll m,ll n,ll k)
{
    ll a,b,i,j;
    if(k==0)return;
    for(i=0;i<2;i++)
    {
        a=m+d1[i];
        b=n+d2[i];
        if(dp[a][b]==k)
        {
            break;
        }
    }
    if(i==2)
    {
        ans+=ss[m-1];
        dfs(m-1,n-1,k-1);
    }
    else dfs(a,b,k);
}

int main()
{
    fast;
    ll a,b,c,d,e,f,g,i,j;
    ll n,k;
    memset(dp,-1,sizeof(dp));
    cin>>ss>>tt;
    a=ss.size();
    b=tt.size();
    f=solve(a,b);
    d=1;
    /*for(i=0;i<=a;i++)
    {
        for(j=0;j<=b;j++)
        {
            cout<<dp[i][j]<<' ';
        }
        cout<<endl;
    }*/
    dfs(a,b,f);
    for(i=f-1;i>=0;i--)
    {
        cout<<ans[i];
    }
    cout<<endl;
}


Measured memory_bytes: 71040
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    int n;
    cin >> n;
    ll a[100002], b[100002];
    ll s[200002];
    P pa[100002], pb[100002];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        s[i * 2] = a[i];
        s[i * 2 + 1] = b[i];
        pa[i] = P(a[i], i);
        pb[i] = P(b[i], i);
    }
    sort(pa, pa + n);
    sort(pb, pb + n);
    sort(s, s + n * 2);
    bool used[100002];
    fill(used, used + n, false);
    int na = 0, nb = 0;
    ll ans = 0;
    int last;
    for(int i = 0; i < n; i++){
        if(pa[na] < pb[nb]){
            ans += pa[na].first;
            used[pa[na].second] = true;
            last = pa[na].second;
            na++;
        }
        else{
            ans += pb[nb].first;
            used[pb[nb].second] = true;
            last = pb[nb].second;
            nb++;
        }
    }
    if(na == 0 || nb == 0){
        cout << ans << endl;
        return 0;
    }
    bool dbl = false;
    for(int i = 0; i < n; i++) dbl |= !used[i];
    if(dbl){
        cout << ans << endl;
        return 0;
    }
    int r;
    if(pa[na].first < pb[nb].first){
        r = pa[na].second;
        na++;
    }
    else{
        r = pb[nb].second;
        nb++;
    }
    if(last != r){
        cout << ans - s[n - 1] + s[n] << endl;
    }
    else{
        cout << ans + min(s[n + 1] - s[n - 1], s[n] - s[n - 2]) << endl;
    }
}

Measured memory_bytes: 6656
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 405;
const int mod = (int) 1e9 + 7;

int n, c;
int a[MAXN], b[MAXN];
long long sum[MAXN][MAXN];
long long p[MAXN];
long long dp[MAXN][MAXN];

long long binpow(long long x, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) {
      res = (res * x) % mod;
      p--;
    } else {
      x = (x * x) % mod;
      p /= 2;
    }
  }
  return res % mod;
}

long long calc(int i, int num) {
  long long &res = dp[i][num];
  if (res != -1) {
    return res;
  }
  res = 0;
  if (i == n - 1) {
    res = sum[i][num];
    return res;
  }
  for (int cur = 0; cur <= num; cur++) {
    long long add = sum[i][cur] * calc(i + 1, num - cur) % mod;
    res = (res + add) % mod;
  }
  return res;
}

int main() { 

  scanf("%d %d", &n, &c);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }

  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j <= b[i]; j++) {
      p[j] = 1;
    }
    for (int j = 0; j <= c; j++) {
      for (int k = a[i]; k <= b[i]; k++) {
        sum[i][j] = (sum[i][j] + p[k]) % mod;
        p[k] = p[k] * k % mod;
      }
    }
  }

  memset(dp, -1, sizeof(dp));

  cout << calc(0, c) << endl;

  return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
int main(void)
{
    int n,s,r[100],i,j,c,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d ",&r[i]);
    }
    for(i=n-1;i>=0;i--)
    {
        for(j=0;j<i;j++)
        {
            if(r[j]>r[j+1])
            {
                c = r[j];
                r[j] = r[j+1];
                r[j+1] = c;
                cnt++;
            }
        }
    }
    for(i=0;i<n-1;i++)
    {
        printf("%d ",r[i]);
    }
    printf("%d\n%d\n",r[i],cnt);
    return 0;
}


Measured memory_bytes: 2148
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int[] ary = new int[5];
		for (int i = 0; i < 5; i++) {
			ary[i] = si();
		}
		Arrays.sort(ary);
		for (int i = 4; i >=0 ; i--) {
			out.print(ary[i] + (i==0 ? "" : " "));
		}
		out.println();
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 17156