akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mod=1e9+7;

int fn(int A[], int n, int k) 
{ 
    // sorting given input array 
    sort(A, A + n); 
  
    // variable to store final product of all element 
    // of sub-sequence of size k 
    int product = 1; 
  
    // CASE I 
    // If max element is 0 and 
    // k is odd then max product will be 0 
    if (A[n - 1] == 0 && (k & 1)) 
        return 0; 
  
    // CASE II 
    // If all elements are negative and 
    // k is odd then max product will be 
    // product of rightmost-subarray of size k 
    if (A[n - 1] <= 0 && (k & 1)) { 
        for (int i = n - 1; i >= n - k; i--) {
            product *= A[i]; 
            product%=mod;
            product=(product+mod)%mod;
        }
        return product; 
    } 
  
    // else 
    // i is current left pointer index 
    int i = 0; 
  
    // j is current right pointer index 
    int j = n - 1; 
  
    // CASE III 
    // if k is odd and rightmost element in 
    // sorted array is positive then it 
    // must come in subsequence 
    // Multiplying A[j] with product and 
    // correspondingly changing j 
    if (k & 1) { 
        product *= A[j]; 
        product%=mod;
        product=(product+mod)%mod;
        j--; 
        k--; 
    } 
  
    // CASE IV 
    // Now k is even 
    // Now we deal with pairs 
    // Each time a pair is multiplied to product 
    // ie.. two elements are added to subsequence each time 
    // Effectively k becomes half 
    // Hence, k >>= 1 means k /= 2 
    k >>= 1; 
  
    // Now finding k corresponding pairs 
    // to get maximum possible value of product 
    for (int itr = 0; itr < k; itr++) { 
  
        // product from left pointers 
        int left_product = A[i] * A[i + 1]; 
  
        // product from right pointers 
        int right_product = A[j] * A[j - 1]; 
  
        // Taking the max product from two choices 
        // Correspondingly changing the pointer's position 
        if (left_product > right_product) { 
            product *= left_product%mod; 
            product%=mod;
            product=(product+mod)%mod;
            i += 2; 
        } 
        else { 
            product *= right_product%mod; 
            product%=mod;
            product=(product+mod)%mod;
            j -= 2; 
        } 
    } 
  
    // Finally return product 
    return product; 
} 
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,k;
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    cout << fn(a,n,k) ;
}

Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,mt;
  int min = 0;
  int flag = 1;
  int start = 1;
  cin >> n;
  vector<int> cost(n);
  vector<int> t(n);
  cin >> mt;
  for (int i = 0; i < n; i++) {
    cin >> cost[i] >> t[i];
  }

  for (int i = 0; i < n; i++) {
    if (t[i]<=mt) {
      if (start) {
        start = 0;
        min = cost[i];
      }
      if(cost[i]<min){
        min = cost[i];
      }
      flag = 0;
    }
  }
if (flag) {
  cout << "TLE";
}else {
  cout << min;
}

}


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

using namespace std;

int n, m;
int a[100010];
long long sum = 0;
vector<pair<int, int> > p;

int main(){
	scanf("%d%d", &n, &m);

	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);

	sort(a + 1, a + 1 + n);

	for(int i = 1; i <= n; i++){
		sum += a[i];
	}

	p.resize(m);
	for(int i = 0; i < m; i++){
		scanf("%d%d", &p[i].second, &p[i].first);
	}

	sort(p.rbegin(), p.rend());

	int idx = 0;
	long long diff = 0;
	for(int i = 0; i < m; i++){
		while(idx < n && a[idx + 1] < p[i].first && p[i].second){
			p[i].second--;
			++idx;
			diff += p[i].first - a[idx];
		}
	}

	printf("%lld\n", diff + sum);
	
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define rep(i,s,e)  for(int i=s;i<e;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


void solve(){
	int k;
	cin>>k;

	queue<int> q;

	for(int i=1;i<=9;i++){
		q.push(i);
	}

	for(int i=0;i<k-1;i++){
		int el=q.front();
		//trace(el);
		q.pop();

		if(el%10!=0)
			q.push(10*el+(el%10)-1);

		q.push(10*el+(el%10));

		if(el%10!=9)
			q.push(10*el+(el%10)+1);
	}

	int ans=q.front();
	cout<<ans<<endl;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sol() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for(int i=0; i<n; i++) {
      cout << s[i] << t[i];
  }
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

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

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N;
double ans;
vector<double> v;

int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		double x;
		scanf("%lf", &x);
		v.pb(x);
	}
	sort(v.begin(), v.end());
	ans = v[0];
	for(int i=1; i<N; i++){
		//cout<<ans;
		ans = (ans + v[i]) / 2.0;
	}
	printf("%lf", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10005], b[10005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;

int main() {
	int n;
	cin >> n;
	vector<int>L(n);
	for (int i = 0; i < n; i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			int sum = L[i] + L[j];
			int a = lower_bound(L.begin(), L.end(), sum) - L.begin();
			int b = i + 1;
			ans += a - b;

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


int main() {
	ll N;
	cin >> N;
	vll x(N), y(N), h(N);
	rep(i, N) cin >> x[i] >> y[i] >> h[i];

	rep(i, 101) {
		rep(j, 101) {
			ll H;
			rep(k, N) {
				if (h[k] != 0) {
					H = h[k] + abs(x[k] - i) + abs(y[k] - j);
					break;
				}
			}
			bool flag = true;
			rep(k, N) if (max(H - abs(x[k] - i) - abs(y[k] - j), ll(0)) != h[k]) flag = false;
			if (flag) {
				cout << i << " " << j << " " << H << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
a=map(int, raw_input().split())
b=map(int, raw_input().split())
c=map(int, raw_input().split())

b.sort()
c.sort()
b.reverse()

if b[0]<c[0] and a[2]<c[0] and b[0]<a[3]:
    print "No War"
else:
    print "War"

Measured memory_bytes: 2568
N = int(input())
AAA, AAG, AAC, AAT, AGA, AGG, AGC, AGT, ACA, ACG, ACC, ACT, ATA, ATG, ATC, ATT, GAA, GAG, GAC, GAT, GGA, GGG, GGC, GGT, GCA, GCG, GCC, GCT, GTA, GTG, GTC, GTT, CAA, CAG, CAC, CAT, CGA, CGG, CGC, CGT, CCA, CCG, CCC, CCT, CTA, CTG, CTC, CTT, TAA, TAG, TAC, TAT, TGA, TGG, TGC, TGT, TCA, TCG, TCC, TCT, TTA, TTG, TTC, TTT = 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
for i in range(N-3):
    AAA, AAG, AAC, AAT, AGA, AGG, AGC, AGT, ACA, ACG, ACC, ACT, ATA, ATG, ATC, ATT, GAA, GAG, GAC, GAT, GGA, GGG, GGC, GGT, GCA, GCG, GCC, GCT, GTA, GTG, GTC, GTT, CAA, CAG, CAC, CAT, CGA, CGG, CGC, CGT, CCA, CCG, CCC, CCT, CTA, CTG, CTC, CTT, TAA, TAG, TAC, TAT, TGA, TGG, TGC, TGT, TCA, TCG, TCC, TCT, TTA, TTG, TTC, TTT = AAA + GAA + CAA + TAA, AAA + GAA + CAA + TAA, AAA + GAA + CAA + TAA, AAA + GAA + CAA + TAA, AAG + GAG + CAG + TAG, AAG + GAG + CAG + TAG, 0, AAG + GAG + CAG + TAG, AAC + GAC + CAC + TAC, 0, AAC + GAC + CAC + TAC, AAC + GAC + CAC + TAC, AAT + GAT + CAT + TAT, AAT + GAT + CAT + TAT, AAT + GAT + CAT + TAT, AAT + GAT + CAT + TAT, AGA + GGA + CGA + TGA, AGA + GGA + CGA + TGA, 0, AGA + GGA + CGA + TGA, AGG + GGG + CGG + TGG, AGG + GGG + CGG + TGG, GGG + CGG + TGG, AGG + GGG + CGG + TGG, AGC + GGC + CGC + TGC, AGC + GGC + CGC + TGC, GGC + CGC + TGC, AGC + GGC + CGC + TGC, AGT + GGT + CGT + TGT, AGT + GGT + CGT + TGT, GGT + CGT + TGT, AGT + GGT + CGT + TGT, ACA + GCA + CCA + TCA, ACA + GCA + CCA + TCA, ACA + GCA + CCA + TCA, ACA + GCA + CCA + TCA, ACG + GCG + CCG + TCG, ACG + GCG + CCG + TCG, GCG + CCG + TCG, ACG + GCG + CCG + TCG, ACC + GCC + CCC + TCC, ACC + GCC + CCC + TCC, ACC + GCC + CCC + TCC, ACC + GCC + CCC + TCC, ACT + GCT + CCT + TCT, ACT + GCT + CCT + TCT, ACT + GCT + CCT + TCT, ACT + GCT + CCT + TCT, ATA + GTA + CTA + TTA, ATA + GTA + CTA + TTA, ATA + GTA + CTA + TTA, ATA + GTA + CTA + TTA, ATG + GTG + CTG + TTG, ATG + GTG + CTG + TTG, GTG + CTG + TTG, ATG + GTG + CTG + TTG, ATC + GTC + CTC + TTC, ATC + GTC + CTC + TTC, ATC + GTC + CTC + TTC, ATC + GTC + CTC + TTC, ATT + GTT + CTT + TTT, ATT + GTT + CTT + TTT, ATT + GTT + CTT + TTT, ATT + GTT + CTT + TTT
print((AAA + AAG + AAC + AAT + AGA + AGG + AGC + AGT + ACA + ACG + ACC + ACT + ATA + ATG + ATC + ATT + GAA + GAG + GAC + GAT + GGA + GGG + GGC + GGT + GCA + GCG + GCC + GCT + GTA + GTG + GTC + GTT + CAA + CAG + CAC + CAT + CGA + CGG + CGC + CGT + CCA + CCG + CCC + CCT + CTA + CTG + CTC + CTT + TAA + TAG + TAC + TAT + TGA + TGG + TGC + TGT + TCA + TCG + TCC + TCT + TTA + TTG + TTC + TTT)%(10**9+7))

Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{
	int n,m,a[55],b[55],c,d;
	vector<pair<int,int>>v[55];
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>c>>d;
		for(int j=0;j<n;j++)
		{
			v[j].push_back(make_pair(abs(a[j]-c)+abs(b[j]-d),i+1));
		}
	}
	for(int i=0;i<n;i++)
	{
		sort(v[i].begin(),v[i].end());
		cout<<v[i][0].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
struct ff
{
	string place;
	int num;
	int xuhao;
}f[105];
bool cmp(ff a,ff b)
{
	if(a.place==b.place){
		return a.num>b.num;
	}
	return a.place<b.place;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>f[i].place>>f[i].num;
		f[i].xuhao=i+1;
	}
	sort(f,f+n,cmp);
	for(int i=0;i<n;i++){
		cout<<f[i].xuhao<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int P = 998244353 ; 
const int N = 400 + 5 ; 
int n, A[N], a[N][N], B[N], SA, SB, inv[N], fac[N], dp[N][N][N] ;
int fpow( int x, int k ) {
    int ans = 1, base = x ; 
    while( k ) {
        if( k & 1 ) ans = 1ll * ans * base % P ; 
        base = 1ll * base * base % P, k >>= 1 ; 
    } return ans % P ; 
}
int Dec( int x, int y ) {
    return ( x - y + P ) % P ; 
} 
signed main() 
{
    n = gi() ; 
    rep( i, 1, n ) A[i] = gi(), B[i] = gi() ; 
    rep( i, 1, n ) SA += A[i], SB += B[i] ; 
    fac[0] = inv[0] = 1 ; 
    rep( i, 1, SB ) fac[i] = fac[i - 1] * i % P, inv[i] = fpow( fac[i], P - 2 ) ;
    rep( i, 1, n ) rep( j, 0, SB ) a[i][j] = ( j == 0 ) ? 1 : a[i][j - 1] * A[i] % P ;
    dp[0][0][0] = -1 ; 
    rep( i, 1, n ) rep( j, 0, SA ) rep( k, 0, SB ) {
        dp[i][j][k] = dp[i - 1][j][k] ; 
        for( re int l = 0; l < B[i]; ++ l ) if( A[i] <= j && l <= k ) 
        dp[i][j][k] = Dec( dp[i][j][k], 1ll * dp[i - 1][j - A[i]][k - l] * a[i][l] % P * inv[l] % P ) ;
    }
    int Ans = 0 ;
    rep( j, 0, SA ) rep( k, 0, SB ) 
    Ans = ( Ans + SA * fpow( fpow( j, P - 2 ), k + 1 ) % P * dp[n][j][k] % P * fac[k] % P ) % P ;
    cout << Ans << endl ; 
	return 0 ; 
}

Measured memory_bytes: 515200
X, Y , A, B, C = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

P = p[0:X]
Q = q[0:Y]
R = r[0:X+Y]

S = P + Q + R

S.sort(reverse = True)

ans = sum(S[0:X+Y])

print(ans)

Measured memory_bytes: 23328
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Cin.Int()
    Dim c(0 To 9, 0 To 9) As Integer
    For i As Integer = 1 To n
      If (i Mod 10) <> 0 Then
        Dim s As String = i.ToString()
        c(Integer.Parse(s(0)), Integer.Parse(s(s.Length() - 1))) += 1
      End If
    Next
    Dim r As Long = 0
    For i As Integer = 1 To n
      If (i Mod 10) <> 0 Then
        Dim s As String = i.ToString()
        r += c(Integer.Parse(s(s.Length() - 1)), Integer.Parse(s(0)))
      End If
    Next
    Console.WriteLine(r.ToString())
  End Sub
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

Measured memory_bytes: 17324
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 main() {
    let mut n: usize = read();
    let mut ans: Vec<usize> = vec![2, 3, 25];
    let thirty_times = (1..16).map(|x| x * 30).collect::<Vec<_>>();
    let two_times = (226..15001).map(|x| x * 2).collect::<Vec<_>>();
    let three_times = (75..4995).map(|x| x * 6 + 3).collect::<Vec<_>>();
    let five_times = (15..999).map(|x| x * 30 + 5).collect::<Vec<_>>();

    /*
    println!("{:?}", thirty_times);
    println!("{:?}", two_times.len());
    println!("{:?}", three_times.len());
    println!("{:?}", five_times.len());
    println!("{:?}", (&three_times[0..10], &three_times[0..10].iter().sum::<i32>()));
    */
    n -= 3;

    let two_times_nums = std::cmp::min(two_times.len(), (n / 15) * 15);
    n -= two_times_nums;
    for i in 0..two_times_nums {
        ans.push(two_times[i]);
    }
    let three_times_nums = std::cmp::min(three_times.len(), (n / 10) * 10);
    n -= three_times_nums;
    for i in 0..three_times_nums {
        ans.push(three_times[i] as usize);
    }
    let five_times_nums = std::cmp::min(five_times.len(), (n / 6) * 6);
    n -= five_times_nums;
    for i in 0..five_times_nums {
        ans.push(five_times[i] as usize);
    }
    for i in 0..n {
        ans.push(thirty_times[i] as usize);
    }


    println!("{}", ans.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" "));
}


Measured memory_bytes: 4476
//
//  main.cpp
//  A
//
//  Created by 黄宇凡 on 2017/4/9.
//  Copyright © 2017年 黄宇凡. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

const int maxn = 10005;

string s[maxn];
string ss[maxn];
string T;

int n;

int main(int argc, const char * argv[]) {
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> s[i];
    }
    cin >> T;
    int n1 = 0,n2 = 0;
    for(int i = 1;i <= n;i++){
        ss[i] = "";
        for(int j = 0;j < s[i].length();j++){
            if(s[i][j] == '?') ss[i] += 'a';
            else ss[i] += s[i][j];
        }
        if(ss[i] <= T) n1++;
    }
    for(int i = 1;i <= n;i++){
        ss[i] = "";
        for(int j = 0;j < s[i].length();j++){
            if(s[i][j] == '?') ss[i] += 'z';
            else ss[i] += s[i][j];
        }
        if(ss[i] >= T) n2++;
    }
    //cout << n1 << " " << n2 << endl;
    for(int i = n - n2 + 1;i <= n1 + 1;i++){
      //  cout << i << endl;
        printf("%d%c",i,i == n1 + 1? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 1536
n = gets.chomp.to_i

ar = gets.chomp.split(' ').map(&:to_i)
br = gets.chomp.split(' ').map(&:to_i)

diffs = ar.zip(br).map { |a,b| a-b }.reject{ |n| n == 0 }
# a, b, c

diffs = diffs.sort

if diffs.inject(0){|sum,x| sum + x } < 0
  puts '-1'
  exit 0
end


d = 0
changes = 0
while !diffs.empty?
  if 0 <= d
    s = diffs.shift

    if 0 <= s
      puts changes
      exit 0
    end

    d = s + d
  else
    s = diffs.pop
    if s < 0
      puts '-1'
      exit 0
    end

    d = s + d
  end

  changes += 1
end

puts changes

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



int main() {

    int n,k; cin >> n >> k;
    double Max = -1;
    vector<double> p(n);
    rep(i,n) cin >> p[i];

    vector<double> s(n+1,0);
    rep(i,n) s[i+1] = s[i] + (p[i]+1)/2;

    rep(i,n+1-k){
        Max = max(Max,s[i+k] - s[i]);
    }

    cout << fixed << setprecision(13) << Max;

    return 0;
}











Measured memory_bytes: 6456
#include <stdio.h>
int main()
{
	char a,b,c;
	scanf("%s%s%s",&a,&b,&c);
	
	if (a==b && a!=c){
		printf("Yes");
	}
	else if(b==c && b!=a){
		printf("Yes");
	}
	else if(c==a && c!=b){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1688
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var N = ReadInt();
            var d = new Dictionary<int, int>();

            for (int i = 0; i < N; i++)
            {
                var A = ReadInt();
                if (d.ContainsKey(A))
                    d[A] += 1;
                else
                    d.Add(A, 1);
            }

            var ans = 0;
            foreach (var key in d.Keys)
            {
                if (d[key] % 2 != 0) ans++;
            }

            Println(ans);
        }

        static List<int> ReadLines(int n)
        {
            var l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                l.Add(ReadInt());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 19040
from itertools import product
from collections import Counter
N = int(input())
res = 0
for k in range(11):
    for p in product([3,5,7],repeat=k):
        if len(Counter(p)) == 3:
            tmp, pw = 0, 1
            for q in p:
                tmp += q*pw
                pw *= 10
            if tmp <= N:
                res += 1
print(res)

Measured memory_bytes: 77352
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

m,k=map(int,input().split())

if m==0 and k!=0:
    print(-1)
    quit()
elif m==1 and k!=0:
    print(-1)
    quit()
elif k>=2**m:
    print(-1)
    quit()
if m==1 and k==0:
    print(*[0,0,1,1])
    quit()

lst=[i for i in range(2**m) if i!=k]
# print(lst)
anslst=lst[:]+[k]+sorted(lst,key=lambda x: -x)+[k]
print(*anslst)

Measured memory_bytes: 68076
#include <bits/stdc++.h>
#include <functional>
#include <iomanip>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>

using ll = long long;
ll INF = LLONG_MAX / 4 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
    int a,b,c; cin >> a >> b >> c;
    if (b + c <= a) {
        cout << 0 << endl;
    } else {
        int lim = a -b;
        cout << c - lim << endl;
    }
}

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


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int f(int N,int x){
    if(N==-1) return 0;
    return N/x+1;
}
signed main()
{
    int a,b,x; cin>>a>>b>>x;
    cout<<f(b,x)-f(a-1,x)<<endl;
}

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

int n;
int x[24],y[24],c[24],r[24];
char memo[1<<24];
int hit(int i,int j){
	int L = r[i]*r[i] + r[j]*r[j] + 2 * r[i] * r[j];
	int X = (x[i]-x[j])*(x[i]-x[j]);
	int Y = (y[i]-y[j])*(y[i]-y[j]);
	return X + Y < L;
}
int nocover(int n,int bit){
	for(int i = 0 ; i < n ; i++){
		if( (bit>>i&1) && hit(i,n) ) return false;
	}
	return true;
}
int dfs(int bit){
	if(~memo[bit]) return memo[bit];
	int ans = 0;
	for(int i = 0 ; i < n ; i++){
		for(int j = i+1 ; j < n ; j++){
			if( (bit >> j & 1) && (bit >> i & 1) && c[i] == c[j] && nocover(i,bit) && nocover(j,bit) ){
				ans = max(ans , dfs( bit & ~(1<<j) & ~(1<<i) ) + 2);
			}
		}
	}
	return memo[bit] = ans;
}
int main(){
	while(cin >> n , n){
		for(int i = 0 ; i < n ; i++){
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		memset(memo,-1,sizeof(memo));
		cout << dfs((1<<n)-1) << endl;
	}
}


Measured memory_bytes: 19456
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int M = 1010;
int n,m;
int dp[M][(1<<12)];
int a[M],b[M],c[M][13];
int full=0;
int solve(int id,int msk){
  if(msk==full)return 0;
  if(id==m+1)return 1e9;
  int &x = dp[id][msk];
    if(x!=-1)return x;
    x=solve(id + 1,msk);
    
    int nmsk = msk;
    for(int j=1;j<=b[id];j++){
      nmsk|=(1<<c[id][j]);
    }
    x = min(x,a[id] + solve(id+1,nmsk));
    return x;
}

// long long ? ?
int32_t main(){
  fastio;
  int n,k;
  cin>>n>>k;
  int ans=0;
  rep(i,0,n){
    int x;
    cin>>x;
    if(x>=k)ans++;
  }
  cout<<ans;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, d;
	while (cin >> n >> d, n) {
		vvi v(n);

		int cnt = 0;
		REP(i, n) {
			int k; cin >> k;
			v[i].resize(k);
			cnt += k;
			REP(j, k)cin >> v[i][j];
		}
		vi sum(n);
		REP(i, n)REP(j, v[i].size())sum[i] += v[i][j];
		auto f = [&](int a, int b) {
			return sum[a] < sum[b];
		};
		priority_queue<int, vi, decltype(f)> q(f), tmp(f);
		REP(i, n)q.push(i);
		
		while (cnt) {
			int a = -INF;
			bool updated = false;
			while (!q.empty()) {
				int p = q.top(); q.pop();

				if (v[p].empty())continue;
				int t;
				if (a == -INF)t = sum[q.top()];
				else t = a;
				if (sum[p] - v[p].back() >= t - d) {
					sum[p] -= v[p].back();
					v[p].pop_back();
					q.push(p);
					cnt--;
					updated = true;
				}
				else {
					tmp.push(p);
					if (a == -INF)a = sum[p];
				}
			}
			while (!tmp.empty()) {
				q.push(tmp.top());
				tmp.pop();
			}
			if (!updated)break;
		}
		if (cnt == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  string S;
  cin >> N >> S;

  set<char> one;
  set<string> two,ans;

  for(int i = 0;i < N;i++) {
    set<char>::iterator itr = one.begin();

    set<string>::iterator itr2 = two.begin();
    for(;itr2 != two.end();itr2++) {
      string s = *itr2;
      s.push_back(S.at(i));
      ans.insert(s);
    }

    for(;itr != one.end();itr++) {
      string se = "";
      se.push_back(*itr);
      se.push_back(S.at(i));
      two.insert(se);
    }

    one.insert(S.at(i));
  }
  
  cout << ans.size() << endl;
}




Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <climits>
#include <cstring>
using namespace std;

typedef pair<int,int> P;

int n, ans;
int t[1002];
vector<P> g[1002];
map<string,int> name;
bool used[1002], loop[1002];

int getId(string s){
  if(name.find(s) != name.end()){
    return name[s];
  }
  int size = name.size();
  return name[s] = size;
}

void solve(){
  memset(used, 0, sizeof(used));

  for(int i = 0; i < n; i++){
    if(used[i]) continue;

    memset(loop, 0, sizeof(loop));

    int id = i;
    bool flg = true;

    while(!loop[id]){
      if(used[id]){
	flg = false;
	break;
      }

      loop[id] = true;
      used[id] = true;
      id = g[id][0].first;
    }
    if(!flg) continue;

    int start = id;
    int minId = start;

    id = g[start][0].first;

    while(id != start){
      if(t[minId] - g[minId][0].second > t[id] - g[id][0].second){
	minId = id;
      }
      id = g[id][0].first;
    }

    ans += t[minId] - g[minId][0].second;
  }

  cout << ans << endl;
}

int main(){
  while(cin >> n, n){
    ans = 0;
    name.clear();

    for(int i = 0; i < 1002; i++){
      g[i].clear();
    }

    for(int i = 0; i < n; i++){
      string FROM, TO;
      int a, b;
      cin >> FROM >> a >> TO >> b;

      int from = getId(FROM);
      int to = getId(TO);
      t[from] = a;
      g[from].push_back(P(to, b));
      ans += b;
    }

    solve();
  }
}

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

using namespace std;

int main()
{
	int b;
	cin >> b;
	int *a;
	a=new int(b);
	int i;
	for(i=0;i<b;i++){
		cin>> a[i];
		}
	for(i=b-1;i>0;i--){
	cout << a[i] <<" ";
	}
	cout << a[0]<<endl;
	return 0;
}

Measured memory_bytes: 1188
/*input
5 5
.#.#.
#.#.#
.#.#.
#.#.#
.#.#.
*/
#include <bits/stdc++.h>
using namespace std; 
#define int long long int
#define max(x, y) ((x) > (y) ? (x) :(y))
#define pii pair< int , int> 
#define vi vector<int>
#define REP(i,en) for ( int i =0; i < en; i++)
#define SZ(a) a.size()
#define all(v) v.begin() , v.end()

const int mod = 1e9 + 7;
int add( int &a, int b){
	a = a + b;
	if ( a > mod) a -= mod;
}
int sub( int &a, int b){
	a = a - b;
	if ( a < 0) a += mod;
}
int mul( int a , int b){
	return ((a %mod) * (b %mod) ) %mod;
}
int exp( int a , int pow){
	if ( pow == 0 ) return 1;
	if ( pow == 1) return a;
	return  ( pow & 1  ? mul ( a ,exp( mul(a, a) , pow /2) ) : exp(mul(a ,a) , pow/2));
}

int gcd( int a,int b){
	if ( b == 0 ) return a;
	return gcd( a % b ,a);
}
// const int inf = 1e18;
const int maxn = 4e3 +5;

char  mat[200][200];
int dp[200][200];
void solve(int test) 
{	
	int h , w ; 
	cin >> h >> w;
	for ( int i =0 ; i < h; i++)
		for ( int j = 0;  j < w ; j++)
			cin >> mat[i][j];
	dp[0][0] = mat[0][0] == '#';
	for ( int i = 1 ; i  < h ; i++) {
		dp[i][0] += dp[i-1][0];
		if ( mat[i][0] == '#' && mat[i-1][0] == '.'){
			dp[i][0]++;
		}
	}
	for ( int i = 1 ; i  < w ; i++) {
		dp[0][i] += dp[0][i-1];
		if ( mat[0][i] == '#' && mat[0][i-1] == '.'){
			dp[0][i]++;
		}
	}
	for ( int i =1; i  < h ; i++)
		for ( int j = 1; j < w ; j ++){
			if ( mat[i][j] == '#'){
				int ans1 = dp[i][j-1] + (mat[i][j-1] == '.');
				int ans2 = dp[i-1][j] + ( mat[i-1][j] == '.');
				dp[i][j] = min( ans1 , ans2);
 			}
 			else
 				dp[i][j] = min( dp[i][j-1] , dp[i-1][j] );
		}
	cout << dp[h-1][w-1];

} 
signed main(){
	int t =1; 
	// cin >> t;
	for ( int i = 0 ; i < t; i++)
	solve(i+1);
}

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

using namespace std;

int main(){
	long long n, k, ans = 1;
	cin >> n >> k;
	ans *= k;
	k--;
	for(long long i = 1; i < n; ++i){
        ans *= k;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**8)
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})


d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cctype>
#include <utility>
#include <array>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	array<int, 4> a;
	array<int, 5> t = {10, 50, 100, 500, 100000};
	for (int n, m = 0; (n = -in()); m++) {
		if (m)
			outl();
		for (int i = 0; i < 4; i++)
			n += a[i] = in() * t[i];
		for (int i = 0, c; i < 4; i++) {
			int d = n % t[i + 1];
			if ((c = (a[i] - d) / t[i]) > 0)
				outl(t[i], ' ', c);
			n -= d;
		}
	}
}


Measured memory_bytes: 2408
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, D = LI()
X = []
for i in range(N):
    X.append(LI())

result = 0
for i in range(N-1):
    for j in range(i + 1, N):
        tmp = 0
        for d in range(D):
            tmp += (X[i][d] - X[j][d])**2
        tmp = math.sqrt(tmp)
        if tmp % 1 == 0:
            result += 1
print(result)


Measured memory_bytes: 67052
#include <stdio.h>
#include <algorithm>

using namespace std;

#define MAX_N (100000)

int S[MAX_N];

int main()
{
    int n, q;
    int ans = 0;
    scanf("%d", &n);

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

    scanf("%d", &q);

    for ( int i = 0; i < q; i++ ) {
	int t;
	scanf("%d",&t);
	if ( *lower_bound( S, S + n, t ) == t ) {
	    ans++;
	}
    }
    
    printf("%d\n", ans);

    return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

int main(){
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int res = 0;
  for (int i = 0; i < n; i++) {
    vector<int> tmp;
    map<char, int> count;
    count[a[i]]++;
    count[b[i]]++;
    count[c[i]]++;
    for(auto j : count){
      tmp.push_back(j.second);
    }
    int maxv = *max_element(all(tmp));
    res += 3 - maxv;
  }
  cout << res << endl;


}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <list>
#include <queue>
#include <map>
#include <stack>
#include <set>
#define inf 0x3f3f3f3f
#define PI acos(double(-1))
using namespace std;

typedef long long ll;
const int maxn=1e5+10;
int n,m,num[maxn];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        num[a]++;
        num[b]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(num[i]&1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
   lint n;
   cin>>n;
   lint a[n];
   lint sum=0;
   rep(i,n){
       cin>>a[i];
       sum+=a[i];
   }
   sum%=MOD;
   lint ans=0;
   rep(i,n){
       lint x=sum-a[i];
       x+=MOD;
       x%=MOD;
       ans+=a[i]*x;
       ans%=MOD;
       sum-=a[i];
       sum+=MOD;
       sum%=MOD;
   }
   cout<<ans<<endl;
  }
      

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n, l;
int main() {
	std::cin >> n >> l;

	int min = 9999999999, sum = 0;
	for (int i = 1; i <= n; ++i) {
		sum += l + i - 1;
		if (std::abs(min) > std::abs(l + i - 1))
			min = l + i - 1;
	}

	std::cout << sum - min << std::endl;
	return 0;
}


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

int p(string x){
    int s = x.size();
    for(int i=0;i<s/2;i++){
        if(x[i] != x[s-i-1]){
            return 0;
        }
    }
    return 1;
}

int main(void){
    int a,b,x;
    int ans = 0;
    cin >> a >> b;
    for(x=a;x<=b;x++){
        ans += p(to_string(x));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int a, b;

    cin >> a >> b;

    cout << (a <= b ? a : a-1) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abl_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = Convert.ToInt32(Console.ReadLine());
            for (int loop= 0; loop < K; loop++)
            {
                Console.Write("ACL");
            }
        }
    }
}

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

int main() {
  long long x;
  cin >> x;
  
  for(long long i=0LL; i<=50LL; i++){
    if(pow(2,i) <= x && x < pow(2,i+1)){
      long long s=1LL;
      for(long long j=1LL; j<=i+1; j++){
        s *= 2;
      }
      cout << s - 1 << endl;
    }
  }
  
  
	return 0;
}


Measured memory_bytes: 256