akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> L(101);

int binarySearch(int key, int n)
{
  int left=0;
  int right = n;
  int m;
  while(right > left)
  {
    m = (left+right)/2;
    if(L.at(m) == key) return m;
    else if(L.at(m) > key)
    {
      right = m;
    }
    else
    {
      left = m+1;
    }
  }
  return right-1;
}

int main()
{
  int n;
  cin >> n;
  int i,j,k;
  for(i=0; i<n; i++)
  {
    cin >> L.at(i);
  }
  
  sort(L.begin(),L.begin()+n);
  
  int num =0;
  int left,right;
  
  for(i=0; i<n-2; i++)
  {
    for(j=i+1; j<n-1; j++)
    {
      if(L.at(i) != L.at(j))
      {
        left = n;
        right = n-1;
        for(k=j+1; k<n; k++)
        {
          if(L.at(k) != L.at(j) && left == n)
          {
            left = k;
          }
          if(L.at(k) > L.at(i)+L.at(j)-1 && right == n-1)
          {
            right = k-1;
          }
        }  
        if(left != n)
        {
          num += right - left + 1;
        }
      }
      else
      {
        cout << endl;
      }
    }
  }
  
  cout << num << endl;
  
  return 0;
}
  
        
        
        
        
       
          
        

  
  
 
  

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

int main() {
  int n,m;
  cin>>n>>m;
  vector<pair<ll,ll>> mz(n);
  rep(i,n){
    ll a,b;
    cin>>a>>b;
    mz[i]=make_pair(a,b);
  }
  sort(mz.begin(),mz.end());
  ll kane=0,zai=0;
  rep(i,n){
    if(zai+mz[i].second<=m){
      kane += mz[i].first*mz[i].second;
      zai += mz[i].second;
    }else if(zai >=m) break;
    else{
      kane += (m-zai)*mz[i].first;
      zai += (m-zai);
    }
  }
  cout<<kane<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
int main()
{
   int a[3];
   int mx=0,sum=0;
   for(int i=0;i<3;i++)
   {
       scanf("%d",&a[i]);
       if(a[i]>mx)
        mx=a[i];
       sum+=a[i];
   }
   printf("%d\n",sum-mx);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    set<string> set_items;
    int n;
    string item;
    cin >> n;
    rep(i,n){
        cin >> item;
        set_items.insert(item);
    }

    cout << set_items.size() << endl;

  return 0;
}

Measured memory_bytes: 19216
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


double Main(int N, VI &A)
{
    double ans = 0.0;
    REP(i, N) ans += 1.0 / A[i];
    return 1.0/ans; 
}

int main(void){
    int N;
    cin >> N;
    VI A(N);
    REP(i, N) cin >> A[i];
    printf("%.12f\n", Main(N, A));
    return 0;
}

Measured memory_bytes: 256
S = input()
slen = len(S)
S = int(S)
count = 0
for i in range(0,slen, 2):
    if ( i == slen-1):
        inv = 1 if i == 0 else 10 ** i
        count = count + (S-inv) + 1
        # print(i, (S-inv) + 1)
    else:
        count = count + 10 ** (i+1) - 10 ** (i)
        # print(i, 10 ** (i+1) - 1)
print(count)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int n,w;
  cin>>n>>w;
  vector<long int> dp(w+1,0);
  for(long int i=0;i<n;i++){
    long int weight,value;
    cin>>weight>>value;
    for(long int capacity=w;capacity>=0;capacity--){
      if(weight<=capacity) dp[capacity]=max(dp[capacity],dp[capacity-weight]+value);
    }
  }
  cout<<dp[w];
  return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
S = input()
N = len(S)

def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True

con1 = is_kaibun(S)
con2 = is_kaibun(S[0:int((N-1)/2)])
con3 = is_kaibun(S[int((N + 3) / 2)-1:])
# print(S, S[0:int((N-1)/2)-1], S[int((N + 3) / 2):])
# print(con1, con2, con3)
if (con1 and con2 and con3):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <stdio.h>
 
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: 580
program main
 implicit none
 real*8 a,b,x,theta,pi
 pi = 4.D0*atan(1.D0)
 read(*,*) a,b,x
 if(x > (a*a*b)/2) then
  theta = atan2(2*(a*a*b-x)/(a*a),a)
 else
  theta = atan2(b,2*x/(a*b))
 end if
 write(*,*) theta*180/pi
end program main

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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}

int numOfTriansOfEachFromTheFirstDToSecondD[502][502];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int n , m , q;
	cin >> n >> m >> q;
	loop(m)
	{
		int l , r;
		cin >> l >> r;
		numOfTriansOfEachFromTheFirstDToSecondD[l][r]++;
	}
	//my prefix sum "Ehab"
	for(int i = n; i>= 1; i--)
	{
		for(int j = 1; j<= n; j++)
		{
			numOfTriansOfEachFromTheFirstDToSecondD[i][j] += numOfTriansOfEachFromTheFirstDToSecondD[i+1][j];
			numOfTriansOfEachFromTheFirstDToSecondD[i][j] += numOfTriansOfEachFromTheFirstDToSecondD[i][j-1];
			numOfTriansOfEachFromTheFirstDToSecondD[i][j] -= numOfTriansOfEachFromTheFirstDToSecondD[i+1][j-1];
		}
	}
	loop(q)
	{
		int l  , r;
		cin >> l >> r;
		cout << numOfTriansOfEachFromTheFirstDToSecondD[l][r] << endl;
	}
    return 0;
}


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

#define jaldi ios_base::sync_with_stdio(false)
#define fr(i,j,n) for(i=j;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppii pair<int,int> 
#define ppll pair<long long,long long>
#define ppcc pair<char,char>
#define ppss pair<string,string> 
#define vpll vector<pair<long long,long long>>
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 998244353

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

int main()
{
    jaldi;
    precision(20);
    
    ll n;
    cin>>n;

    double x=n;
    cout<<2*x*PI<<endl;

    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin >> n >> m >> c;
    vector<vector<int> > a(n,vector<int>(m,0));
    vector<int> b(m,0);
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    
    int k=0;
    for (int i = 0; i < n; i++)
    {
        int sum=0;    
        for (int j = 0; j < m; j++)
        {
            sum+=a[i][j]*b[j];
        }
        sum+=c;
        if(sum>0)
            k++;
    }
    
    cout << k;

}




























































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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fi > xed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  arep(i, x) cin >> i;
  int ans = LINF;
  rep(bit, 0, bits(n)) {
    int sum = 0;
    int cnt = 0;
    int now = 0;
    rep(i, 0, n) {
      if (bit & bits(i)) {
        if (now < x[i])
          now = x[i];
        else {
          ++now;
          sum += (now - x[i]);
        }
        ++cnt;
      } else
        chmax(now, x[i]);
    }
    if (cnt >= k) chmin(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <set>
#include<string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define N 509
int n, b[N], sm, gg[10000], ngg, md, c[N], lst, k, anss;
int main() {
	scanf("%d%d", &n, &k);
	int i, j;
	for (i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
		sm += b[i];
	}
	md = sqrt(sm);
	for (i = 1; i <= md; i++) {
		if (sm%i == 0) {
			gg[++ngg] = i;
			if (i*i != sm) {
				gg[++ngg] = sm / i;
			}
		}
	}
	sort(gg + 1, gg + 1 + ngg);
	lst = 1;
	for (int dv = 1; dv <= ngg; dv++) {
		int pl = 0, plnm, pls = 0;
		for (i = 1; i <= n; i++) {
			c[i] = b[i] % gg[dv];
			pl += c[i];
		}
		plnm = pl / gg[dv];//plnm개의 gg[i], n-plnm개의 0
		sort(c + 1, c + 1 + n);
		plnm = n - plnm;
		for (i = 1; i <= plnm; i++) {
			pls += c[i];
		}
		if (pls <= k) {
			anss = gg[dv];
		}
	}
	printf("%d", anss);
}

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

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

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long 
#define all(x) x.begin(), x.end()
using namespace std ;
const int INF = 1e18 ;
int32_t main(){
	int a,b,q ;
	cin >> a >> b >> q ;
	vector<int> s(a+2) , t(b+2), Q(q);
	for(int i = 0 ; i < a ; i++)
		cin >> s[i] ;
	for(int i = 0 ; i < b ; i++)
		cin >>  t[i] ;
	s[a] = -INF ; s[a+1] = INF ; t[b] = -INF ; t[b+1] = INF ;
	for(int& i : Q)
		cin >> i ;
	
	sort(all(s)) ;		
	sort(all(t)) ;
	for(int i = 0 ; i < q ; i++){
		int target = Q[i] ;
		auto rs = lower_bound(all(s),target) ;
		auto ls = rs - 1 ;
		auto rt = lower_bound(all(t),target) ;
		auto lt = rt - 1 ;
		int shrine[] = {*ls,*rs} ;
		int temple[] = {*lt,*rt} ;
		int d = 1e20 ;
		for(int i = 0 ; i < 2 ; i++){
			for(int j = 0 ; j < 2 ; j++){
				d = min(abs(target - shrine[i]) + abs(shrine[i] - temple[j]) , d ) ;
				d = min(abs(target - temple[j]) + abs(temple[j] - shrine[i]) , d ) ;
			}
		}
		cout << d << endl ;		
	}
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
using namespace std;
int main() {
    string a,b,d;
    //a = "atcoderbeginnercontest";
    //b = "atcoderregularcontest";
    cin >> a >> b;
    int c = a.size();
    int e = b.size();
    for (int i = 0;i < c;i++){
        d.push_back(a[i]);
        d.push_back(b[i]);
    }
    if (c != e){
        d.pop_back();
        //cout << "Nullを排除" << endl;
    //}else{
        //cout << "Nullは排除されなかった" << endl;
    }
        cout << d;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<ll> a(3);
	REP(i,3) cin >> a[i];
	ll ans = INF * INF;
	REP(i,3) REP(j,3) REP(k,3) {
		if(i == j || j == k || k == i) continue;
		ans = min(ans,abs(a[i] - a[j]) + abs(a[j] - a[k]));
	}
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */


Measured memory_bytes: 256
//Abid's code for debug
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,r,c,i,j,k=0;
    cin>>r>>c;
    int ar[r+5][c+5];
    int cn[r*c+5][4+5];
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cin>>ar[i][j];
        }
    }
     for(i=0;i<r;i++)
    {
        for(j=0;j<c-1;j++)
        {
            if(ar[i][j]%2!=0)
            {
                k++;
                ar[i][j+1]=ar[i][j+1]+1;
                ar[i][j]=ar[i][j]-1;
             cn[k-1][0]=i;
              cn[k-1][1]=j;
               cn[k-1][2]=i;
                cn[k-1][3]=j+1;


            }
           // cout<<ar[i][j]<<" ";
        }
        //cout<<ar[i][c-1];
        //cout<<endl;
    }
    for(j=c-1;j<c;j++)
    {
        for(i=0;i<r-1;i++)
        {
            if(ar[i][j]%2!=0)
            {
                k++;
                ar[i+1][j]=ar[i+1][j]+1;
                ar[i][j]=ar[i][j]-1;
             cn[k-1][0]=i;
              cn[k-1][1]=j;
               cn[k-1][2]=i+1;
                cn[k-1][3]=j;


            }
        }
    }
//     for(i=0;i<r;i++)
//    {
//        for(j=0;j<c;j++)
//        {
//            cout<<ar[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    cout<<k<<endl;
    for(i=0;i<k;i++)
    {
        for(j=0;j<4;j++)
        {
            if(j!=3)cout<<cn[i][j]+1<<" ";
            else cout<<cn[i][j]+1<<endl;
        }
    }


}


Measured memory_bytes: 9004
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Long n = sc.nextLong();
        Long a = sc.nextLong();
        Long b = sc.nextLong();
        Long res = a*(n/(a+b));
        Long amari = n%(a+b);
        res += Math.min(amari, a);
        System.out.println(res);

    }
}


Measured memory_bytes: 23636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

vector<int> ans;
vector<vector<pair<int, int>>> g;
int n;

void dfs(int pos, int par, int dist) {

	if (pos == par)return;
	if (ans[pos] != -1)return;
	ans[pos] = dist;

	for (int i = 0; i < g[pos].size(); i++) {
		LL ret = (dist+(g[pos][i].second % 2))%2;

		dfs(g[pos][i].first, pos, ret);
		
	}

	return;

}


int main() {

	cin >> n;

	ans.resize(n);

	for (int i = 0; i < n; i++) {
		ans[i] = -1;
	}

	g.resize(n);

	for (int i = 0; i < n-1; i++) {
		int x, y, z; cin >> x >> y >> z;
		x--; y--;
		g[x].push_back({ y,z });
		g[y].push_back({ x,z });
	}

	dfs(0, -1, 0);

	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}


	
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int main (){
  double N;
   int K;
  cin >>N>>K;
  double p;
  for (int i=1;i<N+1;i++){
    int l=0;
    if (i>K-1){
      p+=1/N;
    }
    else{
      while(i*pow(2.0,l)<K){
        l++;
      }
      p+=1/N*pow(1/2.0,l);
  }
  }
  printf("%.12f\n",p);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define rrep(i,n) ll(i)=(n);ll now=-1;while((i)--&&(now++||1))
#define vll vector<ll>
#define pb push_back
#define Yes(n) cout<<((n)?Yes:No)<<"\n"

using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here
const string Yes = "Yes";
const string No = "No";

void solve(ll N, ll K, ll Q, vector<ll> A){
    vll points(N, K - Q);
    rep(i, Q) points.at(A.at(i) - 1)++;
    rep(i, N) Yes(points.at(i) > 0);
}

int main() {
    ll N;
    ignore_ret(scanf("%lld",&N));
    ll K;
    ignore_ret(scanf("%lld",&K));
    ll Q;
    ignore_ret(scanf("%lld",&Q));
    vector<ll> A(Q);
    for(int i = 0 ; i < Q ; i++){
        ignore_ret(scanf("%lld",&A[i]));
    }
    solve(N, K, Q, move(A));
    return 0;
}

Measured memory_bytes: 2176
import sys
input = sys.stdin.readline
INF = 10**5
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)

def main():
    h,w = map(int,input().split())
    grid = [list(input()) for _ in range(h)]

    dp = [[INF] * (w + 1) for _ in range(h + 1)]

    if grid[0][0] == '.':
        dp[1][1] = 0
    else:
        dp[1][1] = 1

    for i in range(h):
        for j in range(w):
            if i == 0 and j == 0:
                continue
            if grid[i][j] == '.':
                dp[i + 1][j + 1] = min(dp[i + 1][j],dp[i][j + 1])
            else:
                if j - 1 >= 0: 
                    if grid[i][j - 1] == '.':
                        dp[i + 1][j + 1] = min(dp[i + 1][j + 1],dp[i + 1][j] + 1)
                    else:
                        dp[i + 1][j + 1] = min(dp[i + 1][j + 1],dp[i + 1][j])
                if i - 1 >= 0:
                    if grid[i - 1][j] == '.':
                        dp[i + 1][j + 1] = min(dp[i + 1][j + 1],dp[i][j + 1] + 1)
                    else:
                        dp[i + 1][j + 1] = min(dp[i + 1][j + 1],dp[i][j + 1])
    
    print(dp[-1][-1])    
if __name__=='__main__':
    main() 

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,x,i,sum=0;
    cin>>n>>m;
    for(i=0; i<m; i++)
    {
        cin>>x;
        sum=sum+x;
    }

    if(sum>n)
    {
        cout<<-1<<endl;
    }
else
{cout<<n-sum<<endl;}

}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//差が2以内の数は操作により同じ数にできる 差が2以内の数の集合のうち、要素数がmaxのものを出力
/*先頭から順に見ていき、差が2まではカウントを増やす。差が2より大きくなると、その数より２だけ小さい数が在れば、その数の１個目からカウント再開、無ければ１だけ小さい数からカウント再開、無ければその数からカウント再開。　カウントが途切れるたびに最大のものに更新していく*/
//数とその個数のペア配列を作る
int main() {
  int N;
	cin >> N;
	vector<int> a(N);
	for(int i = 0;i<N;i++){
		cin >> a[i];
	}

 sort(a.begin(),a.end());
 a.push_back(-1);
 int c = 1;
 vector<pair<int,int>> p;
 for(int i = 0;i<N;i++){
	 if(a[i] == a[i+1]){
		 c++;
	 }
	 if(a[i] != a[i+1]){
    p.push_back(make_pair(a[i],c));
		c = 1;
     }
	 }
	 if(p.size() == 1) cout << p[0].second << endl;
	else{
      p.push_back(P(1000000,1));
    int C = 0;
	int ans  = 0;
	int i = 0;
	int j = 0;
	while(true){
		if(p[j].first - p[i].first <= 2){
			C += p[j].second;
			j++;
		}
   	else if(p[j].first - p[i].first > 2){
		 ans = max(ans,C);
		 i++;
		 C = 0;
		 if(p[j].first - p[i].first <= 2){
			 j = i;
		 }
		 else i++;
	  }
    if(i == p.size()-1) break;
		}
	cout << ans << endl;
	}
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    int n;
    int count=0;

    cin>>n;
    vector<int> p(n);

    FOR(i,0,n-1){
        cin>>p[i];
    }

    FOR(i,1,n-2){
        if((p[i]!=max(p[i-1],max(p[i],p[i+1])))&&(p[i]!=min(p[i-1],min(p[i],p[i+1])))){
            count++;
        }
    }

    cout<<count<<endl;

}


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

int main()
{
    int N;
    scanf("%d", &N);
    stack<pair<string, char>> task;
    task.push(pair<string,char>("",'a'));
    while(!task.empty()){
        auto p = task.top();
        task.pop();
        if(p.first.length() >= N) { printf("%s\n", p.first.c_str()); continue; }
        char cmax = p.second;
        for(char c = cmax; c >= 'a'; --c) {
            task.push(pair<string,char>(p.first + c, ((c == cmax) ? (char)(cmax + 1) : cmax)) );
        }
    }
    return 0;
}

Measured memory_bytes: 1536
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll f[N], s[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, i, x, m, p;
    cin >> n >> x >> m;
    s[1] = p = x;
    f[x] = 1;
    for (i = 2; i <= n; i++)
    {
        x = p * p % m;
        p = x;
        s[i] = s[i - 1] + x;
        if (f[x])
            break;
        f[x] = i;
    }
    if (i == n + 1)
        return cout << s[n], 0;
    ll q = (n - f[x] + 1) / (i - f[x]);
    ll r = (n - f[x] + 1) % (i - f[x]);
    ll ans = (s[i] - s[f[x]]) * q + s[f[x] + r - 1];
    cout << ans;
}

Measured memory_bytes: 4708
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<ll> a(3 * n);
  rep(i, 3 * n) cin >> a[i];

  sort(a.begin(), a.end(), greater<ll>());
  ll ans = 0;
  rep(i, n) {
    ans += a[2 * i + 1];
  }
  cout << ans << '\n';






  
  return 0;
}

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

int str_to_num(string s) {
    return atoi(s.c_str());
}

int main(){
  string s; cin >> s;
  int a = str_to_num(s.substr(0,2));
  int b = str_to_num(s.substr(2,2));
  bool a_1to12 = a>0 && a<13;
  bool b_1to12 = b>0 && b<13;
  if(a_1to12){
    if(b_1to12){
      cout << "AMBIGUOUS" << endl;
    }else{
      cout << "MMYY" << endl;
    }    
  } else if(b_1to12){
    cout << "YYMM" << endl;
  } else{
    cout << "NA";
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}



int main(){
    unsigned long long N;
    cin >> N;
    // scanf("%lld",&N);
    // 1000000000000001
    // N=754;
    unsigned long long q=N;
    unsigned long long r=N%26;
    string s;

    do {
        q--;
        char c='a'+q%26;
        s+=c;
        q/=26;
    } while (q>0);

    reverse(all(s));
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	ll h, x = 0, ans = 1, n = 1;
	cin >> h;
	while (h /= 2)
		x++;
	for (ll i = 0; i < x; ++i) {
		n *= 2;
		ans += n;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class alds15a
{
    static void Main(){
        Console.ReadLine();
        string[] A=Console.ReadLine().Split(' ');
        List<int> list=new List<int>();
        foreach (string a in A)
        {
            int num;
            if (int.TryParse(a, out num))
            {
                int len = list.Count;
                for (int i = 0; i < len; i++)
                {
                    list.Add(list[i] + num);
                }
                list.Add(num);
            }
        }
        Console.ReadLine();
        string[] B=Console.ReadLine().Split(' ');
        foreach(string b in B)
        {
            int tgt;
            if(int.TryParse(b,out tgt))
            {
                if (list.Contains(tgt))
                {
                    Console.WriteLine("yes");
                }
                else
                {
                    Console.WriteLine("no");
                }
            }
        }
    }
}

Measured memory_bytes: 20328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int n;
cin >> n;
vector<int> h(n);
rep(i,n) cin >> h[i];

vector<int> kai(n);

reverse(all(h));
kai[0] = 0;
int ans = 0;

for(int i=1; i < n;i++){
    if(h[i] - h[i-1] >= 0) kai[i] = kai[i-1] + 1;
    else kai[i] = 0;
    ans = max(ans,kai[i-1]);
}

ans = max(ans,kai[n-1]);

cout << ans << endl;

return 0;
}

Measured memory_bytes: 1024
from decimal import Decimal
 
def solve():
	n = int(input())
 
	sum = Decimal("0")
	for i in range(n):
		amount, type = input().split()
		if type == "JPY":
			sum += Decimal(amount)
		else:
			sum += Decimal(amount)*Decimal("380000.0")
	return sum
  
print(solve())

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> W(N);
  int lw=0,rw=0;
  for(int i=0;i<N;i++){
    cin>>W[i];
    rw+=W[i];
  }
  lw+=W[0];
  rw-=W[0];
  int m=abs(lw-rw);
  for(int i=1; i<N-1; i++){
    lw+=W[i];
    rw-=W[i];
    int a=abs(lw-rw);
    m=min(a,m);
  }
  cout<<m<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int i;
    for(i=0;i<=N-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        int A,B,C;
        A=a*a;
        B=b*b;
        C=c*c;
        if(A==B+C)  cout<<"YES";
        else if(B==A+C)  cout<<"YES";
        else if(C==A+B) cout<<"YES";
        else    cout<<"NO";
        cout<<endl;
    }
}


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

#define ll long long
#define ull unsigned long long 

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> s(n);

    for(int i=0; i<n; ++i){
        cin >> s[i];
    }
    
    vector<int> vr, vc;
    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j){
            if(s[i][j] == '#'){
                vr.emplace_back(i);
                break;
            }
        }
    }

    for(int i=0; i<m; ++i){
        for(int j=0; j<n; ++j){
            if(s[j][i] == '#'){
                vc.emplace_back(i);
                break;
            }
        }
    }

    for(int i=0; i<(int)vr.size(); ++i){
        for(int j=0; j<(int)vc.size(); ++j){
            cout << s[vr[i]][vc[j]];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;

long long gcd(long long a, long long b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    long long n, X, ans = 0, x[100000];

    cin >> n >> X;
    for(int i=0; i<n; ++i) scanf("%lld", &x[i]);
    
    if(n == 1){
        cout << abs(x[0] - X) << endl;
        return 0;
    }

    sort(x, x + n);

    ans = x[1] - x[0];
    for(int i=2; i<n; ++i){
        ans = gcd(x[i] - x[0], ans);
    }

    cout << gcd(ans, X - x[0]) << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    int a, b;
    cin >> a >> b;
    bool k = true;
    char s[11];
    for (int i = 0; i < a+b+1; i++){
        cin >> s[i];
        if (i == a){
            if (s[a] != '-') k = false;
        } else {
            if (!(s[i]-'0'>= 0&&s[i]-'0'<=9)){
                k = false;
            }
        }
    }
    if (k == true) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main()
{
    int a, b;
    while (1) {
        cin >> a >> b;
        if (a == 0 && b == 0) break;
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int po[11];

int main(){
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  int ans = 0;
  int p = min(n,k);
  ans += p*x;
  n -= p;
  ans += n*y;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
N=int(input())
l=list(map(int,input().split()))
c=gcd(l[0],l[1])
for i in range(1,N-1):
  c=gcd(l[i],c)
print(c)

Measured memory_bytes: 14252
<?php

// Atcoder ABC 120 D問題の解説放送で出ていたコードをPHPにした奴
class UnionFind
{
    // 親のノードの番号を格納する。自身が親ノードだった場合には-(その集合のサイズ)
    // (普通のUnionFindだと親を-1にするらしいが、-(サイズ)にすると便利らしい)
    // キー: 自身のノードの番号、値: 親のノードの番号
    // ex) $parents[1] = 10 だった場合、1の親は10
    private $parents = [];

    public function getParents()
    {
        return $this->parents;
    }

    public function setParents($parents)
    {
        $this->parents = $parents;
    }

    public function getParent($node)
    {
        return $this->parents[$node];
    }

    public function setParent($node, $value)
    {
        $this->parents[$node] = $value;
    }

    public function __construct($node_number)
    {
        // -1で初期化することで全てのノードを親なしで初期化
        $this->setParents(array_fill(0, $node_number, -1));
    }

    /**
     * 所属しているグループの取得
     */
    public function root($A)
    {
        if ($this->getParent($A) < 0) {
            return $A;
        } 

        // 親が判明した後で、親を繋ぎかえる
        $this->setParent($A, $this->root($this->getParent($A)));

        return $this->getParent($A);
    }

    /**
     * 所属しているグループの頂点数
     */
    public function size($A)
    {
        return -1 * $this->getParent($this->root($A));
    }

    public function connect($A, $B)
    {
        $ra = $this->root($A);
        $rb = $this->root($B);

        // すでに接続している
        if ($ra === $rb) return false;

        if ($this->size($ra) > $this->size($rb)) {
            // Aのサイズを更新
            $this->setParent(
                $ra, 
                $this->getParent($ra) + $this->getParent($rb)
            );

            // Bの親をAに変更
            $this->setParent($rb, $ra);
        } else {
            // Bのサイズを更新
            $this->setParent(
                $rb, 
                $this->getParent($ra) + $this->getParent($rb)
            );

            // Bの親をAに変更
            $this->setParent($ra, $rb);
        }

        return true;
    }
}

fscanf(STDIN, "%d %d", $n, $m);
$A = [];
$B = [];
for ($i = 0; $i < $m; ++$i) {
    fscanf(STDIN, "%d %d", $a, $b);
    --$a;
    --$b;
    $A[] = $a;
    $B[] = $b;
}

$ans = [];
$ans[$m - 1] = (int) ($n * ($n - 1) / 2);

$uni = new UnionFind($n);
for ($i = $m - 2; $i >= 0; --$i) {
    if ($uni->root($A[$i + 1]) !== $uni->root($B[$i + 1])) {

        $ans[$i] = $ans[$i + 1] - (int) $uni->size($A[$i + 1]) * $uni->size($B[$i + 1]);
        $uni->connect($A[$i + 1], $B[$i + 1]);
    } else {
        $ans[$i] = $ans[$i + 1];
    }
}

for ($i = 0; $i < $m; ++$i) {
    echo $ans[$i], PHP_EOL;
}


Measured memory_bytes: 24436
mod = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= mod
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= mod
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[-1][5])


Measured memory_bytes: 64348
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <sstream>

using namespace std;

int main() {
    int a[7] = {1,3,5,7,8,10,12},b[4] = {4,6,9,11},d,e,flaga = 0,flagb = 0;

    cin >> d >> e;

    for(int i = 0;i < 7;i++){
        if(d == a[i] || e == a[i]){
            flaga++;
        }
    }

    for(int j = 0;j < 4;j++){
        if(d == b[j] || e == b[j]){
            flagb++;
        }
    }

    if(flaga == 2 || flagb == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

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

    int q;
    cin >> q;
    bool prime[100001] = {false};
    int sum[100002] = {0};
    repi(i, 100000 + 1, 2)
    {
        if (!prime[i])
        {
            for (int j = i + i; j <= 100000; j += i)
            {
                prime[j] = true;
            }
        }
    }
    for (int i = 3; i <= 100000; i += 2)
    {
        if (!prime[i] && !prime[(i + 1) / 2])
            sum[i]++;
    }
    repi(i, 100000 + 1, 3)
    {
        sum[i + 1] += sum[i];
    }
    repi(ri, q, 0)
    {
        int r, l;
        cin >> l >> r;
        cout << sum[r] - sum[l - 1] << endl;
    }

    return 0;
}


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

int main(void)
{
    int K,S;
    cin >> K >> S;

    int sum = 0;
    for(int x = 0; x <= K; x++)
    {
        for(int y = 0; y <= K; y++)
        {
            int Z = S - x - y;
            if((Z >= 0) && (Z <= K))
            {
                sum++;
            }
        }
    }
    cout << sum << endl;

    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
const ll INF=1e18,MOD=1e9+7;
bool comp(ll a,ll b){
    return abs(a)>abs(b);
}
int main(){
    int n,k;
    cin>>n>>k;
    cout<<n%k<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main(){
  int n;
  cin >> n;
  priority_queue<P,vector<P>,greater<P>> ab;
  priority_queue<P,vector<P>,greater<P>> cd;
  for(int i=0; i<n; ++i){
    int a, b;
    cin >> a >> b;
    ab.push(make_pair(a,b));
  }
  for(int i=0; i<n; ++i){
    int c, d;
    cin >> c >> d;
    cd.push(make_pair(c,d));
  }
  int ans = 0;
  vector<int> b(0);
  while(!cd.empty()){
    while(!ab.empty() && ab.top().first < cd.top().first){
      int bi = ab.top().second;
      b.push_back(bi);
      ab.pop();
    }
    int d = cd.top().second;
    cd.pop();
    int isnam = -1;
    for(int i=0; i<(int)b.size(); ++i){
      if(b[i] < d) isnam = max(isnam, b[i]);
    }
    //cout << d << " " << isnam << endl;
    for(int i=0; i<(int)b.size(); ++i){
      if(b[i] == isnam) b[i] = 1000;
    }
    if(isnam != -1) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;

    int l, i = 1, A[N+1];
    while (cin >> l) {
        A[i] = l;
        // cout << h[i] << " ";
        i++;
        if (i >= N+1) {
            break;
        }
    }

    int B[N+1];
    for (int j = 1; j <= N; j++)
    {
        B[A[j]] = j;
    }
    
    for (int k = 1; k <= N; k++)
    {
        cout << B[k] << " ";
    }
    
    
}

Measured memory_bytes: 1536
#include<iostream>
    #include<vector>
    #include<string>
     #include<algorithm>
    using namespace std;
     
    int main()
    {
    int n, k; cin>>n>>k;
    string names[121];
    string temp;
    for(int i = 0; i<n; i++)
    {
    cin>>names[i];
    }
     
    sort(names, names+n);
     
    for(int i=0; i<n; i++) cout<<names[i];
    cout<<endl;
    return 0;
     }

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

using namespace std;

int main()
{
    string s;
    unordered_map<string, int> m;
    string longest;
    while (cin >> s) {
        m[s] += 1;
        if (s.size() > longest.size()) {
            longest = s;
        }
    }
    cout << max_element(begin(m), end(m),
                        [](const decltype(m)::value_type& a,
                           const decltype(m)::value_type& b) {
                            return a.second < b.second;
                        })
                ->first
         << ' ' << longest << endl;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define    ll   long long int
#define    sz   200010
#define    md   1000000007
#define    py   printf("Yes\n")
#define    pn   printf("No\n")

using namespace std;


ll ara[sz];


int main()
{


     ll a,b,n;

     cin>>a>>b;
     a=a*3;
     a+=b;

     cout<<a/2<<endl;



    return 0;
}


Measured memory_bytes: 256
use std::cmp;

fn main() {
    let mut sc = Scanner::new();
    let s: Vec<char> = sc.read::<String>().chars().collect();
    let n = s.len();

    if n % 2 == 1 {
        let mut i = 0;
        let center = n / 2;
        while center >= i && s[center + i] == s[center - i] && s[center] == s[center + i] {
            i += 1;
        }
        let core = (i - 1) * 2 + 1;
        println!("{}", (n - core) / 2 + core);
    } else {
        let mut i = 0;
        let center = n / 2;
        while n / 2 >= i + 1 && s[center - 1 - i] == s[center + i] && s[center] == s[center + i] {
            i += 1;
        }
        let core = i * 2;
        println!("{}", (n - core) / 2 + core);
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    int ans = 0;
    forn(i, n) {
        int x, y;
        cin >> x >> y;
        ans += y - x + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256