akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	string s;
	cin >> s;
	if (s[0] == s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    abc=MI()
    s=set(abc)
    print(len(s))

main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int N;
int ans=0;

int check(int a){
	int x=0,y=0,z=0;
	if(a>N)return 0;
	while(a>0){
		if(a%10==3)x++;
		else if(a%10==5)y++;
		else if(a%10==7)z++;
		else return 0;
		a/=10;
	}

	if(x*y*z>0)return 1;
	else return 0;
}
void f(int x,int a){
	if(x>9)return;
	a*=10;
	a+=3;
	if(check(a)) ans++;
	f(x+1,a);
	a-=3;
	a/=10;

	a*=10;
	a+=5;
	if(check(a)) ans++;
	f(x+1,a);
	a-=5;
	a/=10;

	a*=10;
	a+=7;
	if(check(a)) ans++;
	f(x+1,a);
	a-=7;
	a/=10;
}
int main(){
	cin >> N;
	f(1,0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int N=3010;
struct node
{
	int to,nxt;
}edge[N*2];
int head[N],cnt,n,a[N],book[N];
void add(int x,int y) {edge[++cnt]=(node){y,head[x]},head[x]=cnt;}
void ff(int x,int fa)
{
	book[x]=0;a[x]--;
	for(int i=head[x];i!=-1;i=edge[i].nxt)
	{
		if(edge[i].to==fa || a[edge[i].to]>a[x]) continue;
		ff(edge[i].to,x);
		if(book[edge[i].to]==0)
		{
			book[x]=1;
			break;
		}
	}
	a[x]++;
}
int main()
{
	memset(head,-1,sizeof(head)),cnt=-1;
	int i,j,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(i=1;i<=n;i++)
	{
		ff(i,0);
		if(book[i]==1) printf("%d ",i);
	}
	return 0;
}

Measured memory_bytes: 384
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let m = v[1];
	let mut road = vec![0; n as usize];
	for i in 0..m {
		let v:Vec<i32> = procon_read();
		let ai = v[0];
		let bi = v[1];
		road[(ai - 1) as usize] = road[(ai - 1) as usize] + 1;
		road[(bi - 1) as usize] = road[(bi - 1) as usize] + 1;
	}
	for i in road {
		println!("{}", i);
	}
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long n,m,sum=0,cnt=0,temp,i;
    cin>>n>>m;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    temp=sum/(4*m);
    if(temp*4*m==sum)
        temp=temp;
    else
        temp++;
    for(i=0;i<n;i++)
    {
        if(a[i]>=temp)
            cnt++;
    }
    //cout<<temp<<endl;
    if(cnt>=m)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 2;
int dp[N][N];
int sb[2 * N][N], sw[2 * N][N];
int b[2 * N], w[2 * N];
pair<int, int> arr[2 * N];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		char x;
		cin >> x >> arr[i].first;
		arr[i].first--;
		if (x == 'W')
			w[arr[i].first] = i;
		else 
			b[arr[i].first] = i, arr[i].second = 1;
	}
	for (int i = 1; i <= 2 * n; i++) {
		for (int j = 0; j < n; j++) {
			sb[i][j] = sb[i - 1][j] + (int) (arr[i - 1].second && arr[i - 1].first >= j);
			sw[i][j] = sw[i - 1][j] + (int) (!arr[i - 1].second && arr[i - 1].first >= j);
		}
	}
	for (int i = 1; i <= n; i++) {
		dp[0][i] = dp[0][i - 1] + sb[w[i - 1]][0] + sw[w[i - 1]][i - 1];
		dp[i][0] = dp[i - 1][0] + sb[b[i - 1]][i - 1] + sw[b[i - 1]][0];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = min(dp[i - 1][j] + sb[b[i - 1]][i - 1] + sw[b[i - 1]][j], dp[i][j - 1] + sb[w[j - 1]][i] + sw[w[j - 1]][j - 1]);
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}


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

int main()
{
    ll X, A, B, ans;
    scanf("%ld", &X);
    // printf("%ld %ld %ld", A, B, C);

    A=X/500;
    B=(X-A*500)/5;
    // printf("%ld %ld", A, B);
    ans=A*1000+B*5;
    printf("%ld", ans);

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define max(a, b) (a > b ? a : b)

int main() {
	int n, r;
	scanf("%d%d", &n, &r);
	printf("%d", r + max(100 * (10 - n),0));
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int r, g, b, n, ans;

int main()
{
    int i, j;
    scanf("%d%d%d%d", &r, &g, &b, &n);

    for(i=0; i<=n/r; i++)
    {
        for(j=0; j<=n/g; j++)
        {
            int t=n-i*r-j*g;
            if(t>=0 && t%b==0) ans++;
        }
    }
    printf("%d", ans);
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem086a(a, b))
}

fun problem086a(a: Int, b: Int): String {
    return if (a * b % 2 == 0) "Even" else "Odd"
}

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

int main(){
    int H,W;
    
    while(1){
        cin >> H >> W;
        int cou = 0;
        if (H ==0 && W ==0){
            break;
        }    
        for (int i =0; i<H;i++){
            cou +=1;
            for (int j =0; j <W ;){
                if (cou%2 !=0){
                    if (j ==W){
                        break;
                        cout <<endl;
                    }
                    cout << "#";
                    j += 1;
                    if(j ==W){
                        break;
                        cout <<endl;
                    }
                    cout << ".";
                    j +=1;
                }
                else{
                    if (j ==W){
                        break;
                        cout <<endl;
                    }
                    cout << ".";
                    j +=1;
                    if (j ==W){
                        break;
                        cout <<endl;
                    }
                    cout <<"#";
                    j +=1;
                }
            }
            cout <<endl;
        }
        cout << endl;
    }
     return 0;
}


Measured memory_bytes: 3088
#include "bits/stdc++.h"
#include <random>

using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll D=365;
vi c(26);
vi last(26,-1);
vvi dat(D, vi(26));  // N * M の2次元配列
vvi AAlist(100, vi(D));  // N * M の2次元配列


ll calcscore(vi &Alist)
{
  for(ll i=0;i<26;i++){
    last[i]=-1;
  }
  

  ll sc=0;
  ll sct=0;
  ll l;
  ll id;
  ll factscore=0;
  for(ll i=0;i<D;i++){
    sc=-922337203685477580LL;
    for(ll j=0;j<26;j++){
      if (Alist[i]==j)continue;
      l=i-last[j];
      sct=l*c[j];
      factscore-=sct;
    }

    id=Alist[i];
    factscore+=dat[i][id];
    last[id]=i;
  }

  return factscore;
}



int main(){
  ll ans=0;
  cin>>ans;
  ll factscore=0;


  for(ll i=0;i<26;i++){
    cin>>c[i];
  }
  for(ll i=0;i<D;i++){
    for(ll j=0;j<26;j++){
      cin>>dat[i][j];
    }
  }


  ll sc=0;
  ll sct=0;
  ll maxid=-1;
  for(ll i=0;i<D;i++){
    sc=-922337203685477580LL;
    maxid=0;
    
    for(ll j=0;j<26;j++){
      ll l=i-last[j];
      sct=l*c[j];
      factscore-=sct;
      sct=dat[i][j]+sct;
      if (sc<sct){
        sc=sct;
        maxid=j;
      }
    }
    factscore+=sc;
    last[maxid]=i;
    AAlist[0][i]=maxid;
    cout<<(maxid+1)<<endl;
  }




  //cout<<calcscore(AAlist[0])<<endl;


  return 0;
}

Measured memory_bytes: 3980
import fractions as frac
n=int(input())
t=[int(input()) for _ in range(n)]
t=sorted(set(t))
t1=t[0]
if len(t)==1:
    print(t1)
    exit()
for i in range(1,len(t)):
    t2=t[i]
    g=frac.gcd(t1,t2)
    ans=t1*t2//g
    t1=ans
print(int(ans))


Measured memory_bytes: 5048
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H==0&&W==0) break;
        for(int i=0;i<W;i++){
            cout << "#";
        }
        cout << endl;
        for(int i=0;i<H-2;i++){
            cout << "#";
            for(int j=0;j<W-2;j++){
                cout << ".";
            }
            cout << "#" << endl;
        }
        for(int i=0;i<W;i++){
            cout << "#";
        }
        cout << endl;
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
n, t = map(int,input().split())
ct = [list(map(int,input().split())) for _ in range(n)]

z = sorted(ct, key=lambda x: (x[0],x[1]))
for i in range(n):
    if z[i][1] <= t:
        print(z[i][0])
        exit()
print("TLE")


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int edge[3];
    for(int i=0,a; i<3; i++){
      cin >>a;
      edge[i] = a*a;
    }
    if(edge[0] == edge[1]+edge[2]) cout <<"YES"<<endl;
    else if(edge[1] == edge[0]+edge[2]) cout <<"YES"<<endl;
    else if(edge[2] == edge[1]+edge[0]) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;

int main() 
{
    int n;
    int cnt = 1;
    while(true){
        cin >> n;
        if(n==0) break;
        cout << "Case " << cnt << ": " << n << endl;
        cnt++;
    }
}



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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;

int main(){
	int n, k;
	int sunuke[120];

	cin >> n >> k;

	for(int i = 0; i < n; i++) sunuke[i] = 0;
	
	for(int i = 0; i < k; i++){
		int d;
		cin >> d;
		for(int j = 0; j < d; j++){
			int a;
			cin >> a;
			sunuke[--a]++;
		}
	}

	int cnt = 0;

	for(int i = 0; i < n; i++){
		if(sunuke[i] == 0) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3624
import sys
 
_input1 = int(input())
_input2 = [int(s) for s in input().split()]
_output = sys.maxsize
 
for i in range(min(_input2),max(_input2)+1):
    score = 0
    for j in _input2:
        score += (j-i)**2
 
    if score < _output:
        _output = score
 
print(_output)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10)), d(10, vector<int>(10, INT_MAX));
    REP(i, 10) REP(j, 10) { cin >> c[i][j]; }
    REP(i, 10) {
        priority_queue<P, vector<P>, greater<P>> pq;
        d[i][i] = 0;
        pq.emplace(0, i);
        while (!pq.empty()) {
            int w, j;
            tie(w, j) = pq.top();
            pq.pop();
            REP(k, 10) {
                if (j == k) continue;
                if (d[i][k] > d[i][j] + c[j][k]) {
                    d[i][k] = d[i][j] + c[j][k];
                    pq.emplace(d[i][k], k);
                }
            }
        }
    }
    int res = 0;
    REP(i, H) REP(j, W) {
        int A;
        cin >> A;
        if (A == -1) continue;
        res += d[A][1];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
ls = [int(raw_input()) for _ in range(n)]
ans = 0
for i, j in enumerate(ls):
    ans += j / 2
    if i < len(ls)-1 and j % 2 == 1 and ls[i+1] > 1:
        ans += 1
        ls[i+1] -= 1
print ans


Measured memory_bytes: 8964
#include<cstdio>
#include<algorithm>
using namespace std;
int f[3][101],a[3][101],N;
int main()
{
	scanf("%d",&N);
	for(register int i=1;i<=2;i++)
		for(register int j=1;j<=N;j++)
			scanf("%d",&a[i][j]);
	for(register int i=1;i<=2;i++)
		for(register int j=1;j<=N;j++)
			f[i][j]=max(f[i-1][j],f[i][j-1])+a[i][j];
	printf("%d\n",f[2][N]);				
	return 0;		
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll r, c, m;
    cin>>r>>c>>m;
    map<ll, ll> row, col;
    map<pl, ll> allt;
    ll m1=0, m2=0;
    ll ans=0;
    forr(i, m)
    {
    	ll x, y;
    	cin>>x>>y;
    	--x, --y;
    	allt[{x, y}]++;
    	row[x]++, col[y]++;
  		m1=max(m1, row[x]), m2=max(m2, col[y]);
    }
    vl rr, cc;
    forr(i, r)
    {
    	if(row[i]==m1)
    		rr.pb(i);
    }
    forr(j, c)
    {
    	if(col[j]==m2)
    		cc.pb(j);
    }
    ans=m1+m2-1;
    forr(i, rr.size())
    {
    	forr(j, cc.size())
    	{
    		ll rrr=rr[i], ccc=cc[j];
    		if(allt.find({rrr, ccc})==allt.end())
    		{
    			cout<<ans+1<<endl;
    			return;
    		}
    	}
    }
    cout<<ans<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 67852
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <ctime>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("data","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
char str[maxn];
int main()
{
#ifdef LOCAL
    in();
#endif
    scanf("%s",str);
    int len = strlen(str);
    if (str[0]==str[len-1]) len--;
    if (len&1) puts("First");
    else puts("Second");
    return 0;
}


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

const int N = 2e5;
int n, m, a[N];
// ans >= k ?
bool solve(int k) {
  int cnt = 1;
  int c = m - 1;
  vector<int> b(n);
  for(int i = 1; i < n; i++) {
    if((a[i] >= k) == (a[i - 1] >= k)) {
      cnt++;
    } else {
      b.emplace_back(cnt);
      cnt = 1;
    }
  }
  b.emplace_back(cnt);
  int now = 0;
  cnt = 0;
  for(int i = 0; i < b.size(); i++) {
    if(b[i] != 1) {
      int l = now - cnt, r = now - 1;
      if(l <= c && c <= r) {
        int f = a[now] >= k;
        int t = a[now - cnt - 1] >= k;
        if(c - l > r - c) return f;
        return t;
      }
      l = now, r = now + b[i] - 1;
      if(l <= c && c <= r) {
        return a[now] >= k;
      }
      cnt = 0;
    } else cnt++;
    now += b[i];
  }
  return a[0] >= k;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> m; n = m + m - 1;
  for(int i = 0; i < n; i++) cin >> a[i];
  int ok = 1, ng = n + 1;
  while(ng - ok > 1) {
    int mid = (ng + ok) >> 1;
    if(solve(mid)) ok = mid; else ng = mid;
  }
  cout << ok << endl;
}


Measured memory_bytes: 3428
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0 || i % 5 == 0) {
                continue;
            }
            sum += i;
        }
        System.out.println(sum);
    }

}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n;
  cin >> n;
  vi c(n);
  rep (i, n) {
    cin >> c[i];
    c[i]--;
  }

  vl dp(n + 1);
  dp[0] = 1;
  vi pre(200000, -1);
  rep (i, n) {
    dp[i + 1] = dp[i];
    int j = pre[c[i]];
    if (j != -1 && j != i - 1) {
      (dp[i + 1] += dp[j + 1]) %= MOD;
    }
    pre[c[i]] = i;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  string s;
  cin >>s;
  if(s=="A") cout <<"T"<<endl;
  else if(s=="C") cout <<"G"<<endl;
  else if(s=="G") cout <<"C"<<endl;
  else if(s=="T") cout <<"A"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=101000;
int n,tot,front[MAXN],ord[2][MAXN],ans1,ans2;
struct edge{
	int to,next;
}e[MAXN*2];
void init(int from,int to)
{
	tot++;
	e[tot].to=to;
	e[tot].next=front[from];
	front[from]=tot;
}

void dfs(int u,int father,bool t)
{
	ord[t][u]=ord[t][father]+1;
	for(int i=front[u];i;i=e[i].next)
	{
		int v=e[i].to;
		if(v!=father)
			dfs(v,u,t);
	}
}

int main()
{
	//freopen("test.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		init(x,y);
		init(y,x);
	}
	dfs(1,0,0);
	dfs(n,0,1);
	for(int i=1;i<=n;i++)
		if(ord[0][i]<=ord[1][i])
			ans1++;
		else
			ans2++;
	if(ans2>=ans1)
		printf("Snuke");
	else
		printf("Fennec");
	return 0;
}

Measured memory_bytes: 7552
#include<iostream>
using namespace std;
#define df 0

int main(){
  int n; cin >> n;
  int prev; cin >> prev;
  int cnt=0;
  for(int i=1;i<n;i++){
    int temp; cin >> temp;
    if(temp==prev){
      cnt++;
      prev=0;
    }else{
      prev=temp;
    }
  }
  cout << cnt;
}

/// confirm df==0 ///


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  vector<int> l_most, r_most;
  for (int i = 0; i < (int) s.size(); i++) {
    (s[i] == 'L' ? l_most : r_most).push_back(i);
  }
  vector<int> ans(s.size());
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] == 'R') {
      int pos = *lower_bound(l_most.begin(), l_most.end(), i);
      if ((pos - i) % 2 == 0) ++ans[pos];
      else ++ans[pos - 1];
    } else {
      int get_l = *lower_bound(l_most.begin(), l_most.end(), i);
      auto pos = lower_bound(r_most.begin(), r_most.end(), get_l);
      --pos;
      if ((i - *pos) % 2 == 0) ++ans[*pos];
      else ++ans[*pos + 1]; 
    }
  }
  for (int i : ans) cout << i << ' ';
  cout << '\n';
  return 0;
}


Measured memory_bytes: 1612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int n, ary[50];

int solve(int i, int m) {
	if (m == 0) return 1;
	if (i >= n) return 0;

	int res = solve(i + 1, m) || solve(i + 1, m - ary[i]);
	return res;
}


int main() {


	int q, m, i;
	cin >> n;
	vector<int> num(n);
	for (int i = 0;i < n;i++) {
		cin >> ary[i];
	}


	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> m;

		if (solve(0, m)) {
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3108
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e9,M=1e9+7;
const int N=1e5+5;

vi v[N];
int dp[N][3];

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

    for(int i=0;i<m;++i)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
    }

    int s,t;
    cin>>s>>t;

    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<3;++j)
            dp[i][j]=inf;
    }

    priority_queue<pii> pq;
    dp[s][0]=0;
    pq.push({0,s});

    while(!pq.empty())
    {
        auto p=pq.top();
        pq.pop();

        int dist=-p.F,x=p.S;
        int a=dist%3,b=(dist+1)%3;
        for(auto c:v[x])
        {
            if(dp[c][b]>dp[x][a]+1)
            {
                dp[c][b]=dp[x][a]+1;
                pq.push({-dp[c][b],c});
            }
        }
    }

    if(dp[t][0]==inf)
        cout<<-1;
    else
        cout<<dp[t][0]/3;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 8192
S = input()

a = S[0]
b = None
acount = 0

for i in range(4):
    if a == S[i]:
        acount += 1
    else:
        b = S[i]
        
bcount = 0
for i in range(4):
    if b == S[i]:
        bcount += 1
if acount == 2 and bcount ==2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k=int(input())

print(list[k-1])


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#define MAX 100001
int partition(int *,int ,int);

int main() {
  int A[MAX],n,i,q;

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

  q = partition(A,0,n-1);
  
 for(i=0;i < q;i++){
    printf("%d",A[i]);
    printf(" ");
  }
 
 printf("[%d] ",A[q]);
   
  for(i=q+1;i < n;i++){
    printf("%d",A[i]);
    if(i < n-1){
    printf(" ");
    }
  }
  printf("\n");

  return 0;
}

int partition(int *A,int p,int r) {
  int x,i,j,tmp;
  x = A[r];
  i = p-1;
  for(j = p;j < r;j++) {
    if(A[j] <= x) {
      i = i+1;
      tmp = A[i]; 
      A[i] = A[j];
      A[j] = tmp;
    }
  }
    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;
	  
  return i+1;
     }

Measured memory_bytes: 992
#include<bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> parent, sz;
  UF(int n) {
    parent.resize(n);
    sz.resize(n, 1);
    iota(parent.begin(), parent.end(), 0);
  }
  void unite(int u, int v) {
    int pu = find(u);
    int pv = find(v);
    if (pu == pv) return;
    parent[pu] = pv;
    sz[pv] += sz[pu];
  }
  int find(int x) {
    int p = parent[x];
    if (p == x) return x;
    int pp = find(p);
    parent[x] = pp;
    return pp;
  }
  int size(int x) {
     return sz[find(x)];
  }
  bool same(int a, int b) {
    return find(a) == find(b);
  }
};
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UF uf(n);
  vector<int> bias(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
    bias[a]--, bias[b]--;
  }
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (uf.same(a, b)) {
      bias[a]--, bias[b]--;
    }
  }

  for (int i = 0; i < n; i++) {
    // cerr << uf.find(i) << " " << uf.size(i) << endl;
    cout << uf.size(i) + bias[i] - 1<< endl;
  }
}

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

int main()
{
  int n;
  cin >> n;
  int m;
  cin >> m;

  if (n%2) {
    for (int i=1; i<=m; i++) {
      int l = i;
      int r = n-i;
      printf("%d %d\n", l, r);
    }
  } else {
    bool flg = false;
    for (int i=1; i<=m; i++) {
      int l = i;
      int r = n-i;
      if (!flg && r-l <= n/2) flg = true;
      if (flg) r--;
      printf("%d %d\n", l, r);
    }
  }

  return 0;
}


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

int main(){
  int a,i=0;
  cin>>a;
  if (a>99){
    i++;
    if(a>109){
      i++;
    }
  }else if(a>9){
    i++;
  }
  if(a%2==1){
    i++;
  }
  
  cout<<i<<endl;
}
  

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
	while (true) {
		int K;
		scanf("%d", &K);
		if (K == 0) {
			break;
		}
		
		int ans = 0;
		for (int i = 0; i < K * (K - 1) / 2; i++) {
			int tmp;
			scanf("%d", &tmp);
			ans += tmp;
		}
		ans /= K - 1;
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int x;
    cin >> x;;
    
    if (x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <numeric>

//#include <map>

using namespace std;

class CSet
{
	int mm, mf, mr;
	char chRank;

	void calcRank()
	{
		int sum = 0;
		sum = mm + mf;
		if (mm == -1 || mf == -1)
		{
			chRank = 'F';
		}
		else if (sum >= 80)
		{
			chRank = 'A';
		}
		else if (sum >= 65)
		{
			chRank = 'B';
		}
		else if (sum >= 50)
		{
			chRank = 'C';
		}
		else if (sum >= 30)
		{
			if (mr >= 50)
			{
				chRank = 'C';
			}
			else
			{
				chRank = 'D';
			}
		}
		else
		{
			chRank = 'F';
		}
	}

public:

	CSet(int m, int f, int r) 
	{
		mm = m; mf = f; mr = r;
		calcRank();
	}

	char getRank()
	{
		return chRank;
	}
};

int main()
{
	vector<CSet> vs;

	while (1)
	{
		int m, f, r;
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1)break;
		CSet set(m, f, r);
		vs.push_back(set);
	}

	for (int i = 0; i < vs.size(); i++)
	{
		cout << vs.at(i).getRank() << endl;
	}

	return 0;
}

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


using namespace std;





int main(){


	int n;cin>>n;
	vector<int> A(n);
	for(int i=0; i<n;i++){
		cin>>A[i];
	}
	int ans = 0;
	for(int i = 1; i< n-1; i++){
		if((A[i-1]<A[i]&&A[i]<A[i+1])||(A[i-1]>A[i]&&A[i]>A[i+1])){
			ans++;
		  }
	  }
	cout<<ans<<endl;
	}





Measured memory_bytes: 256
#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 ALP_NUM = 26;

int main() {
    int d;
    cin >> d;
    vector<int> C(ALP_NUM);
    rep(i, ALP_NUM) cin >> C[i];
    vector<vector<int>> S(d, vector<int>(ALP_NUM));
    rep(i, d) rep(j, ALP_NUM) cin >> S[i][j];
    vector<int> T(d);
    vector<set<int>> schedules(ALP_NUM);
    rep(i, ALP_NUM) schedules[i].insert(-1);
    rep(i, d) {
        cin >> T[i];
        --T[i];
        schedules[T[i]].insert(i);
    }

    auto get_score = [&](vector<int> A, int n) {
        int res = 0;
        vector<int> D(ALP_NUM, -1);
        rep(i, n) {
            int t = A[i];
            res += S[i][t];
            D[t] = i;
            rep(j, ALP_NUM) {
                res -= (i-D[j]) * C[j];
            }
        }
        return res;
    };

    auto change = [&](int nd, int nt) {
        int pt = T[nd];
        int res = S[nd][nt] - S[nd][pt];

        auto it_l = schedules[pt].lower_bound(nd);
        auto it_r = schedules[pt].upper_bound(nd);
        --it_l;
        int pt_ld = *it_l;
        int pt_rd;
        if (it_r != schedules[pt].end()) pt_rd = *it_r;
        else pt_rd = d;
        res -= C[pt] * (nd-pt_ld) * (pt_rd-nd);

        it_l = schedules[nt].lower_bound(nd);
        it_r = schedules[nt].upper_bound(nd);
        --it_l;
        int nt_ld = *it_l;
        int nt_rd;
        if (it_r != schedules[nt].end()) nt_rd = *it_r;
        else nt_rd = d;
        res += C[nt] * (nd-nt_ld) * (nt_rd-nd);

        return res;
    };


    int score = get_score(T, d);

    int m;
    cin >> m;
    rep(i, m) {
        int nd, nt;
        cin >> nd >> nt;
        --nd; --nt;
        int diff = change(nd, nt);
        
        score += diff;
        int pt = T[nd];
        schedules[pt].erase(nd);
        schedules[nt].insert(nd);
        T[nd] = nt;

        cout << score << endl;
    }

    return 0;
}

Measured memory_bytes: 3688
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

N, M = map(int, input().split())
S = input()
T = input()
g = gcd(N, M)
for i in range(g):
    if S[i*N//g] != T[i*M//g]:
        print(-1)
        break
else:
    print(N*M//g)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){	
		
	/*map<ll, ll> m;
	ll n, sum=0;
	cin>>n;
	
	for(ll i=0; i<n; i++){
		
		ll x;
		cin>>x;
		sum+=x;
		m[x]++;
	}
	
	ll q;
	cin>>q;
	
	while(q--){
		
		ll b,c;
		cin>>b>>c;
		sum=sum+m[b]*(c-b);
		cout<<sum<<endl;
		
		map<ll, ll>:: iterator i=m.find(b);
		if(i!=m.end()){
			
			ll value=i->second;
			m.erase(i);
			m[c]=value+m[c];
		}
	}*/
	ll n;
	cin>>n;
	ll ans=0;
	ll arr[n];
	
	for(ll i=0; i<n; i++){
		
		cin>>arr[i];
		ans=ans^arr[i];
	}
	
	for(ll i=0; i<n; i++){
		
		ll x=ans^arr[i];
		cout<<x<<" ";
	}
}

Measured memory_bytes: 5180
class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const myIterator& begin(){return i;}const myIterator& end(){return n;}};

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

using i64 = long long;
void calc(i64 mean, const vector<i64>& vec, vector<i64>& ma) {
    for(int i : in(vec.size())) {
        i64 t = vec[i];
        i64 plus = mean > t ? mean - t : t - mean;
        ma[i] += plus;
    }
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    i64 w, h, n;
    cin >> w >> h >> n;
    vector<i64> xcoord(n), ycoord(n);
    for(int i : in(n))
      cin >> xcoord[i] >> ycoord[i];
    auto sortx = xcoord, sorty = ycoord;
    sort(sortx.begin(), sortx.end());
    sort(sorty.begin(), sorty.end());
    vector<i64> midId = {n / 2};
    if(~n & 1) midId.emplace_back(n / 2 - 1);
    i64 sum = 0LL;
    for(int i : in(n)) {
        if(i <= midId[0])
          sum += sortx[midId[0]] - sortx[i] + sorty[midId[0]] - sorty[i];
        else
          sum += sortx[i] - sortx[midId[0]] + sorty[i] - sorty[midId[0]];
    }
    tuple<i64, i64, i64> ans(0LL, -1e18, -1e18);
    vector<i64> ma(n, 0LL);
    for(auto id1 : midId) for(auto id2 : midId) {
        i64 x = sortx[id1], y = sorty[id2];
        fill(ma.begin(), ma.end(), 0LL);
        calc(x, xcoord, ma); calc(y, ycoord, ma);
        ans = max(ans, make_tuple(*max_element(ma.begin(), ma.end()), -x, -y));
    }
    i64 minus, x, y; tie(minus, x, y) = ans;
    cout << sum * 2LL - minus << '\n' << -x << ' ' << -y << endl;
    return 0;
}

Measured memory_bytes: 6868
#include <stdio.h>

int main(void)
{
	int n;
	int i, j, k, l;
	int count;
	int sum;
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		for (i = 0; i < 10; i++){
			for (j = 0; j < 10; j++){
				for (k = 0; k < 10; k++){
					for (l = 0; l < 10;l++){
						sum = i + j + k + l;
						if (sum == n){
							count++;
						}
					}
				}
			}
		}
		printf("%d\n", count);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
char s[200005];
int main()
{
    scanf("%s",s);
    long long ans=1;
    int l=strlen(s);
    sort(s,s+l);
    for(int i=0;i<l;)
    {
        int t=upper_bound(s+i+1,s+l,s[i])-s;
        if(t==l)break;
        ans+=1LL*(t-i)*(l-t);
        i=t;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m=1000000007;
int main() {
	ll m,n,k,i,j,w;
	string a,b;
	cin>>a>>b;
	n=a.length();
	m=b.length();
	vector<vector<ll>>dp(n+1,vector<ll>(m+1,0));
	for(i=0;i<n;i++)
	{
	    for(j=0;j<m;j++)
	    {
	        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
	        if(a[i]==b[j])
	        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
	    }
	}
	k=dp[n][m];
	string ans="";
	if(k==0)
	{
	    cout<<' ';
	    return 0;
	}
	i=n,j=m;
	while(1)
	{
	    if(ans.length()==k)
	    break;
	    if(a[i-1]==b[j-1])
	    {
	        ans+=a[i-1];
	        i=i-1;
	        j=j-1;
	    }
	    else if(dp[i][j-1]==dp[i][j])
	    {
	        j=j-1;
	    }
	    else
	    {
	        i-=1;
	    }
	}
	for(i=k-1;i>=0;i--)
	cout<<ans[i];
	return 0;
}


Measured memory_bytes: 73712
import java.util.*;

public class Main {

	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		char a=sc.next().charAt(0);
		char b=sc.next().charAt(0);
		if(a=='H') {
			if(b=='H') System.out.println("H");
			else System.out.println("D");
		}
		if(a=='D') {
			if(b=='H') System.out.println("D");
			else System.out.println("H");
		}
	}
}


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

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

typedef long long ll;

void solve(){
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;++i){
		cin>>a[i];
		if(i>=k){
			if(a[i]>a[i-k])cout<<"Yes\n";
			else cout<<"No\n";
		}
	}
}

int main(){
	Red;
	int T=1;
	//cin>>T;
	while(T--)solve();
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  int d=max(a,b);
  int e=max(d,c);
  int f=min(a,b);
  int g=min(f,c);
  int h=a+b+c-g-e;
  if((g%2==0&&h%2==0)||(g%2==1&&h%2==1))
  cout<<(e*3-(a+b+c))/2;
  else
    cout<<((e+1)*3-(a+b+c+2))/2+1;
    
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

if $0 == __FILE__
  N, Y = gets.split(' ').map &:to_i
  # i:    1000円札の数
  # j-i:  50000円札の数
  # N-j:  1000円札の数
  (0..N).each do |i|
    (i..N).each do |j|
      if Y == 1000*i + 5000*(j-i) + 10000*(N-j)
        puts "#{N-j} #{j-i} #{i}"
        exit
      end
    end
  end

  puts "-1 -1 -1"
end


Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define WHITE 0
#define GRAY 1
#define BLACK 2

void bfs(int);

int n, A[101][101], color[101], d[101], Q[101];

int main(){
  int u, k, v, i, j;
  
  scanf("%d", &n);

  for(i = 1; i <= n; i++){
    color[i] = WHITE;
    d[i] = -1;
    Q[i] = -1;
    for(j = 1; j <= n; j++){
      A[i][j] = 0;
    }
  }

  for(i = 1; i <= n; i++){
    scanf("%d%d", &u, &k);
    for(j = 1; j <= k; j++){
      scanf("%d", &v);
      A[u][v] = 1;
    }
  }

  bfs(1);

  for(i = 1; i <= n; i++) printf("%d %d\n", i, d[i]);
  
  return 0;
}

void bfs(int s){
  int u, v, i;

  color[s] = GRAY;
  d[s] = 0;
  
  Q[1] = s;

  while(Q[1] != -1){
    
    u = Q[1];
    for(i = 1; Q[i] != -1; i++) Q[i] = Q[i+1];
    
    for(v = 1; v <= n; v++){
      if(color[v] == WHITE && A[u][v] == 1){
	color[v] = GRAY;
	d[v] = d[u] + 1;
	
	for(i = 1; ; i++){
	  if(Q[i] == -1){
	    Q[i] = v;
	    break;
	  }
	}
	
      }
    }
      color[u] = BLACK;
  }
}

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

#define num_max(p,q)((p)>(q)?(p):(q))
#define num_min(p,q)((p)<(q)?(p):(q))
int cmp(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;//昇順
	 //降順ならreturn *(int*)b - *(int*)a;
}
int main()
{
	long long n,i,ans=0;
	long long b[110];
	scanf("%lld", &n);
	for (i = 1;i <= n-1;i++)scanf("%lld", &b[i]);
	ans += b[1];
	for (i = 2;i <= n-1;i++)
	{
		ans += num_min(b[i-1], b[i]);
	}
	ans += b[n - 1];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
/*
Author: CNYALI_LK
LANG: C++
PROG: C.cpp
*/
#include<bits/stdc++.h>
#define up(a,b,c) for (int a(b),a##end(c);a<=a##end;++a)
#define down(a,c,b) for (int a(b),a##end(c);a>=a##end;--a)
#define uup(a,c,b) for (int a(b),a##end(c);a<=a##end;++a)
#define udown(a,b,c) for (int a(b),a##end(c);a>=a##end;--a)
#define endl '\n'
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
const double eps=1e-8;
const long double PI=acos(-1.0);
typedef long long ll;
template<class T>void chkmin(T &a,T b){a=a<b?a:b;}
template<class T>void chkmax(T &a,T b){a=a>b?a:b;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
struct zb{
	int x,y;
	void read(){
		scanf("%d%d",&x,&y);
	}
};
zb a,b,s[201010];
int cmp(zb a,zb b){
	return a.x<b.x;
}
int xa[201010],xb[201010],l,r;
const long double asd=20-5*PI;
const long double ttp=5*PI;
int main(){
#ifdef cnyali_lk
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	a.read();
	b.read();
	if(a.x>b.x)swap(a,b);
	int n,t=0,sxy=a.y<b.y?a.y:b.y,sty=a.y+b.y-sxy;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		s[i].read();
		if(s[i].x>=a.x&&s[i].x<=b.x&&s[i].y>=sxy&&s[i].y<=sty);else {--n;--i;}
	}
	sort(s+1,s+n+1,cmp);
	if(!n){
		printf("%.15Lf\n",(long double)(b.x-a.x+sty-sxy)*100);
		return 0;
	}
	for(int i=1;i<=n;++i)xa[i]=s[i].y;
	int len=0,mid;
	
	if(a.y<b.y){
		xb[++len]=xa[1];
		for(int i=2;i<=n;++i){
			l=1;r=len;
			while(l<=r){
				mid=(l+r)>>1;
				if(xb[mid]>xa[i])r=mid-1;
				else l=mid+1;
			}
			xb[r+1]=xa[i];
			if(r==len)++len;
		}
		int tp= (len==b.y-a.y+1)||(len==b.x-a.x+1);
		printf("%.15Lf\n",(long long)(b.y-a.y+b.x-a.x)*100-asd*len+tp*ttp);
	}
	else{
		xb[++len]=xa[1];
		for(int i=2;i<=n;++i){
			l=1;r=len;
			while(l<=r){
				mid=(l+r)>>1;
				if(xb[mid]<xa[i])r=mid-1;
				else l=mid+1;
			}
			xb[r+1]=xa[i];
			if(r==len)++len;
		}
		int tp=(len==a.y-b.y+1)||(len==b.x-a.x+1);
		printf("%.15Lf\n",(long long)(a.y-b.y+b.x-a.x)*100-asd*len+tp*ttp);

	}
	return 0;
}



Measured memory_bytes: 3328
#include <iostream>

using namespace std;

static const unsigned long long C = 1000000007;

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

    unsigned long long n;
    unsigned long long power = 1;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        power %= C;
        power *= (i + 1) % C;
        power %= C;
    }

    cout << power << endl;

    return 0;
}


Measured memory_bytes: 256
pub mod fenwick_tree {
    pub struct FenwickTree {
        n: usize,
        dat: Vec<i64>,
    }

    impl FenwickTree {
        pub fn new(n: usize) -> FenwickTree {
            let n2 = n.next_power_of_two();
            FenwickTree {
                n: n2,
                dat: vec![0; n2 + 1],
            }
        }

        pub fn add(&mut self, k: usize, v: i64) {
            let mut i = k as i32;
            while i <= self.n as i32 {
                self.dat[i as usize] += v;
                i += i & (-i);
            }
        }

        pub fn sum(&self, l: usize, r: usize) -> i64 {
            self._sum(r) - self._sum(l - 1)
        }

        pub fn _sum(&self, r: usize) -> i64 {
            let mut result = 0;
            let mut i = r as i32;
            while i >= 1 {
                result += self.dat[i as usize];
                i -= i & (-i);
            }
            result
        }
    }
}

extern crate proconio;
use proconio::input;

fn main() {
    input! {
        n: usize,
        q: usize,
        a: [usize; n],
        lr: [(usize, usize); q],
    }
    let mut lri = lr
        .iter()
        .zip(0..q)
        .map(|(&(l, r), i)| (l, r, i as usize))
        .collect::<Vec<_>>();
    lri.sort_by(|x, y| x.1.cmp(&y.1));
    let mut t = fenwick_tree::FenwickTree::new(n);
    let mut last: Vec<Option<usize>> = vec![None; n + 1];
    let mut j = 0 as usize;
    let mut ans = vec![-1; q];
    for i in 0..n {
        if let Some(k) = last[a[i]] {
            t.add(k, -1);
        }
        last[a[i]] = Some(i + 1);
        t.add(i + 1, 1);
        while j < q && lri[j].1 == i + 1 {
            let (l, _, k) = lri[j];
            ans[k] = t.sum(l, i + 1);
            j += 1;
        }
    }
    println!(
        "{}",
        ans.iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}


Measured memory_bytes: 83444
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int n, m, pos = 1, ans = 0;
    scanf("%d%d", &n, &m);
    vector< pair<int, int> > d(m);
    for (int i = 0; i < m; ++i) scanf("%d%d", &d.at(i).first, &d.at(i).second);
    sort(d.begin(), d.end(), [](pair<int, int> i, pair<int, int> j) { return i.second < j.second || (i.second == j.second && i.first < j.first); });
    for (int i = 0; i < m; ++i) if (pos <= d.at(i).first) pos = d.at(i).second, ++ans;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1152
ans=0
n=int(input())
lst=[]
for i in range(n):
  lst.append(input())
m=int(input())
x=[]
for j in range(m):
  x.append(input())
for k in set(lst):
  c=lst.count(k)-x.count(k)
  ans=max(ans,c)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int main(){
  string s; int q;
  cin >> s >> q;
  deque<char> deq;
  for(int i=0;i<s.size();i++){
    deq.push_back(s[i]);
  }
  int f = 0;
  for(int i=0;i<q;i++){
    int x; cin >> x;
    if(x==1){
      f++;
      continue;
    }
    int ff; char c;
    cin >> ff >> c;
    if((ff+f)%2==0) deq.push_back(c);
    else deq.push_front(c);
  }
  string ans = "";
  if(f%2==1){
    while(!deq.empty()){
      ans += deq.back();
      deq.pop_back();
    }
  }else{
    while(!deq.empty()){
      ans += deq.front();
      deq.pop_front();
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 4228
n = int(input())
word = [input() for _ in range(n)]
count=0
for i in range (0,n):
    for j in range (i+1,n):
        if (word[i] == word[j]):
            count += 1
for k in range (0,n-1):
    if (word[k][len(word[k])-1] != word[k+1][0]):
        count += 1
if (count == 0):
    print("Yes")
else:
    print("No")

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

int main(){
    char N[3];
    rep(i,3) cin >> N[i];

    if ( (N[0] == '7') || (N[1] == '7') || (N[2] == '7') ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
//ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 200010

using namespace std;

string cislo;
map<char,ll>cis;
int main(){
FAST_READ;
cin>>cislo;
for(ll i=0;i<cislo.size();i++)
{
  if(cislo[i]==cislo[i+1] && cislo[i]==cislo[i+2]  && i+1<cislo.size() && i+2<cislo.size())
  {
  	cout<<"Yes"<<endl;
  	return 0;
  }
}
cout<<"No"<<endl;





return 0;
} 

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#define rep(i,n) for(int i = 0;i<(int)(n);i++);
using namespace std;
using ll = long long;
const ll INF = 100100100100100;


int main() {
	ll N, T;
	cin >> N >> T;
	vector<vector<ll>> road(N, vector<ll>(2));
	for (int i = 0; i < N; i++) cin >> road[i][0] >> road[i][1];
	ll ans = INF;
	for (int i = 0; i < N; i++) {
		if (road[i][1] <= T) {
			ans = min(ans, road[i][0]);
		}
	}
	if (ans == INF) cout << "TLE" << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 256