akhauriyash/Code-Regression huggingface dataset:
L,R=map(int, raw_input().split())
a=L%2019
b=R%2019

T=[]
ans=float("inf")
if a<b:
	T=range(a,b+1)
	if R-L>2018:
		print 0
		quit()
	else:
		l=len(T)
		for i in range(l):
			for j in range(i+1,l):
				ans=min(ans, (T[i]*T[j])%2019 )

		print ans
else:
	print 0
	quit()



Measured memory_bytes: 30700
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
#define REP(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
const lli mod = 1e9 +7;

lli modfact(lli n){
    lli ret =1;
    for(int i=2; i<=n; i++) ret = ret*i %mod;
    return ret;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    vector<vector<lli> > dp(1<<8, vector<lli>(101, 0));
    dp[0][0] = 1;
    REP(i, n){
        vector<vector<lli> > next(1<<8, vector<lli>(101, 0));
        REP(j, 1<<8){
            int bit = j^a[i];
            REP(k, i+1){
                next[bit][k+1] = (next[bit][k+1] +dp[j][k])%mod;
                next[j][k] = (next[j][k] +dp[j][k])%mod;
            }
        }
        dp = next;
    }

    lli ans = 0;
    REP(i, 101){
        ans = (ans + dp[k][i]*modfact(i))%mod;
    }
    cout << ans << endl;
    return 0;
}


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

class Solve {
private:
public:
    bool is_last_;
    Solve()
    {
        int n;
        std::cin >> n;
        if (n == 0)
        {
            is_last_ = true;
            return;
        }
        std::vector<int> k(n);
        for (auto& e: k) std::cin >> e;
        std::string s;
        std::cin >> s;
        for (int i{}; i < (int)s.size(); i++)
        {
            int p{(52 - k[i % n])};
            if ('a' <= s[i] && s[i] <= 'z')
                p += s[i] - 'a';
            else
                p += s[i] - 'A' + 26;
            p %= 52;
            if (p < 26) putchar('a' + p);
            else putchar('A' + p - 26);
        }
        putchar('\n');
    }
};

int main()
{
    while (!Solve().is_last_);
}


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

const long long INF = 1LL << 60;

int N, a[3009];

long long dp[3009][3009];

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> a[i];

    for(int bit = 0; bit < N; bit++) {
        for(int l = 1; l + bit <= N; l++) {
            int r = l + bit;
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }

    cout << dp[1][N] << endl;

    return 0;
}

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

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

    if (n == 2) {
	if (s[0] == s[1])
	    cout << 1 << " " << 2 << endl;
	else
	    cout << -1 << " " << -1 << endl;
	return 0;
    }

    bool tf = false;
    for (int i = 0; i < n - 1; i++) {
	if (s[i] == s[i + 1]) {
	    cout << i + 1 << " " << i + 2 << endl;
	    tf = true;
	    break;
	} else if ((s[i] == s[i + 2]) && (i + 1 < n)) {
	    cout << i + 1 << " " << i + 3 << endl;
	    tf = true;
	    break;
	}
    }
    if (!tf)
	cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ll n, m;
  cin >> n >> m;

  vP ps(n);
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    ps[i] = P(a, b);
  }

  Sort(ps);
  ll cnt = m;
  ll ans = 0;
  for (ll i = 0; i < (ll)ps.size(); i++) {
    if(ps[i].second <= cnt){
      ans += ps[i].first * ps[i].second;
      cnt -= ps[i].second;
    } else {
      ans += ps[i].first * cnt;
      cnt = 0;
    }
    if (cnt == 0) break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]*(n+1)
for i in reversed(range(1,n+1)):
    if sum(b[i::i])%2!=a[i]:
        b[i]=1
print(sum(b))
for i,j in enumerate(b):
    if j==1:
        print(i,end=' ')

Measured memory_bytes: 8756
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0

for i in range(0, n):
    a_no = a[i] - 1
    ans += b[a_no]
    if 0 < i and i < n:
        if a[i] == a[i - 1] + 1:
            ans += c[a_no - 1]
print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}

int main() {
ll N;
cin>>N;
ll m=N-1;
vector<ll>a(m);
if(N==2){
ll s;
cin>>s;
cout<<'1'<<endl;
cout<<'0'<<endl;}
else{
rep(i,m){
    cin>>a[i];
}
vector<ll>cnt(N);
rep(j,m){cnt[a[j]]++;}

for(ll i=1;i<N;i++){
    cout<<cnt[i]<<endl;
}
cout<<'0'<<endl;}
return 0;
}

Measured memory_bytes: 6424
#include <stdio.h>
int main() {
	int num,i;
	char c1[101];
	char c2[101];
	char c3[202];
	scanf("%d",&num);
	scanf("%s %s",&c1,&c2);
	for(i=0;i<num;i++) {
		c3[2*i]=c1[i];
		c3[2*i+1]=c2[i];
	}
  	c3[2*num]='\0';
	printf("%s",c3);
	return 0;
}

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

int main() {
  int n;

  cin >> n;

  int a = 0;
  int b = n;
  while (b > 0) {
    a += b % 10;
    b /= 10;
  }

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,i;
  int a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a%2==0){
      if(a%3==0||a%5==0){
        continue;
      }else{
        printf("DENIED\n");
        return 0;
      }
    }
  }
  printf("APPROVED\n");
  return 0;
}


Measured memory_bytes: 128
using System;

namespace A___One_Card_Poker
{
    class Program
    {
        static void Main(string[] args)
        {
            var A_B = Console.ReadLine().Split();
            var index = new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 };
            int A = int.Parse(A_B[0]), B = int.Parse(A_B[1]);

            Console.WriteLine(A == B ? "Draw" : Array.IndexOf(index, A) > Array.IndexOf(index, B) ? "Alice" : "Bob");
        }
    }
}


Measured memory_bytes: 13140
use strict;
use warnings;

my $N = <>;
my %S = ();

while (<>) {
    if (not exists($S{$_})) {
        $S{$_} = 0;
    }
    $S{$_}++;
}

my @S = map {[ $_, $S{$_} ]} keys %S;
@S = sort {$b->[1] <=> $a->[1] or $a->[0] cmp $b->[0]} @S;

my $max = $S[0][1];

foreach (@S) {
    if ($_->[1] != $S[0][1]) {
        last;
    }
    print($_->[0]);
}


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

using namespace std;

const int MAXN = 100005;

int n, k, a[MAXN];

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

    int ans = 0;
    for(int i = 0; i < n; ++i)
        ans += (a[i] >= k);

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 640
s=input()
k=s[::-1]
c=0
if s==k:
    c+=1
f=((len(s)-1)//2)

s1=s[0:f]
#print(s1)
s1p=s1[::-1]
if s1==s1p:
    c+=1
f1=(((len(s)+3)//2)-1)
s2=s[f1:]
#print(s2)
s2p=s2[::-1]
if s2==s2p:
    c+=1
if c==3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int n;
int a[3010];
int dp[3010][3010];
bool vis[3010][3010];

int solve(int l, int r) {
	if (vis[l][r]) {
		return dp[l][r];
	}
	if (l == r) {
		vis[l][r] = true;
		return 0;
	}
	if (n % 2 == (r - l) % 2) {
		vis[l][r] = true;
		return dp[l][r] = max(solve(l, r - 1) + a[r - 1], solve(l + 1, r) + a[l]);
	}
	else {
		vis[l][r] = true;
		return dp[l][r] = min(solve(l, r - 1) - a[r - 1], solve(l + 1, r) - a[l]);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	cin >> n;
	rep(i, n) cin >> a[i];
	cout << solve(0, n) << endl;
}

Measured memory_bytes: 78592
import sys
r = [0]*100000
n,k = [int(x) for x in sys.stdin.readline().split()]
for i in range(n):
	a, b = [int(x) for x in sys.stdin.readline().split()]
	r[a-1] += b
c = 0
for i,j in enumerate(r):
	c += j
	if c >= k:
		print(i+1)
		break

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

int main() {
    double n,d;
    cin >> n >> d;
    
    vector<vector<int>> data(n, vector<int>(d));
    rep(i,n) {
     rep(j,d) {
      cin >> data.at(i).at(j);
     }
    }
    
        int count = 0;
    
    rep(i, n - 1) {
     for(double j = i; j < n - 1;j++) {
             
        double dist = 0;
        rep(k, d) {
         dist += ((data.at(i).at(k) - data.at(j + 1).at(k)) * (data.at(i).at(k) - data.at(j + 1).at(k)));
        } 
             if(sqrt(dist) == int(sqrt(dist))){
              count++;
             }
     
      }
    }
 cout << count;
}

Measured memory_bytes: 3772
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
  end

  def solve
    return [0] if n.zero?
    
    ans = []
    while @n != 0
      bit = @n % 2
      ans << bit
      @n = (@n - bit) / -2
    end
    ans
  end

  def show(ans)
    puts ans.join.reverse
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14364
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	if (a % 2 == b % 2) {
		cout << abs(a - b) / 2 << "\n";
	} else {
		ll opt1 = 0, opt2 = 0;
		const ll nafter = abs(a - b) / 2;
		opt1 = (min(a, b) - 1) + 1 + nafter;
		opt2 = (n - max(a, b)) + 1 + nafter;
		cout << min(opt1, opt2) << "\n";
	}
	return 0;
}


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

int main() {
	deque<ll> D;
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int p;
		cin >> p;		
		if (p == 0) {
			int d;
			cin >> d;
			if (d == 0) {
				ll x;
				cin >> x;
				D.push_front(x);
			}
			else {
				ll x;
				cin >> x;
				D.push_back(x);
			}			
		}
		else if (p == 1) {
			ll p;
			cin >> p;
			cout << D[p] << endl;
		}
		else if (p == 2) {
			int d;
			cin >> d;
			if (d == 0) {
				D.pop_front();
			}
			else {
				D.pop_back();
			}
		}
	}
}



Measured memory_bytes: 6320
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n, m;
    scan(n, m);

    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int ui, vi, ci;
        scan(ui, vi, ci);
        adj[ui] ~= Edge(vi, ci, adj[vi].length.to!int);
        adj[vi] ~= Edge(ui, 0, adj[ui].length.to!int - 1);
    }

    int ans = FordFulkerson(adj, 0, n - 1);

    writeln(ans);
}


alias Edge = Tuple!(int, "to", int, "cap", int, "rev");
immutable inf = 10^^9 + 7;

int FordFulkerson(Edge[][] adj, int s, int t) {
    int n = adj.length.to!int;
    auto visited = new bool[](n);

    int dfs(int u, int f) {
        if (u == t) {return f;}

        visited[u] = 1;

        foreach (ref e ; adj[u]) {
            if (!visited[e.to] && e.cap > 0) {
                int d = dfs(e.to, min(f, e.cap));

                if (d > 0) {
                    e.cap -= d;
                    adj[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }

        return 0;
    }

    int F;

    while (true) {
        visited[] = 0;
        int f = dfs(0, inf);
        if (!f) break;
        F += f;
    }

    return F;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int main(){
  int n;
  cin >> n;
  int t[n+1],x[n+1],y[n+1];
  t[0]=x[0]=y[0]=0;
  int i,j;
  for(i=1;i<=n;i++){
    cin >> t[i] >> x[i] >> y[i];
    if(t[i]%2 != (x[i]+y[i])%2){
      cout << "No" << endl;
      return 0;
    }else{
      if(abs(t[i]-t[i-1])<abs(x[i]-x[i-1])+abs(y[i]-y[i-1])){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1408
n = int(input())
p = [int(i) for i in input().split()]
ctn = 0
for j in range(1, n-1):
    if p[j - 1] < p[j] < p[j + 1] or p[j + 1] < p[j] < p[j - 1]:
        ctn += 1
print(ctn)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll dp[ 10005 ][ 105 ][ 2 ];
string s;
ll d;
ll solve(ll pos, ll sum, bool tight) {
	if (pos == s.length())
		return sum == 0;
	if (dp[pos][sum][tight] != -1)
		return dp[pos][sum][tight];
	ll ans = 0;
	ll end = ((tight) ? (s[pos] - '0') : 9);
	for (ll i = 0; i <= end; i++) {
		ans = (ans + solve(pos + 1, (sum + i) % d, tight & (i == end))) % mod;
	}
	return dp[pos][sum][tight] = ans;
}
int main() {
	cin >> s;
	cin >> d;
	memset(dp, -1, sizeof dp);
	cout << (solve(0, 0, 1) - 1 + mod) % mod << endl;
}


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

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

	int sum = 0;
	rep(i, n){
		int d;
		cin >> d;
		sum += d;
	}

	if(h <= sum) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P,int>PP;

signed main() {
	int n, a, b; cin >> n >> a >> b;
	if ((b - a) %2==0)cout << (b-a)/2 << endl;
	else {
		int res = a+(-1+b-a)/2;
		int res2 = n - b + 1+(b - a - 1) / 2;

		cout << min(res,res2) << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;

inline int my_stoi(const string &S) {
    int res = 0;
    for (auto it = S.begin(); it != S.end() && isdigit(*it); ++it) {
        res = res * 10 + (*it) - '0';
    }
    return res;
}

int dfs(string S) {
    vector<int> vec;
    S = S.substr(1, S.length() - 2);
    if (isdigit(S[0])) {
        return my_stoi(S) / 2 + 1;
    }
    const int L = S.length();
    int rank = 0;
    int left = 0;
    for (int i = 0; i < L; ++i) {
        if (S[i] == '[') ++rank;
        if (S[i] == ']') --rank;
        if (rank == 0) {
            vec.emplace_back(dfs(S.substr(left, i - left + 1)));
            left = i + 1;
        }
    }
    sort(begin(vec), end(vec));
    // for (int i = 0; i < vec.size(); ++i) {
    //     cerr << vec[i] << " ";
    // }cerr << endl;
    return accumulate(vec.begin(), vec.begin() + vec.size() / 2 + 1, 0);
}

void solve() {
    string S;
    cin >> S;
    cout << dfs(S) << endl;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

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

int main() {
  int n,k; cin >> n >> k;
  int height[n+k];
  for (int i = 0; i < n; i++) cin >> height[i+k];
  for (int i = 0; i < k; i++) height[i] = height[k];
  
  int dp[n+k]; dp[k] = 0;
  for (int i = 1; i < n; i++) dp[i+k] = dp[i+k-1] + abs(height[i+k]-height[i+k-1]); 
   for (int i = 0; i < k; i++) dp[i] = dp[k];
  for (int i = 1; i < n; i++)
    for (int j = 1; j <= k; j++)
      dp[i+k] = min(dp[i+k], dp[i+k-j] + abs(height[i+k]-height[i+k-j])); 
  cout << dp[n+k-1] << endl;
}

Measured memory_bytes: 1024
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;


       cin>>n>>k;

       n--;

       ans=k;

       while(n--)ans*=(k-1);

       cout<<ans<<endl;









}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,c=0,s=0,p=0,ans=0;

cin>>a;
s=a;

c=s/500;
s=s%500;
p= s/5;
s=s%5;
//cout<<s<<endl;
//cout<<c<<" "<<p<<endl;
ans=c*1000+p*5;
cout<<ans<<endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=5005;
int n,A,B,a[N];
ll f[N];
int main(){
	scanf("%d%d%d",&n,&A,&B);
	For(i,1,n) scanf("%d",&a[i]);
	For(i,1,n) f[i]=1ll<<60;
	For(i,1,n){
		ll S=0;
		Rep(j,i-1,1){
			if (a[j]<a[i])
				f[i]=min(f[i],f[j]+S);
			S+=(a[j]<a[i]?B:A);
		}
		f[i]=min(f[i],S);
	}
	ll ans=1ll<<60;
	For(i,1,n){
		ll S=0;
		For(j,i+1,n)
			S+=(a[j]<a[i]?B:A);
		ans=min(ans,f[i]+S);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include<iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {

	int a, b, c,d,no;
	int result[1000];

	cin >> no;
	for (int i = 0; i < no; i++) {
		cin >> a >> b >> c;

		d = a;
		if (d < b)
			d = b;
		if (d < c)
			d = c;

		if (d == a) {
			if (a*a == b*b + c*c)
					result[i] = 1;
			else result[i]= 0;
			}
		else if (d == b) {
			if (b*b == a*a + c*c)
				result[i] = 1;
			else result[i] = 0;
		}
		else {
			if (c*c == a*a + b*b)
				result[i] = 1;
			else result[i] = 0;
		}
	}


	for (int i = 0; i < no; i++) {
		if (result[i] == 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;

}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define MAX 100000

int main(){
    int n,m,g=0,k=0;
    char a[50][50],b[50][50];
    bool flag=1;
    cin>>n>>m;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,m){
        cin>>b[i];
    }
    rep(i,n){
        rep(j,n-m+1){
            if(a[i][j]==b[g][k]){
                for(k;(k+1)*(g+1)!=m*m;k++){
                    if(k==m){
                        g++, k=0;
                    }
                    if(b[g][k]!=a[i+g][j+k])flag=0;
                }
                if(flag){
                    cout<<"Yes"<<endl;
                    return 0;
                }
                else flag=1,g=0,k=0;
            }
        }    
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main(){
  int n,a,b,z=0,x=0;
  string s;
  cin>>n>>a>>b;
  cin>>s;
  for(int i=0;i<s.size();i++){
	if(s[i]=='a'){
      if(a+b>x){
        cout<<"Yes\n";
        x++;
      }else{
        cout<<"No\n";
      }
    }else if(s[i]=='b'){
      if(a+b>x && b>z){
        cout<<"Yes\n";
        x++;
        z++;
      }else{
        cout<<"No\n";
      }
    }else{
      cout<<"No\n";
    }
  }
}

Measured memory_bytes: 896
N = int(input())
H = list(map(int, input().split()))

fl = True
for i in range(1,N):
    if H[i]-H[i-1]>0:
        H[i] -= 1

for i in range(1,N):
    if H[i]-H[i-1]<0:
        fl = False
        break

print('Yes') if fl else print('No')


Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, k, d, a, ans = 0;
bool flag[101] = {};

int main() {
	cin >> n >> k;
	rep(i, k) {
		cin >> d;
		rep(j, d) {
			cin >> a;
			flag[a] = true;
		}
	}
	rep(i, n) {
		if (!flag[i + 1])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    int main(){
    ll int x;
     cin>>x;
     if(x%2==0){
         cout<<"-1"<<endl;
     }
     else{
     int a=7;
    // ll b=x;
     int flag=0;
     for(ll i=1; i<=(ll)1e7;i++){
         if(a%x==0){
             cout<<i;
             flag=1;
             break;}
              a=((a*10)%x +7)%x;
         }
         if(flag==0){
             cout<<-1;}

         
     }

     }

        
        
    

Measured memory_bytes: 3624
#include<stdio.h>
#define MAX 100001

int X,Y,Z;
int check(int ans)
{
    if ((unsigned long long)Y * ans + Z * (ans + 1) <= X)
        return 1;
    else
        return 0;
}

int upper_bound(int left, int right)
{
    if (right - left == 1)
        return left;
    int mid = left + (right - left) / 2;
    if (check(mid))
        return upper_bound(mid, right);
    else
        return upper_bound(left, mid);
}


int main()
{
    scanf("%d %d %d", &X, &Y, &Z);
    // [1 MAX)
    int ans = upper_bound(-1, MAX);
    if (ans <= 0)
        printf("0\n");
    else
        printf("%d\n", ans);
}


Measured memory_bytes: 1680
n = int(input())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
print(dp[-1])

Measured memory_bytes: 52208
#include "bits/stdc++.h"

typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
ll x;
signed main() {
	cin >> x;
	ll ans = 0;
	rep(i,1000000) {
		ans += i;
		if (ans >= x) {
			cout << i << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		scan.close();
		System.out.println((a == b && b != c || a == c && b != c || c == b && b != a)? "Yes":"No");
	}
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    double x1,y1,x2,y2,x3,y3,xp,yp;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
    //printf("%lf %lf %lf %lf %lf %lf %lf %lf\n",x1,y1,x2,y2,x3,y3,xp,yp);
        //printf("%s\n",(((x2-x1)*(y2-yp)-(y2-y1)*(x2-xp)>0)==((x3-x2)*(y3-yp)-(y3-y2)*(x3-xp)>0)==((x1-x3)*(y1-yp)-(y1-y3)*(x1-xp)>0))?"YES":"NO");
        //if((((x2-x1)*(y2-yp)-(y2-y1)*(x2-xp)>0)==true)&&(((x3-x2)*(y3-yp)-(y3-y2)*(x3-xp)>0)==true)&&(((x1-x3)*(y1-yp)-(y1-y3)*(x1-xp)>0)==true)){
        //printf("%lf %lf %lf\n",(x2-x1)*(y2-yp)-(y2-y1)*(x2-xp),(x3-x2)*(y3-yp)-(y3-y2)*(x3-xp),(x1-x3)*(y1-yp)-(y1-y3)*(x1-xp));
        if(((x2-x1)*(y2-yp)-(y2-y1)*(x2-xp)>0)&&((x3-x2)*(y3-yp)-(y3-y2)*(x3-xp)>0)&&((x1-x3)*(y1-yp)-(y1-y3)*(x1-xp)>0)){
            printf("YES\n");
        }else if(((x2-x1)*(y2-yp)-(y2-y1)*(x2-xp)<0)&&((x3-x2)*(y3-yp)-(y3-y2)*(x3-xp)<0)&&((x1-x3)*(y1-yp)-(y1-y3)*(x1-xp)<0)){
            printf("YES\n");
        }else{
            printf("NO\n");
        }

    }
    return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define N 100010
typedef pair<ll,ll> P;
vector<P> v;
ll n,a[N];
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(int i=1;i<n-1;i++){
      if(a[i]<0)continue;
      v.push_back(make_pair(a[0],a[i]));
      a[0]=a[0]-a[i];
  }
  for(int i=1;i<n-1;i++){
      if(a[i]>=0)continue;
      v.push_back(make_pair(a[n-1],a[i]));
      a[n-1]=a[n-1]-a[i];
  }
  v.push_back(make_pair(a[n-1],a[0]));
  cout<<a[n-1]-a[0]<<endl;
  for(int i=0;i<n-1;i++){
      cout<<v[i].first<<" "<<v[i].second<<endl;
  }
  return 0;
}


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

int main() {
  int r;
  cin >> r;
  if(r < 1200){
    cout << "ABC" <<endl;
  }
  else if(r >= 1200 && r < 2800){
    cout << "ARC" <<endl;
  }
  else{
    cout << "AGC" <<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;


int main(void) {
    int A, B, T;
    cin >> A >> B >> T;
    int num = T / A;
    int ans = num * B;
    cout << ans << endl;
    return 0;  
}

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

#define mp              make_pair
#define pb              push_back

#define ff              first
#define ss              second

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    
    int A[n];
    for(int i=0; i<n; ++i)
        cin >> A[i];
    
    int total = 0;
    for(int i=0; i<n; ++i)
        for(int j=0; j<i; ++j)
            total += A[i]*A[j];
    
    cout << total << "\n";
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  ll X, Y;
  scanf("%lld %lld", &X, &Y);
  int ans = 0;
  ll val = X;
  while (val <= Y) {
    ++ans;
    val *= 2;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		int[] c = new int[n];
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
		List<Integer>[] lists = new List[n];
		for (int i = 0; i < n; i++)
			lists[i] = new ArrayList<Integer>();
		for (int i = 0; i < k; i++) {
			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;
			lists[a].add(b);
			lists[b].add(a);
		}
		PriorityQueue<Point> pq = new PriorityQueue<Point>();
		pq.offer(new Point(0, 0, 0));
		boolean[][] v = new boolean[n][n];
		while (!pq.isEmpty()) {
			Point p = pq.poll();
			if (p.b == n - 1) {
				System.out.println(p.cost);
				return;
			}
			if (v[p.a][p.b])
				continue;
			v[p.a][p.b] = true;

			pq.offer(new Point(p.cost + c[p.b], r[p.b], p.b));
			if (p.a > 0)
				for (int x : lists[p.b]) {
					pq.offer(new Point(p.cost, p.a - 1, x));

				}

		}
	}

	class Point implements Comparable<Point> {
		int cost, a, b;

		@Override
		public String toString() {
			return "Point [cost=" + cost + ", a=" + a + ", b=" + b + "]";
		}

		public Point(int cost, int a, int b) {
			super();
			this.cost = cost;
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Point o) {
			if (cost == o.cost)
				return o.b - b;
			return cost - o.cost;
		}
	}
}

Measured memory_bytes: 77484
from bisect import bisect_left, bisect_right
n = int(input())
*a, = sorted(map(int, input().split()))
*b, = sorted(map(int, input().split()))
*c, = sorted(map(int, input().split()))

ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])*(n-bisect_right(c, b[i])))
print(ans)


Measured memory_bytes: 23232
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

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

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n, d;
    cin >> n >> d;
    int cnt = 0;
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= ll(d) * d) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
typedef long long ll;
#define equ(a,b) ((fabs((a)-(b)))<(eps))
#define more(a,b) (((a)-(b))>(eps))
#define less(a,b) (((a)-(b))<(-eps))
#define inf 0x3f3f3f3f

int main(){
    string s;
    ll n;
    cin>>n;
    while(n){
        n--;
        char a=97+(n)%26;
        s+=a;
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)
#define chmax(x, a)  do { x = max(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

// x < 3 * 10^5
ll f(ull x) {
  static vector<ll> memo(300000, -1);
  if (x == 0)
    return 0;
  if (memo[x] != -1)
    return memo[x];

  ll popcnt = 0;
  rep(i, 30)
    if ((x >> i) & 1)
      popcnt++;
  return memo[x] = 1 + f(x % popcnt);
}

ll ans[300000];

int main(void) {
  ll N;
  string s;
  cin >> N >> s;
  reverse(begin(s), end(s));
  ll popcnt = 0;
  for (auto c : s)
    if (c == '1')
      popcnt++;
  ll orig_p = 0, orig_m = 0;
  ll ten_p = 1, ten_m = 1;
  rep(i, N) {
    if (s[i] == '1') (orig_p += ten_p) %= popcnt + 1;
    if (s[i] == '1' && popcnt > 1) (orig_m += ten_m) %= popcnt - 1; // popcnt > 1
    (ten_p *= 2) %= popcnt + 1;
    if (popcnt > 1) (ten_m *= 2) %= popcnt - 1;
  }

  ten_p = 1, ten_m = 1;
  rep(i, N) {
    ll nxt;
    if (s[i] == '0') {
      nxt = (popcnt + 1 + orig_p + ten_p) % (popcnt + 1);
    }
    if (s[i] == '1') {
      if (popcnt == 1) { ans[i] = 0; continue; }
      if (popcnt > 1) nxt = (popcnt - 1 + orig_m - ten_m) % (popcnt - 1); // popcnt > 1
    }
    ans[i] = 1 + f(nxt);
    (ten_p *= 2) %= popcnt + 1;
    if (popcnt > 1) (ten_m *= 2) %= popcnt - 1;
  }
  for (ll i = N - 1; i >= 0; i--) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 7616
import Control.Monad
import Data.List
import Control.Applicative

readPair :: IO (Double, String)
readPair = do
  [n, s] <- words <$> getLine
  let num = read n :: Double
  return (num, s)

f :: Double -> (Double, String) -> Double
f acc (d, s)
  | s == "JPY" = d + acc
  | otherwise  = d * 380000.0 + acc

main :: IO ()
main = do
  n <- readLn :: IO Int
  ylist <- replicateM n readPair
  print $ foldl f 0.0 ylist


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

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

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

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    int x,y;
    cin>>x>>y;
    string ans="No";
    if(y%2==0){
        if(y>=2*x&&y<=4*x){
            ans="Yes";
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3828
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    string s;
    cin >> s;

    int n = s.size();
    vector<int> a(n+1, 0);

    for (int i=0; i<n; i++) {
        if (s[i] == '<') a[i+1] = a[i] + 1;
    }

    for (int i=n-1; 0<=i; i--) {
        if (s[i] == '>' and a[i] <= a[i+1]) a[i] = a[i+1] + 1;
    }

    long long ans = 0;
    for (int ai: a) {
        ans += ai;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2820
#include<stdio.h>

int main()
{
    int a,x=1,b,i=0;

    scanf("%d",&a);

    int A[a];

    while(i<a){
        scanf("%d",&A[i]);
        i++;
    }

    b=A[0];
    i=1;

    while(i<a){

        if(A[i]<b)
        {
            b=A[i];
            x++;

        }

        i++;
    }

    printf("%d\n",x);

    return 0;
}


Measured memory_bytes: 2504
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, d) = (v[0], v[1]);
    let mut points = vec![];
    for i in 0..n {
        let v = read_vec::<i64>();
        points.push(v);
    }
    let mut ans = 0;
    for i in 0..n {
        for j in i + 1..n {
            let dist = points[i]
                .iter()
                .zip(points[j].iter())
                .map(|(&y1, &y2)| (y1 - y2) * (y1 - y2))
                .sum::<i64>();
            for i in 1..1000 {
                if i * i == dist {
                    ans += 1;
                    break;
                }
            }
        }
    }
    println!("{}", ans);
}

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

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


Measured memory_bytes: 2144
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Info{
	Info(ll arg_sum,ll arg_num){
		sum = arg_sum;
		num = arg_num;
	}
	bool operator<(const struct Info &arg) const{

		return sum*arg.num > arg.sum*num;
	}

	ll sum,num;
};


ll N,A,B;
ll value[55];
ll dp[55],num[55];


int main(){

	scanf("%lld %lld %lld",&N,&A,&B);

	for(ll i = 0; i < N; i++){

		scanf("%lld",&value[i]);
	}

	if(N == 1){

		printf("%.10lf\n",value[0]);
		printf("1\n");
		return 0;
	}

	//dp[数字の使用個数] = 最大値
	for(ll i = 0; i <= N; i++){
		dp[i] = 0;
	}
	for(ll i = 0; i <= N; i++){

		num[i] = 0;
	}

	num[0] = 1;

	for(ll i = 0; i < N; i++){
		for(ll k = i; k >= 0; k--){
			if(num[k] == 0)continue;

			ll tmp = dp[k]+value[i];

			if(tmp > dp[k+1]){

				dp[k+1] = tmp;
				num[k+1] = num[k];

			}else if(tmp == dp[k+1]){

				num[k+1] += num[k];
			}
		}
	}

	vector<Info> V;
	for(ll i = A; i <= B; i++){

		V.push_back(Info(dp[i],i));
	}
	sort(V.begin(),V.end());

	ll ans = num[V[0].num];

	for(ll i = 1; i < V.size(); i++){

		if(V[i-1].sum*V[i].num == V[i].sum*V[i-1].num){

			ans += num[V[i].num];

		}else{

			break;
		}
	}

	printf("%.10lf\n",(double)V[0].sum/(double)V[0].num);
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

int N;

int H[MAX_N], dp[MAX_N];

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

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    dp[0] = 0;
    dp[1] = abs(H[1] - H[0]);
    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]));
    }

    cout << dp[N - 1] << "\n";

    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li a, b, c;
    cin >> a >> b >> c;
    cout << (c / a)*b << endl;


    return 0;
}

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

int L;
vector < tuple <int, int, int> > edges;

int main() {
	cin >> L;
	int lg = 31 - __builtin_clz(L), n = lg + 1;
	for (int i = 1, j = n - 2; j >= 0; --j, ++i) {
		edges.emplace_back(i, i + 1, 0);
		edges.emplace_back(i, i + 1, 1 << j);
		if (L >> j & 1) edges.emplace_back(1, lg - j + 1, L >> (j + 1) << (j + 1));
	}
	cout << n << " " << edges.size() << "\n";
	for (auto it : edges) {
		int u, v, w; tie(u, v, w) = it;
		cout << u << " " << v << " " << w << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,l,i;
   cin>>n>>l;
   vector<string>str(n);
   for(i=0;i<n;i++)
   {
     cin>>str[i];
   }
   sort(str.begin(),str.end());
   for(i=0;i<n;i++)
   {
     cout<<str[i];
   }
   cout<<endl;
   return 0;
}

Measured memory_bytes: 3596
data = [0]*3
c = [[0,0,0],[0,0,0],[0,0,0]]
a = [[0,0,0],[0,0,0],[0,0,0]]
flag = 0

for i in range(3):
    data[i] = input("")
    for j in range(3):
        c[i][j] = int(data[i].split(" ")[j])
for i in range(1,3):
    for j in range(3):
        a[i][j] = c[i][j] - c[0][j]
    for j in range(1,3):
        if a[i][j] != a[i][j-1]:
            print("No")
            flag = 1
            break
    if flag != 0:
        break
if flag == 0:
    print("Yes")

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

int main(){
    long long n;
    cin >> n;

    bool odd = false;
    for(long long i = 0; i < n; i++){
        long long a;
        cin >> a;
        if(a % 2 != 0){
            odd = true;
        }
    }

    if(odd == true){
        printf("first\n");
    }
    else{
        printf("second\n");
    }
    return 0;
}

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

int main(){
    long count = 0;
    int N, current_hight=0, previous_hight=0, fa;
    cin >> N >> fa;
    previous_hight = fa;
    for (int i = 1; i < N; i++){
        cin >> current_hight;
        if (current_hight<previous_hight) 
            count += previous_hight - current_hight;
        else 
            previous_hight = current_hight;
    }
    cout << count << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    int N;

    cin >> N;
    
    long long A[N];

    long long mul = 1;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    for (int i = 0; i < N; i++) {
        if (A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < N; i++) {
        if (A[i] <= 1000000000000000000 / mul) {
            mul *= A[i];
        } else {
            cout << -1 << endl;

            return 0;
        }
    }

    cout << mul << endl;

    return 0;
}


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

using namespace std;


int main()
{
    int N;
    int tmp, sum = 0;
    vector<int> c, v;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> tmp;
        v.push_back(tmp);
    }
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        c.push_back(tmp);
    }

     for (int i = 0; i < N; i++) {
        if (v[i] - c[i] > 0) {
            sum+= v[i] - c[i];
        }
    }

    cout << sum << endl;



   
    return 0;   
};




Measured memory_bytes: 256