akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
# B - Checkpoints
# 標準入力の取得
N,M = list(map(int, input().split()))
a,b = [],[]
for n in range(N):
    a_n,b_n = [int(i) for i in input().split()]
    a.append(a_n)
    b.append(b_n)
c,d = [],[]
for m in range(M):
    c_m,d_m = [int(i) for i in input().split()]
    c.append(c_m)
    d.append(d_m)

# 全探索により、最も近いチェックポイントを算出
nearest_checkpoint_list = []
for n in range(N):
    a_n = a[n]
    b_n = b[n]

    nearest_checkpoint = 0
    min_manhattan_distance = abs(a_n - c[0]) + abs(b_n - d[0])

    for m in range(1, M):
        manhattan_distance = abs(a_n - c[m]) + abs(b_n - d[m])
        if min_manhattan_distance > manhattan_distance:
            min_manhattan_distance = manhattan_distance
            nearest_checkpoint = m

    nearest_checkpoint_list.append(nearest_checkpoint + 1)

# 結果出力
for n in range(N):
    print(nearest_checkpoint_list[n])

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



int main(){
  int n;
  cin>>n;
  if(n==1){
    cout << 1;
    return 0;
  }
  vector<int>l(1010);
  
  for(int i=2;i<=n;i++){
    int a=i;
    for(int j=2;j*j<=i;j++){
      while(a%j==0){
        l.at(j)++;
        a/=j;
      }
    }
    if(a!=1){
      l.at(a)++;
    }
  }
  long ans=1;
  for(i:l){
    if(i!=0){
      ans*=(i+1);
      ans%=1000000000+7;
    }
  }
  cout <<ans;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	int ret=0;
	int sum=0;
	FOR(i,N) {
		cin>>A[i];
		A[i]*=4*M;
		sum+=A[i];
	}
	sum/=4*M;
	FOR(i,N) if(A[i]>=sum) ret++;
	if(ret>=M) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    int n, d ,x;
    cin >> n >> d >> x;

    vector<int> v(n);

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

    int counter = 0;
    int k = 0;
    for (int j = 0; j <n; ++j) {
        while(v[j]*k+1 <= d){
            counter++;
            k++;
        }
        k = 0;
    }
    cout << counter+x << endl;


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,k,r,s,p,i,j,ans[100010],a[100010],ans1;
  char b;
  scanf("%d %d\n%d %d %d\n",&n,&k,&r,&s,&p);
  for(i=0;i<n;i++){
    scanf("%c",&b);
    if(b=='r'){
      a[i]=0;
      ans[i]=p;
    }
    else if(b=='s'){
      a[i]=1;
      ans[i]=r;
    }
    else{
      a[i]=2;
      ans[i]=s;
    }
  }
  for(i=0;i<n;i++){
    if(i-k>=0 && a[i-k]!=-1 && a[i-k]==a[i]){
      ans[i]=0;
      a[i]=-1;
    }
  }
  for(i=0;i<n;i++){
    ans1=ans1+ans[i];
  }
  printf("%d\n",ans1);
  return 0;
}
        

Measured memory_bytes: 896
main = do
    n <- read<$>getLine
    as <- g n
    putStrLn$solve as

g 0 = pure []
g n = do
    x <- read<$>getLine
    r <- g$n-1
    pure$x:r

solve as = if foldl1 (&&) (map even as)
    then "second"
    else "first"

Measured memory_bytes: 62716
N, K, Q= map(int, input().split())
A = []
for i in range(Q):
    array = list(map(int, input().strip().split()))
    A.append(array)
Point = [K-Q]*N
for i in range(Q):  
  a = A[i][0]
  Point[a-1] = Point[a-1] + 1
for j in range(N):
  if Point[j] > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 27512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
 
  int N  ;
  cin >> N ;
  int M = N / 100 ;
  int P = N % 100 ;
  if( M * 100 <= N && N <= M*100 + 5*M ) cout << 1 << endl ;
  else cout << 0 << endl ;
}

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

int main() {
  int N;
  cin >> N;
  int s = 0;
  int M = N;
    while(M != 0){
      s += M % 10;
      M = M / 10;
    }
	if ( N % s == 0)
      cout << "Yes" << endl;
  	if ( N % s != 0)
      cout << "No" <<endl;
}



Measured memory_bytes: 3648
N = int(input())
A = list(map(int, input().split()))

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2

for i in range(N):
    print(s - d[A[i]] + 1)


Measured memory_bytes: 26140
/*

                                  In the name of Allah, Most Gracious, Most Merciful


*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;

//*** constant value ***
const long double PI = 3.141592653589793238;
const double EPS = 1e-6 ;
//*** constant value ***

//****** define ********
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define dd double
#define vll vector<ll>
#define vs vector<string>
#define fn(i,n) for(ll i = 0; i<n; i++)
#define f(i,a,b) for(i=a;i<b;i++)
#define f1(i,a,b) for(i=b-1;i>=a;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define vpl vector<pll>
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define tt cout<<"Came here"<<endl;
//****** define ********
void solve()
{

   ll n;
   cin>>n;
   vll v;
   while(n != 0)
   {
       n--;
       v.pb(n%26);
       n /= 26;
   }

   reverse(v.begin(),v.end());

   string s;

   fn(i,v.size())
       s += (v[i] + 'a');

   cout<<s<<endl;

}

int main()
{
    IOS;
    ll tc = 1;
    while(tc--)
    {
        solve();
    }


return 0;
}



Measured memory_bytes: 3648
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>ca>>cb>>cc;
    map<char,ll> ma;
    ma[ca]++;
    ma[cb]++;
    ma[cc]++;
    if(ma['a']&&ma['b']&&ma['c']) Yes;
    else No;
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> x(n), y(n), h(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] > 0) {
        	swap(x[0], x[i]);
            swap(y[0], y[i]);
            swap(h[0], h[i]);
        }
    }
    
    int H, Cx, Cy;
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int nh = abs(x[0] - cx) + abs(y[0] - cy) + h[0];
            bool can = true;
            for (int i = 1; i < n; i++) {
                if (max(nh - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) {
                    can = false;
                }
            }
            if (can) {
                H = nh;
                Cx = cx;
                Cy = cy;
            }
        }
    }
    cout << Cx << " " << Cy << " " << H << endl;
}


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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n), b(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	b = a;
	sort(b.begin(), b.end());
	
	int max = b.back();
	for(int i = 0; i < n; ++i) {
		if( a[i] < max ) cout << max << endl;
		else cout << b[n - 2] << endl;
	}

	return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>
long cmp(const void *a,const void *b){
  return *(long*)a - *(long*)b;
}

int main(){
  int n = 0;
  long a[100000] = {};
  int i = 0;
  long long max = 0;
  long long sec = 0;
  long long result = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  qsort(a,n,sizeof(long),cmp);
  for(i=0;i<n;i++){
    if(a[i+1] == a[i]){
      if(a[i] >= max){
        sec = max;
        max = a[i];
        i++;
      }else if(a[i] > sec){
        sec = a[i];
        i++;
      }else{
        i++;
      }
    }
  }
  result = max * sec;
  printf("%lld",result);
  return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll sum = accumulate(A.begin(),A.end(),0ll);

    ll t = N * (N+1) / 2;
    if(sum % t > 0){
        cout << "NO" << endl;
        return 0;
    }

    ll k = sum / t;
    ll cnt = 0;
    vector<ll> d(N);
    rep(i,N){
        int j = (i+1) % N; 
        d[i] = A[j] - A[i];
        int tmp = (k-d[i]) / N;
        if(tmp < 0){
            cout << "NO" << endl;
            return 0;
        }
        cnt += tmp;

    }
    if(cnt == k){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<string> vs(n);
  rep(i, n) cin >> vs[i];

  int ans = 0;
  rep(k, n) {
    bool f = true;
    rep(i, n) REP(j, i, n) {
      int y = i;
      int x = (j + k) % n;
      int ny = j;
      int nx = (i + k) % n;
      if (vs[y][x] != vs[ny][nx]) f = false;
    }
    if (f) ans++;
  }

  cout << ans * n << endl;
}


Measured memory_bytes: 512
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let D: usize = sc.get();
    let c: Vec<i64> = sc.vec(26);
    let s: Vec<Vec<i64>> = sc.mat(D, 26);
    let mut ans = 0i64;
    let mut last = vec![0; 26];
    for d in 0..D {
        let t: usize = sc.get();
        ans += s[d][t-1];
        last[t-1] = d as i64 + 1;
        for i in 0..26 {
            ans -= c[i] * (d as i64 + 1 - last[i]);
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 2236
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
  printf("\n");
  char str[1000];
  
  int N,T;
  fgets(str,1000,stdin);
  sscanf(str,"%d %d",&N,&T);

  int c, t;
  int mincost = 1001;
  for(int n=0;n<N;n++) {
    fgets(str,1000,stdin);
    sscanf(str,"%d %d",&c,&t);

    if( t<=T && c<mincost ) {
      mincost = c;
    }
  }
  if( mincost==1001 ) printf("TLE");
  else printf("%d",mincost);

  printf("\n");
}


Measured memory_bytes: 256
#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;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	T init;
	F f;
	int sz;
	vector<T> seg;
	SegmentTree(){}
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void ini(int n, const T _init, const F _f) {
		init = _init;
		f = _f;
		sz = 1;
		while(sz < n) sz <<= 1;
		seg.resize(sz << 1, init);
	}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

SegmentTree<int> seg[26];
int main() {
	int n; cin >> n;
	for(int i = 0; i < 26; ++i) {
		seg[i].ini(n, 0, [](int a, int b){return a + b;});
	}
	string s; cin >> s;
	for(int i = 0; i < n; ++i) {
		seg[s[i] - 'a'].replace(i, 1);
	}
	int q; cin >> q;
	while(q--) {
		int op;
		cin >> op;
		if(op == 1) {
			int i; cin >> i;
			char c; cin >> c;
			--i;
			seg[s[i] - 'a'].replace(i, 0);
			seg[c - 'a'].replace(i, 1);
			s[i] = c;
		}
		if(op == 2) {
			int l, r; cin >> l >> r;
			--l;
			int ans = 0;
			for(int i = 0; i < 26; ++i) {
				ans += min(1, seg[i].get(l, r));
			}
			cout << ans << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 109444
#include <bits/stdc++.h>
#include <algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD (ll)(1e9+7)
#define MAX (ll)(1e5*2+200)
#define print(x) cout << x << endl;
#define length(arr) sizeof arr / sizeof arr[0];
#define printArr(arr) REP(i, (sizeof arr / sizeof arr[0])){print(arr[i])}
#define printVec(vec) REP(i, vec.size()){print(vec[i])}

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    
    int t = s.size();
    char first, last;
    first = s[0];
    last = s[t-1]; 
    
    if(first == last){
        if(t%2 == 0){
            print("First");    
        }else{
            print("Second");
        }
    }else{
        if(t%2 == 0){
            print("Second");
        }else{
            print("First"); 
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	bool flag = false;
	int sum;
	for(int i = 0;i <= 25;i ++)
	{
        if(4*i>n)
			break;
		sum = 4*i;
		for(int j = 0;j <= 15;j ++)
		{
			sum += j*7;
			if(sum == n)
			{
				flag = true;
				break;
			}
			if(sum > n)
				break;
		}
		if(flag)
			break;
	}
	if(flag)
		printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) {
		cout << c << endl;
	}
	if (b == c) {
		cout << a << endl;
	}
	if (a == c) {
		cout << b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
int total,a[N],b[N],c[N];
int hukasa(int);
int height(int);
int main(int jeep,char *com[]){
  int i,j;
  scanf("%d",&total);
  for(i=0;i<total;i++){
    a[i]=-1;
    b[i]=-1;
    c[i]=0;
  }
  for(i=0;i<total;i++){
    int k,left,right;
    scanf("%d %d %d",&k,&left,&right);
    if(left!=-1){
      a[left]=k;
      b[left]=right;
      c[k]++;
    }
    if(right!=-1){
      a[right]=k;
      b[right]=left;
      c[k]++;
    }
  }
  for(i=0;i<total;i++){
    int d;
    d=hukasa(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,\
a[i],b[i],c[i],d,height(i));
    if(d==0){
      printf("root\n");}
    else if(c[i]==0){
      printf("leaf\n");}
    else{
      printf("internal node\n");
    }
  }
return 0;
}
int hukasa(int jeep){
  if(a[jeep]==-1)return 0;
  return hukasa(a[jeep])+1;
}
int height(int jeep){
  int j,divala=0,ryohu;
  for(j=0;j<total;j++){
    if(a[j]==jeep){
      ryohu=height(j)+1;
      if(ryohu>divala)
        divala=ryohu;
    }
  }
  return divala;
}


Measured memory_bytes: 2112
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
using namespace std;
int main(){
    ll n,m;
    cin >> n >> m;

    ll Lmax = 0,Rmin = n;

    REP(i,m){
        ll a,b;
        cin >> a >> b;

        Lmax = max(Lmax,a);

        Rmin = min(Rmin,b);

    }
    if (Lmax <= Rmin)
    cout << Rmin - Lmax +1 <<endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var a, b, c int

  fmt.Scanf("%d %d %d", &a, &b, &c)
	
  if a == 7 {
		if b == 5 && c == 5 {
      fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	} else if a == 5 {
		if b == 7 && c == 5 {
			fmt.Println("YES")
		} else if b == 5 && c == 7 {
			fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  } else {
    fmt.Println("NO")
	}
}

Measured memory_bytes: 512
import copy
N, M = [int(_) for _ in input().split()]
AB = [[int(_) - 1 for _ in input().split()] for _ in range(M)]

G = [[0] * N for _ in range(N)]
for ab in AB:
    G[ab[0]][ab[1]] = 1
    G[ab[1]][ab[0]] = 1


def dfs(Gn, a, x):
    a[x] = 1
    for i in range(N):
        if Gn[x][i] == 1 and a[i] == 0:
            a[i] = 1
            dfs(Gn, a, i)


count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if G[i][j] == 1:
            Gn = copy.deepcopy(G)
            Gn[i][j] = 0
            Gn[j][i] = 0
            flag = False
            for k in range(N):
                a = [0] * N
                dfs(Gn, a, k)
                if all(a):
                    flag = True
                    break
            if not flag:
                count += 1
print(count)


Measured memory_bytes: 3548
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

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

void Ok()
{
    long long int a,b,c,d[1013],e,f,g,h,t,i,j = 0,k,l1,l2,m,n,x,y,sum,ans_1,ans_2,ans_3,cnt,Max,Min,flag,div,rcv,temp;
    long double aa,bb,cc,dd,ee,ff,gg;
    char aaa[100013],bbb[1013],ccc[1013],alpbt;

    cin>>a>>b>>c;
    for(i=1;i<=100;i++)
    {
        if(a%i==0 && b%i==0)
        {
            d[++j] = i;
        }
    }
    sort(d+1,d+j+1,greater<int>());
    ans_1 = d[c];
    cout<<ans_1<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


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

int main() {
    long long n,x,m,newone;
    cin>>n>>x>>m;
    vector<long long>a;
    a.push_back(x);
    set<long long>st;
    st.insert(x);
    for(int i=1;i<=n;i++) {
        newone = (a[i-1]*a[i-1])%m;
        if(st.find(newone)!=st.end()) break;
        st.insert(newone);
        a.push_back(newone);
    }
    long long ans=0;
    long long sum=0;
    int ind=0;
    int sz=a.size();
    // for(int i=0;i<sz;i++) cout<<a[i]<<" ";
    // cout<<endl;
    // cout<<sz<<endl;
    if(n<=sz) {
        for(int i=0;i<n;i++) ans+=a[i];
    }
    else {
        for(int i=0;i<sz;i++) {
            if(a[i]==newone) {
                ind=i;
                break;
            }
            ans+=a[i];
        }
        for(int i=ind;i<sz;i++) sum+=a[i];
        ans+= (sum*((n-ind)/(sz-ind)));
        for(int i=ind;i<ind+(n-ind)%(sz-ind);i++) ans+=a[i];
    }
   
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5988
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int v;
  ll cost;

  Node(int v = -1, ll cost = -1) {
    this->v = v;
    this->cost = cost;
  }

  bool operator>(const Node &n) const {
    return cost > n.cost;
  }
};

map<int, map<int, int> > en_cost;
map<int, map<int, int> > snuku_cost;
vector<int> edges[100010];

int main() {
  int N, M, S, T;
  cin >> N >> M >> S >> T;

  int u, v, a, b;

  for (int i = 0; i < M; ++i) {
    cin >> u >> v >> a >> b;

    edges[u].push_back(v);
    edges[v].push_back(u);

    en_cost[u][v] = a;
    en_cost[v][u] = a;

    snuku_cost[u][v] = b;
    snuku_cost[v][u] = b;
  }

  priority_queue <Node, vector<Node>, greater<Node> > pque;
  pque.push(Node(S, 0));
  ll before_cost[N + 1];
  memset(before_cost, -1, sizeof(before_cost));

  while (!pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (before_cost[node.v] != -1) continue;
    before_cost[node.v] = node.cost;

    for (int i = 0; i < edges[node.v].size(); ++i) {
      int u = edges[node.v][i];
      pque.push(Node(u, node.cost + en_cost[node.v][u]));
    }
  }

  ll after_cost[N + 1];
  pque.push(Node(T, 0));
  memset(after_cost, -1, sizeof(after_cost));

  while (!pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (after_cost[node.v] != -1) continue;
    after_cost[node.v] = node.cost;

    for (int i = 0; i < edges[node.v].size(); ++i) {
      int u = edges[node.v][i];
      pque.push(Node(u, node.cost + snuku_cost[node.v][u]));
    }
  }

  for (int i = 1; i <= N; ++i) {
    ll cost = before_cost[i] + after_cost[i];

    pque.push(Node(i, cost));
  }

  ll money = 1000000000000000;

  for (int i = 0; i < N; ++i) {
    while (!pque.empty() && pque.top().v <= i) {
      pque.pop();
    }

    cout << money - pque.top().cost << endl;
  }

  return 0;
}


Measured memory_bytes: 47984
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int n=0;n<N;n++) a[n]=sc.nextInt();
        
        int[] divBy2 = new int[3];
        for(int n=0;n<N;n++){
        	if(a[n]%4==0) divBy2[2]++;
        	else if(a[n]%2==0) divBy2[1]++;
        	else divBy2[0]++;
        }
        boolean ans = true;
        if(divBy2[0]>divBy2[2]+1) ans=false;
        if(divBy2[0]==divBy2[2]+1 && divBy2[1]>0) ans=false;
        System.out.println(ans ? "Yes" : "No");
    }
}


Measured memory_bytes: 50828
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

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

    int n = s.length();
    int res = n;

    int s_cnt = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S')     s_cnt++;
        else{       // s[i] == 'T'
            if(s_cnt > 0){
                res -= 2;
                s_cnt--;
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

ll f(ll n){
  if(n<=0)return 0;
  ll num1=n/2;
  ll num2=n%2;
  if(num2==0){
    return (num1%2)^n;
  } else {
    return (num1+1)%2;
  }
}

int main(){
  ll a, b;
  cin >> a >> b;
  ll ans=f(a-1)^f(b);
  cout << ans << endl;
  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int k,ans,hoge=1;
string s;
vector<pair<int,int>> v;

signed main() {
    cin >> s >> k;
    rep11(i,s.size()) {
        if (s[i-1] == s[i]) hoge++;
        else v.pb(mp(hoge,s[i-1])), hoge=1;
    }
    v.pb(mp(hoge,s[s.size()-1]));
    if (v.size() == 1) {
        ans = (v[0].fi*k)/2;
    } else if (v[0].se == v[v.size()-1].se) {
        rep11(i,v.size()-1) ans += v[i].fi/2*k;
        ans += v[0].fi/2;
        ans += v[v.size()-1].fi/2;
        ans += (v[0].fi+v[v.size()-1].fi)/2*(k-1);
    } else {
        rep(i,v.size()) ans += v[i].fi/2*k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int n;
        int t=0;
        int h=0;
        cin>>n;
        for(int i=0;i<n;i++){
                char x[100],y[100];
                scanf("%s %s",x,y);
                if (strcmp(x,y)==0) {
                        t+=1;
                        h+=1;
                } else if (strcmp(x,y)<0) {
                        h+=3;
                } else {
                        t+=3;
                }
        }
        printf("%d %d\n",t,h);
        return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int a,b;
    while(cin>>a>>b)

    {
      int c,d,e,f,g;

      c=a-1;
      d=(c*(c+1))/2.;
      e=b-1;
      f=(e*(e+1))/2.;
      cout<<d+f<<endl;

    }











    return 0;
}


Measured memory_bytes: 3592
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
String ans="Bob";
if(a==1)a=14;
if(b==1)b=14;
if(a>b)ans="Alice";
else if(a==b)ans="Draw";
System.out.println(ans);
}
}

Measured memory_bytes: 23892
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);


    int k, cou = 0;
    bool ok = false;
    string s;
    cin >> k >> s;
    if(k >= s.size())
        cout << s << endl;
    else {
        for(int i = 0; i < k; ++i) {
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;
typedef long long ll;
#define REP(i,b,n) for(int i=~b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int idx;
string s;

bool solve(){
  if(s[idx] == '-'){
    idx++;
    bool tmp = solve();
    return !tmp;
  }
  else if(s[idx] == 'T'){
    idx++;
    return true;
  }
  else if(s[idx] == 'F'){
    idx++;
    return false;
  }
  else{
    idx++; // '('のぶん

    bool res;
    bool flgL = solve();

    if(s[idx] == '*'){
      idx++;
      bool flgR = solve();
      res = flgL && flgR;
    }
    else if(s[idx] == '+'){
      idx++;
      bool flgR = solve();
      res = flgL || flgR;
    }
    else{
      idx += 2;
      bool flgR = solve();
      if(flgL && !flgR){
        res = false;
      }
      else{
        res = true;
      }
    }

    idx++; // ')'のぶん

    return res;
  }
}

string trans(string ts, int bit){
  string res = "";

  for(int i = 0; i < ts.size(); i++){
    if(ts[i] == 'a') res += ((bit & (1 << 0)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'b') res += ((bit & (1 << 1)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'c') res += ((bit & (1 << 2)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'd') res += ((bit & (1 << 3)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'e') res += ((bit & (1 << 4)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'f') res += ((bit & (1 << 5)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'g') res += ((bit & (1 << 6)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'h') res += ((bit & (1 << 7)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'i') res += ((bit & (1 << 8)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'j') res += ((bit & (1 << 9)) != 0 ? 'T' : 'F');
    else if(ts[i] == 'k') res += ((bit & (1 << 10)) != 0 ? 'T' : 'F');
    else{
      res += ts[i];
    }
  }

  return res;
}

int main(){
  while(cin >> s, s != "#"){
    int len = s.length();
    string l, r;

    for(int i = 0; i < len; i++){
      if(s[i] == '='){
        l = s.substr(0, i);
        r = s.substr(i + 1, len - (i + 1));
        break;
      }
    }

    bool ans = true;

    for(int bit = 0; bit < (1 << 11); bit++){
      s = trans(l, bit);
      idx = 0;
      bool flgL = solve();

      s = trans(r, bit);
      idx = 0;
      bool flgR = solve();

      if(flgL != flgR){
        ans = false;
        break;
      }
    }

    if(ans){
      cout << "YES\n";
    }
    else{
      cout << "NO\n";
    }
  }
}

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

int n;
int a[3001];
long long sum = 0;

int main() {
  int i;
  cin >> n;
  for(i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  cout << sum - n << endl;
  return 0;
}

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

int gcd(int a,int b){
  if(a%b==0){
    return b;
  }
  else{
    return gcd(b,a%b);
  }
}
int main(){
  int n,x;
  cin>>n>>x;
  vector<int>d(n);
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  int ans=abs(d[0]-x);
  for(int i=1;i<n;i++){
    ans=gcd(ans,abs(d[i]-x));
  }
  cout<<ans<<endl;
}
  


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using ll = unsigned long long;
using namespace std;

// http://drken1215.hatenablog.com/entry/2019/05/19/224500_2

int main(void) {

    ll n, k;
    cin >> n >> k;

    double prob = 0.0;

    for (ll i = 1; i <= n; ++i) {
        /*
        double n = log2(k)-log2(i);
        prob1 += prob_i * powf(0.5, n < 1.0 ? 0 : ceil(n));
        */
       double prob_i = 1.0;
       ll nn = i;
       while(nn < k) {
           nn *= 2;
           prob_i /= 2.0;
       }

       prob += prob_i;

    }

    prob /= n;

    cout << setprecision(12) << prob << endl;

    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A.at(i).at(j);
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int sum = 0;
        for (int j = 0; j < N; j++) {
            if (j <= i) {
                sum += A.at(0).at(j);
            }
            if (j >= i) {
                sum += A.at(1).at(j);
            }
        }
        ans = max(ans, sum);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3612
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
b = [(a[i],i) for i in range(n)]
b.sort(reverse=True)
b.append((0,0))
ans = [0]*n
v = b[0][1]
for i in range(n):
    ans[v] += (i+1)*(b[i][0]-b[i+1][0])
    v = min(v,b[i+1][1])
for i in range(n):
    print(ans[i])


Measured memory_bytes: 93388
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
typedef long long LL;

using namespace std;



int main(void) {
	int n, x;
	cin >> n >> x;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	bool tarinai = false;
	for (int i = 0; i < n; i++) {
		if (x - a[i] >= 0) {
			x -= a[i];
			ans++;
		}
		else {
			tarinai = true;
			break;
		}
	}
	if (x == 0) {
		cout << ans;
	}
	else {
		if (tarinai) {
			cout << ans;
		}
		else {
			cout << ans - 1;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1e9+7
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

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

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}


int read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

int main(){
	ll N;
	cin >> N;
	ll x[N+5],pref[N+5];
	vector<pair<int,int> > v;
	for(int i=1;i<=N;i++) 
	{
		cin >> x[i];
		v.pb({x[i],i});
	}
	memset(pref,0,sizeof pref);
	sort(v.begin(),v.end());
	set<int> st;
	st.insert(N+1);
	st.insert(0);
	ll sum = 0;
	for(int i=0;i<v.size();i++){
		ll r = v[i].fi,t = v[i].se;
		set<int>::iterator it = st.upper_bound(t);
		ll val = *it;
		it--;
		int gg = (*it);
		sum += r * (t - gg) * (val - t);
		st.insert(t);
	} 
	cout << sum << "\n";
}



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N-1);
  vector<int> vecn(N,0);
  int count=0;
  for(int i=0;i<N-1;i++){
    cin >> vec.at(i);
  }
  for(int j=0;j<N-1;j++){
    vecn.at(vec.at(j)-1)+=1;
  }
  for(int j=0;j<N;j++){
    cout << vecn.at(j) << endl;
  }
  
}

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

int main()
{

  int n, r, p, c;
  
 while(cin >> n >> r, n){
        int s[n];
	
        for(int i = 0; i < n; i++){   // s??????????????????????????\??????
            s[i] = n - i;
        }
	
        for(int i = 0; i < r; i++){
       
            cin >> p >> c;
            rotate(s, s + p - 1, s + p + c - 1);	    
        }
	
        cout << s[0] << endl;
    }

}

Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>

int main(void)
{
	using namespace std;
	int data[2];

	while(1){
		for(int i=0; i<2; i++){
			cin >> data[i];
		}
		if(data[0] == 0 && data[1] == 0)	break;

		sort(data, data+2);
		cout << data[0] << " " << data[1] << endl;
	}

	return 0;

}

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

int main(){
  int n, q; cin >> n >> q;
  string s; cin >> s;
  int d[100010];
  for (int i = 0; i < n; i++) d[i] = 0;
  for (int i = 1; i < n; i++) {
    d[i] += d[i-1];
    if (s.substr(i-1, 2) == "AC") d[i]++;
  }
  int ans[100010];
  for (int i = 0; i < q; i++) {
    int l, r; cin >> l >> r;
    ans[i] = d[r-1] - d[l-1];
  }
  for (int i = 0; i < q; i++){
    cout << ans[i] << endl;
  }
  return 0;
} 

Measured memory_bytes: 1792
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, k] <- map read.words <$> getLine :: IO [Int]
    css <- S.toList.S.fromList <$> replicateM n getLine
    print $ solve k $ map head $ sort css

solve :: Int -> [Char] -> Int
solve k cs = go 0 $ map length $ group cs
  where
    go !res xs
      | Just xs' <- step xs = go (res+1) xs'
      | otherwise = res

    step :: [Int] -> Maybe [Int]
    step xs
      | length xs >= k = Just $ sortBy (flip compare) $ filter (>0) $ zipWith (-) xs $ replicate k 1 ++ repeat 0
      | otherwise = Nothing

Measured memory_bytes: 8572
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int ame (int j, int N, int a1[], int a2[])
{
  int tmp = 0;

  REP(i,j+1) tmp += a1[i];
  FOR(i,j,N) tmp += a2[i];

  return tmp;
}

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

  int a1[N], a2[N];
  REP (i,N) cin>>a1[i];
  REP (i,N) cin>>a2[i];

  REP (j,N) ans = max (ans, ame(j,N,a1,a2));


  cout<<ans<<endl;

  return 0;
}


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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    string s, t;
    cin >> s >> t;
    map<char, set<int>> index;
    rep(i, s.length()){
        index[s[i]].insert(i+1);
    }
    
    int loops = 0, now = 0;
    for(char c : t){
        if(index[c].empty()){
            cout << -1 << endl;
            exit(0);
        }
        auto it = index[c].upper_bound(now);
        if(it == index[c].end()){
            loops++;
            it = index[c].begin();
        }
        now = *it;
    }
    
    cout << loops * s.length() + now << endl;
}

Measured memory_bytes: 8540
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MAXN = 16;

ll memo[1 << MAXN], c[1 << MAXN];
int N;
int mat[MAXN][MAXN];

ll dp(int bm) {
    ll& ans = memo[bm];
    if(ans == -1) {
        ans = 0LL;
        for(int sbm = bm; sbm; sbm = (sbm - 1) & bm) {
            ans = max(ans, c[sbm] + dp(bm & ~sbm));
        }
    }
    return ans;
}

vector<int> getbits(int x) {
    vector<int> ans;
    for(int i = 0; x; x >>= 1, ++i) {
        if(x & 1) {
            ans.emplace_back(i);
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N;
    foi(i,0,N) {
        foi(j,0,N) {
            cin >> mat[i][j];
        }
    }
    foi(x,0,1<<N) {
        ll& cost = c[x] = 0LL;
        memo[x] = -1LL;
        vector<int> bits_on = getbits(x);
        foi(i,0,bits_on.size()) {
            foi(j,1+i,bits_on.size()) {
                cost += mat[bits_on[i]][bits_on[j]];
            }
        }
    }
    cout << dp((1 << N) - 1) << '\n';
    return 0;
}


Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            if (N % 2 == 0)
            {
                Console.WriteLine(N);
            }
            else
            {
                Console.WriteLine(N * 2);
            }

        }
    }
}

Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const ll inf = 1e15;
int n;
ll a[N], dp[N][3];
char s[N][2];
int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; ++i) {
		scanf("%lld%s", &a[i], s[i]);
	}
	scanf("%lld", &a[n]);
	dp[1][0] = a[1];
	dp[1][1] = dp[1][2] = -inf;	
	for(int i = 2; i <= n; ++i) {
		if(s[i - 1][0] == '-') {
			dp[i][0] = -inf;
			dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) - a[i];
			dp[i][2] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		} else {
			dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
			dp[i][1] = max(dp[i - 1][2], dp[i - 1][1]) - a[i];
			dp[i][2] = dp[i - 1][2] + a[i];
		}
	}
	printf("%lld\n", max(max(dp[n][0], dp[n][1]), dp[n][2]));
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  ll sum = 0;
  REP(i, M) {
    int a;
    cin >> a;
    sum += a;
  }
  if(N<sum){
    cout << -1 << endl;
    return 0;
  }
  cout << N - sum << endl;
 
  return 0;
}


Measured memory_bytes: 3636