akhauriyash/Code-Regression huggingface dataset:
line = readlines.map(&:to_i)

N = line[0]

ans = []
for i in 1..N do
  if ans == [] then
    ans.push(line[i])
  else
    found = false
    j = (ans.length - 1) / 2
    min = 0
    max = ans.length
    while found == false do
      if ans[j] >= line[i] then
        min = j + 1
        j = (max + j) / 2
      elsif ans[j] < line[i] then  #can be colored j
        max = j
        j = (min + j) / 2
      end
      if min == max then
        found = true
      end
    end
    if min == -1 then
      ans.push(line[i])
    else
      ans[min] = line[i]
    end
  end
end
        
print ans.length

Measured memory_bytes: 11772
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;

  string ans;
  for(auto c: s) {
    if(c == 'B') {
      if (!ans.empty()) ans.pop_back();
    } else {
      ans.push_back(c);
    }
  }

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


Measured memory_bytes: 256
<?php
  fscanf(STDIN,"%d %d %d",$n, $k, $q);
  for($i=1; $i<=$n; $i++){
    $player[$i] += $k;
    $player[$i] -= $q;
  }
  for($i=0; $i<$q; $i++){
    $player[trim(fgets(STDIN))] += 1;
  }
  for($i=1; $i<=$n; $i++){
    if($player[$i] > 0){
      echo "Yes\n";
    }else{
      echo "No\n";
    }
  }

Measured memory_bytes: 10744
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


int main() {
    Int N,T,ans;
    cin >> N >> T;
    vi t = vi(N);

    rep(i,N){
        cin >> t[i];
    }

    ans = T;
    REP(i,1,N){
        if(t[i]-t[i-1]>T){
            ans+=T;
        }else{
            ans+= T-(T-(t[i]-t[i-1]));
        }
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define f(x1,y1,x2,y2)(a[x2][y2]-a[x1][y2]-a[x2][y1]+a[x1][y1])
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

int uniquell(ll*p,ll*ans,int cnt){
	ll*a=malloc(sizeof(ll)*cnt);
	memcpy(a,p,sizeof(ll)*cnt);
	sortup(a,cnt);
	int c=0;
	ans[0]=a[0];
	rep(i,1,cnt)if(a[i]!=ans[c])ans[++c]=a[i];
	return c+1;
}

//座圧2
//uniquell(a,comp,n)でcompに昇順の配列を作る
ll cocompf(ll n,ll*comp,ll compcnt){
	//comp[i]<=n<comp[i+1]なるiを返す
	ll l=0,r=compcnt;
	while(r-l>1){
		ll m=(l+r)/2;
		if(comp[m]<=n)l=m;
		else r=m;
	}
	return l;
}

int a[5010][5010];
ll x[5010],y[5010];
ll cx[5010],cy[5010];

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,0,n)scanf("%lld%lld",x+i,y+i);
	x[n]=y[n]=-INF;
	x[n+1]=y[n+1]=INF;
	int xcnt=uniquell(x,cx,n+2);
	int ycnt=uniquell(y,cy,n+2);
	
	rep(i,0,n){
		int pp=cocompf(x[i],cx,xcnt)+1;
		int qq=cocompf(y[i],cy,ycnt)+1;
		a[pp][qq]++;
	}
	rep(i,0,xcnt+5)rep(j,0,ycnt+5)a[i][j+1]+=a[i][j];
	rep(j,0,ycnt+5)rep(i,0,xcnt+5)a[i+1][j]+=a[i][j];
	
	rep(_,0,m){
		ll p,q,r,s;
		scanf("%lld%lld%lld%lld",&p,&q,&r,&s);
		int x1=cocompf(p-1,cx,xcnt)+1;
		int y1=cocompf(q-1,cy,ycnt)+1;
		int x2=cocompf(r,cx,xcnt)+1;
		int y2=cocompf(s,cy,ycnt)+1;
		printf("%lld\n",f(x1,y1,x2,y2));
	}
}



Measured memory_bytes: 100108
#include <stdio.h>
#include <stdlib.h>

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, u, w, N, M;
	scanf("%d %d", &N, &M);
	list **adj = (list**)malloc(sizeof(list*) * (N + 1)), *d = (list*)malloc(sizeof(list) * M * 2);
	for (i = 1; i <= N; i++) adj[i] = NULL;
	for (i = 0; i < M; i++) {
		scanf("%d %d", &u, &w);
		d[i*2].v = w;
		d[i*2+1].v = u;
		d[i*2].next = adj[u];
		d[i*2+1].next = adj[w];
		adj[u] = &(d[i*2]);
		adj[w] = &(d[i*2+1]);
	}
	
	int ans = 0, l;
	list *p;
	for (i = 2, l = 1; i <= N; i++) {
		for (p = adj[i]; p != NULL; p = p->next) {
			if (p->v >= l && p->v < i) {
				ans++;
				l = i;
				break;
			}
		}
	}
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    double s = (a + b + c) / 2;
    double sum = s * (s - a) * (s - b) * (s - c);
    cout << sqrt(sum) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#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 = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && a + b >= c)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
// Copyright 2020 yaito3014
#include "bits/stdc++.h"
using namespace std;

int main() {
  cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  int64_t K;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (auto& e : A)cin >> e;
  sort(begin(A), end(A));
  int64_t Max = 1e18;
  int64_t low = -Max-1, high = Max;
  while (high - low > 1) {
    int64_t mid = low + (high - low) / 2;
    int64_t n = 0;
    for (int i = 0; i < N; ++i) {
      int d;
      if (A[i] >= 0) {
        auto iter = partition_point(next(begin(A), i + 1), end(A), [&](int64_t v) { return A[i] * v < mid; });
        d = distance(next(begin(A), i + 1), iter);
      }
      else {
        auto iter = partition_point(rbegin(A), prev(rend(A), i + 1), [&](int64_t v) { return A[i] * v < mid; });
        d = distance(rbegin(A), iter);
      }
      n += d;
    }
    if (n >= K)high = mid;
    else low = mid;
  }
  cout << high-1 << endl;
}


Measured memory_bytes: 1792
// abc134c: Exception Handling
#include <stdio.h>

int search(int k, int *a, int n){
  int l=0,r=n,m;
  while(l<r){ m=(l+r)/2; if(a[m]<k) r=m; else l=m+1; }
  return l;
}

int main(){
  int n;scanf("%d",&n);
  int g[n],m = 0;
  for(int i=0;i<n;i++){
    int a;scanf("%d",&a);
    int j = search(a,g,m);
    g[ j<m? j: m++ ] = a;
  }
  printf("%d\n",m);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int x,y;
	bool ans=true;
	cin >>x>>y;
	if(y%2!=0){
		ans=false;
	}else if(x*2 >y){
		ans=false;
	}else if(x*4 <y){
		ans=false;
	}
	cout<<solve(ans)<<endl;
}

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

int main()
{
	string S;
  cin >> S;
  bool flag = false;
  
  for(int i = 0; i < S.size(); i++){
   if(i%2 == 0){
     if(S.at(i) == 'L'){
       flag = false;
       cout << "No" << endl;
       break;
     }	else {
       flag = true;
     }
   } else{
     if(S.at(i) == 'R'){
       flag = false;
       cout << "No" << endl;
       break;
     } else {
       flag = true;
     }
   }
  }    

  if(flag)
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  double q, x;

  while(1){
    scanf("%lf", &q);
    if(q == -1.0) break;

    x = q/2;
    while(1){
      x = x - (x*x*x - q)/(3*x*x);
      if(x*x*x-q>-0.00001*q && x*x*x-q<0.00001*q)
	break;
    }
    printf("%f\n", x);
  }

  return 0;
}

Measured memory_bytes: 0
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  ds <- T.getContents :: IO T.Text
  let
    s = length . filter (uncurry (==)) . (T.zip <$> id <*> T.tail) $ ds :: Int
  print $ (s + 2 * k) `min` (n - 1)


Measured memory_bytes: 4960
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll h,w,counth=0,countw=0;
    cin>>h>>w;
    vector<string> a(h);
    rep(i,h) cin>>a[i];
    rep(i,h) {
        ll c=0;
        rep(j,w){
        if(a[i].at(j)=='.') c++;
        }
        if(c==w) {
            countw++;
            rep(j,w) a[i].at(j)='a';
        }
    }
    rep(i,w){
        ll c=0;
        rep(j,h){
            if(a[j].at(i)=='.' || a[j].at(i)=='a') c++;
        }
        if (c==h){
            counth++;
            rep(j,h) a[j].at(i)='a';
        }
    }
    
    rep(i,h){
        ll d=0;
        rep(j,w){
            if(a[i].at(j)!='a') {
                d++;
                if(d==w-counth) cout<<a[i].at(j)<<endl;
                else cout<<a[i].at(j);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		String A = sc.next(), B = sc.next(), C = sc.next();
		int ans = 0;
		for(int i = 0; i < N; i++) {
			if(A.charAt(i) == B.charAt(i) && B.charAt(i) == C.charAt(i)) {
				continue;
			}else if(A.charAt(i) != B.charAt(i) && A.charAt(i) != C.charAt(i) && B.charAt(i) != C.charAt(i)) {
				ans += 2;
			}else {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  long ans=0;
  if(a>b) ans=0;
  else if(n==1&&a!=b) ans=0;
  else if(n==1&&a==b||n==2) ans=1;
  else ans=(n-2)*(b-a)+1;

  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
N = gets
d = N.length
n = N.to_i

cnt = 0
3.upto(d) do |i|
	['3', '5', '7'].repeated_permutation(i) do |num|
		next if !num.include?('3')
		next if !num.include?('5')
		next if !num.include?('7')
		num = num.join('').to_i
		if num <= n
          cnt += 1
		end
    end
end

puts cnt

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << (double)(W * H) / 2.0 << " ";
    if(x * 2 == W && y * 2 == H) cout << "1" << endl;
    else cout << "0" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std ;
int main()
{
  int A, B, k ;
  cin >> A >> B  ;
  
  if((A-B)%2 == 0){
  k = (A+B)/2 ;
    cout << k <<endl ;
  }
  
  else {
    cout << "IMPOSSIBLE" <<endl ;
  }
  

  
  return 0 ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 200005
#define INF 1000000007

typedef long long int lli;

int main(void) {
  int h, n;
  scanf("%d %d", &h, &n);
  int a[MAX], b[MAX];
  rep(i, 0, n) scanf("%d %d", &a[i], &b[i]);

  // dp[i]:体力iのモンスターを倒すのにかかる魔力の最小値
  int dp[MAX] = {0};
  rep(i, 0, MAX) dp[i] = INF;
  dp[0] = 0;
  rep(i, 0, h) {
    rep(ni, 0, n) {
      if (dp[i] == INF) continue;
      dp[i + a[ni]] = min(dp[i] + b[ni], dp[i + a[ni]]);
    }
  }

  int ans = INF;
  rep(i, h, MAX) {
    ans = min(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}


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

int main()
{
	double ary[10] ;

	while( cin >> ary[0] )
	{
		double sum = ary[0] ;
		for( int i = 1 ; i < 10 ; i ++ )
		{
			if( i %2 == 1 ){ ary[i] = ary[i-1]*2 ; }
			else if( i %2 == 0 ){ ary[i] = ary[i-1]/3 ; }
			sum += ary[i] ;
		}
		printf("%.8f\n",sum) ;
	}
	return 0 ;
}

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

namespace ABC_Training
{

    public class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            PriorityQueue<long> priorityQueue = new PriorityQueue<long>(n, (x, y) => (x - y == 0 ? 0 : x - y > 0 ? -1 : 1));
            for(int i = 0; i< n; i++)
            {
                priorityQueue.Enqueue(a[i]);
            }
            for(int i = 0; i< m; i++)
            {
                var tmp = priorityQueue.Dequeue();
                tmp /= 2;
                priorityQueue.Enqueue(tmp);
            }
            var sum = 0L;
            for(int i = 0; i < n; i++)
            {
                sum += priorityQueue.Dequeue();
            }
            Console.WriteLine(sum);

            
        }
    }
    class PriorityQueue<T>
    {
        private readonly List<T> m_list;
        private readonly Func<T, T, int> m_compare;
        private int m_count;
        public PriorityQueue(int capacity, Func<T, T, int> compare)
        {
            m_list = new List<T>(capacity);
            m_compare = compare;
            m_count = 0;
        }
        private int Add(T value)
        {
            if (m_count == m_list.Count)
            {
                m_list.Add(value);
            }
            else
            {
                m_list[m_count] = value;
            }
            return m_count++;
        }
        private void Swap(int a, int b)
        {
            T tmp = m_list[a];
            m_list[a] = m_list[b];
            m_list[b] = tmp;
        }
        public void Enqueue(T value)
        {
            int c = Add(value);
            while (c > 0)
            {
                int p = (c - 1) / 2;
                if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                c = p;
            }
        }
        public T Dequeue()
        {
            T value = m_list[0];
            m_list[0] = m_list[--m_count];
            int p = 0;
            while (true)
            {
                int c1 = p * 2 + 1;
                int c2 = p * 2 + 2;
                if (c1 >= m_count) { break; }
                int c = (c2 >= m_count || m_compare(m_list[c1], m_list[c2]) < 0) ? c1 : c2;
                if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                p = c;
            }
            return value;
        }
    }
}


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

using namespace std;

typedef long long ll;
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / gcd(a, b) * b
 
int main()
{
    int a1, m1, a2, m2, a3, m3;
 
    while (1) {
	cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3;
	if (a1 + m1 + a2 + m2 + a3 + m3 == 0) break;
 
	ll xx = 0, yy = 0, zz = 0;
	ll x = 1, y = 1, z = 1;
	while (1) {
	    x = a1 * x % m1;
	    xx++;
	    if (x == 1) break;
	}
	while (1) {
	    y = a2 * y % m2;
	    yy++;
	    if (y == 1) break;
	}
	while (1) {
	    z = a3 * z % m3;
	    zz++;
	    if (z == 1) break;
	}
	cout << lcm(xx, lcm(yy, zz)) << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>
#define INF 1<<30
#define int long long

typedef struct {
  int vertics;
  int cost;
}pair;
void Search_path(int **,int*,int,int*);
void minHeapify(pair *,int,int);
void swap(pair *,int,int);
signed main(){
  int i,j,k,n,m,dast;
  int *flag,*distant,**array;

  scanf("%lld",&n);
  flag = malloc(sizeof(int)*n);
  distant = malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    flag[i]=0;
    distant[i]=INF;
  }
  array = malloc(sizeof(int *)*n);
  for(i=0;i<n;i++){
    scanf("%lld %lld",&dast,&m);
    array[i]=malloc(sizeof(int)*(2*m+1));
    array[i][2*m]=-1;
    for(j=0;j<m;j++)scanf("%lld %lld",&array[i][j*2],&array[i][j*2+1]);
  }

  //for(i=0;i<n;i++){
  // for(j=0;array[i][j*2]!=-1;j++)printf(" %lld",array[i][j*2]);
  //printf("\n");
  //}
  
  //
  Search_path(array,flag,n,distant);
  
   for(i=0;i<n;i++)printf("%lld %lld\n",i,distant[i]);
  //
 
  for(i=0;i<n;i++)free(array[i]);
  free(array);
  free(flag);
  free(distant);

  return 0;
}

void Search_path(int **array,int *flag,int n,int *distant){
  int queue_count=0,i,j,num=0,tmp_vertics,tmp_cost,p;
  pair queue[500001];
  
  flag[num]=1;
  distant[num]=0;
  while(1){
    for(i=0;array[num][i*2]!=-1;i++){
      if(flag[array[num][i*2]] == 0){
	
	j=++queue_count;
	queue[j].vertics=array[num][i*2];
	queue[j].cost=distant[num]+array[num][i*2+1];
	while(j > 1 && queue[j/2].cost > queue[j].cost){
	  swap(queue,j,j/2);

	  //tmp_vertics=queue[j].vertics;
	  //tmp_cost=queue[j].cost;
	  
	  //queue[j].vertics=queue[j/2].vertics;
	  //queue[j].cost=queue[j/2].cost;
	  
	  //queue[j/2].vertics=tmp_vertics;
	  //queue[j/2].cost=tmp_cost;
	  
	  j = j/2;
	}
      }
    }
    /**
    printf("%lld",queue_count);
    for(p=0;p<=queue_count;p++)printf("B(%lld %lld)",queue[p].vertics,queue[p].cost);
    printf("\n");
    **/
    if(queue_count == 0)break;
    p=num;
    num = queue[1].vertics;
    if(flag[num]==0)  distant[num]= queue[1].cost;
    
    flag[num]=1;

    queue[1].vertics= queue[queue_count].vertics;
    queue[1].cost = queue[queue_count--].cost;
    /**
    printf("%lld",queue_count);
    for(p=0;p<=queue_count;p++)printf("A(%lld %lld)",queue[p].vertics,queue[p].cost);
    printf("\n");
    **/
    minHeapify(queue,1,queue_count);
    
  }
};
      
void minHeapify(pair *queue,int i,int queue_count){
  int l,r,min;

  l = i*2;
  r = i*2+1;
  if( l <= queue_count && queue[l].cost < queue[i].cost)min=l;
  else min = i;
  if( r <= queue_count && queue[r].cost < queue[min].cost)min=r;
  if(min != i){
    swap(queue,i,min);
    minHeapify(queue,min,queue_count);
  }
}

void swap(pair *queue,int i,int j){
  int tmp_vertics,tmp_cost;
  
  tmp_vertics=queue[i].vertics;
  tmp_cost=queue[i].cost;
	  
  queue[i].vertics=queue[j].vertics;
  queue[i].cost=queue[j].cost;
	  
  queue[j].vertics=tmp_vertics;
  queue[j].cost=tmp_cost;
}
  
    
			



Measured memory_bytes: 16012
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

#define REP(i,n) for(int i = 0; i < int(n); i++)

using namespace std;
using ll = long long;

int main() {
	
	
	ll a,b,c;
	int N;
	cin >> N;
	vector<ll> A, B, C;

	REP(i, N) {
		cin >> a;
		A.push_back(-a);
	}
	REP(i, N) {
		cin >> b;
		B.push_back(b);
	}
	REP(i, N) {
		cin >> c;
		C.push_back(c);
	}
	sort(A.begin(), A.end());
	sort(C.begin(), C.end());

	ll count = 0;
	REP(i, N) {
		auto itrA = upper_bound(A.begin(), A.end(),-B[i]);
		auto itrC = upper_bound(C.begin(), C.end(), B[i]);
		count += distance(itrA, A.end()) * distance(itrC, C.end());
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3316
def main():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=[0]*n
    for i in range(n):
        cnt[a[i]-1]+=1
    res=0
    for i in range(n):
        if cnt[i]>1:
            res+=cnt[i]*(cnt[i]-1)//2
    ans=[0]*n
    for i in range(n):
        if cnt[i]>=1:
            ans[i]=res-(cnt[i]-1)
    for i in range(n):
        print(ans[a[i]-1])
        
if __name__=="__main__":
    main()

Measured memory_bytes: 26140
import sys
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            k = a[i][j]
            if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
                break
            if x[j] == y[k]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(sys.stdin.readline())
x = [sys.stdin.readline().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

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

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

	vector<int> vec(N, 0);
	int A;

	for (int i = 0; i < N - 1; i++) {
		cin >> A;
		vec.at(A-1)++;
	}

	for (int i = 0; i < N; i++) {
		cout << vec.at(i) << endl;
	}

	return 0;
}


Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

ll p[200009];
ll dp[200009]; // dp[i]:p(i)からp(i+K-1)までのk個の和


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

	ll N, K; cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> p[i];
	for (int i = 0; i <= K - 1; i++) dp[0] += p[i];
	for (int i = 1; i + K - 1 < N; i++) {
		dp[i] = dp[i - 1] - p[i - 1] + p[i + K - 1];
	}
	ll ans = 0;
	for (int i = 0; i + K - 1 < N; i++) ans = max(ans, dp[i]);
	ans += K;
	cout << setprecision(15) << double(ans) / 2 << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
long long x[100005];
int main() {
  int n;
  long long a, b;
  cin >> n >> a >> b >> x[1];
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    cin >> x[i];
    ans += min(b, a * (x[i] - x[i - 1]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int a, b, c, x, y;

int main(void)
{
    cin >> a >> b >> c >> x >> y;

    lin mx = max(x, y);
    lin mn = min(x, y);
    lin case1 = mx * 2 * c;
    lin case2c = mn * 2 * c;
    lin case2a = x > y ? ((x - mn) * a) : 0;
    lin case2b = x < y ? ((y - mn) * b) : 0;
    lin case2 = case2a + case2b + case2c;
    lin case3 = x * a + y * b;

    if(case1 < case2 && case1 < case3)
        cout << case1 << endl;
    else if(case2 < case3)
        cout << case2 << endl;
    else
        cout << case3 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[120000];
int b[100000];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    memset(b,0,sizeof(b));
    int s=0,j=0;
    for(int i=0; i<n; i++)
    {
        b[j]++;
        while(a[i]==a[i+1])
        {
            b[j]++;
            i++;
        }
        if(b[j]&1)
            s++;
        j++;
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 896
n = int(input())

order = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
add = list(map(int, input().split()))


ans = 0
before = order[0]

for i in range(n):
    if order[i] == before+1:
        ans += manzoku[order[i]-1] + add[before-1]
    else:
        ans += manzoku[order[i]-1]

    before = order[i]

print(ans)


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

int main(){
  int n, k, s;
  cin >> n >> k >> s;
  if(s != 1000000000){
    for(int i=0; i<k; i++){
      cout << s << " ";
    }
    for(int i=k; i<n; i++){
      cout << 1000000000 << " ";
    }
  }else{
    for(int i=0; i<k; i++){
      cout << s << " ";
    }
    for(int i=k; i<n; i++){
      cout << 2 << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 1280
<?php
fscanf(STDIN, "%d", $N);
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s %d", $s[$i], $t[$i]);
}
fscanf(STDIN, "%s", $X);
$bool = false;
for ($i = 0; $i < $N; $i++) {
    if ($bool) {
        $ans += $t[$i];
    }
    if ($s[$i] === $X) {
        $bool = true;
    }        
}
echo $ans;


Measured memory_bytes: 4856
<?php
$p='';
while(1){
  list($h,$w)=explode(' ',trim(fgets(STDIN)));
  if($h||$w){

    $l='#';for($i=2;$i<$w;$i++){$l.='#';}$l.='#'.PHP_EOL;

    $m='#';for($i=2;$i<$w;$i++){$m.='.';}$m.='#'.PHP_EOL;

    $p.=$l;for($i=2;$i<$h;$i++){$p.=$m;}$p.=$l.PHP_EOL;
  }
  else break;
}
print $p;

Measured memory_bytes: 15448
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const int limit = 16;
const int inf = 1e9;
//16通りを一度に計算
const int v0 = 0b0000000000000000;
const int v1 = 0b1111111111111111;
const int va = 0b0000000011111111;
const int vb = 0b0000111100001111;
const int vc = 0b0011001100110011;
const int vd = 0b0101010101010101;
int conv(char c){
	switch(c){
	case '0': return v0;
	case '1': return v1;
	case 'a': return va;
	case 'b': return vb;
	case 'c': return vc;
	case 'd': return vd;
	}
	return -1;
}

//構文解析
int parse(int &p, string &s){
	if(s[p] == '-'){
		p++;
		return parse(p, s) ^ v1;
	}
	if(s[p] != '('){
		return conv(s[p++]);
	}
	p++;
	int x = parse(p, s);
	char op = s[p++];
	int y = parse(p, s);
	p++;
	if(op == '*'){
		return x & y;
	}else{
		return x ^ y;
	}
}

int main(){
	vector<map<string, int> > formula(limit+1);
	formula[1]["0"] = v0;
	formula[1]["1"] = v1;
	formula[1]["a"] = va;
	formula[1]["b"] = vb;
	formula[1]["c"] = vc;
	formula[1]["d"] = vd;
	vector<int> minlen(65536, inf);
	//小さいものから値が新しいものを順次生成していく
	for(auto &psi : formula[1]){
		minlen[psi.second] = psi.first.length();
	}
	for(int i=2; i<=limit; i++){
		//単項マイナス
		for(auto &psi : formula[i-1]){
			string ns = "-" + psi.first;
			int nv = psi.second ^ v1;
			if(minlen[nv] == inf){
				minlen[nv] = ns.length();
				formula[i][ns] = nv;
			}
		}
		//二項演算
		for(int x=1; x<i-3; x++){
			int y = i-3-x;
			for(auto &psi1 : formula[x]){
				for(auto &psi2: formula[y]){
					string ns;
					int nv;
					ns = "(" + psi1.first + "*" + psi2.first + ")";
					nv = psi1.second & psi2.second;
					if(minlen[nv] == inf){
						minlen[nv] = ns.length();
						formula[i][ns] = nv;
					}
					ns = "(" + psi1.first + "^" + psi2.first + ")";
					nv = psi1.second ^ psi2.second;
					if(minlen[nv] == inf){
						minlen[nv] = ns.length();
						formula[i][ns] = nv;
					}
				}
			}
		}
	}

	while(1){
		string s;
		cin >> s;
		if(s == ".") break;
		int p = 0;
		cout << minlen[parse(p, s)] << endl;
	}
    return 0;
}


Measured memory_bytes: 3404
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define INF 0x7fffffff
#define PI acos(-1.0)
#define MOD 2520
#define E 1e-12
#define ll long long   
using namespace std;
#define N 1500
int a[N];
int main()
{
    ll n;
    scanf("%lld",&n);
    if(n<=6)
	{
		cout<<1<<endl;
	}
	else
	{
		ll ans=0;
		ll x=n/11;
		ll y=n%11;
		ans+=2*x;
		if(y<=6&&y>=1)
		{
			ans++;
		}
		else if(y>6)
		{
			ans+=2;
		}
		cout<<ans<<endl;
		
	}
    
    return 0;
}



Measured memory_bytes: 256
package main
import(
  "fmt"
)
func main(){
  var(
    a [5]int
    time,module int
  )
  module=10
  for i:=0;i<=4;i++{
    fmt.Scan(&a[i])
    if a[i]%10==0{
      time+=a[i]
    }else{
      time+=a[i]+10-a[i]%10
      if module>a[i]%10{
        module=a[i]%10
      }
    }
  }
  fmt.Println(time-10+module)
}

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

int digit(int n) {
	int ret = 0;
	for (; n; n /= 10)
		++ret;
	return ret;
}
int main()

{
	
	int n, ret  = 0; cin >> n;
	for (int i = 1; i <= n; ++i) {
		if (digit(i) % 2)
			++ret;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 100005
typedef struct pp{
  char name[100];
  int t;
} P;
P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
P dequeue(){
  P tmp = Q[head];
  head = (head + 1) % LEN;
  return tmp;
}
int min(int a, int b){
  return a < b ? a : b;
}
int main(){
  char line[100];
  fgets(line, sizeof(line), stdin);
  int q;
  sscanf(line, "%d %d", &n, &q);
  
  for(int i = 1; i <= n; ++i){
    fgets(line, sizeof(line), stdin);
    sscanf(line, "%s %d", Q[i].name, &Q[i].t);
  }
  head = 1;
  tail = n+1;
  P u;
  int elaps = 0, c;
  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0)
      enqueue(u);
    else{
      printf("%s %d\n", u.name, elaps);
    }
 }
 return 0;
}


Measured memory_bytes: 11932
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long int> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
const int N = 3e5;
VI g[N+1];
ll vis[N+1];
ll dp[N+1];
ll ans=0;
void graph(ll n,ll m)
{
    ll u, v;
    while(m--){
        cin>>u>>v;
        g[u].push_back(v);
      
    }
}
void dfs(ll node) {
    vis[node]=1;
    for(auto i: g[node]) {
        if(!vis[i]) dfs(i);
        dp[node] = max(dp[i] + 1, dp[node]);
        ans = max(ans, dp[node]);
    }
}
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int diff(string a,string b){
    int dc=0;
    fore(i,a.length()){
        if(a[i]!=b[i])dc++;
    }
    return dc;
}
int main()
 {  fast();
     ll t,n,m;
    t=1;
    while(t--){
        cin>>n>>m;
        graph(n,m);
        fore1(i,1,n+1){
            if(!vis[i])dfs(i);
        }
       cout<<ans<<endl; 
    }
    
	}
	/*5
2 4
abac
zbab
2 4
aaaa
bbbb
3 3
baa
aaa
aab
2 2
ab
bb
3 1
a
b
c*/

Measured memory_bytes: 15872
#include <stdio.h>
 
int main(){
    long long int i, j, prm[1000000];
     
    for(i = 0; i < 1000000; i++) prm[i] = 1;
     
    for(i = 4; i < 1000000; i += 2) prm[i] = 0;
     
    prm[0] = prm[1] = 0;
     
    for(i = 3; i * i < 1000000; i += 2)
        if(prm[i])
            for(j = i + i; j < 1000000; j += i) prm[j] = 0;
                 
    for(i = j = 0; i < 1000000; i++){
        if(prm[i]) j++;
         
        prm[i] = j;
    }
     
    while(scanf("%d", &i) != EOF) printf("%d\n", prm[i]);
     
    return 0;
}

Measured memory_bytes: 9520
using System;

namespace AtCoder132C
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;
            int N = int.Parse(Console.ReadLine());

            string[] s = Console.ReadLine().Split(' ');

            int[] X = new int[N];

            for (int i = 0; i < N; i++)
            {
                X[i] = int.Parse(s[i]);
            }

            Array.Sort(X);

            ans = X[N / 2] - X[N / 2 - 1];

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 18784
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner stdIn = new Scanner(System.in);

        while(true){
            int m = stdIn.nextInt();
            int n = stdIn.nextInt();
            if(m==0&&n==0) return;
            int p = m;
            int s = 0;
            int t = 0;
            int tmpP = m;
            int cnt = 0;

            while(true){
            	cnt++;
                m = m*10%n;
                p = (p*10%n)*10%n;
                if(m==p){
                    break;
                }
            }
            if(p!=0){
            	p = tmpP%n;
                s = 1;
                while(m!=p){
                    s++;
                    m = m*10%n;
                    p = p*10%n;
                }
                p = p*10%n;
                t = s;
                while(m!=p){
                    t++;
                    p = p*10%n;
                }
            }

            if(s==0&&t==0){
            	System.out.println(cnt+" "+t);
            }
            else System.out.println((s-1)+" "+(t-s+1));
        }
    }
}

Measured memory_bytes: 21468
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  ll n;
  cin >> n;
  string s;
  map<string,ll> mp;
  rep(i,n){
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }

  ll ans = 0;

  for(auto x: mp){
    ll pr = x.second;
    ans +=  pr*(pr-1)/2;
  }

  printf("%lld\n", ans);



  return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

int main()
{

	string s;
	cin >> s;

	int ans = 0;
	for (int i = 1; i < sz(s); ++i) {
		if (s[i] != s[i - 1]) {
			++ans;
		}
	}

	cout << ans << "\n";

}


Measured memory_bytes: 512
#include <stdio.h>
 int main(void)
 {
 int a,b;
 scanf("%d",&a);
 scanf("%d",&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: 2040
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int cur = 1;
        int res = 0;
        foreach (var item in a)
        {
            if (item == cur)
            {
                cur++;
            }
            else res++;
        }
        if (res == n) res = -1;
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 43600
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 100000;

using ll = long long;
using P = std::pair<ll, int>;

struct edge
{
	ll from, to, cost;

	edge( ll from, ll to, ll cost )
	:	from(from), to(to), cost(cost)
	{}
};

struct UnionFind
{
	std::vector<int> data;

	UnionFind( int size )
	:	data(size, -1)
	{}

	bool unite(int x, int y)
	{
		x = root(x); y = root(y);

		if (x != y)
		{
			if (data[y] < data[x])
				std::swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}

		return x != y;
	}
	
	bool same( int x, int y )
	{
		return root(x) == root(y);
	}

	int root(int x)
	{
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
};

int N;
ll x[MAX_N], y[MAX_N];
std::vector<P> xs, ys;
std::vector<edge> es;

int main()
{
	scanf("%d", &N);
	rep(i, N)
	{
		scanf("%lld%lld", x + i, y + i);
		xs.push_back(P(x[i], i));
		ys.push_back(P(y[i], i));
	}

	std::sort(xs.begin(), xs.end());
	std::sort(ys.begin(), ys.end());

	rep(i, N - 1)
	{
		es.push_back(edge(xs[i].second, xs[i+1].second, xs[i+1].first-xs[i].first));
		es.push_back(edge(ys[i].second, ys[i + 1].second, ys[i + 1].first - ys[i].first));
	}

	std::sort(es.begin(), es.end(), [](const edge &e1, const edge &e2) { return e1.cost < e2.cost; });

	UnionFind uf(N);

	ll ans = 0;
	for (auto &e : es)
	{
		if (uf.same(e.from, e.to))
			continue;

		uf.unite(e.from, e.to);
		ans += e.cost;
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 14560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F,  H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

vvi G(100100);
vi dp(100100,-1);

int rec(int v)
{
    if(dp[v] != -1) return dp[v];

        int vvv = 0;
    for(auto aa : G[v])
    {
        vvv = max(vvv,rec(aa)+1);
    }

    return dp[v] = vvv;
}

int main()
{
    cin >> N >> M;
    G.assign(N,vi());
    for (int i = 0; i < M; i++) 
    {
        int x,y;
        cin >> x >> y;
        --x;--y;
        G[x].push_back(y);
    }

    int res = 0;
    for (int i = 0; i < N; i++)
    {
        res = max(res,rec(i));
    }
    
    cout << res;
    
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

void crpt(double a1, double b1, double c1, double a2, double b2, 
	double c2, double *x, double *y) {

	*x = (b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1);
	*y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
}

int main()
{
	int n;
	double x1, y1, x2, y2, x3, y3;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		double px, py, r;

		crpt(x2 - x1, y2 - y1, (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) / 2, 
			x3 - x1, y3 - y1, (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) / 2, &px, &py);

		r = sqrt((px - x1) * (px - x1) + (py - y1) * (py - y1));

		cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(3)
			<< px << " " << py << " " << r << endl;
	}

	return 0;
}


Measured memory_bytes: 3176
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int n, T;
  cin >> n >> T;
  vector<int> t(n);
  cin >> t;
  int s = T;
  for (int i = 1; i < n; ++i) s += min(T, t[i] - t[i - 1]);
  cout << s << endl;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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


int main(){
	int x, temp, temp1;
	int total = 0;

	cin >> x;

	for (int i = 1; i <=x; i++){
		for(int j = 1; j <= x; j++){
			temp1 = gcd(i,j);
			for(int k = 1; k <= x; k++){
				temp = gcd(temp1, k);
				total = total + temp;
			}
		}
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 3636
/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/6/20 20:20
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 3005;
const int mod = 998244353;
ll qp(ll a, ll n, ll mod = ::mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int dp[maxn][maxn];

int main(int argc, char* argv[]) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    dp[a][b] = 1;
    for (int i = a; i <= c; ++i) {
        for (int j = b; j <= d; ++j) {
            if (i == a && j == b) continue;
            dp[i][j] = (1ll * j * dp[i - 1][j] % mod + 1ll * i * dp[i][j - 1] % mod - 1ll * (i - 1) * (j - 1) * dp[i - 1][j - 1]) % mod;
        }
    }
    printf("%d\n", (dp[c][d] + mod) % mod);
    return 0;
}

Measured memory_bytes: 38896
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
nx = str(n)[0]
ny = str(n)[-1]
digit = len(str(n))
is_full = [1, 11, 111, 1111, 11111]

for i in range(1, n + 1):
    x = str(i)[0]
    y = str(i)[-1]
    if y == "0":  # 0が先頭になるときを考えない
        continue

    if x == y:  # xとyが同じとき3などの一桁の値をとりうるので+1する
        ans += 1

    if y < nx:  # 注目している数字の末尾，つまり考えている数字y??xの先頭の文字yがnxより小さいとき
        if digit - 2 < 0:  # 無条件で取れる，ものが無ければcontinue
            continue
        ans += is_full[digit - 2]
    elif y == nx:
        if digit - 3 >= 0:
            ans += is_full[digit - 3]
        for num, k in enumerate(list(str(n))[1: -1], 1):  # y???xとnx???nyを比較していく
            ans += int(k) * 10 ** (digit - 2 - num)

        if digit >= 2 and x <= ny:  # 10の位をもうひとつ上げられるとき
            ans += 1
    else:  # 注目している数字の末尾，つまり考えている数字y??xの先頭の文字yがnxより大きいとき
        if digit - 3 < 0:  # このときは無条件に取れるis_fullの位が一段階下がる
            continue
        ans += is_full[digit - 3]

print(ans)

Measured memory_bytes: 68968
// ALDS1_3_B Queue

#include <iostream>
#include <queue>
#include <string>

struct process{
	std::string name;
	int time;
};

int main(int argc, char *argv[]){
	int n, q;
	int total_time = 0;
	std::queue<process> p_queue;
	process p;

	std::cin >> n >> q;
	for(int i=0 ; i<n ; i++){
		std::cin >> p.name >> p.time;
		p_queue.push(p);
	}

	while(!p_queue.empty()){
		p = p_queue.front();
		if(p.time > q){
			total_time += q;
			p.time -= q;
			p_queue.push(p);
		}
		else{
			total_time += p.time;
			std::cout << p.name << " " << total_time << std::endl;
		}
		p_queue.pop();
	}

	return 0;
}



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

using namespace std;

long long n,m,d;

int main(){
    cin >> n >> m >> d;
    if(d==0){
        double a = (double)(m-1) / n;
        printf("%.10f\n",a);
    }else{
        double a = 2.0*(n-d)*(m-1);
        double b = a / (n*n);
        printf("%.10f\n",b);
    }
}

Measured memory_bytes: 256
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    string s;
    cin >> k;
    cin >> s;
    if(s.size() <= k) cout << s << endl;
    else cout << s.substr(0,k) << "..." << endl;
    return 0;
}


Measured memory_bytes: 3656