akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        long N=sc.nextLong(),res=0,M=N;
        for(int i=2;N!=1&&i<(int)Math.sqrt(M);i++){
            if(N%i==0){
                int s=0,t=1;
                while(N%i==0){
                    N/=i;
                    s++;
                    if(s==t){
                        s-=t;
                        t++;
                    }
                }
                res+=t-1;
            }
        }
        if(N!=1) res++;
        System.out.println(res);
    }
}


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

int main(){

	int n;
	std::vector<int>v;
	while (std::cin >> n)v.push_back(n);

	for (int k = 0; k < v.size(); k++){
		char soro[8][5];
		for (int i = 0; i < 8; i++){
			for (int j = 0; j < 5; j++){
				soro[i][j] = '*';
			}
		}
		for (int i = 0; i < 5; i++)soro[2][i] = '=';

		for (int i = 4; i >= 0; i--){
			int mod = v[k] % 10;

			if (mod == 0 || mod == 5)soro[3][i] = ' ';
			if (mod == 1 || mod == 6)soro[4][i] = ' ';
			if (mod == 2 || mod == 7)soro[5][i] = ' ';
			if (mod == 3 || mod == 8)soro[6][i] = ' ';
			if (mod == 4 || mod == 9)soro[7][i] = ' ';

			if (mod < 5)soro[1][i] = ' ';
			else soro[0][i] = ' ';

			v[k] /= 10;
		}

		for (int i = 0; i < 8; i++){
			for (int j = 0; j < 5; j++){
				std::cout << soro[i][j];
			}
			std::cout << std::endl;
		}
		if (k != v.size() - 1)std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(200009);

ll mod_pow(ll x,ll n){
  if(n==0)return 1;
  ll res=mod_pow(x*x%mod,n/2);
  if(n%2)res=res*x%mod;
  return res;
}

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  mint ans=mod_pow(2,n);
  ans-=1;
  mint fact=1,t=n;
  rep(i,a){
    fact*=t;
    t-=1;
  }
  ans-=fact*comb.ifact[a];
  fact=1,t=n;
  rep(i,b){
    fact*=t;
    t-=1;
  }
  ans-=fact*comb.ifact[b];
  cout<<ans.x<<endl;
  return(0);
}


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

long long int min_cost(int height[], int n) {
    long long int dp[n];
    dp[0] = 0;
    dp[1] = abs(height[1] - height[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i-1] + abs(height[i] - height[i - 1]), dp[i-2] + abs(height[i] - height[i - 2]));
    }
    return dp[n - 1];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int height[n];
    for (int i = 0; i < n; ++i) {
        cin >> height[i];
    }
    cout << min_cost(height, n) << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int evaluation(int N, int A, int B, int C, int D, const string& S) {
	if(A > C || B > D || S[A] == '#' || S[B] == '#' || A == B) return inf;
	return abs((C - A) - (D - B));
}
int main() {
	int N, A, B, C, D; string S;
	cin >> N >> A >> B >> C >> D >> S; --A, --B, --C, --D;
	bool ok = true;
	while(A != C || B != D) {
		int e1 = evaluation(N, A + 1, B, C, D, S);
		int e2 = evaluation(N, A, B + 1, C, D, S);
		int e3 = evaluation(N, A + 2, B, C, D, S);
		int e4 = evaluation(N, A, B + 2, C, D, S);
		int mn = min({e1, e2, e3, e4});
		if(mn == inf) {
			ok = false;
			break;
		}
		if(e1 == mn) A += 1;
		else if(e2 == mn) B += 1;
		else if(e3 == mn) A += 2;
		else B += 2;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
using namespace std;

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int i, a[n];
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    // cout << "a[0] : " << a[0] << endl;
    long double numerator = 0;
    for (i = 0; i < n; i++)
    {
        numerator += 1.0 / a[i];
    }

    long double result = 1 / numerator;
    printf("%.10Lf\n", result);

    return 0;
}

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

int main(){
  double a,b,x;
  cin>>a>>b>>x;
  if(a*a*b==x){
    cout<<0<<endl;
  }else if(x<=a*a*b/2.0){
    double length=2.0*x/a/b;
    double surface=sqrtl(powl(length,2.0)+powl(b,2.0));
    double h=2.0*x/surface/a;
    double angle=asin(h/length)*180.0/M_PI;
    printf("%lf\n",angle);
  }else{
    double length=2.0*(a*a*b-x)/a/a;
    double surface=sqrtl(pow(length,2.0)+powl(a,2.0));
    double h=2.0*(a*a*b-x)/surface/a;
    double angle=acos(h/length)*180.0/M_PI;
    printf("%lf\n",angle);
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(std::string S) { cout << (S == "ABC" ? "ARC" : "ABC") << endl; }

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

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(v) for (auto el : v) { cerr << el << ' '; } cerr << endl;

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

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	vector<vector<ii>> tm(n);
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		tm[i].resize(a);
		for (int j = 0; j < a; j++) {
			scanf("%d%d", &tm[i][j].first, &tm[i][j].second);
			tm[i][j].first--;
		}
	}

	int answer = 0;
	for (int m = 0; m < (1<<n); m++) {
		bool good = true;
		for (int i = 0; i < n; i++) {
			if ((m & (1<<i)) == 0) continue;
			for (auto p : tm[i]) {
				int v1 = m & (1<<p.first);
				if ((v1 && !p.second) || (!v1 && p.second)) {
					good = false;
					break;
				}
			}
		}
		if (good) answer = max(answer, __builtin_popcount(m));
	}
	printf("%d\n", answer);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto _i:x) cout << _i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-7
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

long long x, k, bound, q, t, a, val, low, range, oriLow;
vector<int> v;
bool goUp;

void consume (long long wall) {
  long long dis = wall - bound;
  bound = wall;
  // BUG(goUp);
  if (goUp) {
    goUp = false;
    long long newLow = min(x, low + dis);
    long long newHigh = min(x, low + range + dis);
    low = newLow;
    range = newHigh - newLow;
  } else {
    goUp = true;
    if (low - dis < 0) oriLow += dis - low;
    long long newLow = max(0ll, low - dis);
    long long newHigh = max(0ll, low + range - dis);
    low = newLow;
    range = newHigh - newLow;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin >> x >> k;
  REP (i, k) {
    cin >> val;
    v.pb(val);
  }
  reverse(all(v));
  range = x;
  goUp = false;
  cin >> q;
  while (q--) {
    cin >> t >> a;
    while (v.size() && v.back() <= t) consume(v.back()), v.pop_back();
    long long aa = low + a - oriLow;
    // BUG(aa);
    if (a < oriLow) aa = low;
    if (a > oriLow + range) aa = low + range;
    if (goUp) cout << min(x, aa + t - bound);
    else cout << max(0ll, aa - t + bound);
    cout << endl;
  }
}

Measured memory_bytes: 1784
///In the name of ALLAH

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
 
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mx_int_prime 999999937
 
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
 
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))
 
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


const int mx = 1e5+123;

int dp[mx][4], n;
int h[mx][4];

int solve ( int i, int f1 )
{
  if ( i > n ) return 0;
  if ( dp[i][f1] != -1 ) return dp[i][f1];

  int ret = 0;
  for ( int j = 1; j <= 3; j++ ) {
    if ( j != f1 ) {
      ret = max ( ret, h[i][j] + solve ( i+1, j ) );
    }
  }

  return dp[i][f1] = ret;

}

int main()
{
  optimize();

  cin >> n;
  for ( int i = 1; i <= n; i++ ) {
    cin >> h[i][1] >> h[i][2] >> h[i][3];
  }

  memset ( dp, -1, sizeof(dp) );
  cout << solve ( 1, 0 ) << endl;

  return 0;
}

Measured memory_bytes: 14580
#!/usr/bin/env python3
import sys


def solve(S: str):
    a = {chr(c) for c in range(ord("a"), ord("z") + 1)} - set(S)
    print(sorted(a)[0] if a else "None")


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

struct Node {
   int index;
   ll value;
   Node(int index = 0, ll value = 0):index(index),value(value){
   }  
};

ll calHistrigramArea(const vector<ll>& a) {
    deque<Node> dq;
    ll ans = 0;
    for (int i = 0; i < a.size(); i++) {
        int e = a[i];
        while (!dq.empty()) {
            if (dq.back().value > e) {
                ll v = dq.back().value; dq.pop_back();
                int leftIndex = dq.empty() ? -1 : dq.back().index;
                ans = max(ans, (i - leftIndex - 1) * v);
            } else {
                break;
            }
        }
        dq.push_back(Node(i, e));
    }
    
    int i = a.size();
    while (!dq.empty()) {
        ll v = dq.back().value;dq.pop_back();
        int leftIndex = dq.empty() ? -1 : dq.back().index;
        ans = max(ans, (i - leftIndex - 1) * v);
    }
    return ans;
}


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    ll ans = calHistrigramArea(a);
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5336
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        boolean ansFlag = true;
        int max = Integer.parseInt(sc.next()) - 1;
        for(int i = 1;i<n;i++){
            int tmp = Integer.parseInt(sc.next());
            if(tmp > max){
                tmp -= 1;
            }
            if(tmp < max){
                ansFlag = false;
                break;
            }
            max = Math.max(max,tmp);
        }
        if(ansFlag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

int main() {
  int a;
  int b;
  int c;
  
  cin >> a;
  c=0;
  if (a%1000 == 0) {
    cout << "0";
    return 0;
  }
  for (int i = 1; i <= 10; i++) {
    c = c + 1000;
    if (a < c) {
      b = c - a;
      cout << b;
      return 0;
    }
  }
  
  cout << "0";
   
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
#define lint int64_t

int main(){
    int N,T;
    cin >> N >> T;
    
    int min_cost = 1001;
    rep(i,N){
        int a, b;
        cin >> a >> b;

        if(b <= T) min_cost = min(min_cost,a);
    }
    

    if(min_cost == 1001){
        cout << "TLE" << endl; 
    }else{
        cout << min_cost << endl;
    }
  
}


Measured memory_bytes: 256
n,m = map(int,input().split())
H = list(map(int,input().split()))
L = [1]*n
for _ in range(m):
  a,b = map(int,input().split())
  if H[a-1] == H[b-1]:
    L[a-1] = 0
    L[b-1] = 0
  elif H[a-1] < H[b-1]:
    L[a-1] = 0
  elif H[a-1] > H[b-1]:
    L[b-1] = 0
print(sum(L))

Measured memory_bytes: 20056
def read_ints():
    return [int(c) for c in input().split()]


def count(x):
    ret = 0
    while x % 2 == 0:
        ret += 1
        x //= 2
    return ret


def main():
    input()
    xs = read_ints()
    print(sum(count(x) for x in xs))


if __name__ == '__main__':
    main()

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;
constexpr int tenfive = 100000;

int main() {
	int N,ans = 0;
	cin >> N;
	vector<int> n(N);
	vector<vector<pair<int, int>>> v(N);
	for (int i = 0; i < N; i++) {
		cin >> n[i];
		for (int j = 0; j < n[i]; j++) {
			int x, y;
			cin >> x >> y;
			x--;
			v[i].push_back({ x,y });
		}
	}
	for (int i = 0; i < (1<< N); i++) {
		bitset<16> bs(i);
		bool ng = false;
		for (int j = 0; j < N; j++) {
			if (ng)break;
			if (bs[j]) {
				for (auto num : v[j]) {
					if (bs[num.first] != num.second) {
						ng = true;
					}
				}
			}
		}
		if (!ng) {
			ans = max(ans, (int)bs.count());
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  int sum1 = 0;
  int sum2 = 0;
  
  if(N - K >= 0){
    for(int i=1; i<=K; i++){
      sum1 += X;
    }
  
    for(int i=1; i<=N-K; i++){
      sum2 += Y;
    }
   cout << sum1 + sum2 << endl;
  }
  
  if(N - K < 0){
    for(int i=1; i<=N; i++){
      sum1 += X;
    }
   cout << sum1 << endl;
  }
  
}


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

using namespace std;

struct dice{
	int q1,q2,q3,q4,q5,q6;
};

void mN(dice &d){
	int tmp=d.q1;
	d.q1=d.q2;
	d.q2=d.q6;
	d.q6=d.q5;
	d.q5=tmp;
}

void mE(dice &d){
	int tmp=d.q1;
	d.q1=d.q4;
	d.q4=d.q6;
	d.q6=d.q3;
	d.q3=tmp;
}

void spin(dice &d){
	int tmp=d.q2;
	d.q2=d.q3;
	d.q3=d.q5;
	d.q5=d.q4;
	d.q4=tmp;
}

bool isSame(dice y, dice z){
	bool flag = false;

	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}
	
	mE(y);
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){		
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}	
			
	return flag;
}

int main(){
	dice a[100];
	int n;
	bool ans=false;
	
	scanf(" %d", &n);
	
	for(int i=0; i<n; ++i)
		scanf(" %d %d %d %d %d %d", &a[i].q1, &a[i].q2, &a[i].q3, &a[i].q4, &a[i].q5, &a[i].q6);
		
	for(int i=0; i<n-1; ++i){
		for(int j=i+1; j<n; ++j){
			ans=isSame(a[i], a[j]);
			if(ans) break;
		}
		if(ans) break;
	}
	
	if(ans) printf("No\n");
	else printf("Yes\n");
		
	return 0;
}



Measured memory_bytes: 3164
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
                                                                                                     
ll MOD=1000000007;                                                                                     
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,mmax=0,pmax=0; cin>>n;
    vector<int> a(n,0);
    vector<pp> ans;
    rep(i,n){
        cin>>a[i];
        if(a[i]>0) pmax=max(pmax,a[i]);
        if(a[i]<0) mmax=max(mmax,-a[i]);
    }
    if(pmax>mmax){
        int idx;
        rep(i,n)if(pmax==a[i]) idx=i;
        rep(i,n){
            if(a[i]<0) ans.push_back(mk(idx+1,i+1));
        }
        rep(i,n-1){
            ans.push_back(mk(i+1,i+2));
        }
    }
    else{
        int idx;
        rep(i,n)if(-mmax==a[i]) idx=i;
        rep(i,n){
            if(a[i]>0) ans.push_back(mk(idx+1,i+1));
        }
        rep(i,n-1){
            ans.push_back(mk(n-i,n-i-1));
        }
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()) cout<<ans[i].first<<" "<<ans[i].second<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
const ll INF=1e18;
#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define double long double
const double pi = acos(-1.0);
int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}
 
long long binpows(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)  //impar
            res = res * a;
        a = a * a;
        b >>= 1;  // /2
    }
    return res;
}
int binpow(int a, int b, int m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
const int mod=1e9+7;
//CHECAR SE PRECISA DE LONG LONG
struct sparSeg{
    sparSeg(){}
    struct node{
        node *l=nullptr,*r=nullptr;
        int value=0;
    };
    node *raiz=new node();
    void update(int pos, int val){update(pos,val,raiz,0,1e9+1);}
    void update(int pos,int val,node *v,int tl, int tr){
        if(tl==tr){
            v->value+=val;
            return;
        }
        int med=(tl+tr)/2;
        if(pos<=med){
            if(v->l==nullptr){
                v->l=new node();
            }
            update(pos,val,v->l,tl,med);
        }else{
            if(v->r==nullptr){
                v->r=new node();
            }
            update(pos,val, v->r, med+1,tr);
        }
        v->value=max(v->value,val);
    }
    int sum(int l, int r){return sum(l,r,raiz,0,1e9+1);}
    int sum(int l, int r, node *v, int tl, int tr){
        if(tl>r or tr<l)
            return 0;
        if(tl>=l and tr<=r){
            return v->value;
        }
        int sx=0;
        int med=(tl+tr)/2;
        if(v->l!=nullptr){
            sx=max(sx,sum(l,r,v->l,tl,med));
        }
        if(v->r!=nullptr){
            sx=max(sx,sum(l,r,v->r,med+1,tr));
        }
        return sx;
    }

};
void solve(){
    int n;
    cin>>n;
    vector<int> h(n);
    vector<int> a(n);
    sparSeg aux;
    int dp[n+1];
    memset(dp,0,sizeof(dp));
    for(int &i: h)
        cin>>i;
    for(int &i: a)
        cin>>i;
    for(int i=1; i<=n; i++){
        dp[i]+=a[i-1];
        dp[i]+=aux.sum(0,h[i-1]-1);
        aux.update(h[i-1],dp[i]);
    }
    cout<<aux.sum(0,2e5)<<endl;
}  
 
//revise as variaveis e a ordem nas funções
signed main(){fastio;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 20364
#include<iostream>

using namespace std;

int main() {
	int H1, M1, H2, M2, K;
	int X1, X2, T;

	cin >> H1 >> M1 >> H2 >> M2 >> K;

	X1 = H1 * 60 + M1;
	X2 = H2 * 60 + M2;

	T = X2 - X1 - K;

	cout << T << endl;
	return 0;
}

Measured memory_bytes: 3632
function main (sdi) {
  var input = sdi.trim();
  var a = input.match(/[ACTG]+/g);
  var loop = a ? a.length : 0;
  var length = 0;
  var r = "";
  for(var i=0; i<loop; i++){
    if(a[i].length > length){
      length = a[i].length;
    }
  }
  console.log(length);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));

Measured memory_bytes: 7372
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

calc :: [Int] -> Int -> Int
calc [] _ = 0
calc [p] i
  | p == i = 1
  | otherwise = 0
calc (p : ps) i
  | p == i = 1 + calc (p : (tail ps)) (i + 1)
  | otherwise = calc ps (i + 1)

main = do
  n <- getInt
  ps <- getIntList
  print $ calc ps 1


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

int main(){
	/*
	int a,b,c,d,e;

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

	int x;

	if(a > 0){
		x = e*(b-a);
	}
	if(a == 0){
		x = e*b + d;
	}
	if(a < 0){
		x = -c*a + e*b + d;
	}

	cout << x <<endl;
	*/

	/*
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	int m,n;
	int x = a + b + c + d + e + f;


	
	if(e<f)
	{
		x = x - e;
		if(a<b)
		{
			if(a<c)
			{
				if(a<d)
				{
					cout << x-a << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
		else
		{
			if(b<c)
			{
				if(b<d)
				{
					cout << x-b << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
	}
	else
	{
		x = x - f;
		if(a<b)
		{
			if(a<c)
			{
				if(a<d)
				{
					cout << x-a << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
		else
		{
			if(b<c)
			{
				if(b<d)
				{
					cout << x-b << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
	}
	*/
/*
	int n;
	cin >> n;
	int a;
	cin >> a;
	int max = a,min = a;
	int i = 1;
	while(i<n){
		cin >> a;
		if(a > max){
			max = a;
		}
		if(a < min){
			min = a;
		}
		i++;
	}
	cout << max << endl << min << endl;
	*/
	/*
	string s;
	cin >> s;
	int j,o,i;
	for(int i;i < s.size;i++){
		
	}
	*/
	/*
	int n;
	cin >> n;
	int A;
	int X[100000];
	int n=0;
	for(int i=0;i<n;i++){
		cin >> A;
		
	}
	*/
	/*
	int a,b,c,d,p;
	cin >> a >> b >> c >> d >> p;
	int X,Y=b;

	X = a*p;
	
	if(p>c){
		Y += d*(p-c);
	}

	if(X > Y){
		cout << Y << endl;
	}
	else{
		cout << X << endl;
	}
	*/ 
	/*
	int l,a,b,c,d;
	cin >> l >> a >> b >> c >> d;

		int Jap = a/c;
		if(a%c != 0){
			Jap += 1;
		}
		int Math = b/d;
		if(b%d != 0){
			Math += 1;
		}

	int day = Jap;
	if(Jap < Math) {
		day = Math;
	}

	cout << l - day << endl;
	*/

	int pa,pb,pc,ja,jb;
	cin >> pa >> pb >> pc >> ja >> jb;
	
	if(pa > pb){
		pa = pb;
	}
	if(pa > pc){
		pa = pc;
	}

	if(ja > jb){
		ja = jb;
	}

	cout << pa + ja -50 << endl;

	return 0;
}



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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int n[2019] = {};
  for (char c : s) {
    n[0] += 1;
    int d = (int)(c - '0');
    int nxt[2019] = {};
    for (int i=0;i<2019;++i) {
      int p = (i*10+d)%2019;
      nxt[p] += n[i];
    }
    ans += nxt[0];
    for (int i=0; i<2019; ++i) n[i] = nxt[i];
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, sum=0;
  cin >> N;
  
  vector<int> A(N);
  for(int i=0; i<N; i++)
    cin >> A.at(i);
  
  map<long long, long long> c;
  for (auto x : A){
    if(c.count(x))
      c[x]++;
    else
      c[x] = 1;
  }
  
  for(auto x : c){
    sum += x.second*(x.second-1)/2;
  }
  
  for(auto x : A){
  
    cout << sum - c[x] + 1 << endl;
  }
  
}

Measured memory_bytes: 10240
//33
#include<iostream>

using namespace std;

int main(){
  int t;
  cin>>t;
  while(t--){
    int h,w;
    cin>>h>>w;
    char g[20][20];
    int tx,ty,d=0;
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	cin>>g[y][x];
	switch(g[y][x]){
	case '<':
	  d++;
	case 'v':
	  d++;
	case '>':
	  d++;
	case '^':
	  ty=y;
	  tx=x;
	  g[y][x]='.';
	}
      }
    }
    int n;
    cin>>n;
    while(n--){
      char o;
      cin>>o;
      int dy[]={-1,0,1,0};
      int dx[]={0,1,0,-1};
      if(o=='S'){
	int gy=ty+dy[d];
	int gx=tx+dx[d];
	for(;;){
	  if(gy<0||h<=gy||gx<0||w<=gx)break;
	  if(g[gy][gx]=='#')break;
	  if(g[gy][gx]=='*'){
	    g[gy][gx]='.';
	    break;
	  }
	  gy+=dy[d];
	  gx+=dx[d];
	}
      }else{
	d=(o=='U')?0:
	  (o=='R')?1:
	  (o=='D')?2:3;
	int ny=ty+dy[d];
	int nx=tx+dx[d];
	if(0<=ny&&ny<h&&0<=nx&&nx<w&&g[ny][nx]=='.'){
	  ty=ny;
	  tx=nx;
	}
      }
    }
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	if(y!=ty||x!=tx){
	  cout<<g[y][x];
	}else{
	  const char *tc="^>v<";
	  cout<<tc[d];
	}
      }
      cout<<endl;
    }
    if(t){
      cout<<endl;
    }
  }
  return 0;
}
	
      

Measured memory_bytes: 1152
#include <iostream>
#include <climits>

using namespace std;
void test1(int N,string S);
void test2(int N,string S);
int main(int argc, char *argv[])
{

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

  test2(N,S);
  return 0;
}

void test2(int N,string S){
  int result = INT_MAX;
  int muki;
  int counter = 0;
  for (int i = 1; i < N; i++) {

    if (S[i] == 'E') {
      counter++;
    }
  }
  result = counter;
  muki = counter;

  for (int i = 1; i < N; i++) {
    //    cout << result << "\n";
    if (S[i] == 'E' && S[i-1] == 'E') {
      muki = muki-1;
    }
    if (S[i] == 'W' && S[i-1] == 'W') {
      muki = muki+1;
    }
    if (result > muki) {
      result = muki;
    }

  }
  cout << result << "\n";
}

void test1(int N,string S){
  int result = INT_MAX;
    for (int i = 0; i < N; i++) {
      int counter = 0;
      for (int j = 0; j < i; j++) {
	if (S[j] == 'W') {
	  counter++;
	}
      }
      if ((i+1) < N) {
	for (int j = (i+1); j < N; j++) {
	  if (S[j] == 'E') {
	    counter++;
	  }
	}
      }

      if (result >counter) {
	result = counter;
      }
    }
  cout << result << "\n";
}


Measured memory_bytes: 900
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.regex;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  auto m = s.split(regex(`[^ATCG]+`));
  writeln(m.map!(mi => mi.length).reduce!max);
}


Measured memory_bytes: 336
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <limits.h>

using namespace std;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    cout << (int)ceil((double)(N-1) / (K-1)) << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll x,y;
  cin>>x>>y;
  if(abs(x-y)<=1) cout<<"Brown"<<endl;
  else cout<<"Alice"<<endl;

  return 0;
}


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

using namespace std;
int n,a,b,c,d;
string s;

void solve(){
    a--;b--;c--;d--;

    int cur_a=a,cur_b=b;
    bool a_bool=true,b_bool=true;
    if(c < d){
        while(cur_b<d){
            if(cur_b+2<n && s[cur_b+2]!='#'){
                cur_b+=2;
            }
            else if(cur_b+1 < n && s[cur_b+1]!='#'){
                cur_b+=1;
            }
            else if(s[cur_b+1]=='#'&& s[cur_b+2]=='#'){
                b_bool=false;
                break;
            }
        }
        while(cur_a<c){
            if(cur_a+2<n && s[cur_a+2]!='#'){
                cur_a+=2;
            }
            else if(cur_a+1 < n && s[cur_a+1]!='#'){
                cur_a+=1;
            }
            else if(s[cur_a+1]=='#'&& s[cur_a+2]=='#'){
                a_bool=false;
                break;
            }
        }
    }
    else{
        while(cur_a<c){
            if(cur_a+2<n && cur_a+2!=cur_b && s[cur_a+2]!='#'){
                cur_a+=2;
            }
            else if(cur_a+1<n && cur_a+1!=cur_b && s[cur_a+1]!='#'){
                cur_a++;
            }
            else if(cur_a+2==cur_b || cur_a+1==cur_b){
                if(cur_b==d){
                    a_bool=false;
                    break;
                }
                else if(cur_b+1<n && s[cur_b+1]!='#'){
                    cur_b++;
                }
                else if(cur_b+2<n && s[cur_b+2]!='#'){
                    cur_b += 2;
                }
                else if(s[cur_b+1]=='#' && s[cur_b+2]=='#'){
                    b_bool=false;
                    break;
                }
            }
            else if(s[cur_a+1]=='#' && s[cur_a+2]=='#'){
                a_bool=false;
                break;
            }
        }
    }

    if(a_bool && b_bool){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

int main(){
    cin >> n >> a >> b >> c >> d;
    cin >> s;
    solve();
}

Measured memory_bytes: 640
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define mod        1000000007 
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod;}
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2);}
ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
ll a[2000000];
void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=1;}}}}
vector<ll>v1;
bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second);
} 
ll ans=0;
ll arr[1000000];
vector<ll>root;
map<string,ll>m1;
map<pair<string,ll>,ll>m2;

void comp()
{
	ll i,j,k,n,m;
	string s,t;
	cin>>n>>m;
	ll ans,count=1;
	if(m==1)
	{
		cout<<0;
		return;
	}
	if(n>m)
	{
		cout<<1;
		return ;
	}
	for(i=1;;i++)
	{
		if(count>=m)
		{
			ans=i-1;
			break;
		}
		count--;
		count+=n;
		if(count>=m)
		{
			ans=i;
			break;
		}
	}
	cout<<ans<<"\n";
} 
int main()
{
	speedup;
	ll i=0,t;
	ll n;
	//cin>>t;
	t=1;
	while(t--)
	{
	 comp();
	}
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

//container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

ll n;

int main() {
	int a[4],v[4];
	cin >> a[0]>> a[1] >> a[2] >> a[3] >> n;
	REP(i,4)v[i] = pow(2,3-i)*a[i]; // max is 4e8
	n*=4;
	int t = 4;
	ll ans = 0;
	while(true){
		int mi = -1, mv = 4e8 + 1;
		REP(i, t){
			if(mv > v[i]){
				mv = v[i];mi = i;
			}
		}
		if(mi==-1)break;
		t=mi;
		ans += (ll)n/ll(pow(2,t)) * a[t];
		n%=(int)pow(2,t);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int S[4];
    int count = 0;

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

    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 4; j++){
            for (int k = 0; k < 4; k++){
                for (int l = 0; l < 4; l++){
                    if (S[i] == 1 && S[j] == 9 && S[k] == 7 && S[l] == 4){
                        count++;
                    }
                }
            }
        }
    }
    
    if (count > 0){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

int main() {
  int N,K;
  int counter = 0;
  cin >> N >> K;

  rep(i,N){
    int x;
    cin >> x;
    if(x >= K) counter++;
  }
  cout << counter << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    DIC = [[]]*N
    for i in range(N):
        name, score = input().split()
        DIC[i] = [name, int(score)*-1, i]
    sDIC = sorted(DIC)

    for i in range(N):
        print(sDIC[i][2] + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

	sort(A, A+N);

	int cnt = 0, e = -1, W = 0, H = 0;

	for (int i = 0; i < N; i++) {
		if (e == A[i]) cnt++;

		if (e != A[i] || i == N-1) {
			if (cnt >= 4) {
				W = e;
				H = e;
			} else if (cnt >= 2) {
				if (e > W) {
					H = W;
					W = e;
				} else if (e > H) {
					H = e;
				}
			}
			e = A[i];
			cnt = 1;
		}
	}

	cout << (ll)W * (ll)H << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<array>

using namespace std;
int main(){
int a1,b1,a2,b2;
cin>>a1>>b1>>a2>>b2;
while(a1>=0 && a2>=0){
  a2=a2-b1;
  if(a2<=0){
    cout<<"Yes"<<endl;
    break;
  }
  a1=a1-b2;
  if(a1<=0){
    cout<<"No"<<endl;
    break;
  }
}


}



Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;
  cin>>k;
  vector<ll>a(50);
  rep(i,50)
  {
    a[i]=49+k/50;
  }
  rep(i,k%50)
  {
    rep(j,50)
    {
      a[j]--;
    }
    a[i]+=51;
  }
  cout<<50<<endl;
  rep(i,50)cout<<a[i]<<" ";
  cout<<endl;

  return 0;

}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn parse_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let line = parse_line::<String>();
    let mut iter = line.split_whitespace();
    (
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
    )
}

fn parse_line_vec<T: FromStr>() -> Vec<T> {
    let line = parse_line::<String>();
    line.split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn println<T: std::string::ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn sq(n: i32) -> u32 {
    (n * n) as u32
}

fn distance(p1: &Vec<i32>, p2: &Vec<i32>) -> f32 {
    ((0..p1.len())
        .map(|i| sq(p1[i] - p2[i]))
        .sum::<u32>() as f32)
        .sqrt()
}

fn main() {
    let (n, _d) = parse_pair::<usize, usize>();

    let x: Vec<Vec<i32>> = (0..n).map(|_| parse_line_vec()).collect();

    let mut count = 0;

    for i in 0..n - 1 {
        for j in i + 1..n {
            if distance(&x[i], &x[j]).fract() == 0.0 {
                count += 1;
            }
        }
    }

    println(count);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int n; cin >> n;
	vector<string>v; bool b = 1;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		if (i) {
			if (v[i - 1][v[i - 1].size() - 1] != s[0])b = 0;
			for (int j = 0; j < i; j++) {
				if (v[j] == s)b = 0;
			}
		}
		v.push_back(s);
	}
	cout << (b ? "Yes\n" : "No\n");
	cin >> b;
}

Measured memory_bytes: 256
'use strict'

function main(input) {
    const n = input.trim().split(/\s/).map(str=>~~str)
    
    const deg = Math.abs( (360*n[2] / 12) + 30*n[3] / 60 - (360*n[3] / 60)) % 360
    
    console.log(Math.sqrt(n[0]**2 + n[1]**2 - 2*n[0]*n[1]*Math.cos(deg * Math.PI / 180)))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 29752
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod =924844033;
typedef pair<int, int> P;
typedef pair<int, P> PP;
vector<int>G[200006];
int d1[200006], d2[200006];
int ans[200006];
int used[200006];
vector<int>B, W;

void bfs(int now) {
	fill(d1, d1 + 200006, inf);
	d1[now] = 0;
	queue<int>Q;
	Q.push(now);
	while (Q.size()) {
		int p = Q.front(); Q.pop();
		if (d1[p] & 1)B.push_back(p);
		else W.push_back(p);
		for (int e : G[p]) {
			if (d1[p] +1<d1[e]) {
				d1[e] = d1[p] + 1;
				Q.push(e);
			}
		}
	}
}

signed main() {

	int n; cin >> n;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	int i;
	rep(j, n) {
		if (G[j].size() == 1) {
			i = j; break;
		}
	}

	bfs(i);
	if (B.size() > W.size())swap(B, W);

//	for (int e : B)cout << e << endl; cout << endl;
//	for (int e : W)cout << e << endl;


	if (B.size() <= n / 3) {
		int now = 3;
		for (int e : B) {
			ans[e] = now;
			used[now]++;
			now += 3;
		}
		now = 1;
		for (int e : W) {
			while (used[now])now++;
			ans[e] = now;
			used[now]++;
		}
	}
	else {
		int now = 1;
		for (int e : B) {
			ans[e] = now; used[now]++; now += 3;
			if (now > n)break;
		}
		now = 2;
		for (int e : W) {
			ans[e] = now; used[now]++; now += 3;
			if (now > n)break;
		}
		now = 3;
		rep(j, n) {
			if (ans[j])continue;
			while (used[now])now++;
			ans[j] = now;
			used[now]++;
		}

	}

	rep(ii, n) {
		if (ii)cout << ' ';
		cout << ans[ii];
	}cout << endl;
	return 0;


	
}

Measured memory_bytes: 24296
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define all(x) (x).begin(),(x).end()
//#define DEBUG
#ifdef DEBUG
#include "debug.cpp"
#endif
using namespace std;

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int>* al = new vector<int>[m];
    rep(i, n)
    {
        int a, b; cin >> a >> b;
        if (a > m) continue;
        al[a-1].push_back(b);
    }
    priority_queue<int> q;
    int sum = 0;
    rep(i, m)
    {
        for (auto b : al[i])
        {
            q.push(b);
        }
        if (q.empty()) continue;
        sum += q.top();
        q.pop();
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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 mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}

int main(){
    int a,b,c,d;cin >> a >> b >> c >> d;
    if(a==c||b==d) puts("0");
    else{
        int ans = abs(a - c) + abs(b - d);
        cout << ans - gcd(abs(a-c),abs(b-d)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<assert.h>

#define MAX 100000

char input[MAX];
int stack_top;
double stack[MAX];

void push(double v) {
  stack[stack_top++] = v;
}

double pop() {
  return stack[--stack_top];
}

double getValue(int *ptr) {
  double value = 0;
  int minus = 0;
  if( input[*ptr] == '-' ) minus = 1, ++(*ptr);
  while( isdigit(input[*ptr]) ) {
    value *= 10;
    value += ( input[(*ptr)++]-'0' );
  }
  if( minus ) value *= -1;
  return value;
}

int main() {
  int i, len;
  while(fgets(input,sizeof input,stdin)) {
    len = strlen(input);
    for(i=0;i<len;++i) {
      while( i < len && input[i] == ' ' ) ++i;
      if( isdigit(input[i]) || ( i+1<len && input[i] == '-' && isdigit(input[i+1]) ) ) {
	push(getValue(&i));
	--i;
      } else if( input[i] == '+' ) {
	push(pop()+pop());
      } else if( input[i] == '-' ) {
	double v1 = pop();
	double v2 = pop();
	push(v2-v1);
      } else if( input[i] == '*' ) {
	push(pop()*pop());
      } else if( input[i] == '/' ) {
	double v1 = pop();
	double v2 = pop();
	push( v2 / v1 );
      } 
    }
    printf("%.10f\n",pop());
  }
  return 0;
}

Measured memory_bytes: 576
#include <stdio.h>

int main(void) {
	int n,i;
	int now,max;
	int a,b;
	scanf("%d",&n);
	scanf("%d",&now);
	max=now;
	for(i=0;i<n;i++) {
		scanf("%d%d",&a,&b);
		now+=a-b;
		if(now<0){puts("0");return 0;}
		if(now>max)max=now;
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;

ll ans=0;ll H,W;
deque<P> deq;

vector<vector<char>> maze(20, vector<char>(20, ' '));
vector<vector<ll>> Max(20, vector<ll>(20, -1));

vector<ll> dx={1,0,-1,0},dy={0,1,0,-1};

void bfs(ll x,ll y){
    Max[x][y]=0;
    deq.emplace_back(P(x,y));
    while(deq.size()){
        P Q=deq.front();
        deq.pop_front();
    for(int i=0;i<4;i++){
        ll nx=Q.first+dx[i]; ll ny=Q.second+dy[i];
        if(nx>=0&&nx<H&&ny>=0&&ny<W&&maze[nx][ny]=='.'&&Max[nx][ny]==-1){
            deq.emplace_back(P(nx,ny));
            Max[nx][ny]=Max[Q.first][Q.second]+1;
            ans=max(ans,Max[nx][ny]);
        }
    ;}}
    return;
}



int main(){
    cin >> H;
    cin >> W;
    
    for(int i=0;i<H;i++){
     for(int j=0;j<W;j++){
         cin>>maze[i][j]
     ;};}
    for(int i=0;i<H;i++){
     for(int j=0;j<W;j++){
         for(int k=0;k<H;k++){
          for(int l=0;l<W;l++){
              Max[k][l]=-1;
          ;}
         ;}
         deque<P> deq;
         if(maze[i][j]=='.'){bfs(i,j);}
     ;}
    ;}    
    cout<<ans<<endl;

return 0;
}  



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

int main(){

    int N,M,X;
    cin >> N >> M >> X;

    vector<int> C(N);
    vector<vector<int>> A(N);
    for(int i=0;i<N;i++){
        cin >> C[i];
        for(int j=0;j<M;j++){
            int temp;
            cin >> temp;
            A[i].emplace_back(temp);
        }
    }

    int m = 10000000;
    bool bigflag=false;


    for(int bit=1;bit < (1<<N);bit++){
        bool flag = true;
        vector<vector<int>> v;
        vector<int> t;
        for(int i=0;i<N;i++){
            if(bit & 1<<i){
               v.push_back(A[i]);
               t.push_back(C[i]);
            }
        }
    
        int ans=0;
        vector<int> s(M,0);

        /*
        cout << bit << endl;
        for(int k=0;k<v.size();k++){
            cout << "C" << k << " " << t[k] << " ";
            for(int j=0;j<M;j++){
                cout << v[k][j] << " ";
            }
            cout <<endl;
        }
        */

        for(int k=0;k<v.size();k++){
            ans+=t[k];
            for(int j=0;j<M;j++){
                s[j]+=v[k][j];
            }
        }

        /*
        for(int k=0;k<M;k++){
            cout << s[k] << " ";
        }
        cout <<endl;
        
        cout << ans <<endl;
        cout <<endl;
        */

        for(int l = 0;l<M;l++){
            if(X>s[l])flag=false;
        }
            
        if(flag){
            m=min(ans,m);
            bigflag=true;
        }
    }

    if(bigflag)cout << m << endl;
    else cout << -1 << endl;


    return 0;
}

Measured memory_bytes: 3636