akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, p;
    cin >> n >> p;
    vint a(n);
    rep(i, n) cin >> a[i];

    int o = 0;
    rep(i, n) if (a[i]%2) o++;

    ll ans = 2ll << (n-2);
    if (o == 0) {
        if (p) puts("0");
        else cout << ans*2 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   string s; cin>>s;
   if(s[0]==s[1]&&s[1]==s[2]) cout<<"No"<<endl;
   else cout<<"Yes"<<endl;
   return 0; 
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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








template <typename T>
class SegmentTree {
private:
    int n;    // 配列の要素数
    T init;    // 配列を初期化するときの値
    vector<T> data;     // セグメントツリーを持つ配列
public:
    SegmentTree(int m, T init = INF) : n(1), init(init){
        while(n < m) n <<= 1;
        data.assign(2 * n - 1, init);
    }
    
    T operation(T t1, T t2){
        return max(t1, t2);
    }
    
    void update(int k, T val){
        k += n - 1;
        data[k] = val;
        
        while(k > 0){
            k = (k - 1) / 2;
            data[k] = operation(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }
    
    // [a, b) の値を求める
    T query(int a, int b){
        return query(a, b, 0, 0, n);
    }
    
    ll query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return init;
        if(a <= l && r <= b){
            return data[k];
        }
        else{
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return operation(vl, vr);
        }
    }
};



int main(){
    ll n, c, x[100000], v[100000];
    
    scanf("%lld %lld", &n, &c);
    REP(i, n){
        scanf("%lld %lld", &x[i], &v[i]);
    }
    
    ll sum1 = 0, sum2 = 0, mx1 = 0, mx2 = 0;
    SegmentTree<ll> s1(n, -INF), s2(n, -INF);
    REP(i, n){
        if(i == 0){
            sum1 += v[i] - x[i];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]);
        }
        else{
            sum1 += v[i] - x[i] + x[i - 1];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]) + (c - x[n - i]);
        }
        mx1 = max(mx1, sum1);
        s1.update(i, mx1);
        mx2 = max(mx2, sum2);
        s2.update(i, mx2);
    }
    
    ll mx3 = 0;
    sum1 = 0;
    sum2 = 0;
    REP(i, n - 1){
        if(i == 0){
            sum1 += v[i] - x[i];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]);
        }
        else{
            sum1 += v[i] - x[i] + x[i - 1];
            sum2 += v[n - i - 1] - (c - x[n - i - 1]) + (c - x[n - i]);
        }
        mx3 = max(mx3, max(sum1 - x[i] + s2.query(0, n - i - 1), sum2 - (c - x[n - i - 1]) + s1.query(0, n - i - 1)));
    }
    
    printf("%lld\n", max(max(mx1, mx2), mx3));
}

Measured memory_bytes: 5888
#include <iostream>
#include <string>
#define rep(i, k, n) for (int i = k; i < n; ++i)

using namespace std;

int main(){
  // input
  string S;
  cin >> S;
  int N = S.size();

  // bit search
  long long ans = 0;
  rep(bit, 0, (1 << N - 1)) { // 0 ~ 3(11)
    int start = 0, length = 0;
    for (int i = N - 1; i >= 0; --i) { // 2 ~ 0
      if(bit & 1 << i) {
        string s = S.substr(start,(length));
        ans += stoll(s);
        start = N - 1 - i;
        length = 0;
      }
      ++length;
    }
    ans += stoll(S.substr(start, length));
  }

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

type Stack struct {
	xs []int
}

func (s *Stack) push(x int) {
	s.xs = append(s.xs, x)
}

func (s *Stack) pop() (int, bool) {
	if len(s.xs) == 0 {
		return 0, false
	}
	x := s.xs[len(s.xs)-1]
	s.xs = s.xs[:len(s.xs)-1]
	return x, true
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	sc.Scan()
	s := sc.Text()

	stack := &Stack{}
	areas := make(map[int]int)
	totalArea := 0
	last := 0
	for currentStep, c := range s {
		switch c {
		case '\\':
			stack.push(currentStep)
		case '/':
			startStep, ok := stack.pop()
			if ok {
				area := currentStep - startStep
				totalArea += area
				areas[startStep] += area
				for i := startStep + 1; i < currentStep; i++ {
					a, ok := areas[i]
					if ok {
						areas[startStep] += a
						delete(areas, i)
					}
				}
				last = startStep
			}
		}
	}
	fmt.Println(totalArea)
	fmt.Printf("%d", len(areas))
	for i := 0; i <= last; i++ {
		x, ok := areas[i]
		if ok {
			fmt.Printf(" %d", x)
		}
	}
	fmt.Println()
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,a,b,c;
  cin>>n;
  int arr[n][3];
  int dp[n][3];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    dp[0][0]=arr[0][0];dp[0][1]=arr[0][1];dp[0][2]=arr[0][2];
  }
 
  for(int i=1;i<n;i++)
  {
    dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=arr[i][2]+max(dp[i-1][1],dp[i-1][0]);
  }
  
  sort(dp[n-1] , dp[n-1]+3);
  cout<<(dp[n-1][2]);
  
  //cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  return 0;
}


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

int main()
{
	int sum,len;
	char x[1200];
	while(true)
	{
		cin>>x;
		if(x[0]==48) return 0;
		len = strlen(x);
		sum=0;
		for(int i=0;i<len;i++)
			sum += (x[i]-48);
		cout<<sum<<endl;
	}
}



Measured memory_bytes: 3096
using System;

namespace A___Placing_Marbles {
    class Program {
        static void Main(string[] args) {

            var num = Console.ReadLine().ToString();

            int cnt = 0;
            for (int i = 0; i < 3; i++) {
                if (num[i].ToString() == "1") {
                    cnt++;
                }
                
            }

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


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, k;
    int ans = 0;
    cin >> n >> k;
    while(n > 0) {
        ++ans;
        n /= k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template< typename T >
struct RadixHeap
{
  using uint = unsigned;
  vector< pair< uint, T > > v[33];
  uint size, last;

  RadixHeap() : size(0), last(0) {}

  bool empty() const { return size == 0; }

  inline int getbit(int a)
  {
    return a ? 32 - __builtin_clz(a) : 0;
  }

  void push(uint key, const T &value)
  {
    ++size;
    v[getbit(key ^ last)].emplace_back(key, value);
  }

  pair< uint, T > pop()
  {
    if(v[0].empty()) {
      int idx = 1;
      while(v[idx].empty()) ++idx;
      last = min_element(begin(v[idx]), end(v[idx]))->first;
      for(auto &p : v[idx]) v[getbit(p.first ^ last)].emplace_back(p);
      v[idx].clear();
    }
    --size;
    auto ret = v[0].back();
    v[0].pop_back();
    return ret;
  }
};


template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<int, T> > > & G,T INF){
  int n=G.size();
  vector<T> d(n,INF);
  vector<int> b(n,-1);
  RadixHeap<T> q;
  d[s]=0;
  q.push(d[s],s);
  while(!q.empty()){
    auto p=q.pop();
    int v=p.second;
    if(d[v]<(T)p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.push(d[u],u);
      }
    }
  }
  return d;
}

//INSERT ABOVE HERE
signed main(){
  int n,m,r;
  scanf("%d %d %d",&n,&m,&r);
  using P = pair<int, int>;
  vector<vector<P > > G(n);
  for(int i=0;i<m;i++){
    int s,t,d;
    scanf("%d %d %d",&s,&t,&d);
    G[s].emplace_back(t,d);
  }
  auto ans=dijkstra(r,G,INT_MAX);
  for(int i=0;i<n;i++){
    if(ans[i]==INT_MAX) puts("INF");
    else printf("%d\n",ans[i]);
  }
  return 0;
}



Measured memory_bytes: 13912
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main(void){
  int num;
  cin >> num;
  vector<long long> friendly(num);
  for(int i = 0;i < num;i++){
    cin >> friendly[i];
  }
  sort(friendly.begin(),friendly.end());
  long long ans = 0;
  for(int i =0;i < num-1;i++){
    int p = (3+i)/2;
    ans = ans+ friendly[num-p];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4776
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to;int cost;};
typedef pair<int,int> P;
const int Inf=1e7;
int N;
int A,B,C;
vector<edge>X[10];
int d[10];
int cou;
int main()
{
	while(true){

		for(int i=0;i<=cou;i++)X[i].clear();
		int ans1=0,ans2=1e9;
		cou=0;
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<N;i++){
			scanf("%d%d%d",&A,&B,&C);
			edge e1={B,C};
			X[A].push_back(e1);
			edge e2={A,C};
			X[B].push_back(e2);
			cou=max(cou,max(A,B));
		}
		for(int s=0;s<=cou;s++){
			for(int i=0;i<=cou;i++)d[i]=Inf;
			d[s]=0;
			priority_queue<P, vector<P>, greater<P> > que;
			que.push(make_pair(0,s));
			while(!que.empty()){
				P p=que.top();que.pop();
				int v=p.second;
				if(d[v]<p.first)continue;
				for(int i=0;i<X[v].size();i++){
					edge e=X[v][i];
					if(d[e.to]>d[v]+e.cost){
						d[e.to]=d[v]+e.cost;
						que.push(make_pair(d[e.to],e.to));
					}
				}
			}
			//for(int i=0;i<=cou;i++)printf("%d %d %d\n",s,i,d[i]);
			int sum=0;
			for(int i=0;i<=cou;i++)sum+=d[i];
			if(ans2>sum){
				ans2=sum;
				ans1=s;
			}
		}
		printf("%d %d\n",ans1,ans2);
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using Pair = pair<int, int>;
const ll mod = 1e9 + 7;


template<class T>
T gcd(T a, T b)
{
  if(a && b) {
    return gcd(min(a, b), max(a, b) % min(a, b));
  } else {
    return a;
  }
}

template<class T>
T lcm(T a, T b)
{
  return a / gcd(a, b) * b;
}

ll power(ll base, ll exponent, ll module)
{
  if(exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if(exponent) {
    ll root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}

struct combination
{
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1)
  {
    fact[0] = 1;
    for(int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2, mod);
    for(int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll Pair(int n, int r)
  {
    if(r < 0 || n < r) return 0;
    return (fact[n] * inv[n - r] % mod);
  }
  ll C(int p, int q)
  {
    if(q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};

template<typename T>
void print_vec(vector<T>& v)
{
  for(const auto& e: v) {
    cout << e << " ";
  }
  cout << endl;
}
template<typename T>
void print_2dvec(vector<vector<T>>& m)
{
  for(const auto& v: m) {
    for(const auto& e: v) {
      cout << e << " ";
    }
    cout << endl;
  }
}


ll rec(ll h) {
  if (h == 1) return 1;
  return 2 * rec(h / 2) + 1;
}


int main(int argc, char const* argv[])
{
  ll h;
  cin >> h;

  cout << rec(h) << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
for i in range(N):
    l = p[i]
    p[i] = ((1+p[i]) * p[i])//2
    p[i] = p[i]/l
ans = 0
for i in range(K):
    ans +=p[i]
l = ans
for i in range(K,N):
    ans = ans + p[i] - p[i-K]
    l = max(l,ans)
print('{:.8f}'. format(l))

Measured memory_bytes: 67824
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int n;

    cin >> n;
    
    int a;
    
    a = (n - n % 100) / 100;
    
    if (a * 100 + a * 10 + a < n) a++;
    
    cout << a * 100 + a * 10 + a << endl;
    
    return 0;
}

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

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(type,i,n) for(type i=0;i<(n);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N,A,B,C,D;
	cin >> N >> A >> B >> C >> D;
	--A;
	--B;
	--C;
	--D;
	int ans=INF;
	for(int i=1; i<=N; ++i){
		int x1=abs(A%i-B%i),x2=abs(C%i-D%i),y1=abs(A/i-B/i),y2=abs(C/i-D/i);
		ans=min(ans,x1+y1+x2+y2);
		//cout << i << ' ' << x1+y1+x2+y2 << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
ll f[maxn];
ll ksm ( ll a, ll b){
    ll ans = 1 , base = a;
    while(b){
        if (b & 1) ans = ans * base % mod;
        b >>= 1;
        base = base * base % mod;
    }
    return ans;
}
int main(){
    ll n , k; cin >> n >> k;
    f[k] = 1;
    for (int i = k - 1 ; i >= 1 ; i -- ){
        f[i] = ksm(k / i , n);
        for (int j = i + i ; j <= k ; j += i){
            f[i] = (f[i] - f[j] + mod) % mod;
        }
    }
    ll ans = 0;
    for (int i = 1 ; i <= k ; i++){
        ans = (ans + f[i] * i % mod) %mod;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4344
#include<stdio.h>

int max(int a, int b) {
  if (a >= b) {
    return a;
  }
  else {
    return b;
  }
}

int main(void) {
  int N, W;

  // input the number of items and the maximum weight
  scanf("%d %d", &N, &W);
  int value[N], weight[N];
  int dp[N+1][W+1];

  // input values and weights
  for(int i = 0; i < N; i++) {
    scanf("%d %d", &value[i], &weight[i]);
  }

  // initialization
  for (int i = 0; i <= N; i++)
  {
    for (int j = 0; j <= W; j++)
    {
      dp[i][j] = 0;
    }
  }
  
  
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j <= W; j++)
    {
      if (j >= weight[i]) {
        dp[i+1][j] = max(dp[i][j-weight[i]]+value[i], dp[i][j]);
      }
      else {
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  printf("%d\n", dp[N][W]);
}


Measured memory_bytes: 5780
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#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++)
int main() {
  int N;
  cin >> N;
  int A, B;
  vector<int> vec(N);
  rep(i, N) {
    cin >> A >> B;
    if(A == B) {
      vec.at(i) = 1;
    }
    else {
      vec.at(i) = 0;
    }
  }
  int co = 0;
  rep(i, N) {
    if(vec.at(i) == 1) {
      co++;
    }
    else {
      co = 0;
    }
    if(co == 3) {
      cout << "Yes" << endl;
      break;
    }
  }
  if(co < 3) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

bool check(int bit, int k) {
  return ((bit >> k) & 1) > 0;
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> f(n);
  for(int i = 0; i < n; i++) f[i].resize(10);
  for(int i = 0; i < n; i++) for(int j = 0; j < 10; j++) cin >> f[i][j];
  vector<vector<int>> p(n);
  for(int i = 0; i < n; i++) p[i].resize(11);
  for(int i = 0; i < n; i++) for(int j = 0; j < 11; j++) cin >> p[i][j];
  long long ans = -1000000000000;
  for(int i = 1; i < (1 << 10); i++) {
    long long sum = 0;
    for(int j = 0; j < n; j++) {
      long long c = 0;
      for(int k = 0; k < 10; k++) if (check(i, k) && f[j][k] == 1) c++;
      sum += p[j][c];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;

// print(x, y, z);
// print(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N, K;
  std::cin >> N >> K;

  std::priority_queue< ll > kind[N];
  for (ll i = 0; i < N; i++) {
    ll t, d;
    std::cin >> t >> d;
    kind[t-1].push(d);
  }

  std::priority_queue< ll > best;
  std::priority_queue< ll > remain;
  for (ll i = 0; i < N; i++) {
    if (kind[i].empty()) continue;
    best.push(kind[i].top());
    kind[i].pop();
    while (!kind[i].empty()) {
      remain.push(kind[i].top());
      kind[i].pop();
    }
  }

  std::vector< ll > best_sum(1, 0);
  std::vector< ll > remain_sum(1, 0);

  ll sum = 0;
  while (!best.empty()) {
    sum += best.top();
    best_sum.push_back(sum);
    best.pop();
  }

  sum = 0;
  while (!remain.empty()) {
    sum += remain.top();
    remain_sum.push_back(sum);
    remain.pop();
  }

  ll ans = 0;
  for (ll x = 1; x <= K; ++x) {
    if (x >= (ll)best_sum.size()) {
      continue;
    }
    if (K - x >= (ll)remain_sum.size()) {
      continue;
    }
    ans = std::max(ans, best_sum[x] + remain_sum[K - x] + x * x);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 8820
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

template<typename T>T&get(){T a;cin >> a;return a;}
template<typename T>T&rev(T&a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>a){sort(all(a));return a;}

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int inf = 1e9;
const ll linf = 3e18;

int d[10][10];
int N;
bool found[10];

void wf()
{
    rep(k, 10) rep(i, 10) rep(j, 10) {
        chmin(d[i][j], d[i][k] + d[j][k]);
    }
}

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

    while (cin >> N, N) {
        memset(found, 0, sizeof(found));
        fill(d[0], d[10], inf);
        rep(i, 10) d[i][i] = 0;

        rep(i, N) {
            int a, b, c; cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            found[a] = found[b] = true;
        }

        wf();

        int mi = inf, a;

        rep(i, 10) if (found[i]) {
            int sum = 0;
            rep(j, 10) if (found[j]) {
                sum += d[i][j];
            }
            if (mi > sum) {
                mi = sum;
                a = i;
            }
        }

        cout << a << " " << mi << endl;
    }
}

Measured memory_bytes: 1196
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
	double R;
	cin >> R;
	cout << fixed << setprecision(20) << 2*R*M_PI << endl;
	return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u) a--;
    if (t == u) b--; 
    cout << a << " " << b << endl;
    return 0;
}

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

int main()
{
  int A,B;
  cin >> A >> B;

  if(A%3==0 || B%3==0 || (A+B)%3==0)
    cout << "Possible";
  else
    cout << "Impossible";

  return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> p(N);
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    };

    sort(p.begin(), p.end());

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (M - p[i].second < 0) {
            ans += M * p[i].first;
            break;
        }
        else {
            ans += p[i].first * p[i].second;
            M -= p[i].second;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
n=int(input())
s=str(input())
t=len(s)
#setの方が参照速度が速い
r=set()
g=set()
b=set()
a=0
for i in range(n):
    if s[i]=='R':
        r.add(i)
    if s[i]=='G':
        g.add(i)
    if s[i]=='B':
        b.add(i)
d=len(r)*len(g)*len(b)
for ri in r:
    for gi in g:
        rg=gi-ri
        if rg+gi in b:
            d-=1
        if  ri-rg in b:
            d-=1
        if (gi+ri)/2 in b:
            d-=1

print(d)

Measured memory_bytes: 9448
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

int f(int n) {
    int res = 0;
    while (n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

void solve() {
    int N; cin >> N;
    if (N % f(N) == 0) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3644
/* PIcture frame
 * b
 */

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

int main() {
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    string a[105];
    for(int i = 1; i <= h; ++i)
            cin >> a[i];
    for(int i = 1; i <= h; ++i) {
        a[i] = '#'+a[i];
        a[i] = a[i]+'#';
    }
    for(int i = 0; i < w+2; ++i) {
        a[0] = '#'+a[0];
        a[h+1] = '#'+a[h+1];
    }
    for(int i = 0; i <= h+1; ++i) {
            cout << a[i];
        cout << "\n";
    }


    return 0;
}


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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

const int N = 200005;
int n;
struct node
{
    ll sum;
    node():sum(INF){}
}fake;
    // base value is assigned to fake node
struct SEGTREE
{
    ll a[N];
    SEGTREE(){ mem0(a); }
    node tree[4*N];
    void buildTree(ll v,ll st,ll en)
    {
        if(st==en)
        {
            tree[v].sum = n;
            return ;
        }
        ll mid=(st+en)>>1;
        buildTree(v<<1,st,mid);
        buildTree(v<<1 | 1,mid+1,en);
    }
    void update(ll v,ll st,ll en,ll l,ll r,ll val)
    {
        if(l>r)
            return ;
        if(en<l || st>r)return ;
        if(st>=l && en<=r)
        {
            amin(tree[v].sum,val);
            return ;
        }
        ll mid=(st+en)>>1;
        update(v<<1,st,mid,l,r,val);
        update(v<<1 | 1,mid+1,en,l,r,val);
    }
    ll query(ll v,ll st,ll en,ll x)
    {
        if(st==en)
            return tree[v].sum;
        ll u = tree[v].sum;
        ll mid = (st+en)/2;
        if(x<=mid)
            return min(u,query(v<<1,st,mid,x));
        else
            return min(u,query(v<<1|1,mid+1,en,x));
    }
}segr,segc;

int _runtimeTerror_()
{
    int Q;
    cin>>n>>Q;
    segr.buildTree(1,1,n);
    segc.buildTree(1,1,n);
    ll ans = (n-2)*1LL*(n-2);
    for(int i=0;i<Q;++i)
    {
        int tt,x;
        cin>>tt>>x;
        if(tt==1)
        {
            ll y = segc.query(1,1,n,x);
            ans -= y-2;
            segr.update(1,1,n,2,y,x);
        }
        else
        {
            ll y = segr.query(1,1,n,x);
            ans -= y-2;
            segc.update(1,1,n,2,y,x);
        }
    }
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 19288
# Area of Polygon

from math import sin
from math import radians

while True:
    m = int(raw_input())
    if m == 0:
        break

    a1, v, vv = (0.0, 0, 0)
    for i in range(m):
        if i < m - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a1 += sin(radians(v)) * 100 / 2

    n = int(raw_input())

    a2, v, vv = (0.0, 0, 0)
    for i in range(n):
        if i < n - 1:
            v = int(raw_input())
            vv += v
        else:
            v = 360 - vv
        a2 += sin(radians(v)) * 100 / 2

    if a1 > a2:
        print 1
    elif a1 < a2:
        print 2
    else:
        print 0

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

int main()
{
	int n, l[210], sum;

	cin >> n;
	n *= 2;

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

	sort(l, l + n);

	for (int i = 0; i < n; i += 2)
	{
		sum += l[i];
	}
	cout << sum << endl;
	return (0);
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n,r;
  cin >> n >> r;
  int ans = r + 100*max(10-n,0);
  cout << ans << endl;
  return 0;
}


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

int main(){
  string a,b;
  cin >> a >> b;
  a += b;
  int c = stoi(a);
  double d = sqrt(c);
  int e = floor(d);
  if(e*e==c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    int cnt[n+1]={};
    forn(i,k){
        int d;
        cin>>d;
        while(d--){
            int x;
            cin>>x;
            cnt[x]++;
        }
    }
    int ans=0;
    for1(i,n) ans+=cnt[i]==0;
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3672
s=input()
n=len(s)
l=[]
r=[]
for i in range(1,n):
    if s[i]=="L" and s[i-1]=="R":
        l.append(i)
for i in range(n-1):
    if s[i]=="R" and s[i+1]=="L":
        r.append(i)
r=sorted(r,reverse=True)
r_dis=[]
l_dis=[]
lcnt=0
rcnt=0
for i in range(n):
    if s[i]=="R" and i<l[lcnt]:
        r_dis.append([i,l[lcnt]-i])
    if s[i]=="R" and i==l[lcnt]-1:
        lcnt+=1
for i in range(n-1,0,-1):
    if s[i]=="L" and i>r[rcnt]:
        l_dis.append([i,i-r[rcnt]])
    if s[i]=="L" and i==r[rcnt]+1:
        rcnt+=1
ans=[0]*n
for i in range(len(r_dis)):
    if r_dis[i][1]%2==0:
        ans[r_dis[i][0]+r_dis[i][1]]+=1
    else:
        ans[r_dis[i][0]+r_dis[i][1]-1]+=1
for i in range(len(l_dis)):
    if l_dis[i][1]%2==0:
        ans[l_dis[i][0]-l_dis[i][1]]+=1
    else:
        ans[l_dis[i][0]-l_dis[i][1]+1]+=1
ans2=[]
for j in range(n):
    ans2.append(str(ans[j]))
print(" ".join(ans2))


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 1000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll GCD(ll a,ll b){
    if(a < b)return GCD(b,a);
    ll r = INF;
    while(r){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main(){
 ll N;cin >> N;
 ll ans = 0;
 ll g = 0;
 ll m1,m2;
 vector<ll> A(N),B(N);
 set<ll> S;
 for(ll i = 0;i < N;i++){
     cin >> A[i] >> B[i];
     if(i == 0){
         m1 = A[i];m2 = B[i];
     }else{
         for(ll j = max(m1/A[i],m2 / B[i]);;j++){
             if(A[i] * j >= m1 && B[i] * j >= m2){
                 m1 = A[i] * j;
                 m2 = B[i] * j;
                 break;
             }
         }
     }
 }
 cout << m1 + m2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<map>

using namespace std;

typedef pair<int,int> Pt;
#define fr first
#define sc second

int mas[10][10],h,w,dx[]={0,1,-1,0},dy[]={1,0,0,-1};
Pt gl;
Pt Move(Pt p,int n){
  while(true){
    p.fr += dx[n] , p.sc += dy[n];
    if(p.fr >= 0 && p.fr < h && p.sc >= 0 && p.sc < w){
      if( mas[p.fr][p.sc] == 1 ) return p;
    }else return Pt(-1,-1);
  }
}
int solve(Pt p,int home){
  if( !home ){
    return ( p.fr == gl.fr || p.sc == gl.sc ? 1 : 0 );
  }
  int rec = 0;
  for(int i=0;i<4;i++){
    Pt s = Move(p,i);
    if(s.fr == -1) continue;
    mas[s.fr][s.sc] = -1;
    rec += solve(s,home-1);
    mas[s.fr][s.sc] = 1;
  }
  return rec;
}
int main(){
  while(cin >> w >> h && w){
    int home = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> mas[i][j];
        if( mas[i][j] == 1 ) home++;
        else if(mas[i][j] == 2 ) gl = Pt(i,j);
      }
    }
    cout << solve(gl,home) << endl;
  }
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func min(s []byte, k int64) (int, int64) {
	sl := len(s)
	for i := 0; i < sl; i++ {
		if s[i] == 'a' {
			continue
		}
		if int64(('z'+1)-s[i]) <= k {
			diff := 'z' + 1 - s[i]
			s[i] = 'a'
			return i, k - int64(diff)
		}
	}
	s[sl-1] += byte(k % 26)
	return -1, 0
}

func main() {
	in := bufio.NewReader(os.Stdin)
	s, _ := in.ReadString(byte('\n'))
	s = s[:len(s)-1]
	kstr, _ := in.ReadString(byte('\n'))
	kstr = kstr[:len(kstr)-1]
	k, _ := strconv.ParseInt(kstr, 10, 64)
	b := []byte(s)
	i := 0
	for k > 0 {
		var v int
		v, k = min(b[i:], k)
		i += v
	}
	fmt.Println(string(b))
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
      
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            if (a < b)
            {
                Console.WriteLine("a < b");
            }
            if (a > b)
                Console.WriteLine("a > b");
            if (a == b)
                Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 9300
#include "bits/stdc++.h"
using namespace std;

int main() {
	static long long N, Q, A[300000], B[300000], COUNT = 0;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i], B[i] = A[i];
	sort(B, B + N);
	for (int i = 0; i < N; i++) if (A[i] != B[i]) COUNT++;
	if (COUNT == 0) {
		cout << 0 << endl;
		return 0;
	}
	cin >> Q;
	for (int i = 1; i <= Q; i++) {
		long long X, Y;
		cin >> X >> Y;
		X--, Y--;
		if (A[X] == B[X]) COUNT++;
		if (A[Y] == B[Y]) COUNT++;
		if (A[X] == B[Y]) COUNT--;
		if (A[Y] == B[X]) COUNT--;
		if (COUNT == 0) {
			cout << i << endl;
			return 0;
		}
		swap(A[X], A[Y]);
	}
	cout << -1 << endl;
}


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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') cout << a+b << '\n';
    else cout << a-b << '\n';

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	nums := sc.nextIntSlice(N)
	ans := 0
	for _, v := range nums {
		ans += (v - 1)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int64 N;
  cin >> N;
  vector<int64> v(N + 1);
  for (int64 i = 1; i <= N; i++) {
    for (int64 j = i; j <= N; j += i) {
      v[j]++;
    }
  }
  debug(v);
  int64 ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += i * v[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81388
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
AB = [LI() for i in range(N)]
A = [AB[i][0] for i in range(N)]
B = [AB[i][1] for i in range(N)]
A = sorted(A)
B = sorted(B)

from copy import deepcopy

if N % 2 == 0:
    C = [0]*N
    D = [0]*N
    for i in range(N):
        C[i] = 2*A[i]
        D[i] = 2*B[i]
    m = N//2
    d = (D[m]+D[m-1])//2
    c = (C[m]+C[m-1])//2
    print(d-c+1)
    exit()

n = N//2
print(B[n]-A[n]+1)

Measured memory_bytes: 133172
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] sw = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        if (sw[0] <= sw[1])
            Console.WriteLine("unsafe");
        else
            Console.WriteLine("safe");
    }
}

Measured memory_bytes: 28224
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;

int n,a[N],naik[N],turun[N],dp[N];

int rec(int pos){
	if (pos>n) return 0;
	int &ret=dp[pos];
	if (ret!=-1) return ret;
	return ret=1+min(rec(naik[pos]+1),
	rec(turun[pos]+1));
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=1;i<=n;i++){
		cin >> a[i];
	}
	naik[n]=turun[n]=n;
	for (int i=n-1;i;i--){
		if (a[i+1]>=a[i]){
			naik[i]=naik[i+1];
		}else{
			naik[i]=i;
		}
		if (a[i+1]<=a[i]){
			turun[i]=turun[i+1];
		}else{
			turun[i]=i;
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << rec(1) << "\n";
}

Measured memory_bytes: 4992
class Node:
    def __init__(self, idnum):
        self.id = idnum
        self.parent = -1
        self.left = -1
        self.right = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = "root"
#input
n = int(input())
T = [Node(i) for i in range(n)]
for ni in range(n):
    idnum, left, right = [int(i) for i in input().split()]
    T[idnum].left = left
    T[idnum].right = right
    T[idnum].degree = 2 - [left, right].count(-1)
    if left != -1:
        T[left].parent = idnum
        T[left].sibling = right
    if right != -1:
        T[right].parent = idnum
        T[right].sibling = left


#teach node type
leaf_id = []
for ni in range(n):
    if T[ni].parent == -1:
        T[ni].type = "root"
        root_id = ni
    elif T[ni].degree == 0:
        T[ni].type = "leaf"
        leaf_id.append(ni)
    else:
        T[ni].type = "internal node"

def setDepth(p, d):
    T[p].depth = d
    if T[p].left != -1:
        setDepth(T[p].left, d+1)
    if T[p].right != -1:
        setDepth(T[p].right, d+1)
setDepth(root_id,0)

def setHeight(p, h):
    if T[p].height < h:
        T[p].height = h
    if T[p].parent != -1:
        setHeight(T[p].parent, h+1)

for l in leaf_id:
    setHeight(l, 0)

#output
for ni in range(n):
    print("node "+str(T[ni].id)+\
        ": parent = "+str(T[ni].parent)+\
            ", sibling = "+str(T[ni].sibling)+\
                ", degree = "+str(T[ni].degree)+\
                    ", depth = "+str(T[ni].depth)+\
                        ", height = "+str(T[ni].height)+\
                            ", "+T[ni].type)


Measured memory_bytes: 5624
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <map>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)

  int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,char>> v(n);
    rep(i,m){
      int x;
      char y;
      cin >> x >> y;
      pair<int,char> p=make_pair(x,y);
      v[i]=p;
    }
    for (int i=0;i < 1000;i++){
      string s;
      s=to_string(i);
      if (s.size() != n) continue;
      bool f=true;
      rep(j,m){
        if (s[v[j].first-1] != v[j].second){
          f=false;
          break;
        }
      }
      if (f) {
        cout << i << endl;
        return 0;
      }
    }
    cout << -1 << endl;


    return 0;
  }
    
    

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: i32,
        x: i32,
        t: i32,
    }

    let alpha = if n % x == 0 { 0 } else { 1 };
    let res = (n / x + alpha) * t;

    println!("{}", res);
}


Measured memory_bytes: 2116
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static final int SAME_AS_N_SO_FAR = 0;
  static final int LESS_THAN_OR_EQ_N = 1;

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String n = sc.next();
    int t = Integer.valueOf(sc.next());
    int[][][] dp = new int[n.length() + 1][t + 1][LESS_THAN_OR_EQ_N + 1];
    dp[0][0][SAME_AS_N_SO_FAR] = 1;
    for (int i = 0; i < n.length(); i++) {
      for (int j = 0; j <= t; j++) {
        for (int k = SAME_AS_N_SO_FAR; k <= LESS_THAN_OR_EQ_N; k++) {
          int nd = Integer.parseInt(String.valueOf(n.charAt(i)));
          for (int d = 0; d < 10; d++) {
            int ni = i + 1;
            int nj = j;
            int nk = k;
            if (d != 0) {
              nj++;
            }
            if (nj > t) {
              continue;
            }
            if (k == SAME_AS_N_SO_FAR) {
              if (d < nd) {
                nk = LESS_THAN_OR_EQ_N;
              }
              if (d > nd) {
                continue;
              }
            }
            dp[ni][nj][nk] += dp[i][j][k];
          }
        }
      }
    }
    int ans = dp[n.length()][t][0] + dp[n.length()][t][1];
    pw.println(ans);
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }


int main() {
    string S; cin >> S;
    int N = sz(S);
    int cnt = 1;
    if(S[0] == '0' || S[N - 1] == '1') {
        cout << "-1\n";
        return 0;
    }
    bool same = true;
    for(int i = 0; i < N - 1; ++i) {
        if(S[i] != S[N - 2 - i]) {
            same = false;
            break;
        }
    }
    if(!same) {
        cout << "-1\n";
        return 0;
    }
    vector<int> body;
    vector<pii> edges;
    for(int i = 0; i < N; ++i) {
        if(S[i] == '1') body.push_back(i);
    }
    body.push_back(N - 1);
    for(int i = 0; i < sz(body) - 1; ++i) {
        edges.push_back({body[i], body[i + 1]});
    }
    for(int i = 0, j = 0; i < N; ++i) {
        if(i == body[j]) ++j;
        else {
            edges.push_back({i, body[j]});
        }
    }
    for(auto &e : edges) cout << e.first + 1 << " " << e.second + 1 << "\n";
}

Measured memory_bytes: 2868