akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

void AOJ0005()
{
	long a, b;
	while (cin >> a)
	{
		cin >> b;
		long c = max(a,b);
		long d = min(a,b);
		while (c != d)
		{
			long e = c - d;
			c = max(d, e);
			d = min(d, e);
		}
		long f = a/c * b;
		cout << c << " " << f <<endl;
	}
}

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

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

int main(){
	int w, n, a, b;
	while(cin>>w){
		vector<pair<int, int> > all;
		cin>>n;
		for(int i=0; i<n; i++){
			scanf("%d,%d", &a, &b);
			all.push_back(pair<int, int>(a, b));
		}
		reverse(all.begin(), all.end());
		for(int i=1; i<=w; i++){
			int ima = i;
			for(int j=0; j<n; j++){
				if(all[j].first == ima) ima = all[j].second;
				else if(all[j].second == ima) ima = all[j].first;
			}
			cout<<ima<<endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
  ll a[6];
  ll c1=0,c2=0,c3=0,c4=0;
  for(ll i=0;i<6;i++){
     cin>>a[i];
     if(a[i]==1)
        c1++;
     else if(a[i]==2)
        c2++;
     else if(a[i]==3)
        c3++;
     else if(a[i]==4)
        c4++;
  }
  if(c1==1&&c2==2&&c3==2&&c4==1)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int main() {
  int n, l;
  cin >> n >> l;
  int ans = 0;
  rep(i, n) ans += (l+i);
  // cout << ans << endl;

  if(l > 0) {
    cout << ans - l << endl;
  } else if(l+n-1 < 0) {
    cout << ans - (l+n-1) << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int x;
bool pd(int k,int last)
{
	double t=k;
	if (k==1) return true;
	for (int i=2;i<=sqrt(t);i++)
	{
		if (k%i==0)
		{
			int t1=0;
			while (k%i==0&&k!=1)
			{
				k/=i;
				t1++;
			}
			if (k==1&&(t1==last||last==-1)) return true;
			else if (k==1&&t1!=last) return false;
			else if (t1!=last&&last!=-1) return false;
			else return pd(k,t1);
		}
	}
	return false;
}
int main()
{
	scanf("%d",&x);
	for (int i=x;i>=1;i--)
	{
		if (pd(i,-1))
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}

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

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

    ll ans=0;
    rep(i, n+1){
        if(i==0) continue;
        ans+=(n-1)/i;
    }

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

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;

int N;

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

int main()
{
    cin >> N;
    ll sum = 0;
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            for (int k = 1; k <= N; k++)
            {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;
    // system("pause");
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

int main(void) {

  int t;
  int n,h[150];
  int up_max,down_max;
  int i,j;
  char buf[600];
  char* p;

  scanf("%d",&t);

  for(i=0;i<t;i++) {

    scanf("%d",&n);
    getchar();

    fgets(buf,sizeof(buf),stdin);
    buf[strlen(buf)-1]='\0';

    p=strtok(buf," ");
    h[0]=atoi(p);
    for(j=0;j<n-1;j++) {
      p=strtok(NULL," ");
      h[j+1]=atoi(p);
    }
    
    up_max=down_max=0;

    for(j=0;j<n-1;j++) {
      if(up_max<(h[j+1]-h[j])) up_max=h[j+1]-h[j];
      if(down_max<(h[j]-h[j+1])) down_max=h[j]-h[j+1];
    }

    printf("%d %d\n",up_max,down_max);

  }

  return 0;

}
    

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
const int N = 3e5+15;
int e[N],w[N];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n; 
	cin>>n;
	for(int i=1;i<=n;i++){
		char c; 
		cin>>c; 
		if(c=='W')w[i]++;
		else e[i]++;
	}
	for(int i=1;i<=n;i++)w[i] += w[i-1];
	for(int i=n;i>=0;i--)e[i] += e[i+1];
	int ans = n+12;
	for(int i=1;i<=n;i++){
		ans =min(ans,w[i-1]+e[i+1]);
	}
	cout<<ans<<endl;
    return 0;
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

struct UnionFind{
    vector<int> par;
    int count;
    UnionFind(int n) : par(n, -1), count(0){}
    int Find(int x){return par[x] < 0 ? x : Find(par[x]);}
    int Size(int x){return par[x] < 0 ? -par[x] : Size(par[x]);}
    bool Unite(int x, int y){
        x = Find(x);
        y = Find(y);
        if(x == y)
            return false;
        if(par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return ++count;
    }
};



signed main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        edges[u].emplace_back(v);
    }
    int s, t;
    cin >> s >> t;
    --s, --t;
    priority_queue<tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>>> que;
    vector<vector<int>> dist(n, vector<int>(3, MOD));
    dist[s][0] = 0;
    que.emplace(0, s, 0);
    while(!que.empty()){
        int x, d, mo;
        tie(d, x, mo) = que.top();
        que.pop();
        if(dist[x][mo] != d)
            continue;
        for(auto ed : edges[x]){
            if(chmin(dist[ed][(mo + 1) % 3], d + 1))
                que.emplace(dist[ed][(mo + 1) % 3], ed, (mo + 1) % 3);
        }
    }
    cout << (dist[t][0] == MOD ? -1 : dist[t][0] / 3) << endl;
}

Measured memory_bytes: 14028
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
void vprint() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}
template <class T> void mprint(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << "";
        }
    }
}

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

    int N, X;
    cin >> N >> X;
    vector<int> a(N);
    for (auto &&i : a) {
        cin >> i;
    }
    ll ans = 0;
    FOR(i, 1, N) {
        ll sum = a[i] + a[i - 1];
        if (X < sum) {
            ll diff = sum - X;
            if (diff <= a[i]) {
                a[i] -= diff;
                ans += diff;
            } else {
                ans += a[i];
                diff -= a[i];
                a[i] = 0;
                ans += diff;
            }
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
#define MAXN 200000
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
struct E{int u,v,w; E(){} E(int _u, int _v, int _w){u=_u,v=_v,w=_w;}}; inline bool operator < (E a, E b){return a.w<b.w;}
int fa[MAXN+5], a[MAXN+5], n, c; long long Ans; vector<E> Ed; inline int getf(int x){return x^fa[x]?fa[x]=getf(fa[x]):x;}
inline bool Union(int x, int y){return (x=getf(x))^(y=getf(y))?fa[x]=y,true:false;}
int main()
{
	for(rint q = (n = read(), memset(a,0x3f,n<<2), read()), A, B, C; q--; Ed.push_back(E(A,B,C)))
		A = read(), B = read(), C = read(), a[B] = min(a[B],C+2), a[A] = min(a[A],C+1);
	for(rint i = 0; i < (n<<1); a[-~i%n] = min(a[-~i%n],a[i%n]+2), i++);
	for(rint i = 0; i < n; Ed.push_back(E(i,-~i%n,a[i])), fa[i] = i, i++); sort(Ed.begin(),Ed.end());
	c = n-1; for(auto _:Ed)if(Union(_.u,_.v)&&(Ans+=_.w,!--c))break; printf("%lld\n",Ans); return 0;
}

Measured memory_bytes: 9584
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        t: usize,
        mut v: [(usize, usize); n]
    }
    v.sort_by_key(|x| x.0);
    let mut dp = vec![0; t + 3001];
    for i in 0..n {
        let mut dp_next = dp.clone();
        for j in 0..t {
            dp_next[j + v[i].0] = max(dp_next[j + v[i].0], dp[j] + v[i].1);
        }
        dp = dp_next;
    }
    println!("{}", dp.iter().cloned().max().unwrap());
}


Measured memory_bytes: 4352
// https://atcoder.jp/contests/abc122/tasks/abc122_c

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <regex>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

vector<string> search(string const &text, regex const &re) {
    vector<string> result;

    auto iter = text.cbegin();
    auto end = text.cend();

    smatch m;

    while (regex_search(iter, end, m, re)) {
        result.push_back(m.str());
        iter = m[0].second;
    }

    return result;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int l[q], r[q];
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i];
    }

    regex re("AC");
    // n文字目から末尾までのAC出現回数
    int findAC[n];
    int cnt = 0;
    findAC[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            cnt++;
        }
        findAC[i] = cnt;
    }

    for (int i = 0; i < q; i++) {
        cout << findAC[l[i] - 1] - findAC[r[i] - 1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 2256
h,w=map(int, input().split())
a=[input() for _ in range(h)]
ta=[]
tb=[]
tc=[]
for x in a:
    j=False
    for y in x:
        if y=='#':
            j=True
    if j:
        ta.append(x)
for i in range(1,w+1):
    t=[ta[j][-i] for j in range(len(ta))]
    j=False
    for x in t:
        if x=='#':
            j=True
    if j:
        tb.append(t)
for i in range(len(tb[0])):
    t=[tb[-j][i] for j in range(1,len(tb)+1)]
    print("".join(t))

Measured memory_bytes: 3188
const fs = require('fs');

function main(input) {
  arr = input.split('\n');
  var a = parseInt(arr[0]);
  var b = parseInt(arr[1]);
  var c = parseInt(arr[2]);
  var x = parseInt(arr[3]) / 50;

  var tot;
  var cnt = 0;
  for (var i = 0; i <= a; i++) {
    for (var j = 0; j <=  b; j++) {
      for (var k = 0; k <= c; k++) {
        tot = 10*i + 2*j + k;
        if (tot === x) {
          cnt++
        }
      }
    }
  }
  console.log(cnt)
}

input = fs.readFileSync('/dev/stdin', 'utf8');
main(input);

Measured memory_bytes: 7372
from collections import deque
h,w=map(int,input().split())
a=[[] for _ in range(h)]
for i in range(h):
    s=input()
    for j in s:
        if j=='.':
            a[i].append(-1)
        else:
            a[i].append(0)

def bfs():
    d=[[0,1],[1,0],[-1,0],[0,-1]]
    q=deque()
    c=0
    for i in range(h):
        for j in range(w):
            if a[i][j]==0:
                q.append((i,j))
    while(len(q)>0):
        cur=q.popleft()
        i,j=cur
        for dd in d:
            di,dj=dd[0],dd[1]
            if (i+di)*(h-1-i-di)>=0 and (j+dj)*(w-1-j-dj)>=0 and a[i+di][j+dj]<0:
                c=a[i][j]+1
                a[i+di][j+dj]=c
                q.append((i+di,j+dj))
    return(c)

print(bfs())

Measured memory_bytes: 86016
from itertools import *
n,*s=open(0).read().split()
u=[[min(accumulate(chain([0],t),lambda a,b: a+(1 if b=="(" else -1))),2*t.count("(")-len(t)] for t in s]
m=0
for c,d in chain(sorted([x for x in u if x[1]>=0])[::-1],sorted([x for x in u if x[1]<0],key=lambda z:z[0]-z[1])):
    if m+c<0:print("No");break
    m+=d
else:print("No" if m else "Yes")

Measured memory_bytes: 119404
#include <cstdio>
#include <algorithm>
using namespace std;

const int N_MAX = 100000;

int N;
int L[] = {
  1,
  6,
  36,
  216,
  1296,
  7776,
  46656,
  9,
  81,
  729,
  6561,
  59049
};
int memo[N_MAX];

void solve() {
  for (int i = 1; i <= N; i++) {
    memo[i] = N_MAX;
    for (int j = 0; j < 12; j++) {
      if (L[j] > i) continue;
      if (L[j] == i) {
        memo[i] = 1;
        break;
      }
      int x = memo[i - L[j]] + 1;
      memo[i] = min(x, memo[i]);
    }
  }
  printf("%d\n", memo[N]);
}

int main() {
  scanf("%d", &N);

  solve();
}


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

int main() {
  int64_t N, kabu, money, allkabu;
  kabu = 0;
  allkabu = 0;
  money = 1000;
  cin >> N;
  
  vector<int64_t> vec(N);
  
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  for(int j = 0; j < N-1; j++){
    if(vec.at(j) < vec.at(j+1)){
      kabu = money/vec.at(j);
      allkabu += kabu;
      money = money - kabu*vec.at(j);
    }
    else{
      money = money + allkabu*vec.at(j);
      allkabu = 0;
    }
    kabu = 0;
  }
  if(allkabu!=0) money += allkabu*vec.at(N-1);
  cout << money;
  
}

Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#define MAX 550
#define INF (1e100)

int n;
double p[MAX], q[MAX];
int temp[MAX][MAX];
double temp2[MAX][MAX], temp3[MAX][MAX];

// double fuga(int a, int b, int count){
	// if(a>b)return 0;
	// double ans = count*p[temp[a][b]];
	// ans += fuga(a,temp[a][b]-1,count+1);
	// ans += fuga(temp[a][b]+1,b,count+1);
	// if(a == temp[a][b]) ans += q[a-1]*(count+1);
	// if(b == temp[a][b]) ans += q[b]*(count+1);
	
	// return ans;
// }
double fuga(int a, int b, int count){
	if(a>b)return 0;
	double ans = p[temp[a][b]];
	temp3[a][b] = 0;
	if(a <= temp[a][b]-1)ans += temp2[a][temp[a][b]-1]+temp3[a][temp[a][b]-1];
	if(temp[a][b]+1 <= b)ans += temp2[temp[a][b]+1][b]+temp3[temp[a][b]+1][b];
	temp3[a][b] = temp3[a][temp[a][b]-1] + temp3[temp[a][b]+1][b] + p[temp[a][b]];
	if(a==temp[a][b]) {temp3[a][b] += q[a-1]; ans += q[a-1]*2;}
	if(b==temp[a][b]) {temp3[a][b] += q[b];   ans += q[b]*2;}
	return ans;
}

void hoge(int a, int b){
	double t, mi = INF;
	int ti = a;

	for(int i = a; i <= b; i++){
		temp[a][b] = i;
		if((t = fuga(a,b,1)) < mi){
			mi = t;
			ti = i;
		}
	}
	temp[a][b] = ti;
	temp2[a][b] = fuga(a,b,1);
	// temp2[a][b] = mi;
}

double solve(){
	
	for(int i = 1; i < n; i++){
		for(int j = 1; j+i <= n; j++){
			hoge(j,j+i);
		}
	}
}

void print(){
	for(int i = 1; i <= n; i++){
		// for(int j = 1; j < i; j++){
			// cout<<"\t\t";
		// }
		for(int j = 1; j <= n; j++){
			// cout<<fuga(i,j,1)<<"\t\t";
			// cout<<temp[i][j]<<" "<<fuga(i,j,1)<<"\t\t";
			cout<<temp[i][j]<<" "<<temp2[i][j]<<"\t\t";
		}
		cout<<endl;
	}
}

int main(){
	cout<<fixed<<setprecision(5);
	cin>>n;
	
	for(int i = 1; i <= n; i++){
		cin>>p[i];
		temp[i][i] = i;
		temp3[i][i] = p[i];
		temp2[i][i] = p[i];
	}
	for(int i = 0; i <= n; i++){
		cin>>q[i];
		temp2[i][i] += q[i]*2;
		temp2[i+1][i+1] += q[i]*2;
		temp3[i][i] += q[i];
		temp3[i+1][i+1] += q[i];
	}
	solve();
	// print();
	cout<<fuga(1,n,1)<<endl;
	
	return 0;
}


Measured memory_bytes: 8640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

vector<vector<int>> G;
int dfs(int v) {
	int res = 0;
	multiset<int, greater<int>> dic;
	for (auto nv : G[v]) {
		dic.emplace(dfs(nv));
	}
	int k = 0;
	for (auto i : dic) {
		k++;
		chmax(res,i+k);
	}
	return res;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	G.resize(N);
	rep(i,N-1) {
		int a; cin >> a;
		a--;
		G[a].emplace_back(i+1);
	}

	cout << dfs(0) << endl;
}

Measured memory_bytes: 13568
#include<stdio.h>
    int main(void){
    int a,i,j,n,m,tri[3]={0};
    scanf("%d",&a);
    for(n=0;n<a;n++){
        scanf("%d %d %d",&tri[0],&tri[1],&tri[2]);
    for(i=0;i<2;i++){
        for(j=i+1;j<3;j++){
            if(tri[i]<tri[j]){
            m=tri[i];
            tri[i]=tri[j];
            tri[j]=m;
            }
        }
    }
    if(tri[0]*tri[0]==tri[1]*tri[1]+tri[2]*tri[2]){
        printf("YES\n");
    }else{
            printf("NO\n");
            }
    }
    return 0;
}

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

using lint = long long;
constexpr lint INF = 1LL << 30;

void solve() {
    int n;
    lint k;
    std::cin >> n >> k;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    lint ok = 0, ng = INF;
    // you need to cut more than k times to make minimum ok
    while (ng - ok > 1) {
        lint mid = (ok + ng) / 2;

        lint cnt = 0;
        for (auto x : xs) {
            cnt += (x + mid - 1) / mid - 1;
        }

        if (cnt > k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    std::cout << ng << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 4704
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 


#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

int main() {
    
    fastio;
    int n;
    cin >> n;
    int d[n];
    rep(i, n)
    cin >> d[i];
    sort(d, d+n);
    int a = d[n/2-1];
    int b = d[n/2];
    cout << b-a;
    return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int n=0;
	ll al = 0, bu = 0;
	cin >> n;
	int p[100];
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
	}
	sort(p, p+n, greater<int>());
	for (int i = 0; i < n; i++)
	{
		if(i%2==0)
		al += p[i];
		else
		bu += p[i];
	}
	
	cout << al-bu;
}





Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

// ユークリッドの互除法
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 main(){
    ll k; cin >> k;
    ll sum = 0;

    rep2(a,1,k+1){
        rep2(b,1,k+1){
            ll x = gcd(a,b);
            rep2(c,1,k+1){
                ll y = gcd(x,c);
                sum += y;
            }
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3644
/*
BY: SAFWAAN SHAIKH
PROBLEM:
KEY IDEAS: 
TIME COMPLEXITY: 
*/

#define r(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#include <cmath>
#include <fstream>
#define f first
#define endl "\n"
#define s second
#define pb push_back
#define ms(a,b) memset(a,b,sizeof(a))
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
char _;

int main(){
//	freopen("problemname.in", "r", stdin);
//  freopen("problemname.out", "w", stdout);
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a;
	cin>>a;
	int c=0;
	int ans=0;
	for(int i=0;i<a.size();i++){
		if(a[i]=='R')c++;
		else c=0;
		ans=max(c,ans);
	}	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxM = 2e5+7;
const int maxV = 90010;

const int MOD = 1e9+7;

int T;
const int maxN = 2e5+8;
const ll INF = 1000000000000000010LL;
const int K = 15;
int n;
int a[maxN];
int b[maxN];
int c[maxN];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	b[1] = a[1];
	for(int i=2;i<=n;i++)
	{
		b[i] = max(b[i-1],a[i]);
	}
	c[n] = a[n];
	for(int i=n-1;i>=1;i--)
	{
		c[i] = max(c[i+1],a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		int L = 0,R = 0;
		if(i-1>=1)
			L = b[i-1];
		if(R+1<=n)
			R = c[i+1];
		int ans = max(L,R);
		cout<<ans<<endl;
	}
    return 0;
}


Measured memory_bytes: 3968
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var N int
	fmt.Scan(&N)
	var total int64
	for i := 1; i < (N + 1); i++ {
		if (i % 15) == 0 {
		} else if (i % 5) == 0 {
		} else if (i % 3) == 0 {
		} else {
			total += int64(i)
		}
	}
	fmt.Println(total)
}

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

int main(){
    LL N;
    cin >> N;
    vector<LL> a(0), b(0);
    for(LL i = 9;i <= N;i*=9)    a.emplace_back(i);
    for(LL i = 1;i <= N;i*=6)    b.emplace_back(i);
    LL ans = 100000;
    for(LL i = 0;i <= N;i+=9){
        LL sum = 0;
        LL c = i;
        for(LL j = a.size()-1;c > 0;j--){
            while(a[j] <= c){
                sum++;
                c -= a[j];
            }
        }
        LL d = N-i;
        for(LL j = b.size()-1;d > 0;j--){
            while(b[j] <= d){
                sum++;
                d -= b[j];
            }
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

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

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    cout << N * X - max(0, N - K) * (X - Y) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,b,f,r,v,i,m[4][3][10],g,h;

  scanf("%d",&n);

  for(b=0;b<4;b++){
    for(f=0;f<3;f++){
      for(r=0;r<10;r++){
	m[b][f][r]=0;
      }
    }
  }

  
  

  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    m[b-1][f-1][r-1]=m[b-1][f-1][r-1]+v;
  }
  for(b=0;b<4;b++){
    for(f=0;f<3;f++){
      for(r=0;r<10;r++){
	printf(" %d",m[b][f][r]);
      }
      printf("\n");
    }
    if(b!=3){
      printf("####################\n");
    }
  }
}
    




Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 402

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
ll n;
ll a[N];
ll pre[N]={0};
ll solve(ll l,ll r)
{
	return pre[r]-pre[l-1];
}
ll dp[N][N];
ll go(ll l,ll r)
{
	if(l>r)
		return hell;
	if(l==r)
		return 0;
	if(l==(r-1))
		return a[l]+a[r];
	if(dp[l][r]!=-1)
		return dp[l][r];
	//test2(l,r);
	ll ans=LLONG_MAX;
	rep(i,l,r)
	{
		ll left=go(l,i);
		ll right=go(i+1,r);
		ans=min(ans,left+right+ (solve(l,i)+solve(i+1,r)));
	}
	return dp[l][r]=ans;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
        
	cin>>n;
	rep(i,1,n+1)
	{
		cin>>a[i];
		pre[i]=pre[i-1]+a[i];
	}
	memset(dp,-1,sizeof(dp));
	ll ans=go(1,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int isSpy(vector<int> &v, vector<int> &L) {
 int cnt = 0;
  for(int a : v) for(int b : L) if(a == b) ++cnt;
  return cnt == L.size();
}

int solve(vector< vector<int> > &V, vector<int> &L) {
  int ans = -1;
  REP(i, V.size()) {
    if(isSpy(V[i], L)) {
      if(ans != -1) return -1;
      else ans = i + 1;
    }
  }
  return ans;
}

int main() {
  int N;
  while(cin >>N && N) {
    vector< vector<int> > V(N);
    REP(i, N) {
      int M; cin >>M;
      V[i] = vector<int>(M);
      REP(j, M) cin >>V[i][j];
    }

    int K; cin >>K;
    vector<int> L(K);
    REP(i, K) cin >>L[i];

    cout <<solve(V, L) <<endl;
  }
  return 0;
}

Measured memory_bytes: 3116
fun main(args: Array<String>) {
	val s = mutableMapOf<Char, String>()

	for (i in 0 until 3) {
		s['A' + i] = readLine()!!
	}

	var turn = 'A'

	while (s[turn]!! != "") {
		val pre = turn
		turn = s[turn]!![0].toUpperCase()

		s[pre] = s[pre]!!.slice(1..s[pre]!!.lastIndex)
	}

	println(turn)
}


Measured memory_bytes: 33792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007ll
#define mod1 998244353ll
#define endl "\n"
using namespace std::chrono;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll r,s,p;
    cin>>r>>s>>p;
    string t;
    cin>>t;
    string play="";
    ll ans=0;
    vector<bool> win(n,false);
    for(ll x=0;x<k;x++)
    {
        if(t[x]=='r'){play+='p'; ans+=p;}
        else if(t[x]=='p'){play+='s';ans+=s;}
        else if(t[x]=='s'){play+='r';ans+=r;}
        win[x]=true;
    }
    for(ll x=k;x<n;x++)
    {
        char used=play[x-k];
        if(t[x]=='r')
        {
            if(used!='p')
            {
                play+='p';
                ans+=p;
                win[x]=true;
            }
            else{
                if(win[x-k]==false)
                {
                    play+='p';
                    ans+=p;
                    win[x]=true;
                }else
                {
                    play+='r';
                    win[x]=false;
                }
            }
        }else if(t[x]=='p')
        {
            if(used!='s')
            {
                play+='s';
                ans+=s;
                win[x]=true;
            }else{
                if(win[x-k]==false){
                    play+='s';
                    ans+=s;
                    win[x]=true;
                }else{
                    play+='p';
                    win[x]=false;
                }
            }
        }else if(t[x]=='s')
        {
            if(used!='r')
            {
                play+='r';
                ans+=r;
                win[x]=true;
            }else{
                if(win[x-k]==false)
                {
                    play+='r';
                    ans+=r;
                    win[x]=true;
                }else{
                    play+='s';
                    win[x]=false;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

vector<bool> sw;
vector<vector<bool>> sw_permutation;

void dfs(int i, const int size) {
    if (i == size) {
        sw_permutation.emplace_back(sw);
    } else {
        for (int j = 0; j < 2; ++j) {
            sw[i] = static_cast<bool>(j);
            dfs(i + 1, size);
        }
    }
}

int main() {
    int n, m;
    cin >> n;
    cin >> m;

    int k[10];
    int s[10][10];
    int p[10];

    for (int i = 0; i < m; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }

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

    sw.resize(n);
    sw_permutation.clear();
    dfs(0, n);

    int ans = 0; //num of all bulb on
    for (const auto &x : sw_permutation) {
        bool is_ok = true;

        for (int bulb_id = 0; bulb_id < m; bulb_id++) {
            int on_num = 0; //num target switch on

            for (int j = 0; j < k[bulb_id]; j++) {
                on_num += (x[s[bulb_id][j]] ? 1 : 0);
            }

            if (on_num % 2 != p[bulb_id]) {
                is_ok = false;
                break;
            }
        }

        if (is_ok) { ans++; }

    }

    printf("%d", ans);

    return 0;
}

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

const int N = 200005;

int n;
char s[N];

int two[3][N];

int dp[N];
int f(int x) {
  if (x == 0) return 0;
  if (~dp[x]) return dp[x];
  return dp[x] = 1 + f(x % __builtin_popcount(x));
}

int solve() {
  scanf("%d", &n);
  scanf("%s", s);

  memset(dp, -1, sizeof dp);

  int cnt = 0;
  for (int i = 0; i < n; ++i) cnt += s[i] == '1';

  two[0][n-1] = two[1][n-1] = two[2][n-1] = 1;
  for (int i = n-2; i >= 0; --i) {
    for (int j = 0; j < 3; ++j) {
      if (cnt + j - 1 > 0)
        two[j][i] = (two[j][i+1] * 2) % (cnt + j - 1);
    }
  }

  int sum0 = 0, sum1 = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '1') {
      if (cnt - 1 > 0) {
        sum0 = (sum0 + two[0][i]) % (cnt - 1);
      }
      sum1 = (sum1 + two[2][i]) % (cnt + 1);
    }
  }

  for (int i = 0; i < n; ++i) {
    int ans;
    if (s[i] == '0') {
      // cerr << (sum1 + two[2][i]) % (cnt + 1) << endl;
      ans = 1 + f((sum1 + two[2][i]) % (cnt + 1));
    } else {
      // cerr << (sum0 -s two[0][i] + cnt-1) % (cnt - 1) << endl;
      if (cnt == 1) ans = 0;
      else ans = 1 + f((sum0 - two[0][i] + cnt-1) % (cnt-1));
    }

    printf("%d\n", ans);
  }

  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 7092
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int n;
vi vec;
map<int,int> maap;
int mx=-1;
int ans=0;

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

    cin>>n;
    vec.resize(n);
    rep(i,n){
        cin>>vec[i];
        maap[vec[i]]++;
        mx=max(mx,vec[i]);
    }

    for(auto i=maap.begin();i!=maap.end();++i){
        if(i->second==i->first) continue;
        else{
            if(i->second>i->first) ans+=i->second-i->first;
            else ans+=i->second;
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();
      int t;

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];

        switch( op ) {
          case "insert" :
            tree.insert(Integer.parseInt(words[k]));
            break;
          case "find" :
            t = Integer.parseInt(words[k]);
            System.out.println( tree.find(t) ? "yes" : "no" );
            break;
          default :
            tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) )
      root = z;
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  }
  boolean find(int target) {
    BTreeNode x = root;

    while( !x.equals(NIL) ) {
      if( target == x.key )
        return true;
      else if( target < x.key )
        x = x.left;
      else
        x = x.right;
    }

    return false;
  }
  
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  final int key;
  BTreeNode parent,left,right;

  public BTreeNode(final int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 137232
#include <stdio.h>

void judge_leap_year(int a, int b);

int existance_leap_year(int a, int b);

int main(void)
{
    while(1) {
      int exist;
      int start_year, end_year;
      scanf("%d %d", &start_year, &end_year);
      static int k = 0;
      ++k;
      if (start_year == 0 && end_year == 0) {
        break;
      } else {exist = existance_leap_year(start_year, end_year);
        if (k != 1) {
          printf("\n");
        }
        if (exist == 1) {
          judge_leap_year(start_year, end_year);
        } else {
          printf("NA\n");
        }
      }
    }
    return 0;
}

void judge_leap_year(int a, int b)
{
  int year;
      for (year = a; year <= b; year++) {
      if (year % 400 == 0) {
        printf("%d\n", year);
      } else if (year % 4 == 0 && year % 100 != 0) {
        printf("%d\n", year);
      }
    }
}
//閏年を記述する 

int existance_leap_year(int a, int b)
{
    int n = 0;
    int year;
    for (year = a; year <= b; year++) {
      if (year % 400 == 0) {
        n = 1;
        break;
      } else if (year % 4 == 0 && year % 100 != 0) {
        n = 1;
        break;//一度閏年を検出した時点でループを抜ける。                                                                                                                             
      }
    }
    return n;
}
//閏年があった時、１を返す                                                                                                                                                           

Measured memory_bytes: 1044
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = readline().decode().rstrip()

w = s.count('W')
r = s.count('R')
if r == 0 or w == 0:
    print(0)
    exit()
i_r = s.index('R')
r2 = s[:r:].count('R')
print(r-r2)


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    ll n;
    while (cin >> n, n) {
        vector<string> x(n+1);
        stack<pair<string, ll>> st;
        rep(i, n) {
            cin >> x[i];
        }
        x[n] = "x";

        rep(i, n+1) {
            ll num = 0;
            string tmp = "";

            if (x[i] == "x") {
                vector<pair<string, ll>> tp;

                if (st.size() == 1) {
                    cout << st.top().first << endl;
                    break;
                }

                while (true) {
                    auto cur = st.top(); st.pop();
                    if (cur.first == "+" or cur.first == "*") {
                        ll next = (cur.first == "+" ? 0 : 1);
                        for (auto t : tp) {
                            if (cur.first == "+") next += (stoll(t.first));
                            else next *= (stoll(t.first));
                        }
                        pair<string, ll> now2(to_string(next), cur.second);
                        tp.clear();

                        if (st.size() == 0) {
                            cout << next << endl;
                            break;
                        }

                        st.push(now2);
                    }
                    else {
                        tp.push_back(cur);
                    }
                }

                break;
            }

            rep(j, x[i].size()) {
                if (x[i][j] == '.') num++;
                else tmp += x[i][j];
            }
            pair<string, ll> now(tmp, num);
            if (st.size() and st.top().second > now.second) {
                vector<pair<string, ll>> tp;
                while (true) {
                    auto cur = st.top(); st.pop();
                    if (cur.first == "+" or cur.first == "*") {
                        ll next = (cur.first == "+" ? 0 : 1);
                        for (auto t : tp) {
                            if (cur.first == "+") next += (stoll(t.first));
                            else next *= (stoll(t.first));
                        }
                        pair<string, ll> now2(to_string(next), cur.second);
                        st.push(now2);
                        tp.clear();
                        if (now2.second == now.second) break;
                    }
                    else {
                        tp.push_back(cur);
                    }
                }
            }
            st.push(now);
        }
    }
}



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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }
#define dsort(v) vfsort(v,[](ll x,ll y) -> int{return x>y;})

using Data = pair<ll,vint>;

int k;
vector<ll> a,b,c;

int main(){
  vint n(3); vin(n); //x,y,z
  cin >> k;
  vector<vector<ll>> v(3);
  rep(i,3){
    v[i].resize(n[i]);
    rep(j,n[i]) cin >> v[i][j];
    dsort(v[i]);
  }

  priority_queue<Data> que;
  set<Data> se;
  que.push(Data(v[0][0]+v[1][0]+v[2][0],vint({0,0,0})));

  rep(i,k){
    auto c = que.top();que.pop();
    cout << c.first << endl;

    //次の3候補
    rep(i,3){
      if(c.second[i]+1<n[i]){
        ll sum = c.first + (v[i][c.second[i]+1] - v[i][c.second[i]]);
        auto num = c.second; num[i]++;
        auto d = Data(sum,num);

        //すでにpushされたもの以外
        if(!se.count(d)) se.insert(d), que.push(d);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 1408
d,g=map(int,input().split())
l=[]
for i in range(d):
    l.append(list(map(int,input().split())))
op=[[0],[1]]
for i in range(d-1):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp
ans=10**10
for i in op:
    z=0
    k=[]
    c=0
    for j in range(d):
        if i[j]==1:
            z+=l[j][0]*100*(j+1)+l[j][1]
            c+=l[j][0]
        else:
            k.append(j)
    if z>=g:
        ans=min(ans,c)
    else:
        if len(k)>0:
            m=max(k)
            p=g-z
            cn=-(-p//((m+1)*100))
            if cn<l[m][0]:
                ans=min(ans,c+cn)
print(ans)


Measured memory_bytes: 42348
// 2013/05/13 Tazoe

#include <iostream>
using namespace std;

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

	int cnt[101][3];
	for(int i=1; i<=100; i++){
		for(int j=0; j<3; j++){
			cnt[i][j] = 0;
		}
	}

	int M[200][3];
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			cin >> M[i][j];

			cnt[M[i][j]][j]++;
		}
	}

	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			if(cnt[M[i][j]][j]>=2){
				M[i][j] = 0;
			}
		}

		cout << M[i][0]+M[i][1]+M[i][2] << '\n';
	}

	return 0;
}

Measured memory_bytes: 1164
using System;
 
class Program
{
    static void Main()
    {
    	while(true) {
    		var s = Console.ReadLine();
    		
    		if(s == "0")	break;
    	
	    	var sum = 0;
	    	foreach(var c in s.ToCharArray()) {
	    		sum += int.Parse(c.ToString());
	    	}
	    	Console.WriteLine(sum);
    	}
    }
}

Measured memory_bytes: 9124