akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    int a,b,c,d,x,y;
    cin >> a >> b >> c >>d;

    x = min(b,d);
    y = max(a,c);
    
    if(x-y>0) cout << x-y << endl;
    else cout << 0 << endl;

    return 0;
}

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

int main(){
   ll n; cin>>n;
   cout<<n*(n-1)/2<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n;
    cin >> n;
    int cnt = 0,len = 1;
    vector<int> a(n+1);
    rep(i,n) cin >> a[i];
    a[n] = -1;
    rep(i,n){
        if(a[i] == a[i+1]){
            len++;
        }else{
            if(len > 1){
                cnt += len/2;
            }
            len = 1;
        }
    }
    
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,m;
    cin >> n >> m;
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    vector<int> v(m);
    for(int i=0;i < m;i++)
    {
        cin >> v.at(i);
    }
    sort(v.begin(),v.end());
    priority_queue<int> q;
    
    for(int i=0;i < m-1;i++)
    {
        q.push(v.at(i+1)-v.at(i));
    }

    int total=0;
    
    for(int i=0;i < n-1;i++)
    {
        total += q.top();
        q.pop();
    }

    cout << v.at(m-1)-v.at(0)-total << endl;
}

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

typedef long long ll;
const int MAX_N = 5030;    // Change as necessary
const ll  MODD = 1000000009; //

int A[MAX_N];
bool B[2][MAX_N][MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n,K; cin >> n >> K;
  for(int i=0;i<n;i++) cin >> A[i];
  
  sort(A,A+n);

	B[0][0][0] = true;
	for(int i=0;i<n;i++){
		for(int j=0;j<=K;j++) B[0][i+1][j] = B[0][i][j];
		for(int j=0;j<=K;j++)
			if(B[0][i][j])
				B[0][i+1][min(K,j+A[i])] = true;
	}

	B[1][n][0] = true;
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<=K;j++) B[1][i][j] = B[1][i+1][j];
		for(int j=0;j<=K;j++)
			if(B[1][i+1][j])
				B[1][i][min(K,j+A[i])] = true;
	}

	int ans = 0;
	for(int i=0;i<n;i++){
		vector<int> v;
		for(int j=0;j<=K;j++)
			if(B[0][i][j])
				v.push_back(j);
		
		bool found = true;
		for(int j=0;j<=K;j++)
			if(B[1][i+1][j]){
				int idx = lower_bound(v.begin(),v.end(),K-A[i]-j)-v.begin();
				for(int kk=-1;kk<=1;kk++){
					if(!(0 <= idx+kk && idx+kk < v.size())) continue;
					if((K-A[i] <= j+v[idx+kk] && j+v[idx+kk] < K)) { found = false; }
				}
				idx = lower_bound(v.begin(),v.end(),K-j)-v.begin();
				for(int kk=-1;kk<=1;kk++){
					if(!(0 <= idx+kk && idx+kk < v.size())) continue;
					if((K-A[i] <= j+v[idx+kk] && j+v[idx+kk] < K)) { found = false; }
				}
			}
			ans += found;
	}

	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 49664
import numpy as np

N, A = map(int, input().split())
X = [0] + list(map(int, input().split()))
NX = N * max(X + [A])

dp = np.zeros((N + 1, 2 * NX + 1), dtype=int)

dp[0][NX] = 1

for j in range(1, N + 1):
    y = X[j] - A
    for t in range(2 * NX + 1):
        if 0 <= t - y < 2 * NX:
            dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
        else:
            dp[j][t] = dp[j - 1][t]

print(dp[N][NX] - 1)


Measured memory_bytes: 14436
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int A[1000000],n,cnt=0;
int G[100];
void shell(int n){
	int ij=0;
	for (int h=1;h<=n;h=3*h+1) G[ij++]=h;
	printf("%d\n",ij--);
	for	(int i=ij;i>=0;i--){
		printf("%d",G[i]);
		if (i==0) printf("\n");
		else printf(" ");
	}
	for (int D=G[ij];D>=1;D=G[ij--]){
		for (int i=D;i<n;i++){
			int v=A[i],j=i-D;
			while(j>=0&&A[j]>v){ 
				A[j+D]=A[j];
				j-=D;
				cnt++;
			}
			A[j+D]=v;
		}	
	}
	printf("%d\n",cnt);
	for (int i=0;i<n;i++) printf("%d\n",A[i]);	
}
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",&A[i]);
	shell(n);	
} 


Measured memory_bytes: 7056
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

map<string, string> mp, mpg,mpa;

/*--------------------template--------------------*/

int main()
{
	cin >> s;
	REP(i, s.size())
	{

		if (s[i] == 'A') {
			if (i != s.size() - 1 && s[i + 1] == 'C') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

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

int main()
{
    int x;
    for (int i = 0; i < 5; i++)
    {
        cin >> x;
        if (x == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}


int main(){
    int n=in();
    vec p(n),a(n),b(n);
    rep(i,n){
        int x=in()-1;
        p[x]=(int)i;
    }
    rep(i,n){
        a[i]= (int)(30000*(i+1));
        b[i]=(int)(30000*(n-i)) + p[i];
    }
    REP(e,a)cout<<e<<" ";
    cout<<endl;
    REP(e,b)cout<<e<<" ";
    cout<<endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
    ll a,b ,c,k ;
    cin >> a >> b >>c>>k ;
    if(k<a)
    cout << k<< endl;
    else if(k<=a+b)
    cout << a<<endl ;
    else

  cout <<-k+2*a+b<<endl ; 
    return 0;
}

Measured memory_bytes: 3596
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


ll N;
unordered_map<ll, bool> a;
ll result = 0;

int main() {
    std::cin >> N;
    for (int i = 0; i < N; i++) {
        ll tmp;
        std::cin >> tmp;
        if(a[tmp]){
            a.erase(tmp);
            result--;
        }else{
            a[tmp]=true;
            result++;
        }
    }
    std::cout << result << std::endl;
}



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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

template <typename _Ty>
struct Edge {
    int src, to;
    _Ty cost;

    constexpr Edge(int _to, _Ty _cost) noexcept
        : src(-1), to(_to), cost(_cost) {}
    constexpr Edge(int _src, int _to, _Ty _cost) noexcept
        : src(_src), to(_to), cost(_cost) {}
};
template <typename _Ty>
using WeightedGraph = std::vector<std::vector<Edge<_Ty>>>;

template <typename _Ty>
void dijkstra(std::vector<_Ty>& dist, std::vector<int>& prev,
              const WeightedGraph<_Ty>& g, int s) {
    constexpr _Ty inf = std::numeric_limits<_Ty>::max();
    dist.assign(g.size(), inf);
    prev.assign(g.size(), -1);

    using Pi = std::pair<_Ty, int>;
    std::priority_queue<Pi, std::vector<Pi>, std::greater<Pi>> q;
    dist[s] = 0;
    q.emplace(dist[s], s);
    while (!q.empty()) {
        _Ty cost;
        int idx;
        tie(cost, idx) = q.top();
        q.pop();
        if (dist[idx] < cost) continue;
        for (const auto& edge : g[idx]) {
            _Ty next_cost = cost + edge.cost;
            if (next_cost >= dist[edge.to]) continue;
            dist[edge.to] = next_cost;
            prev[edge.to] = idx;
            q.emplace(next_cost, edge.to);
        }
    }
}

Vi dist, prev_idx;
WeightedGraph<int> g;
Vi checked;
Vi tami;

int dfs(int u) {
    int tmp = dist[u];
    for (const auto& to : g[u]) {
        if (checked[to.to] != 0) continue;
        checked[to.to] = 1;
        tmp = max(tmp, dfs(to.to));
    }
    tami[u] = tmp;
    return tmp;
}

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

    int N, U, V;
    cin >> N >> U >> V;
    --U;
    --V;

    g.resize(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].emplace_back(b, 1);
        g[b].emplace_back(a, 1);
    }

    dijkstra(dist, prev_idx, g, V);

    tami.resize(N);
    checked.resize(N);
    checked[V] = 1;
    dfs(V);

    int ad = (dist[U] - 1) / 2;

    int max_tami = tami[U];
    int tmpU = U;
    for (int i = 0; i < ad; ++i) {
        tmpU = prev_idx[tmpU];
        max_tami = max(max_tami, tami[tmpU]);
    }

    cout << max_tami - 1 << endl;

    return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(){
    ll n,a,b,k,l;
    cin>>n>>a>>b;
    k = n%(a+b);
    l = n/(a+b);
    if(k>a) k = a;
    cout<<a*l + k;
}

Measured memory_bytes: 256
C = input()
List = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"]
i = List.index(C)
print(List[i + 1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long long n,k,a[100000009],ans;
map<long long,long long> m1;
int main()
{
	cin>>n;
	for(k=1;k<=n;k++)
	{
		cin>>a[k];
		m1[a[k]+k]++;
	}
	for(k=1;k<=n;k++)
	{
		if(m1[k-a[k]]>0) ans+=m1[k-a[k]];
	}
	cout<<ans;
}
/*
a[i]+a[j]=j-i;
a[i]+i=j-a[j];
*/

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

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

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=5e5+500;

ll x[maxn];
ll sx[maxn];
ll rx[maxn];

ll par[maxn];
ll maxy[maxn];

ll par2[maxn];
vector<pii> NOTOK[maxn];

ll findPar2(ll a){
	if(a==par2[a])return a;
	par2[a]=findPar2(par2[a]);
	return par2[a];
}
void merge2(ll a,ll b){
	a=findPar2(a);
	b=findPar2(b);
	if(a!=b){
		par2[a]=b;
	}
}
ll findPar(ll a){
	if(a==par[a])return a;
	par[a]=findPar(par[a]);
	return par[a];
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<n;i++){
		cin>>x[i];
		sx[i]=x[i];
	}
	vector<pair<ll,pii> > yal;

	for(ll i=0;i<m;i++){
		ll a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		yal.pb(mp(c,mp(a,b)));
	}
	sort(yal.begin(),yal.end());
	for(ll i=0;i<n;i++){
		par[i]=i;
		maxy[i]=0;
		par2[i]=i;
	}
	for(auto e:yal){
		ll a=e.S.F;
		ll b=e.S.S;
		ll w=e.F;
		ll pa=findPar(a);
		ll pb=findPar(b);
		if(pa!=pb){	
			if(NOTOK[pa].size()<NOTOK[pb].size()){
				swap(pa,pb);
				swap(a,b);
			}
			maxy[pa]=max(maxy[pa],maxy[pb]);
			maxy[pa]=max(maxy[pa],w);
			par[pb]=pa;
			x[pa]+=x[pb];
			for(auto e:NOTOK[pb]){
				NOTOK[pa].pb(e);
			}
			NOTOK[pb].clear();
			NOTOK[pa].pb(e.S);
			if(maxy[pa]<=x[pa]){
				for(auto u:NOTOK[pa]){
					merge2(u.F,u.S);
				}
				NOTOK[pa].clear();
			}
/*
			cout<<pb<<" DEAD\n";
			cout<<pa<<' '<<maxy[pa]<<' '<<x[pa]<<" $#$ ";
			for(auto rrr:NOTOK[pa])cout<<(rrr.F)<<":"<<(rrr.S)<<"   ";
			cout<<endl;
*/
		}
	}	
	for(ll i=0;i<n;i++){
	//	cout<<i<<":"<<findPar2(i)<<endl;
		rx[findPar2(i)]+=sx[i];
	}
	ll ans=0;
	for(ll i=0;i<m;i++){
		ll a=yal[i].S.F;
		ll b=yal[i].S.S;
		ll w=yal[i].F;
		if(findPar2(a)!=findPar2(b) || rx[findPar2(a)]<w){
			ans++;
		}
	}
	cout<<ans;
	
}




















Measured memory_bytes: 41584
import math
from functools import reduce

def LCM_base(x, y):
    return (x * y) // math.gcd(x, y)


# 最小公倍数（リスト引数）
def LCM_list(numbers):
    return reduce(LCM_base, numbers, 1)


N = int(input())
T = [int(input()) for x in range(N)]

lcm = LCM_list(T)
print(lcm)

Measured memory_bytes: 67552
import sys
import numpy as np

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 = int(input_raw[0])
    point_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        point_list.append(int(input_raw[0]))

    sum_point = sum(point_list)
    while (1):
        if sum_point % 10 != 0 or len(point_list) == 0:
            break;
        max_sum_point = 0
        remove_idx = 0
        remove_point_list = []
        for i in range(len(point_list)):
            #remove_point_list.append(sum_point - point_list[i])
            if (sum_point - point_list[i]) % 10 != 0 and sum_point - point_list[i] > max_sum_point:
                max_sum_point = sum_point - point_list[i]
        if max_sum_point == 0:
            point_list.remove(min(point_list))
        sum_point = max_sum_point

    print sum_point




if __name__ == '__main__':
    main()


Measured memory_bytes: 17776
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    string s; cin>>s;

    cout << string((int)s.size(), 'x') << endl;

    return 0;
}

Measured memory_bytes: 384
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {

        var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = NM[0];
        var A = NM[1];
        var B = NM[2];


        if(A > B || (A != B && N == 1))
        {
            Console.WriteLine(0);
        }
        else
        {
            Console.WriteLine((B - A) * (N - 2) + 1);
        }
        

    }


    
}


Measured memory_bytes: 28140
n,m = map(int,input().split())
aa = []
kk=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    kk.append(tmp[0])
    aa.append(tmp[1:])

aaa = []
for a in aa:
    for ai in a:
        aaa.append(ai)
ans=0
for i in range(m):
    if aaa.count(i+1)==n:
        ans+=1
print(ans)

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())

    cnt = [0] * (N + 1)
    for _ in range(M):
        a, b = map(int, input().split())
        cnt[a] += 1
        cnt[b] += 1

    ans = "YES" if all(c % 2 == 0 for c in cnt) else "NO"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve77(string s) {
    REP(i,s.size()) {
        if (s[i] != '@') cout << s[i];
        else {
            REP(j,s[i+1]-'0') cout << s[i+2];
            i+=2;
        }
    }
    cout << endl;
}

int main() {
    string s;
    while (cin >> s) {
        solve77(s);
    }
    return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	list<int> l;
	while(n--){
		string ins;
		long int x;
		cin >> ins;
		if(ins == "insert"){
			cin >> x;
			l.push_front(x);
		}
		else{
			if(ins == "delete"){
				cin >> x;
				for(list<int>::iterator it = l.begin(); it != l.end(); it++){
					if(x == *it) {
						l.erase(it);
						break;
					}
				}
			}
			else{
				if(ins == "deleteFirst"){
					l.pop_front();
				}
				else{
					l.pop_back();
				}
			}
		}
	}
	while(!l.empty()){
		cout << l.front();
		l.pop_front();
		if(!l.empty()) cout << " ";
	}
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 34484
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

vector<vector<ll>> a(20, vector<ll>(20,0));
vector<ll> dp((1<<18),-longinf);
int n;

ll rec(ll x){
  if(dp[x]!=-longinf) return dp[x];
  ll cur = 0;
  rep(i,n)rep(j,i)if(bit(x,i) && bit(x,j)){ cur += a[i][j]; }
  for(ll i=(1<<n)-1; i>=0; i--){
    i &= x; //x bubun syugo //https://primenumber.hatenadiary.jp/entry/2016/12/01/000000
    if(i==x || i==0) continue;
    cur = max(cur, rec(i) + rec(i^x));
  }
  return dp[x] = cur;
}

int main(){
  cin >> n;
  rep(i,n)rep(j,n){
    cin >> a[i][j];
  }
  ll ans = rec((1<<n)-1);
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>

void trace(int A[], int N)
{
  int i;
  for(i=0; i<N; i++){
    if(i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}


void insertSort(int A[], int N)
{
  int j, i, v;
  for(i=1; i<N; i++){
    v = A[i];
    j = i - 1;
    while(j>=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}

int main()
{
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for(i=0; i<N; i++) scanf("%d", &A[i]);

  trace(A, N);
  insertSort(A, N);

  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int a[50],b[50],c[50],d[50],N,M,distance[50],answer[50],min_distance[50];

  cin>>N>>M;

  REP(i,N){
    cin>>a[i]>>b[i];
  }

  REP(i,M){
    cin>>c[i]>>d[i];
  }

  REP(i,N){
    min_distance[i] = 1000000000;
    REP(j,M){
      distance[j] = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if (distance[j] < min_distance[i]) {
        min_distance[i] = distance[j];
        answer[i] = j+1;
      }
    }
    cout<<answer[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i,n) for(i = 0; i < n; i++)
#define FOR(i,m,n) for(i = m, i < n; i++)
#define repr(i,n) for(i = n; i >= 0; i--)
#define INF = 999999999
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
const int MOD = 1000000007;

  
int main(){
  int x,y,z;
  cin >> x >> y >> z;
  cout << (x - z) / (y + z) << endl;

  return 0;
}
       


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

void solve(){
    int n,m;
    cin>>n>>m;
    
    vector<bool> AC(n+1,false);
    vector<int> P(n+1,0);
    
    int ac=0,pen=0;
    
    for(int i=0;i<m;i++){
        int pro;
        string s;
        cin>>pro>>s;
        if(AC[pro]==false){
            if(s=="AC"){
                pen+=P[pro];
                AC[pro]=true;
                ac++;
            }
            else{
                P[pro]++;
            }
        }
    }
    cout<<ac<<" "<<pen;
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

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

using namespace std;

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    if(n==1)
        cout << 0;
    else
        cout << 1;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int time;
	cin >> time;
	int hour = time / 3600;
	int min = time % 3600 / 60;
	int second = time % 3600 % 60;

	cout << hour << ":" << min << ":" << second << endl;
}



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


// 数字と、桁数を渡す
int same(int n,int d){
    vector<int> vec;
    int count = 0;

    for (int i=0; i<d; i++){
        vec.push_back(n%10);
        n = floor(n/10);
    }

    for (int i=0; i<vec.size(); i++){
        if(vec[0] == vec[i]) count++;
    }

    return count;
}

int main() {
    int n,abc,bcd,counta,countb;
    counta = 0;
    countb = 0;

    cin >> n;

    abc = floor(n / 10);
    bcd = n % 1000;

    abc = same(abc,3);
    bcd = same(bcd,3);

    if(max(abc,bcd) >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

struct Gamestate {
	int hand[2][2];
	int turn;
};

int dfs(Gamestate p) {
	if (p.hand[p.turn][0] >= 5 && p.hand[p.turn][1] >= 5)
		return -1;
	for (int i = 0; i < 2; i++) {
		if (p.hand[p.turn][i] >= 5) continue;
		for (int j = 0; j < 2; j++) {
			if (p.hand[1 - p.turn][j] >= 5) continue;
			p.hand[1 - p.turn][j] += p.hand[p.turn][i];
			p.turn = 1 - p.turn;
			if (dfs(p) == -1) return 1;
			p.turn = 1 - p.turn;
			p.hand[1 - p.turn][j] -= p.hand[p.turn][i];
		}
	}
	return -1;
}

int main() {
	Gamestate p;
	p.turn = 0;
	cin >> p.hand[0][0] >> p.hand[0][1] >> p.hand[1][0] >> p.hand[1][1];
	if (dfs(p) == 1) cout << "ISONO" << endl;
	else cout << "NAKAJIMA" << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

//素数判定
bool IsPrime(int num)
{
	if (num < 2) return false; //2未満は素数でない
	else if (num == 2) return true; //2は素数である
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false; // 素数でない
		}
	}

	return true; // 素数である
}

int main() {
	int q;
	cin >> q;
	vector<pair<int,int>> range(q);
	int mx = 0;
	rep(i, 0, q) {
		int L, R;
		cin >> L >> R;
		range[i].first = L; range[i].second = R;
		mx = max(R, mx);
	}
	//iが2017に似ているかどうかを判定
	vector<bool> same(mx); 
	rep(i, 0, mx + 1) {
		if (IsPrime(i) && IsPrime((i + 1) / 2)) same[i] = true;
	}
	//累積和で範囲を数え上げ
	vector<LL> accum(mx + 1);
	rep(i, 0, mx + 1) accum[i + 1] = accum[i] + same[i];
	rep(i, 0, q) {
		cout << accum[range[i].second + 1] - accum[range[i].first] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }

        System.out.println(solve(A, B) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int[] A, int[] B) {
        int[] sortedIndices = IntStream.range(0, A.length).boxed().sorted((i1, i2) -> Integer.compare(B[i1], B[i2]))
                .mapToInt(x -> x).toArray();

        int time = 0;
        for (int index : sortedIndices) {
            time += A[index];
            if (time > B[index]) {
                return false;
            }
        }

        return true;
    }
}

Measured memory_bytes: 67236
package main

import "fmt"

func main() {

	var n, m, a_ij, b_j int
	fmt.Scan(&n, &m)
	
	a := make([][]int, n)
	for i:=0; i<n; i++ {
		a[i] = make([]int, m)
		for j:=0; j<m; j++ {
			fmt.Scan(&a_ij)
			a[i][j] = a_ij
		}
	}
	b := make([]int, m)
	for j:=0; j<m; j++ {
		fmt.Scan(&b_j)
		b[j] = b_j
	}

	c := make([]int, n)
	for i:=0; i<n; i++ {
		c[i] = 0
		for j:=0; j<m; j++ {
			c[i] += a[i][j]*b[j]
		}
		fmt.Println(c[i])
	}

}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;

const int N=1e9+5;

int main(){
    ll N; cin >> N;
    ll val_2=0, val_5=0;
    ll cnt=2;
    ll res=0;
    if(N%2 == 0){
        while(N/cnt > 0){
            val_2+=N/cnt;
            cnt*=2;
        }
        cnt=5;
        while(N/cnt > 0){
            val_5+=N/cnt/2;
            cnt*=5;
        }
        res=min(val_2, val_5);
    }
    else res=0;
    cout << res << endl;
    return 0;
}

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

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  cout << ((a <= x && x <= a + b) ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>

int main()
{
    long long D, T, S;
    std::cin >> D >> T >> S;

    long long gap = S*T-D;
    if(gap >= 0)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    

}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main a = new Main();
        a.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a = scan.nextInt();
        int b = scan.nextInt();
        int answer = a - 1;
        if (a <= b) {
            answer += 1;
        }
        System.out.println(answer);
    }

}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    string s;
    int q;
    cin >> s >> q;
    string b = "";
    string head = "", tail = "";
    
    int n = s.length();
    int r = 0;
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            r += 1;
        }
        else if (t == 2) {
            int f;
            char c;
            cin >> f >> c;
            if (r % 2 == 0) {
                if (f == 1) {
                    head = c + head;
                }
                else if (f == 2) {
                    tail = tail + c;
                }
            }
            else {
                if (f == 1) {
                    tail = tail + c;
                }
                else if (f == 2) {
                    head = c + head;
                }
            }
        }
    }

    if (r % 2 == 0) {
        cout << head + s + tail;
    } 
    else {
        reverse(s.begin(), s.end());
        reverse(head.begin(), head.end());
        reverse(tail.begin(), tail.end());
        cout << tail + s + head << endl;
    }

    return 0;
}

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

void solve(int N, vector<string> S)
{
    int res = 1;
    for (int s = 0; s < N; s++)
    {
        vector<int> t(N);
        t.at(s) = 1;
        queue<int> q;
        q.push(s);
        while (!q.empty())
        {
            int u = q.front();
            q.pop();
            for (int v = 0; v < N; v++)
            {
                if (S.at(u).at(v) == '0')
                    continue;
                if (t.at(v) > 0)
                {
                    if (t.at(u) == t.at(v))
                    {
                        cout << -1 << endl;
                        return;
                    }
                }
                else
                {
                    t.at(v) = t.at(u) + 1;
                    res = max(res, t.at(v));
                    q.push(v);
                }
            }
        }
    }
    cout << res << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++)
    {
        cin >> S.at(i);
    }
    solve(N, move(S));
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#define re register
using namespace std;
int t[100000+10];
inline char nc() 
{
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
inline int read()
{
	re int n=0,ch=nc();
	while(ch<'0'||ch>'9')ch=nc();
	while(ch>='0'&&ch<='9')
		{
			n=(n<<3)+(n<<1)+ch-'0';
			ch=nc();
		}
	return n;
}
void write(int n)
{
	if(n>=10)write(n/10);
	putchar(n%10+'0');
}
int main()
{
	re int s=0,N,M;
	N=read();
	re int j;
	N-=4;
	for(j=1;j<=N;j+=4)
		{
			s+=t[j]=read();
			s+=t[j+1]=read();
			s+=t[j+2]=read();
			s+=t[j+3]=read();
		}
	for(;j<=N+4;++j)
		s+=t[j]=read();

	M=read();
	re int p,x;	
	re int k;
	M-=4;
	for(k=1;k<=M;k+=4)
		{
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
		}
	for(;k<=M+4;++k)
		{
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
		}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<pair<string,int>,int>> vec(n);
  int i;
  for(i=0;i<n;i++){
    int a;
    string s;
    cin >> s >> a;
	vec.at(i)=make_pair(make_pair(s,-a),i);
  }
  sort(vec.begin(),vec.end());
  for(i=0;i<n;i++){
    cout << vec.at(i).second+1 << endl;
  }
}
    

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(auto& i : a) cin >> i;
    if(any_of(a.begin(), a.end(), [](ll x){ return !x; })) return !puts("0");
    __int128_t s = 1;
    for(auto& i : a){
        s *= i;
        if(s > 1'000'000'000'000'000'000) return !puts("-1");
    }
    cout << ll(s) << endl;
}

Measured memory_bytes: 4000
#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

//
// Main
//

fn main() {
    let (n, an, mut xs) = {
        input! {
            n: usize,
            m: usize,
            an: [u64; n],
            xs: [(usize, u64); m],
        }
        (n, an, xs)
    };

    xs.sort_by(|x1, x2| x2.1.cmp(&x1.1));
    let ys = xs.into_iter().flat_map(|(b, c)| vec![c; b]).take(n).vec();

    let mut heap = BinaryHeap::new();

    for x in an.into_iter().chain(ys) {
        heap.push(x);
    }

    let ans = (0..n).fold(0, |a, _| a + heap.pop().unwrap());
    println!("{}", ans);
}


Measured memory_bytes: 11360
n, m = map(int, input().split())
V = n + m
par = [i for i in range(V)]
sizes = [1] * V


def f(x):
    if x == par[x]:
        return x
    par[x] = f(par[x])
    return par[x]


def unite(x, y):
    x, y = f(x), f(y)
    if x == y:
        return
    if sizes[x] < sizes[y]:
        x, y = y, x
    par[y] = x
    sizes[x] += sizes[y]


for i in range(n):
    for l in [int(k)for k in input().split()][1:]:
        unite(i,l-1+n)
print("NO"if len([i for i in range(n)if f(i)!=f(0)])>0 else"YES")


Measured memory_bytes: 12592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 310;
int dist[maxn][maxn], n;
bool vis[maxn][maxn];

int main(void) {
    while(~scanf("%d", &n)) {
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                scanf("%d", dist[i] + j);
                vis[i][j] = 0;
            }
        }
        bool flag = true;
        for(int k = 0; k < n && flag; ++k) {
            for(int i = 0; i < n && flag; ++i) {
                for(int j = 0; j < n & flag; ++j) {
                    if(k == i || k == j || i == j) continue;
                    if(dist[i][k] + dist[k][j] < dist[i][j]) {
                        flag = false;
                        break;
                    }
                    if(dist[i][k] + dist[k][j] == dist[i][j]) vis[i][j] = true;
                }
            }
        }
        if(!flag) {
            puts("-1");
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n - 1; ++i) {
            for(int j = i + 1; j < n; ++j)
                if(!vis[i][j]) ans += (ll)dist[i][j];
        }
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
const int INF = 1<<30;

int main(){
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n-i; j++) {
			int k = n - i - j;
			int rest = y - 1000 * i - 5000 * j;
			if(k >= 0 && rest >= 0 && rest % 10000 == 0 && 10000 * k == rest){
				cout << k << " " << j << " " << i << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1"<< endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define MAX 1000001
struct node{
	int p,l,r;
};
struct node t[MAX];
int deep[MAX];
int  getDepth(int u){
	int d=0;
	while(t[u].p!=NIL){
		u=t[u].p;
		d++;
	}
	return d;
}
void setDepth(int u,int d){
	deep[u]=d;
	if(t[u].r!=NIL)
	setDepth(t[u].r,d);
	if(t[u].l!=NIL)
	setDepth(t[u].l,d+1);
}
void printChildren(int u){
	int c=t[u].l;
	int time=0;
	printf(", [");
	while(c!=NIL){
		if(time)
		printf(", ");
		printf("%d",c);
		c=t[c].r;
		time++;
	}
	printf("]\n");
}
int main(){
    int n,i,j,k;
    scanf("%d",&n);
    for(i=0;i<n;i++){
    	t[i].l=NIL;
    	t[i].p=NIL;
    	t[i].r=NIL;
	}//初始化 
    int id[n];
    for(i=0;i<n;i++){
    	scanf("%d%d",&id[i],&k);
    	if(k){
    	int ch[k];
    	for(j=0;j<k;j++){
    		scanf("%d",&ch[j]);
            if(j)
            t[ch[j-1]].r=ch[j];
            t[ch[j]].p=id[i];
		}
		t[id[i]].l=ch[0];}
	}//输入 
    for(i=0;i<n;i++){
    	deep[i]=getDepth(i);
	}//求深度 
	for(i=0;i<n;i++){
		printf("node %d: parent = %d, depth = %d, ",i,t[i].p,deep[i]);
		if(deep[i]==0)
		printf("root");
		else if(t[i].l==NIL)
		printf("leaf");
		else
		printf("internal node");
		printChildren(i);
	}
	return 0;
}


Measured memory_bytes: 4128
#include "bits/stdc++.h"
using namespace std;
const int MAX_INT = 1000000;
bool is_prime[MAX_INT + 1];
int prime[MAX_INT];

//エラトステネスの篩(素数の数を返している)
//11→2,3,5,7,11

int sieve(long long  n) {
	int p = 0;
	is_prime[0] = false;
	is_prime[1] = false;
	for (int m = 2; m <= n; ++m) {//初期化
		is_prime[m] = true;
	}

	for (int m = 2; m <= n; ++m) {
		if (is_prime[m]) {
			++p;
			prime[p] = m;
			for (int l = 2 * m; l <= n; l += m) {
				is_prime[l] = false;
			}
		}
	}
	return p;
}

int main() {
	sieve(100000);
	vector<int>sum(100000 + 1);
	for (int i = 1; i < 100000; ++i) {
		sum[i] = sum[i - 1];
		if (1 == i % 2) {
			if (is_prime[i] && is_prime[(i + 1) / 2]) {
				sum[i]++;
			}
		}
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3720
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
 
class dice {
public:
    int face[7];
    int get;
 
    dice(int x[]) {
        for (int i = 1; i <= 6; i++)
            face[i] = x[i];
    }
 
    void round(char x) {
            switch (x) {
            case 'E':
                get = face[1];
                face[1] = face[4];
                face[4] = face[6];
                face[6] = face[3];
                face[3] = get;
                break;
            case 'W':
                get = face[1];
                face[1] = face[3];
                face[3] = face[6];
                face[6] = face[4];
                face[4] = get;
                break;
            case 'N':
                get = face[1];
                face[1] = face[2];
                face[2] = face[6];
                face[6] = face[5];
                face[5] = get;
                break;
            case 'S':
                get = face[1];
                face[1] = face[5];
                face[5] = face[6];
                face[6] = face[2];
                face[2] = get;
                break;
            }
    }

    int match(dice x) {
        int ident = 0, i;
        string operate="EEENEEENEEESEEESEEENEEEN";

        if(face[1]==x.face[1] && face[2]==x.face[2] && face[3]==x.face[3] && face[4]==x.face[4] && face[5]==x.face[5] && face[6]==x.face[6]  ){
            ident=1;
        }

        for(i=0;i<operate.size();i++){
            x.round(operate[i]);
            if(face[1]==x.face[1] && face[2]==x.face[2] && face[3]==x.face[3] && face[4]==x.face[4] && face[5]==x.face[5] && face[6]==x.face[6]  ){
                ident=1;
                break;
            }
        } 
        return ident;
    }
};
 
int main() {
    int facef[7], i;
 
    for (int i = 1; i <= 6; i++) {
        cin >> facef[i];
    }
 
    dice dice1(facef);
 
    for (int i = 1; i <= 6; i++) {
        cin >> facef[i];
    }

    dice dice2(facef);
 
    if(dice1.match(dice2)==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3192
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


Int mod(Int)(Int a, Int m) {
  if ((a %= m) < 0) a += m; return a;
}
Int gcd(Int)(Int a, Int b) { return (b != 0) ? gcd(b, a % b) : a; }
Int lcm(Int)(Int a, Int b) { return a / gcd(a, b) * b; }

Int gojo(Int)(Int a, Int b, out Int x, out Int y) {
  if (b != 0) { Int g = gojo(b, a % b, y, x); y -= (a / b) * x; return g; }
  x = 1; y = 0; return a;
}

Tuple!(Int, "b", Int, "m") modSol(Int)(Int b0, Int m0, Int b1, Int m1) {
  Int b, m, x, y;
  const g = gojo(m0, m1, x, y);
  if ((b1 - b0) % g == 0) {
    b = b0 + m0 * ((x * (((b1 - b0) / g) % (m1 / g))) % (m1 / g));
    m = m0 * (m1 / g);
    if ((b %= m) < 0) {
      b += m;
    }
  }
  return Tuple!(Int, "b", Int, "m")(b, m);
}


void main() {
  try {
    for (; ; ) {
      const N = readLong();
      
      long n = 2 * N;
      long[] pes;
      for (long p = 2; p^^2 <= n; ++p) {
        if (n % p == 0) {
          long e;
          do {
            ++e;
            n /= p;
          } while (n % p == 0);
          pes ~= p^^e;
        }
      }
      if (n > 1) {
        pes ~= n;
      }
      const pesLen = cast(int)(pes.length);
      debug {
        writeln("pes = ", pes);
      }
      
      BigInt ans = long.max;
      void dfs(int i, BigInt b, BigInt m) {
        if (i == pesLen) {
          debug {
            writeln(b, " ", m);
            foreach (j; 0 .. pesLen) {
              writeln("  ", pes[j], " ", b % pes[j]);
            }
          }
          chmin(ans, (b == 0) ? m : b);
        } else {
          foreach (r; [0, pes[i] - 1]) {
            const res = modSol(b, m, BigInt(r), BigInt(pes[i]));
            dfs(i + 1, res.b, res.m);
          }
        }
      }
      dfs(0, BigInt(0), BigInt(1));
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
#include <cmath>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<int>
#define endl "\n"
#define allb(x) sort((x).begin(), (x).end())
#define allg(x) sort((x).begin(), (x).end(), greater<int>())
using namespace std;
const ll M = 1e9+7;

ll GCD(ll a, ll b)
{
	if(a==0){return b;}
	if(b==0){return a;}
	return GCD(b,a%b);
}
ll GCD_EUCLID(ll a, ll b)
{
	ll dividend = a>=b ? a:b;
	ll divisor = a<=b ? a:b;
	while(divisor!=0)
	{
		ll remainder = dividend%divisor;
		dividend = divisor;
		divisor = remainder;
	}
	return dividend;
}
ll ModExponent(ll p, ll q)
{
	ll int y=0;
	if(q==0){return 1;}
	if(q%2==0)
	{
		y = ModExponent(p,q/2);
		return (y*y)%M;
	}
	else
	{
		y = ModExponent(p,q-1);
		return ((p%M)*(y))%M;
	}

}
void PrimeNumbers()
{
	//time complexity using sieve of Eratoshthenes O(loglogn)

	int n;
	cin>>n;
	int prime[n+1];
	for(int i = 0; i<=n; i++)
	{
		prime[i]=1;
	}
	prime[0]=0;
	prime[1]=0;
	//As the pair repeat after the square root
	//of any number so we will just check till square root
	//and update all the multiples of the no. to 0
	for(int i = 0; i<=sqrt(n); i++)
	{
		if(prime[i]==1)
		{
			for(int j = 2; i*j<=n; j++)
			{
				prime[i*j]=0;
			}
		}
	}
	//print all index which contains 1
	for(int i = 0; i<=n; i++)
	{
		if(prime[i]==1)
		{
			cout<<i<<" ";
		}
	}
	cout<<"\n";

}
void solve()
{
	int n;
	cin>>n;
	int x,y;
	int flag = 0,count = 0;
	for(int i = 0; i<n; i++)
    {
        cin>>x>>y;
        if(x==y)
        {
            flag = 1;
            count++;
        }
        else if(flag==1&&count<3)
        {
            count = 0;
        }

    }
    if(count>=3)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
    return 0;
}


Measured memory_bytes: 3676