akhauriyash/Code-Regression huggingface dataset:
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n, m;
	cin >> n >> m;
	if(n == m){
		puts("Yes");
	}else puts("No");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    int L_max = 0, R_min = 1e9 + 1;
    for(int i = 0; i < M; i++)
    {
        int L, R;
        cin >> L >> R;

        L_max = max(L, L_max);
        R_min = min(R, R_min);
    }

    int ans;
    if(L_max == R_min)
    {
        ans = 1;
    }

    else if(L_max > R_min)
    {
        ans = 0;
    }

    else
    {
        ans = R_min - L_max + 1;
    }

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

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
ll n;
vector<ll> segment, v;

void build(ll l=0, ll r=n, ll id=1) {
  if (r - l < 2) {
    segment[id] = v[l]*(v[l] - 1)/2;
    return ;
  }
  ll mid = (l+r)/2;
  build(l, mid, 2*id);
  build(mid, r, 2*id+1);
  segment[id] = segment[2*id] + segment[2*id+1];
}

ll query(ll x, ll y, ll l=0, ll r=n, ll id=1) {
  if (l >= y || r <= x) return 0;
  if (l >= x && r <= y) return segment[id];
  ll mid = (l+r)/2;
  return query(x,y,l,mid,2*id) + query(x,y,mid,r,2*id+1);
}

int main() { _
  cin >> n;
  vector<ll> ball(n);
  v.resize(n, 0); segment.resize(4*n+4);
  for (ll i = 0; i < n; i++) {
    cin >> ball[i];
    v[ball[i]-1]++;
  }
  build();
  for (ll k = 0; k < n; k++) {
    ll m = v[ball[k]-1]-1;
    ll ans = m*(m-1)/2;
    ans += query(0, ball[k]-1) + query(ball[k], n);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 12032
import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		String t = scan.nextLine();

		int num = s.length();
		String check = t.substring(0, num);

		if(s.equals(check)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26980
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int b = 0, r = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') b++;
    else r++;
  }
  cout << min(r, b) * 2 << endl;
  return 0;
}

Measured memory_bytes: 512
a = [int(_) for _ in input().split()]
if all(1 <= i <= 100 for i in a):
    a.sort();print(1 if a[0] == a[1] == a[2] else 2 if a[0] == a[1] or a[1] == a[2] else 3)
else:
    print('hoge!')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main() {
	int D,N,X;
	int A[100];
	cin >> N  >> D >> X;
	for(int i = 0;i<N;i++){
		cin >> A[i];
		if(D%A[i] != 0){
			X = X + (D/A[i])+1; 
		}else{
			X = X + D/A[i];
		}
	}
	cout << X << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 50
string g[N];
int h, w;
int count_bomb(int i, int j) {
    int ans = 0;
    for(int di = -1; di <= 1; di++) {
        for(int dj = -1; dj <= 1; dj++) {
            int ni = i + di;
            int nj = j + dj;
            ans += 0 <= ni and ni < h and 0 <= nj and nj < w and g[ni][nj] == '#';
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> h >> w;
    for(int i = 0; i < h; i++) {
        cin >> g[i];
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(g[i][j] == '#') {
                cout << g[i][j];
            } else {
                cout << count_bomb(i, j);
            }
        }
        cout << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<ll, int> P;

struct edge{int to; ll cost;};

int N;
ll C;
vector<ll> x;
vector<ll> rx;
vector<ll> v;

vector<ll> s(100001);
vector<ll> g(100001);
vector<ll> g2(100001);

int main() {
    cin >> N >> C;
    s[0] = 0;
    x.push_back(0);
    v.push_back(0);
    for(int i = 1; i <= N; i++) {
        ll xx, vv;
        cin >> xx >> vv;
        x.push_back(xx);
        v.push_back(vv);
        s[i] = s[i-1] + v[i];
    }

    rx.push_back(0);
    for(int i = N; i > 0; i--) {
        rx.push_back(C - x[i]);
    }

    for(int i = 1; i <= N; i++) {
        g[i] = max(g[i-1], s[i]-x[i]);
        g2[i] = max(g2[i-1], s[i]-x[i]-x[i]);
    }

    ll ans = 0;
    for(int b = 0; b <= N; b++) {
        int a = N - b;
        ll rs = s[N] - s[N - b];
        ans = max(ans, g[a] + rs - 2 * (rx[b]));
        ans = max(ans, g2[a] + rs - (rx[b]));
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 5740
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = l[0], b = l[1];

            Console.WriteLine(Math.Ceiling((double)(a + b) / 2));
        }

    }
}


Measured memory_bytes: 13268
N, K = map(int, input().split())
A = list(map(int, input().split()))
m = 10**9+7
pos = [*filter(lambda x: x>=0, A)]
neg = [*filter(lambda x: x<0, A)]
pos.sort(reverse=True)
neg.sort()

ans = 1
i,j = 0,0# 使った数
while i+j < K:
    flag = True
    if i == len(pos):
        flag = False
    elif j == len(neg):
        flag = True
    elif pos[i] >= -neg[j]:
        flag = True
    else:
        flag = False

    if flag:
        ans = ans * pos[i] % m
        i += 1
    else:
        ans = ans * neg[j] % m
        j += 1

if j % 2 == 0 or N==K:
    print(ans)
elif len(pos) == 0:
    ans = 1
    for i in range(K):
        ans = ans * neg[len(neg)-1-i] % m
    print(ans)
else:
    flag2 = True
    if i == 0:
        flag2 = True
    elif j == 0:
        flag2 = False
    elif i == len(pos):
        flag2 = False
    elif j == len(neg):
        flag2 = True
    elif pos[i-1]*pos[i] > neg[j-1]*neg[j]:# = を抜いた
        flag2 = True
    else:
        flag2 = False

    if flag2:
        ans = ans * pow(neg[j-1],m-2,m) % m
        ans = ans * pos[i] % m
    else:
        ans = ans * pow(pos[i-1],m-2,m) % m
        ans = ans * neg[j] % m
    print(ans)

Measured memory_bytes: 31460
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll N,a,b;
    Scll3(N,a,b);

    ll ans = 0;
    if( a + b == 0 ){
        printf ("%d\n", 0 );
        return 0;
    }

    ll t = N/(a+b);

    ans += t * a;
    ans += min( a, N%(a+b) );

    printf ("%lld\n", ans );

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();
		int BLACK = 0;
		int WHITE = 0;
		for(int i=0;i<N;i++) {
			if(S.charAt(i)=='.') {
				WHITE++;
			}
		}
		int min = WHITE;
		for(int i=0;i<N;i++) {
			if(S.charAt(i)=='#') {
				BLACK++;
			}
			else {
				WHITE--;
			}

			min = Math.min(min, WHITE + BLACK);
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 26500
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  REP(i, 3){
    if(s[i] ==  '1') s[i] = '9';
    else if(s[i] == '9') s[i] = '1';
  }
  cout << s << endl;
  return 0;
}

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

int main() {
  int M, D;
  cin >> M >> D;
  int ans = 0;
  for (int m = 1; m <= M; ++m)
    for (int d = 1; d <= D; ++d)
      if (d / 10 >= 2 && d % 10 >= 2 && (d % 10) * (d / 10) == m)
        ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main(int argc, char const* argv[]) {
    std::vector<int> v(3);

    for (size_t i = 0; i < 3; i++) {
        std::cin >> v.at(i);
    }

    if ((v[0] == 5 && v[1] == 5 && v[2] == 7) || (v[0] == 5 && v[1] == 7 && v[2] == 5) ||
        (v[0] == 7 && v[1] == 5 && v[2] == 5)) {
        std::cout << "YES" << '\n';
    } else {
        std::cout << "NO" << '\n';
    }


    return 0;
}

Measured memory_bytes: 256
#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)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    printf("%c%c%c\n", a[0], b[0], c[0]);

    return 0;
}


Measured memory_bytes: 256
c=list(map(int,input().split()))
l,r=c[0],c[1]
if r-l>2017:
  print(0)
else:
  ml,mr=l%2019,r%2019
  if ml>mr:
    print(0)
  else:
    mini=2019
    d=mr-ml
    for i in range(d):
      for j in range(d-i):
        if mini>(ml+i)*(ml+i+1+j)%2019:
        	mini=(ml+i)*(ml+i+1+j)%2019
    print(mini)

Measured memory_bytes: 3064
def main():
     n=input()
     k=len(n)
     n=int(n)
     ans=0
     for i in range(1,k):
          if i%2==1:
               ans+=10**i-10**(i-1)
     if k%2==1:
          ans+=n+1-10**(k-1)
     print(ans)
     
if __name__ == '__main__':
     main()

Measured memory_bytes: 38384
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
import math
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  N = int(input())
  G = [[] for i in range(N)]
  C = [-1] * N
  C[0] = 0
  for i in range(N-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    G[u].append((v,w))
    G[v].append((u,w))
  def dfs(now):
    for ne_xt, w in G[now]:
      if C[ne_xt]==-1:
        C[ne_xt]=(C[now]+w)%2
        dfs(ne_xt)
  dfs(0)
  for i in range(N):
    print(C[i])
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 155824
#include<stdio.h>
int first[200000],b[200000];
int go[400000],next[400000];
void search(int k){
	int t=first[k];
	while (t!=0){
		int v=go[t];
		if (b[v]==1){
			b[v]=0;
			search(v);
		}
		t=next[t];
	}
}
int main(){
	int n,m;
	int x,y;
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++){
	scanf("%d %d",&x,&y);
    next[i]=first[x];
    first[x]=i;
    go[i]=y;
    next[i+m]=first[y];
    first[y]=i+m;
    go[i+m]=x;
	}
	int count=0;
	for (int i=1;i<=n;i++){
		b[i]=1;
	}
	for (int i=1;i<=n;i++){
		if (b[i]==0) continue;
		count++;
		b[i]=0;
		search(i);
	}
	printf("%d",count-1);
}

Measured memory_bytes: 5272
#include<stdio.h>
#include <iostream>
#include<math.h>

using namespace std;
int main()
{
	string s;
	cin >> s;

	if (s[0] == s[1] ||
		s[1] == s[2] ||
		s[2] == s[3])
	{
		cout << "Bad" << endl;
	}
	else
	{
		cout << "Good" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
import math

inf = 10**9+7

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())

red = n - k
for i in range(1,k+1):
    if red+1 >= i:
        print(combinations_count(red+1, i)*combinations_count(k-1, i-1)%inf)
    else:
        print(0)

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

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a;
        cin >> a;
        n -= a;
    }
    if(n >= 0) cout << n << endl;
    else cout << -1 << endl;
}


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

num_lists = [a, b, c]
maximum = a
if maximum < b: maximum = b
if maximum < c: maximum = c

max_index = num_lists.index(maximum)
num_lists.pop(max_index)

remainder = num_lists[0] + num_lists[1]
if maximum == remainder:
  ans = 'Yes'
else:
  ans = 'No'
  
print(ans)

Measured memory_bytes: 9072
#include<stdio.h>
int main(void){

int n,x=0,i=1;

scanf("%d",&n);

	for(i=1;i<=n;i++){
		if(i%3 == 0){
			printf(" %d",i);
		}
		else{
			if(i%10 == 3){
			printf(" %d",i);
			}
			else{
				x = i;
				while(x!=0){
					if(x%10 != 3){
					x = x/10;
					}
					else{
					printf(" %d",i);
					break;
					}
				}
			}
		}
	}
	printf("\n");
return 0;
}



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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1&&b!=1)
    {
        cout<<"Alice"<<endl;
    }
    else if(a!=1&&b==1)
    {
        cout<<"Bob"<<endl;
    }
    else if(a==b)
    {
        cout<<"Draw"<<endl;
    }
    else  if(a>b)
    {
        cout<<"Alice"<<endl;
    }
    else if(b>a)
    {
        cout<<"Bob"<<endl;
    }
}


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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N;
    cin >> N;

    ll x = 1;
    ll y = 1;

    for(ll i=0; i<N; i++)
    {
        ll T, A;
        cin >> T >> A;
        // cin >> T[i] >> A[i];
        ll x2, y2;
        if(x%T==0)
        {
            x2 = x/T;
        }

        else
        {
            x2 = x/T + 1;
        }

        if(y%A==0)
        {
            y2 = y/A;
        }

        else
        {
            y2 = y/A + 1;
        }

        ll m = max(x2, y2);

        x = T*m;
        y = A*m;
    }    

    cout << x+y << endl;
    

    return 0;
}

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

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

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

fn main() {
  let n = read::<u32>();
  let x = read::<i32>();
  let mut x_vec = vec![];

  for _ in 0..n {
    let x_i = read::<i32>();
    let x_abs = (x - x_i).abs();
    x_vec.push(x_abs as u32);
  }
  let mut ans = x_vec[0];
  for i in x_vec {
    ans = gcd(ans, i);
  }

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


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


Measured memory_bytes: 4352
#include<bits/stdc++.h> 
using namespace std; 
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<3;++i)
	{
		if(n%10==7)
		{
			printf("Yes\n");
			return 0;			
		}
		n=n/10;
	}
	printf("No\n");
return 0; 
} 


Measured memory_bytes: 3756
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for i in range(D)]

last = [0]*27

for i in range(1,D+1):
    r = 0
    manzokudo = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[k])
            else:
                continue
        if j == 1:
            r = 1
            manzokudo = m
        else:
            if manzokudo < m:
                manzokudo = m
                r = j
    print(r)
    last[r] = i

Measured memory_bytes: 69420
using System;
using System.Collections.Generic;
using System.Linq;

namespace WelcomeAtcordet
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int to = input.IndexOf("A")+1;
            int from = input.LastIndexOf("Z")+1;

            Console.WriteLine((from-to)+1);
        }
    }
}


Measured memory_bytes: 13664
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout << "debug... " << n1 << "\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
public:
    ll x, y;
};
int main()
{
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
        ll h,
        w;
    cin >> h >> w;
    ve<string> grid(h);
    ve<ve<ll>> dp(h, ve<ll>(w, 0));
    rep(i, 0, h)
    {
        cin >> grid[i];
    }
    bool flag = false;
    rep(i, 0, h)
    {
        if (grid[i][0] == '#')
            flag = true;
        if (!flag)
            dp[i][0] = 1;
        else
            dp[i][0] = 0;
    }
    flag = false;
    rep(i, 0, w)
    {
        if (grid[0][i] == '#')
            flag = true;
        if (!flag)
            dp[0][i] = 1;
        else
            dp[0][i] = 0;
    }
    rep(i, 1, h)
    {
        rep(j, 1, w)
        {
            if (grid[i][j] != '#')
                dp[i][j] = (dp[i - 1][j]%rem + dp[i][j - 1]%rem)%rem;
            else
                dp[i][j] = 0;
        }
    }
    cout << dp[h - 1][w - 1] << "\n";
}


Measured memory_bytes: 9216
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    int n; cin >> n;
    int a[200005] = {0};

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

    ll ans = 0;
    ll s = 0, x = 0, r = 0;

    for (int l = 0; l < n; l++) {
        while ( r < n && ( (s+a[r]) == (x^a[r]) ) ) {
            s += a[r];
            x ^= a[r];
            r++;
        }
        ans += (r-l);

        if (l == r) { r++; }
        else {
            s -= a[l];
            x ^= a[l];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,ans=0,P=1;
  cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A.at(i);
  rep(i,N){
    if(i==0){
      ans+=A.at(i)-1;
      P++;
    }else if(A.at(i)==P){
      P++;
    }else{
      if(A.at(i)%P!=0){
        ans+=A.at(i)/P;
      }else{
        ans+=1;
        A.at(i)-=P+1;
        ans+=A.at(i)/P;
      }
    }
  }
  cout << ans << endl;
  
    
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX 100000
#define INF 1e+6
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int a,b,x;
int main(){
  scan(x);scan(a);scan(b);
  prin((x-a)%b);
  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mn(a,b) (a < b ? a : b)
#define mx(a,b) (a > b ? a : b)
#define f first
#define s second
#define mp make_pair
#define all(v) (v).begin(),(v).end()

using namespace std;

int const MAXn = 1e5 + 10;
int arr[MAXn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
        cin>>arr[i];

    int con = 0;
    if(arr[1] == 1)
        swap(arr[1],arr[2]), con++;

    for(int i = 2; i <= n; i++){
        if(arr[i] == i)
            swap(arr[i], arr[i + 1]), con++;
    }
    cout<<con;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int N, a, b, c, cnt = 0;
    
    scanf("%d", &N);
    
    a = N / 100;
    N = N%100;
    b = N/10;
    c = N%10;
    if(a == 7 || b == 7 || c == 7){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 1604
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    ll sum = 0;
    cin >> n;
    vll cnt(100001,0);
    REP(i,n){
        ll a;
        cin >> a;
        cnt[a]++;
        sum += a;
    }
    ll q;
    cin >> q;
    REP(i,q){
        ll b,c;
        cin >> b >> c;
        sum -= b*cnt[b];
        sum += c*cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << "\n";
    }

    return 0;
}

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

int main(){
    int n ;
    cin >> n ;
    int k = 0 ;
    while ( k < n){
        k += 1000 ;
    }
    cout << k - n << endl;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  
  int counter = 0;
  while(N >= K){
    N /= K;
    counter++;
  }
  
  cout << counter+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        
using namespace std;
        
typedef long long ll;
#define mp make_pair
#define pub push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define y0 asdfasdf3rcdt234d5c23xd234dx43

int n;
int a[200007];

const bool is_testing = 0;
int main() { 
    srand('D' + 'E' + 'N' + 'I' + 'S' + 'S' + 'O' + 'N' + time(NULL));
    //mt19937 rnd(time(NULL));
    //ios_base::sync_with_stdio(0); cin.tie(0);
    if (is_testing) {
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    } else {
        //freopen("cpr.in", "r", stdin);
        //freopen("cpr.out", "w", stdout);
    }
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
    	scanf("%d", &a[i]);
    }
    deque<int> d;

    if (n % 2 == 0){
    	for (int i = 0; i < n; i += 2){
    		d.push_back(a[i]);
    		d.push_front(a[i + 1]);
    	}
    } else {
    	for (int i = 0; i < n - 1; i += 2){
    		d.push_front(a[i]);
    		d.push_back(a[i + 1]);
    	}
    	d.push_front(a[n - 1]);
    }

    for (int x : d) printf("%d ", x);
}

Measured memory_bytes: 3840
N, M = map(int, input().split())
K = [[] for i in range(M)]
for i in range(M):
    k = list(map(int, input().split()))
    K[i] = k[1:]

num = 0
P = list(map(int, input().split()))
for i in range(1 << N):
    tmp = [0] * M
    for j in range(N):
        if i & 1 << j:
            for l in range(M):
                if j + 1 in K[l]:
                    tmp[l] += 1

    for j in range(M):
        if tmp[j] % 2 != P[j]:
            break
    else:
        num += 1

print(num)



Measured memory_bytes: 3064
a = [input().split() for _ in range(3)]
n = int(input())
b = [input() for _ in range(n)]
ans = "No"
flag = [ [False for _ in range(3)] for _ in range(3)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i] == a[j][k]: flag[j][k] = True

for i in range(3):
    if all((flag[0][i],flag[1][i],flag[2][i])) or all((flag[i][0],flag[i][1],flag[i][2])):
        ans = "Yes"
if all((flag[0][0],flag[1][1],flag[2][2])) or all((flag[0][2],flag[1][1],flag[2][0])): ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<cfloat>
using namespace std;

double dp[30][30][100];

void init(){
    for(int i = 0; i < 30; i++) for(int j = 0; j < 30; j++)
    for(int k = 0; k < 100; k++)    dp[i][j][k] = DBL_MAX;
}

struct data{
    int to, d, u;
};

#define F first
#define S second

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        init();
        int s, g;   cin >> s >> g;
        s--, g--;
        vector<data> v[n];
        while(m-- > 0){
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--, y--;
            v[x].push_back(data({y, d, c}));
            v[y].push_back(data({x, d, c}));
        }
        // score, velocity, from, to
        priority_queue<pair<double, pair<int, pair<int,int>>>> pq;
        pq.push({-0.0, {0, {s, s}}});
        dp[s][s][0] = 0;
        while(!pq.empty()){
            auto p = pq.top();  pq.pop();
            double cost = -p.F;
            int ve = p.S.F, from = p.S.S.F, pos = p.S.S.S;
            if(dp[from][pos][ve] != cost)    continue;
            for(int dv = -1; dv <= 1; dv++){
                int nv = ve+dv;
                if(nv <= 0) continue;
                for(data d : v[pos]){
                    if(nv > d.u)    continue;
                    int to = d.to;
                    if(to == from)  continue;
                    double ncost = cost + (double)(d.d)/nv;
                    if(dp[pos][to][nv] > ncost){
                        dp[pos][to][nv] = ncost;
                        pq.push({-ncost, {nv, {pos, to}}});
                    }
                }
            }
        }
        double ans = DBL_MAX;
        for(int i = 0; i < n; i++)  if(i != g)  ans = min(ans, dp[i][g][1]);
        if(ans == DBL_MAX)  cout << "unreachable" << endl;
        else                cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4336
#include <stdio.h>

int main(void) {
	int t, n;
	int seat[4] = {6000, 4000, 3000, 2000};
	int i;
	for (i = 0; i < 4; i++) {
		scanf("%d%d", &t, &n);
		printf("%d\n", seat[t-1]*n);
	}
	return 0;
}

Measured memory_bytes: 600
k = gets.chomp.to_i
que = [*1..9]
n = 0

def add(n, i)
  return n*10+i
end

1.upto(k) do
  n = que.shift()
  i = n%10
  que.push(add(n, i-1)) unless i == 0
  que.push(add(n, i))
  que.push(add(n, i+1)) unless i == 9
end

puts n

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536870912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// bit: &/and, |/or, ^/xor, ~/not

#define	MOD 1000000007

void unique_count(vector<int> &a, vector<vector<int>> &b) {
	// erase(b.begin(), b.end());
	for (int i=0; i<a.size(); i++)
		if ((i>0)&&(a.at(i)==a.at(i-1)))
			b.back().at(1)++;
		else
			b.push_back({a.at(i), 1});
	return;
}

int	main() {
	int N;
	cin >>N;
	vector<int> a(N);
	for (int i=0; i<N; i++)
		cin >>a.at(i);
	sort(a.begin(), a.end());
	vector<vector<int>> b;
	unique_count(a, b);
	int S=0;
	if (1==b.size()) {
		S=b.at(0).at(1);
	} else if (2==b.size()) {
		S=max(b.at(0).at(1), b.at(1).at(1));
		if (b.at(1).at(0)==b.at(0).at(0)+1) {
			S=b.at(0).at(1)+b.at(1).at(1);
		}
	} else {
		S=max(b.at(0).at(1), b.at(1).at(1));
		for (int i=1; i<b.size()-1; i++) {
			int SS=b.at(i).at(1);
			if (b.at(i).at(0)==b.at(i-1).at(0)+1)
				SS += b.at(i-1).at(1);
			if (b.at(i).at(0)==b.at(i+1).at(0)-1)
				SS += b.at(i+1).at(1);
			S=max(S, SS);
		}
	}
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;


ll gcd(ll a, ll b){
    if (a < b) swap(a,b);
    if (a % b == 0) return b;
    return gcd(a % b, b);
}
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
ll countNonDivisor(ll x, ll c, ll d){
    return x - x/c -x/d + x/lcm(c, d);
}
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll upper = countNonDivisor(b, c, d);
    ll lower =countNonDivisor(a-1, c, d);

    cout << upper - lower  << endl;
}


Measured memory_bytes: 3524
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h>

using namespace std;


#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         SET(m)                      memset(m, 1,sizeof m)
#define         RESET(m)                    memset(m,0,sizeof m)
#define         mp(a,b)                     make_pair(a,WWb)
#define         mod                         1000000007
#define         INF                         1e17
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)

//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

int main(){
    ll a,b;
    cin>>a>>b;
    if(a<b){
        for(ll i=1;i<=b;i++){
            cout << a;
        }
    }
    else{
        for(ll i=1;i<=a;i++){
            cout << b;
        }
    }
    cout << endl;
    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define ll long long
#define ld long double

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)

#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second

#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()

#define endl '\n'
using namespace std;

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; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double PI=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  
  while(m--){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    tree.merge(a,b);
  }
  ll ans = 0;
  rep(i,n){
    if(tree.root(i)==i){
      chmax(ans,tree.size(i));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6348
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=1;i<=n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=1;i<=n;i++){cout<<a[i]<<" ";}

using namespace std;
int main()
{
    int64_t h1,m1,h2,m2,k=0;
    cin>>h1>>m1>>h2>>m2>>k;
    int64_t hm1=h1*60+m1;
    int64_t hm2=h2*60+m2;
    cout<<(hm2-hm1)-k<<endl;
    return 0;
}


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

class UF {
public:
    int par[200000];
    int r[200000];
    UF (int N) {
        for (int i = 0; i < N; i++) {
            par[i] = i;
        }
    }

    int find(int x) {
        if (x == par[x]) return x;

        return par[x] = find(par[x]);
    }

    void add(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (r[x] < r[y]) par[x] = y;
        else {
            par[y] = x;
            if (r[x] == r[y]) r[x]++;
        }
    }
};

int main() {
    int N, K, L;
    cin >> N >> K >> L;

    vector<vector<int> > md(N);
    vector<vector<int> > mt(N);

    vector<pair<int,int> > dP(K), tP(L);

    for (int i = 0; i < K; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        dP[i] = pair<int,int>(min(x, y), max(x, y));
    }

    for (int i = 0; i < L; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        tP[i] = pair<int,int>(min(x, y), max(x, y));
    }

    UF duf(N), tuf(N);

    for (int i = 0; i < K; i++) {
        duf.add(dP[i].first, dP[i].second);
    }

    for (int i = 0; i < L; i++) {
        tuf.add(tP[i].first, tP[i].second);
    }

    UF uf(N);
    for (int i = 0; i < K; i++) {
        if (tuf.find(dP[i].first) == tuf.find(dP[i].second)) {
            uf.add(dP[i].first, dP[i].second);
        }
    }
    for (int i = 0; i < L; i++) {
        if (duf.find(tP[i].first) == duf.find(tP[i].second)) {
            uf.add(tP[i].first, tP[i].second);
        }
    }

    vector<vector<int> > tmp(N);
    for (int i = 0; i < N; i++) {
        tmp[duf.find(i)].push_back(i);
    }

    vector<int> pcount(N);
    for (int i = 0; i < N; i++) {
        map<int,int> count;
        for (int j = 0; j < tmp[i].size(); j++) {
            count[tuf.find(tmp[i][j])]++;
        }

        for (int j = 0; j < tmp[i].size(); j++) {
            pcount[tmp[i][j]] += count[tuf.find(tmp[i][j])];
        }
    }

    for (int i = 0; i < N-1; i++) {
        cout << pcount[i] << " ";
    }

    cout << pcount[N-1] << endl;

    return 0;
}


Measured memory_bytes: 25976
#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)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;

vector<int> G[100050];
vector<bool> seen;
map<P, int> mp;

void dfs(int v, int ban) {
    seen[v] = true;
    int cur = 0;
    for(int nv : G[v]) {
        if(seen[nv]) continue;
        if(cur == ban) cur++;
        int t = v, u = nv;
        if(t > u) swap(t, u);
        mp[{t, u}] = cur+1;
        dfs(nv, cur);
        cur++;
    }
}

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

int N; cin >> N;
vector<P> edge;
rep(i,N-1) {
    int a,b; cin >> a >> b;
    a--; b--;
    edge.push_back(make_pair(a,b));
    G[a].push_back(b);
    G[b].push_back(a);
}
int K = 0;
int sv;
rep(i,N) {
    if( chmax(K, SZ(G[i])) ) sv = i;
}
seen.assign(N, false);
dfs(sv, -1);

cout << K << endl;
rep(i,N-1) cout << mp[edge[i]] << endl;

return 0;
}

Measured memory_bytes: 14076
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def swap(a,b):
    c=a
    a=b
    b=c
    return a,b
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,k = map(int,input().split()) 
    a = list(map(int,input().split()))
    x=a[0]
    for i in range(n-1):
        x=gcd(x,a[i+1])
        if x==1:
            break
    if k in a:
        print("POSSIBLE")
        return
    if x==1 and k<=max(a):
        print("POSSIBLE")
        return
    for i in range(n):
        a[i]-=k
        if a[i]<=0:
            a[i]=-1
        if a[i]%x==0:
            print("POSSIBLE")
            return
    print("IMPOSSIBLE")
main()

Measured memory_bytes: 62576
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()


using namespace std;
 
int main() {
  int n;
  
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  
  int f=0;
  rep(i,n){
    if(a.at(i)%2==0&&(a.at(i)%5!=0&&a.at(i)%3!=0)){
      f=1;
        break;
    }
  }
  
  if(f==1){
    cout<<"DENIED";
  }
  else{
    cout<<"APPROVED";
  }
}

    
      


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

int main(){
  int n, m, q, l, r, pi, qi;
  cin >> n >> m >> q;
  vector<vector<int>> v(n,vector<int>(n,0));
  for(int i=0; i<m; ++i){
    cin >> l >> r;
    --l; --r;
    ++v[l][r];
  }
  vector<vector<int>> v2(n,vector<int>(n+1,0));
  for(int i=0; i<n; ++i) for(int j=0; j<n; ++j){
    v2[i][j+1] = v[i][j] + v2[i][j];
  }
  for(int i=0; i<q; ++i){
    cin >> pi >> qi;
    --pi; --qi;
    int ans = 0;
    for(int i=pi; i<=qi; ++i){
      ans += v2[i][qi+1] - v2[i][pi];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 5528
#include<stdio.h>

int main(){
	int a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(!(a|b))return 0;
		int now=0;
		if(a<b){
			int c=a;
			a=b;
			b=c;
		}
		while(b!=0){
			a=a%b;
			int c=a;
			a=b;
			b=c;
			now++;
		}
		printf("%d %d\n",a,now);
	}
}



Measured memory_bytes: 2032
# ?????????http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1257
# ?????????????????§??????
# ???????????¨?????????????????????????????????????????§???10 000 ?????§????´???°????±????????????????
# ????????°???????????§??£?¶?????????°????????§??¨???????????????subsequence.rb??¨??????????????§??¢??????
array = []
while array[array.length-1]!=0
	array << gets.chomp.to_i
end
array.pop

def prime_sifting(num)
  range = (2..num).to_a
  prime = 2
  i=2
  non_prime_arr = []

  while prime <= Math.sqrt(num)
    for i in 2..num 
      if prime * i <= num
        non_prime_arr << prime * i
      else
        break
      end
    end 
    prime +=1
  end

  return range - non_prime_arr
end

sosu = prime_sifting(10000)

array.each do |a|
	n,j,k = 0,0,0
  sum = 0
  add_next = true
	while k < sosu.length && sosu[j]<=a
    sum = add_next ? sum + sosu[k] : sum - sosu[j-1]
		if sum == a
			n = n+1
      j = j+1
      add_next = false
		elsif sosu[j..k].inject(:+) > a
			j = j+1
      add_next = false
		else
			k = k+1
      add_next = true
		end
	end
	p n
end

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

int main(){
  int N;
  cin>>N;

  int k=sqrt(2*N)+1;
  
  if(N!=k*(k-1)/2){
	cout << "No" << endl;
	return 0;
  }
  cout << "Yes" << endl;
  cout << k << endl;

  for(int i=0;i<k-1;i++){
	cout << k-1;
	for(int j=0;j<i+1;j++){
	  cout << " " << j+1+(i+1)*(i-1+1)/2;
	}
	for(int j=i+1;j<k-1;j++){
	  cout << " " << i+1+(i+1)*i/2+((j+1)*j/2-(i+1)*i/2);
	  }	  	
	cout << endl;
  }
  
  cout << k-1;
  for(int i=0;i<k-1;i++){
	cout << " " << (i+1+1)*(i+1)/2;	
  }
  cout << endl;
    

  return 0;
}


Measured memory_bytes: 1408