akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}

ll rec(ll n) {
	if (n == 1) return 1;
	else return n * rec(n - 1);
}

//145 C
int main(void) {
	ll n;
	cin >> n;
	vector<ll> x = vector<ll>(n);
	vector<ll> y = vector<ll>(n);
	long double ans = 0;
	
	rep(i, 0, n) cin >> x[i] >> y[i];
	rep(i, 0, n-1) {
		rep(j, i + 1, n) {
			ans += 2 * (rec(n - 1)) * sqrt(((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])));
		}
	}

	cout << fixed << setprecision(10) << (ans / (long double)rec(n)) << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    S = in_s()
    T = in_s()

    N = len(S)

    count = 0
    for i in range(N):
        if S[i] != T[i]:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9668
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */
 
const double PI=3.14159265358979323846;
 
signed main(){
    int r;
    cin >> r;
    cout << 2*r*PI << "\n";
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[1001][1001], prm[2003];
int vis[100005], cnt;
void euler() {
    vis[1] = 1;
    for (int i = 2; i <= 10000; ++i) {
        if (!vis[i]) prm[++cnt] = i;
        for (int j = 1; j <= cnt && i * prm[j] <= 10000; ++j) {
            vis[i * prm[j]] = 1;
            if (!(i % prm[j])) break;
        }
    }
}

long long gcd(long long x, long long y) {
    while (y ^= x ^= y ^= x %= y) void();
    return x;
}

long long lcm(long long x, long long y) {
    if (!x || !y) return x + y;
    return x / gcd(x, y) * y;
}

int main() {
    scanf("%d", &n), euler();
    if (n == 2) return puts("4 7\n23 10\n"), 0;
    for (int i = 1; i <= n; ++i)
        for (int j = (i + 1 & 1) + 1; j <= n; j += 2)
            a[i][j] = prm[(i + j) / 2] * prm[n + (i - j) / 2 + (n + 1) / 2];
    for (int i = 1; i <= n; ++i)
        for (int j = (i & 1) + 1; j <= n; j += 2)
            a[i][j] = lcm(lcm(a[i - 1][j], a[i][j - 1]),
                          lcm(a[i][j + 1], a[i + 1][j])) +
                      1;
    for (int i = 1; i <= n; ++i, puts(""))
        for (int j = 1; j <= n; ++j) printf("%lld ", a[i][j]);
    return 0;
}

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

//BEGIN CUT HERE
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;  //セグ木の幅
  F f;  //モノイドの作用
  T ti;  //初期値
  vector<T> dat;  //セグ木で使う配列 一番上に使われるのがdat[1] 一番下の段の左端がdat[n]
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}  //fがモノイドとしての作用、tiが単位元
  SegmentTree(F f,T ti,int n_):f(f),ti(ti){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  SegmentTree(F f,T ti,const vector<T> &v):f(f),ti(ti){
    int n_=v.size();
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
    for(int i=0;i<n_;i++)dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  T get(int x){
    return dat[x+n];
  }

  void init(int n_){  //ただの初期化
    n=1;
    while(n<n_) n<<=1;  //nが実際にとる２べきの幅
    dat.assign(n<<1,ti);  //dat配列は幅の２倍あってその全てにtiを代入
  }

  void build(const vector<T> &v){  //vector vに合わせた初期化
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];  //v[i]を一番子の所に代入
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);  //iの子供は2*i、2*i+1
  }

  void set_val(int k,T x){  //（0-indexedで）kにxを代入
    dat[k+=n]=x;
    while(k>>=1)  //kがどんどん自分の親になっていく、0になったらおしまい
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){  //[a,b)の範囲のモノイドの作用を返す
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);  //左端を使いたくなるのはブロックが奇数の時
      if(r&1) vr=f(dat[--r],vr);  //右端〃偶数の時（開区間なのでr:奇数で反応）
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){  //dat[k]:[l,r)の間にいるenを返す
    //下のfind用なので先にそっち読むべき
    //accはst~lとかで確定している値
    if(l+1==r){  //答えがちゃんと存在するならこのlが答え
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1; //入るならk-n(==l)を、入らないなら-1を返す
    }
    int m=(l+r)>>1;  //にぶたんのそれ
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);  //mがstより後ろなら明らかにl=m;
    if(st<=l&&!check(f(acc,dat[k]))){  //今見てるk全部でもダメ(mだと足りないのでl=mにする）
      acc=f(acc,dat[k]);  //kは全部accに加えた上で-1を返す
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);  //まず[l,m)の中にenがいるか探す
    if(~vl) return vl;  //いたならそれを返す(if(~vl)は-1以外にのみ反応する)
    return find(st,check,acc,(k<<1)|1,m,r);  //いなかったら[m,r)の中にenがいるのでそれを返す
    //acc=f(acc,dat[k]);がここで効いてる
  }

  template<typename C>
  int find(int st,C &check){
    //check(f(dat[st]~dat[en-1]))=false,check(f(dat[st]~dat[en]))＝trueとなるenを返す
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};
//END CUT HERE

signed main(){
  int n,k;cin>>n>>k;
  SegmentTree<int> seg([](int a,int b){return max(a,b);},0,600000);
  while(n--){
    int a;cin>>a;
    seg.set_val(a,seg.query(max(a-k,0),a+k+1)+1);
  }
  cout<<seg.query(0,300001)<<endl;
}


Measured memory_bytes: 11452
import sys

n = sys.stdin.readline().rstrip()

def main():
    ans = 'Yes'
    if n[1] != n[2]:
        ans = 'No'
    else:
        if n[0] != n[1] and n[2] != n[3]:
            ans = 'No'
    print(ans)

if __name__ ==  '__main__':
    main()

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

int vec[100110][3];
int dp[100110][3];

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>vec[i][j];
    }
  }
  dp[0][0]=vec[0][0];
  dp[0][1]=vec[0][1];
  dp[0][2]=vec[0][2];
  for(int i=1;i<n;i++){
    for(int j=0;j<3;j++){
      if(j==0){
        dp[i][j]=max(dp[i-1][1]+vec[i][0],dp[i-1][2]+vec[i][0]);
      }
      if(j==1){
        dp[i][j]=max(dp[i-1][0]+vec[i][1],dp[i-1][2]+vec[i][1]);
      }
      if(j==2){
        dp[i][j]=max(dp[i-1][0]+vec[i][2],dp[i-1][1]+vec[i][2]);
      }
    }
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

Measured memory_bytes: 2560
n,k,a;
long dp[2<<17],mod=1e9+7;
f(j){
	dp[j]+=dp[j+1];
	j>0&&f(j-1);
	dp[j]=(dp[j]-dp[j+a+1])%mod;
}
main()
{
	scanf("%*d%d",&k);
	for(dp[k]=1;~scanf("%d",&a);)
	{
		f(k);
	}
	printf("%ld",*dp);
}


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

long long int p[1000][1000];

int main(){

string A;
string B;

long long int j=0;
long long int i=0;
long long int c=0;

long long int answer=0;
long long int final=0;

long long int n=0;//上の文の文字数
long long int m=0;//下の文の文字数

cin>>A;
cin>>B;

n=A.size(); //4
m=B.size(); //2

/////p全部に0を代入する///////

for(i=0;i<1000;i++){
for(j=0;j<1000;j++){
	p[j][i]=0;
}
}

//////////////////////////////

////一番上の段だけみる////

for(i=0;i<n;i++){
	if(A[i]==B[0]){
		p[i][0]=1;			
	}
}

///////////////////////




for(j=1;j<m;j++){   //j=1  
for(i=0;i<n;i++){   //i=0,1,2,3

	if(A[i]==B[j]){
		for(c=0;c<i;c++){
			p[i][j]=p[i][j]+p[c][j-1]%1000000007; //
		}
		//cout<<p[i][j]%1000000007;			
	}else{
		//cout<<0;
	}
	
}

//cout<<endl;

}

for(i=0;i<n;i++){
	answer=answer%1000000007+p[i][m-1]%1000000007;
}

final=answer%1000000007;

cout<<final<<endl;

}


Measured memory_bytes: 11056
#include <cstdio>
#include <iostream>
#include <vector>
#include <limits>
 
using namespace std;
#define INF 1e18
 
int main() {
    int N, W;
    int w, v;
    scanf("%d%d", &N, &W);
    vector<int> wt(N), vl(N);
    int sum_val = 0;
    for (int i = 0; i < N; ++i) {
        scanf("%d%d", &w, &v);
        wt[i] = w;
        vl[i] = v;
        sum_val += v;
    }
    vector<vector<long long>> dp(N+1, vector<long long>(sum_val+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= sum_val; ++j) {
            if (j < vl[i])
                dp[i+1][j] = dp[i][j];
            else
                dp[i+1][j] = min(dp[i][j], dp[i][j - vl[i]] + wt[i]);
        }
    }
    int ans = 0;
    for (int j = sum_val; j >= 0; --j) {
        if (dp[N][j] <= W) {
            ans = j;
            break;
        }
    }
    cout << ans;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  bool exist1=false, exist2=false;
  int ans1, ans2;
  for (int i=0; i<s.size()-1; i++) {
    if (s[i]==s[i+1]) {
      ans1=i+1, ans2=i+2;
      exist1 = true;
      break;
    }
  }
  for (int i=0; i<s.size()-2; i++) {
    if (s[i]!=s[i+1]&&s[i+1]!=s[i+2]&&s[i]==s[i+2]) {
      ans1=i+1, ans2=i+3;
      exist2 = true;
      break;
    }
  }
  if (exist1||exist2) cout << ans1 << " " <<  ans2 << endl;
  else cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;
    }

    public static string Solve()
    {
        int ans = 0;
        int lastDigit = 10;
        int[] nums = new int[5];
        for (int i = 0; i < 5; i++)
        {
            int num = ReadInt();
            if (num % 10 == 0)
            {
                ans += num;
            }
            else
            {
                ans += num / 10 * 10 + 10;
                lastDigit = Math.Min(lastDigit, num - num / 10 * 10);
            }
        }
        return (ans - 10 + lastDigit).ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
   

    
    
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=(1LL<<63) - 600;
const ll mod=1e9+7 ;
const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  int N, K; cin >> N >> K; ll a[N];
  rep(i, N){
    cin >> a[i];
  }
  sort(a, a+N); ll ans=0;
  COMinit();
  for(int i=N-1; i>=0; i--){
    ans+=(COM(i, K-1)*a[i]%mod);
    ans%=mod;
    ans-=(COM(N-1-i, K-1)*a[i]%mod);
    ans%=mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 24448
import java.util.Scanner;
import java.util.ArrayList;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> primes = getPrimes(n);
		int[][] powerIndexes;
		int[] nFactorialPowerIndexes = new int[primes.size()];
		int cnt = 0;
		int[][] pattern = {
			{ 3, 3, 5, 5 },
			{ 3, 5, 3, 5 },
			{ 3, 5, 5, 3 },
			{ 2, 3, 25, 0 },
			{ 2, 25, 3, 0 },
			{ 2, 5, 15, 0 },
			{ 2, 15, 5, 0 },
			{ 1, 75, 0, 0 }
		};

		powerIndexes = new int[n + 1][];
		for(int i = 1; i <= n; ++i)
		{
			powerIndexes[i] = factor(primes, i);
		}

		//System.out.print(n + "! = ");
		for(int i = 0; i < primes.size(); ++i)
		{
			for(int j = 1; j <= n; ++j)
			{
				nFactorialPowerIndexes[i] += powerIndexes[j][i];
			}

			/*
			if(nFactorialPowerIndexes[i] != 0)
			{
				System.out.print(primes.get(i) + "^" + nFactorialPowerIndexes[i] + " * ");
			}
			*/
		}
		//System.out.println();

		for(int i = 0; i < pattern.length; ++i)
		{
			cnt += countSevenFiveThree(nFactorialPowerIndexes, pattern[i], 0, pattern[i][0]);
		}

		System.out.println(cnt);
	}

	private static int countSevenFiveThree(int[] powerIndexes, int[] pattern, int primeIdx, int patternIdx)
	{
		if(patternIdx == 0)
		{
			return 1;
		}

		if(primeIdx == powerIndexes.length)
		{
			return 0;
		}
		
		int ret = countSevenFiveThree(powerIndexes, pattern, primeIdx + 1, patternIdx);

		if(powerIndexes[primeIdx] >= pattern[patternIdx] - 1)
		{
			ret += countSevenFiveThree(powerIndexes, pattern, primeIdx + 1, patternIdx - 1);
		}

		return ret;
	}

	private static ArrayList<Integer> getPrimes(int n)
	{
		boolean[] isNotPrime = new boolean[n + 1];
		ArrayList<Integer> primeList = new ArrayList<>();

		for(int i = 2; i * i <= n; ++i)
		{
			if(!isNotPrime[i])
			{
				for(int j = i * 2; j <= n; j += i)
				{
					isNotPrime[j] = true;
				}
			}
		}

		for(int i = 2; i <= n; ++i)
		{
			if(!isNotPrime[i])
			{
				primeList.add(i);
			}
		}

		return primeList;
	}

	private static int[] factor(ArrayList<Integer> primes, int n)
	{
		int[] powerIndexes = new int[primes.size()];

		for(int i = 0; i < primes.size(); ++i)
		{
			int power = 0;
			while(n % primes.get(i) == 0)
			{
				n /= primes.get(i);
				++power;
			}
			powerIndexes[i] = power;
		}
		
		return powerIndexes;
	}
}

Measured memory_bytes: 23124
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(X),
    get_number(Y),
    Z is X + Y div 2,
    writeln(Z).


Measured memory_bytes: 8176
#include<iostream>
#include<string>
#include<vector>
#include<stdbool.h>
using namespace std;

int main() {
	int N, t = 0, x = 0;
	cin >> N;
	int *C, *S, *F;
	C = (int*)malloc(sizeof(int)*(N - 1));
	S = (int*)malloc(sizeof(int)*(N - 1));
	F = (int*)malloc(sizeof(int)*(N - 1));
	for (int i=0;i < N - 1;i++)cin >> C[i] >> S[i] >> F[i];
	for (int i = 0;i < N ;i++) {
		x = i;
		t = 0;
		if (i == N - 1) {
			cout << 0 << endl;
			return 0;
		}
		while (x!=N-1) {
			for (;x < N - 1;) {
				if ((S[x] <= t) && ((t%F[x]) == 0)) {
					t += C[x];
					x++;
				}
				else {
					t++;
				}

				if (x == N - 1) {
					cout << t << endl;
				}
				
			}
			
		}
	}
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static long MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
        
        Arrays.sort(nums);
        
        boolean clear = true;
        long answer = 0;
        if (n % 2 == 0) {
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) {
                    if (nums[i] - 1 != i) {
                        clear = false;
                        break;
                    }
                } else {
                    if (nums[i] != i) {
                        clear = false;
                        break;
                    }
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) {
                    if (nums[i] != i) {
                        clear = false;
                        break;
                    }
                } else {
                    if (nums[i] - 1 != i) {
                        clear = false;
                        break;
                    }
                }
            }
        }
        
        if (clear) {
            answer = 1;
            for (int i = 1; i <= n / 2; i++) {
                answer = answer * 2 % MOD;
            }
        }
        
        System.out.println(answer);
    }
}


Measured memory_bytes: 50456
import sys
n, m = map(int,input().split())

if n >= m:
  print(0)
  sys.exit()
  
x = list(map(int,input().split()))
x.sort()
between = [x[i+1]-x[i] for i in range(len(x)-1)]
between.sort(reverse = True)
print(sum(between[n-1:]))

Measured memory_bytes: 13960
use proconio::input;
fn main() {
    input! {
        n: usize,
        s:String,
    };
    let rn=s.match_indices("R").map(|x| x.0).count();
    let gn=s.match_indices("G").map(|x| x.0).count();
    let bn=s.match_indices("B").map(|x| x.0).count();
    let v=s.as_bytes();
    let mut sum = rn*gn*bn;
    for i in 0..n{for j in i+1..(n+i+1)/2{
        let k = j+j-i;
        if v[i]!=v[j] && v[i]!=v[k]&&v[j]!=v[k]{
            sum-=1;
        }
    }}
    println!("{}",sum)
}


Measured memory_bytes: 2168
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()


l = n + k
fac = [1] * (l + 1)
inv = [1] * (l + 1)


for j in range(1, l + 1):
    fac[j] = fac[j - 1] * j % mod

inv[l] = pow(fac[l], mod - 2, mod)
for j in range(l - 1, -1, -1):
    inv[j] = inv[j + 1] * (j + 1) % mod



def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


if n == k:
    for i in range(k):
        if i == 0:
            print(1)
        else:
            print(0)

else:
    for i in range(k):
        print((comb(k - 1, i) * (comb(n - k - 1, i) * 2 + comb(n - k - 1, i + 1) + comb(n - k - 1, i - 1))) % mod)

Measured memory_bytes: 44272
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int[] a=cin.ArrayInt(N,0);
        int[] b=cin.ArrayInt(N,0);
        int[] c=cin.ArrayInt(N-1,0);
        int ans=0;
        for(int i=0;i<N;i++)
        {
            ans+=b[a[i]-1];
            if(i<N-1&&a[i]==a[i+1]-1)ans+=c[a[i]-1];
        }
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11220
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream cin("input.txt")
//#define of1 ofstream cout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,d;
	cin>>n>>d;
	vector< vector<ll> >points;
	for(ll i=0;i<n;i++)
	{
	    vector<ll>tmp;
	    for(ll j=0;j<d;j++)
	    {
	        ll x;
	        cin>>x;
	        tmp.eb(x);
	    }
	    points.eb(tmp);
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
	    for(ll j=i+1;j<n;j++)
	    {
	        ll lol=0;
	        for(ll k=0;k<d;k++)
	        {
	            lol+=((points[i][k]-points[j][k])*(points[i][k]-points[j][k]));
	        }
	        double hehe=sqrt(lol);
	        if(ceil(hehe)==floor(hehe))
	            ans++;
	    }
	}
	cout<<ans;
    return 0;
}

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

int main() {
    int r, c;
    cin >> r >> c;

    vector<vector<int>> diagram(r, vector<int>(c, 0));
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> diagram.at(i).at(j);
        }
    }

    for(int i = 0; i < r; i++) {
        int sum = 0;

        for(int j = 0; j < c; j++) {
            sum += diagram.at(i).at(j);
        }
        diagram.at(i).push_back(sum);
    }
  
  	vector<int> last(c+1, 0);
  
  	for(int j = 0; j < c+1; j++) {
    	for(int i = 0; i < r; i++) {
        	last.at(j) += diagram.at(i).at(j);
        }
    }

    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c+1; j++) {
            cout << diagram.at(i).at(j);
          	j == c ? cout << endl : cout << ' ';
        }
    }
  	
  	for(int i = 0; i < c+1; i++) {
    	cout << last.at(i);
      	i == c ? cout << endl : cout << ' ';
    }
}


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

int main() {
  int a,b; cin >> a >> b;
  int ans = 0;
  if ((a+b)%3==0 || a%3==0 || b%3==0) ans = true;
  cout << (ans ? "Possible" : "Impossible") << endl;
  return 0;
}


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

int main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int ans=1;
  for(int i=0;i<N-1;i++){
    if(v[i+1]-v[i]!=0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

    // check
    for (int i=0; i<N; ++i) {
        if (i+1 < b[i]) { 
            cout << -1 << endl;
            return 0;
        }
    }

    vector<int> his;
    while ((int)b.size() > 0) {
        for (int j=(int)b.size()-1; j>=0; --j) {
            if (b[j] == j+1) {
                his.push_back(b[j]);
                b.erase(b.begin() + j);
                break;
            }
        }
    }
    reverse(his.begin(), his.end());

    for (int i=0; i<(int)his.size(); ++i) {
        cout << his[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, j, maxv=-1000000000, minv, n, r;

  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%d", &r);
    if(i==0){
      minv=r;
    }else{      
      if(maxv<r-minv){
	maxv=r-minv;
      }
      if(minv>r){
	minv=r; 
      }
    }    
  }

  printf("%d\n", maxv);
  
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    int A[N];
    vector<ll>cnt(N + 1, 0);
    cnt[0] = 3;
    ll ans = 1;
    rep(i, N) {
        cin >> A[i];
        ans = ans * cnt[A[i]] % MOD;
        cnt[A[i]]--;
        cnt[A[i] + 1]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>
using namespace std;

#define INF 10000000

typedef pair<int,int> P;

queue<P> que;
char map[1000][1001];
int vst[1000][1000];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int H,W,N,sx,sy,sum=0;

int main() {
	scanf("%d %d %d",&H,&W,&N);
	for(int i=0;i<H;i++) {
		scanf("%s",map[i]);
		char *ptr=strchr(map[i],'S');
		if(ptr!=NULL) sx=ptr-map[i],sy=i;
	}
	que.push(P(sx,sy));
	for(int i=1;i<=N;i++) {
		for(int j=0;j<H;j++) {
			for(int k=0;k<W;k++) {
				vst[j][k]=INF;
			}
		}
		vst[sy][sx]=0;
		while(!que.empty()) {
			P p=que.front();
			que.pop();
			if(map[p.second][p.first]==i+'0') {
				sum+=vst[p.second][p.first];
				while(!que.empty()) que.pop();
				que.push(P(p.first,p.second));
				sx=p.first,sy=p.second;
				break;
			}
			for(int j=0;j<4;j++) {
				int nx=p.first+dx[j],ny=p.second+dy[j];
				if(0<=nx&&nx<W&&0<=ny&&ny<H&&map[ny][nx]!='X'&&vst[ny][nx]==INF) {
					vst[ny][nx]=vst[p.second][p.first]+1;
					que.push(P(nx,ny));
				}
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 5940
#include <stdio.h> 
int main(){ 
double a,b,c,d,e,f,g,h; 
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f,&g,&h)!=EOF){
if(a==c&&f==h){printf("YES\n");continue;}
if(b==d&&e==g){printf("YES\n");continue;}
if(a==c||e==g){printf("NO\n");continue;}
if((b-d)*(f-h)/((a-c)*(e-g))==-1){printf("YES\n");continue;}
else{printf("NO\n");continue;}
 }
return 0; 
}

Measured memory_bytes: 612
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;

struct vertex {
    vector<int> to;
    int num = 0, par = 0;
};

int n, c[10000];
vertex ver[10000];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        ver[a - 1].to.emplace_back(b - 1);
        ver[b - 1].to.emplace_back(a - 1);
    }
    for (int i = 0; i < n; i++) scanf("%d", &c[i]);
    sort(c, c + n);

    int ans = 0;
    for (int i = 0; i < n - 1; i++) ans += c[i];
    
    int ind = 0; 
    for (int i = 0, num = 0; i < n; i++) {
        if (ver[i].to.size() > num) {
            num = ver[i].to.size();
            ind = i;
        }
    }

    queue<int> q;
    ver[ind].par = ind;
    int a = n - 1;
    ver[ind].num = c[a--];
    q.emplace(ind);
    while(!q.empty()) {
        int i = q.front(); q.pop();
        for (auto &j : ver[i].to) {
            if (j == ver[i].par) continue;
            ver[j].num = c[a--];
            ver[j].par = i;
            q.emplace(j);
        }
    }
    
    printf("%d\n", ans);
    for (int i = 0; i < n; i++) printf("%d ", ver[i].num);
    printf("\n");
    return 0;
}


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

#define int long long
const int inf = 1e15;

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

    vector<int> cs(N+1);
    for (int i = 0; i < N; i++) cs[i+1] = cs[i] + A[i];

    int dp[N+1][N+1];
    for (int i = 0; i < N+1; i++) {
        for (int j = 0; j < N+1; j++) {
            dp[i][j] = inf;
        }
    }

    for (int i = 0; i < N; i++) {
        dp[i][i+1] = 0;
    }

    for (int b = 2; b < N+1; b++) {
        for (int i = 0; i < N-b+1; i++) {
            int j = i + b;
            for (int k = i+1; k < j; k++) {
                int query = cs[j] - cs[i];
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + query);
            }
        }
    }
    cout << dp[0][N] << endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c){
		cout<<1;
	}else if(a==b||b==c||c==a){
		cout<<2;
	}else{
		cout<<3;
	}
}

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

int main() {
  int x;
  cin >> x;
  
  int a,b;
  a = x / 500;
  x -= 500 * a;
  b = x / 5;
  
  cout << a * 1000 + b * 5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int N;
	cin >> N;
	vector<int> A(N + 2, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i + 1];
	}

	//total
	int total = 0;
	for (int i = 0; i < N + 1; i++) {
		total += abs(A[i + 1] - A[i]);
	}

	for (int i = 1; i < N + 1; i++) {
		cout << total + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll a,b,c,fact[1000005],inv[1000005];
int n;
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
ll C(int n,int m)
{
	return fact[n]*inv[m]%MOD*inv[n-m]%MOD;
}
int main()
{
	scanf("%d%lld%lld%lld",&n,&a,&b,&c);
	fact[0]=1;
	for(int i=1;i<=1000000;i++)fact[i]=fact[i-1]*i%MOD;
	inv[1000000]=quick_pow(fact[1000000],MOD-2);
	for(int i=1000000;i>=1;i--)inv[i-1]=inv[i]*i%MOD;
	ll pos=(a+b)*quick_pow(100,MOD-2)%MOD;
	ll inv=quick_pow(a+b,MOD-2);
	a=a*inv%MOD,b=b*inv%MOD;
	ll ans=0;
	for(int i=n;i<=2*n-1;i++)
	{
		ans+=C(i-1,n-1)*quick_pow(a,n-1)%MOD*quick_pow(b,i-n)%MOD*a%MOD*i%MOD;
		ans+=C(i-1,n-1)*quick_pow(b,n-1)%MOD*quick_pow(a,i-n)%MOD*b%MOD*i%MOD;
	}
	ans%=MOD;
	printf("%lld\n",ans*quick_pow(pos,MOD-2)%MOD);
	return 0;
}

Measured memory_bytes: 15744
N=int(input())
A=[int(s) for s in input().split()]
B=[int(s) for s in input().split()]
C=[int(s) for s in input().split()]


count=0
a=999
b=0
for i in range(0,N):
    b=A[i]-1
    count=count+B[b]
    if A[i]==a+1:
        count+=C[b-1]
    a=A[i]

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;



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

  lint min = n, cnt = 0;
  REP(i,n){
    if(min >= p[i]){
      cnt++;
      min = p[i];
    }
  }

  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...)
#define dump(x)
#define debug(x)
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

class DPreparingBoxes {
public:
void solve(std::istream& in, std::ostream& out) {
    int N;
    in >> N;
    vector<int> a(N+1);
    REP(i,1,N+1) in >> a[i];

    vector<int> b(N+1);
    int M = 0;

    RREP(i,1,N+1) {
        int sum = 0;
        int j = i*2;
        while (j <= N) {
            sum += b[j];
            j += i;
        }
        b[i] = abs(a[i] - sum) % 2;
        if (b[i] % 2 == 1) M++;
    }

    out << M << "\n";
    REP(i,1,N+1) {
        if (b[i] == 1) out << i << "\n";
    }
}
};


int main() {
	DPreparingBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2432
object Main extends App {
  val N = io.StdIn.readLine.toInt
  val TA = io.StdIn.readLine.split(' ')
  val T = TA.head
  val A = TA.last
  val Hs = io.StdIn.readLine.split(' ').map(_.toInt)

  val min = Hs.map(hi => math.abs(A.toDouble - (T.toDouble - hi * 0.006))).zipWithIndex.min

  println(min._2 + 1)
}


Measured memory_bytes: 25416
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    int x; cin >> x;
    if (x == 0)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3628
from scipy.spatial import distance
import itertools

n, d = map(int, input().split())

x = []
for i in range(n):
    x.append(list(map(int, input().split())))

combi = list(itertools.combinations(x, 2))

ans = 0
for i in range(len(combi)):
    dis = distance.euclidean(combi[i][0], combi[i][1])
    if dis.is_integer():
        ans += 1

print(ans)


Measured memory_bytes: 20080
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M);
	vector<vector<int> > G(N);
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		a[i]--; 
		b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	vector<int> dist(N, -1);
	int cnt = 0, compcnt = 0, biparcnt = 0;
	for (int i = 0; i < N; i++) {
		if (!G[i].empty()) cnt++;
		if (dist[i] != -1) continue;
		dist[i] = 0;
		queue<int> que; que.push(i);
		bool bipartite = true;
		while (!que.empty()) {
			int u = que.front(); que.pop();
			for (int j : G[u]) {
				if (dist[j] == -1) {
					dist[j] = dist[u] ^ 1;
					que.push(j);
				}
				if (dist[j] == dist[u]) {
					bipartite = false;
				}
			}
		}
		if (!G[i].empty()) {
			compcnt++;
			if (bipartite) biparcnt++;
		}
	}
	cout << 1LL * N * N - 1LL * cnt * cnt + 1LL * compcnt * compcnt + 1LL * biparcnt * biparcnt << "\n";
	return 0;
}

Measured memory_bytes: 8960
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 100005;

int N, M;
int all;
int Min_val, Min_id;
int a[MaxN];
int pre[2 * MaxN], last[MaxN], other[2 * MaxN];
bool vis[MaxN];

void build(int x, int y) {
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
}

void Dfs(int x, int fa) {
	vis[x] = true;
	if(a[x] < Min_val) {
		Min_val = a[x];
		Min_id = x;
	}
	for(int ed = last[x]; ed != -1; ed = pre[ed]) {
		int dr = other[ed];
		if(dr != fa) 
			Dfs(dr, x);
	}
}

void solve() {
	LL cost = 0;
	for(int i = 0; i < N; i++) {
		if(!vis[i]) {
			Min_val = inf;
			Dfs(i, -1);
			cost += 1LL * Min_val;
			a[Min_id] = inf;
		}
	}
	sort(a, a + N);
	int cnt = N - M;  //number of trees;
	if(cnt == 1) {
		printf("0\n");
		return;
	}
	for(int i = 0; i < cnt - 2; i++) {
		if(a[i] == inf) {
			printf("Impossible\n");
			return;
		}
		cost += a[i];
	}
	printf("%lld\n", cost);
}

int main()
{
	while(scanf("%d %d", &N, &M) != EOF)
	{
		all = -1; memset(last, -1, sizeof(last));
		memset(vis, 0, sizeof(vis));
		for(int i = 0; i < N; i++) scanf("%d", &a[i]);
		for(int i = 0; i < M; i++) {
			int u, v;
			scanf("%d %d", &u, &v);
			build(u, v); build(v, u);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 2560
N = int(input())
T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

if T[N-1] != A[0]:
    print(0)
    exit()

fix = [False for i in range(N)]
fix[0] = True
for i in range(1, N):
    if T[i] > T[i-1]:
        fix[i] = True

# print(fix)

if fix[N-1] is True and T[N-1] != A[N-1]:
    print(0)
    exit()
else:
    fix[N-1] = True
    T[N-1] = A[N-1]

for j in range(N-2, 0, -1):
    if A[j] > A[j+1]:
        if fix[j] is True and A[j] != T[j]:
            print(0)
            exit()
        else:
            fix[j] = True
            T[j] = A[j]
    elif fix[j] is True and T[j] > A[j]:
        print(0)
        exit()
    elif fix[j] is not True:
        T[j] = min(T[j], A[j])


MOD = 10**9 + 7
ans = 1
for i in range(N):
    if fix[i] is False:
        ans *= T[i]
        ans %= MOD
print(ans)


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

int main(){
	int n,m;
	cin >> n >> m;
	
	int a=0,b=100000;
	for(int i=0; i<m; i++){
		int l,r;
		cin >> l >> r;
		a = max(a,l);
		b = min(b,r);
	}
	int ans = b-a+1;
	cout << max(ans,0) << endl;
}

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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 2e5+3;

inline int add(int a, int b)
{
	int ret=((ll)a+b)%modn;
	if(ret<0) {
		ret=(ret+modn)%modn;
	}
	return ret;
}

inline int mul(int a, int b)
{
	int ret=((ll)a*b)%modn;
	if(ret<0) {
		ret=(ret+modn)%modn;
	}
	return ret;
}

int n;
vector<int> color;
vector<vector<int>> pos(MAX+3);
vector<int> dp;

int solve(int i)
{
	if(i==n) return 1;
	
	int &memo=dp[i];
	if(memo!=-1) return memo;
	
	//~ int ind=lower_bound(all(pos[color[i]]), i)-pos[color[i]].begin();
	int ind=0;
	
	//~ for(int j=ind; j<sz(pos[color[i]]); j++) {
		//~ int ii=pos[color[i]][j];
		//~ dp[ii]=0;
	//~ }
	
	vector<int> suf;
	int ans=0;
	for(int j=sz(pos[color[i]])-1; j>=ind; j--) {
		int ii=pos[color[i]][j];
		ans=add(ans, solve(ii+1));
		dp[ii]=ans;
	}
	return dp[i];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	cin>>n;
	color=vector<int>(n);
	for(int i=0; i<n; i++) {
		cin>>color[i];
	}
	
	vector<int> newcolor;
	for(int i=0; i<n; i++) {
		if(sz(newcolor)==0 or color[i]!=newcolor.back()) {
			newcolor.push_back(color[i]);
		}
	}
	
	n=newcolor.size();
	color=newcolor;
	
	//~ printV(color);
	
	//~ for(int i=0; i<n; i++) {
		//~ pos[color[i]].push_back(i);
	//~ }
	
	dp=vector<int>(n+1, 0);
	vector<int> pref(MAX+3);
	dp[n]=1;
	
	for(int i=n; i>=1; i--) {
		dp[i-1]=add(dp[i], pref[color[i-1]]);
		pref[color[i-1]]=add(pref[color[i-1]], dp[i]);
	}
	cout<<dp[0]<<"\n";
    return 0;
}



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

typedef long long ll;

bool testk(ll n, ll k){
	while (n%k==0){
		n/=k;
	}
	if ((n-1)%k==0){
		return true;
	}
	return false;
}

int main(){
	ll n;
	cin>>n;
	if (n==2){
		cout<<1<<endl;
		return 0;
	}
	ll cnt = 1;
	for (ll i = 2; i*i<=n; i++){
		if (n%i==0){
			ll sm = i;
			ll la = n/i;
			//smallest is k
			if (testk(n,sm)){
				cnt++;
			}
			if (sm!=la){
				if (testk(n,la)){
					cnt++;
				}
			}
		}
	}
	//how many non-divisors are there
	ll tmp = n-1;
	//how many factors
	ll fcnt = 1;
	for (ll i = 2; i*i<=tmp; i++){
		if (tmp%i==0){
			fcnt++;
			if (i*i!=tmp){
				fcnt++;
			}
		}
	}
	cout<<cnt+fcnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);
    if (a < b)
        printf("a < b\n");
    else if (a > b)
        printf("a > b\n");
    else
        printf("a == b\n");
    
    return 0;
}


Measured memory_bytes: 2700
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
ll loc[200020][3];

vector<int> g[200020];
int far[200010][8];
bool visited[200020][8];
ll ans[200020];

ll calc(int id,int t){
    ll res=0;
    for(int j=0;j<3;j++){
        if(t&(1<<j)) res+=loc[id][j];
        else res-=loc[id][j];
    }
    return res;
}

void dfs(int now,int t,int tar){
    visited[now][t]=true;
    far[now][t]=tar;
    for(auto nex:g[now]){
        if(visited[nex][t]) continue;
        dfs(nex,t,tar);
    }
    return;
}

int main(){
  cin>>N>>M;
  rep(i,N) cin>>loc[i][0]>>loc[i][1]>>loc[i][2];
  rep(i,M){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[b].push_back(a);
  }

  for(int k=0;k<8;k++){
      vector<pair<ll,int>> v;
      for(int i=0;i<N;i++){
          ll r=calc(i,k);
          v.push_back(mkp(r,i));
      }
      sort(v.begin(),v.end());
      reverse(v.begin(),v.end());

      for(int i=0;i<v.size();i++){
          int now=v[i].second;
          if(visited[now][k]) continue;
          dfs(now,k,now);
      }
  }

  for(int i=0;i<N;i++){
      for(int k=0;k<8;k++){
          ans[i]=max(ans[i],calc(i,~k)+calc(far[i][k],k));
      }
      cout<<ans[i]<<endl;
  }

  return 0;
}



Measured memory_bytes: 42420