akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	ll N,Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	vector<char> t(Q),d(Q);
	FOR(i,0,Q)cin>>t[i]>>d[i];
	vector<bool> ok(N+2,true);
	s = 'x'+s+'x';
	ok[0]=ok[N+1]=false;
	ll l=0,r=N+1;

	FORR(i,0,Q){
		if(d[i]=='L'){
			if(s[l+1]==t[i]){
				l += 1;
			}
			if(s[r]==t[i]){
				r++;
			}
		}else{
			if(s[r-1]==t[i]){
				r -= 1;
			}
			if(s[l]==t[i]){
				l -= 1;
			}
		}
		if(l<0)l=0;
		if(r>N+1)r=N+1;
	}
	ll ans = 0;
	FOR(i,1,N+1){
		if(i>l&&i<r)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll r;
    cin>>r;
    long double ans=6.2831853071795*r;
    cout<<ans;

    return (0);
}


Measured memory_bytes: 3800
import math

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

ans=0

for i in range(n-1):
    for k in range(i+1,n):
        temp=0.0
        for j in range(d):
            temp+=(dl[i][j]-dl[k][j])*(dl[i][j]-dl[k][j])
        tempr=math.sqrt(temp)
        if tempr.is_integer():
            ans+=1

print(ans)

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

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int main(){
   string s;
   cin >> s;
   int sum = 0;
   for(int i = 0; i < s.size(); i++){
    sum += s[i] - '0';
   }
   puts((sum % 9) ? "No" : "Yes");
   return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

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

class Main {



    public static int getMaxCost(int numberOfDays, int[] ah, int[] bh, int[] ch) {
        int[][] memo = new int[numberOfDays][4];
        for(int i=0;i<numberOfDays;i++)
            Arrays.fill(memo[i], -1);
        return getMaxCostHelper(0, numberOfDays, ah, bh, ch, 3, memo);
    }

    private static int getMaxCostHelper(int day, int numberOfDays, int[] ah, int[] bh, int[] ch, int taken,
                                        int[][] memo) {
        if(day == numberOfDays) {
            return 0;
        }

        if(memo[day][taken] != -1) {
            return memo[day][taken];
        }


        int poss1 = (taken != 0) ? ah[day] + getMaxCostHelper(day + 1, numberOfDays, ah, bh, ch, 0, memo) : Integer.MIN_VALUE;
        int poss2 = (taken != 1) ? bh[day] + getMaxCostHelper(day + 1, numberOfDays, ah, bh, ch, 1, memo) : Integer.MIN_VALUE;
        int poss3 = (taken != 2) ? ch[day] + getMaxCostHelper(day + 1, numberOfDays, ah, bh, ch, 2, memo) : Integer.MIN_VALUE;

        return memo[day][taken] = Math.max(poss1, Math.max(poss2, poss3));
    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numberOfDays = scanner.nextInt();
        int[] aH = new int[numberOfDays];
        int[] bH = new int[numberOfDays];
        int[] cH = new int[numberOfDays];

        for(int i=0; i<numberOfDays; i++) {
            aH[i] = scanner.nextInt();
            bH[i] = scanner.nextInt();
            cH[i] = scanner.nextInt();
        }
        System.out.println(getMaxCost(numberOfDays, aH, bH, cH));
    }

}

Measured memory_bytes: 107940
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
int dp[4005][2005];
int main(){
	int n,m,K,ans=0;
	scanf("%d%d%d",&n,&m,&K);
	for(int k=1;k<K;k++)
	if(k<=m&&K-k<=n)dp[1][k]=1;
	for(int i=2;i<=(n+m-1)/(K-1);i++)
	rep1(j,m){
		//第i层，用了j个1
		int check=i*(K-1)+1-j;
		if(check<=0||check>n)continue;
		rep(k,K)dp[i][j]=(dp[i][j]+dp[i-1][j-k])%INF;
	}
	rep1(i,(n+m-1)/(K-1))rep1(j,m)
	if((m-j)%(K-1)==0)ans=(ans+dp[i][j])%INF;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 30464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	
	static BufferedReader reader =
			new BufferedReader(new InputStreamReader(System.in));
	
	public static void main(String[] args) throws IOException{
		Main byakko = new Main();
		
		int n,count;;
		
		while((n = Integer.parseInt(reader.readLine())) != 0){
		count = 0;
		
		while(n != 1){
			n = byakko.number(n);
			count++;
		}
		System.out.println(count);
		}
		reader.close();
	}
	
	public int number(int n){
		if(n % 2 == 0){
			n /= 2;
		}
		else{
			n = n * 3 + 1;
		}
		return n;
	}
	
}

Measured memory_bytes: 16876
/*
    @Author
       Sujeet Kushwaha
    */
     
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define fast ios_base::sync_with_stdio(false)
    #define fast_input cin.tie(NULL)
    #define fast_output cout.tie(NULL)
    // #define vi vector<long long int> 
    #define pb push_back
    #define mp make_pair
    #define pp pop_back
    #define iter vector<int>::iterator
    #define pa pair<long long int ,long long int> 
    #define f(a,b) for(int a=0;a<b;a++)
    #define mod 1000000007
    #define F first
    #define S second
    #define sett set<long long int>
    #define um unordered_map<ll,ll>
    ll powmod(ll a, ll b)
    {
        ll res = 1;
        while (b) {
            if (b&1) {
                res *= a;
            }
            b >>= 1;
            a = (a * a);
        }
     
        return res;
    }
     
    // ll modInv(ll a)
    // {
    //     return powmod(a, mod - 2);
    // }
    // int fastread(){
    //     int x=0;
    //     int c = getchar_unlocked();
    //     while(c<48)
    //         c = getchar_unlocked();
    //     while(c>=48){
    //         x = x*10 + (c - 48);
    //         c = getchar_unlocked();
    //     }
    //     return x;
    // }
    ll b[100005];
    void solve()
    {
        ll r;
      cin>>r;
      ll ans=r*r;
      cout<<ans;
        
        
    }
    int main() {
    	fast;
    	fast_input;
    	fast_output;
    // 	ll t;
    // 	cin>>t;
    // 	while(t--)
    // 	{
    	  solve();
    // 	}
    	return 0;
    }

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

int main() {
  int X;
  cin>>X;
    if(X<600){cout<<8<<endl;}
  else if(X<800){cout<<7<<endl;}
  else if(X<1000){cout<<6<<endl;}
  else if(X<1200){cout<<5<<endl;}
  else if(X<1400){cout<<4<<endl;}
    else if(X<1600){cout<<3<<endl;}
    else if(X<1800){cout<<2<<endl;}
    else {cout<<1<<endl;}
}

Measured memory_bytes: 3628
def main(N,A):
    B=[0]
    count = 0
    for i in range(N):
        T = A[i] + B[i]

        B.append(T)


    B = sorted(B)
    # print(B)
    c = 0
    for i in range(len(B)):
        if i==0:
            continue
        if B[i] == B[i-1]:
            c+=1
            count +=c
            # print(c)
            # 
            # print(count)
        else:
            c = 0

    return print(count)

if __name__ == "__main__":
    N=int(input())
    A=list(map(int,input().split()))

    main(N,A)


Measured memory_bytes: 31680
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
vector<vector<pair<ll,ll>>> v;
vector<ll> dist;
void dfs(ll cur, ll par,ll point=0){
    dist[cur] = point;
    // cout<<"cur:"<<cur<<", par:"<<par<<endl;
    for(ll i=0;i<v[cur].size();i++){
        ll next = v[cur][i].first;
        ll next_point = v[cur][i].second+point;
        // cout<<"next:"<<next<<endl;
        if(next!=par){
            dfs(next,cur,next_point);
        }
    }
    return;
}

int main(){
    long N;
    cin>>N;
    v.resize(N);
    dist.resize(N);
    for(ll i=0;i<N-1;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    
    ll Q,K;
    cin>>Q>>K;
    K--;
    ll x[Q],y[Q];
    for(ll i=0;i<Q;i++){
        ll _x,_y;
        cin>>_x>>_y;
        _x--;_y--;
        x[i] = _x;
        y[i] = _y;
    }
    dfs(K,-1);
    for(ll i=0;i<Q;i++){
        cout<<dist[x[i]]+dist[y[i]]<<"\n";
    }




}

Measured memory_bytes: 15872
using System;

namespace JOI
{
    class marubatsu
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var ans = 0;
            
            for(var i = 1; i < N; i++)
            {
                if(S[i] != S[i - 1])
                {
                    ans++;
                    i++;
                }
            }
            Console.WriteLine(ans);
            
        }
    }
}


Measured memory_bytes: 18036
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iterator>

using COST_T = uint64_t;
constexpr uint32_t N_MAX = 100000;
constexpr COST_T INF = 10000000000000000;//std::numeric_limits<double>::infinity()

#if defined(_MSC_VER) && defined(_DEBUG)
//static_assert(false, "リリースでコンパイルしないと遅いよ！！");
#endif

struct edge {
	uint32_t to;
	COST_T cost;
	edge() {}
	edge(uint32_t to_, COST_T cost_)
		:to(to_), cost(cost_) {}
};
std::vector<edge> graph1[N_MAX];
std::vector<edge> graph2[N_MAX];

//ダイクストラ
COST_T D1[N_MAX];
COST_T D2[N_MAX];
void Dijkstra(uint32_t s, COST_T (&D)[N_MAX], std::vector<edge> (&graph)[N_MAX])
{
	using P = std::pair<COST_T, uint32_t>;//cost pos
	std::priority_queue<P, std::vector<P>, std::greater<>> que;
	std::fill(std::begin(D), std::end(D), INF);

	D[s] = 0;
	que.emplace(0, s);
	while (!que.empty())
	{
		auto p = que.top(); que.pop();
		const auto& nowpos = p.second;
		const auto& nowcost = p.first;
		if (D[nowpos] < nowcost) { continue; }

		//for (int32_t to = 0; to < N; ++to)
		//{
		//	auto cost = nowcost + graph[nowpos][to];
		//	if (cost < D[to]) {
		//		D[to] = cost;
		//		que.emplace(D[to], to);
		//	}
		//}

		for (const auto& e : graph[nowpos])
		{
			auto cost = nowcost + e.cost;
			if (cost < D[e.to]) {
				D[e.to] = cost;
				que.emplace(cost, e.to);
			}
		}

	}
}



int32_t N,M;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	int s, t;
	in >> s >> t; --s; --t;
	for (int32_t i = 0; i < M; i++)
	{
		int a, b, c1, c2;
		in >> a >> b >> c1 >> c2; --a; --b;
		graph1[a].emplace_back(b, c1);
		graph1[b].emplace_back(a, c1);

		graph2[a].emplace_back(b, c2);
		graph2[b].emplace_back(a, c2);
	}

	Dijkstra(s, D1, graph1);
	Dijkstra(t, D2, graph2);

	std::vector<COST_T> res_rev;
	auto res_now = INF;
	for (int i = N - 1; i >= 0; i--)
	{
		res_now = std::min(res_now, D1[i]+ D2[i]);
		res_rev.push_back(res_now);
	}


	for (int i = N - 1; i >= 0; i--)
	{
		out << (999999999999999+1 - res_rev[i]) << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 20280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	ll cnt = 0;
	makei(N);
	makel(K);
	vector<pii> v;
	rep(N) {
		int a, b;
		cin >> a >> b;
		v.push_back({ a,b });
	}
	sort(all(v));
	int i = 0;
	while (cnt < K) {
		cnt += v[i++].second;
	}
	say(v[i - 1].first);
}

Measured memory_bytes: 1400
#include<stdio.h>
int main(void)
{
  int n,i,flag=0,j;
  scanf("%d",&n);
  for(i=1;i<=9;i++)
  {
    for(j=1;j<=9;j++)
    {
  	if(n==i*j)
    flag = 1;
    }
  }
  if(flag==1)
    printf("Yes");
  else 
    printf("No");
 return 0; 
}

Measured memory_bytes: 128
//C - Forbidden List

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  rep(i, N) cin >> p[i];

  vector<bool> isValid(102, true);
  rep(i, N) {
    isValid[p[i]] = false;
  }

  int ans;
  int tmp = 1000;
  rep(i, 102) {
    if (isValid[i] && abs(X - i) < tmp) {
      ans = i;
      tmp = abs(X - i);
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
	int n,k,x,y;
  	cin >> n >> k >> x >> y;
  	int sum=0;
  	if(n-k>0){
    	sum += k*x +(n-k)*y;
    }
  	else{
    	sum += n*x;
    }
  	cout << sum << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define ll long long
#define int long long
#define ld long double
#define pii pair <int , int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const int maxn = 3e5 , N = 1e5 + 5 , SQ = 600 , base = 1999 , mod = 1e9 + 7 , INF = 1e18 , lg = 17;

int n , k , a[maxn] , dp[maxn];

int32_t main() {
    FAST
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    fill(dp , dp + maxn , INF);
    dp[0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i - 1; j >= max(0ll , i - k); --j) {
            dp[i] = min(dp[i] , dp[j] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 6728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include<stack>
#include <unordered_map>

using namespace std;

int abs(int x) { return x < 0 ? -x : x; }

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0, a; i < N; i++) {
		cin >> a;
		A[i] = a;
	}
	sort(A.begin(), A.end());
	long h = 0;
	for (int i = N - 1; i >= 1;) {
		if (A[i] == A[i - 1]) {
			if (h == 0)h = A[i];
			else {
				cout << h * A[i];
				return 0;
			}
			i--;
		}
		i--;
	}
	cout << 0;
	return 0;
}



Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
char buf[1025], res[128], mem[26], *p;
int n, l, r, h, t;
int main()
{
    n = atoi(fgets(buf, 1025, stdin));
    while (n--) {
        memset(res, 0, sizeof(res));
        memset(mem, 0, sizeof(mem));
        fgets(buf, 1025, stdin);
        p = &buf[strlen(buf)-1];
        if (*p == '\n') *p = '\0';

        h = t = 0;
        l = sizeof(res) / 2 - 1;
        r = sizeof(res) / 2 + 1;
        res[sizeof(res) / 2] = buf[0];
        mem[buf[0]-'a'] = 1;
        REP(i, 1, strlen(buf)) {
            if (buf[i] == '-') continue;
            else if (buf[i] == '<') { h = 1; t = 0; }
            else if (buf[i] == '>') { h = 0; t = 1; }
            else {
                if (mem[buf[i]-'a']) continue;
                mem[buf[i]-'a'] = 1;
                if (h) res[l--] = buf[i];
                else if (t) res[r++] = buf[i];
            }
        }
        rep(i, sizeof(res)) if (res[i] > 0) putchar(res[i]);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> a,b,c;
  ll p;
//  ll a[n],b[n],c[n];
  /*for(ll i=0;i<n;i++) cin >>a[i];
  for(ll i=0;i<n;i++) cin >>b[i];
  for(ll i=0;i<n;i++) cin >>c[i];*/
  for(ll i=0;i<n;i++) {
    cin >>p;
    a.push_back(p);
  }
  for(ll i=0;i<n;i++) {
    cin >>p;
    b.push_back(p);
  }
  for(ll i=0;i<n;i++) {
    cin >>p;
    c.push_back(p);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  ll ans=0;
  for(ll i=0;i<n;i++){
  ll k=lower_bound(a.begin(),a.end(),b[i])-a.begin();
  ll j=upper_bound(c.begin(),c.end(),b[i])-c.begin();
  ans+=(k*(n-j));
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 3316
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Point[] arr = new Point[n];
		int zero = 0;
		for(int i=0;i<n;i++){
			
			arr[i] = new Point(sc.nextInt(), sc.nextInt(), sc.nextInt());
			
			if(arr[i].h==0)
			    zero++;
		}
		
		if(zero==n){
		    System.out.println("0 0 1");
		}
		else{
			
			Arrays.sort(arr, new Comparator<Point>(){

				@Override
				public int compare(Point arg0, Point arg1) {
					// TODO Auto-generated method stub
					return -Integer.compare(arg0.h, arg1.h);
				}
				
			});
			
    		int h = 0;
    		boolean val=true;
    		L1:for(int x=0;x<=100;x++){
    			for(int y=0;y<=100;y++){
    				val=true;
    				for(int i=0;i<n;i++){
    					if(i==0){
    						h = Math.abs(x-arr[i].x)+Math.abs(y-arr[i].y)+arr[i].h;
    					}
    					else{
    						if(Math.max(h-Math.abs(x-arr[i].x)-Math.abs(y-arr[i].y), 0)!=arr[i].h){
    							val=false;
    							break;
    						}
    					}
    				}
    				if(val && h>=1){
    					System.out.println(x+" "+y+" "+h);
    					break L1;
    				}
    			}
    		}   
		}
	}
}
class Point{
	int x, y, h;
	Point(int x, int y, int h){
		this.x=x;
		this.y=y;
		this.h=h;
	}
}
/*
4
2 3 5
2 1 5
1 2 5
3 2 5

5
2 3 5
2 1 5
1 2 5
3 2 5
10 20 0

2
47 23 0
10 20 1
*/

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> query(101);
string s, tmp;
void sendQuery()
{
    cout << '?';
    for (int i = 0; i < n; i++)
        cout << ' ' << query[i];
    cout << endl;
    cin >> tmp;
    if (tmp[0] == '-')
        exit(1);
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        query[i] = i + 1;
    sendQuery();
    s.insert(0, tmp);
    int l = 1, r = n + 1;
    while (r - l > 1)
    {
        int mid = (l + r) / 2;
        for (int i = 0; i < n; i++)
            query[i] = mid + i;
        sendQuery();
        if (s[0] == tmp[0])
            l = mid;
        else
            r = mid;
    }
    vector<bool> ans(2 * n, 0);
    ans[l - 1] = (s[0] == 'R');
    ans[l + n - 1] = !(s[0] == 'R');
    for (int i = 0; i < n - 1; i++)
        query[i] = l + 1 + i;
    for (int i = 1; i <= 2 * n; i++)
    {
        if (i >= l && i <= l + n)
            continue;
        query[n - 1] = i;
        sendQuery();
        ans[i - 1] = (tmp[0] == 'R');
    }
    int hlp;
    query[n - 1] = l + n;
    for (int i = 0; i < n - 1; i++)
    {
        hlp = query[i];
        query[i] = l;
        sendQuery();
        query[i] = hlp;
        ans[l + i] = !(tmp[0] == 'R');
    }
    cout << "! ";
    for (int i = 0; i < 2 * n; i++)
        cout << (ans[i] ? 'R' : 'B');
    cout << endl;
    return 0;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x;
    cin>>n>>x;
    vector<ll> a(n);
    REP(i,n) cin>>a[i];
    ll ans=0;
    if(a[0]>x){
        ans+= a[0] - x;
        a[0] = x;
    }
    REP(i,n-1){
        if(a[i]+a[i+1]>x){
            ll minus = max(a[i]+a[i+1] - x,0LL);
            a[i+1] -= minus;
            ans+=minus;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  std::vector<int> a(n);
  for(int i=0;i<n-1;i++){
    int tmp=0;
    cin >> tmp;
    a.at(tmp-1)++;
  }
  for(int i=0;i<n;i++){
    cout << a.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3988
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b, x;
	cin >> a >> b;

	x = a + b - 1;

	cout << a * b - x << endl;


}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long

ll ans;
ll P[100001];
ll L[100001];

ll root (ll i) {
  if (P[i] == i) return i;
  else {
    return P[i] = root(P[i]);    
  }  
}

void unite (ll i, ll j) {
  ll x = root(i);
  ll y = root(j);
  if (x == y) return ;  
  if (x != y) {
    P[y] = x;
    ans += L[x] * L[y];
    L[x] += L[y];  
  }
}

int main () {
  ll n, m;
  ans = 0;
  cin >> n >> m;
  for (ll i = 0; i <= n; i++) {
    P[i] = i;
    L[i] = 1;  
  }  
  ll A[m], B[m];
  ll ANS[m];
  for (ll i = 0; i < m; i++) {
    cin >> A[i] >> B[i];  
    ANS[i] = 0;
  }
  for (ll i = 0; i < m; i++) {
    ll j = m - 1 - i;
    unite(A[j], B[j]);
    ANS[j] = ans;
  }
  for (ll i = 0; i < m - 1; i++) {
    cout << n * (n - 1) / 2 - ANS[i + 1] << endl;    
  }
  cout << n * (n - 1) / 2 << endl;


}

Measured memory_bytes: 5376
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

const int INF = 1e9;
int n;
ll a[100100];

int mini = INF;

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

  cin >> n;
  REP(i,n) {
    cin >> a[i];
    if(a[i] < mini) mini = a[i];    
  }

  bool f = true;
  while(f){
    int tmp = mini;
    int cnt = 0;
    REP(i, n) {
      if(a[i]%mini != 0){
	a[i] %= mini;
      }
      else{
	cnt++;
      }
    }
    if(cnt == n) break;
    REP(i, n) mini = min((int)a[i], mini);
    
  }


  cout << mini << endl;
  //sort(a, a+n);
  //cout << a[0] << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  vector<ll> x(n + 1);
  for (int i = 0; i < n; i++){
    cin >> x[i];
  }
  ll sum = 0;

  for (int i = 1; i<n; i++){
    if((x[i]-x[i-1]) * a > b){
      sum += b;
    }else {
      sum += (x[i] - x[i - 1]) * a;
    }
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 1024
import math
n, d = input().split()
n = int(n)
d = int(d)
ans = 0
for i in range(n):
    x, y = input().split()
    x = int(x)
    y = int(y)
    r = x * x + y * y
    if math.sqrt(r) <= d:
        ans += 1
print(ans)

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


int main(void){
    int N;
    cin >> N;
    

    int D = N%10;
    int C = (N%100-N%10)/10;
    int B = (N%1000-N%100)/100;
    int A = (N-N%1000)/1000;
    int sum = 0;
    string op1,op2,op3,op4;
   for(int i = 0; i <(1<<3);++i){
       
        sum +=A;
        
       
        if (i & (1<<0)){sum +=B;op2="+";}
        else{sum -= B;op2="-";}
        
        if (i & (1<<1)){sum += C;op3="+";}
        else{sum -= C;op3="-";}
       
        if (i & (1<<2)){sum += D;op4="+";}
        else{sum -= D;op4="-";}
        
        if(sum == 7)break;
        sum = 0;
   }
    
    cout << A << op2 << B << op3 << C << op4 <<D <<"=7"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<set>
using namespace std;
set<string> ss;
int main(){
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		ss.insert(s);
	}
	cout<<ss.size();
    return 0;
}

Measured memory_bytes: 19196
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <array>
#include <limits>
//#include <tuple>

using namespace std;

//constexpr long long mod = static_cast<long long>(1e9 + 7);


int main() {
    int V, E, r;
    std::cin >> V >> E >> r;

    std::vector<std::vector<std::pair<int, int>>> edges(V, std::vector<std::pair<int, int>>());
    while(--E >= 0) {
        int s, t, d;
        std::cin >> s >> t >> d;
        edges[s].push_back(std::make_pair(t, d));
    }

    std::vector<int> dist(V, std::numeric_limits<int>::max());
    dist[r] = 0;
    while(--V >= 0){
        for(int i = 0; i < edges.size(); ++i) {
            for(const auto& edge: edges[i]) {
                int v = edge.first;
                int w = edge.second;
                if(dist[i] != std::numeric_limits<int>::max()) {
                    dist[v] = std::min(dist[v], dist[i] + w);
                }
            }
        }
    }

    bool isNegative = false;
    for(int i = 0; i < edges.size(); ++i) {
        for(const auto& edge: edges[i]) {
            int v = edge.first;
            int w = edge.second;
            if(dist[i] != std::numeric_limits<int>::max()
               && dist[v] > dist[i] + w) isNegative = true;
        }
    }

    if(isNegative) {
        std::cout << "NEGATIVE CYCLE" << std::endl;
    } else {
        for (auto val: dist) {
            if(val != std::numeric_limits<int>::max())std::cout << val << std::endl;
            else std::cout << "INF" << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
bool isVowel(char c){
  string vowels("aeiou");
  for(char vowel:vowels)if(vowel==c)return true;
  return false;
}
main(){
  char c;
  cin>>c;
  cout<<(isVowel(c)?"vowel":"consonant")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 505;

ll d[MX][MX];
ll e[MX][MX];
ll dp[MX][MX];

int main() {
  int n;
  scanf("%d",&n);
  vvi a(n,vi(n));
  rep(i,n)rep(j,n) {
    if (i == j) continue;
    scanf("%d",&a[i][j]);
  }
  rep(l,n) {
    ll x = 0;
    srep(r,l,n) {
      srep(i,l,r) x += a[i][r];
      e[l][r+1] = x;
    }
  }
  rep(l,n) {
    ll x = 0;
    srep(r,l,n) {
      srep(i,l,r) x += a[r][i];
      d[l][r+1] = x;
    }
  }
  rep(i,n+1)rep(j,n+1) dp[i][j] = LINF;
  dp[0][0] = d[0][n];
  rep(i,n)srep(j,i,n) {
    srep(k,j+1,n+1) {
      ll now = dp[i][j];
      now += e[j][k];
      now -= d[i][k] - d[i][j];
      mins(dp[j][k], now);
    }
  }
  ll ans = LINF;
  rep(i,n) mins(ans, dp[i][n]);
  cout<<ans<<endl;
  return 0;
}






















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

int main(){

  int n,l;
  int i,j;
  int a[300];
  int sum = 0;
  int flag = 0;

  scanf("%d %d", &n, &l);

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

  i = 0;
  while(1){
    for(j = 1;j <= n;j++) if(abs(a[j]) == i){
      sum -= a[j];
      flag = 1;
      break;
    }

      if(flag == 1) break;

      i++;
  }

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


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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int A, B ,C;
	
	cin >> A >> B >> C;
	
	if(C - (A - B) >= 0)
		cout << C - (A - B);
	else
		cout << 0;
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

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

	int n;
	cin >> n;

	int even = n / 2;
	int odd = (n + 1) / 2;

	cout << even * odd << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

class Combination {
private:
    int64_t mod; // 元, 素数でないとNG
    int64_t max_size; // 最大値, 10^7まで
    vector<int64_t> factorial; // 階乗
    vector<int64_t> inverse; // 逆元
    vector<int64_t> inverse_factorial; // 逆元の階乗

    void init() {
        // 値は1で初期化する
        factorial.assign(max_size, 1);
        inverse.assign(max_size, 1);
        inverse_factorial.assign(max_size, 1);
        for (auto i = 2; i < max_size; i++) {
            factorial[i] = factorial[i - 1] * i % mod;
            inverse[i] = mod - inverse[mod % i] * (mod / i) % mod; // 拡張Euclidの互除法の変形版
            // inverse[i] = modinv(i); // Fermatの小定理
            inverse_factorial[i] = inverse_factorial[i - 1] * inverse[i] % mod;
            // cout << i << " " << factorial[i] << " " << inverse[i] << " " << inverse_factorial[i] << endl;
        }
    };
public:;
    Combination(int64_t mod, int64_t max_size) {
        this->mod = mod;
        assert(max_size < 1e7);
        this->max_size = max_size + 1;
        // テーブル生成
        init();
    };
    virtual ~Combination(){};

    int64_t modpow(int64_t a, int64_t n) {
        int64_t ret = 1;
        while(n > 0) {
            if(n & 1) ret = ret * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return ret;
    };
    int64_t modinv(int64_t a) { return modpow(a, mod - 2); };
    int64_t combination(int64_t n, int64_t k) {
        if (n < k) return 0;
        if (n < 0 or k < 0) return 0;
        // cout << factorial[n] << " " << inverse_factorial[k] << " " << inverse_factorial[n - k] << endl;
        return factorial[n] * (inverse_factorial[k] * inverse_factorial[n - k] % mod) % mod;
    };
};

int main(){
    int x, y;
    cin >> x >> y;

    int a = x / 2, b = (x - a * 2);
    while(y != a + b * 2) {
        a--; b+=2;
        // cout << a << " " << b << " " << a * 2 + b << " " << a + b * 2 << endl;
        if(a < 0 or b > y / 2) {
            cout << 0 << endl;
            return 0;
        }
    }

    int64_t mod = 1e9+7, n = a + b;
    Combination c(mod, n);

    cout << c.combination(n, a) % mod << endl;
    return 0;
}

Measured memory_bytes: 18812
N = int(input())
A = list(map(int,input().split()))
C = []
for _ in range(N):
  C.append([])
for i in range(N):
  C[i].append(A[i])
for j in range(N):
  C[j].append(j+1)
C.sort(key = lambda x:x[0])
B = [C[k][1] for k in range(N)]
for s in B:
  print(s,end = ' ')


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n;

    cin>>n;

    li a[n+1];

    f(i,1,n)
    {
        cin>>a[i];
    }

    vi sum(n+1);

    vi dp(n+1);

    f(i,1,n)
    {
        sum[i]=(i>2?sum[i-2]:0)+a[i];
    }

    f(i,2,n)
    {
        if(i&1)
            dp[i]=max(dp[i-1],dp[i-2]+a[i]);
        else
            dp[i]=max(sum[i-1],dp[i-2]+a[i]);
    }

    cout<<dp[n];

    return 0;
}

Measured memory_bytes: 7916
import math
n,d=map(int,input().split())

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

cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    s=0
    for k in range(d):
      s+=(x[i][k]-x[j][k])**2
    if int(math.sqrt(s))**2==s:
      cnt+=1
      
print(cnt)
  

Measured memory_bytes: 9128
A, B = map(int, input().split())

def F(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return 1 ^ n
    else:
        return 0

print(F(A - 1) ^ F(B))


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt() % 10;
            System.out.println((N == 0 || N == 1 || N == 6 || N == 8) ? "pon" : (N == 3) ? "bon" : "hon");
        }
    }
}


Measured memory_bytes: 26988
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
    
#define f first
#define s second
    
int n,m,a[N], x,y, dsu[N], cnt;
    
int findparent(int u)
{
    if(u == dsu[u]) return u;
    return dsu[u] = findparent(dsu[u]);
}

void merge(int u, int v)
{
    u = findparent(u);
    v = findparent(v);
    dsu[u] = v;
}
    
int main() {
    iota(dsu, dsu+N, 0);
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n ; i++) scanf("%d",a+i);
    while(m--)
    {
        scanf("%d%d",&x,&y);
        merge(x,y);
    }
    for(int i=1; i<=n; i++)
    {
        cnt += (findparent(i) == findparent(a[i]));
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b,k;
    cin >> a >> b >> k;
    if(b-a+1 <= 2*k){
        FOR(i,a,b+1)cout << i << endl;
        return 0;
    }
    FOR(i,a,a+k)cout << i << endl;
    FOR(i,b-k+1,b+1)cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <ctime>
#include <climits>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define sz(x) (int)(x.size())

typedef long long ll;
typedef tuple<int, int, int> tri;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef __gnu_pbds::tree<
    int,
    __gnu_pbds::null_type,
    less<int>,
    __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>
    ordered_set;

const ll MODULO = 1000000007;

void ftime()
{
#ifndef ONLINE_JUDGE
    cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}

static int speed_increase = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    return 0;
}();

vll arr(2e5+1);
vll pre(2e5+1);
void solve()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i) cin>>arr[i];
    for(int i=1; i<=n; ++i) {
        pre[i] = (pre[i-1]+arr[i])%MODULO;
    }
    ll sum = 0;
    for(int i=n; i>1; --i) {
        sum = (pre[i-1]*arr[i]+sum)%MODULO;
    }
    cout<<sum<<"\n";
}

int main()
{
    solve();
    // ftime();
    return 0;
}

Measured memory_bytes: 6336
#import sys
#input = sys.stdin.readline
def main():
    A = list( map( int, input().split()))
    C = [0]*11
    for a in A:
        C[a] += 1
    if C[5] == 2 and C[7] == 1:
        print("YES")
    else:
        print("NO")
if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint pow(i64 r) const noexcept {
    modint ans(1);
    modint aa = *this;
    while(r) {
      if(r & 1) {
        ans *= aa;
      }
      aa *= aa;
      r >>= 1;
    }
    return ans;
  }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

template<const i64 M>
std::ostream& operator<<(std::ostream& os, const modint<M>& m) {
  os << m.value();
  return os;
}

using fp = modint<(i64)(1e9 + 7)>;

int main() {
  i64 N, K;
  cin >> N >> K;
  cout << fp(K).pow(N) << endl;
}



Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();
		
		double[] doubleArray = new double[n];
	
		for(int i=0; i < n; i++) {
		    int s = sc.nextInt();
		    double result = a - (t - (s * 0.006));
		    result = result * result;
		    doubleArray[i] = result;
		}
		
		double min = doubleArray[0];	
		int result2 = 0;
		for (int i=0; i<doubleArray.length; i++) {
			if (min > doubleArray[i]) {	
				min = doubleArray[i];	
				result2 = i;
			}
		}
		System.out.println(result2 + 1);
	}

}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    srand(time(0));
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i < n; i++) cin >> v[i];
    multiset<int> kek;
    for (int i=0; i < n; i++) kek.insert(v[i]);
    int ans = 0;
    while (kek.size()){
        auto it = kek.end();
        it--;
        int num = *it;
        kek.erase(it);
        for (int i=0; i < 40; i++){
            if ((1LL<<i) > num){
                int D = (1LL<<i) - num;
                //cout << D << endl;
                if (kek.size() && kek.find(D) != kek.end()){
                    ans++;
                    kek.erase(kek.find(D));
                }
                //cout << 1 << endl;
                break;
            }
        }
        //kek.erase(kek.end());
    }
    cout << ans;

}


Measured memory_bytes: 11264
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <iterator>      // std::next prev


using namespace std;


int main() {   
    std::ios::sync_with_stdio(false);
	int n,t;
	cin>>n>>t;
	vector<int> start(n);
	for(int i = 0 ; i < n ; i++)
	{
		cin>>start[i];
	}
	
	long long begin = 0;
	long long end = t;
	long long ans = 0;
	for(int i = 0 ; i < n ; i++)
	{
		int st = start[i];
		if(st<end)
		{
			end = st+t;
		}
		else
		{
			ans += end - begin;
			begin = st;
			end = begin + t;
		}
	}
	cout<<ans+end-begin;

	return 0;
}


Measured memory_bytes: 1024