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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll ans=0;
  ll min=10;
  rep(i,5){
    ll a; cin>>a;
    if(a%10==0) ans+=a;
    else{
      ans+=a/10*10+10;
      chmin(min,a%10);
    }
    // cout<<ans<<endl;
  }
  cout<<ans-(10-min)<<endl;
}

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

int main() {//0
  int n,m;
  cin>>n>>m;
  vector<vector<bool>> sw(m,vector<bool>(n,false));
  for(int i=0;i<m;i++){//1
    int k;
    cin>>k;
    for(int j=0;j<k;j++){//2
      int s;
      cin>>s;
      sw[i][s-1]=true;
    }//1
  }//2
  vector<int> p(m);
  for(int &X: p) cin>>X;
  int ans=0;
  for(int bit=0;bit<(1<<n);bit++){//3
    bool flag=true;
    for(int i=0;i<m;i++){ //電球 //4
      int cnt=0;
      for(int j=0;j<n;j++){ //bit動かす //5
      if(bit>>j&1&&sw[i][j]) cnt++; 
      }//5
      if(cnt%2!=p[i]) {//6
        flag=false;
      }//6
    }//4
      if(flag) ans++;
  }//3
    cout<<ans<<endl;
}//0
      
      
      
      

Measured memory_bytes: 256
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

n,r=map(int,input().split())

if n>=10:
    print(r)
else:
    print(r+100*(10-n))

Measured memory_bytes: 66156
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MOD=1000000007;
int mypow(int x,int n) { int ret=1; while(true) { if(n&1) ret=(ll)ret*x%MOD; if((n>>=1)==0) return ret; x=(ll)x*x%MOD; } }


int len,mxval;

void run() {
	scanf("%d%d",&len,&mxval);

	vector<int> dv;	for(int i=1;i*i<=len;++i) if(len%i==0) { dv.PB(i); if(i*i<len) dv.PB(len/i); } sort(dv.begin(),dv.end());
	int ndv=SZ(dv);
	vector<int> ways(ndv);
	REP(i,ndv) {
		ways[i]=mypow(mxval,(dv[i]+1)/2);
		REP(j,i) if(dv[i]%dv[j]==0) ways[i]=(ways[i]+MOD-ways[j])%MOD;
	}
	int ret=0;
	REP(i,ndv) {
		int times=dv[i]%2==0?dv[i]/2:dv[i];
		//printf("%d: %d*%d\n",dv[i],times,ways[i]);
		ret=(ret+(ll)times*ways[i])%MOD;
	}
	printf("%d\n",ret);
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=5e5+10, maxm=1e6+10, lg=21, mod=1e9+7, inf=1e18;

ll a[maxn],sum;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
		
	string s; cin>>s; ll n=SZ(s);
	for(int i=0;i<n;i++) a[n-i-1]=s[i]-'0';
	ll l=0,r=10*maxn,mid;
	while(r-l>1){
		mid=(l+r)/2;
		ll N=0,X=mid*9;
		bool F=0;
		for(int i=0;i<n;i++){
			X-=((X-a[i])%10+10)%10;
			if(N>X){
				l=mid;
				F=1; break;
			}
			ll nx=X/10;
			X+=nx-N;
			N=nx;
		}
		if(!F) r=mid; // real madrid :)
	}
	cout<<r;
	
	return 0;
}

Measured memory_bytes: 7692
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

n, x = map(int, input().split())
xlist = list(map(int, input().split()))
for i in range(n):
    xlist[i] = abs(xlist[i]-x)
    
if len(xlist)==1:
    print(xlist[0])
else:
    maxgcd = gcd(xlist[0], xlist[1])
    for i in range(2,n):
        maxgcd = gcd(maxgcd, xlist[i])
    print(maxgcd)

Measured memory_bytes: 14252
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

const int N = 1e5+10;

int a[N];
bool st[N];
int main()
{
    
    string s;
    
    cin >> s;
    if(s=="SUN"){
        cout << 7 << endl;
    }
    else if(s=="MON"){
        cout << 6 << endl;
    }
    else if(s=="TUE"){
        cout << 5 << endl;
    }
    else if(s=="WED"){
        cout << 4 << endl;
    }
    else if(s=="THU"){
        cout << 3 << endl;
    }
    else if(s=="FRI"){
        cout << 2 << endl;
    }
    else if(s=="SAT"){
        cout << 1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    Integer[] A = new Integer[N];
    int sum = 0;
    String ret = "Yes";
    for(int i = 0; i < A.length; i++){
      A[i] = sc.nextInt();
      sum += A[i];
    }
    Arrays.sort(A, Collections.reverseOrder());
    for(int i = 0; i < M; i++){
      if(A[i] * 4 * M < sum){
        ret = "No";
        break;
      }
    }
    System.out.println(ret);
  }
}

Measured memory_bytes: 23636
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll calc(ll a,int i)
{
    ll s=1;
    while (i>=0)
    {
        if (!(a&(1ll<<i))) s+=1ll<<i;
        i--;
    }
    return s;
}

ll solve(ll a,ll b,int i)
{
    if (a<=b) return 1ll<<(i+1);
    if (b>=(1ll<<i)) return 1ll<<(i+1);
    if (!i) return 2;
    if (a<(1ll<<i)) return solve(a,b,i-1)+(1ll<<i);
    ll ans=0;
    for (int j=i-1;j>=-1;j--) if (j==-1||(b&(1ll<<j))) {ans+=(1ll<<(j+1));break;}
    return ((1ll<<(i+1))-a)+ans;
}

int main()
{
    //freopen("input.txt","r",stdin);
    ll a,b,ans=0;cin>>a>>b;
    if (a==b) {puts("1");return 0;}
    for (int i=59;i>=0;i--)
        if ((b&(1ll<<i))&&!(a&(1ll<<i)))
        {
            ans=calc(a&((1ll<<i)-1),i-1)+solve(a&((1ll<<i)-1),b&((1ll<<i)-1),i-1);
            break;
        }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

int main(){
    int L;
    cin >> L;
    double s = 1.0 * L / 3;
    printf("%.10lf\n", s * s * s);
    return 0;
}


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

using namespace std;

#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i <= int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long

const int mod = 1000000007;

inline int add(int a, int b);
inline int mult(int a, int b);
inline int sub(int a, int b);
inline int divv(int a, int b);

struct block {
    int w, s, v;

    bool operator<(block &other) {
        return s + w < other.s + other.w;
    }
};

int p[200500];

int c(int n, int k) {
    return divv(divv(p[n], p[k]), p[n - k]);
}

int dp[3050];

int32_t main() {
    std::iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);

    p[0] = 1;
    for (int i = 1; i < 200500; i++)
        p[i] = mult(p[i - 1], i);

    int h, w;
    cin >> h >> w;

    vector<pair<int, int>> v;
    v.emplace_back(h, w);

    int n;
    cin >> n;
    while (n--) {
        int r,c;
        cin >> r >> c;
        v.emplace_back(r, c);
    }

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

    forn(i, v.size()) {
        int res = c(v[i].first + v[i].second - 2, v[i].first - 1);

        forn(j, i)
            if (v[j].first <= v[i].first && v[j].second <= v[i].second)
                res = sub(res, mult(dp[j], c(v[i].first - v[j].first + v[i].second - v[j].second, v[i].second - v[j].second)));

        dp[i] = res;
        //cout << res << endl;
    }


    cout << dp[v.size() - 1];

    return 0;
}

int add(int a, int b) {
    int result = a + b;
    if (result >= mod)
        result -= mod;
    return result;
}

int sub(int a, int b) {
    int result = a - b;
    if (result < 0)
        result += mod;
    return result;
}

int mult(int a, int b) {
    return (a * 1ll * b) % mod;
}

int bin(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1)
            res = mult(res, a);

        a = mult(a, a);
        n /= 2;
    }

    return res;
}

int divv(int a, int b) {
    return mult(a, bin(b, mod - 2));
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

template <typename T>
vector<pair<T,T>> arg_sort(vector<pair<T,T>> &a){
  sort(ALL(a), [](const auto &p, const auto &q){return atan2(p.snd, p.fst) < atan2(q.snd, q.fst);});
  return a;
}


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

    vector<pair<int,int>> engine(N);
    REP(i,N){
      int x,y; cin >> x >> y;
      engine[i] = make_pair(x,y);
    }

    engine = arg_sort(engine);
    REP(i,N){
      engine.push_back(engine[i]);
    }

    double ans = 0;

    REP(i,N){
      FOR(j,i,i+N){
        double x = 0, y = 0;

        FORE(k,i,j){
          x += engine[k].fst;
          y += engine[k].snd;
        }
        
        chmax(ans, sqrt(x*x+y*y));
      }
    }

    cout << fixed << setprecision(12) << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = []
for i in range(n):
    s = list(str(input()))
    s.sort()
    arr.append(s)
arr.sort()
ans = 0
count = 1
for i in range(1, n):
    if arr[i] == arr[i - 1]:
        count += 1
    else:
        ans += count * (count - 1) // 2
        count = 1
    if i == n - 1:
        ans += count * (count - 1) // 2
print(ans)

Measured memory_bytes: 24652
a = int(input())
b = str(input())

res = []
def finder(A,B):
    goi = 0
    for k in range(97, 97+26):
        num = chr(k)
        if num in A and num in B:
            goi += 1
    else:
        return goi

for i in range(1,a):
    c = b[0:i]
    d = b[i:a]
    tyu = finder(c,d)
    
    res.append(tyu)
else:
    bigg = max(res)
    print(bigg)


Measured memory_bytes: 3060
import java.util.*;

public class Main{
    private int n, cnt, tmp;
    private int[] a;

    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    }

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

//約数列挙 O(sqrt(n))
set<ll> get_divisors(ll n) {
  set<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.insert(i);
      res.insert(n / i);
    }
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  auto st = get_divisors(n);
  ll ans = 1e18;
  FOREACH(x, st) {
    ll t = x + n / x - 2;
    ans = min(ans, t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

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

fn main() {
    let x = read_as_vec::<u32>()[0];
    println!("{}", 10 - x / 200);
}


Measured memory_bytes: 2136
#include<stdio.h>
#include<memory.h>
#include<algorithm>
#include<vector>
using namespace std;
#define INF 0x7ffffffff
int main()
{
    int N, W;
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &N, &W);
    vector<int>w(N);
    vector<int>v(N);
    for(int i=0; i<N; i++)
    {
        scanf("%d%d", &w[i], &v[i]);
    }
    vector<long> dp(N*1000+1, INF);
    dp[0] = 0;
    for(int i=0; i<N; i++)
    {
        for(int j=N*1000; j>=v[i]; j--)
        {
            dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
        }
    }
    long ans = 0;
    for(long i=0; i<=N*1000; i++)
    {
       if(dp[i] <= W)ans = max(ans, i);
    }
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

int n, ans;

int main() {
	read(n);
	for (int i = 1; i <= n; ++i)
		if (i & 1) ++ans;
	printf("%.10lf\n", ans * 1.0 / n);
	return 0;
}

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

int middium(int mat,int ing, int jap){
	return (mat + ing + jap) / 3;
}


void classes(int mat,int ing,int jap){
	int mid;
	mid = middium(mat,ing,jap);

	if(mat == 100 || ing == 100 || jap == 100) cout <<  "A";
	else if((mat + ing)/2 >= 90)	cout << "A";
	else if(mid >= 80)	cout <<  "A";
	else if(mid	>= 70)	cout <<  "B";
	else if(mid >= 50 && (mat >= 80 || ing >= 80))	cout <<  "B";
	else	cout << "C";
}

int main(){
	int n,pm,pe,pj;
	char cla;

	while(cin >> n,n){
		for(int i=0;i<n;i++){
			cin >> pm >> pe >> pj;
			classes(pm,pe,pj);
			cout << endl;
		}
	}

	return 0;
}

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

using namespace std;

#define first ff
#define second ss

typedef long long ll;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

ll bin_pow(ll x, ll k) {
    if (k == 0) {
        return 1;
    }
    if (k % 2 == 0) {
        ll res = bin_pow(x, k / 2);
        return (res * res) % MOD;
    } else {
        return (bin_pow(x, k - 1) * x) % MOD;
    }
}

ll C(ll n, ll k) {
    ll res = 1;
    for (ll i = 1; i <= k; i++) {
        res = ((res * (n - k + i)) % MOD * bin_pow(i, MOD - 2)) % MOD;
    }
    return res;
}

int main() {
#ifdef LOCAL
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#else
    // freopen("levenshtein.in", "r", stdin);
    // freopen("levenshtein.out", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n, a, b;

    cin >> n >> a >> b;

    ll sum = (bin_pow(2, n) - 1 + MOD) % MOD;

    //cout << sum << "\n";

    //cout << C(n, a) << "\n";

    sum = (sum - C(n, a) + MOD) % MOD;
    sum = (sum - C(n, b) + MOD) % MOD;

    cout << sum;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 99999
#define NIL -1

struct Node{
  int parent,left,right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];//D:深さ,H:高さ。

void setDepth(int u,int d){
  if(u == NIL)
    return;
  D[u] = d;
  if(T[u].right != NIL)
    setDepth(T[u].right, d + 1);
  if(T[u].left != NIL)
    setDepth(T[u].left, d + 1);
}

int setHeight(int u){
  int h1 = 0,h2 = 0;
  if(T[u].right != NIL)
    h1 = setHeight(T[u].right) + 1;
  if(T[u].left != NIL)
    h2 = setHeight(T[u].left)+1;
  if(h1 > h2)
    return H[u] = h1;
  else
    return H[u] = h2;
}

int getSibling(int u){//uの兄弟を返す関数
  if(T[u].parent == NIL)
    return NIL;
  else if(T[T[u].parent].left == NIL || T[T[u].parent].right == NIL)
    return NIL;
  else if(T[T[u].parent].left == u)
    return T[T[u].parent].right;//再帰的に呼び出している
  else
    return T[T[u].parent].left;
}

void print(int u){
  int deg = 0;
  printf("node %d: ",u);
  printf("parent = %d, sibling = %d, ",T[u].parent, getSibling(u));
  if(T[u].left != NIL)
    deg++;
  if(T[u].right != NIL)
    deg++;
  printf("degree = %d, depth = %d, height = %d,",deg, D[u], H[u]);
  
  if (D[u] == 0) printf(" root\n");
  else if
    (H[u] == 0) printf(" leaf\n");
  else
    printf(" internal node\n");
}

int main(){
  int i,j;
  int v,l,r;
  int root;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++)
    T[i].parent = NIL;
  
  for(i = 0; i < n; i++){
    scanf("%d %d %d",&v,&r,&l);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL)
      T[l].parent = v;
    if(r != NIL)
      T[r].parent = v;
  }
  for(i = 0; i < n; i++){
    if(T[i].parent == NIL)
      root = i;
  }

    setDepth(root,0);
    setHeight(root);

    for(i = 0; i < n; i++)
      print(i);
    
  return 0;
}

    
  
  
  




Measured memory_bytes: 2124
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<i32> = (0..n).map(|_| read()).collect();
    let b: Vec<i32> = (0..n).map(|_| read()).collect();
    let c: Vec<i32> = (0..n - 1).map(|_| read()).collect();

    let mut prev_menu_number = a[0];
    let mut sum = 0;

    for &a_i in a.iter() {
        if prev_menu_number + 1 == a_i {
            sum += c[prev_menu_number as usize - 1];
        }
        sum += b[a_i as usize - 1];
        prev_menu_number = a_i;
    }

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
/*
* @Author: Samson
* @Date:   2018-06-12 18:24:44
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-13 12:00:47
*/
//   @URL : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_A
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define white 0
#define gray 1
#define black 2
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e3+10;

int p[MAXN],color[MAXN],a[MAXN][MAXN],t,n,d[MAXN];

int prim()
{
	int minv,u,v;
	for(int i = 1; i <= n; ++i)
	{
		d[i] = INF;
		p[i] = -1;
		color[i] = white;
	}
	
	d[1] = 0;

	while(1)
	{
		minv = INF;
		u = -1;
		for(int i = 1; i <= n; ++i)
		{
			if(minv > d[i] && color[i] != black)
				minv = d[i],u = i;
		}
		if(u == -1)	break;
		color[u] = black;
		for(int v = 1; v <= n; ++v)
		{
			if(color[v] != black && a[u][v] != INF)
			{
				if(d[v] > a[u][v])
				{
					d[v] = a[u][v];
					p[v] = u;
					color[v] = gray;
				}
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i)
		if(p[i] != -1)
			ans += a[i][p[i]];
	return ans;
}

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	cin>>n;
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= n; ++j)
		{
			cin>>t;
			a[i][j] = t==-1?INF:t;
		}
	}
	cout<<prim()<<'\n';
	return 0;
}


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

vector<bool> visited;
vector<vector<int>> g;
vector<pair<int,int>> pi;
vector<pair<pair<int,int>,int>> px;
vector<pair<pair<int,int>,int>> py;
int ans=0;
int n,w,h;
int wall;
int wallcnt[]={0,0,0,0};
int colsize;

bool dfsended(){
    for (auto i:visited)if(!i)return false;
    return true;
}

int dfs(int sid){
    visited[sid]=true;
    ++colsize;
    if(pi[sid].first==1)wall=0;
    if(pi[sid].second==1)wall=1;
    if(pi[sid].first==w)wall=2;
    if(pi[sid].second==h)wall=3;

    for(auto i:g[sid]){
        if(!visited[i])dfs(i);
    }

}

int main() {
    cin>>n>>w>>h;
    for (int i = 0; i < n; ++i) {
        int x,y;
        cin>>x>>y;
        pi.emplace_back(x,y);
        px.emplace_back(make_pair(make_pair(x,y),i));
        py.emplace_back(make_pair(make_pair(y,x),i));
    }
    sort(px.begin(),px.end());
    sort(py.begin(),py.end());

    g=vector<vector<int>>(n);
    for (int i = 0; i < n-1; ++i) {
        if(px[i].first.first==px[i+1].first.first){
            g[px[i].second].emplace_back(px[i+1].second);
            g[px[i+1].second].emplace_back(px[i].second);
        }
    }
    for (int i = 0; i < n-1; ++i) {
        if(py[i].first.first==py[i+1].first.first){
            g[py[i].second].emplace_back(py[i+1].second);
            g[py[i+1].second].emplace_back(py[i].second);
        }
    }

    visited=vector<bool>(n,false);

    int colcnt=0;
    while(!dfsended()){
        int sid;
        for (int i = 0; i < n; ++i) {
            if(!visited[i]){
                sid=i;
                break;
            }
        }
        wall=-1;
        colsize=0;
        dfs(sid);
        ans+=colsize-1;
        if(wall!=-1)++wallcnt[wall];
        ++colcnt;
    }
    if (colcnt == 1) {
        if(wall!=-1)++ans;
    }
    else {
        ans += colcnt + (colcnt - 1);
    }
    int t=0;
    for (int i = 0; i < 4; ++i) {
        t=max(t,wallcnt[i]);
    }
    ans-=t;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5668
A, B = map(int, input().split())
A1 = A/0.08
A2 = (A+1)/0.08
B1 = B/0.1
B2 = (B+1)/0.1
C = 0
for i in range(1001):
  if A1 <= i < A2 and B1 <= i < B2:
    print(i)
    C = 1
    break
if C == 0:
  print(-1)


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

using namespace std;

int main(){
    int k, s, cnt = 0;
    cin >> k >> s;
    for(int i = 0; i <= k; ++i){
        for(int j = 0; j <= k; ++j)
            if(s - i - j >= 0 && s - i - j <= k)cnt++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int a,b;
    cin >> a >> b;

    cout << max(0, a - 2 * b) << endl;
    return 0;
}


Measured memory_bytes: 256
//Code by ASIM FOIZE AIMON
//CSE'19;CUET
//avoid copy paste//Hit the frined button
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define endl "\n"
#define int int64_t
#define ll long long
#define yes printf("Yes\n")
#define no printf("No")
int32_t main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/input.txt", "r", stdin);
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/output.txt", "w", stdout);
    #endif*/
    int x;
    cin>>x;
    if(x<30)
        no;
    else
        yes;
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    int N;
    cin >> N;

    vector<int> p(N, 0);
    REPinit(i, 0, N) cin >> p[i];

    sort(CONTAINER_ALL(p));

    ll ans = 0;
    REPinit(i, 0, N - 1) ans += p[i];

    cout << (ans + (int)(p.back() / 2)) << endl;
    
    return 0;
}


Measured memory_bytes: 3540
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var a = int.Parse(input[0].ToString());
            var b = int.Parse(input[1].ToString());
            var c = int.Parse(input[2].ToString());
            var d = int.Parse(input[3].ToString());

            for(int i = 0; i < 8; i++)
            {
                var now = a;
                var op1 = "";
                var op2 = "";
                var op3 = "";

                if((i & 1) == 1)
                {
                    now += b;
                    op1 = "+";
                }
                else
                {
                    now -= b;
                    op1 = "-";
                }

                if ((i >> 1 & 1) == 1)
                {
                    now += c;
                    op2 = "+";
                }
                else
                {
                    now -= c;
                    op2 = "-";
                }

                if ((i >> 2 & 1) == 1)
                {
                    now += d;
                    op3 = "+";
                }
                else
                {
                    now -= d;
                    op3 = "-";
                }

                if(now == 7)
                {
                    Console.WriteLine("{0}{4}{1}{5}{2}{6}{3}=7", a, b, c, d,op1,op2,op3);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 27456
#include <stdio.h>

#define N 100000
#define TYPE {"root", "internal node", "leaf"}

typedef struct{
  int parent;
  int leftChild;
  int rightSbling;
} Node;

void printNode(Node *, int);
void printChild(Node *, int);
int nodeDepth(Node *, int);

int main() {
  int n, id, k, c, left;
  int i, j;
  Node node[N];

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
     node[i].parent = -1;
     node[i].leftChild = -1;
     node[i].rightSbling = -1;
  }

  for (i = 0; i < n; i++) {
    scanf("%d %d", &id, &k);
    
    for (j = 0; j < k; j++) {
      
      scanf("%d", &c);
      node[c].parent = id;
      
      if (j == 0) {
	node[id].leftChild = c;
	left = c;
	continue;
      }
      
      node[left].rightSbling = c;
      left = c;
    }
  }

  for (i = 0; i < n; i++) {
    printNode(node, i);
  }
  
  return 0;
}

void printNode(Node *node, int id){
  int t;
  char *type[] = TYPE;
  
  printf("node %d: ", id);
  printf("parent = %d, ", node[id].parent);
  printf("depth = %d, " ,nodeDepth(node, id));
  
  if (node[id].parent == -1) t = 0;
  else if (node[id].leftChild != -1) t = 1;
  else t = 2;
  printf("%s, [", type[t]);

  if (t != 2) {
    printChild(node, id);
  }
  
  printf("]\n");
}

void printChild(Node *node, int id){
  int c = node[id].leftChild;

  if (c == -1) {
    return;
  }
  
  printf("%d", c);
  
  while (node[c].rightSbling != -1) {
    printf(", %d", node[c].rightSbling);
    c = node[c].rightSbling;
  }
}

int nodeDepth(Node *node, int id){
  int cnt = 0;
  
  while(node[id].parent != -1){
    cnt++;
    id = node[id].parent;
  }
  return cnt;
}



Measured memory_bytes: 2872
#include<bits/stdc++.h>
#define rep(i,n) 				for(int i=0; i<(n); ++i)
#define all(c) 				(c).begin(),(c).end()
#define sortall(x)                 sort(all(x))
#define tr(c,i) 				for( typeof( (c).begin() ) i = (c).begin();  i != (c).end(); ++i)
#define pb 					push_back
#define sz(a) 					int((a).size())
#define mp                         make_pair
#define ll                         long long
#define F                          first
#define S                          second
#define PI                         3.1415926535897932384626
// Input macros
#define s(n)                       scanf("%d",&n)
#define sc(n)                      scanf("%c",&n)
#define sl(n)                      scanf("%lld",&n)
#define sf(n)                      scanf("%lf",&n)
#define ss(n)                      scanf("%s",n)

// Others
#define test(t) 				int t; cin>>t; while(t--)
#define endl 					"\n"

using namespace std;

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

const int mod = 1000000007;
const int INF = 1e9+5;

int main(){
     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

     int n, w;
     s(n);
     s(w);
     
     vector<ll> dp (w+2,0);
     
     // dp[i] = max value you can get when you have weight limit equal to i
     
     for(int item=0 ; item<n ; item++){
		 int item_val, item_wei;
		 scanf("%d %d", &item_wei, &item_val);
		 
		 vector<ll> dp_new(w+2,0);
		 
		 for( int j=0 ; j<=w ; j++){
			if( item_wei <= j){
				// option 1 : select it
				// option 2 : do not select it
				// select the max of these options
				dp_new[j] = max( dp[j-item_wei] + item_val, dp[j] );
			}else{
				dp_new[j] = dp[j]; 
			}
		}  
		
		dp = dp_new;
	
	}
     
     printf("%lld\n",dp[w]);
     

     return 0;

}
	







Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

string s,t;
cin >> s >> t;
s += s;
vvi mp(26);
rep(i,SZ(s)) {
    mp[s[i]-'a'].push_back(i);
}

// tにあってsにない文字があるとtを作ることはできない
rep(i,SZ(t)) {
    if(!SZ(mp[t[i]-'a'])) {
        cout << -1 << endl;
        return 0;
    }
}


ll cur = 0;
ll ans = 0;
rep(i,SZ(t)) {
    ll iter = lower_bound(mp[t[i]-'a'].begin(), mp[t[i]-'a'].end(), cur) - mp[t[i]-'a'].begin();
    ll idx = mp[t[i]-'a'][iter];
    ans += idx - cur + 1;
    if(idx >= SZ(s)/2) idx -= SZ(s)/2;
    cur = idx+1;
}
cout << ans << endl;
return 0;
}

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

int main(){
    int N,M; cin>>N>>M;
    vector<pair<int,int> >v(N);
    long long res=0,ans=0;
    for(int i=0;i<M;i++){
        string S;
        int p; cin>>p>>S; p--;
        if(v[p].first==1)continue;
        else{
            if(S=="WA"){
                v[p].second+=1;
            }
            else v[p].first=1;
        }
    }

    

    for(int i=0;i<N;i++){
        if(v[i].first==1){
        res+=v[i].first;
        ans+=v[i].second;
        }
    }
    cout<<res<<" "<<ans<<endl;



    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[111111];
vector<int> ii;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h,j;
  string s;
  cin >>a;
  for(int n=0;n<a;n++) cin >>b,i[b]++;
  for(int n=1;n<100000;n++){
    e=i[n-1]+i[n]+i[n+1];
    d=max(e,d);
  }
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 640
#x,y = map(lambda x: int(x), input().split())
#list = list(map(lambda x: int(x), input().split()))


n,k = map(lambda x: int(x), input().split())
p_lst = list(map(lambda x: int(x), input().split()))


def cum_sum(list):
    result = []
    for i in range(len(list)):
        if i == 0:
            result.append(list[i])
        else:
            result.append(result[i-1] + list[i])
    return result


def cum_sum_exp(list):
    result = []
    for i in range(len(list)):
        if i == 0:
            result.append((list[i]+1)/2)
        else:
            result.append(result[i-1] + (list[i]+1)/2)
    return result



cum_sum_main = cum_sum_exp(p_lst)


cmp = cum_sum_main[k-1]


for i in range(k-1,n):
    if i == k-1:
        cmp = cum_sum_main[i]
    else:
        tmp = cum_sum_main[i] - cum_sum_main[i-k]

        if cmp < tmp:
            cmp = tmp



print(cmp)



Measured memory_bytes: 25052
#include<stdio.h>
#define MAX_N 150
typedef struct {
	int a;
	int b;
	int w;
} hen;

int par[MAX_N];
int rank[MAX_N];
int n,m;
hen dis[20000];

void init(int n){
	int i;
	for(i=0;i<n;i++){
		par[i] = i;
		rank[i] = 0;
	}
}
int find(int x){
	if(par[x]==x){
		return x;
	}else {
		return par[x] = find(par[x]);
	}
}
void unite(int x,int y){
	x =find(x);
	y =find(y);
	if(x==y){
		return ;
	}
	if(rank[x] < rank[y]){
		par[x] = y;
	}else {
		par[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}
int same(int x,int y){
	return find(x)==find(y);
}
int  judge(hen *a,hen *b){
	return (a->w)-(b->w);
}

int Kruskal(int start){
	int ans=0;
	int i,j,k;
	int max=0;
	int min = dis[start].w;
	init(110);
	for(i=start;i<m;i++){
		hen h = dis[i];
		if(!same(h.a,h.b)){
			unite(h.a,h.b);
			ans += h.w;
			if(max<h.w){
				max = h.w;
			}
		}
	}
	for(i=1;i<n+1;i++){
	//	printf("%d ",find(i));
		if(!same(1,i)){
			return -1;
		}
	}
//	return ans;
	return max-min ;
}
int main(){
	int i,j,k;
	int ans=10e8;
	int buf=0;
	while(scanf("%d %d",&n,&m)){
		if(n==0&&m==0){
			break;
		}
		for(i=0;i<m;i++){
			scanf("%d %d %d",&dis[i].a,&dis[i].b,&dis[i].w);
		}
		ans=10e8;
		qsort(dis,m,sizeof(hen),judge);
		for(i=0;i<m;i++){
			buf = Kruskal(i);
			if(buf!=-1&&buf<ans){
				ans =buf;
			}
		}
		if(ans==10e8){
			printf("%d\n",-1);
		}else {
			printf("%d\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=5e5+5;
int main(){
	char s[10];
	cin>>(s+1);
	if(s[3]==s[4]&&s[5]==s[6])printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    x = list(map(int, input().split()))
    m = 10**10
    for i in range(n - k + 1):
        m = min(m, abs(x[i + k - 1] - x[i]) + abs(x[i]))
        m = min(m, abs(x[i + k - 1] - x[i]) + abs(x[i + k - 1]))
    print(m)

if __name__ == "__main__":
    main()

Measured memory_bytes: 23116
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
 
using namespace std;
 
#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define REP1(i,n) for(int (i)=(1);(i)<(n);++i)
#define ll long long

int main()
{
    int a,b,n,ans;
    cin >> n >> a >> b;

    if(a*n>b)ans=b;
    else ans=a*n;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
	int R[MAX], n;
	
	cin >> n;
	for( int i = 0; i < n; i++ ) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for( int i = 1; i < n; i++ ) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 3860
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{

    int i, j;
    int pasta[3], juice[2];
    int sum = 0, min = 9999;
    
    for (i = 0; i < 3; i++) {
        scanf("%d", &pasta[i]);
    }
    
    for (i = 0; i < 2; i++) {
        scanf("%d", &juice[i]);
    }
    
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 2; j++) {
            sum = pasta[i] + juice[j] - 50;
            if (sum < min) {
                min = sum;
            }
        }
    }
    
    printf("%d\n", min);
    
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;

int tab[200010];
int pref[2][200010];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; i++)
	{
		pref[0][i] = pref[0][i - 1];
		pref[1][i] = pref[1][i - 1];
		char ta;
		cin >> ta;
		if (ta == '.')
			++pref[0][i];
		else
			++pref[1][i];
	}
	int ans = INF;
	//batas putih
	for (int i = 0 ; i <= n ; i++)
	{
		int PutihKanan = pref[0][n] - pref[0][i];
		int HitamKiri = pref[1][i];
		int cnt = PutihKanan + HitamKiri;
		ans = min(ans,cnt);
	}
	cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    string ans = "Yes";
    for(int i = 0; i < s.length(); i++){
        if(i % 2 == 0){
            if(!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) ans = "No";
        }else{
            if(!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<sstream>
#include<iterator>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef pair<int,int> P;

string TF(string s)
{
  transform(s.begin(),s.end(),s.begin(),::toupper);
  rep(i,s.size())
    if(!('A' <= s[i] && s[i] <= 'Z'))s[i] = ' ';
  stringstream ss;
  ss << s;
  string ret;
  while(!(ss >> s).fail())
    ret += s;

  return ret;
}

bool cmp(const string &a,const string &b)
{
  return a.size() > b.size();
}

bool isPalind(string s)
{
  string rs = string(s.rbegin(),s.rend());
  return rs == s;
}

int main()
{
  string line;
  while(getline(cin,line))
    {
      line = TF(line);
      set<string> palim;
      int Size = line.size();
      rep(i,Size)
	{
	  REP(j,i+2,Size)
	    {
	      if(line[i] != line[j])continue;
	      string s = line.substr(i,j-i+1);
	      if(isPalind(s))
		palim.insert(s);
	    }
	}


      vector<string> vec;
      for(set<string>::iterator it = palim.begin();it != palim.end();it++)
	vec.push_back(*it);
      sort(vec.begin(),vec.end(),cmp);
      int vsize = vec.size();
      bool used[vsize];
      rep(i,vsize)used[i] = false;
      rep(i,vsize)
	{
	  if(used[i])continue;
	  bool flag = vec[i].size()%2;
	  REP(j,i+1,vsize)
	    {
	      bool flag2 = vec[j].size()%2;
	      if(flag^flag2)continue;
	      int pos = vec[i].size()/2 - (vec[j].size()/2);
	      if(vec[i].substr(pos,vec[j].size()) == vec[j])
		{
		  used[j] = true;
		}
	    }
	}

      bool f = true;
      rep(i,vsize)
	{
	  if(used[i])continue;
	  if(!f)cout << ' ';
	  f = false;
	    
	  cout <<  vec[i];
	}
      cout << endl;



    }
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define le 1003
using namespace std;
int dp[le][le];
char ch[le][le];
int mod = 1000000007;
int fnc(int a, int b, int r, int c){
    if(!(a >= 0 && a < r && b >= 0 && b < c && ch[a][b] != '#')) return 0;
    if(a == r - 1 && b == c - 1) return 1;
    if(dp[a][b] != -1) return dp[a][b];
    int ans = fnc(a + 1, b, r, c);
    int nas = fnc(a, b + 1, r, c);
    return dp[a][b] = ((ans % mod) + (nas % mod)) % mod;
}
int main(){
    //freopen("input.txt", "r", stdin);
    int r, c;
    string s;
    cin >> r >> c;
    for(int i = 0; i < r; i++){
        cin >> s;
        for(int j = 0; j < s.size(); j++) ch[i][j] = s[j], dp[i][j] = -1;
    }
    cout << fnc(0, 0, r, c) << endl;
    return 0;
}


Measured memory_bytes: 8628
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
typedef pair<int,int> P;
int ceil(int a,int b){// a以上でbの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}

int R,C;
int sy,sx;
int gy,gx;
string c[51];
void solve(){
	queue<P> qp;
	qp.push({sy,sx});
}
int dp[110][10010];
int main(){
	while(1){
		int x,y,s;
		cin>>x>>y>>s;
		if(x==0 && y==0 && s==0) break;
		int max=0;
		int na,nb;
		for(int i=1;i<s;i++){
			for(int j=1;j<s;j++){
				if(i*(100+x)/100+j*(100+x)/100==s){
					if(i*(100+y)/100+j*(100+y)/100>max) {
							max=i*(100+y)/100+j*(100+y)/100;
							na=i;
							nb=j;					
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}	


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

int main(){
  int N,M;cin >> N >> M;
  vector<long long> A(N);
  bool b=0;
  long long B=1;
  for(int i=0;i<N;i++){
    cin >> A[i];
    B*=A[i]/__gcd(A[i],B);
  }
  B/=2;
  int i=0;
  long long K=A[0];
  while(A[i]%2==0){
    A[i]/=2;
  	i++;
    i%=N;
  }
  if(i!=0||A[0]==K) b=1;
  for(int j=0;j<N;j++) if(A[j]%2!=1)b=1;
  if(B%2==0&&b) cout << 0 << endl;
  else cout << (M/B+1)/2 << endl;
}

Measured memory_bytes: 1152
a,b,c = map(int,input().split())
k=int(input())

for i in range(k):
    if a < b:
        if b < c:
            break
        else:
            c*=2
    else:
        b*=2

if a < b and b < c:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61652
#include <stdio.h>
#define M 500000
#define NIL -1

typedef struct node_tbl{
    int key,p,l,r;
}node;

node T[M+1];
int root=NIL;

void inorder(int u){
  if (u==NIL) return;
  inorder(T[u].l);
  printf(" %d", T[u].key);
  inorder(T[u].r);
}

void preorder(int u){
  if (u==NIL) return;
  printf(" %d", T[u].key);
  preorder(T[u].l);
  preorder(T[u].r);
}

void postorder(int u){
    if(u==NIL) return;
    postorder(T[u].l);
    postorder(T[u].r);
    printf(" %d",T[u].key);
}

int main(void){
    int n,i,k,l,r;
    scanf("%d",&n);
    
    for(i=0;i<n;i++) T[i].p=NIL;
    
    for(i=0;i<n;i++){
        scanf("%d %d %d",&k,&l,&r);
        T[k].l=l,T[k].r=r,T[k].key=k;
        if(l!=NIL) T[l].p=k;
        if(r!=NIL) T[r].p=k;
        
        //printf("%d %d %d %d\n",T[k].key,T[k].l,T[k].r,T[k].p);
    }
    
    for(i=0;i<n;i++){
        if(T[i].p==NIL){
            printf("Preorder\n");
            preorder(i);
            printf("\n");
            printf("Inorder\n");
            inorder(i);
            printf("\n");
            printf("Postorder\n");
            postorder(i);
            printf("\n");
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 2000