akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

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

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    return gcd(b, a % b);

}

auto getPrimes(int lim) {
    vector<bool> flags(lim + 1, true);
    flags[0] = flags[1] = false;

    for (int i = 2; i <= lim; i++) {
        if (flags[i]) {
            for (int j = 2 * i; j <= lim; j += i) {
                flags[j] = false;
            }
        }
    }

    vector<int> primes;

    for (int i = 0; i <= lim; i++) {
        if (flags[i]) {
            primes.push_back(i);
        }
    }

    return primes;

}

class Solve {
public:
    void solve() {
        Int A, B;
        cin >> A >> B;
        Int G = gcd(A, B);
        Int ans = 1;
        Int x = 2;
        while (true) {
            if (G % x == 0) {
                ans++;
                while (G % x == 0) G /= x;
                x++;
            } else {
                x++;
            }
            if (x * x > G) {
                if (G > 1) ans++;
                break;
            }
        }
        cout << ans << endl;
//        auto P = getPrimes(1000001);
//
//        for (auto p : P) {
//        }

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int m, d;
	cin >> m >> d;

	int cnt = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 10; j <= d; j++) {
			int d1, d2;
			d1 = j / 10;
			d2 = j % 10;
			if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) {
				cnt++;
			}
		}
	}

	out(cnt);

	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
list = []
n.times do |i|
  list[i] = gets.chomp.split.map(&:to_i)
end

list.sort_by!{ |a, b| b }

now = 0
result = 'Yes'
n.times do |i|
  a, b = list[i]
  now += a
  if now > b
    result = 'No'
    break
  end
end

puts(result)

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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
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; }

#define MOD097 1000000007

///// For Debug

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// 提出時はコメントアウト
// #define LOCAL
#define DEBUG_

#ifndef LOCAL
#undef DEBUG_
#endif

#ifdef DEBUG_

#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)

#endif

//////////

int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll A,B,C,X;
    cin >> A >> B >> C >> X;

    ll ans = 0;
    rep(a,A+1) {
        rep(b,B+1) {
            rep(c,C+1) {
                if (500*a+100*b+50*c==X) ans++;
            }
        }
    }


    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

// a^b
template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

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

    int N;
    cin >> N;
    // cnt[i] := i で割り切れる回数
    vector<int> cnt(N + 1, 0);
    for (int i = 2; i <= N; i++)
    {
        int v = i;
        for (int j = 2; j * j <= i; j++)
        {
            if (v % j)
                continue;
            while (v % j == 0)
            {
                cnt[j]++;
                v /= j;
            }
        }
        if (v != 1)
            cnt[v]++;
    }
    set<ll> st;
    // 74
    for (int i = 2; i <= N; i++)
        if (cnt[i] >= 74)
            st.insert(mypow(i, 74));
    // 3 * 25, 5*15
    for (int i = 2; i <= N; i++)
    {
        for (int j = 2; j <= N; j++)
        {
            if (i == j)
                continue;
            if (cnt[i] >= 2 && cnt[j] >= 24)
                st.insert((mypow(i, 2) * mypow(j, 24)) % MOD);
            if (cnt[i] >= 4 && cnt[j] >= 14)
                st.insert((mypow(i, 4) * mypow(j, 14)) % MOD);
            // 3 * 5 * 5
            for (int k = 2; k <= N; k++)
            {
                if (i == k || j == k)
                    continue;
                if (cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4)
                    st.insert(((mypow(i, 2) * mypow(j, 4)) % MOD) * mypow(k, 4) % MOD);
            }
        }
    }
    cout << st.size() << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

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

typedef pair<int,int> P;

// uf
struct unionfind {
  vector<int> par;
  unionfind(int n) : par(n) { for (int i = 0; i < n; ++i) par[i] = i; }
  
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y) {
    par[find(x)] = par[find(y)] = find(x);
  }
  
  bool same(int x, int y) { return find(x) == find(y); }
};

struct edge {
  int u, v, cost;
  bool operator<(const edge& other) const {
    return cost < other.cost;
  }
};

int N, M;
int H[202];
int G[202][202];

// 連結でなくなる時間を求める
int getTime() {
  vector<P> lands;
  rep(i,N) lands.push_back(P(H[i], i));
  sort(all(lands));
  vector<int> enable(N, 1);
  rep(z,N) {
    unionfind uf(N);
    // enable の島だけで掛けられそうな橋をとりあえず掛ける
    rep(i,N) {
      if (!enable[i]) continue;
      rep(j,N) {
        if (!enable[j] || i == j || (G[i][j] <= 0)) continue;
        if (!uf.same(i,j)) {
          uf.unite(i,j);
        }
      }
    }
    // 連結であるか
    rep(i,N) {
      if (!enable[i] || i == lands[z].second) continue;
      if (!uf.same(i, lands[z].second)) {
        if (z == 0) return -1;
        return lands[z-1].first;
      }
    }
    enable[lands[z].second] = 0;    
  }
  return lands.back().first + 1;
}

int solve() {
  int time = getTime(), ans = 0;
  vector<P> lands;
  rep(i,N) lands.push_back(P(H[i], i));
  sort(all(lands), greater<P>());
  // printf("time : %d\n", time);
  // 最初から連結でない
  if (time == -1) {
    return 0;
  }
 
  // 橋を掛ける
  vector<edge> es;
  rep(i,N) rep(j,N) if (G[i][j]) es.push_back((edge){i, j, G[i][j]});
  sort(all(es));

  vector<int> on(N, 0);
  
  unionfind uf(N);
  rep(z,N) {
    on[lands[z].second] = 1;
    const int t = lands[z].first;
    if (t > time) continue;
    if ((z+1 < N) && (lands[z].first == lands[z+1].first)) continue;
    
    rep(i,es.size()) {
      edge e = es[i];
      int u = e.u, v = e.v;
      if (on[u] && on[v]) {
        if (G[u][v] && !uf.same(u, v)) {
          ans += e.cost;
          uf.unite(u, v);
          // printf("%d - %d : %d | %d\n", u, v, e.cost, ans);
        }
      }
    }
  }
  
  return ans;
}

int main() {
  while (scanf("%d%d", &N, &M), N) {
    // G[][] 初期化
    rep(i,N) rep(j,N) G[i][j] = 0;
    rep(i,N) G[i][i] = 0;
    
    rep(i,N) scanf("%d", H+i);
    rep(i,M) {
      int a, b, c;      
      scanf("%d%d%d", &a, &b, &c);
      --a; --b;
      G[a][b] = G[b][a] = c;
    }
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 2540
N = int(input())
As = []
for i in range(N):
  A = int(input())
  As.append(A)
r = 0
c = 0
for A in As:
  if A == 0:
    r += c//2
    c = 0
  else:
    c += A
r += c//2
print(r)


Measured memory_bytes: 7072
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        Integer[] L = new Integer[N];
        for(int i=0;i<N;i++){
            L[i] = sc.nextInt();
        }
        Arrays.sort(L, Comparator.reverseOrder());
        int count = 0;

        for(int i=0;i<L.length;i++) {
            for(int j=i+1;j<L.length;j++){
                for(int k=j+1;k<L.length;k++){
                    boolean flag = true;
                    if(L[i] < L[j] + L[k] && L[j] < L[i] + L[k] && L[k] < L[i] + L[j]){
                        count++;
                    }else {
                        flag = false;
                    } 
                    if(flag == false){
                        break;
                    }
                    /*System.out.print(L[i]+" ");
                    System.out.print(L[j]+" ");
                    System.out.println(L[k]); */
                }
            }
        }

        System.out.println(count);
        
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define PI 3.14159265358979323846
ll A,B,X;
ll i, j, k;
double ans;
bool bs(double aa){
    double a = B / tan(aa);
    if(a>A){
        double c = A * tan(aa);
        return X <= (B - c/2) * A * A;
    }
    return X <= a * B * A / 2.0;
}
int main(){
    scanf("%lld%lld%lld",&A,&B,&X);
    double l = 0, r = PI / 2;
    while(l<r){
        double c = (l + r + 1e-12) / 2;
        if(bs(c)){
            l = c;
        }else{
            r = c - 1e-12;
        }
    }
    printf("%.12lf", l * 180 / PI);

    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

ans = ''

if set(S)!=set(T):
    ans = 'No'

for i in range(len(S)):
    if ans:
        break
    U = S[i:]+S[:i]
    if U==T:
        ans = 'Yes'

if not ans:
    ans = 'No'

print(ans)

Measured memory_bytes: 3060
from heapq import heappush, heappop
import sys

readline = sys.stdin.readline
N, Q = map(int, readline().split())
ans = [None]*Q
def solve(readline=readline):
    qs = [0]*(N+1)
    for i in range(N):
        s, t, x = map(int, readline().split())
        qs[i] = (s-x, t-x, x)
    qs[N] = (10**10, 10**10, 0)
    qs.sort()

    que = []
    D = [int(readline()) for i in range(Q)]
    j = 0
    it = iter(qs).__next__
    s, t, x = it()
    v = w = N
    for d in D:
        while j < N and s <= d:
            heappush(que, (x, t))
            v, w = que[0]
            s, t, x = it()
        while que and w <= d:
            heappop(que)
            if que:
                v, w = que[0]
        if que:
            yield "%d\n" % v
        else:
            yield "-1\n"
ans[:] = solve()
sys.stdout.writelines(ans)

Measured memory_bytes: 75220
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,u,v,x,k;
int a[N];
bool vis[N];
int cnt,head[N];
struct edge{int next,to;}e[N<<1];

struct node
{
	int id,v;
	inline bool operator < (const node &x) const
	{
		return x.v<v; 
	}
};

inline void add(int u,int v)
{
	cnt++;
	e[cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}

priority_queue<node>q;

int main(){
	scanf("%d",&n);
	for (register int i=1; i<n; ++i) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	scanf("%d",&k);
	while (k--) 
	{
		scanf("%d%d",&u,&x);
		a[u]=x; vis[u]=true;
		q.push((node){u,x});
	}
	bool jay=true;
	while (q.size())
	{
		node u=q.top(); q.pop();
		for (register int i=head[u.id]; i; i=e[i].next)
		if (!vis[e[i].to])
		{
			vis[e[i].to]=true;
			a[e[i].to]=a[u.id]+1;
			q.push((node){e[i].to,a[e[i].to]});
		}
		else
		{
			if (a[e[i].to]!=a[u.id]+1 && a[e[i].to]!=a[u.id]-1) {jay=false; break;}
		}
	}
	if (!jay) puts("No");
	else
	{
		puts("Yes");
		for (register int i=1; i<=n; ++i) printf("%d\n",a[i]);
	}
return 0;	
}

Measured memory_bytes: 4212
from math import factorial
def comb(n,r):
    if n<r:
        return 0
    else:
        return(factorial(n)//(factorial(n-r)*factorial(r)))

N, K = map(int, input().split())
MOD = 1000000007

for i in range(1,K+1):
    if N-K+1<i:
        print(0)
    else:
        print(comb(K-1,i-1)*comb(N-K+1,i)%MOD)


Measured memory_bytes: 3316
n = int(input())
a = list(map(int, input().split()))

l = []
r = []
s = []

for i, x in enumerate(a):
    left = i
    while len(s) > 0  and x < s[-1][0]:
        left = s[-1][1]
        s.pop()
        
    l.append(left)    
    s.append([x, left])

s = []
for i in range(n-1, -1, -1):
    right = i
    x = a[i]
    while len(s) > 0  and x < s[-1][0]:
        right = s[-1][1]
        s.pop()
        
    r.append(right)    
    s.append([x, right])
r = r[::-1]

ans = 0    
for i, (x, left, right)  in enumerate(zip(a,l,r)):
    ans += x * (right+1-i) * (i+1-left)
print(ans)

    

Measured memory_bytes: 43616
#include <iostream>
using namespace std;
int main() {
	int a, b, c, x, y, z;
	cin >> a >> b >> c;
	if (a>b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	if (y>c) {
		z = y;
		y = c;
	} else {
		z = c;
	}
	if (x>y) {
		cout << y << " " << x << " " << z << endl;
	} else {
		cout << x << " " << y << " " << z << endl;
	}
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  string s;
  cin >> s;
 
  vector<ll> ans(s.size(), 0);
  ll condidx = 0;
  ll cnt = 1;
  for (ll i = 1; i < s.size(); ++i) {
    if (s[condidx] == s[i]) {
      cnt++;
    } else {
      if (s[i] == 'L') {
        ans[i-1] += cnt / 2;
        if (cnt % 2 != 0) ans[i-1]++;
        ans[i] += cnt / 2;
      } else if (s[i] == 'R') {
        ans[condidx-1] += cnt / 2;
        ans[condidx] += cnt / 2;
        if (cnt % 2 != 0) ans[condidx]++;
      }
      
      condidx = i;
      cnt = 1;
    }
  }
  ans[condidx-1] += cnt / 2;
  ans[condidx] += cnt / 2;
  if (cnt % 2 != 0) ans[condidx]++;

  for (ll i = 0; i < ans.size()-1; ++i) {
    cout << ans[i] << " ";
  }
  cout << ans[ans.size()-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#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, A, B;
    string s;
    cin >> n >> A >> B >> s;
    int count = 0;
    int bc = 1;
    for (int i = 0; i < n; i++)
    {
        if (s.at(i) == 'a')
        {
            if (A+B > count)
            { 
                cout << "Yes" << endl;
                count++;
            }
            else cout << "No" << endl;
        }
        else if (s.at(i) == 'b')
        {
            if (A+B > count && B >= bc)
            {
                cout << "Yes" << endl;
                count++;
                bc++;
            }
            else cout << "No" << endl;
        }
        else if (s.at(i) == 'c')
        {
            cout << "No" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3700
#include<stdio.h>
#include<stdlib.h>
void printHeap(int*,int);
int parent(int);
int left(int);
int right(int);
int main(void)
{
  int i;//counter
  int n;//the size of binary heap
  int *arr;//heap array
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*(n+1));
  for(i=1;i<=n;i++) scanf("%d",&arr[i]);
  printHeap(arr,n);
  return 0;
}
void printHeap(int *arr,int n)
{
  int i;//counter
  for(i=1;i<=n;i++)
    {
      printf("node %d: ",i);
      printf("key = %d, ",arr[i]);
      if(parent(i)>=1) printf("parent key = %d, ",arr[parent(i)]);
      if(left(i)<=n) printf("left key = %d, ",arr[left(i)]);
      if(right(i)<=n) printf("right key = %d, ",arr[right(i)]);
      printf("\n");
    }
  
}
int parent(int i)
{
  return i/2;
}
int left(int i)
{
  return 2*i;
}
int right(int i)
{
  return 2*i+1;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
const int MOD = 1000000007;

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

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

  int n, m;
  cin >> n >> m;
  vector<bool> issafe(n + 1, true);

  rep(i, m) {
    int a;
    cin >> a;
    issafe[a] = false;
  }

  vector<int> dp(n + 1, 0);

  dp[0] = 1;
  if (issafe[1]) dp[1] = 1;

  for (int i = 2; i <= n; i++) {
    if (issafe[i - 1]) dp[i] += dp[i - 1];
    if (issafe[i - 2]) dp[i] += dp[i - 2];

    dp[i] %= MOD;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 640
from functools import reduce
from operator import add

S = input()
N = len(S)


def dfs(i, a):
    if i == N:
        return reduce(add, map(int, a.split("+")))

    if i == 0:
        return dfs(i + 1, S[i])

    return dfs(i + 1, a + S[i]) + dfs(i + 1, a + "+" + S[i])


print(dfs(0, ""))


Measured memory_bytes: 39024
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	n := int64(nextInt())
	// n := int64(1000000) // for test
	sum := int64(0)
	var i int64
	for i = int64(1); i <= n; i++ {
		if i%3 != 0 && i%5 != 0 {
			sum += i
		}
	}
	fmt.Println(sum)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 1756
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}
//for (int j = 0; j < M; j++){}
long long gcd(long long a, long long b) {
    if (b == 0){
      return a;
    }
    else return gcd(b, a % b);
}

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

    long long A[N];

    for (long long i = 0; i < N; i++){
        cin >> A[i];
    }

    long long minusCnt = 0;
    for(long long i=0; i < N; i++){
        if(A[i]<0){
            minusCnt++;
        }
    }

    long long maxSums = 0;
    long long minNum = 10000000000;
    for(long long i=0; i < N; i++){
        maxSums += abs(A[i]);
        minNum = min(minNum, abs(A[i]));
    }
//    cout << maxSums << endl;
//    cout << minusCnt << endl;

    long long res = 0;
    if(minusCnt%2 == 0){
        res = maxSums;
    }else{
        res = maxSums - 2*minNum;
    }

    cout << res << endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}


int main(void){
  ll N, M, A, B, C, D, W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> H >> W;
  char s[H+2][W+2];
  rep(i, H+2) rep(j, W+2) s[i][j] = 's';
  rep_s(i, 1, H+1) rep_s(j, 1, W+1) cin>>s[i][j];
  rep_s(i, 1, H+1){
    rep_s(j, 1, W+1){
      if (s[i][j] =='#'){
        if (s[i-1][j] != '#' && s[i][j-1] != '#' && s[i+1][j] != '#' && s[i][j+1] != '#'){
          cout <<"No" << endl;
          return 0;
        }
      }
    }
  }
  cout <<"Yes" << endl;
  return 0;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



int main()
{
	int n, a, b;

	scanf("%d %d %d", &n, &a, &b);

	if (n * a <= b) {
		printf("%d", n * a);
	}
	else printf("%d", b);


	

}


Measured memory_bytes: 128
#include<iostream>
#include <stdlib.h>
using namespace std;

int main(){
	int a,b;
	
	while(1){
	
	cin >> a >> b;
	
	if(a==0&&b==0) break;
	
	int r = b-a;
	int x=0,y=0,z=0;
	
	for(r;r>=1000;x++,r=r-1000);
	for(r;r>=500;y++,r=r-500);
	for(r;r>0;z++,r=r-100);
	
	cout<<z<<" "<<y<<" "<<x<<endl;
	
	
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
const int INF=100100100;

int cost[100100];
int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    rep(i, 100100) cost[i]=INF;

    cost[0]=0;
    cost[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        cost[i]=min(abs(h[i]-h[i-1])+cost[i-1], abs(h[i]-h[i-2])+cost[i-2]);
    }
    cout<<cost[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>

#define arrayLength(array) (size_t)((sizeof array) / (sizeof array[0]))

int main() {
  int n = 0, m = 0, x = 0, y = 0, z = 0, a = 0, b = 0;

  char s[255];
  char t;

  //   scanf(" %d %d %d %d", &n, &m, &x, &y);
  scanf("%d %d", &a, &b);
  x = a + b > a - b ? a + b > a * b ? a + b : a * b
                    : a - b > a * b ? a - b : a * b;
  printf("%d", x);

  return 0;
}


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

ans = []
a = 0

for i in range(len(t)):
  if i % 2 == 0:
    a += t[i]
  else:
    a -= t[i]

ans.append(a)

for i in range(1,len(t)):
  ans.append(2*(t[i-1]-(ans[i-1]//2)))

map_result = map(str, ans)
print(" ".join(map_result))

Measured memory_bytes: 19096
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
int cl[1000];
int di[1000];
int main(){
    int n,m;
    while(cin>>n>>m,m){
        rep(i,n)cin>>cl[i];
        rep(i,m)cin>>di[i];
        int cur=0,cnt=0;
        n--;
        while(cur<n){
            cur+=di[cnt];
            cur+=cl[cur];
            cnt++;
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 1168
s = input()
s2 = s
ans = 10000000000
for k in s2:
    s = k + s2 + k
    t = 0
    u = 0
    m = 0
    for i, l in enumerate(s):
        if(l == k):
            t = u
            u = i
            m = max(u-t-1,m)
    ans = min(ans, m)
print(ans)
                



Measured memory_bytes: 3060
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        int num = 0;
        for (int i = 0; i < line.length(); i++) {
            num += (line.charAt(i) - 48);
        }

        if (num % 9 != 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 40992
K, A, B = map(int, input().split())

N = 1

if B >= A + 2:
    # A枚までビスケット増やす
    N = A
    K = K - (A - 1)
    k = K // 2
    K = K % 2
    N = A + (B - A) * k
    # 残りの回数1枚だけ増やす
    N = N + K
else:
    # ひたすら1枚ずつ増やす
    N = N + K

print(N)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
	int N,sum2=0,sum=0,i=0,max=0;
	scanf("%d",&N);
	int A[2][N];

	for(i;i<2;i++){
		for(int j=0;j<N;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(i=0;i<N;i++){
		sum2+=A[0][i];
		for(int j=i;j<N;j++){
			sum+=A[1][j];
		}
		if(max<sum2+sum)max=sum2+sum;
		sum=0;
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
sunukes = [0 for k in range(N)]
for k in range(K):
  d = int(input())
  A = list(map(int, input().split()))
  for a in A:
    sunukes[a-1] += 1
  assert len(A) == d
print(len([k for k in sunukes if k == 0]))

Measured memory_bytes: 9120
#include <stdio.h>

int main(void)
{
  int a[10];
  int x, i, l;

  for(i = 0;i < 10;i++){
    scanf("%d", &a[i]);
  }

  for(l = 0;l < 10;l++){
    for(i = 0;i < 9;i++){
      if(a[i] < a[i+1]){
	x = a[i+1];
	a[i+1] = a[i];
	a[i] = x;
      }
    }
  }

  printf("%d\n", a[0]);
  printf("%d\n", a[1]);
  printf("%d\n", a[2]);

  return(0);
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; ll K; cin >> N >> K;
    int P[N]; rep(i, N){int a; cin >> a; P[i] = a-1;}
    ll ans = -mod;
    ll C[N]; rep(i, N){ll c; cin >> c; C[i] = c; ans = max(ans, c);}

    if(K > N){
        rep(i, N){
            int pos = P[i];
            int len = 1;
            ll mx_in_loop = C[pos];
            ll acc = C[pos];
            while(pos != i){
                pos = P[pos];
                acc += C[pos];
                mx_in_loop = max(mx_in_loop, acc);
                len++;
            }
            ll num_loop = K/len - 1;
            ll remain = K - num_loop*len;
            pos = i;
            ll acc2 = 0;
            ll mx = 0;
            rep(j, remain){
                pos = P[pos];
                acc2 += C[pos];
                mx = max(mx, acc2);
            }
            if(acc >= 0) ans = max(ans, acc*num_loop + mx);
            else ans = max(ans, mx_in_loop);
        }
        cout << ans << endl;
    } 
    else{
        rep(i, N){
            ll acc = 0;
            int pos = i;
            rep(j, K){
                pos = P[pos];
                acc += C[pos];
                ans = max(ans, acc);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=1005;
const int mod=1e9+7;
int pow_mod(int a,LL b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;
}
int n,m;LL K;
char ch[MAXN][MAXN],ch1[MAXN][MAXN];
int up[MAXN],lef[MAXN],cnt0,cnt1;
bool vis[MAXN][MAXN];

void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
struct matrix
{
	int m[2][2];
	matrix(){memset(m,0,sizeof(m));}
	friend matrix operator *(matrix u,matrix v)
	{
		matrix ret;
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++)
			ad(ret.m[i][k],1LL*u.m[i][j]*v.m[j][k]%mod);
		return ret;
	}
	friend matrix operator ^(matrix u,LL b)
	{
		matrix ret;ret.m[0][0]=ret.m[1][1]=1;
		for(;b;b>>=1,u=u*u)if(b&1)ret=ret*u;
		return ret;
	}
};
int main()
{
	n=read();m=read();K=read();
	if(K<=1)return puts("1"),0;
	for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);
	for(int i=1;i<=m;i++)up[i]=(ch[1][i]=='#'&&ch[n][i]=='#'),cnt0+=up[i];
	for(int i=1;i<=n;i++)lef[i]=(ch[i][1]=='#'&&ch[i][m]=='#'),cnt1+=lef[i];
	
	int cnt2=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cnt2+=(ch[i][j]=='#');
	if(cnt0&&cnt1)return puts("1"),0;
	else if(!cnt0&&!cnt1)return pr2(pow_mod(cnt2,K-1)),0;
	else
	{
		if(!cnt1)
		{
			for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ch1[j][i]=ch[i][j];
			swap(n,m);for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ch[i][j]=ch1[i][j];
			memcpy(lef,up,sizeof(lef));swap(cnt0,cnt1);
		}cnt0=0;
		for(int i=1;i<=n;i++)
		{
			int sum=0;
			for(int j=1;j<m;j++)sum+=(ch[i][j]=='#'&&ch[i][j+1]=='#');
			cnt0+=sum;
		}
		matrix re,temp;
		temp.m[0][0]=cnt2;temp.m[1][0]=cnt0;
		temp.m[1][1]=cnt1;re.m[0][1]=1;
		temp=temp^(K-1);re=re*temp;
		
		int u1=pow_mod(cnt2,K-1);
		u1=(u1-re.m[0][0]+mod)%mod;
		pr2(u1);
	}
	return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#define N_MAX 200000
#define RT_MAX 1000000000

int main(){
  int i,j,n,R[N_MAX],max=-RT_MAX,mi,d,db;
  scanf("%d",&n);
  if(n>N_MAX || n<2)exit(8);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
    if(R[i]>RT_MAX || R[i]<1)exit(8);
  }
  mi=R[0];
  for(j=1;j<n;j++){
    d=R[j]-mi;
    if(d>max)max=d;
    if(R[j]<mi)mi=R[j];
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2576
_,M,*A=`dd`.split.map &:to_i
*c=(*b=(*a=[z=0]*(2*M+1)))
A.each_cons(2){|l,r|
	l>r&&r+=M
	z+=r-l
	a[l+1]+=l
	a[r+1]-=l
	b[l+1]+=1
	b[r+1]-=1
}
1.upto(2*M){|i|
	a[i]+=a[i-1]
	b[i]+=b[i-1]
	c[i]=a[i]-b[i]*(i-1)
}
p z+M.times.map{|i|c[i]+c[i+M]}.min

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

int main() {
  int64_t K;
  cin >> K;
  int N = 50;
  vector<int64_t> xs(N + 1);
  for (int i = 1; i <= N; ++i) {
    xs[i] = i - 1;
    xs[i] += K / N;
  }
  for (int i = 1; i <= K % N; ++i) {
    xs[i] += N;
    for (int j = 1; j <= N; ++j) {
      if (j != i) --xs[j];
    }
  }
  cout << N << endl;
  for (int i = 1; i <= N; ++i) {
    cout << xs[i];
    if (i != N) cout << " ";
  }
  cout << endl;
}


Measured memory_bytes: 256
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=np.array(readline().strip().split(),dtype="int64")
    
    a.sort()
    neg=a[a<0]
    neg_p=neg**2
    zero=a[a==0]
    pos=a[a>0]
    pos_p=pos**2
    l=-10**18-1
    r=10**18
    while l<r-1:
        x=(l+r)//2
        cnt=0
        if len(neg)>0:
            cnt+=(len(a)-np.searchsorted(a,(x+neg+1)//neg)).sum()
            cnt-=len(neg_p[neg_p<=x])
        if len(zero)>0:
            if x>=0:
                cnt+=(len(a)-1)*len(zero)
        if len(pos)>0:
            cnt+=np.searchsorted(a,x//pos,side="right").sum()
            cnt-=len(pos_p[pos_p<=x])

        cnt//=2
        if cnt>=k: r=x
        else: l=x

    print(r)

if __name__=="__main__":
    main()

Measured memory_bytes: 34648
mod = 1000000007
L = input()
ans = 1
n = len(L)
i = n - 1
while i >=0:
    n0 = 0
    n1 = 0
    while L[i] == '0':
        n0 += 1
        i -= 1
    while L[i] == '1':
        n1 += 1
        i -= 1
        if i < 0:
            break
    ans *= pow(2, n1, mod)
    ans += (pow(3, n1, mod) - pow(2, n1, mod)) * pow(3, n - i - 1 - n1, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 41328
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n+1][2];
		//input??¨????????°
		string s[n+1];
		a[0][1]=-1;
		a[1][1]=0;
		for(int i=1;i<=n;i++){
			cin>>a[i][0]>>s[i];
			a[i][1]=a[a[i][0]][1]+1;
		}
		for(int i=3;i<=n;i++){
			int nowa1=a[i][1];
			string nows=s[i];
			int nowa0=a[i][0],ireru;
			for(int j=nowa0+1;j<=i-1;j++){
				if(a[j][1]<nowa1){
					for(int k=i-1;k>=j;k--){
						a[k+1][0]=a[k][0];
						a[k+1][1]=a[k][1];
						s[k+1]=s[k];
					}
					a[j][0]=nowa0;
					a[j][1]=nowa1;
					s[j]=nows;
					for(int k=j+1;k<=n;k++){
						if(a[k][0]>=j&&a[k][0]<=i-1){
							a[k][0]++;
						}
						else if(a[k][0]==i){
							a[k][0]=j;
						}
					}
					break;
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=a[i][1];j++){
				cout<<".";
			}
			cout<<s[i]<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1332
using System;
using System.Linq;
public class Program {
  public static void Main() {
    int[] NX = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    int[] x = Console.ReadLine().Split(' ').Select(int.Parse).Concat(new[]{NX[1]}).OrderBy(i => i).ToArray();
    int[] s = new int[x.Length-1];
    for (int i = 1; i < x.Length; i++) {
      s[i-1] = x[i] - x[i-1];
    }
    s = s.Distinct().ToArray();
    if (s.Length == 1) {
      Console.WriteLine(s[0]);
      return;
    }
    int[] gcds = new int[s.Length-1];
    for (int i = 1; i < s.Length; i++) {
      gcds[i-1] = gcd(s[i-1],s[i]);
    }
    Console.WriteLine(gcds.Min());
  }

  static int gcd(int a, int b) {
    if (a < b) swap(ref a, ref b);
    int mod = a%b, div = b, temp;
    while (mod != 0) {
      temp = mod;
      mod = div % mod;
      div = temp;
    }
    return div;
  }

  static void swap(ref int a, ref int b) {
    int temp = a;
    a = b;
    b = temp;
  }
}

Measured memory_bytes: 22240
#include<bits/stdc++.h>
using namespace std;
string x,y;
bool ok(int a,int b,string y){
	for(int i=a;i<=b;i++)
		if(x[i]!=y[i-a]&&x[i]!='?')
			return false;
	return true;
}
int main(){
	cin>>x>>y;
	for(int i=x.size()-y.size();i>=0;i--)
		if(ok(i,i+y.size()-1,y)){
			for(int j=0;j<i;j++){
				if(x[j]=='?')
					x[j]='a';
				cout<<x[j];
			}
			cout<<y;
			for(int j=i+y.size();j<x.size();j++){
				if(x[j]=='?')
					x[j]='a';
				cout<<x[j];
			}
			return 0;
		}
	cout<<"UNRESTORABLE";
	return 0;
}

Measured memory_bytes: 256
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.trim().chars().next().unwrap();
    let t = ["Sunny", "Cloudy", "Rainy"];
    let k = match s {
        'S' => 0,
        'C' => 1,
        _ => 2,
    };
    println!("{}", t[(k + 1) % 3]);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back

int main(){
  int H,W,A,B;
  cin>>H>>W>>A>>B;
  rep(i,H){
    rep(j,W){
      if((i<B&&j<A)||(i>=B&&j>=A)) cout<<0;
      else cout<<1;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1280
#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>;

void Main()
{
  unordered_set<string> se;
  int N;
  cin >> N;
  vector<string> S(N);
  int cnt = 0;
  rep(i,N) {
    cin >> S[i];
    if (se.find(S[i]) == se.end()) {
      cnt++;
      se.insert(S[i]);
    }
  }
  cout << cnt << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 23932
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    set<string> s;
    int n; cin>>n;
    For(i, 0, n){
        string a; cin>>a;
        s.insert(a);
    }
    cout<<sz(s);
}

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    solve();
    return 0;
}





Measured memory_bytes: 19240
#include <stdio.h>

int main()
{
	int N, A[101], B[101];
	scanf ("%d", &N);
	for (int i = 1; i <= N; i++) scanf ("%d", &A[i]);
	for (int k = N; k >= 1; k--){
		bool f = 0;
		for (int i = k; i >= 1; i--) if (A[i] == i){
			for (int j = i + 1; j <= k; j++) A[j - 1] = A[j];
			B[k] = i;
			f = 1;
			break;
		}
		if (!f){
			puts("-1");
			return 0;
		}
	}
	for (int i = 1; i <= N; i++) printf ("%d\n", B[i]);
	return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;

//----------------------------------------------------------

int H, N;
int dp[10001];

int main(){
    cin >> H >> N;
    int maxm=0;
    FOR(i,1,10001)
    {
        dp[i]=INT_MAX-1;
    }
    REP(i,N)
    {
        int a,b;
        cin >> a >> b;
        REP(j,a)
        {
            chmin(dp[j],b);
        }
        FOR(j,a,10001)
        {
            chmin(dp[j],b+dp[j-a]);
        }
    }
    cout << dp[H] << endl;
    return 0;
}


Measured memory_bytes: 256
// contest.cpp : アプリケーションのエントリ ポイントを定義します。
//


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N, x;
	cin >> N >> x;
	vector<int>a(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0; 
	for (int i = 0; i < N; i++) {
		if (i == N - 1) {
			if (a[N - 1] == x)ans++;
			break;
		}
		if(x >= a[i]) {
			x -= a[i];
			ans++;
		}
		else {
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 2019;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    reverse(all(s));

    vec ms(n+1);

    lint res = 0;

    lint now = 1;
    for (int i = 1; i <= n; i++) {
        int nd = s[i-1] - '0';
        ms[i] = (ms[i-1] + now * nd) % MOD;
        now *= 10;
        now %= MOD;
    }

    map<int, int> mp;

    rep(i, n+1) mp[ms[i]]++;

    for (auto&& p : mp) {
        res += p.second * (p.second - 1) / 2;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5184