akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main()
{
    string s,t;
    cin>>s>>t;
    red(i,s.size()){
        if(s==t)yn(1),exit(0);
        s=s.substr(1)+s[0];
    }
    yn(0);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
ll a;cin>>a;
  cout<<a+a*a+a*a*a<<endl;
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <deque>
    #include <vector>
    #define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
    #define all(_v) (_v).begin() , (_v).end()
    #define sz size()
    #define pb push_back
    #define SET(__set, val) memset(__set, val, sizeof(__set))
    #define FOR(__i, __n) ffor (__i, 0, __n)
    typedef long long LL;

    using namespace std;

    LL A, B;

    LL mysqrt(LL x) {
    	LL y = sqrt(x);
    	if (y * y > x)
				y--;
    	if ((y + 1LL) * (y + 1LL) <= x)
    		return y + 1;
    	return y;
    }

    int main() {
    	int tests;
    	cin >> tests;
    	FOR (test, tests) {
    		cin >> A >> B;
    		LL ret = 0LL;
    		LL mm = A * B - 1;
    		LL s = mysqrt(mm);
    		ret += 2 * s;
    		//cout << s << " " << A << " " << B << " " << mm << endl;
    		if (s * (s + 1) > mm)
    			ret--;
    		if (s >= min(A, B))
    			ret--;
    		cout << ret << endl;
    		//cout << "ret = " << ret << "; s = " << s << "; mm  = " << mm << endl;
    	}
      return 0;
    }

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

int main(){

    int n;
    string s;
    cin >> n >> s;

    int ans=n;
    int t=0;
    vector<int> a(n,0),b(n,0);

    rep(i,n){
        if(s[i]=='#'){
            t++;
        }
        b[i]=t;
    }

    t=0;
    rep(i,n){
        if(s[n-i-1]=='.'){
            t++;
        }
        a[n-i-1]=t;
    }

    if(b.back()==n||a[0]==n){
        cout << 0 << endl;
        return 0;
    }

    rep(i,n-1){
        ans=min(ans,a[i+1]+b[i]);
    }
    ans=min({ans,a[0],b.back()});

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2180
# include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
  int flag = 1;
  cin >> s;
  for(int i = 0; i < s.length(); i++){
  if(i %2 == 0 && s[i]=='L')
  {
    flag = 0;
  cout << "No"<<'\n';
    break;
  }
    if(i%2 == 1 && s[i]=='R'){
  cout << "No"<<'\n';
      flag = 0;
    break;    
    }
  }
  if (flag)
    cout <<"Yes"<<'\n';
	
  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main() {
	int N, T;
	cin>>N>>T;
	vector<int>c(N),t(N);
for(int i = 0; i<N;++i){
	cin>>c[i]>>t[i];
}

	int cost = 10000;
	for(int i=0; i<N;++i){
		if(T>=t[i]){
			cost = min(cost,c[i]);
		}
	}
	if(cost != 10000){
		cout<<cost<<endl;
	}
	else{
		cout<<"TLE"<<endl;
	}


	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    x0, x1 = 0, W
    y0, y1 = 0, H
    for i in range(N):
        if a[i] == 1:
            x0 = max(x0, x[i])
        if a[i] == 2:
            x1 = min(x1, x[i])
        if a[i] == 3:
            y0 = max(y0, y[i])
        if a[i] == 4:
            y1 = min(y1, y[i])
    if x1 <= x0 or y1 <= y0:
        ret = 0
    else:
        ret = (x1 - x0) * (y1 - y0)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    a = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const int INF = 100000000;

void chmax(long long *a, long long b) {
    if(*a < b) {
        *a = b;
    }
}

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

    long long w[n], v[n];
    for(int i = 0; i < n; i++) {
        scanf("%lld %lld", w+i, v+i);
    }

    long long dp[n][W+1];
    memset(dp, 0, sizeof(long long) * n * (W+1));

    dp[0][0] = 0;
    dp[0][w[0]] = v[0];
    for(int i = 1; i < n; i++) {
        for(int j = 0; j < W+1; j++) {
            chmax(&dp[i][j], dp[i-1][j]);
            if(j - w[i] >= 0) {
                chmax(&dp[i][j], v[i] + dp[i-1][j - w[i]]);
            }
        }
    }

    long long v_max = 0;
    for(int j = 0; j < W+1; j++) {
        if(v_max < dp[n-1][j]) {
            v_max = dp[n-1][j];
        }
    }

    printf("%lld\n", v_max);
    return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int c=0;
    for (int i=0;i<s.length()/2;i++){
        if (s[i]!=s[s.length()-i-1])
        c++;
    }
    cout<<c<<endl;
    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

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

std::vector<std::string> split(std::string str, char del) {
    int first = 0;
    int last = str.find_first_of(del);

    std::vector<std::string> result;

    while(first < str.size()) {
        std::string subStr(str, first, last - first);

        result.push_back(subStr);

        first = last + 1;
        last = str.find_first_of(del, first);

        if(last == std::string::npos) {
            last = str.size();
        }
    }

    return result;
}

V p;
int N;

int main() {
    cin >> N;
    int disc = 0;
    int sum = 0;
    REP(i, N) {
        CINT(p);
        sum += p;
        disc = max(disc, p);
    }
    cout << sum - disc / 2 << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    string w,prev;
    set<string> s;
    cin>>w;
    prev=w;
    s.insert(w);
    int f=0;
    for (i=1;i<n;i++)
    {
        cin>>w;
        if (s.find(w)==s.end() && prev[prev.size()-1]==w[0])
        {
            prev=w;
            s.insert(w);
        }
        else
        {
            f=1;
            break;
        }
    }
    if (f)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();
typedef pair<int,int> P;

int main()
{
    int H,W;
    cin >> H >> W;
    char A[H][W];
    int dark[H][W];
    REP(i,H) REP(j,W) dark[i][j] = -1;
    queue <P> que;

    REP(i,H) REP(j,W) {
        cin >> A[i][j];
        if (A[i][j] == '#'){
            dark[i][j] = 0;
            que.push(make_pair(i,j));
        }
    }
    int x,y;
    int yoko[] = {1,0,-1,0};
    int tate[] = {0,1,0,-1};
    while (!que.empty()){
        P p = que.front();
        que.pop();
        REP(i,4){
            x = p.first + yoko[i];
            y = p.second + tate[i];
            if (x<0 || x>=H || y<0 || y>=W) continue;
            if (dark[x][y] == -1){
                dark[x][y] = dark[p.first][p.second]+1;
                que.push(make_pair(x,y));
            }
        }
    }
    int ans = 0;
    REP(i,H) REP(j,W) ans = max(ans,dark[i][j]);    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13328
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

typedef long long ll;

int N, cnt[3];
string s[100000 + 10];

int main() {
	cin >> N >> cnt[0] >> cnt[1] >> cnt[2];
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		if (s[i] == "AC")s[i] = "CA";
	}

	string ans;
	int idx = 0;
	while (idx < N) {
		int fst = s[idx][0] - 'A', scd = s[idx][1] - 'A';
		if (cnt[fst] == 0 && cnt[scd] == 0) {
			cout << "No" << endl;
			return 0;
		}
		else if (cnt[fst] == 0) {
			cnt[scd]--;
			cnt[fst]++;
			ans += 'A' + fst;
			idx++;
		}
		else if (cnt[scd] == 0) {
			cnt[fst]--;
			cnt[scd]++;
			ans += 'A' + scd;
			idx++;
		}
		else {
			if (idx == N - 1) {
				cnt[fst]--;
				cnt[scd]++;
				ans += 'A' + scd;
				idx++;
				//どっちを足してもよい
			}
			else {
				//次のを見て決める
				if (s[idx] == s[idx + 1]) {
					//2回1セットでやるので実質的にcntは変化しない
					ans += s[idx];
					idx += 2;
				}
				else if (s[idx][0] == s[idx + 1][1]) {
					//例えば、AB, CAと並ぶならA+B-からのC+A-をする
					cnt[s[idx][1] - 'A']--;
					cnt[s[idx + 1][0] - 'A']++;
					ans += s[idx][0];
					ans += s[idx + 1][0];
					idx += 2;
				}
				else if (s[idx][1] == s[idx + 1][0]) {
					//例えば、AB, BCと並ぶなら、A-B+からのB-C+をする。
					cnt[s[idx][0] - 'A']--;
					cnt[s[idx + 1][1] - 'A']++;
					ans += s[idx][1];
					ans += s[idx + 1][1];
					idx += 2;
				}
				//上の3パターンのうちのいずれかに必ず入る
			}
		}
	}

	cout << "Yes" << endl;
	for (int i = 0; i < N; i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 6892
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;

			// int maxw=0,maxh=0;
			HashMap<Integer, Masu2> list = new HashMap<Integer, Masu2>();
			int[][] map = new int[401][401];

			map[201][201] = 0;
		/*	for (int i = 0; i < 201; i++) {
				for (int j = 0; j < 201; j++) {
					map[i][j] = -1;
				}
			}*/
			Masu2 sub = new Masu2(201, 201);
			list.put(0, sub);

			int maxx = 201, maxy = 201, minx = 201, miny = 201;

			for (int i = 1; i < n; i++) {

				int nn = sc.nextInt();
				int dd = sc.nextInt();
				
				
				Masu2 desu = list.get(nn);
				int yy = desu.y;
				int xx = desu.x;

				switch (dd) {
				case 0:
					xx--;
					break;
				case 1:
					yy++;
					break;
				case 2:
					xx++;
					break;
				case 3:
					yy--;
					break;
				}

				if (xx < minx)
					minx = xx;
				else if (xx > maxx)
					maxx = xx;
				if (yy < miny)
					miny = yy;
				else if (yy > maxy)
					maxy = yy;

				map[yy][xx] = i;
				Masu2 sub2 = new Masu2(yy, xx);
				list.put(i, sub2);
			}

			int height = maxy - miny + 1;
			
			int width = maxx - minx + 1;
			
//			System.out.println(maxy + " " + miny);
//			System.out.println(maxx + " " + minx);
			System.out.println(width + " " + height);
	/*		
			for(int i=180;i<220;i++){
				for(int j=180;j<220;j++){
					System.out.print(map[i][j]+" ");
				}
				System.out.println();
			}
		*/	
		}
	}

}

class Masu2 {
	int y;
	int x;

	public Masu2(int y, int x) {
		this.x = x;
		this.y = y;
	}
}

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

using namespace std;

#define DUMP(x) std::cout << (#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 pb push_back

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

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 = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

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

vint strToVint(const string &s)
{
    vint ret(s.size());
    rep(i, s.size())
    {
        ret[i] = s[i] - '0';
    }
    return ret;
}

void Main()
{
    string s;
    cin >> s;

    vint v = strToVint(s);

    int n = s.size() - 1;
    rep(bit, (1 << n))
    {
        int ans = v[0];
        rep(i, n)
        {
            if (bit & (1 << i))
            {
                ans += v[i + 1];
            }
            else
            {
                ans -= v[i + 1];
            }
        }
        if (ans == 7)
        {
            string out = {s[0]};
            rep(i, n)
            {
                if (bit & (1 << i))
                {
                    out.pb('+');
                }
                else
                {
                    out.pb('-');
                }
                out.pb(s[i + 1]);
            }
            out += "=7";
            cout << out << endl;
            return;
        }
    }
}

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
<?php
$n = (int)trim(fgets(STDIN));

$args = explode(' ', trim(fgets(STDIN)));;
$fours = 0;
$twos = 0;
foreach ($args as $val) {
	$tmp=(int)$val;
	if ($tmp%4===0) {
		++$fours;
	}elseif ($tmp%2===0) {
		++$twos;
	}
}
if ($twos===0) {
	$max_covered=$fours*2+1;
}else{
	$max_covered=$fours*2+$twos;
}
if ($max_covered>=$n) {
	echo 'Yes';
}else{
	echo 'No';
}


Measured memory_bytes: 12792
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define PB push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll X,Y,A,B,C,R[100000],G[100000],CO[100000],x,y;
    cin>>X>>Y>>A>>B>>C;
    F(i,0,A,1)
    cin>>R[i];
    F(i,0,B,1)
    cin>>G[i];
    F(i,0,C,1)
    cin>>CO[i];
    sort(R,R+A);
    sort(G,G+B);
    sort(CO,CO+C);
    ll eat[200000];
    ll j=A-1;
    ll i=0;
    x=X;
    y=Y;
    while(X!=0)
    {
        eat[i]=R[j];
        X--;
        j--;
        i++;
    }
    j=B-1;
     while(Y!=0)
    {
        eat[i]=G[j];
        Y--;
        j--;
        i++;
    }
sort(eat,eat+x+y);
i=0;
j=C-1;
while(C!=0)
{
    if(eat[i]<CO[j])
    {
        eat[i]=CO[j];
        i++;
        j--;
    }
    C--;

}
ll sum=0;
F(i,0,x+y,1)
{
    sum+=eat[i];
}
cout<<sum;
return 0;
}



Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define Pct puts("------ Yes ------");
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
#define fir first
#define sec second
#define ls son[u][0]
#define rs son[u][1]
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;
template <class T> void rd(T &x){ x = 0; int f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); x *= f; }

typedef long long ll;
const int maxn = 1e5 + 5;
pair <int, int> p[maxn];
ll res;
ll n, m;

int main(){
	rd(n), rd(m);
	rep(i, 1, n) rd(p[i].fir), rd(p[i].sec);
	sort(p + 1, p + n + 1);
	rep(i, 1, n){
		if(m <= p[i].sec){
			res += (ll) p[i].fir * m;
			break;
		}
		else res += (ll) p[i].fir * p[i].sec, m -= p[i].sec;
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline char ch(){
	static char s[1<<16],*S,*T;
	return (S==T)?(T=(S=s)+fread(s,1,1<<16,stdin),*S++):*S++;
}
#define ch() getchar()
template<typename T> void read(T &x){
	x = 0; int f(1); char c = ch();
	for(;!isdigit(c);c = ch()) if(c == '-') f = -1;
	for(;isdigit(c);c = ch()) x = x*10+c-'0';
	x *= f;
}
const int maxn = 200005;
int n,nxt[maxn]; ll k;
int in[maxn],p[maxn],len,S,dp[maxn];
void dfs(int x,int dep){
	p[dep] = x; in[x] = 1; dp[x] = dep;
	if(!in[nxt[x]])	dfs(nxt[x],dep+1);
	else{S = nxt[x]; len = dp[x]-dp[nxt[x]]+1; return;}
}
int main(){
	read(n); read(k);
	for(int i(1);i <= n;++i)	read(nxt[i]);
	dfs(1,0);
	if(k < dp[S])	printf("%d\n",p[k]);
	else{
		k -= dp[S]; k %= len; int u;
		for(u = S;k;--k)	u = nxt[u];
		printf("%d\n",u);
	}
	return 0;
}

Measured memory_bytes: 6820
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

class Node(var par:Int, var lef: Int,var rig:Int) {
    fun show(){
        println("par: ${this.par}, lef: ${this.lef}, rig: ${this.rig}")
    }
}

fun main(args: Array<String>) {
    val n = nextInt()
    val fig = Array(n){Node(-1, -1, -1)}
    for(i in 0 until n){
        val (id, lef, rig) = nextListOfInt()
        fig[id].lef = lef
        fig[id].rig = rig
        if(lef != -1) fig[lef].par = id
        if(rig != -1) fig[rig].par = id
    }

    var root = -1
    for(i in 0 until n) {
        if (fig[i].par == -1) root = i
    }

    val H = Array(n){-1}
    val D = Array(n){-1}

    setHigh(fig, H, root)
    setDep(fig, D, root, 0)


    for(i in 0 until n){
        println("node $i: parent = ${fig[i].par}, sibling = ${getSib(fig, i, root)}, degree = ${getDeg(fig, i, root).first}," +
                " depth = ${D[i]}, height = ${H[i]}, ${getDeg(fig, i, root).second}")
    }
}

fun setHigh(fig: Array<Node>, H :Array<Int>, u :Int) : Int {
    var h1 = 0
    var h2 =0
    if(fig[u].rig != -1) h1 = setHigh(fig, H, fig[u].rig) + 1
    if(fig[u].lef != -1) h2 = setHigh(fig, H, fig[u].lef) + 1
    H[u] = Math.max(h1, h2)
    return Math.max(h1, h2)
}

fun setDep(fig: Array<Node>, D :Array<Int>, u :Int, d :Int) {
   if(u == -1) return
    D[u] = d
    setDep(fig, D, fig[u].rig, d+1)
    setDep(fig, D, fig[u].lef, d+1)
}

fun getSib(fig :Array<Node>, u :Int, root :Int) : Int{
    if(u == root) return -1
    if(fig[fig[u].par].rig != -1 && fig[fig[u].par].rig != u) return fig[fig[u].par].rig
    if(fig[fig[u].par].lef != -1 && fig[fig[u].par].lef != u) return fig[fig[u].par].lef
    return -1
}

fun getDeg(fig: Array<Node>, u: Int, root: Int) : Pair<Int, String> {
    var deg = 0
    var type: String
    if(fig[u].rig != -1) deg++
    if(fig[u].lef != -1) deg++
    type = if(deg == 0) "leaf" else "internal node"
    if(u == root) type = "root"
    return Pair(deg, type)
}


fun abc000a() {
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }


Measured memory_bytes: 32984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int X;
    cin >>X;
    for(int i=0;i<100000;i++){
        int y=i*i*i*i*i;
        int z=abs(X-y);
        int p=pow(z,0.2);
        string w="";
        if(X-y>0) w="-";
        if(p*p*p*p*p==z) {
            cout << i << " "<< w<<p << endl;
            break;
        }
    }



}

Measured memory_bytes: 4092
// In the name of God

#include <bits/stdc++.h>
using namespace std;

int cnt(int x) {
	int ret = 0;
	while(x) {
		ret++;
		x /= 10;
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for(int i=1; i<=n; i++) {
		if(cnt(i) % 2 == 1) ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	r(i,a.size()){
		int f=0;
		r(j,b.size()){
			if(i+j>=a.size())break;
			if(a[i+j]==b[j])f++;
		}
		if(f==b.size())cout<<i<<endl;
	}
}


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

const ll INF = 1LL << 60;

ll N, A, B, C;
vector<P> q;
vector<ll> d;

int main() {
    cin >> N >> A >> B >> C;
    d.push_back(A);
    d.push_back(B);
    d.push_back(C);

    rep(i, N) {
        string s;
        cin >> s;
        int a, b;
        if (s == "AB") {
            a = 0;
            b = 1;
        } else if (s == "BC") {
            a = 1;
            b = 2;
        } else {
            // AC
            a = 0;
            b = 2;
        }

        q.emplace_back(a, b);
    }

    vector<char> ans;
    auto add = [&](int a, int b) {
        d[a]++;
        d[b]--;

        ans.push_back('A' + a);
    };

    rep(i, N) {
        int a = q[i].first;
        int b = q[i].second;

        if (d[a] == 0 && d[b] == 0) {
            cout << "No" << endl;
            return 0;
        }

        if (d[a] == 0) {
            add(a, b);
        } else if (d[b] == 0) {
            add(b, a);
        } else {
            // if (i == N - 1) {
            //     // どっちでもいい
            //     add(a, b);
            //     continue;
            // }
            // cout << "other" << endl;
            int na = q[i + 1].first;
            int nb = q[i + 1].second;
            // cout << na << " " << nb << endl;
            if (a == na || a == nb) {
                add(a, b);
            } else {
                add(b, a);
            }
        }
    }

    cout << "Yes" << endl;
    rep(i, ans.size()) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4308
#include <stdio.h>
int main (void){
int a[300];
int b[300];
int x;
int z;
int i=0;
int v=0;
while(1){

scanf("%d %d",&a[i],&b[v]);
 if (a[i]==0&&b[v]==0)break;
 for (z=0; z<a[i]; z++){
    for (x=0; x<b[v]; x++){
   printf ("#");
    }

 printf ("\n");
 }
i++; v++;
printf ("\n");

}
return 0;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    vector<int> a(n);
    for(int &i: a) cin >> i;
    int cnt = 0;
    for(int i = 1 ; i < n-1; i++)
        cnt += (min(a[i], min(a[i+1], a[i-1])) != a[i] && max(a[i], max(a[i+1], a[i-1])) != a[i]);
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
// 171

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

int main(){
    string s, t;
    cin >> s;
    cin >> t;
    long int count=0;
    for(int i=0; i<s.size(); i++){
        if(s.at(i) != t.at(i)) count++;
    }
    cout << count << endl;
    return 0;
}


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

int main(){
    int N, K, A, A_pop;
    std::cin >> N >> K;
    vector<int> buff(K);
    vector<int> ans(N-K);


    for(int i = 0; i < K; i++){
        std::cin >> buff[i];
    }

    for(int i = 0; i < N-K; i++){
        std::cin >> A;
        A_pop = buff[0];
        if(A_pop < A){
            std::cout << "Yes" << "\n";
        }else{
            std::cout << "No" << "\n";
        }
        buff.erase(buff.begin());
        buff.push_back(A);
    }


}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> vx(N);
    vector<int> vy(N);
    vector<int> vh(N);
    int si = -1;
    for (int i = 0; i < N; ++i) {
        cin >> vx[i] >> vy[i] >> vh[i];
        if (vh[i] > 0) si = i;
    }
    ll resx = -1, resy = -1, resh = -1;
    for (int x = 0; x <= 100; ++x) {
        for (int y = 0; y <= 100; ++y) {
            ll h = vh[si] + abs(x - vx[si]) + abs(y - vy[si]);
            bool ok = true;
            for (int i = 0; i < N; ++i) {
                if (vh[i] > 0 && h - vh[i] != abs(x - vx[i]) + abs(y - vy[i])) ok = false;
                if (vh[i] == 0 && h > abs(x - vx[i]) + abs(y - vy[i])) ok = false;
            }
            if (ok) resx = x, resy = y, resh = h;
        }
    }
    cout << resx << " " << resy << " " << resh << endl;
    return 0;
}

Measured memory_bytes: 3616
a, b = map(int, input().split())

if a + b == 15 and 1 <= a <=15 and 1 <= b <=15:
    print('+')
elif  a * b == 15 and 1 <= a <=15 and 1 <= b <=15:
    print('*')
else:
    print('x')

Measured memory_bytes: 3060
def main():
  H,W,K = map(int,input().split())
  S = [[] for _ in range(H)]
  for i in range(H):
    for s in input():
      S[i].append(int(s))
  #print(S)
  
  ans = 10000
  for i in range(2**(H-1)):
    # 横方向の割り方を全検索する。
    # T:横方向の割り方を固定したときに、同じブロック内のホワイトチョコの個数を縦方向に集約した配列。
    th = bin(i).count('1')
    T = [[0 for _ in range(W)] for _ in range(th+1)]
    ti = 0
    for j in range(H):
      for k in range(W):
        T[ti][k] += S[j][k]
      if (i>>j)&1 == 1:
        ti += 1
    #print(th,T)

    # 縦方向の1列分の中に、Kより大きい個数のホワイトチョコが含まれる場合は
    # どのように割っても条件を満たさないのでスキップする。
    f = True
    for k in range(W):
      for j in range(th+1):
        if T[j][k] > K:
          f = False
    if not f:
      continue

    # 横方向に順にホワイトチョコの数を数えていき、Kを超える場合は割る回数ans0を+1する。
    ans0 = th
    T0 = [0 for _ in range(th+1)]
    for k in range(W):
      f = True
      for j in range(th+1):
        T0[j] += T[j][k]
        if T0[j] > K:
          f = False
      if not f:
        ans0 += 1
        # 割った場合は、カウントしていたホワイトチョコの数をカレントの1列分に戻す。
        for j in range(th+1):
          T0[j] = T[j][k]
    ans = min(ans0,ans)
  print(ans)

main()

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

int main() {

    int N;
    string S;
    cin >> N >> S;

    int cnt = 0;
    rep(i, N-2) if (S.substr(i, 3) == "ABC") cnt++;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    adj_list = {}
    is_red = [False for i in range(N)]
    is_red[0] = True
    num = [1 for i in range(N)]
    for i in range(M):
        input_raw = read_func().strip().split()
        [x, y] = [int(input_raw[0]), int(input_raw[1])]
        if is_red[x - 1] == True:
            is_red[y - 1] = True
            if num[x - 1] <= 1:
                is_red[x - 1] = False
        num[x - 1] -= 1
        num[y - 1] += 1
    print sum(is_red)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7600
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn gcd(a: i64, b: i64) -> i64 {
  if a % b == 0 {
    b
  } else {
    gcd(b, a % b)
  }
}

fn lcm(a: i64, b: i64) -> i64 {
  a * b / gcd(a, b)
}

fn main() {
  let mut a = read::<i64>();
  let mut b = read::<i64>();
  let mut c = read::<i64>();
  let mut d = read::<i64>();
  let mut cnt = 0;

  let min_mul = lcm(c, d);

  let m = (b / c) - ((a - 1) / c);
  let m2 = (b / d) - ((a - 1) / d);
  let m3 = (b / min_mul) - ((a - 1) / min_mul);
  println!("{}", (b - a + 1) - (m + m2 - m3));
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

//空vectorを要素数NのsegTreeとしてzで初期化
template<class T>
void segTree_init(vector<T>& vec, int N, T z) {
	int RN = 1;
	while (RN < N)RN *= 2;
	vec.resize(2 * RN, z);
}

//vecをsegTreeとしてn番目をxに
template<class T>
void segTree_set(vector<T>& vec, int n, T x, function<T(T, T)> f, int k = -1) {
	int RN = (vec.size() + 1) / 2;
	if (k == -1) {
		k = n + RN;
		vec[k] = x;
		segTree_set(vec, n, x, f, k / 2);
	}
	else if (k != 0) {
		vec[k] = f(vec[2 * k], vec[2 * k + 1]);
		segTree_set(vec, n, x, f, k / 2);
	}
}

//vecがsegTreeの時の、n番目の要素
template<class T>
T segTree_at(vector<T>& vec, int n) {
	int RN = (vec.size()) / 2;
	return vec[RN + n];
}

//get [a,b]
template<class T>
T segTree_get(vector<T>& vec, int a, int b, function<T(T, T)> f, T e, int k = 1, int l = 0, int r = -1) {
	if (r == -1)r = vec.size() / 2 - 1;
	if (b < l || r < a)return e;
	else if (a <= l && r <= b)return vec[k];
	else return f(
		segTree_get(vec, a, b, f, e, 2 * k, l, (l + r) / 2),
		segTree_get(vec, a, b, f, e, 2 * k + 1, (l + r) / 2 + 1, r)
	);
}

int N;
vector<int> pos;   //nがどこにあるか(1-index)
vector<int> seg;
function<int(int, int)> lambda = [](int a, int b) {
	return max(a, b);
};
int RN = 1;

void sett(int k) {
	seg[k] = max(seg[2 * k], seg[2 * k + 1]);
	if (k != 1)sett(k / 2);
}

void set(int n, int x) {
	seg[RN + n] = x;
	sett((RN + n) / 2);
}

int get(int a, int b, int k = 1, int l = 0, int r = RN - 1) {
	if (b < l || r < a)return 0;
	if (a <= l && r <= b)return seg[k];
	return max(get(a, b, 2 * k, l, (l + r) / 2), get(a, b, 2 * k + 1, (l + r) / 2 + 1, r));
}

int main() {
	cin >> N;
	pos.resize(N + 1);
	for (int n = 1; n <= N; n++) {
		int a;
		cin >> a;
		pos[a] = n;
	}
	while (RN < N + 2)RN *= 2;
	seg.resize(RN * 2, 0);
	long long ans = 0;
	::set(0, 1);
	::set(N + 1, 1);
	for (int n = 1; n <= N; n++) {
		//左
		int s = 0, e = pos[n];
		while (e - s > 1) {
			int m = (e + s) / 2;
			if (get(m, pos[n]) == 1) {
				s = m;
			}
			else e = m;
		}
		long long left = pos[n] - s;
		s = pos[n], e = N + 1;
		while (e - s > 1) {
			int m = (e + s) / 2;
			if (get(pos[n], m) == 1) {
				e = m;
			}
			else s = m;
		}
		long long right = e - pos[n];
		ans += n * left * right;
		::set(pos[n], 1);
	}
	std::cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		
	int[] men = new int[7];
	int[] meng = new int[7];
	int[] kari = new int[7];
	int ue;
	int yoko;
	int c = 0;
		
	Scanner scan = new Scanner(System.in);
	
	for(int i=1; i<=6; i++){
		meng[i] = scan.nextInt();}
	for(int i=1; i<=6; i++){
		men[i] = scan.nextInt();}
		
	ue = meng[1];
	yoko = meng[2];
		
		for(int i=1; i<=6; i++){
			if(men[i]==ue){
				if(i==2){
					kari[1] = men[1];		kari[2] = men[2];
					kari[5] = men[5];		kari[6] = men[6];
			
					men[1] = kari[2];		men[2] = kari[6];
					men[6] = kari[5];		men[5] = kari[1];
				}
				else if(i==3){
					kari[1] = men[1];		kari[3] = men[3];
					kari[4] = men[4];		kari[6] = men[6];
			
					men[1] = kari[3];		men[3] = kari[6];
					men[4] = kari[1];		men[6] = kari[4];
				}
				else if(i==4){
					kari[1] = men[1];		kari[3] = men[3];
					kari[4] = men[4];		kari[6] = men[6];
			
					men[1] = kari[4];		men[3] = kari[1];
					men[4] = kari[6];		men[6] = kari[3];
				}
				else if(i==5){
					kari[1] = men[1];		kari[2] = men[2];
					kari[5] = men[5];		kari[6] = men[6];
			
					men[1] = kari[5];		men[2] = kari[1];
					men[6] = kari[2];		men[5] = kari[6];
				}
				else if(i==6){
					kari[1] = men[1];		kari[2] = men[2];
					kari[5] = men[5];		kari[6] = men[6];
			
					men[1] = kari[2];		men[2] = kari[6];
					men[6] = kari[5];		men[5] = kari[1];
					
					kari[1] = men[1];		kari[2] = men[2];
					kari[5] = men[5];		kari[6] = men[6];
			
					men[1] = kari[2];		men[2] = kari[6];
					men[6] = kari[5];		men[5] = kari[1];
				}
			}
		}
		
		for(int q=0; q<4; q++){
			if(men[2]==yoko){
				break;
			}
			
			kari[1] = men[1];		kari[2] = men[2];
			kari[5] = men[5];		kari[6] = men[6];
			
			men[1] = kari[2];		men[2] = kari[6];
			men[6] = kari[5];		men[5] = kari[1];
			
			kari[1] = men[1];		kari[3] = men[3];
			kari[4] = men[4];		kari[6] = men[6];
			
			men[1] = kari[4];		men[3] = kari[1];
			men[4] = kari[6];		men[6] = kari[3];
			
			kari[1] = men[1];		kari[2] = men[2];
			kari[5] = men[5];		kari[6] = men[6];
			
			men[1] = kari[5];		men[2] = kari[1];
			men[6] = kari[2];		men[5] = kari[6];
		}
		
		for(int i=1; i<=6; i++){
			if(meng[i]!=men[i]){
				c = 1;
				break;
			}
		}
			
		if(c==0){
			System.out.println("Yes");
		}
		else if(c==1){
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26408
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int s[2][3];
  FOR(2)FORJ(3)scanf("%d",&s[i][j]);
  if(s[0][0]*800+s[0][1]*40+s[0][2]>s[1][0]*800+s[1][1]*40+s[1][2]){
    FOR(3){
      int t=s[0][i];
      s[0][i]=s[1][i];
      s[1][i]=t;
    }
  }
  PRN(s[1][0]-s[0][0]+(s[1][1]*40+s[1][2]>s[0][1]*40+s[0][2]));
  return 0;
}



Measured memory_bytes: 2096
# input
n,a,b = list(map(int,input().split()))
p=10**9+7

#全体の組み合わせの数：All
all_ = pow(2,n,p)

#n本からi本選ぶ組み合わせの数:C[i],i:0~b
C_=[1]*(b+10)
for i in range(1,b+1):
    C_[i] = (C_[i-1] * (n-i+1)%p * pow(i,p-2,p))%p 
# C_

ans = (all_-C_[a]-C_[b])%p
print(ans-1)

Measured memory_bytes: 16604
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;


fn main() {
    input! {
        N: i64,
    }

    let a : i64 = N / 1000;
    let b : i64 = (N -  1000*a )/ 100;
    let c : i64 = (N - 1000 * a-  100*b)/ 10;
    let d : i64 = N%10;

    let ans = if a == b && b == c || b == c && c == d {
        "Yes"
    } else {
        "No"
    };

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


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

int main() {
  int n,k,q,a;
  cin >> n >> k >> q;
  vector<string> point (n,"Yes");
  if (k > q){
    for (int i=0; i<n; i++){
      cout << point.at(i) << endl;
    }
  }
  else{
    vector<int> judge (n);
    for (int i=0; i<q; i++){
      cin >> a;
      judge.at(a-1)++;
    }
    for (int i=0; i<n; i++){
      if (judge.at(i) > q-k){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 1664
int main(int argc, const char * argv[]) {
    
    int card[4][13] = {};
    char color[4] = {'S','H','C','D'};
    
    int n;
    scanf("%d",&n);
    
    int i;
    for(i=0;i<n;i++){
        char c;
        int a;
        scanf(" %c %d",&c,&a);
        
        switch (c) {
            case 'S':
                card[0][a-1] = 1;
                break;
            case 'H':
                card[1][a-1] = 1;
                break;
            case 'C':
                card[2][a-1] = 1;
                break;
            case 'D':
                card[3][a-1] = 1;
                break;
            default:
                break;
        }
    }
    
    int j;
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(card[i][j] == 0){
                printf("%c %d\n",color[i],j+1);
            }
            
        }
    }
    
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; ++i){
        cin >> l[i];
    }
    
    sort(l.begin(), l.end());
    ll res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            int lb = abs(l[i] - l[j]);
            int ub = l[i] + l[j];
            
            int tmp = 0;
            tmp += lower_bound(l.begin(), l.begin() + i, ub) - upper_bound(l.begin(), l.begin() + i, lb);
            tmp += lower_bound(l.begin() + i + 1, l.begin() + j, ub) - upper_bound(l.begin() + i + 1, l.begin() + j, lb);
            tmp += lower_bound(l.begin() + j + 1, l.end(), ub) - upper_bound(l.begin() + j + 1, l.end(), lb);
            res += tmp;
        }
    }
    
    cout << res / 3 << endl;
}


Measured memory_bytes: 256
while True:
  count = int(input())
  if count == 0:break
  else:
    a,b,c,d = [],[],[],[]
    for i in range(count):
      g = map(str,raw_input().split())
      a.append(g[0])
      b.append(g[1])
    tugi = int(input())
    for j in range(tugi):
      r = raw_input()
      for x in range(count):
        if r[0] == a[x]:
          c.append(b[x])
          break
      else: c.append(r[0])
    print ''.join(c)
      

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


int main()
{
    int N;
    vector<int> a(110);
    int alice=0;
    int bob=0;

    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    int turn=0;
    int add;
    while(!a.empty())
    {
        add=a.back();
        a.pop_back();
        if(turn%2==0) alice+=add;
        else bob+=add;

        turn++;
    }

    int ans=alice-bob;
    cout<<ans;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
struct Point{
  double x;
  double y;
};
 
int kock(int,struct Point,struct Point);
 
int main(){
  
  struct Point p1,p2;
  int n;
  
  scanf("%d",&n);
  
  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;
 
 
  printf("%f %f\n", p1.x , p1.y );
  kock(n , p1 , p2 );
  printf("%f %f\n", p2.x , p2.y );
   
  return 0;
}
 
int kock(int n,struct Point a,struct Point b){
  struct Point s, t, u;
 
  if(n==0){
    return 0;
  }
 
  s.x=(2*a.x+1*b.x)/3;
  s.y=(2*a.y+1*b.y)/3;
  
  t.x=(1*a.x+2*b.x)/3;
  t.y=(1*a.y+2*b.y)/3;

  u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;
 
  kock(n - 1,a,s);
  
  printf("%f %f\n",s.x,s.y);
  kock(n - 1,s,u);

  printf("%f %f\n",u.x,u.y);
  kock(n - 1,u,t);

  printf("%f %f\n",t.x,t.y);
  kock(n - 1,t,b);
}



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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e5+5;

int n;
struct edge{
	int x,nxt;
}e[N*2];
int h[N],tot;

void inse(int x,int y){e[++tot].x=y;e[tot].nxt=h[x];h[x]=tot;}

bool vis[N];
int mx[N];
int fa[N];
vector<int>key[N];
int Fa[N];
int val[N];

void dfs(int x){
	vis[x]=1;
	for(int p=h[x];p;p=e[p].nxt)
	if (!vis[e[p].x]){
		Fa[e[p].x]=x;
		mx[e[p].x]=max(mx[x],x);
		dfs(e[p].x);
	}
}

int siz[N];

int getfather(int x){return fa[x]==x?x:fa[x]=getfather(fa[x]);}

int ans[N];
int sta[N],top,pos[N];

void getans(int x){
	sta[pos[x]=++top]=x;
	if (x!=1)ans[x]=ans[x]+ans[mx[x]]-val[sta[pos[mx[x]]+1]];
	vis[x]=1;
	for(int p=h[x];p;p=e[p].nxt)
	if (!vis[e[p].x])getans(e[p].x);
	top--;
}

int main(){
	n=get();
	fo(i,2,n){
		int x=get(),y=get();
		inse(x,y);
		inse(y,x);
	}
	dfs(1);
	fo(i,1,n)fa[i]=i,siz[i]=1;
	siz[1]=0;
	fo(i,2,n)key[mx[i]].push_back(i);
	fo(i,1,n){
		for(auto x:key[i]){
			if (x<i)ans[x]=siz[getfather(x)];
			else{
				for(int p=h[x];p;p=e[p].nxt)
				if (e[p].x<i){
					int v=siz[getfather(e[p].x)];
					if (Fa[e[p].x]==x)val[e[p].x]=v;
					ans[x]+=v;
				}
				ans[x]++;
			}
		}
		for(int p=h[i];p;p=e[p].nxt)
		if (e[p].x<i){
			int fx=getfather(i),fy=getfather(e[p].x);
			fa[fx]=fy;
			siz[fy]+=siz[fx];
		}
	}
	fo(i,1,n)vis[i]=0;
	getans(1);
	fo(i,2,n)printf("%d%c",ans[i],i==n?'\n':' ');
	return 0;
}

Measured memory_bytes: 23796
import re

# .にすることで正規表現で任意の文字列として扱う
S = input().replace('?', '.')
T = input()
ls = len(S)
lt = len(T)

for i in range(ls-lt,-1,-1):
    # Sの一部にTが含まれるかチェック
    if re.match(S[i:i+lt], T):
        S = S.replace('.', 'a')
        # i~i+lsとTの文字の部分に置き換えることで、Tを含む文字が作れる
        S = (S[:i]+T+S[i+lt:])
        print(S)
        exit(0)
print('UNRESTORABLE')

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

const int MAXN = 100005;
int n, a[MAXN];

int main()
{
	scanf("%d", &n);
	int up, down;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]), up = max(up, a[i]);
	int x, y;
	if (up%2 == 1) {
		x = up/2, y = x+1;
	} else x = y = up/2;
	int cur = 0, cur_dis = 1e9+7;
	for (int i = 1; i <= n; i++)
		if (min(abs(x-a[i]), abs(y-a[i])) <= cur_dis) {
			cur = a[i];
			cur_dis = min(abs(x-a[i]), abs(y-a[i]));
		}
	cout << up << " " << cur << endl;		
	return 0;
}


Measured memory_bytes: 640
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 500 + 20 , M = 3e4 + 20 ;
int n , a[N][N] ;
bool np[M] ;
vector <int> vec ;

inline void add (int &a , int b) {
	a = a / __gcd(a , b) * b ;
}

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

	cin >> n ;

	if (n == 2) {
		cout << "4 7\n23 10\n" ;
		return 0 ;
	}

	np[0] = np[1] = 1 ;
	for (int i = 2 ; i < M ; i ++) {
		if (np[i]) continue ;

		vec.push_back(i) ;

		for (int j = 2 * i ; j < M ; j += i) np[j] = 1 ;
	}

	for (int i = 0 ; i < n ; i ++)
		for (int j = 0 ; j < n ; j ++)
			if (((i + j) & 1) == 0) 
				a[i][j] = vec[(i + j) >> 1] * vec[((i - j + n) >> 1) + n] ;

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

	for (int i = 0 ; i < n ; i ++) {
		for (int j = 0 ; j < n ; j ++) cout << a[i][j] << ' ' ;
		cout << '\n' ;
	}
}

Measured memory_bytes: 5248
// luogu-judger-enable-o2
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int wb[1000010],wc[1000010],wa[1000010],n,sa[1000010],k;
char s[1000100];
void get_sa()
{
    int *x=wa,*y=wc;
    int m=150;
    for(register int i=0;i<=m;++i) wb[i]=0;
    for(register int i=1;i<=n;++i) wb[x[i]=s[i]]++;
    for(register int i=1;i<=m;++i) wb[i]+=wb[i-1];
    for(register int i=n;i>=1;--i) sa[wb[x[i]]--]=i;
    for(register int j=1,p=0;p<n;m=p,j<<=1)
    {
        p=0;
        for(register int i=n-j+1;i<=n;++i) y[++p]=i;
        for(register int i=1;i<=n;++i) if(sa[i]>j)y[++p]=sa[i]-j;
        for(register int i=0;i<=m;++i) wb[i]=0;
        for(register int i=1;i<=n;++i) wb[x[y[i]]]++;
        for(register int i=1;i<=m;++i) wb[i]+=wb[i-1];
        for(register int i=n;i>=1;--i) sa[wb[x[y[i]]]--]=y[i];
        swap(x,y);
        p=1;x[sa[1]]=1;
        for(register int i=2;i<=n;++i) x[sa[i]]=y[sa[i]]==y[sa[i-1]]&&y[sa[i]+j]==y[sa[i-1]+j]?p:++p;
    }
}
int main()
{
    scanf("%s",s+1);
    scanf("%d",&k);
    n=strlen(s+1);
    get_sa();
    int st,ed;
    for(register int i=1;i<=n;++i)
    {
    	if(i!=1)
    	{
    		int j=sa[i-1];
    		int t=sa[i];
    		while(s[j]==s[t]) j++,t++,k++;
		}
    	if((n-sa[i]+1)<k)
    	{
    		k-=(n-sa[i]+1);
    		continue;
		}
		else 
		{
			st=sa[i],ed=sa[i]+k-1;break;
		}
	}
	for(register int i=st;i<=ed;++i)
	{
		putchar(s[i]);
	}
    return 0;
} 

Measured memory_bytes: 6400