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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=2005;
const int mo=1e9+7;

int ans;

signed main()
{
	int n=read();
	int m=read();
	for ( int i=m;i<=n+1;i++ ) 
	{
		int x=i-1;
		x=(1+x)*x/2;
		x=(x+mo)%mo;
		int tot=0;
		int y=n-i+1;
//		cout<<y<<endl;
		int all=(y+n)*(n-y+1)/2;
		all=all%mo;
		ans=(ans+all-x+1)%mo;
	}
	cout<<(ans+mo)%mo<<endl;
}


Measured memory_bytes: 3596
from collections import deque
 
 
class Dinic:
    def __init__(self, n: int):
        """頂点数をnとする"""
        self.INF = float("inf")
        self.n = n
        self.graph = [[] for _ in range(n)]
 
    def add_edge(self, _from: int, to: int, capacity: int):
        """残余グラフを構築
        1. _fromからtoへ向かう容量capacityの辺をグラフに追加する
        2. toから_fromへ向かう容量0の辺をグラフに追加する
        """
        forward = [to, capacity, None]
        forward[2] = backward = [_from, 0, forward]
        self.graph[_from].append(forward)
        self.graph[to].append(backward)
 
    def bfs(self, s: int, t: int):
        """capacityが正の辺のみを通ってsからtに移動可能かどうかBFSで探索
        level: sからの最短路の長さ
        """
        self.level = [-1] * self.n
        q = deque([s])
        self.level[s] = 0
        while q:
            _from = q.popleft()
            for to, capacity, _ in self.graph[_from]:
                if capacity > 0 and self.level[to] < 0:
                    self.level[to] = self.level[_from] + 1
                    q.append(to)
 
    def dfs(self, _from: int, t: int, f: int) -> int:
        """流量が増加するパスをDFSで探索
        BFSによって作られた最短路に従ってfを更新する
        """
        if _from == t:
            return f
        for edge in self.itr[_from]:
            to, capacity, reverse_edge = edge
            if capacity > 0 and self.level[_from] < self.level[to]:
                d = self.dfs(to, t, min(f, capacity))
                if d > 0:
                    edge[1] -= d
                    reverse_edge[1] += d
                    return d
        return 0
 
    def max_flow(self, s: int, t: int):
        """s-tパス上の最大流を求める
        計算量: O(|E||V|^2)
        """
        flow = 0
        while True:
            self.bfs(s, t)
            if self.level[t] < 0:
                break
            self.itr = list(map(iter, self.graph))
            f = self.dfs(s, t, self.INF)
            while f > 0:
                flow += f
                f = self.dfs(s, t, self.INF)
        return flow

n = int(input())
a = list(map(int, input().split()))

dinic = Dinic(n + 2)
s = 0
t = n + 1
_sum = 0
for i in range(0, n):
    if a[i] > 0:
        dinic.add_edge(s, i+1, 0)
        dinic.add_edge(i+1, t, a[i])
        _sum += a[i]
    elif a[i] < 0:
        dinic.add_edge(s, i+1, -a[i])
        dinic.add_edge(i+1, t, 0)
    else:
        dinic.add_edge(s, i+1, 0)
        dinic.add_edge(i+1, t, 0)

for i in range(n):
    num = i+1
    next_num = 2 * num
    while next_num <= n:
        dinic.add_edge(num, next_num, 10**18)
        next_num += num

print(_sum - dinic.max_flow(s, t))

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

vector<int> p, r;

void Init(int n) {
  for (int i = 1; i <= n; ++i)
    p[i] = i, r[i] = 0;
}

int Find(int x) {
  if (p[x] == x)
    return x;
  else
    return p[x] = Find(p[x]);
}

void Unite(int x, int y) {
  x = Find(x), y = Find(y);
  if (x == y)
    return;

  if (r[x] < r[y]) {
    p[x] = y;
  } else {
    p[y] = x;
    if (r[x] == r[y])
      ++r[x];
  }
}

bool Same(int x, int y) { return Find(x) == Find(y); }

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> com(q), x(q), y(q);
  for (int i = 0; i < q; ++i)
    cin >> com[i] >> x[i] >> y[i];

  p.resize(n + 1), r.resize(n + 1);
  Init(n);
  for (int i = 0; i < q; ++i)
    if (com[i] == 0)
      Unite(x[i], y[i]);
    else if (Same(x[i], y[i]))
      cout << 1 << endl;
    else
      cout << 0 << endl;
}


Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> p(n);
    map<string,int> res;
    rep(i,n) {
        cin >> s[i] >> p[i];
        s[i] = s[i] +"          "+string((3-std::to_string(100-p[i]).length()),' ') +std::to_string(100-p[i]);
        res[s[i]] = i+1;
    }
    sort(ALL(s));
    rep(i,n) cout << res[s[i]] << endl;
    return 0;
}


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

using namespace std;

const int N = 1e5+7;

int n, s, t;
vector<int> e[N];
int ds[N], dt[N];

inline void dfs(int x, int dis[]) {
    dis[x] = 0;
    queue<int> q;
    q.push(x);
    while (q.size()) {
        int cur = q.front();
        q.pop();
        for (int nex : e[cur]) {
            if (dis[nex] != -1 || nex == t) continue;
            dis[nex] = dis[cur]+1;
            q.push(nex);
        }
    }
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> s >> t;
    for (int i = 1, u, v; i < n; ++i) {
        cin >> u >> v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    memset(ds, -1, sizeof ds);
    memset(dt, -1, sizeof dt);
    dfs(s, ds);
    dfs(t, dt);
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        if (ds[i] == -1 || dt[i] == -1 || ds[i] >= dt[i]) continue;
        res = max(res, ds[i]+dt[i]-ds[i]-1);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 6656
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

bool comp2(const pair<int,int> &a,const pair<int,int> &b)
{
  return a.second>b.second;
}


int main(){
  int n,h;
  vector<pii> p,p2;
  vector<int> v;
  
  cin>>n>>h;
  int a,b;
  int maxa,minb;
  maxa=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    maxa=max(a,maxa);
    p.pb(pii(a,b));
  }

  for(auto x : p){
    if(x.second>=maxa){
      v.pb(x.second);
    }
  }
  sort(v.begin(),v.end(),greater<int>());

  int res=0;
  for(auto x : v){
    h-=x;
    res++;
    if(h<=0) break;
  }
  if(h<=0) cout<<res<<endl;  
  else cout<<res + (h-1)/maxa + 1<<endl;

  
  return 0;
}



Measured memory_bytes: 1908
#include <iostream>
using namespace std;
int main()
{
    int x,y;
    scanf("%x %x",&x,&y);
    if(x<y)
    {
        cout << "<" << endl;
    }
    else if(x>y)
    {
        cout << ">" << endl;
    }
    else
    {
        cout << "=" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // 1とNが組む、２とN-1が組む・・・M/2を超えたら片方だけ一つ引いてXとN-Xが組む
    int N, M;
    cin >> N >> M;
    vector<P> ans;
    int low = 1, high = N;
    if (N&1) {
        rep(i, M) {
            ans.emplace_back(low, high);
            low++; high--;
        }
    } else {
        rep(i, (M+1)/2) {
            ans.emplace_back(low, high);
            low++; high--;
        }
        high--;
        while (sz(ans) < M) {
            ans.emplace_back(low, high);
            low++; high--;
        }
    }
    for (auto p : ans) {
        cout << p.first << ' ' << p.second << '\n';
    }
    return 0;
}

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


int main(){
    int N,D,X,choco;

    scanf("%d",&N);
    int* A = new int[N];
    scanf("%d %d",&D,&X);
    for(int i=0;i<=N-1;i++){
        scanf("%d",&A[i]);
    }

    choco=0;
    for(int i=0;i<=N-1;i++){
        if(D%A[i]==0){
            choco=choco + D/A[i];
        }else{
            choco=choco + D/A[i]+1;
        }
    }

    printf("%d\n", choco+X);

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

c = 0
while True:
   try:
      s = input()
      cc = 0
      for i in range(len(s)):
         if s[i] == s[len(s) - 1 - i]:
            cc += 1
      if cc == len(s):
         #print("@", s)
         c += 1

   except EOFError:
      break
   
print(c)




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

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	
	if(a>=b){
		cout << "delicious" << endl;
	}
	else if(a+x>=b){
		cout << "safe" << endl;
	}
	else{
		cout << "dangerous" << endl;
		
	}
	
    
    
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll K, X;
  cin >> K >> X;
  FOR(i, -K + 1, K) { cout << X + i << " "; }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N,M;
	cin>>N>>M;
	int L = 1;
	int R = N;
	int i;
	for(i=0; i<M; i++)
	{
		int l,r;
		cin>>l>>r;

		L = max(L,l);
		R = min(R,r);
	}
	cout<<max(0,(R-L+1))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

int diff(vector<int> P,vector<int> Q)
{
  int n=P.size();
  for (int i=0;i<n;i++)
  {
    if (P[i]<Q[i]) return (-1);
    if (P[i]>Q[i]) return (1);
  }
  return (0);
}

int main()
{
  int N;cin>>N;
  vector<int> P(N),Q(N);
  for (int i=0;i<N;i++)
    cin>>P[i];
  for (int i=0;i<N;i++)
    cin>>Q[i];
  
  int count=0;
  if (diff(P,Q)<0)
  {
    while (P!=Q)
    {
      next_permutation(P.begin(),P.end()); 
      count++;
    }
  }
  else
  {
     while (P!=Q)
    {
      next_permutation(Q.begin(),Q.end()); 
      count++;
    }
  }
  cout<<count<<endl;
}

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

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int k;
  cin>>k;
  
  int m=s.at(k-1);
  
  for(int i=0;i<n;i++){
    if(s.at(i)!=m)
      s.at(i)='*';
  }
  cout<<s;
}

Measured memory_bytes: 256
n = int(input())
p = [int(num) for num in input().split()]

ans = 0
min_v = 2 * (10 ** 6)

for v in p:
  if min_v == 1:
    break
  if min_v > v:
    ans += 1
    min_v = v
  else:
    continue
print(ans)

Measured memory_bytes: 75472
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		int n=s.nextInt(),k=s.nextInt();
		long a=LONGS(n).sorted().limit(Math.max(0,n-k)).sum();
		System.out.println(a);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}

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

#define MOD (1000 * 1000 * 1000 + 7)
typedef long long ll;
typedef long double ld;

int nums[10];

int main() {
	
	ld avg = 0;
	int n;
	scanf("%d", &n);
	
	vector<int> vi(n);
	for(auto &i:vi) {
		scanf("%d", &i);
		avg += i;
	}
	
	avg = round(avg / n);
	
	ll pay = 0;
	for(auto &i:vi) {
		if(i != avg)
			pay += (i - avg) * (i - avg);
	}
	
	cout << pay << endl;
	
	
	
	return 0;
}


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

int main()
{
    int n;
    while (cin >> n)
    {
        if (!n)
            return 0;
        vector<string> v(n);
        stack<pair<int, int>> st;
        for (int i = 0; i < n; i++)
        {
            cin >> v[n - i - 1];
        }
        for (int i = 0; i < n; i++)
        {
            int cnt = 0;
            int m = v[i].size();
            for (int j = 0; j < m; j++)
            {
                if (v[i][j] == '.')
                    cnt++;
                else if (v[i][j] == '+')
                {
                    int x = cnt;
                    int sum = 0;
                    while (st.size() && x + 1 == st.top().second)
                    {
                        sum += st.top().first;
                        st.pop();
                    }
                    st.push({sum, x});
                }
                else if (v[i][j] == '*')
                {
                    int x = cnt;
                    int product = 1;
                    while (st.size() && x + 1 == st.top().second)
                    {
                        product *= st.top().first;
                        st.pop();
                    }
                    st.push({product, x});
                }
                else
                    st.push({v[i][j] - '0', cnt});
            }
        }
        cout << st.top().first << endl;
    }
}



Measured memory_bytes: 3208
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

ll Recur(ll n, ll N, bool three, bool five, bool seven){
	if(n > N)
	{
		return 0;
	}
	else{
		int count = 0;
		if(three) { count += Recur(n * 10 + 3, N, three, five, seven);}
		if(five) { count += Recur(n * 10 + 5, N, three, five, seven);}
		if(seven) {count += Recur(n * 10 + 7, N, three, five, seven);}
		return count + 1;
	}
}

ll Calc(ll N){
	ll ans = 0;
	ans += Recur(0, N, true, true, true) - 1;
	ans -= Recur(0, N, true, true, false) - 1;
	ans -= Recur(0, N, true, false, true) - 1;
	ans -= Recur(0, N, false, true, true) - 1;
	ans += Recur(0, N, true, false, false) - 1;
	ans += Recur(0, N, false, true, false) - 1;
	ans += Recur(0, N, false, false, true) - 1;
	return ans;
}

int main()
{
	ll N;
	cin >> N;
	cout << Calc(N) << endl;
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int m;
	while (cin >> m&&m != 0) {
		vector<pair<int, int>> find_stars;
		vector<pair<int, int>> sky;
		int a, b;
		for (int i = 0; i < m; i++) {
			cin >> a >> b;
			find_stars.emplace_back(a, b);
		}
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			sky.emplace_back(a, b);
		}
		for (int i = 0; i < n; i++) {
			int ansx = sky[i].first - find_stars[0].first,ansy = sky[i].second - find_stars[0].second;
			int count = 0;
			for (int j = 0; j < m; j++) {
				for (int h = 0; h < n; h++) {
					if (sky[h].first - find_stars[j].first == ansx&&sky[h].second - find_stars[j].second == ansy)count++;
				}
			}
			if (count == m) {
				cout << ansx << " " << ansy << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3112
n = int(input())
s = input()
copy = s
s_list = list(s)
left_list = []
right_list = []

n = len(s_list)
flag = 1
if len(s_list) > 1:
    while flag == 1:
        flag = 0

        if n>=1:
            for i in range(n-1):
                if s_list[i] == '(' and s_list[i+1] == ')':
                    s_list.pop(i)
                    s_list.pop(i)
                    n -= 2
                    flag = 1
                    break

        else:
            break




for word in s_list:
    if word == ')':
        left_list.insert(0,'(')
    else:
        right_list.insert(len(right_list),')')


word = ""

for lef in left_list:
    word += lef

word += s

for rig in right_list:
    word += rig

print(word)

Measured memory_bytes: 3064
N = int(input())
S = input()

lcs = [0]
rcs = [0]
for c in S:
    c = int(c)
    lcs.append(lcs[-1] | (1<<c))
for c in S[::-1]:
    c = int(c)
    rcs.append(rcs[-1] | (1<<c))
rcs.reverse()

ss = set()
for i,c in enumerate(S):
    c = int(c)
    ls = []
    for l in range(10):
        if lcs[i]&(1<<l):
            ls.append(l)
    rs = []
    for r in range(10):
        if rcs[i+1]&(1<<r):
            rs.append(r)
    for l in ls:
        for r in rs:
            ss.add(l*100 + c*10 + r)
print(len(ss))

Measured memory_bytes: 5572
//2/05/2020
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'


#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

//Number Theory
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

//Geometry
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan2( double(y1-y2) , double(x1-x2));}


/*Containers*/
vector<ll>v;
deque<ll>dq;
stack<ll>stk;
map<ll,ll>mp;
unordered_map<ll,ll>ump;
set<ll>st;
multiset<ll>mst;
unordered_set<ll>ust;
unordered_multiset<ll>umst;
priority_queue<ll,deque<ll>,greater<ll>>pq;
Pbds<ll>ost;

ll A,B,N;

ll F(ll x){
    ll p=(A*x)/B;
    ll q=A*(x/B);
    return p-q;
}


int main(){
    _fastio
    cin>>A>>B>>N;

    ll ans=0;

    ll l=0,r=N;
    while(1){
        ans=max(ans,F(l));
        ans=max(ans,F(r));
        ll mid=(l+r)/2;
        if(r-l==1){
            ans=max(ans,F(l));
            ans=max(ans,F(r));
            break;
        }
        else if(F(mid)>=F(l)){
            l=mid;
            ans=max(ans,F(mid));
        }
        else{
            r=mid;
            ans=max(ans,F(mid));
        }
    }
    cout<<ans<<en;

    return 0;
}


Measured memory_bytes: 3648
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    if(k<=(n+1)/2)YES;
    else NO;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Long> list = new ArrayList<>();
        ArrayList<Long> listSorted = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            long tmp = sc.nextLong();
            list.add(tmp);
            listSorted.add(tmp);
        }
        Collections.sort(listSorted);
        Long midL = listSorted.get(n / 2 - 1);
        long midR = listSorted.get(n / 2);
        for (int i = 0; i < n; i++) {
            if(list.get(i) > midL) {
                System.out.println(midL);
            } else {
                System.out.println(midR);
            }
        }
    }
}

Measured memory_bytes: 75400
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1300005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int power(int x, unsigned int y, unsigned int m)
{
    if (y == 0)
        return 1;
    int p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}
        int dp[100001];
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n,w;
        cin>>n>>w;
        pair<int,int> a[n];
        rep(i,0,n){
            int b,c;
            cin>>b>>c;
            a[i] = {b,c};
        }
        dp[0] = 0;
        rep(i,1,100001) dp[i] = INF;
        rep(i,0,n){
            for(int j=100000; j>=0; j--){
                if(dp[j]!=INF){
                    if(a[i].sc+j>100000) continue;
                    dp[a[i].sc+j] = min(dp[a[i].sc+j], dp[j]+a[i].fr);
                }
            }
        }
        for(int i=100000; i>=0; i--){
            if(dp[i]<=w){
                cout<<i;
                r0;
            }
        }
    }       
}     

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

int main() {
  int N; cin >> N;
  vector<pair<pair<string, int>, int>> rst(N);
  for (int i=0; i<N; i++) {
    string s; int p; cin >> s >> p;
    rst[i] = make_pair(make_pair(s, -p), i+1);
  }
  sort(rst.begin(), rst.end());
  for (int i=0; i<N; i++) {
    printf("%d\n", rst[i].second);
  }
}

Measured memory_bytes: 256
alp = list("abcdefghijklmnopqrstuvwxyz")
n = int(input())
S = []
ans = ""
for i in range(n):
    S.append(input())
for i in alp:
    p = 10 ** 9
    for i2 in range(n):
        p = min(S[i2].count(i),p)
    ans += i * p
print(ans)


Measured memory_bytes: 9172
#include<bits/stdc++.h>
#define INF (1<<30)
using namespace std;
int h,heap[2000001];
void maxHeapify(int i){
    int l,r,largest;
  l=i*2;
  r=i*2+1;
  if(l<=h && heap[l]>heap[i]) largest=l;
  else largest=i;
  if(r<=h && heap[r]>heap[largest]) largest=r;
  if(largest!=i){
    swap(heap[i],heap[largest]);
    maxHeapify(largest);
  }
}
void increasekey(int i, int key){
  if(key<heap[i]) return;
  heap[i]=key;
  while(i>1 && heap[i/2]<heap[i]){
    swap(heap[i/2],heap[i]);
    i=i/2;
  }
}
void insert(int key){
  h++;
  heap[h]=-INF;
  increasekey(h,key);
}
int extract(){
  int maxv;
  if(h<1) return -INF;
  maxv=heap[1];
  heap[1]=heap[h--];
  maxHeapify(1);
  return maxv;
}
int main(){
  int key;
  string com;
  while(1){
    cin>>com;
    if(com=="end") break;
    if(com=="insert"){
      scanf("%d",&key);
      insert(key);
    }else printf("%d\n",extract());
  }
  return 0;
}
      


Measured memory_bytes: 7236
#include<bits/stdc++.h>
using namespace std;
int x,n,p,c[105];
vector<int> v;
int left(int t){
   int l=0,r=v.size();
   while(l<r){
      int m=(l+r)/2;
      if(v[m]<t) l=m+1;
      else r=m;
   }
   return v[l-1];
}
int right(int t){
   int l=0,r=v.size();
   while(l<r){
      int m=(l+r)/2;
      if(v[m]>t) r=m;
      else l=m+1;
   }
   return v[r];
}
int main(){
   cin>>x>>n;
   for(int i=1;i<=n;i++){
      cin>>p;
      c[p]=1;
   }
   if(n==0 || !c[x]){
      cout<<x;
      return 0;
   }
   for(int i=0;i<=101;i++){
      if(!c[i]) v.push_back(i);
   }
   int a=left(x),b=right(x);
   if(x-a<=b-x) cout<<a;
   else cout<<b;
   return 0;
}

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

int main(){

	long int i,j;
	long int x,y,a,b,c;
	double N,M;
	long long sum=0;
	scanf("%lf",&N);
	
	printf("%lf\n",2*3.141592*N);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

#define INF 1e10

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n, m;
	while(cin>>n>>m, n!=0){
		vll s(n), t(m);
		pll ans = mp(INF, INF);
		ll ssum=0, tsum=0;
		rep(i, n) cin >> s[i], ssum+=s[i];
		rep(i, m) cin >> t[i], tsum+=t[i];
		rep(i, n)rep(j, m){
			if ((t[j]-s[i])*2 == tsum-ssum && s[i] < ans.fi){
				ans.fi = s[i];
				ans.se = t[j];
			}
		}
		if (ans.fi!=INF)
			cout << ans.fi << " " << ans.se << "\n";
		else
			cout << "-1\n";
	}

	return 0;
}


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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n, D; cin >> n >> D;
  vector<int> d(n);
  rep(i, n) {
    cin >> d[i];
  }

  vector<int> now(n+1);
  now[0] = D;
  rep(i, n) {
    now[i+1] = min(now[i], abs(now[i]-d[i]));
  }

  vector<ll> len(n+1);
  len[n] = 0;
  for(int i=n-1; i>=0; i--) {
    if (d[i] <= 2*len[i+1]+1) {
      len[i] = len[i+1]+d[i];
    } else {
      len[i] = len[i+1];
    }
  }
  /*
  rep(i, n+1) {
    debug(i); debug(now[i]); debugln(len[i]);
  }*/

  int Q; cin >> Q;
  while(Q--) {
    int pos; cin >> pos;
    if (now[pos-1] <= len[pos]) {
      cout << "NO" << '\n';
    } else {
      cout << "YES" << '\n';
    }
  }
}

Measured memory_bytes: 9728
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();
        int[] A = cin.ArrayInt(N, -1);
        int[] depth = new int[N];
        int MAX = 9999999;
        for (int i = 0; i < N; i++)
        {
            depth[i] = MAX;
        }
        for (int i = N - 1; i >= 0; i--)
        {
            if (A[i] == -1) continue;
            if (depth[i] == MAX) depth[i] = 0;
            depth[A[i]] = Math.Min(depth[A[i]], depth[i] + 1);
        }

        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (A[i] == -1 || depth[i] < K) ans++;
        }
        Console.WriteLine(ans);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 10336
#include<stdio.h>
int main(void){
    int n[101],n_in,n_out,i,MAX=0;
    for(i=0;i<101;i++){
        n[i]=0;
    }
    while(scanf("%d",&n_in)!=EOF){
        n[n_in]++;
    }
    for(i=1;i<101;i++){
        if(n[i]>MAX){
            MAX=n[i];
        }
    }
    for(i=1;i<101;i++){
        if(n[i]==MAX){
            printf("%d\n",i);
        }
    }
    return 0;
}

Measured memory_bytes: 596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
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(a>b){a=b;return 1;}return 0;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int d,g;cin>>d>>g;g/=100;
	vint p(d), c(d),s(d);
	rep(i, d){
		cin>>p[i]>>c[i];
		c[i]/=100;
		s[i] = (i+1)*p[i]+c[i];
	}

	int min = 100000;
	rep(i, 1<<d){
		int sum = 0;
		int cou = 0;
		rep(j, d){
			if((1<<j)&i){
				sum += s[j];
				cou += p[j];
			}
		}
		debug("%d      %d\n",i, sum);
		if(sum >= g){
			chmin(min, cou);
		}else{
			for(int j = d-1;j>=0;j--){
				if(!((1<<j)&i)){
					if(sum + (p[j]-1) * (j+1) >= g){
						chmin(min, cou+(int)(g-sum+j)/(j+1));
					}else{

					}
					debug("%d %d\n", sum, (int)(g-sum+j)/(j+1));
					break;
				}
			}
		}
	}
	cout << min << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

count = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        continue
    else:
        count += 1
print(count)


Measured memory_bytes: 39792
import math

A, B, H, M = map(int, input().split())

As = 2 * math.pi * (H + M/60)/12
Bs = 2 * math.pi * M / 60

S = abs(As-Bs)
C = math.sqrt(A**2+B**2-2*A*B*math.cos(S))

print(C)

Measured memory_bytes: 9432
#include <stdio.h>
 
int main(void)
{
    int pri;
    int cou;
    int kouka[6] = {500, 100, 50, 10, 5, 1};
    int i;
         
    while (1){
        scanf("%d", &pri);
         
        if (pri == 0){
            break;
        }
         
        pri = 1000 - pri;
        cou = i = 0;
        while (pri){
			cou += pri / kouka[i];
			pri -= kouka[i] * (pri / kouka[i]);
			i++;
        }
        printf("%d\n", cou);
    }
     
    return (0);
}

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

namespace CSharpSample01
{
	class Program
	{

		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			long answer = 0;

			for(int i = 1;i < N ; i++)
			{
				if(inputNum[i - 1] > inputNum[i])
				{
					int hightDiff = inputNum[i - 1] - inputNum[i];
					answer += hightDiff;
					inputNum[i] += hightDiff; 
				}
			}

			Console.WriteLine(answer);
		}
	}
}

Measured memory_bytes: 44572
n = int(input())
t, a = map(int, input().split())
places = list(map(int, input().split()))

ans = 1000000000000
leastDiff = 10000000000000000

for i in range(len(places)):
	x = places[i]
	#print('x', x)
	thisTemp = t - (x * 0.006)
	#print('this temp', thisTemp)
	thisDiff = abs(thisTemp - a)
	#print("thisdiff")
	if thisDiff < leastDiff:
		ans = i
		leastDiff = thisDiff
print(ans+1)

Measured memory_bytes: 3064
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

main = do
  [_, _, m] <- map read . words <$> getLine
  as <- VU.fromList <$> (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)
  bs <- VU.fromList <$> (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

  let amin = VU.minimum as
  let bmin = VU.minimum bs
  let m1 = amin + bmin

  let loop :: Int -> [Int] -> IO [Int]
      loop cnt xs
        | cnt >= m = return xs
        | otherwise = do
              [x, y, c] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
              let val = (as VU.! (x-1)) + (bs VU.! (y-1)) - c
              loop (cnt + 1) (val:xs)
  m2 <- minimum <$> loop 0 []

  print $ min m1 m2

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

#define lol long long
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
const lol mod=(1e9)+7;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol abs(lol x){return(x<0?-x:x);}
lol ans[200010];
vector<int> k[200010];
bool vis[200010];
lol cost[200010];
void f(int x,lol sum){
  sum+=cost[x];
  ans[x]=sum;
  for(int i=0;i<k[x].size();i++){
    if(!vis[k[x][i]]){
      vis[k[x][i]]=true;
      f(k[x][i],sum);
    }
  }
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,m,r;
  string s,w;
  cin >>n>>m;
  int a,b;
  for(int i=1;i<n;i++){
    cin >>a>>b;
    k[a].emplace_back(b);
    k[b].emplace_back(a);
  }
  for(int i=0;i<m;i++){
    cin >>a>>b;
    cost[a]+=b;
  }
  vis[1]=true;
  f(1,0);
  cout <<ans[1];
  for(int i=2;i<=n;i++){
    cout <<' '<<ans[i];
  }cout <<'\n';
  return (0);
}


Measured memory_bytes: 25856
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-8;

class UnionFindTree {
private:
  int* par;
public:
  UnionFindTree(int n){
    par = new int[n]();
    for(int i=0;i<n;i++){
      par[i] = i;
    }
  }

  ~UnionFindTree(){
    delete[] par;
  }

  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;
    par[x] = y;
  }

  bool same(int x,int y){
    return find(x) == find(y);
  }
};

vector<int> G[100001];
int marked_count[100001];
int prev_parent[100001];

void dfs(int current_node,int parent,int last_marked_node,UnionFindTree* uft){
  if(marked_count[current_node] > 0){
    last_marked_node = current_node;
  }

  prev_parent[current_node] = parent;
  uft->unite(current_node,last_marked_node);
  for(int to_idx=0;to_idx<G[current_node].size();to_idx++){
    int to = G[current_node][to_idx];
    dfs(to,current_node,last_marked_node,uft);
  }
}

int main(){
  int total_nodes;
  int total_queries;
  while(~scanf("%d %d",&total_nodes,&total_queries)){
    if(total_nodes == 0 && total_queries == 0) break;

    for(int i=0;i<=100000;i++) G[i].clear();

    memset(marked_count,0,sizeof(marked_count));
    for(int node_idx = 2;node_idx-1<total_nodes;node_idx++){
      int parent;
      scanf("%d",&parent);
      G[parent].push_back(node_idx);
    }

    int queries[100001];
    for(int query_idx=0;query_idx < total_queries; query_idx++){
      char operation[2];
      int target_node;
      scanf("%s %d",operation,&target_node);
      if(operation[0] == 'M'){
	marked_count[target_node]++;
	queries[query_idx] = target_node;
      }
      else if(operation[0] == 'Q'){
	queries[query_idx] = -target_node;
      }
    }

    UnionFindTree uft(total_nodes+1);
    dfs(1,1,1,&uft);

    ll sum = 0;
    for(int query_idx=total_queries-1;query_idx>=0;query_idx--){
      if(queries[query_idx] <= 0){
	int target_node = -queries[query_idx];
	sum += uft.find(target_node);
      }
      else if(queries[query_idx] > 0){
	int target_node = queries[query_idx];
	marked_count[target_node]--;
	if(marked_count[target_node] <= 0){
	  uft.unite(target_node,prev_parent[target_node]);
	}
      }
    }
    printf("%lld\n",sum);
  }
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    char C;
    cin >> C;

    cout << (char)(C + 1) << "\n";

return 0;
}

Measured memory_bytes: 256
N = gets.to_i
cnt = 0
3.upto(N) do |n|
  next if n % 2 == 0
  ds = 0
  1.upto(n) do |k|
    if n % k == 0
      ds += 1
    end
  end
  if ds == 8
    cnt += 1
  end
end
puts cnt

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

ll h[100001];
ll n, a, b;

bool isOK(int x) {
  int t = x;
  REP(i,n) {
    if (h[i] > b*x) {
      t -= (h[i]-b*x+a-b-1)/(a-b);
    }
    if (t < 0) return false;
  }
  return true;
}

int binary_search(int s, int t) {
  int ng = s-1, ok = t;
  while (abs(ok-ng) > 1) {
    int mid = (ok+ng) / 2;
    if (isOK(mid)) ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin >> n >> a >> b;
  REP(i,n) cin >> h[i];
  int ans = binary_search(0, INF);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
//Link : https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_e

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
#define mod 1000000007

int add(int x,int y) {
    int ret =  ((x+y)%mod+mod);
    if(ret>=mod) {
        ret -= mod;
    }
    return ret;
}
int mul(int x,int y) {
    return (ll)x*y%mod;
}
int mypow(int x,int c) {
    int ret = 1;
    while(c>0) {
        if(c&1) {
            ret = mul(ret,x);
        }
        x = mul(x,x);
        c/=2;
    }
    return ret;
}

int fac[N], prob[N] ,invFac[N];

int dp[N];

int combination(int n,int c) {
    int ret = fac[n];
    ret = mul(ret, invFac[c]);
    ret = mul(ret, invFac[n-c]);
    return ret;
}

void solve() {
    int B,W;scanf("%d %d",&B,&W);
    prob[0] = 1;
    fac[0] = 1;
    invFac[0] = 1;
    int invTwo = mypow(2,mod-2);
    for(int i=1;i<N;++i) {
        fac[i] = mul(fac[i-1],i);
        invFac[i] = mypow(fac[i],mod-2);
        prob[i] = mul(prob[i-1],invTwo);
    }
    for(int i=0;i<W;++i) {
        int probability = prob[i + B];
        if(B>1) {
            int tmp = mul(probability,combination(i+B-2,B-2));
            dp[1] = add(dp[1],tmp);
            dp[i+B] = add(dp[i+B],-tmp);
        }
        //i+B상태 정의
        int tmp = mul(probability, combination(i+B-1,B-1));
        dp[i+B] = add(dp[i+B], tmp);
        dp[i+B+1] = add(dp[i+B+1],-tmp);
    }
    for(int i=0;i<B;++i) {
        int probability = prob[i + W];
        if(i>=0) {
            int tmp = mul(probability,combination(i+W-2,i-1));
            dp[1] = add(tmp,dp[1]);
            dp[i+W] = add(dp[i+W],-tmp);
        }
        int tmp = mul(probability, combination(i+W-1,W-1));
        dp[i+W+1] = add(dp[i+W+1],tmp);
    }
    for(int i=1;i<=B+W;++i) {
        dp[i] = add(dp[i],dp[i-1]);
        printf("%d\n",dp[i]);
    }
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


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

bool IsM(int a){
	if(a>0&&a<13) return true;
	else return false;	
}



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

int l = (S[0]-'0')*10+S[1]-'0';
int r = (S[2]-'0')*10+S[3]-'0';

if(IsM(l)&&IsM(r)){
	cout<<"AMBIGUOUS"<<endl;
	return 0;
}else if(IsM(l)&&!IsM(r)){
	cout<<"MMYY"<<endl;
	return 0;
}else if(!IsM(l)&&IsM(r)){
	cout<<"YYMM"<<endl;
	return 0;
}else if(!IsM(l)&&!IsM(r)){
	cout<<"NA"<<endl;
	return 0;

}

}

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

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  vector<int>s=a;
  sort(s.rbegin(),s.rend());
  rep(i,n){
    int ans =s[0];
    if (s[0]==a[i]) ans=s[1];
    cout<<ans<<endl;
  }
  return 0;
}


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

bool connected[10][10];
int dp[1 << 10][10];

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

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        connected[a][b] = connected[b][a] = true;
    }
    dp[1][0] = 1;
    for (int mask = 1; mask < (1 << N); mask++) {
        for (int tail = 0; tail < N; tail++) {
            if (dp[mask][tail] == 0) continue;

            for (int to = 0; to < N; to++) {
                if (!connected[tail][to] || ((mask >> to) & 1)) continue;

                dp[mask | (1 << to)][to] += dp[mask][tail];
            }
        }
    }

    int ans = 0;
    for (int tail = 0; tail < N; tail++) {
        ans += dp[(1 << N) - 1][tail];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256