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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int w = in(), h = in(), n = in();
    vvint plane(w, vint(h, 0));
    rep(i, n)
    {
        int x = in(), y = in(), a = in();
        rep(j, w) rep(k, h)
        {
            if (a == 1)
            {
                if (x > j)
                {
                    plane[j][k] = 1;
                }
            }
            if (a == 2)
            {
                if (x <= j)
                {
                    plane[j][k] = 1;
                }
            }
            if (a == 3)
            {
                if (y > k)
                {
                    plane[j][k] = 1;
                }
            }
            if (a == 4)
            {
                if (y <= k)
                {
                    plane[j][k] = 1;
                }
            }
        }
    }
    int cnt = 0;
    rep(i, w) rep(j, h)
    {
        if (plane[i][j] == 0)
            ++cnt;
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int w, h; cin >> w >> h;
    vll p(w), q(h);
    ll res = 0;
    for(auto& e : p) cin >> e, res += e;
    for(auto& e : q) cin >> e, res += e;
    sort(_all(p)); sort(_all(q));

    int idx = 0;
    ll ver = 0;
    rep(i, w){
        while(idx < h and q[idx] < p[i]){
            ver += q[idx];
            idx++;
        }
        res += ver + p[i] * (h - idx);
    }

    cout << res << endl;

    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


ll N;
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

ll f(ll a){
    ll b = N/a;
    return max(to_string(a).size(), to_string(b).size());
}

void solve() {
    cin >> N;
    auto v = divisor(N);
    ll res = INF;
    rep(i, v.size()){
        res = min(res, f(v[i]));
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
L=list()
R=list()
T=0
N,M=map(int,input().split())
for i in range(N):
  A,B=map(int,input().split())
  L.append(A)
  R.append(B)
c = zip(L, R)
c=sorted(c)
L, R = zip(*c)
L=list(reversed(L))
R=list(reversed(R))
while True:
  c=L[-1]
  T+=c*min(M,R[-1])
  M-=min(M,R[-1])
  L.pop(-1)
  R.pop(-1)
  if M==0:
    break
print(T)

Measured memory_bytes: 31780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        Pattern space = Pattern.compile(" ");
        int[] first = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
        int n = first[0];
        int m = first[1];

        Map<Tuple, List<Tuple>> nexts = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int[] line = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
            int u = line[0];
            int v = line[1];
            nexts.computeIfAbsent(new Tuple(u, 0), unused -> new ArrayList<>()).add(new Tuple(v, 1));
            nexts.computeIfAbsent(new Tuple(u, 1), unused -> new ArrayList<>()).add(new Tuple(v, 2));
            nexts.computeIfAbsent(new Tuple(u, 2), unused -> new ArrayList<>()).add(new Tuple(v, 0));
        }

        int[] line = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
        int s = line[0];
        int t = line[1];

        Deque<Tuple> q = new ArrayDeque<>();
        Map<Tuple, Integer> score = new HashMap<>();
        Tuple start = new Tuple(s, 0);
        q.addLast(start);
        score.put(start, 0);
        while (!q.isEmpty()) {
            Tuple current = q.pollFirst();
            if (!nexts.containsKey(current)) {
                continue;
            }

            for (Tuple next : nexts.get(current)) {
                if (score.get(current) + 1 < score.getOrDefault(next, Integer.MAX_VALUE)) {
                    score.put(next, score.get(current) + 1);
                    q.addLast(next);
                }
            }
        }

        Tuple goal = new Tuple(t, 0);
        if (score.containsKey(goal)) {
            stdout.println(score.get(goal) / 3);
        } else {
            stdout.println(-1);
        }
    }

    private static class Tuple {
        private int node;
        private int mod;

        public Tuple(int node, int mod) {
            this.node = node;
            this.mod = mod;
        }

        @Override
        public int hashCode() {
            return Objects.hash(node, mod);
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null || !(obj instanceof Tuple)) {
                return false;
            }

            Tuple other = (Tuple) obj;
            return this.node == other.node && this.mod == other.mod;
        }
    }


    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 169512
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
    
        String name = sc.next();

        char[] work = new char[name.length()];

        for(int i = 0; i < name.length(); i++){
            work[i] = 'x';

            //切り出した文字列を一文字ずつ出力
            }
        System.out.println(work);
	}
}

Measured memory_bytes: 21968
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;


template<int char_size,int base>
struct Trie {
    struct Node {
        vector<int> child,accept;
        int c;
        int common;
        Node(int c):c(c),common(0) {
            child.assign(char_size,-1);
        }
    };
    vector<Node> tree;
    int root;
    Trie(): root(0) {
        tree.push_back(Node(root));
    }
    void insert(const string &s,int id) {
        int node_id = 0;
        for (int i = 0; i < (int)s.size(); ++i) {
            int c = (int)s[i] - base;
            int &next_id = tree[node_id].child[c];
            if (next_id < 0) {
                next_id = (int)tree.size();
                tree.push_back(Node(c));
            }
            ++tree[node_id].common;
            node_id = next_id;
        }
        ++tree[node_id].common;
        tree[node_id].accept.push_back(id);
    }
    // insert s to Trie
    void insert(const string &s) {
        insert(s,tree[0].common);
    }
    // return the number of s in Trie
    int search(const string &s) {
        vector<int> alpha(26,0);
        rep(i,s.size()) alpha[s[i] - base]++;

        int node_id = 0;
        int ans = 0;
        for (int i = 0;i < (int)s.size(); ++i) {
            rep(j,26) {
                if (alpha[j] > 0 && tree[node_id].child[j] >= 0) {
                    int x = tree[node_id].child[j];
                    if ((int)tree[x].accept.size() > 0) ++ans;
                } 
            }
            alpha[s[i] - base]--;
            int c = (int)s[i] - base;
            int &next_id = tree[node_id].child[c];
            if (next_id < 0) return ans;
            node_id = next_id;
        }
        return ans;
    }
};

int main() {
    int N; cin >> N;
    vector<string> S(N);
    rep(i,N) cin >> S[i];
    sort(S.begin(),S.end(),[](const string &a,const string &b){return a.size() < b.size();});
    
    ll ans = 0;
    Trie<26,'a'> tr;
    rep(i,N) {
        string s = S[i];
        reverse(s.begin(),s.end());
        ans += (ll)tr.search(s);
        tr.insert(s);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 168500
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 mt(736);

array<int, 2> get (ll x)
{
	array<int, 2> res{0, 0};
	for (int i = 0; i < 2; i++)
	{
		const int p = (i == 0 ? 2 : 5);
		int cnt = 0;
		while (x % p == 0)
		{
			cnt++;
			x /= p;
		}

		res[i] = cnt;
	}

	return res;
}

void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	map<array<int, 2>, int> cnt;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		double x;
		cin >> x;
		const ll num = ll(round(x * 1e9));
		cnt[get(num)]++;
	}

	const int need = 18;
	ll ans = 0;

	for (auto pr : cnt)
		for (auto other : cnt)
		{
			array<int, 2> res{0, 0};
			for (int i = 0; i < 2; i++)
				res[i] = pr.first[i] + other.first[i];

			if (res[0] >= need && res[1] >= need)
				ans += (pr == other ? ll(pr.second) * (pr.second - 1) : ll(pr.second) * other.second);
		}

	assert(ans % 2 == 0);
	ans /= 2;

	cout << ans << endl;
}

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

	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	do
	{
		solve(fin);

		cout << "===" << endl;

		string str;
		while (getline(fin, str) && str != string(max(1, (int) str.size()), '='));
	} while (fin);

	cout << setprecision(6) << "clock: " << ld(clock() - st) / CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {a = b; return true;}
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {a = b; return true;}
  return false;
}

int main() {
  int N, M; cin >> N >> M;
  V A(M), C(M);
  rep(i, M) {
    cin >> A[i];
    int b; cin >> b;
    rep(j, b) {
      int c; cin >> c;
      c--;
      C[i] |= 1<<c;
    }
  }

  int bit_max = 1<<N;
  VV dp(M+1, V(bit_max, INF));
  rep(m, M+1) dp[m][0] = 0;

  rep(m, M) rep(bi, bit_max) {
    dp[m+1][bi] = dp[m][bi];
    chmin(dp[m+1][bi], dp[m][bi&~C[m]] + A[m]);
  }

  if (dp[M][bit_max-1] == INF) cout << -1;
  else cout << dp[M][bit_max-1];
  cout << endl;
  return 0;
}


Measured memory_bytes: 16384
#include<iostream>
using namespace std;
int main(){
	int N,ans;
	string str1,str2;
	cin >> N;
	ans = 2*N;
	cin >> str1 >> str2;
	for(int i=0;i<N;i++){
		bool flag = true;
		for(int j=0;(i+j)<N;j++){
			if(str1[i+j]!=str2[j]){
				flag = false;
				break;
			}
		}
		if(flag)	ans = min(ans,i+N);
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const ll mod = 1e9 + 7;


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

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

  sort(ps.begin(), ps.end(), [](auto const& lhs, auto const& rhs) {
    double d1 = std::atan2(lhs.second, lhs.first), d2 = std::atan2(rhs.second, rhs.first);
    return d1 < d2;
  });

  ll ans = 0;
  REP(i, N) {
    ll x = 0, y = 0;
    REP(j, N) {
      x += ps[(i+j)%N].first;
      y += ps[(i+j)%N].second;
      ans = max(ans, x * x + y * y);
    }
  }

  std::cout << std::setprecision(30);
  std::cout << std::sqrt(ans) << std::endl;

  return 0;
}


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

# coding: utf-8
# Your code here!

s=input()
K=int(input())
S=list(s) #文字を置き換えるためリストに変換

def monomer(A): #文字列内の置換回数を数える関数。引数がリスト。
    N=0
    for i in range(len(A)-1):
        if A[i]==A[i+1]:
            A[i+1]="?"
            N+=1
    return N

n=monomer(S) #文字列S単体内での隣接重複文字、重複を置き換える
if S[0]!=S[-1]: #モノマー内の置き換え後に最初と最後が同じでなければそのまま掛け算でOK
    print(n*K)

#置き換え後も最初と最後が同じ場合は接続ダブりを考慮
else:
    WS=list(s*2) #pppのような、偶数次と奇数次で置換文字が交互に変わるパターン対策
    WS.insert(0,WS[-1]) #ppapのような2次以降に最初の文字を置換した方がいいパターン対策
    wn=monomer(WS)
    SS=list(s)
    SS.insert(0,SS[-1])
    nn=monomer(SS)
    print(n+wn*((K-1)//2)+nn*((K-1)%2)) #最初のループ、途中のループ、最後に余ったループでの置き換え回数

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

#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a < b) ? a : b)

#define forn(n) for(int i = 0; i < n; i++)
#define fork(k, n) for(int i = k; i < n; i++)

#define pb(n) push_back(n);

typedef long long ll;
typedef double dbl;

const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
	//Code here bby
  map<int, vector<int>> locs;
  int grid[3][3];
  for(int r = 0; r < 3; r++){
    for(int c = 0; c < 3; c++){
      int elem;
      cin>>elem;
      grid[r][c] = elem;
      locs[elem].pb((3 * r) + c);
    }
  }
  int n;
  cin>>n;
  while(n--){
    int elem;
    cin>>elem;
    if(locs.count(elem)){
      int pos = locs[elem][locs[elem].size() - 1];
      grid[pos/3][pos%3] *= -1;
      locs[elem].pop_back();
    }
  }
  bool ok = 0;
  for(int r = 0; r < 3; r++){
    if(grid[r][0] < 0 && grid[r][1] < 0 && grid[r][2] < 0){
      ok = 1;
      break;
    }
  }
  for(int c = 0; c < 3; c++){
    if(grid[0][c] < 0 && grid[1][c] < 0 && grid[2][c] < 0){
      ok = 1;
      break;
    }
  }
  if(grid[0][0] < 0 && grid[1][1] < 0 && grid[2][2] < 0){
    ok = 1;
  }
  if(grid[2][0] < 0 && grid[1][1] < 0 && grid[0][2] < 0){
    ok = 1;
  }
  ok ? cout<<"Yes"<<endl : cout<<"No"<<endl;

}


Measured memory_bytes: 3636
#include<stdio.h>

int solve(int n,int m){
	int L[105],i=0,ave,sum=0;
	for(;i<n;++i)
		scanf("%d",L+i);
	ave=m/n;
	--i;
	while(i>=0){
		if(L[i]>=ave) sum+=ave;
		else sum+=L[i];
		--i;}
	return sum;
}

int main(){
	while(1){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n&&m) printf("%d\n",solve(n,m));
		else break;}
	return 0;
}


Measured memory_bytes: 2040
def dfs(s):
    global ans
    if len(s)==M:
        return
    cnt=[0]*M
    for i in range(N):
        for j in range(M):
            if A[i][j] in s:
                continue
            cnt[A[i][j]]+=1
            break
    p=-1
    m=0
    for i in range(M):
        if cnt[i]>m:
            m=cnt[i]
            p=i
    ans=min(ans,m)
    s.add(p)
    dfs(s)
    return
N,M=map(int,input().split())
A=[list(map(lambda x:int(x)-1,input().split())) for i in range(N)]

ans=float('inf')
dfs(set())
print(ans)

Measured memory_bytes: 75084
let abc = Array.init 3 @@ fun _ -> read_line ()
let is = Array.make 3 0
let g s i = if is.(i) >= String.length s then (Printf.printf "%c\n" @@ Char.chr @@ Char.code 'A' + i; exit 0) else (is.(i) <- is.(i) + 1; is.(i) - 1)
let rec f i = f @@ Char.code abc.(i).[g abc.(i) i] - Char.code 'a'
let _ = f 0

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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int n=nextInt();

		long[] alph = disassemblyAlph(nextString());
		for(int i=1;i<n;i++){
			long[] tmp = disassemblyAlph(nextString());
			for(int a=0;a<tmp.length;a++){
				alph[a]=Math.min(alph[a],tmp[a]);
			}
		}

		String ans="";
		for(int a=0;a<alph.length;a++){
			for(int i=0;i<alph[a];i++){
				ans+=(char)('a'+a);
			}
		}

		System.out.println(ans);

	}


	public static long[] disassemblyAlph(String s){
		long[] alph = new long['z'-'a'+1];
		Arrays.fill(alph, 0);
		for(int i=0;i<s.length();i++){
			alph[s.charAt(i)-'a']++;
		}
		return alph;
	}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
	public static long lcm(long a, long b) {
		long x, y;

		return ((a / gcd(a, b)) * b);
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

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

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3, greater<int>());
	int ans = 0;
	while (a[0] != a[1] && a[0] != a[2]) a[1]++, a[2]++, ans++;
	while (a[1] > a[2]) a[2] += 2, ans++;
	if (a[0] != a[2]) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return sys.stdin.readline()[:-1]

def main():
    a = II()
    s = S()
    if 3200 > a:
        print('red')
    else:
        print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(var,start,end) for(int var=start; var<end; var++)
#define REP(var,cnt) FOR(var,0,cnt)

#if 0
int main(void) {
	
	int N, Z, W;
	cin >> N >> Z >> W;
	unsigned long cards[2010];
	
	REP(i, N) { cin >> cards[i]; }
	
	
}
#endif

#if 1
int main(void) {
	
	int N, M;
	
	cin >> N >> M;
	
	unsigned long long XXX = pow(2, M);
	
	unsigned long long su = (1900 * M + 100*(N-M)) * XXX;
	
	cout << su  << endl;
}
#endif




Measured memory_bytes: 256
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

void solve() {
    int n, m;
    cin >> n >> m;

    cout << n * (n-1) / 2 + m * (m-1) / 2;
}

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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a,b,c,x,y = sc.nextInt()
  val result = (0 to Array(x,y).max).map(_*2).map{nab => {
    val na = if (2*x>=nab){
      x-nab/2
    } else {0}
    val nb = if (2*y>=nab){
      y-nab/2
    } else {0}
    na*a+nb*b+nab*c
  }}.min
  println(result)
}

Measured memory_bytes: 35060
import java.util.Scanner;
import java.util.stream.LongStream;

class Solver {
    void solve(Scanner in) {
        int N = in.nextInt();
        System.out.println(LongStream.rangeClosed(1, N - 1).sum());
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}


Measured memory_bytes: 28620
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <string>

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORN(i, n, s) for (int i = s; i < n; i++)
#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;
#define PACK(a, n) \
  for (int i = 0; i < n; i++) cin >> a[i];
#define PACKN(a, n, s) \
  for (int i = s; i < n; i++) cin >> a[i];
#define LIST(a, n) \
  for (int i = 0; i < n; i++) cout << "[" << i << "] " << a[i] << endl;

using namespace std;

int main() {
  int N;
  IN(N)

  if (N >= 1000) {
    OUT("ABD")
  } else {
    OUT("ABC")
  }

  return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s, t;
  cin >> s >> t;

  ll ans = 0;
  rep(i, (ll)s.size()) if (s[i] != t[i]) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3920
package main

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

var INF int = (2 << 30) - 1

var sc = bufio.NewScanner(os.Stdin)

func next() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i

}

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

type RMQ struct {
	data []int
	size int
}

func NewRMQ(size int) *RMQ {
	s := 1
	for s < size {
		s *= 2

	}
	r := make([]int, s*2)
	for i := 0; i < s*2; i++ {
		r[i] = INF
	}
	return &RMQ{data: r, size: s}
}

func (r *RMQ) update(k, a int) {
	k += r.size - 1
	r.data[k] = a
	for k > 0 {
		k = (k - 1) / 2
		r.data[k] = min(r.data[k*2+1], r.data[k*2+2])
	}

}

/// [a,b]
func (r *RMQ) findMin(a, b int) int {
	return r.query(a, b+1, 0, 0, r.size)
}

// [a,b)
func (rmq *RMQ) query(a, b, k, l, r int) int {
	// case1
	if r <= a || b <= l {
		return INF
	}
	if a <= l && r <= b {
		return rmq.data[k]
	}

	vl := rmq.query(a, b, k*2+1, l, (l+r)/2)
	vr := rmq.query(a, b, k*2+2, (l+r)/2, r)
	return min(vl, vr)
}

func main() {
	sc.Split(bufio.ScanWords)

	n, q := next(), next()

	rmq := NewRMQ(n)

	for i := 0; i < q; i++ {
		com, x, y := next(), next(), next()

		if com == 0 {
			rmq.update(x, y)

		} else {
			fmt.Println(rmq.findMin(x, y))

		}
	}

}



Measured memory_bytes: 5396
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
    int n, k; cin>>n>>k;
    if(k&1){
        cout<<0<<endl;
        return 0;
    }
    k/=2;
    ll dp[51][51][1301]={};
    dp[0][0][0]=1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=i; j++){
            for(int l=0; l<=i*i/2; l++){
                (dp[i+1][j][l+j]+=dp[i][j][l])%=MOD;
                (dp[i+1][j][l+j]+=2*j*dp[i][j][l])%=MOD;
                if(j) (dp[i+1][j-1][l+j]+=j*j*dp[i][j][l])%=MOD;
                (dp[i+1][j+1][l+j]+=dp[i][j][l])%=MOD;
            }
        }
    }
    cout<<dp[n][0][k]<<endl;
    return 0;
}

Measured memory_bytes: 26752
import sys
input = sys.stdin.readline

from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())

ABCD = [tuple(map(int, input().split())) for _ in range(Q)]

lst = [i for i in range(M)]

ans = 0
for tmp in combinations_with_replacement(lst, N):
    score = 0
    for a, b, c, d in ABCD:
        if tmp[b - 1] - tmp[a - 1] == c:
            score += d
    ans = max(ans, score)

print (ans)

Measured memory_bytes: 9212
import sys
input = sys.stdin.readline

N = int(input())
S, _ = input()+'_', input()

A = []

i=0
while i<N:
    if S[i]!=S[i+1]:
        A.append(1)
        i+=1
    else:
        A.append(2)
        i+=2

p = A[0]
ans = 3 if p==1 else 6
mod = 10**9+7
for a in A[1:]:
    d = 2 if p==1 else (1 if a==1 else 3)
    ans = (ans*d)%mod
    p = a

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;



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

		char[] S = sc.next().toCharArray();
		long K = sc.nextLong();


		for (int i = 0; i < S.length; i++) {
			if (S[i] != '1') {
				System.out.println(S[i]);
				break;
			}else {
				if (i == K - 1) {
					System.out.println(S[i]);
					break;
				}
			}
		}

	}
}


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

int main(){
  int n;
  for(;cin >> n;){
    int ans = 0;
    for(int a=0;a<10;a++){
      for(int b=0;b<10;b++){
	for(int c=0;c<10;c++){
	  for(int d=0;d<10;d++){
	    if(a+b+c+d == n)ans++;
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  i64 a, b;
  cin >> a >> b;
  if(13 <= a) {
    cout << b << endl;
  }
  else if(6 <= a) {
    cout << b / 2 << endl;
  }
  else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
using System;

namespace Atcoder_20190413_B
{
    class Program
    {
        static void Main(string[] args)
        {
            //definition
            int n = int.Parse(Console.ReadLine());
            string line2 = (Console.ReadLine());
            int[] hs = new int[n];
            int result = 1;

            for (int i = 0; i < n; i++)
            {
                hs[i] = int.Parse(line2.Split(' ')[i]);
            }

            //Main
            for (int i = 1; i < n; i++)
            {
                bool available = true;
                for(int u = 0; u < i; u++)
                {
                    if (hs[u] > hs[i])
                    {
                        available = false;
                        break;
                    }
                }
                if (available == true)
                    result++;
            }

            //output
            Console.WriteLine(result);


        }
    }
}


Measured memory_bytes: 11092
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    int n ;
    cin >> n ;
    int cnt = 0 ; 
    int two = 0 ;
    for(int i=0;i<n;i++){
    	int x ; 
    	cin >> x ;
    	if ( x % 4 == 0 ){
    		cnt++ ; 
    		continue ;
    	}
    	if ( x % 2 == 0 ) two++;
    }
    cnt += two / 2 ; 
    if ( cnt >= n / 2 ){
    	puts("Yes");
    }
    else puts("No");
    return 0 ;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,pair<ll,ll> > p;

const ll maxw = 20000;

bool compare(p l, p r){
  return l.first+l.second.first<r.first+r.second.first;
}

int main(){
  ll n; cin >> n;
  p data[n];
  REP(i,n) cin >> data[i].first >> data[i].second.first >> data[i].second.second;
  sort(data,data+n,compare);
  //REP(i,n) cout << data[i].first << data[i].second.first << data[i].second.second << endl;
  ll dp[n+1][maxw+1];//i番目まで使えるときに重さの総和wiのときの価値の総和の最大値
  fill(dp[0],dp[1],-INF);
  dp[0][0] = 0;
  REP(i,n){
    REP(j,maxw+1){
      dp[i+1][j] = -INF;
      if(j-data[i].first>=0&&j-data[i].first<=data[i].second.first){
        dp[i+1][j] = max(dp[i][j-data[i].first]+data[i].second.second,dp[i+1][j]);
      }
      dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
      //cout << dp[i+1][j] << " ";
    }
    //cout << endl;
  }
  ll ans = -INF;
  REP(j,maxw+1){
    ans = max(ans,dp[n][j]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 156672
function memoization(f) {
  const cache = {};
  return (...param) => {
    const c = cache[param];
    return typeof c === 'undefined' ? cache[param] = f(...param) : c;
  };
}

class _Node {
  constructor(id, parentId, leftId, rightId) {
    this.id = id;
    this.parentId = parentId;
    this.leftId = leftId;
    this.rightId = rightId;
  }
  get type() {
    return this.parentId === -1
        ? 'root'
        : this.leftId === -1 && this.rightId === -1
            ? 'leaf'
            : 'internal node'}
}

class BinaryTree {
  constructor() {
    this.nodes = [];
    this._nodeInfo = [];
    this.getDepth = memoization(this.getDepth.bind(this));
  }
  static get Node() {return _Node;}

  add(id, leftId, rightId) {this.nodes[id] = new BinaryTree.Node(id, -1, leftId, rightId);}

  connect() {
    for (let i = 0; i < this.nodes.length; i++ ) this._nodeInfo[i] = {node:null, sibling:-1, degree:0};
    this.nodes.forEach(n => {
      if (n.leftId !== -1) {
        this.nodes[n.leftId].parentId = n.id;
        this._nodeInfo[n.leftId].sibling = n.rightId;
      }
      if (n.rightId !== -1) {
        this.nodes[n.rightId].parentId = n.id;
        this._nodeInfo[n.rightId].sibling = n.leftId;
      }
    });
    this.nodes.forEach(n => {
      this._nodeInfo[n.id] = {sibling: this._nodeInfo[n.id].sibling, node: n, degree: (n.leftId !== -1) + (n.rightId !== -1)}
    });
  }

  getDepth(id, i = 0) {
    let pid = this.find(id).parentId;
    return pid === -1 ? i : this.getDepth(pid, i + 1);
  }

  getHeight(id, i = 0) {
    if (id === -1) return i - 1;
    let n = this.find(id);
    let [lid, rid] = [n.leftId, n.rightId];
    return Math.max(this.getHeight(lid, i + 1), this.getHeight(rid, i + 1))
  }

  find(id) {return this.nodes[id]}

  print() {
    console.log(this._nodeInfo.map(o =>
      `node ${o.node.id}: parent = ${o.node.parentId}, sibling = ${o.sibling}, degree = ${o.degree}, depth = ${this.getDepth(o.node.id)}, height = ${this.getHeight(o.node.id)}, ${o.node.type}`
    ).join('\n'));
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  let tree = new BinaryTree();

  let id, l, r;
  lines.map(l => l.split(' ').map(Number)).forEach(function(line) {
    tree.add(...line);
  });
  tree.connect();
  tree.print();
})();



Measured memory_bytes: 16472
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで毎回include
//以下プログラム

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int>> data(n);
	for (int i = 0; i < n; i++) {
		string S;
		int I;
		cin >> S >> I;
		data.at(i) = make_pair(make_pair(S,100 - I), i);
	}
	sort(data.begin(), data.end());
	for (int i = 0; i < n; i++) {
		cout << data.at(i).second + 1 << endl;
	}
}



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

const int MAX_N = 2000;
const ll INF = 1LL<<60;

int n, m, s, t;
bool nc;
vector<pair<P, ll>> G;
vector<ll> dist(MAX_N, INF);

void init()
{
  cin >> n >> m >> s;
  rep(i,m)
  {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    G.emplace_back(pair<P, ll>(P(a, b), c));
  }
  nc = false;
  
  return;
}

void bf()
{
  dist[s] = 0;
  int cnt = 0;
  while(true)
  {
    if(cnt > n)
    {
      nc = true;
      break;
    }
    
    bool flg = false;
    rep(i,G.size())
    {
      int from = G[i].first.first, to = G[i].first.second, cost = G[i].second;
      if(dist[from] >= INF) continue;
      if(dist[from] + cost < dist[to])
      {
        dist[to] = dist[from] + cost;
        flg = true;
      }
    }
    if(flg == false) break;
    cnt++;
  }
  
  return;
}

void put()
{
  if(nc) cout << "NEGATIVE CYCLE" << endl;
  else rep(i,n) cout << ((dist[i] == INF)? "INF" : to_string(dist[i])) << "\n";
  return;
}

int main()
{
  init();
  bf();
  put();
  return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)  cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i]==a[i+1]){
			cout<<"NO"; 
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 1024
// C - Slimes
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int solve(int N, string &S){
	int ans = 0;
	char pre = '-';
	rp(i, 0, N){
		if(pre != S[i]){
			pre = S[i];
			ans++;
		}
	}
	return ans;
}

int main(){
	int N; string S; cin>>N>>S;
	cout<< solve(N, S) <<endl;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*- #

n = int(input())
a_twodim_list = [list(map(int, input().split())) for _ in range(2)]
r = 0
cnt = [0] * n

for i in range(n):
    for j in range(n):
        if i==j:
            cnt[i] += a_twodim_list[r][j]
            r = 1
        cnt[i] += a_twodim_list[r][j]
    r = 0
    
print(max(cnt))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#include<stdio.h>
#include<stdlib.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define array(N,t) (t*)calloc(N,sizeof(t))
const int sz=2e5;
int qLen,qHead,Q[sz];
void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}
int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}
struct touple{int a;int b;};
int main(void)
{
  int A,B,N,M,x;
  x=scanf("%d %d",&N,&M);
  /*struct touple *cave=(struct touple*)malloc((2*M)*sizeof(struct touple));
  rep(i,M)
  {
    x=scanf("%d %d",&A,&B);A--,B--;
    cave[i].a=A;cave[i].b=B;
    cave[i+M].a=B;cave[i+M].b=A;
  }*/
  vector<int> room(N,-1);vector<vector<int>> cave(N);
  rep(i,M)x=scanf("%d %d",&A,&B),A--,B--,cave[A].push_back(B),cave[B].push_back(A);
  //int *room=(int*)malloc((N)*sizeof(int));
  //memset(room,0xFF,sizeof(int)*(N));
  room[0]=0;PUSH(0);
  while(qLen)
  {
    x=POP();
    for(int y:cave[x]){if(!(room[y]<0))continue;room[y]=x,PUSH(y);}
  }
  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);
}

Measured memory_bytes: 10372
#include<cstdio>
using namespace std;
int main(){
    int n,k;
    int s = 0;
    int a[100000] = {0};
    for(;;){
        scanf("%d%d",&n,&k);
        if(n == 0&&k == 0)break;
        for(int i = 0;i < n; i++){
            scanf("%d",&a[i]);
        }
        int x = 0;
        for(int i = 0;i < k; i++){
            x += a[i];
        }
        s = x;
        for(int i = 0;i < (n-k); i++){
            x -= a[i];
            x += a[i+k];
            if(s < x)s = x;
        }
        printf("%d\n",s);
    }
    return 0;
}

Measured memory_bytes: 1428
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int p[n], ans = 0;
    rep(i, n) cin >> p[i];
    for (int i = 1; i < n - 1; i++)
    {
        if ((p[i - 1] < p[i] && p[i] < p[i + 1]) | (p[i - 1] > p[i] && p[i] > p[i + 1]))
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {
  	using namespace std;
  	string w;
  	cin >> w;
  	int c = 0;
  	if ( w == "RRR" ) 
      	c = 3;
  	else if ( w == "RRS" || w == "SRR" )
      	c = 2;
  	else if ( w == "RSR" || w == "RSS" || w == "SRS" || w == "SSR" )
      	c = 1;
   	cout << c << endl;
  	return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>

int main(){

   int n;
   int a;
   int max = -1000000;
   int min = 1000000;
   long long int sum = 0;
   int i;

   scanf("%d", &n);

   for(i=0;i<n;i++){
      scanf("%d", &a);
      if(max<a) max = a;
      if(min>a) min = a;
      sum += a;
   }

   printf("%d %d %lld\n", min, max, sum);
   return 0;
}

Measured memory_bytes: 600