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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,m,q;
    cin>>n>>m>>q;
    int town[n+1][n+1]={};
    for (int i = 0; i < m; i++){
        int l,r;
        cin>>l>>r;
        town[l][r]++;
    }
    int sum[n+1][n+1]={};
    for (int i = 1; i < n+1; i++){
        for (int j = 1; j < n+1; j++){
            sum[i][j]=sum[i][j-1]+town[i][j];
        }
    }
    for (int i = 0; i < q; i++){
        int l,r,ans=0;
        cin>>l>>r;
        for (int j = l; j <= r; j++)ans+=sum[j][r]-sum[j][l-1];
        cout<<ans<<'\n';
    }
}

Measured memory_bytes: 2944
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long arr[]=new long[n];
		for(int i=0;i<n;i++) {
			arr[i]=sc.nextLong();
		}
		long m=1000000007;
		long psum[]=new long[n];
		psum[n-1]=arr[n-1];
		long sum=0;
		for(int i=n-2;i>=0;i--) {
			psum[i]=(psum[i+1]%m+arr[i]%m)%m;
		}
		long ans=0;
		for(int i=0;i<n-1;i++) {
			long product=((arr[i]%m)*(psum[i+1]%m))%m;
			ans=(ans%m+product%m)%m;
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 51964
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

P p[100001];

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  REP(i, n) cin >> p[i].first >> p[i].second;

  sort(p, p+n, greater<P>());

  
  cout << p[0].first + p[0].second << endl;  
  
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll k, mod, ans;

int main() {
	fastio; cin >> k;
	FOR(i, 1, 5000000) {
		mod = (10 * mod + 7) % k;
		if (mod == 0) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

string s, t;

void Sort(string &s, bool rev) {
	int cnt[26] = {0};
	int i, j;
	
	rep(i, s.length()) cnt[s[i] - 'a']++;
	
	string ret;
	if (!rev) {
		rep(i, 26) {
			rep(j, cnt[i]) {
				ret += (char)('a' + i);
			}
		}
	}
	else {
		rrep(i, 26) {
			rep(j, cnt[i]) {
				ret += (char)('a' + i);
			}
		}
	}
	s = ret;
}

int main() {
	cin >> s >> t;
	Sort(s, false);
	Sort(t, true);
	
	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

typedef long long ll;

int h,w;
char arr[1001][1001];
int dp[1001][1001];

int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>arr[i][j];
        }
    }
    dp[0][0]=1;
    for(int c=0;c<w;c++){
        for(int r=0;r<h;r++){
            if(r==0 && c==0) continue;
            int a=0,b=0;
            if (c-1>-1) a=dp[r][c-1];
            if(r-1>-1) b=dp[r-1][c];
            if(arr[r][c]!='#')
            dp[r][c]=(a%mod + b%mod)%mod;
            else
            dp[r][c]=0;
        }
    }

    cout<<dp[h-1][w-1];

    return 0;
}


Measured memory_bytes: 5120
N,Y = map(int,input().split())

for x in range(N+1):
    if Y - x*10000 < 0: break
    for y in range(N+1):
        if x+y > N: break
        z = N-x-y
        if Y == x*10000 + y*5000 + z*1000:
            print(x,y,z)
            exit()
print('-1 -1 -1')


Measured memory_bytes: 41452
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a, b, n;
	scanf("%lld%lld%lld", &a, &b, &n);
	printf("%lld", (long long)((a * min(b - 1, n)) / b - a * (min(b - 1, n) / b)));
	return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(N,vector<int>(2));;
  for (int i=0;i<N;i++){
    cin >> A[i][0];
    A[i][1]=i;
  }
  sort(A.begin(),A.end());
  int x=A[N-1][1],MAX=A[N-1][0];
  for (int i=0;i<N;i++){
    if (i!=x){
      cout << MAX << endl;
    }
    else {
      cout << A[N-2][0] << endl;
    }
  }
}

Measured memory_bytes: 12544
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int mod = 1e9+7;

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


int main() {

  int a, b;
  string s;
  cin >> a >> b >> s;

  for(int i=0; i<a; i++){
    if( !('0' <= s[i] && s[i] <= '9') ){
      cout << "No" << endl;
      return 0;
    }
  }
  if( s[a] != '-' ){
    cout << "No" << endl;
    return 0;
  }
  for(int i=a+1; i<a+b+1; i++){
    if( !('0' <= s[i] && s[i] <= '9') ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n=int(input())
adj=[[] for i in range(n+1)]
dp=[[-1,-1] for i in range(n+1)]
mod=10**9 +7
def dfs(node,parent,color):
    if dp[node][color]!=-1:
        return dp[node][color]
    count=1
    if color==0:
        for i in adj[node]:
            if i==parent:
                continue
            temp=(dfs(i,node,0)+dfs(i,node,1))%mod
            count=(count*temp)%mod
    else:
        for i in adj[node]:
            if i==parent:
                continue
            temp=dfs(i,node,0)%mod
            count=(count*temp)%mod
    dp[node][color]=count
    return count
for _ in range(n-1):
    u,v=map(int,input().split())
    adj[u].append(v)
    adj[v].append(u)
print((dfs(1,-1,0)+dfs(1,-1,1))%mod)

Measured memory_bytes: 110124
#include<stdio.h>
#include<map>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<utility>
#include<string.h>
#include<string>
#define n 300000
#define loop(a, b) for(int i=a; i<=b; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long lli;
typedef double llf;
bool visit[n + 50];
int arr[n + 50], a, b, c, d, e;
string str1, str2;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
vector<edge> V[n + 50];
void addedge(int a, int b, int c)
{
	edge temp;
	temp.from = a;
	temp.to = b;
	temp.weight = c;
}

////////////////////////////////////////

void solve()
{
	cin >> str1 >> str2;
	int counting = 0;
	loop(0, 2)
	{
		if(str1[i] == str2[i]) counting++;
	}
	cout << counting << '\n';
	
}
int main()
{
	int times = 1;
//	cin >> times;
	loop(0, times - 1)
	{
		solve();
		printf("\n");
	}
	return 0;
}


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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

//---------------------------

int main(){
    ll n;
    cin >> n;
    VL alph(28,55);
    rep(i,n){
        string s;
        cin >> s;
        VL temp(28,0);
        rep(j,s.size()){
            temp[s[j]-'a']++;
        }
        rep(j,28){
            chmin(alph[j], temp[j]);
        }
    }

    rep(i,28){
        int c = alph[i];
        char x = 'a' + i;
        rep(j,c){
            cout << x;
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};




int main(){
  ll n;
  cin >> n;
  if(n%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  ll mul = 10LL;
  while(mul <= n){
    ans += n/mul;
    mul *= 5LL;
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int s, w;
    cin >> s >> w;
    if (s > w) 
        cout << "safe"
             << "\n";
    else
        cout << "unsafe" << "\n";
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
  cin>>n;
  int x=0;
  int max1=0;
  getchar();
  for(int i=0;i<n;i++){
        char s;
  cin>>s;
   if(s=='I'){
   x++;
   }
    else if(s=='D'){
     x--;
    }
    max1=max(max1,x);
  }
  cout<<max1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
template <typename T>
vector<T> selectionsort(vector<T> &a){
    int count=0;
    for(int i=0; i<a.size(); i++){
        T minj = i;
        for(int j=i; j<a.size(); j++){
            if(a[minj] > a[j]){
                minj = j;
            }
        }
        if (minj != i){
            swap(a[i], a[minj]);
            count++;
        }
    }
    rep(i, a.size()){
        cout << a[i];
        if (i == a.size()-1) cout << endl;
        else cout << " ";
    }
    cout << count << endl;
    return a;
}
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    selectionsort<int>(a);
    return 0;
}


Measured memory_bytes: 3156
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
using namespace std;

int B[1000][1000];

int main() {
	long long int N, A[1000][1000], Y = 0;;
	cin >> N;
	for (long long int i = 1; i <= N; i++) {
		for (long long int j = 1; j <= N; j++) {
			cin >> A[i][j];
			Y += A[i][j];
		}
	}
	for (long long int k = 1; k <= N; k++) {
        for (long long int i = 1; i <= N; i++) {
			for (long long int j = 1; j <= N; j++) {
				if (A[i][j] > A[i][k] + A[k][j]) {
					Y = -2;
					goto go;
				}
				else if (A[i][j] == A[i][k] + A[k][j]&&i!=k&&k!=j) {
					if (B[i][j]==0) {
					
						Y -= A[i][j];
						
						B[i][j] = 1;
					 }
				}
			}
		}
	}
go:;

	cout << Y / 2 << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  string A,s,C;
  cin >> A >> s >> C;
  cout << "A" << s.at(0) << "C" <<endl;
    return 0;
}



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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n , x , y;
	cin>>n>>x>>y ;
	int a = (n*10+x)*10+y ;
	return cout<<(a%4 == 0 ? "YES" : "NO") , 0 ;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val graph = Array(N, { mutableListOf<Int>()})
    (1..N-1).forEach {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        graph[a-1].add(b-1)
        graph[b-1].add(a-1)
    }

    /*
    fun dFrom(source: Int) : IntArray {
        val default = Int.MAX_VALUE
        val d = IntArray(N, { default })
        val queue : Queue<Int> = ArrayDeque()
        queue.add(source)
        d[source] = 0
        while (!queue.isEmpty()) {
            val current = queue.poll()
            graph[current].forEach {
                if (d[it] == default) {
                    d[it] = d[current] + 1
                    queue.add(it)
                }
            }
        }
        return d
    }
     */
    fun dFrom(first: Int): Array<Int> {
        val score = Array(N) { 0 }
        val visited = Array(N) { false }
        val queue = ArrayDeque<Int>()
        visited[first] = true
        queue.add(first)
        while(queue.isNotEmpty()) {
            val po = queue.remove()
            graph[po].forEach {
                if (!visited[it]) {
                    queue.add(it)
                    visited[it] = true
                    score[it] = score[po] + 1
                }
            }
        }

        return score
    }
    val dFromS = dFrom(0)
    val dFromT = dFrom(N -1)

    var fennec = 0
    var snuke = 0
    for (i in 0 until N) {
        if (dFromS[i] <= dFromT[i]) {
            fennec++
        } else {
            snuke++
        }
    }
    if (fennec > snuke) {
        println("Fennec")
    } else {
        println("Snuke")
    }
}

Measured memory_bytes: 94232
#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
inline int lowbit(int x){
    return x & (-x);
}
inline int modadd(int x, int y){
    return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
    return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
    return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, b >>= 1;
    }
    return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

int n, a[100005];
unordered_map<int, int> mp;
void init(){
    n = read();
    REP(i, 1, n)
        a[i] = read();
}
void solve(){
    bool have = false;
    for (int i = 1, j = 0; j < 30 && !have; ++j, i <<= 1){
        for (int u = 1; u <= n; ++u){
            if (i & a[u]){
                have = true;
                break;
            }
        }
    }
    if (!have){
        printf("Yes\n");
        return ;
    }
    if (n % 3){
        printf("No\n");
        return ;
    }
    REP(i, 1, n){
        if (!mp.count(a[i])) mp[a[i]] = 0;
        ++mp[a[i]];
    }
    if (mp.size() > 3) {
        printf("No\n");
        return ;
    }
    int tt = n / 3;
    int aa[3], l = 0;
    for (auto& p: mp){
        int k = p.first, v = p.second;
        if (v % tt ){
            printf("No\n");
            return ;
        }
        while (v >= tt)
            v -= tt, aa[l++] = k;
    }
    assert(l == 3);
    if ((aa[0] ^ aa[1]) == aa[2] && (aa[0] ^ aa[2]) == aa[1] && (aa[2] ^ aa[1]) == aa[0]){
        printf("Yes\n");
    }else  {
        printf("No\n");
        return ;
    }
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 6940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,ans=0;
  cin >>n;
  ll p[n];
  for(ll i=0;i<n;i++) cin >>p[i];
  for(ll i=0;i<n;i++){
    if(p[i]==i+1) {
      swap(p[i],p[i+1]);
      ans++;
    }
  }
  cout <<ans<<endl;
}


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

const int N = 2e5 + 5;
vector<int> g[N]; 
bool ans;
int n;

void dfs(int u, int d)
{
	if (u == n) ans = 1;
	if (d == 2) return;
	for (auto v : g[u]) dfs(v, d + 1);
}

int main()
{
	int m; scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	ans = 0;
	dfs(1, 0);
	if (ans) printf("POSSIBLE");
	else printf("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 12016
#include <stdio.h>
int search(int A[], int a, int key);
  
int main(){
  int i,j,k,key,sum=0,A[10000+1];
  scanf("%d",&j);
  for(i=0;i<j;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d",&key);
    if(search(A,j,key)){
      sum++;
	}
  }
    printf("%d\n",sum);
    return 0;
  }
int search(int A[], int a, int key){
  int x=0;
  A[a]=key;
  while(A[x]!=key) x++;
  return x!=a;
}



Measured memory_bytes: 2104
#include <cstdio>
using namespace std;

int main() {
	int k[12], v1, v2, x;
	double h, d;

	while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &k[1], &k[2], &k[3],
			&k[4], &k[5], &k[6], &k[7], &k[8], &k[9], &k[10], &v1, &v2) != EOF) {
		x = 0;
		for (int i = 1; i <= 10; i++) {
			x += k[i];
		}
		h = (double) x / (v1 + v2);
		d = (double) v1 * h;
		x = 0;
		for (int i = 1; i <= 10; i++) {
			x += k[i];
			if (d <= x) {
				printf("%d\n", i);
				break;
			}
		}
	}
}

Measured memory_bytes: 2684
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    int A[200000];
    for(int i = 0; i < Q; i++){
        cin >> A[i];
    }
    int point[200000];
    for(int i = 0; i < N; i++){
        point[i] = 0;
    }
    for(int i = 0; i < Q; i++){
        point[A[i] - 1]++;
    }
    for(int i = 0; i < N; i++){
        if(point[i] - Q + K > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n;
    string s,t;
    cin >> n >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }


    
    return 0;

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int N, M, K, p[20][1010];
char s[15][1005];
inline int sum(int L1,int R1,int L2,int R2){
    return  p[L2][R2] + p[L1 - 1][R1 - 1] - p[L1 - 1][R2] - p[L2][R1 - 1] ;
}
inline void solve(){
	scanf("%d%d%d",&N,&M,&K);
	rep(i,0,N){
		scanf("%s",&s[i]);
		rep(j,0,M){
			if(s[i][j]=='1')p[i+1][j+1] = 1;
		}
	}
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i][j - 1]; }
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i - 1][j]; }
    int res = 1E9;
	for(int bits = 0 ;bits<(1<<(N-1));bits++){
		int n1 = __builtin_popcount(bits);
		if(n1>=res)continue;//剪枝 7ms ~ 3ms 
		VI cut;
		for(int i=0;i<N-1;i++){
			if((bits>>i)&1){
				cut.pb(i+1);
			}
		}
		cut.pb(N);
		int  pcol = 1,ans=sz(cut)-1;
		int ok = 1;
		for(int i=1;i<=M;i++){
			int f=1,prow=1;
			for(int j=0;j<sz(cut);j++){
				if(sum(prow,pcol,cut[j],i)>K){
					f = 0;
					break;
				}
				prow = cut[j]+1;
			}
			if(!f){
				ans++;
				if(pcol==i){//Impossible
					ok = 0;
					break;
				}
				pcol = i;
			}
		}
		if(ok)res = min(res,ans);
	}
	printf("%d\n",res);
}
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i!=n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,q;
    cin >> n >> q;
    string str;
    cin >> str;
    vi s(n+1,0);
    rep(i,n)
    {
        if(str[i]=='A'&&str[i+1]=='C')s[i+1]=s[i]+1;
        else s[i+1]=s[i];
    }

    rep(i,q)
    {
        int l,r;
        cin >> l >> r;
        cout << s[r-1] - s[l-1] << endl;
    }
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;

const int L = 753;
string S;
int ans = INF;

int main() {
	cin >> S;
	rep(i, S.size()-2) {
		string M = "";
		for (int j = i; j < i+3; j++)
		{
			M += S.at(j);
			
		} 
		int tmp = stoi(M);
		ans = min(ans, abs(tmp - L));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void){

    int a,b;
    scanf("%d %d",&a,&b);

    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    rep(i,N){
        cin >> s[i];
        cin >> t[i];
    }
    string X;
    cin >> X;
    int ans = 0;
    bool flag = false;
    rep(i,N){
      if(flag) ans+=t[i];
      if (s[i] == X) flag = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a = gets.chomp.split("")
b = []
for i in 0..a.length-1
  b.push(a.count(a[i]))
end
#puts b
  for j in 0..b.length-1
    if b[j] % 2 == 1
      puts "No"
      exit
    end
  end
  #puts b
  puts "Yes"

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

signed main()
{
    int h, w, k, cnt, ans=0;
    char c[6][7];

    cin >> h >> w >> k;
    for(int i=0; i<h ;i++ ){
        cin >> c[i];
    }

    for(int i=0 ;i<(1<<h) ;i++ ){
        for(int j=0 ;j<(1<<w) ;j++ ){
            cnt = 0;
            for(int x=0 ;x<h ;x++ ){
                for(int y=0 ;y<w ;y++ ){
                    if(i&(1<<x) && j&(1<<y)){
                        if(c[x][y] == '#'){
                            cnt ++;
                        }
                    }
                }
            }
            if(cnt == k){
                ans ++;
            }
        }
    }

    cout << ans << endl;  
    return (0);
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int n, d;
        cin >> n >> d;
        d = 2 * d + 1;
        int ans = (n / d) + (n % d != 0);
        cout << ans << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
int main() {
	ll H,N,x,sum=0;
	scanf("%lld%lld",&H,&N);
	for(int i=1;i<=N;i++)
		scanf("%lld",&x), sum+=x;
	if(sum>=H)
		puts("Yes");
	else
		puts("No");
}

Measured memory_bytes: 256
a,b,k = (int(i) for i in input().split())
al,bl = [a],[b]
for i in range(min(k-1,b-a)):
    al.append(al[i]+1)
for i in range(min(k-1,b-a)):
    bl.append(bl[i]-1)
al.extend(bl)
al = list(set(al))
while True:
    print(min(al))
    al.remove(min(al))
    if al == []:
        exit()


Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,c,d,i,t,e=0,o=0;
    cin>>a;
    int s[a];
    for(i=0;i<a;i++)
    {
        cin>>s[i];
        if(s[i]%2==0)e++;
        else if(s[i]%2==1)o++;

    }if(o==0)cout<<"YES";
    else if(o%2==0)cout<<"YES";
    else cout<<"NO";
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, count = 0, j, k;
  cin >> n;
  for(int i = 0; i < 4; i++){
	j = n%10;
    if(i > 0){
		if(k == j){
			count++;
          if(count == 2){
			goto loopout;
          }
        }else{
          count = 0;
        }
    }
    k = j;
    n /= 10;
  }
  loopout:
  if(count == 2){
	cout << "Yes" << endl;
  }else{
	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

signed main(){
	fast;
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	int dp[3][n];
	dp[0][0]=a[0];
	dp[1][0]=b[0];
	dp[2][0]=c[0];
	for(int i=1;i<n;i++){
		dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1]);
		dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
		dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1]);
		//cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<endl;
	}
	cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
	return 0;
}



Measured memory_bytes: 4992
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;

vector<vector<long long>> dp;
vector<long long> a;

long long solve(int i, int r){
    if(r<0)return 0;
    if(dp[i][r] != -1)return dp[i][r];
    if(i == 0){
        if(r == 0)return 1;
        else return 0;
    }
    dp[i][r] = 0;
    // dp[i][r+1] - dp[i][r] = solve(i-1,r+1) - solve(i-1,r-a[i-1]);
    // for(int k=0;k<=a[i-1];++k){
    //     dp[i][r] += solve(i-1,r-k);
    //     dp[i][r] %= M;
    // }
    dp[i][r] = solve(i,r-1) + solve(i-1,r) - solve(i-1,r-a[i-1]-1);
    dp[i][r] %= M;
    dp[i][r] += M;
    dp[i][r] %= M;
    return dp[i][r];
}

int main(int argc, char const *argv[]) {
    long long n,k;cin>>n>>k;
    a = vector<long long>(n);
    dp = vector<vector<long long>>(n+1,vector<long long>(k+1,-1));
    for(int i=0;i<n;++i)cin>>a[i];
    cout<<solve(n,k)<<endl;
    return 0;
}

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

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	if(a[0]+a[1]==a[2])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

class MyClass
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int suma = 0;
        int sumb = 0;
        for (int i = 0; i < 4; i++)
        {
            suma += int.Parse(str[i]);
        }
        str = Console.ReadLine().Split(' ');
        for (int i = 0; i < 4; i++)
        {
            sumb += int.Parse(str[i]);
        }
        Console.WriteLine((suma >= sumb) ? suma : sumb);
    }
}


Measured memory_bytes: 5612
#include <string>
#include <iostream>
using namespace std;
const int mod = 100000;
int H, W, a[409], dp[524333][3], dp_prev[524333][3]; string s[22];
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> s[i];
	int cnt = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == 'J') a[i * W + j] = 1;
			if (s[i][j] == 'O') a[i * W + j] = 2;
			if (s[i][j] == 'I') a[i * W + j] = 3;
			if (s[i][j] == '?') a[i * W + j] = 0, cnt++;
		}
	}
	dp[0][1] = 1;
	for (int i = 1; i <= H * W; i++) {
		for (int j = 0; j < 1 << (W - 1); j++) {
			for (int k = 0; k < 3; k++) dp_prev[j][k] = dp[j][k], dp[j][k] = 0;
		}
		for (int j = 0; j < 1 << (W - 1); j++) {
			for (int k = 0; k < 3; k++) {
				if (a[i - 1] - 1 != k && a[i - 1] != 0) continue;
				if (k == 0 && (j & 1) == 0) {
					for (int l = 0; l < 3; l++) dp[j][k] += dp_prev[j >> 1][l] + dp_prev[(1 << (W - 2)) + (j >> 1)][l];
					dp[j][k] %= mod;
				}
				if (k == 1) {
					bool flag = (i % W == 1);
					if (!(j & 1)) for (int l = (flag ? 0 : 1); l < 3; l++) dp[j][k] += dp_prev[j >> 1][l] + dp_prev[(1 << (W - 2)) + (j >> 1)][l];
					else if(!flag) dp[j][k] += dp_prev[j >> 1][0] + dp_prev[(1 << (W - 2)) + (j >> 1)][0];
					dp[j][k] %= mod;
				}
				if (k == 2 && (j & 1) == 0) {
					for (int l = 0; l < 3; l++) dp[j][k] += dp_prev[j >> 1][l];
					dp[j][k] %= mod;
				}
			}
		}
	}
	int power = 1;
	for (int i = 0; i < cnt; i++) power = power * 3 % mod;
	int sum = 0;
	for (int i = 0; i < (1 << (W - 1)); i++) {
		for (int j = 0; j < 3; j++) sum = (sum + dp[i][j]) % mod;
	}
	cout << (power - sum + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 15456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 100000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const ll MAXN = 1e18;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int n;
	cin >> n;
	int ans = 0;
	for(int i=1; i<n; i++){
		ans+=(n-1)/i;
	}
	cout << ans << endl;
	return 0;
}
//^-^

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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    string S; cin >> S;
    sort(S.begin(), S.end());
    if (S[0] == S[1] && S[2] == S[3]) {
        if (S[0] == S[2]) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(LL i = (a), i##_end_ = (b); i <= i##_end_ ; ++i)
typedef long long LL;
#define Maxn 100009
LL n, a[Maxn], dif[Maxn];
LL sum, k;
void check() {
	rep(i, 1, n) dif[i] = a[i] - a[i + 1]; 
	LL tmp = 0;
	rep(i, 1, n) {
		dif[i] += k;
		if(dif[i] % n || dif[i] < 0) puts("NO"), exit(0);
		tmp += dif[i] / n;
	}
	puts(tmp == k ? "YES" : "NO");
}

int main(){
	scanf("%lld", &n);
	rep(i, 1, n) scanf("%lld", &a[i]);
	a[n + 1] = a[1];
	rep(i, 1, n) sum += a[i];
	if(sum % (n * (n + 1) / 2)) {
		puts("NO");
		return 0;
	}
	k = sum / (n * (n + 1) / 2);
	check();
	return 0;
}


Measured memory_bytes: 1792
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF 1000000000
using namespace std;
//ワーシャルフロイド
//グラフの全点間の最短距離を求める
//初期化はVを入力で受け取った直後
//O(n^3)
//これはAtcoder Beginner Contest 012のD問題

int d[301][301];//i,j間の最短距離
int E, V;//辺,頂点

void init(){
    REP(i, V){
        REP(j, V){
            if(i == j) d[i][j] = 0;
            else d[i][j] = INF;
        }
    }
}

void make(){
    REP(i, E){
        int u, v, c;
        cin >> u >> v >> c;
        u--; v--;
        d[u][v] = c;
        d[v][u] = c;
    }
}

void wd(){
    REP(k, V){
        REP(i, V){
            REP(j, V){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main(){
	int R;
	cin >> V >> E >> R;
	
	vector<int> r;
	REP(i, R){
		int in;
		cin >> in;
		in--;
		r.push_back(in);
	}
	sort(r.begin(), r.end());

    init();
    make();
    wd();

	int ans = INF;

	do{
		int st[R];
		int cost = 0;
		int j = 0;
		for(auto x : r){
			st[j] = x;
			j++;
		}

		REP(i,R-1){
			cost += d[st[i]][st[i+1]];
		}

		ans = min(ans,cost);
	}while(next_permutation(r.begin(), r.end()));


	cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

void solve() {
    ll n;
    cin >> n;
    
    auto check = [&](ll d) {
        for (ll y = -500; y <= 500; ++y) {
            ll x = d + y;
            ll res = x*x*x*x*x - y*y*y*y*y;
            
            if (res == n) {
                cout << x << ' ' << y << '\n';
                exit(0);
            }
        }
    };
    
    for (ll d = 1; d * d <= n; ++d) {
        if (n % d == 0) {
            check(d);
            check(n / d);
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> g(n, vector<int>());
    vector<int> d(n, -1);

    rep(i, n)
    {
        int k;
        cin >> k >> k;
        rep(j, k)
        {
            int t;
            cin >> t;
            t--;
            g[i].emplace_back(t);
        }
    }

    queue<int> q;
    q.push(0);
    d[0] = 0;
    while (q.size())
    {
        int v = q.front();
        q.pop();

        for (auto nv : g[v])
        {
            if (d[nv] >= 0)
                continue;

            d[nv] = d[v] + 1;
            q.push(nv);
        }
        // cout << v << " " << q.size() << endl;
    }

    rep(i, n)
    {
        cout << (i + 1) << " " << d[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	


vector<ll> fac; 

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & ll(1)) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>ll(1); // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p) % p; 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
ll nCrModPFermat(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
  
    return ((fac[n]* modInverse(fac[r], p)) % p * (modInverse(fac[n-r], p) % p)) % p; 
} 

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin >> n >> k;
	fac.resize(n+1);
	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%mod; 
	vector <ll> ncr(n);
	for (int z=k-1;z<n;z++){
		ncr[z] = nCrModPFermat(z,k-1,mod);
	}
	ll ans = 0;
	ll mans = 0;
	vector <ll> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z];
		arr[z] %= mod;
	}
	sort(arr.begin(),arr.end());
	for (int z=n-1;z>=k-1;z--){
		ans += (ncr[z]*arr[z])%mod;
		ans %= mod; 
	}
	for (int z=0;z<=n-k;z++){
		ans -= (ncr[n-z-1]*arr[z])%mod;
		ans %= mod;
	}
	if (ans < 0) ans += mod;
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

ll dyn[1000100], ps[1000100];
ll MOD = 1000000007, n;

int main() {
    int i;
    dyn[0] = ps[0] = 1;
    scanf("%lld",&n);
    for (i=1;i<=n;i++) {
        dyn[i] = (dyn[i-1] + ((i>=3)?ps[i-3]:0))%MOD;
        ps[i] = (ps[i-1]+dyn[i])%MOD;
    }
    ll sum = 0;
    for (i=0;i<n-1;i++) {
        sum += (dyn[i]*(((n-1)*(n-1))%MOD+i+1))%MOD;
        sum %= MOD;
    }
    sum += (dyn[n-1]*(n-1))%MOD;
    sum += dyn[n];
    printf("%lld\n",sum%MOD);

    return 0;
}


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

for i in range(n):
    if a[i] < 400:
        a[i] = 0
    elif a[i] < 800:
        a[i] = 1
    elif a[i] < 1200:
        a[i] = 2
    elif a[i] < 1600:
        a[i] = 3
    elif a[i] < 2000:
        a[i] = 4
    elif a[i] < 2400:
        a[i] = 5
    elif a[i] < 2800:
        a[i] = 6
    elif a[i] < 3200:
        a[i] = 7
    else:
        a[i] = 8

if a.count(8) > 0:
    print(max(len(set(a))-1,1),len(set(a)) -1 +a.count(8))
else:
    print(len(set(a)),len(set(a)))

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

int main() {
	string s; cin>>s;
	int ans=0, cur=0, n=s.size();
	for (int i=0; i<n; i++) {
		if (s[i] == 'S') cur=0;
		else cur++;
		ans = max(ans, cur);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
void selectionSort(int *,int);
int count = 0;
int main(){
  int N,A[100];
  int i;
  scanf("%d",&N); //数列の長さ
  for(i = 0;i < N;i++){
    scanf("%d",&A[i]);
  }
  selectionSort(A,N);
    for(i = 0;i < N; i++){
      printf("%d",A[i]);
      if(i != N-1){
      printf(" ");
    }
    }
  printf("\n%d\n",count);
  }
void selectionSort(int *A,int N){
  int i,j,tmp,minj;
  for(i = 0;i < N;i++){
    minj = i;
    for(j = i;j < N;j++){
      if(A[j]<A[minj]){
        minj = j;
      }
    }
    if(A[i] == A[minj]){
    }else{
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    count++;
  }
  }
}



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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }



int main(){
    ll n;
    cin >> n;
    ll a,b;
    ll ansa,ansb;
    rep(i,0,n){
        cin >> a >> b;
        if(i == 0){
            ansa = a;
            ansb = b;
        }
        else{
            ll k = max(ceil((long double)ansa/a),ceil((long double)ansb/b));
            ansa = k*a;
            ansb = k*b;
        }
    }
    cout << ansa+ansb << endl;

}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size() == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    system("pause");
}

Measured memory_bytes: 504
//by shubham_bitsg

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

//#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define F first
#define S second
#define pb insert_back
#define mp make_pair
#define sort(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    int c=0;
    map <int,int> mp;
    vi a(n);
    forl(i,0,n) {
        int t; cin>>t;
        a[i] = t;
        mp[t]++;
    }
    int max = mp.rbegin()->F;
    
    for(int i=0; i<n; i++) {
        
        for(int j = 2*a[i]; j<=max; j += a[i]) {
            if(mp[j]==1) mp[j]++;
        }
    }
    for(int i=0; i<n; i++) {
        if(mp[a[i]]==1) c++;
    }
    cout<<c<<"\n";
}

Measured memory_bytes: 50652
#include <iostream>
#include <set>

int main(void)
{
    int n;
    std::set<int> s;
    std::cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int d;
        std::cin >> d;
        s.insert(d);
    }
    std::cout << s.size() << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin>>N;
  int H[N];
  for(int i=0; i<N; i++){
    cin>>H[i];
  }
  int ans=0;
  
  for(int j=N-1; j>0; j--){
    if(H[j-1]-1>H[j]){
      ans=1;
      break;
    }
    else if(H[j-1]-1==H[j]){
      H[j-1]--;
    }
  }
  
  if(ans==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 640
//A
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int m;
	long long c,d; 
	long long sum=0,tot=0,ans;//sum:位数；tot：总和 
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld",&d,&c);
		sum+=c;
		tot+=d*c;
	}
	if(tot%9!=0)
		ans=sum-1+tot/9;
	if(tot%9==0)
		ans=sum-1+(tot-9)/9;
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256