akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	double x1, x2, x3, x4, y1, y2, y3, y4;
	String[] input;
	double slopeAB, slopeCD;
	for (int i = 0; i < n; i++) {
	    input = scan.nextLine().split(" ");
	    x1 = Math.round(Double.parseDouble(input[0]) * 100000);
	    y1 = Math.round(Double.parseDouble(input[1]) * 100000);
	    x2 = Math.round(Double.parseDouble(input[2]) * 100000);
	    y2 = Math.round(Double.parseDouble(input[3]) * 100000);
	    x3 = Math.round(Double.parseDouble(input[4]) * 100000);
	    y3 = Math.round(Double.parseDouble(input[5]) * 100000);
	    x4 = Math.round(Double.parseDouble(input[6]) * 100000);
	    y4 = Math.round(Double.parseDouble(input[7]) * 100000);
	    slopeAB = (y1 - y2) * (x3 - x4);
	    slopeCD = (y3 - y4) * (x1 - x2);
	    if (slopeAB == slopeCD) {
		System.out.println("YES");
	    } else {
		System.out.println("NO");
	    }
	}
    }
}

Measured memory_bytes: 26424
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        ArrayList <Number> list = new ArrayList<>();
        int count = 1;
        
        for(int i = 0; i < n; i++){
            int x = sc.nextInt();
            if(x == count){
                count++;
            }
            list.add(x);
        }
        
        if(count==1){
            System.out.println("-1");
        }else{
            System.out.println(n-count+1);
        }
   }
}


Measured memory_bytes: 65828
x, y, a, b, c = map(int, input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = []
for i in range(x):
    a.append(p[i])

for i in range(y):
    a.append(q[i])

for i in range(c):
    a.append(r[i])

a.sort(reverse=True)
ans = 0
for i in range(x + y):
    ans += a[i]

print(ans)

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll d;cin>>d;
    vector<ll>c(26);
    rep(i,26)cin>>c[i];
    vector<vector<ll> >s(d,vector<ll>(26));
    rep(i,d){
        rep(j,26)cin>>s[i][j];
    }
    vector<ll>last(26);
    vector<ll>v(d);
    vector<pair<ll,pll> >q(0);
    rep(i,d){
        rep(j,26){
            q.pb(mp(c[j]*(d-abs(i-d/2))*s[i][j],mp(i,j)));
        }
    }
    sort(rall(q));
    ll ans=0;
    rep(o,50){
        ll x=rand()%200;
        ll a=q[x].second.first;
        ll b=q[x].second.second;
        v[a]=b+1;
    }
    rep(i,d){
        ll ma=-inf*inf;
        ll idx=0;
        if(v[i]>0){
            ll t=v[i]-1;
            last[t]=i+1;
        }
        rep(t,26){
            ll cn=0;
            cn+=s[i][t];
            ll m=last[t];
            last[t]=i+1;
            rep(j,26){
                cn-=c[j]*(i-last[j]+1);
            }
            last[t]=m;
            if(cn>ma){
                ma=cn;
                idx=t;
            }
        }
        last[idx]=i+1;
        v[i]=idx+1;
    }
    rep(i,d){
        cout<<v[i]<<endl;
    }
}

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

r=[0]*n

for i in range(n)[::-1]:
    if sum(r[i::i+1])%2 != a[i]:
        r[i]=1

print(sum(r))
for index, i in enumerate(r):
    if i == 1:
        print(index+1)



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;
vector<ll> A;

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

  cin>>N;
  A.resize(N);
  rep(i,N){
    cin>>A[i];
    A[i]=-A[i];
  }
  reverse(all(A));
  vector<ll> dp(N+1,INF),sum(N+1,0);

  rep(i,N){
    int idx=lower_bound(all(dp),A[i])-dp.begin();
    if(idx==0) minch(sum[idx],A[i]);
    else minch(sum[idx],sum[idx-1]+A[i]);
    dp[idx]=A[i];
  }
  for(ll i=N;i>=0;i--){
    if(dp[i]!=INF){
      cout<<-sum[i]<<endl;
      return 0;
    }
  }

  return 0;
}



Measured memory_bytes: 5188
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    vector<string> vs;
    string s,sb;
    cin >> n;

    bool iswrong = false;
    cin >> s;
    vs.push_back(s);

    for(int i = 0; i < n-1; i++){
        sb = s;
        cin >> s;
        if(sb[sb.length()-1] != s[0]){
            iswrong = true;
        }
        vs.push_back(s);
    }
    sort(vs.begin(), vs.end());

    for(int i = 0; i < n-1; i++){
        if(vs[i] == vs[i+1]){
            iswrong = true;
        }
    }
    if(iswrong){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf (1<<30)
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
int n,nl[6005],nr[6005],ps[6005],ans=inf;
char A[2005],B[6005];
vector<pair<int,int> > v;
void init()
{
	nl[0]=-inf;for(int i=1;i<=n*3;i++) nl[i]=(B[i]=='1')?i:nl[i-1];
	nr[3*n+1]=inf;for(int i=n*3;i>=1;i--) nr[i]=(B[i]=='1')?i:nr[i+1];
	for(int i=1;i<=n*3;i++) ps[i]=ps[i-1]+(B[i]=='1');
}
int getl(int x){return min(inf,x-nl[x]);}int getr(int x){return min(inf,nr[x]-x);}
int main()
{
	scanf("%s%s",A+1,B+1);
	n=strlen(A+1);
	for(int i=n+1;i<=n*3;i++) B[i]=B[(i-1)%n+1];
	init();
	for(int i=1;i<=2*n+1;i++)
	{
		int tot=0;v.clear();v.push_back(make_pair(0,0));
		for(int j=1;j<=n;j++)
		if(A[j]!=B[j+i-1])
		{
			tot++;
			int l=j+i-1,r=j+n; if(l>r) l^=r^=l^=r;
			if(ps[r]-ps[l-1]==0) v.push_back(make_pair(getl(l),getr(r)));
		}
		sort(v.begin(),v.end());
		int sz=v.size(),maxr=0,sum=inf;
		for(int j=sz-1;j>=0;j--)
		{
			if(v[j].first!=inf && maxr!=inf) sum=min(sum,(v[j].first<<1)+(maxr<<1));
			maxr=max(maxr,v[j].second);if(maxr==inf) break;
		}
		if(sum!=inf) ans=min(ans,sum+tot+abs(n+1-i));
	}
	if(ans==inf) puts("-1");
	else printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s,t;
    cin >> s >> t;
    
    ll ls = s.size();
    ll lt = t.size();
    
    map<char, vector<ll>> mp;
    for ( ll i = 0LL; i < ls; i++ )
        mp[s[i]].push_back(i);
    
    ll r = 0LL;
    ll pos = 0LL;
    
    for ( ll i = 0LL; i < lt; i++ ){
        if ( mp[t[i]].empty() ) {
            cout << -1 << endl;
            return 0;
        }
        
        auto itr = lower_bound(mp[t[i]].begin(), mp[t[i]].end(), pos);
        if ( pos > *(mp[t[i]].end()-1) ) {
            r++;
            pos = mp[t[i]][0] + 1;
        } else {
            pos = *itr + 1;
        }
    }
    
    cout << r * ls + pos  << endl;
    
    return 0;
}


Measured memory_bytes: 1736
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let N = lines.shift().split(/\s/).map((v) => v - 0)[0];
    let ans = true;
    let word = [];
    for (let n = 0; n < N; n++) {
        word.push(lines.shift().trim());
    }
    const firstChar = (v) => v.charAt(0);
    const lastChar = (v) => v.charAt(v.length - 1);
    for (let n = 1; n < N && ans; n++) {
        if (lastChar(word[n-1]) != firstChar(word[n])) {
            ans = false;
        }
    }
    word.sort();
    for (let n = 0; n < N - 1 && ans; n++) {
        if (word[n] == word[n+1]) {
            ans = false;
        }
    }
    console.log(ans ? "Yes" : "No");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <stdio.h>

int main(){
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int cnt=0;
    for (int i=0; i<=n; i++){
        int digitsum =0;
        int j = i;
        while (j>0) {
            digitsum += j%10;
            j/=10;
        }
        if (a<=digitsum && digitsum <= b)cnt += i;
    }
    printf("%d",cnt);
    return 0;
}

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

int main() {
    string S = "abcdefghijklmnopqrstuvwxyz";
    string s;
    cin >> s;

    rep(i, 26) {
        rep(j, s.size()) {
            if(S[i] == s[j]) {
                break;
            }
            if(j == s.size() - 1) {
                cout << S[i] << endl;
                return 0;
            }
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
string str;
signed main(){
	cin>>str;
	for(int i=0;i<str.size();i++) if(str[i]=='?') str[i]='D';
	cout<<str;
	return 0;
}


Measured memory_bytes: 3744
#include<iostream>
#include<cstdio>
using namespace std;
long long xs[111111],cs[111111],n,m,from,to,mn,cur;
int main()
{
	mn=1e18;
	scanf("%lld%lld%lld",&n,&m,&from);
	for (int i=2;i<=n;i++)
	{
		scanf("%lld",&to);
		if (from<to)
		{
			cs[1]+=(to-from);
			cs[from+1]-=(to-from);
			cs[from+1]+=(to+1);
			xs[from+1]-=1;
			cs[to+1]-=(to+1);
			xs[to+1]+=1;
			cs[to+1]+=(to-from);
			cs[m+1]-=(to-from);
		}
		else
		{
			cs[1]+=(to+1);
			cs[to+1]-=(to+1);
			xs[1]-=1;
			xs[to+1]+=1;
			cs[to+1]+=(to-from+m);
			cs[from+1]-=(to-from+m);
			cs[from+1]+=(to+m+1);
			cs[m+1]-=(to+m+1);
			xs[from+1]-=1;
			xs[m+1]+=1;
		}
		from=to;
	}
	for (int i=2;i<=m;i++)
	{
		cs[i]+=cs[i-1];
		xs[i]+=xs[i-1];
	}
	for (int i=1;i<=m;i++)
	{
		cur=xs[i]*i+cs[i];
		mn=min(mn,cur);
	}
	printf("%lld\n",mn);
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x[] = new int[3];
    for(int i=0;i<3;i++){
      x[i] = N %10;
      N = N/10;
    }
    if(x[0] == x[2]){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23764
<?php
list($n) = ints();
for ($i = 1; $i <= 50000; ++$i) {
    if (intdiv($i * 108, 100) === $n) exit((string) $i);
}
echo ':(';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

typedef long long ll;

const int inf = 100000;

int main() {
    ll N;
    cin >> N;
    vector<ll>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        
    }
    sort(A.begin(), A.end());
    ll a_max = A[N-1];
    vector<bool>c(a_max+1, true);
    ll p;
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            if (A[i] == p) {
                c[A[i]] = false;
                continue;
            }
        }
        ll y = A[i];
        ll j = 2;
        while (true) {
            if (y*j > a_max) {
                break;
            }
            c[y*j] = false;
            j++;
        }
        p = A[i];
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (c[A[i]]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4836
#!/usr/bin/env python3
n, k = map(int, input().split())

okashi = [0] * n
for _ in range(k):
    d = int(input())
    for i in list(map(int, input().split())):
        okashi[i - 1] += 1

ans = 0
for i in okashi:
    if i == 0:
        ans += 1

print(ans)



Measured memory_bytes: 8916
import sys
sys.setrecursionlimit(10**7)
w, h = map(int, input().split())
S = [list(map(int, input().split())) for i in range(h)]
SW = [[0]*w for i in range(h)]
SH = [[0]*w for i in range(h)]
for i in range(h):
    cnt = 0
    for j in range(w-1, -1, -1):
        cnt += S[i][j]
        SW[i][j] = cnt
for j in range(w):
    cnt = 0
    for i in range(h-1, -1, -1):
        cnt += S[i][j]
        SH[i][j] = cnt
memo = {}
def dfs(x, y):
    if (x, y) in memo:
        return memo[x, y]
    if x == w or y == h:
        return 0
    if (x+y) % 2 == 0:
        # first
        res = max(dfs(x+1, y) - SH[y][x], dfs(x, y+1) + SW[y][x])
    else:
        # second
        res = min(dfs(x+1, y) - SH[y][x], dfs(x, y+1) + SW[y][x])
    memo[x, y] = res
    return res
print(abs(dfs(0, 0)))

Measured memory_bytes: 296028
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	int N; cin >> N;
	vector<P> L(N), R(N);
	rep(i, N){
		cin >> L[i].first >> R[i].first;
		L[i].second = i, R[i].second = i;
	}
	sort(all(L), greater<P>());
	sort(all(R));
	ll K = 0, s = 0;
	rep(i, N){
		if(L[i].first <= R[i].first){
			chmax(K, s+L[i].first);
			chmax(K, s-R[i].first);
		}else{
			s += L[i].first - R[i].first;
			chmax(K, s);
			chmax(K, s+R[i].first);
			chmax(K, s-L[i].first);
		}
	}
	cout << 2*K << endl;
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int c = 1; c < n; c++) {
		int t = n - c;
		int x = 1;
		for (int i = 2; i*i <= t; i++) {
			int p = 0;
			while (t % i == 0) {
				p++;
				t /= i;
			}
			x *= p + 1;
		}
		if (t != 1) x *= 2;
		ans += x;
	}
	cout << ans << endl;
}

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

int main()
{
    int N;
    string S, T;
    cin >> N >> S >> T;
    string ans;
    rep(i, 2 * N)
    {
        if (i % 2 == 0)
        {
            ans += S.at(i / 2);
        }
        else
        {
            ans += T.at((i - 1) / 2);
        }
    }
    cout << ans << endl;
}

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

int A[200010][25], now[25];
int main() {
	int N, u; cin >> N;
	for(int i=0; i<N; ++i){
	    cin >> u;
	    for(int j=0; u>0; ++j){
	        A[i][j]=u%2;
	        u /= 2;
	    }
	}
	long ans=0;
	int bord=0;
	for(int i=0; i<N; ++i){
	    bool flag=true;
	    while(flag && bord<N){
	        for(int j=0; j<25; ++j){
	            if(now[j]+A[bord][j]>1){
	                flag=false;
	                break;
	            }
	        }
	        if(flag){
	            for(int j=0; j<25; ++j) now[j] += A[bord][j];
	            ++bord;
	        }
	    }
	    ans += bord-i;
	    for(int j=0; j<25; ++j) now[j] -= A[i][j];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 19840
n = int(input())
s = input()

r = g = b = 0
for i in s:
    if i == "R":
        r += 1
    elif i == "G":
        g += 1
    elif i == "B":
        b += 1
ans = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1, i+(n-i-1)//2+1):
        sj = s[j]
        k = 2*j-i
        if k < n and s[k] != si and s[k] != sj and si != sj:
            ans -= 1

print(ans)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    string s; cin >> s;
    cout << "2018" + s.substr(4, 6) << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		int a[] = new int[N];
		for(int i = 1; i < N; i++){
			int a1 = sc.nextInt();
			int a2 = sc.nextInt();
			a[a2-1] = a1-1;
		}
		int sum[] = new int[N];
		for(int i = 0; i < Q; i++){
			int a1 = sc.nextInt();
			int a2 = sc.nextInt();
			sum[a1-1] += a2;
		}
		
		for(int i = 1; i < N; i++){			
			sum[i] += sum[a[i]];
		}
		
		for(int i = 0; i < N; i++){
			System.out.print(sum[i]);
			if(i != N -1)System.out.print(" ");
		}
		
	}
	
}

Measured memory_bytes: 159832
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s;
        int m;
        int h[];
        String ans[] = new String[11];
        int cnt = 0;

        while (true) {
            s = sc.next();
            if (s.equals("-")) {
                for (int i = 0; i < cnt; i++) {
                    System.out.println(ans[i]);
                }
                sc.close();
                return;
            }
            m = sc.nextInt();
            h = new int[m];
            for (int i = 0; i < m; i++) {
                h[i] = sc.nextInt();
            }

            String tmp = s;
            String ttmp = s;

            for (int i = 0; i < m; i++) {
                ttmp = (tmp.substring(h[i]) + tmp.substring(0, h[i]));
                tmp = ttmp;
            }
            ans[cnt] = tmp;
            cnt++;
        }
        // System.out.println("cnt: " + cnt);
        // for (int i = 0; i < cnt; i++) {
        // System.out.println(ans[i]);
        // }
        // sc.close();
    }
}


Measured memory_bytes: 26344
import java.util.*;  
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in); 
       int s = input.nextInt();
      	int w = input.nextInt();
      if (s>w)
        System.out.println("safe");
      else 
        System.out.println("unsafe");
    }
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int totime(string s) {
	return stoi(s.substr(0, 2)) * 60 + stoi(s.substr(2, 4));
}

signed main() {
	int n; string p, q;
	while (cin >> n >> p >> q&&n) {
		int tp = totime(p), tq = totime(q);
		int size = tq - tp + 1;
		vector<int> v(size, 0);
		rep(i, 0, n) {
			int m; cin >> m;
			rep(j, 0, m) {
				string pp, qq; cin >> pp >> qq;
				int tpp = totime(pp), tqq = totime(qq);
				v[tpp - tp]++;
				v[tqq - tp]--;
			}
		}
		dumpc(v);
		rep(i, 1, size) {
			v[i] += v[i - 1];
		}
		dumpc(v);
		int ans = 0, tmp = 0;
		rep(i, 0, size - 1) {
			if (v[i] == n)tmp = 0;
			else tmp++;
			chmax(ans, tmp);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
#include <stdio.h>
int main() {
	int a, b, c, x;
	scanf("%d%d%d", &a, &b, &c);
	if (a >= b && a >= c)
		x = 10 * a + b + c;
	else if(b >= a && b >= c)
		x = 10 * b + a + c;
	else
		x = 10 * c + b + a;
	printf("%d\n", x);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int A,B;		cin>>A>>B;
	if(A+B==3)	cout<<"3"<<endl;
	else if(A+B==4)	cout<<"2"<<endl;
	else cout<<"1"<<endl;


    return 0;
}



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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n' //toggle off for interactive problems
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = b*d;
	ans = max(ans, a*c);
	ans = max(ans, a*d);
	ans = max(ans, b*c);
	cout << ans << endl;
	return 0;
}


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

int main(){
    int N;
	cin>>N;
    vector<int> vec(N+1);
    int next;
    vector<char> end(N+1);//検索済み配列
    int cnt=0;
 
    //入力
    for (int i=1; i<=N; i++){
        cin >> vec.at(i);
    }
    next=1;
    
    while(true){
        cnt++;
        end.at(next)='e';//検索済みに追加
        next=vec.at(next);//次のボタンへ移動
        //cout<<cnt<<"回目"<<next<<endl;途中経過が見れる
        if(end.at(next)=='e'){//検索済みなら終了
            cout<<-1<<endl;
            break;
        }
        else if(next==2){//ゴールにたどり着けたら終了
            cout<<cnt<<endl;
            break;
        }
    }
    
    
    
}

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

int N,M,ans;
bool G[10][10];
bool used[10];

void dfs(int v, int cnt) {
  if(cnt==N) {
    ans++;
    return ;
  }
  used[v]=1;
  rep(i, N) {
    if(!used[i]&&G[v][i]) dfs(i, cnt+1);
  }
  used[v]=0;
}
 
int main() {
  cin>>N>>M;
  rep(i, M) {
    int a,b; cin>>a>>b;
    a--; b--;
    G[a][b]=G[b][a]=true;
  }
  dfs(0,1);
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

string s;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> s;
    string t;
    for (int i = 0; i < 15; ++i) {
        t += "hi";
        if (t == s) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];
bool used[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, (1 << N)) cin >> A[i];
	sort(A, A + (1 << N));
	reverse(A, A + (1 << N));
	used[0] = true;

	rep(i, 0, N) {
		deque<int> que;
		rep(j, 0, (1 << N)) {
			if(used[j]) que.push_back(A[j]);
			else {
				if(!que.empty() && A[j] < que.front()) {
					// debug(i, j);
					que.pop_front();
					used[j] = true;
				}
			}
		}
	}
	if(accumulate(used, used + (1 << N), 0) == (1 << N)) cout << "Yes\n";
	else cout << "No\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 2144
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 3002;
const lo mod = 998244353;

int n,m,b[li],a[li],k,flag,t,dp[li][li][4];
int cev;
string s;
vector<int> v;

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

inline int f(int sira,int topl,int bas){
	int cevv=0;
	if(topl<0)return 0;
	if(sira>n){
		if(topl==0)return 1;
		return 0;
	}
	if(~dp[sira][topl][bas])return dp[sira][topl][bas];
	if(bas==0){
		cevv=add(cevv,f(sira+1,topl,0));
		cevv=add(cevv,f(sira,topl,1));
	}
	else{
		cevv=add(cevv,f(sira+1,topl-a[sira],1));
		if(sira!=n)
		cevv=add(cevv,f(n+1,topl-a[sira],1));
		if(sira!=n)
		cevv=add(cevv,f(n+1,topl,1));
		cevv=add(cevv,f(sira+1,topl,1));
	}
	return dp[sira][topl][bas]=cevv;
}

main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&k);
	FOR{
		scanf("%lld",&a[i]);
	}
	printf("%lld\n",f(1,k,0));
	return 0;
}



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

int n;
string s;

int main(){
        //      cin.tie(0);
        //      ios::sync_with_stdio(false);
        cin >> s;
        n = (int)s.size();
        for(char c='a'; c<='z'; ++c){
                int cnt = 0, r = 0;
                for(int l=0; l<n; ++l){
                        while(r < n && s[r] == c){
                                ++r;
                                ++cnt;
                        }
                        if(r+1<n && s[r+1]==c){
                                r += 2;
                                ++cnt;
                        }
//                      cout << l << " " << r << " " << cnt << " " << c << "\n";
                        if(l+1<r && (r-l)<2*cnt){
                                cout << l+1 << " " << r << "\n";
                                return 0;
                        }
                        if(l == r) ++r;
                        if(s[l] == c) --cnt;
                }
        }
        cout << "-1 -1\n";
}

Measured memory_bytes: 512
fn main() {
    let ints: Vec<i32> = read_line_as_vector();
    let total: i32 = ints.iter().sum();
    if total <= 21 {
        println!("win");
    } else {
        println!("bust");
    }
}

fn read_line_as_vector<T: std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().split_whitespace().map(|x| x.parse()).collect::<Result<Vec<T>, _>>() {
        Ok(vec) => vec,
        _ => panic!("error while parsing input: {}", input)
    }
}

Measured memory_bytes: 2144
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
////////////////////////////////
 
#define int long long

const int mod = 1e9 + 7;
const int N = 1e5 + 6;

int dp[N][2];
vector<int> v[N];

void dfs(int s , int par = -1){

	bool ok = true;
	dp[s][0] = dp[s][1] = 1;
	for(int it : v[s]){

		if(it==par)
			continue;
		ok = false;
		dfs(it , s);

		dp[s][1]*=(dp[it][0] + dp[it][1]);
		dp[s][1]%=mod;
		dp[s][0]*=(dp[it][1]);
		dp[s][0]%=mod;
	}
}

void solve(){

	int n;
	cin>>n;

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

		int x , y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	//int ans = 2;
	dfs(1);

	//dfs(1 , 1);
	//debug(dp[1][0] , dp[1][1]);
	int ans = dp[1][0] + dp[1][1];
	ans%=mod;

	cout<<ans<<endl;
}
 
signed main(){
 
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}


Measured memory_bytes: 14208
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect

# from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
data = getInputIntList()

ans = [0 for _ in range(n+1)]

for d in data:
    ans[d] += 1

for i, a in enumerate(ans):
    if i == 0 : continue
    print(a)





Measured memory_bytes: 34804
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO  freopen("C:\\Users\\sourav\\Documents\\cp files\\input.txt", "r", stdin); freopen("C:\\Users\\sourav\\Documents\\cp files\\output.txt", "w", stdout); 
#define maxn 1000000
 
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


signed main()
{
    #ifndef ONLINE_JUDGE 
       FILEIO
    #endif
     FLASH
     int k;
     int a , b;
     cin>>k>>a>>b;
     if(a%k == 0 || b%k == 0)
     {
        cout<<"OK";
        return 0;
     }    
     int temp = a/k;
     int temp1 = b/k;
     if(temp1 > temp)
        cout<<"OK";
    else
        cout<<"NG";
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(){
int n,a[111],min=1111111,ans,i,ave,d;
scanf("%d",&n);
ave=0;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
ave+=a[i];
}
for(i=0;i<n;i++){
d=a[i]*n-ave;
if(d<0)
d=-d;
if(d<min){
ans=i;
min=d;
}
}
printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 128
import sys

n, m = map(int, input().split())
links = [set() for _ in range(n)]
counts = [0] * n
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)
    counts[s] += 1

# Expected number of edges passing from i to N
expected = [0.] * n
exp_get = expected.__getitem__

# i から伸びる辺を1本消すことで削減できる"iからNまでの辺数の期待値"の最大量
reducible = [0.] * n

for i in range(n - 2, -1, -1):
    nxt_exp = list(map(exp_get, links[i]))
    sum_exp = sum(nxt_exp)
    cnt = counts[i]

    expected[i] = sum_exp / cnt + 1

    if cnt > 1:
        reduced_exp = (sum_exp - max(nxt_exp)) / (cnt - 1) + 1
        reducible[i] = expected[i] - reduced_exp
    else:
        reducible[i] = 0.

# Probability of visiting i when starting from 1
probability = [0.] * n
probability[0] = 1.

rdc = 0.

for i in range(n - 1):
    fp = probability[i]
    jp = fp / counts[i]
    for j in links[i]:
        probability[j] += jp
    rdc = max(rdc, fp * reducible[i])

print(expected[0] - rdc)


Measured memory_bytes: 19200
#include <stdio.h>

int N;
long long A[200010];

int nibutan(int start,int end,long long target) {
	int left=start+1,right=end;
	int ok_min=right;
	while(left<=right) {
		int mid=(left+right)/2;
		if(target<=A[mid]-A[start]) {
			if(mid<ok_min)ok_min=mid;
			right=mid-1;
		} else {
			left=mid+1;
		}
	}
	return ok_min;
}

int is_ok(long long p) {
	int i;
	for(i=0;i<N;i++) {
		int a,b;
		a=nibutan(i,i+N,p);
		if(A[a]-A[i]<p)continue;
		b=nibutan(a,i+N,p);
		if(A[b]-A[a]>=p && A[i+N]-A[b]>=p)return 1;
	}
	return 0;
}

void printll(long long v) {
	char buf[64];
	char *p=buf;
	if(v<0) {
		putchar('-');
		v=-v;
	}
	do {
		*(p++)=(char)(v%10+'0');
	} while((v/=10)>0);
	do {
		putchar(*(--p));
	} while(p!=buf);
}

int main(void) {
	int i;
	long long left,right,ans;
	if(scanf("%d",&N)!=1)return 1;
	for(i=1;i<=N;i++) {
		int buf;
		if(scanf("%d",&buf)!=1)return 1;
		A[i]=+buf;
	}
	for(i=1;i<=N;i++) {
		A[N+i]=A[i];
	}
	for(i=1;i<=N+N;i++)A[i]+=A[i-1];
	ans=left=0;right=A[N+N];
	while(left<=right) {
		long long mid=(left+right)/2;
		if(is_ok(mid)) {
			if(ans<mid)ans=mid;
			left=mid+1;
		} else {
			right=mid-1;
		}
	}
	printll(ans);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2128
O=input()
E=input()

ans=""  
for i in range(len(O)):
  if len(O)-len(E)==0:
    ans=ans+(O[i]+E[i])
  elif len(O)-len(E)==1:
    if i<=len(E)-1:
      ans=ans+(O[i]+E[i])
    else:
      ans=ans+O[i]
print(ans)

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

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

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=1,a[100000],b[100000],c=1,d=1,cmp,data,m,h,w,x,y,xcmp=0,ycmp=0,sum=0;

string s;

vector<int> z;

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

       cin >> n;
       rep(i,n){
           cin >> a[i] >> b[i];
       }
       c=a[0];
       d=b[0];
       rrep(i,1,n){
           c=(c+a[i]-1);
           d=(d+b[i]-1);
           cmp=max(c/a[i],d/b[i]);
           c=cmp*a[i];
           d=cmp*b[i];
       }
       Cout(c+d);
return 0;
}


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

int main (void){
  long long int n = 0,c = 1,k = 0,t = 1,ans = 0;
  cin >> n;

  vector<string> s(n,"");
  for(int i = 0;i < n;i++){
    cin >> s[i];
    sort(s[i].begin(),s[i].end());
  }

  sort(s.begin(),s.end());

  for(int i = 0;i < n - 1;i++){
    if(s[i] == s[i + 1]){
      c++;
    }else{
      ans = ans + c*(c-1)/2;
      c = 1;
    }
  }
  ans = ans + c*(c-1)/2;

  cout << ans << endl;

  return 0;
}

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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    map<int,int> mp;
    mp[0] = 3;
    int ans=1;
    for(int i=0; i<N; i++){
        ans *= mp[A[i]];
        ans %= MOD;
        mp[A[i]]--;
        mp[A[i]+1]++;
    }

    cout << ans << endl;

}

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

int main() {
    int N,i,j,k,l,m,c;
    string S,t,ds="";
    cin >> N >> S;
    set<string> ps;
    set<char> pd;

    for(i=0; i<N; i++)
        pd.insert(S.at(i));
    m = pd.size();

    for(auto x : pd)
        ds += x;
    
    for(i=0; i<m; i++)
        for(j=0; j<m; j++)
            for(k=0; k<m; k++) {
                int d1=-1,d2=-1,d3=-1;
                for(l=0; l<N; l++) {
                    if(d1==-1 && S.at(l)==ds.at(i))
                        d1 = l;
                    else if(d1!=-1 && d2==-1 && S.at(l)==ds.at(j))
                        d2 = l;
                    else if(d1!=-1 && d2!=-1 && d3==-1 && S.at(l)==ds.at(k)) {
                        d3 = l;
                        break;
                    }
                }
                if(d1!=-1 && d2!=-1 && d3!=-1 && d1<d2 && d2<d3) {
                    t = "";
                    t += S.at(d1);
                    t += S.at(d2);
                    t += S.at(d3);
                    ps.insert(t);
                }
            }
    
    cout << ps.size() << endl;
}

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



int main() {
    ll n, k;
    cin >> n  >> k;
    ll ans = min(n%k, abs(n%k-k));
    cout << ans << endl;
}

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

int main() {
	int a,b;
	cin>>a>>b;
	
	if(1<=a&&a<=9&&1<=b&&b<=9)cout<<a*b<<endl;
	else cout<<-1<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int N;

int calc_pow(int x, int pow,int m) {
    if (pow == 0) return 1;
    int a = calc_pow(x, pow / 2,m);
    a = a * a % m;
    if (pow % 2 == 1) a *= x;
    return a % m;
}//最小二乗法

signed main(){
    scanf("%lld",&N);
    int ans=calc_pow((int)10,N,mod)-2*calc_pow((int)9,N,mod)+calc_pow((int)8,N,mod);
    ans%=mod;
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}

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

int N;

int main(void)
{

    cin >> N;

    if (N % 2 == 0)
    {
        cout << 0.5;
    }
    else
    {
        float ans = (float)(N - (int)(N / 2)) / N;
        cout << ans;
    }
}

Measured memory_bytes: 256
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
  
const int N=100001;
vi frnd_ship[N];
vi blk_ship[N];
int comp[N],sz[N];
bool vis[N];

void dfs(int u,int cm)
{
	if(vis[u])
		return;
	vis[u]=1;
	for(int v:frnd_ship[u])
	{
		if(!vis[v])
			dfs(v,cm);
	}
	comp[u]=cm;
}

int main()
{      
  fastio();
  int n,m,i,j,k;
  cin>>n>>m>>k;
  
  for(i=0;i<m;i++)
  {
  	int x,y;
  	cin>>x>>y;
  	frnd_ship[x].pb(y);
  	frnd_ship[y].pb(x);
  }
  for(i=0;i<k;i++)
  {
  	int x,y;
  	cin>>x>>y;
  	blk_ship[x].pb(y);
  	blk_ship[y].pb(x);
  }
  int c=1;
  for(i=1;i<=n;i++)
  {
  	if(!vis[i])
  	{
  		dfs(i,c);
  		c++;
  	}
  }
  for(i=1;i<=n;i++)
  {
  	sz[comp[i]]++;
  }
  for(i=1;i<=n;i++)
  {
  	int ans=sz[comp[i]]-frnd_ship[i].size()-1;
  	for(j=0;j<blk_ship[i].size();j++)
  	{
  		if(comp[i]==comp[blk_ship[i][j]])
  			ans--;
  	}
  	cout<<ans<<" ";
  }
  return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[1000]={0},b[1000][2]={0},m,sum=0,c[1000];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		c[i]=a[i];
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>b[i][0]>>b[i][1];
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
		    if(b[i][0]-1==j){
		    	//cout<<"@"<<j<<endl;
		    a[j]=b[i][1];
		    //cout<<a[j]<<endl;
		    for(int ii=0;ii<n;ii++)
		    {
		        //cout<<a[ii]<<" -> ";
			    sum+=a[ii];
				a[ii]=c[ii];
			}
		    cout<<sum<<endl;
		    sum=0;
		    break;
		    }
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
    int N;
    cin >> N;
    int count = 0, ans = 0, highest = 0;
    while(count < N){
        count++;
        int H;
        cin >> H;
        if(highest <= H) {
            ans++;
            highest = H;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;


ll cnt=0;
void merge(int a[], int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    
    int L[n1+1];
    for(int i=0; i<n1; ++i){
        L[i] = a[left+i];
    }
    int R[n2+1];
    for(int i=0; i<n2; ++i){
        R[i] = a[mid+i];
    }
    L[n1] = 1e9;
    R[n2] = 1e9;
    int i=0, j=0;
    
    for(int k=left; k<right; ++k){
        if(L[i]<=R[j]){
            a[k] = L[i];
            i++;
            cnt++;
        }else{
            a[k] = R[j];
            j++;
            cnt++;
        }
    }
}
void mergeSort(int a[], int left, int right){
    if(left+1<right){
        int mid = left+(right-left)/2;
        mergeSort(a, left, mid);
        mergeSort(a, mid, right);
        merge(a, left, mid, right);
    }else{
        return ;
    }
}
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[500010];
    REP(i, n) cin >> a[i];
    
    int left=0, right=n;
    mergeSort(a, left, right);
    
    for(int i=0; i<n; ++i){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << cnt << endl;
	return 0;
}


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

vector<int> a;
int dp[100010];


int moves(int index,int n){
    if(index >= n-1 )
    {
        return 0;
    }
    
    if(dp[index]!=-1){
        return dp[index];
    }

    int a1 = 1e9;
    int b = 1e9;
    if(index+1 < n){
        a1 = abs(a[index]-a[index+1]) + moves(index + 1,n);
    }
    if(index + 2 < n ){
        b = abs(a[index]-a[index + 2]) + moves(index + 2,n);
    }
    return dp[index] = min(a1,b);

}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    a.resize(n);
    memset(dp,-1,sizeof dp);

    for(int i = 0;i<n;i++){
        cin>>a[i];
    }

    cout<<moves(0,n)<<endl;

    return 0;
}

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

int x[200000];

int main(){
	int n;
	scanf("%d", &n);
	ll s = 0;
	f(i, 0, n)scanf("%d", x + i), s += x[i];
	ll z = 0, an = 1e18;
	f(i, 0, n - 1){
		z += x[i];
		s -= x[i];
		an = min(an, abs(z - s));
	}
	printf("%lld\n", an);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    ll X;
    cin >> X;

    ll ans = 1;

    for(ll i = 2; i * i <= X; i++) {
        for(ll j = 2; j; j++) {
            if(pow(i, j) > X) break;
            ans = max(ans, ll(pow(i, j)));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384