akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

int main() {
  uint64_t n, m;
  std::cin >> n >> m;
  std::vector<std::pair<uint64_t, uint64_t>> b(m);

  for (auto &i : b) {
    std::cin >> i.first >> i.second;
    if (i.second < i.first) {
      std::swap(i.first, i.second);
    }
  }

  std::sort(b.begin(), b.end());

  uint64_t counter = 1;
  uint64_t end = b[0].second;

  for (const auto &i : b) {
    if (end <= i.first) {
      counter++;
      end = i.second;
    } else if (i.second < end) {
      end = i.second;
    }
  }

  std::cout << counter << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include	<stdio.h>
int	main(void)
{
	int a,b,d,r;
	double f;
//	scanf("%d,%d",&a,&b);
	scanf("%d",&a);
	scanf("%d",&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
	int a, b, c,ex;
	std::cin >> a >> b >> c;
	if (a > b) {
		ex = a;
		a = b;
		b = ex;
	}
	if (b > c) {
		ex = b;
		b = c;
		c = ex;
	}
	if (a > b) {
		ex = a;
		a = b;
		b = ex;
	}
	std::cout << a << " " << b << " " << c << std::endl;
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
 int h,w ,a ,b;
 cin>> h>>w>>a>>b ;
 if(a*2>w&&b*2>h)
 cout<<"No"<<endl ;
 else{
  rep(i,b){
    rep(j,a) cout<<0 ;
    rep(k,w-a-1) cout<<1 ;
    cout<<1<<endl ;
  }

  rep(i,h-b){
    rep(j,a) cout<<1 ;
    rep(k,w-a-1) cout <<0 ;
    cout <<0<<endl ;
  } 
  } return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");

signed main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int gcd=a[0],lcm=a[0];
  for(int i=1;i<n;++i){
    int p=lcm;
    int r=a[i];
    while(1){
      if(p<r)swap(p,r);
      if(!r)break;
      if(p==r)break;
      p%=r;
    }
    gcd=p;
    lcm=lcm*(a[i]/gcd);
  }
  cout<<lcm;
  return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=9.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N,X;
    cin >> N >> X;
    vector<i64> x(N);
    rep(i,0,N) cin >> x[i];

    vector<i64> s(N);
    s[0]=x[0];
    rep(i,1,N) s[i]=s[i-1]+x[i];

    auto sum=[&](int i, int j){
        i64 res=s[j];
        if(i) res-=s[i-1];
        return res;
    };

    i64 ans=numeric_limits<i64>::max();
    rep(i,1,N+1){
        i64 tmp=5*sum(N-i,N-1)+i*X,d=5;
        for(int j=N-i-1; j>=0; j-=i){
            tmp+=d*sum(max(j-i+1,i64(0)),j);
            d+=2;
            if(tmp>=ans) break;
        }
        ans=min(ans,tmp);
    }

    ans+=N*X;
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 3456
n,q=list(map(int, input().split()))
c=[0 for _ in range(n + 1)]
b=[0,0]
for _ in range(q):
    a,v=map(int, input().split())
    c[a]+=v
    if b[0]==a and v>0:b[1]+=v
    elif b[0]==a:mx=max(c[0:]);b[0],b[1]=min([i for i, value in enumerate(c) if value == mx]),mx
    elif b[1]<c[a]:b[0],b[1]=a,c[a]
    elif b[1]==c[a] and b[0] > a:b[0],b[1]=a,c[a]
    print(*b)

Measured memory_bytes: 15736
def main():
    s = list(input())
    count = 0
    if(s[0] == '1'):
        count += 1
    if(s[1] == '1'):
        count += 1
    if(s[2] == '1'):
        count += 1
    
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
using namespace std;
//四角枠
void yoke(long long int h, long long int w)
{
  for (long long int i = 0; i < h; i++)
  {
    for (long long int j = 0; j < w; j++)
    {
      if((i + j) % 2 == 0) cout << "#";
      else cout << ".";
    }
    cout << endl;
  }
}

int main()
{
  while(1)
  {
    long long int H , W;
    cin >> H >> W;
    if(H == 0&&W == 0) return 0;
    yoke(H, W);
    cout << endl;
  }
}


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

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

Measured memory_bytes: 3616
import sys

N = int(input())
C = [int(x) for x in input().split()]

dp = [sys.maxsize] * N
dp[0] = 0

for i in range(1, N):
    dp[i] = min(dp[i], dp[i - 1] + abs(C[i] - C[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(C[i] - C[i - 2]))

print(dp[N - 1])



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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
    bool ret = true;
    if (x < 2) {
        ret = false;
    }
    for (LL i = 2; i <= sqrt(x); i++) {
        if (x%i == 0) {
            ret = false;
        }
    }
    return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    VI a(n+3,0),r(n+3,0);

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        r[i] += r[i-1] + abs(a[i-1] - a[i]);
        dump(r[i]);
    }
    a[n+1] = 0;
    r[n+1] += r[n] + abs(a[n] - a[n+1]);
        for (int i = 1; i <= n; i++) {
            cout << r[i-1] + r[n+1] - r[i+1] + abs(a[i-1] - a[i+1]) << endl;
        }
    return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			String b = Integer.toBinaryString(n);
			int k = Integer.bitCount(n);
			int t = 1;
			int c = 1;
			for(int i = b.length() - 1; i >= 0; i--) {
				if(b.charAt(i) == '1') {
					if(c == k) {
						System.out.println(t);
					}else {
						System.out.printf("%d ", t);
						c++;
					}
				}
				t *= 2;
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 26668
def judge(red, green,blue):
    if blue > green:
        if green > red:
            return (True)
    else:
        return(False)


def main():
    red, green, blue  = map(int, input().split())
    K = int(input())

    while(K > 0):
        if green <= red:
            green *= 2
            K -= 1
            continue
        if blue <= green:
            blue *= 2
            K -= 1
            continue
        if judge(red, green, blue):
            break
        
    if judge(red, green, blue):
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
#include<cstdio>
int main() {
	int n, a, sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		while (a % 2 == 0) {
			a /= 2;
			sum++;
		}
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

struct Cards  //構造体
{
	char mark;
	int num;
} temp;


int main(void)
{
	int N;
	scanf("%d",&N);
	struct Cards array_b[N],array_s[N];
	int i,cnt1=0;
	for(i=0;i<N;i++)    			//入力
	{
		scanf(" %c%d",&array_b[i].mark,&array_b[i].num);
		array_s[i]=array_b[i];
	}
	
	for(int t=0;t<N-1;t++)		//バブルソート
	{
		for(int i=N-1;i>0;i--)
		{
			if(array_b[i].num<array_b[i-1].num)
			{
				temp=array_b[i];
				array_b[i]=array_b[i-1];
				array_b[i-1]=temp;
			}
	 	}
	}
	
	for(int i=0;i<N;i++)		//バブルソート表示
	{
		printf("%c%d",array_b[i].mark,array_b[i].num);
		if(i<N-1)
		{
			printf(" ");
		}
	}
	printf("\n");
	
	
	printf("Stable\n");

								//選択ソート
	for(int i=0;i<N-1;i++)
	{
		int minj=i;
		for(int j=i;j<N;j++)
		{	
			if(array_s[minj].num>array_s[j].num)
			{
				minj=j;
			}
		}
		temp=array_s[i];
		array_s[i]=array_s[minj];
		array_s[minj]=temp;
		
	}
	
	for(int i=0;i<N;i++)		//選択ソート表示
	{
		printf("%c%d",array_s[i].mark,array_s[i].num);
		if(i<N-1)
		{
			printf(" ");
		}
	}
	printf("\n");
	
	for(int i=0;i<N;i++)			//判定
	{
		if(array_b[i].mark!=array_s[i].mark)
		{
			printf("Not stable\n");
			cnt1++;
			break;
		}
	}
	if(cnt1==0)
	{
		printf("Stable\n");
	}

	return 0;
}









	
		
	


Measured memory_bytes: 2040
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};
int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<int> lens;
		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;
			lens.emplace_back(s.size());
		}

		vector<int> cnts{ 5,7,5,7,7 };
		int start = -1;
		for (int i = 0; i < n; i++) {
			int now = 0;
			int tmp = 0;
			for (int j = i; j < n; j++) {
				tmp += lens[j];
				if (tmp > cnts[now])break;

				if (tmp == cnts[now]) {
					now++;
					tmp = 0;
					if (now == 5) {
						start = i;
						break;
					}
				}
			}

			if (start >= 0)break;
		}
		cout << start + 1 << endl;
	}
}


Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
#include <atcoder/all>
using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q; cin >> n >> q;
    fenwick_tree<ll> f(n);
    rep (i, n) {
        ll a; cin >> a; f.add(i, a);
    }
    rep (_, q) {
        int c, a, b; cin >> c >> a >> b;
        if (c == 0) f.add(a, b);
        else cout << f.sum(a, b) << "\n";
    }
    return 0;
}

Measured memory_bytes: 8256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
template< typename T >
struct BIT {
  int N; int max_2beki;

  vector< T > data;
  // 初期化 1-indexedでデータを管理する 0で初期化
  BIT(int size){
      N = ++size;
      data.assign(N, 0);
      max_2beki = 1;
      while(max_2beki * 2 <= N) max_2beki *= 2;
  }

  // [0,k](閉区間)の総和 閉区間に注意！
  T sum(int k) {
    if(k < 0) return 0; // k<0のとき0を返す
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  // [l,r](閉区間)の総和
  inline T sum(int l,int r){
    return sum(r) - sum(l-1);
  }

  // 一点取得 更新はできないことに注意
  inline T operator[](int k){
    return sum(k) - sum(k-1);
  }

  // data[k] += x;
  void add(int k, T x) {
    for(++k; k < N; k += k & -k) data[k] += x;
  }

  // imos法 [l,r]にxを加算
  void imos(int l,int r,T x){
    add(l , x); add(r + 1 , -x);
  }

  // lower_bound sum(i)がval以上となる最小のi
  int lower_bound(T w){
    if(w <= 0) return 0;
    int x = 0;
    for(int k = max_2beki; k > 0; k /= 2){
      if(x+k <= N - 1 && data[x + k] < w){
        w -= data[x + k];
        x += k;
      }
    }
    return x;
  }

  // upper_bound sum(i)がvalより大きくなる最小のi
  int upper_bound(T w){
    if(w < 0) return 0;
    int x = 0;
    for(int k = max_2beki; k > 0; k /= 2){
      if(x+k <= N - 1 && data[x + k] <= w){
        w -= data[x + k];
        x += k;
      }
    }
    return x;
  }

};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;cin >> n >> k;
    BIT<int> bit(n);
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,k){
        BIT<int> bit(n);
        rep(j,n){
            bit.imos(max(0,j-a[j]),min(n-1,j+a[j]),1);
        }
        bool f=true;
        rep(j,n){
            a[j]=bit.sum(j);
            if(a[j]!=n){
                f=false;
            }
        }
        if(f){
            rep(j,n){
                cout << a[j] << " ";
            }
            cout << endl;
            return 0;
        }
    }
    rep(i,n){
        cout << a[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5652
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n; cin >> n;
    vector<string> s(n);
    string mrc = "march";
    int size = mrc.size();
    vector<int> march(size, 0);
    long ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        char c = s[i][0];
        if (c == 'M') ++march[0];
        else if (c == 'A') ++march[1];
        else if (c == 'R') ++march[2];
        else if (c == 'C') ++march[3];
        else if (c == 'H') ++march[4];
    }

    for (int i = 0; i < size-2; ++i) {
        for (int j = i + 1; j < size-1; ++j) {
            for (int k = j + 1; k < size; ++k) {
                ans += (long)march[i] * march[j] * march[k];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,x;
int main(){
    cin>>a>>b>>c;
    if(b>=a) return cout<<1<<endl,0;
    if(c>=b) return cout<<-1<<endl,0;
    if((a-b)%(b-c)) x=1;
    cout<<((a-b)/(b-c)+x)*2+1<<endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
good = [True for _ in range(n)]
h = list(map(int, input().split()))
for i in range(m):
  a, b = map(int, input().split())
  if(h[a-1] >= h[b-1]):
    good[b-1] = False
  if(h[a-1] <= h[b-1]):
    good[a-1] = False
print(good.count(True))

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

int main() {
    int N; cin >> N;
    int M; cin >> M;
    int ans = N;
    for(int i = 0; i < M; i++){
        int tmp; cin >> tmp;
        if(ans < tmp){
            ans = -1;
            break;
        }
        ans -= tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int h,w; cin >> h >> w;
  vector<vector<char>> s(h+2,vector<char>(w+2));
  rep(i,h) rep(j,w) cin >> s[i+1][j+1];

  vector<vector<bool>> out(h,vector<bool>(w,false));
  rep(i,h+1){
    rep(j,w+1){
      if(s[i][j]=='#' && s[i][j+1]!='#' && s[i][j-1]!='#' && s[i-1][j]!='#' && s[i+1][j]!='#'){
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes";
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().strip().split())
h = list(map(int, input().strip().split()))

dp=[10**9]*n

dp[0]=0
for i in range(n):
    # for j in range(1,k+1):
    #     if i+j>n-1:
    #         break
    for j in range(1,min(k+1,n-i)):
        dp[i+j]=min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[-1])

Measured memory_bytes: 52448
import numpy as np

S = input()
N = int(len(S))
lst = [int(S[i]) for i in range(N)]

if N % 2 == 0:
  med = int(N/2)
else:
  med = int(N/2 + 1)

left = lst[:med]
right = lst[med:]

left_blue = np.sum(left)
left_red = len(left) - left_blue
right_blue = np.sum(right)
right_red = len(right)-right_blue

ans = N - (np.abs(left_red-right_blue) + np.abs(left_blue-right_red))

print(int(ans))

Measured memory_bytes: 14908
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Search Engine
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> w = new ArrayList<String>();
		String[] s = sc.nextLine().replace(",", " ").replace("."," ").split(" ");
		for(String e:s)if(3<=e.length()&&e.length()<=6)w.add(e);
		boolean f = true;
		for(String e:w){
			if(!f)System.out.print(" ");
			System.out.print(e);
			f = false;
		}
		System.out.println();
	}
}

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

#define COUT(x) cout << #x << " = " << (x) << ", "
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
typedef long long ll;
const int MOD = 1000000007;

int main(){
  ll X; cin >> X;
  ll T = 0;
  ll len = 0;
  while(len < X){
    T++;
    len += T;
  }
  cout << T << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
int k,x;
cin>>k>>x;
if(500*k>=x){
  cout<<"Yes"<<endl;
}
else{
  cout<<"No"<<endl;
}

}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main() {
    string s;
    cin>>s;
    char a=s[0];
    int cnt=0,b=s.size();
    for(int i=1;i<b;i++){
        if(s[i]!=a){
            a=s[i];
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


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

class C
{
    static void Main()
    {
        var x = (Console.ReadLine()).Split(' ');

        int N = int.Parse(x[0]);
        int K = int.Parse(x[1]);

        var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();


        for (int i = K; i < N; i++)
        {
            if ((int)A[i - K] < (int)A[i])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

    }
}

Measured memory_bytes: 46284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    string s; cin >> s;
    vector<int> r(n + 1), g(n + 1), b(n + 1);
    for (int i = 0; i < n; i++) {
        r[i + 1] = r[i] + (s[i] == 'R');
        g[i + 1] = g[i] + (s[i] == 'G');
        b[i + 1] = b[i] + (s[i] == 'B');
    }
    ll ans = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            int len = j - i;
            if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
                ans += b[min(n, j + len)] - b[j];
                ans += b[n] - b[min(n, j + len + 1)];
            }
            if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')) {
                ans += r[min(n, j + len)] - r[j];
                ans += r[n] - r[min(n, j + len + 1)];
            }
            if ((s[i] == 'B' && s[j] == 'R') || (s[i] == 'R' && s[j] == 'B')) {
                ans += g[min(n, j + len)] - g[j];
                ans += g[n] - g[min(n, j + len + 1)];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
int alphabet[26];

int main() {
    char ch;
    while (cin >> ch) {
        if ('a' <= ch && ch <= 'z') alphabet[ch - 'a']++;
        else if ('A' <= ch && ch <= 'Z') alphabet[ch - 'A']++;
    }
    for (int i = 0; i < 26; i++) cout << char(i + 'a') << " : " << alphabet[i] << endl;
}


Measured memory_bytes: 3100
n=int(input())
l=[]
l.append([0,0,0])
f=0
for i in range(n):
    ll=list(map(int,input().split()))
    l.append(ll)
for i in range(n):
    dt=abs(l[i][0]-l[i+1][0])
    da=abs(l[i][1]-l[i+1][1])
    db=abs(l[i][2]-l[i+1][2])
    if dt<da+db:
        f=1
    if dt==0 and da+db!=0:
        f=1
    if (da+db)%2 != (dt)%2 and dt>da+db:
        f=1
if f==0:
    print("Yes")
else:
    print("No")
        

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

int main(){

 string A, B, C;
 int N, ans=0;
 cin >> N >> A >> B >> C;

 for(int i=0; i<N; i++){
  if(A[i] != B[i] && A[i] != C[i] && B[i] != C[i]) ans += 2;
  if(A[i] == B[i] && A[i] != C[i] && B[i] != C[i]) ans++;
  if(A[i] != B[i] && A[i] == C[i] && B[i] != C[i]) ans++;
  if(A[i] != B[i] && A[i] != C[i] && B[i] == C[i]) ans++;
 }

 cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

const int M = 17;
const ld inf = 2e9;

int n;
int x[M], y[M], a[M];
ld d[1 << M];
ld f[1 << M];
int p[M];

void ini() {
  iota(p, p + M, 0);
}

int get(int x) {
  return p[x] = p[x] == x ? x : get(p[x]);
}

void uni(int x, int y) {
  x = get(x);
  y = get(y);
  p[x] = y;
}

void read() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> a[i];
  }
}

int bit(int mask, int i) {
  return (mask >> i) & 1;
}

ld mst(int mask) {
  vector<int> V;
  
  vector<tuple<int, int, ld>> E;

  for (int i = 0; i < n; ++i)
    if (bit(mask, i))
      V.push_back(i);

  for (int a : V)
    for (int b : V) {
      ld dist = hypotl(x[a] - x[b], y[a] - y[b]);
      E.emplace_back(a, b, dist);
    }

  sort(E.begin(), E.end(), [](tuple<int, int, ld> x, tuple<int, int, ld> y) -> bool {
      return get<2>(x) < get<2>(y);
      });
      
  
  ld ans = 0;
  ini();

  for (int u : V)
    ans += a[u];

  for (auto e : E) {
    int a, b;
    ld w;
    tie(a, b, w) = e;
    if (get(a) != get(b)) {
      uni(a, b);
      ans -= w;
    }
  }

  if (!V.empty()) {
    ans /= V.size();
  }


  return ans;
}

void kill() {
  for (int mask = 0; mask < (1 << n); ++mask) {
    f[mask] = mst(mask);
  }

  d[0] = inf;
  for (int mask = 1; mask < (1 << n); ++mask) {
    d[mask] = 0;
    for (int sub = mask; sub > 0; sub = (sub - 1) & mask)
      d[mask] = max(d[mask], min(d[mask ^ sub], f[sub]));
  }

  cout << d[(1 << n) - 1] << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif
  cout.precision(10);
  cout << fixed;

  ios_base::sync_with_stdio(false);

  read();
  kill();

}



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

public class Main {
	static int[][] mv = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

	static char[] c = { 'U', 'R', 'D', 'L' };

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		boolean[][] e = new boolean[25][25];
		int h = 0, t = 0;
		for (int x = 0; x < 9; x++) {
			char[] s = br.readLine().toCharArray();
			for (int j = 0; j < s.length; j++) {
				if (s[j] == '0') continue;
				if (t == 0) {
					e[h * 5 + j][h * 5 + j + 1] = e[h * 5 + j + 1][h * 5 + j] = true;
				} else {
					e[h * 5 + j][(h + 1) * 5 + j] = e[(h + 1) * 5 + j][h * 5 + j] = true;
				}
			}
			if (t == 1) h++;
			t = (t + 1) % 2;
		}
		int i = 0, j = 0, d = 1;
		StringBuilder sb = new StringBuilder();
		boolean f = true;
		while (f) {
			for (int k = 3; k <= 6; k++) {
				int nd = (d + k) % 4;
				int ni = i + mv[nd][0];
				int nj = j + mv[nd][1];
				if (0 <= ni && ni < 5 && 0 <= nj && nj < 5 && e[i * 5 + j][ni * 5 + nj]) {
					sb.append(c[nd]); i = ni; j = nj; d = nd;
					if (i == 0 && j == 0) f = false;
					break;
				}
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
 
int main(){
    int N, M;

    cin >> N;
    vec<string> s(N, "0");
    for (int i=0; i<N; i++) cin >> s[i];

    cin >> M;
    vec<string> t(M, "0");
    for (int i=0; i<M; i++) cin >> t[i];

    map<string, int> total;

    for (int i=0; i<N; i++) {
        total[s[i]]++;
    }
    for (int i=0; i<M; i++) {
        total[t[i]]--;
    }

    int ans = 0;
    for( auto i = total.begin(); i != total.end() ; i++ ) {
        if (i->second > ans) ans = i->second;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def tpbc_2018_b():
    a, b, k = map(int, input().split())
    for i in range(k//2):
        a //= 2
        b += a
        b //= 2
        a += b
    if k % 2 == 1:
        a //= 2
        b += a
    return "{} {}".format(a, b)


print(tpbc_2018_b())

Measured memory_bytes: 3060
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

#[allow(unused_imports)]
use input::*;

fn main() {
    let (n,d):(usize,usize);
    input!(n,d);
    if n%(d*2+1)==0{
        p(n/(d*2+1))
    }else{
        p(n/(d*2+1)+1)
    }
}

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

using namespace std;
#define ll long long

const int N = 1e5 + 10;

struct E{
    ll x,y;

}a[N];

bool cmp1(E e1,E e2) {
    return e1.y > e2.y;
}

bool cmp2(E e1,E e2) {
    return e1.x > e2.x;
}

int main(){
    int n,s;cin>>n>>s;
    for(int i = 0;i < n;i++) {
        cin>>a[i].x>>a[i].y;
    }
    sort(a,a+n,cmp2);
    ll max_x = a[0].x;
    sort(a,a+n,cmp1);
    int len_t = n;
    for(int i = 0;i < n;i++) {
        if(a[i].y < max_x) {
            len_t = i;
            break;
        }
    }
    ll sum = 0;
    int res = 0;
    for(int i = 0;i < len_t;i++) {
        sum += a[i].y;
        res++;
        if(sum >= s) {
            cout<<res<<endl;
            return 0;
        }
    }
    s -= sum;
    res += ceil(s*1.0/max_x);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(!f){
	if(in<=min(b,c)){
	  f=1;
	}
	if((b>=c && b<in)||(b<c && c>in))b=in;
	else c=in;
      }
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

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

int x[100010]={0};

int main(void){
	int n, t1=0, t2, x1=0, x2, y1=0, y2;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> t2 >> x2 >> y2;
		int dt=t2-t1, dx=abs(x2-x1), dy=abs(y2-y1);
		if(dt<dx+dy || dt%2!=(dx+dy)%2){
			cout << "No" << endl;
			return 0;
		}
		t1 += dt;
		x1 += (x2-x1);
		y1 += (y2-y1);
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
  int n;
  vector<int> sizearray;
  while(cin>>n&&n){
    sizearray.push_back(n);
  }
  for(int index=0;index<sizearray.size();index++){
    int size=sizearray[index];
    vector<vector<int> > Mat(size);
    for(int i=0;i<size;i++){
      Mat[i].resize(size);
    }
    int y=size/2+1,x=size/2;
    for(int i=1;i<=size*size;i++){
      if(Mat[y][x]){
        y=(y+1)%size;
        x=(x-1)<0?size-1:x-1;
      }
      Mat[y][x]=i;
      y=(y+1)%size;
      x=(x+1)%size;
    }


    for(int i=0;i<size;i++){
      for(int j=0;j<size;j++){
        cout<<setw(4)<<Mat[i][j];
      }
      cout<<endl;
    }
  }

}

Measured memory_bytes: 1228
main = getLine >>= print . solve 0 0 '0'

solve bw wb _ [] = min bw wb
solve bw wb '0' ('0':ss) = solve bw (wb + 1) '1' ss
solve bw wb '0' ('1':ss) = solve (bw + 1) wb '1' ss
solve bw wb '1' ('0':ss) = solve (bw + 1) wb '0' ss
solve bw wb '1' ('1':ss) = solve bw (wb + 1) '0' ss

Measured memory_bytes: 4988
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <bitset>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(c) (c).begin(), (c).end()

const int inf = 1e8;
typedef bitset<110> hasrefrig;

struct Edge {
    int to, wt;
    Edge(int to_, int wt_) : to(to_), wt(wt_) {};
};

typedef vector<Edge> Edges;

struct Graph : vector<Edges> {
    Graph(size_t n) : vector<Edges>(n) {}
    void add(int u, int v, int wt) {
        at(u).emplace_back(v, wt);
        at(v).emplace_back(u, wt);
    }
};

int solve(int M, int A, int H, const hasrefrig& rf, const Graph& G) {
    vector<vector<int>> mem(G.size(), vector<int>(M + 1, inf)); mem[A][M] = 0;
    typedef tuple<int, int, int> State;
    priority_queue<State, vector<State>, greater<State>> Q;
    for (Q.emplace(0, A, M); !Q.empty();) {
        int cost, cur, rerf;
        tie(cost, cur, rerf) = Q.top(); Q.pop();
        if (mem[cur][rerf] < cost) continue;
        if (cur == H) return cost;
        for (const auto e: G[cur]) {
            for (int k = rf[cur]? M: rerf; k >= 0; --k) {
                if (k < rerf) break;
                int nxt = cost + e.wt + k - rerf;
                if (k < e.wt || mem[e.to][k - e.wt] <= nxt) continue;
                mem[e.to][k - e.wt] = nxt;
                Q.emplace(nxt, e.to, k - e.wt);
            }
        }
    }
    throw "Help!";
}

int main() {
    int N, M, L, K, A, H;
    while (cin >> N >> M >> L >> K >> A >> H, N | M | L | K | A | H) {
        hasrefrig rf; rf.set(A); rf.set(H);
        for (int x; L--; rf.set(x)) cin >> x;
        Graph G(N);
        for (int X, Y, T; K--; G.add(X, Y, T)) cin >> X >> Y >> T;
        try {
            cout << solve(M, A, H, rf, G) << endl;
        }
        catch (char const *mes) {
            cout << mes << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1672
N, M = map(int, input().strip().split())
INF = 100000000

d = [[INF for _ in range(N)] for _ in range(N)]
abc = []

for _ in range(M):
  a, b, c = map(int, input().strip().split())
  d[a-1][b-1] = c
  d[b-1][a-1] = c
  abc.append((a-1, b-1, c))

for i in range(N):
  d[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      d[i][j] = min(d[i][j], d[i][k]+d[k][j])

ans = M
for a, b, c in abc:
  shortest = False
  for j in range(N):
    if d[j][a]+c == d[j][b]:
      shortest = True
  if shortest:
    ans -= 1
print(ans)


Measured memory_bytes: 3440
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

lst=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(lst[k-1])

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

int main() {
    string a; cin >> a;
    for(int i=a.size()-2;i>0;i-=2){
      if(a.substr(0,i/2) == a.substr(i/2,i/2))
      {cout << i << endl; break;}
    }

    return 0;
}

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

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

int main(void){
    
    string s;
    cin>>s;
    int ans=1000;
    FOR(i,s.length()-2){
        string str = s.substr(i,3);
        long long a = atoi(str.c_str());
        //cout<<a<<endl;
        if(abs(a-753)<ans)ans=abs(a-753);
        
    }
    
    cout<<ans;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(const pair<A,B> &p,const pair<C,D> &q){ p.X+=p.X; q.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(const pair<A,B> &p,const pair<C,D> &q){ p.X-=p.X; q.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T> T read(){ T re; cin>>re; return move(re);}
template<class T> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}

const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	cauto n=read<int>();
	cauto es=readV<pii>(n-1,{1,1});
	ll re=0;
	reps(i,1,n+1) re+=i*(n+1ll-i);
	for(auto [a,b]:es) re-=(min(a,b)+1ll)*(n-max(a,b));
	cout<<re NL;
  return 0;
}


Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int k;
string s;
cin>>k;
ws(cin);
cin>>s;

if(s.size()<=k)
{

    cout<<s;
}

else
{
    for(int i=0;i<k;i++)
    {
        cout<< s[i];

    }
cout<<  "...";

}

return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>                          
using namespace std;
int t[100];
string s;
int main(){
	cin>>s;
	for(int i=0;i<3;i++)
	    t[s[i]]++;
	for(int i='a';i<='c';i++)
	    if(t[i]!=1) {cout<<"No";return 0;}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int N;cin>>N;
    vi a(N);
    in(N,a);
    rep(i,N) a[i]--;
    vi idx(N);
    rep(i,N) idx[a[i]] = i;
    ll ans = 0;
    set<int> s;
    
    for (int x = N-1; x >= 0; x--) {
        int i = idx[x];
        ll c = 0;
        
        s.insert(i);
        vi l(2,-1),r(2,N);
        auto it = s.find(i);
        rep(j,2){
            if(it == s.begin()) break;
            --it;
            l[j] = *it;
        }
        it = s.find(i);
        rep(j,2){
            ++it;
            if(it == s.end()) break;
            r[j] = *it;
        }
        
        vi ls(2);
        ls[0] = -l[0]+i; ls[1]=l[0]-l[1];
        vi rs(2);
        rs[0] = r[0]-i; rs[1]=r[1]-r[0];
        
        c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
        
        ans += c*(x+1);
    }
    out(ans);
    

    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    char s[100][100];
    int ans[100][100];
    cin >> h >> w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> s[i][j];
            if(s[i][j]=='#'){
                ans[i-1][j-1]++;
                ans[i][j-1]++;
                ans[i-1][j]++;
                ans[i+1][j+1]++;
                ans[i][j+1]++;
                ans[i+1][j]++;
                ans[i+1][j-1]++;
                ans[i-1][j+1]++;
            }
            else continue;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                cout << '#';
            }
            else cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    if (N % 2 != 0){
        cout << "No" << endl;
        return 0;
    }
    string A = S.substr(0,(N / 2));
    string B = S.substr((N / 2),(N / 2));
    if (A == B) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

double dp[3000][3000];

int main() {
    ll N;
    cin >> N;
    double p[N];
    REP(i, 0, N) {
        cin >> p[i];
    }
    REP(i, 0, 3000) {
        fill(dp[i], dp[i] + 3000, 0);
    }
    dp[0][0] = 1;
    REP(i, 0, N) {
        REP(j, 0, i + 1) {
            dp[j + 1][i - j] += dp[j][i - j] * p[i];
            dp[j][i - j + 1] += dp[j][i - j] * (1 - p[i]);
        }
    }
    double ans = 0;
    REP(i, 0, N / 2 + 1) {
        ans += dp[N - i][i];
    }
    cout << setprecision(12);
    cout << ans << endl;
}


Measured memory_bytes: 70528
from functools import lru_cache
def resolve():
    n = int(input())
    x = list(map(int, input().split()))

    x.sort()

    l = 0
    r = max(x)
    
    @lru_cache()
    def cost(p):
        s = 0
        for i in x:
            s += (i - p)**2
        return s

    while l + 1 < r:
        m = (l + r) // 2 
        l_s = cost(l)
        r_s = cost(r)
        if l_s > r_s:
            l = m
        else:
            r = m
    print(min(cost(l), cost(r)))


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

double dp[3010][3010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    double p[3010];
    rep(i, N) cin >> p[i];
    dp[0][0] = 1.0;
    REP(i, 1, N) {
        REP(j, 0, N) {
            if (j == 0) dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
            else {
                dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * (p[i - 1]);
            }
        }
    }
    double ans = 0;
    REP(i, (N + 1)/2, N) {
        ans += dp[N][i];
    }
    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    lint N, K;
    cin >> N >> K;

    lint ans = 0;
    for (int a = 1; a <= N; a++) {
        int a_mod  = a % K;
        int bc_mod = (K - a_mod) % K;

        if ((bc_mod + bc_mod) % K != 0) continue;

        lint cnt = N / K + (bc_mod <= N % K ? 1 : 0) - (bc_mod == 0 ? 1 : 0);

        ans += cnt * cnt;
        // d(ans);
    }

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

Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
int main()
{
    char s[5];
    scanf("%s", s);
    if (strlen(s) == 2)
        printf("%s\n", s);
    else
        printf("%c%c%c\n", s[2], s[1], s[0]);
    return 0;
}

Measured memory_bytes: 128