akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<map>
typedef std::map<int,int>A;
struct S{int s;A a;};
typedef std::map<char,S>M;
M m;
int F(char s[])
{
	char *p=strchr(s,'[');
	if(!p)return atoi(s);
	int v=F(p+1);
	S& a=m[s[0]];
	if(v<0 || v>=a.s) return -1;
	if(a.a.find(v)==a.a.end())return -1;
	return a.a[v];
}
int main()
{
	char s[99],t[99],*p;
	int v,w;
	while(scanf("%s",s),s[0]-'.')
	{
		m.clear();
		int f=0;
		int i=1;
		do
		{
			if(!f)
			{
				if(p=strchr(s,'='))
				{
					strcpy(t,p+1);
					*p='\0';
					w=F(t);
					v=F(s+2);
					if(w<0||v<0 || m[s[0]].s<=v)
						printf("%d\n",i),f=1;
					else	m[s[0]].a[v]=w;
				}
				else
				{v=atoi(strchr(s,'[')+1);m[s[0]].s=v;
				}
			}
			++i;
		}while(scanf("%s",s), s[0]-'.');
		if(!f)puts("0");
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);
  
  public void solve() {
    n = in.ni();
    W = in.ni();
    weight = new int[n];
    value = new long[n];
    for (int i = 0; i < n; i++) {
      weight[i] = in.ni();
      value[i] = in.nl();
    }
    dp = new Long[n][W + 1];
    out.println(recurse(0, 0));
  }
  
  private int n, W;
  private int[] weight;
  private long[] value;
  private Long[][] dp;
  
  private long recurse(int idx, int current) {
    if (idx == n) return 0;
    
    if (dp[idx][current] != null) return dp[idx][current];
    
    long ans = recurse(idx + 1, current);
    if (current + weight[idx] <= W) {
      ans = Math.max(ans, value[idx] + recurse(idx + 1, weight[idx] + current));
    }
    return dp[idx][current] = ans;
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 293672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<ll> A(N);
    REP(i,N)A[i] = in();
    sort(ALL(A));
    ll before = 0;
    int total = 0;
    int small = 0;
    REP(i,N){
        if(before == A[i]){
            small++;
        }else{
            total += small % 2;
            small = 1;
            before = A[i];
        }
    }
    cout << total + small % 2 << "\n";
}

Measured memory_bytes: 1024
// Maximum Heap
#include <stdio.h>

#define MAX 500000

int H; // ヒープサイズ

int parent(int i){
  return i / 2; // 親の接点番号
}

int left(int i){
  return 2 * i; // 左の子の接点番号
}

int right(int i){
  return 2 * i + 1; // 右の子の接点番号
}

// iの左の子と右の子のうち、キーが大きい方を選び、それが現在のキーよりも大きければ、交換していく
void maxHeapify(int *A, int i){
  int l, r, largest, swp;
  l = left(i);
  r = right(i);

  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= H && A[l] > A[i]){
    largest = l;
  }
  else largest = i;
  
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){ // i の子の方が値が大きい場合
    swp = A[i];  A[i] = A[largest];  A[largest] = swp; // A[i] と A[largest] を交換
    maxHeapify(A, largest); // 再帰的に呼び出し
  }
}

// max-ヒープを構築する
void buildMaxHeap(int *A){
  int i;
  for(i=H/2; i > 0; i--){
    maxHeapify(A, i);
  }
}

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

  scanf("%d", &H);

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

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



Measured memory_bytes: 3668
s = input()
t = input()
q = int(input())
ans = ['YES']*q

scnt = [[0]*(len(s)+1) for _ in range(2)]
tcnt = [[0]*(len(t)+1) for _ in range(2)]

for i,S in enumerate(s):
    scnt[0][i+1] = scnt[0][i]
    scnt[1][i+1] = scnt[1][i]
    scnt[ord(S)-ord('A')][i+1] += 1

for i,T in enumerate(t):
    tcnt[0][i+1] = tcnt[0][i]
    tcnt[1][i+1] = tcnt[1][i]
    tcnt[ord(T)-ord('A')][i+1] += 1

for i in range(q):
    a,b,c,d = map(int,input().split())
    a -= 1
    c -= 1
    A = scnt[0][b] - scnt[0][a] - tcnt[0][d] + tcnt[0][c]
    B = scnt[1][b] - scnt[1][a] - tcnt[1][d] + tcnt[1][c]
    if (A-B)%3 != 0:
        ans[i] = 'NO'
print('\n'.join(ans))


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

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

#define filename ""

int n;
int m;
int x[10];

int go (int i, int j) {
	if (i == n) re 1 - j;
	int ans = 0;
	for (int y = x[i] - 1; y <= x[i] + 1; y++)
		ans += go (i + 1, abs (j * y) % 2);
	re ans;
}

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n; i++) scanf ("%d", &x[i]);
	printf ("%d\n", go (0, 1));
	return 0;
}


Measured memory_bytes: 256
# coding:utf-8
def main():
    a = input()
    b = ['Sunny', 'Cloudy', 'Rainy']

    if a == b[0]:
        print(b[1])
    elif a == b[1]:
        print(b[2])
    else:
        print(b[0])


if __name__ == '__main__' :
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
int main()
{
    int  n;
    cin >> n;
    long long int sum = 0;
    
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                int tmp1 = std::gcd(i, j);
                int tmp2 = std::gcd(tmp1, k);
                sum += tmp2;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
for i in range(n):
  for j in range(3):
    if i == 0:
      dp[i][j] = abc[i][j]
    else:
      for k in range(3):
        if k == j:
          continue
        dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j])
ans = max(dp[n-1])
print(ans)

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

aoki = c - b
takahasi = a - d

for i in range(10000):
  if i % 2 == 0:
    c -= b
    if c <= 0:
      print('Yes')
      exit()
  elif i % 2 == 1:
    a -= d
    if a <= 0:
      print('No')
      exit()

  
  


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const int EPS = 1e-9;

int main(){
    cin.sync_with_stdio(false);
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << setprecision(12) << (w*h)/2.0 << ' ';
    if((w/2 == x && w%2 == 0) && (h/2 == y && h%2 == 0)){
        cout << 1 << endl;
    }
    else cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i=0,j=0,m=0,n=0,a[1000]={0},b[1000]={0},c[1000]={0},save=0,max=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
		c[i]=a[i];
	}
	for(i=0;i<m;i++){
		cin>>b[i];
	}
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if(b[i]>=c[j]){
				a[j]++;
				break;
			}
		}
	}
	for(i=0;i<n;i++){
		if(a[i]-c[i]>max){
			max=a[i]-c[i];
			save=i+1;
		}
	}	
	cout<<save<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

struct Circle{
	int cx,cy,r,color;
};

// ð·»è
bool cross(Circle c1,Circle c2){
	return (c1.cx-c2.cx)*(c1.cx-c2.cx)+(c1.cy-c2.cy)*(c1.cy-c2.cy) < (c1.r+c2.r)*(c1.r+c2.r);
}

char dp[1<<24];
Circle circles[30];
int n;

int dfs(int s){
	if(dp[s]!=-1)
		return dp[s];
	if(s==0)
		return 0;

	// ¡êÔãÉ é~ðßé
	bool up[30];
	fill(up,up+30,false);
	for(int i = 0; i < n; i++){
		bool f = false;
		if((((s>>i)&1)==0))
			continue;
		for(int j = 0; j < n; j++){
			if(i==j||(((s>>j)&1)==0))
				continue;
			// SÌ~Æä×ÄêÔãÉ é©Ç¤©ðÝé
			if(cross(circles[i],circles[j])){
				if(i>j){
					f=true;
					break;
				}
			}
		}
		if(!f){
			up[i]=true;
		}
	}

	// æè­û@ð·×Ä·
	int maxNum=0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			if(up[i]&&up[j]&&circles[i].color==circles[j].color){
				int ns=s;
				ns &= ~(1<<i);
				ns &= ~(1<<j);
				maxNum=max(maxNum,dfs(ns)+2);
			}
		}
	}
	dp[s]=maxNum;
	return maxNum;
}

int main(){

	while(cin>>n&&n!=0){
		for(int i = 0; i < n; i++){
			Circle cc;
			cin>>cc.cx>>cc.cy>>cc.r>>cc.color;
			circles[i]=cc;
		}
		fill(dp,dp+(1<<24),-1);
		cout<<dfs((1<<(n))-1)<<endl;
	}

	return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, m;
    cin>>n>>m;
    vector<vector<ll> > v(8, vector<ll>(n));
    rep(i, n){
        vector<ll> use(3);
        rep(i, 3) cin>>use[i];
        for(int bit = 0;bit<(1<<3);bit++){
            vector<int> s(3);
            rep(j, 3){
                if((bit>>j)&1) s[j] = 1;
            }
            ll tmp = 0;
            rep(j, 3){
                if(s[j] == 1){
                    tmp +=use[j];
                }
                else tmp -=use[j];
            }
            v[bit][i] = tmp;
        }
    }
    ll ans = 0;
    rep(i, 8){
        sort(v[i].begin(), v[i].end(), greater<ll>());
        ll tmp = 0;
        rep(j, m) tmp += v[i][j];
        ans=max(ans, tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List

suit :: String -> Char
suit s = s !! 0

rank :: String -> Int
rank s = read $ drop 1 s

swap :: [String] -> Int -> Int -> [String]
swap xs i j = (take i xs) ++ [xs !! j] ++ (take (j - i - 1) $ drop (i + 1) xs) ++ [xs !! i] ++ (drop (j + 1) xs)

bubble :: Int -> [String] -> [String]
bubble n xs = foldl (\ys i -> if rank (ys !! i) < rank (ys !! (i - 1)) then swap ys (i - 1) i else ys) xs [j | i <- [0 .. n - 1], j <- [n - 1, n - 2 .. i + 1]]

selection :: Int -> [String] -> [String]
selection n xs = foldl (\ys i -> let m = f ys i in if i == m then ys else swap ys i m) xs [0 .. n - 1]
    where f ys i = foldl (\j k -> if rank (ys !! k) < rank (ys !! j) then k else j) i [i + 1 .. n - 1]

remove :: [String] -> Int -> [String]
remove xs i = take i xs ++ drop (i + 1) xs

stable :: [String] -> [String] -> String
stable [] []     = "Stable"
stable os (x:xs) = if pred os x then stable (delete x os) xs else "Not stable"
    where
        pred [] _     = False
        pred (y:ys) x = if rank x == rank y then suit x == suit y else pred ys x

main :: IO ()
main = do
    n  <- readLn
    os <- words <$> getLine
    let bs = bubble n os
    let ss = selection n os
    putStr $ unlines $ [unwords bs, stable os bs, unwords ss, stable os ss]

Measured memory_bytes: 5128
(defun solve (s)
  (cond ((< (length s) 2) (format t "~D ~D~%" -1 -1) (return-from solve))
        ((= (length s) 2) (if (eq (aref s 0) (aref s 1))
                            (progn (format t "~D ~D~%" 1 2) (return-from solve))
                            (progn (format t "~D ~D~%" -1 -1) (return-from solve)))
                          )
        (t
          (loop :for c :across s :and i :from 0 :below (- (length s) 2) :do
                (cond ((eq (aref s i) (aref s (+ i 1)))
                       (format t "~D ~D~%" (+ i 1) (+ i 2))
                       (return-from solve))
                      ((eq (aref s i) (aref s (+ i 2)))
                       (format t "~D ~D~%" (+ i 1) (+ i 3))
                       (return-from solve))
                      ))))
  (format t "~D ~D~%" -1 -1))

(defun main()
  (let ((s (read-line)))
    (solve s)
    ))

(main)

Measured memory_bytes: 15588
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int a, b,d=0,f;
	cin >> a >> b;
	f = b;
	while (f > 0) {
		f /= 10;
		d++;
	}
	for (int i = 1; i <= 1000; i++) {
		if (i*i==pow(10,d)*a+b) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

int main()
{
    string S;
    cin >> S;
    int count = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S.at(i) == '+')
        {
            count += 1;
        }
        else if (S.at(i) == '-')
        {
            count -= 1;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 3624
loop do
h, w = gets.split.map(&:to_i)
break if h == 0 && w == 0
(1..h).each do |i|
    (1..w).each do |j|
        if (i + j) % 2 == 0
            print '#'
        else
            print '.'
        end
    end
    puts
end
puts
end


Measured memory_bytes: 6852
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> ss(h); cin >> ss;
    vector<vector<int>> dp(h, vector<int>(w, M));
    // vector<vector<vector<int>>> dp(h + 1, vector<vector<int>>(w + 1, vector<int>(2, M)));
    if(ss[0][0] == '.'){
        dp[0][0] = 0;
        // dp[0][0][0] = 0;
    }else{
        dp[0][0] = 1;
        // dp[0][0][1] = 1;
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            auto proc = [&](int y, int x){ 
                if(y >= h || x >= w){ return; }
                if(ss[y][x] == '.'){
                    dp[y][x] = min(dp[y][x], dp[i][j]);
                }else{
                    dp[y][x] = min(dp[y][x], dp[i][j] + (ss[i][j] == '.'));
                }
            };
            proc(i + 1, j);
            proc(i, j + 1);
        }
    }
    cout << dp[h - 1][w - 1] << '\n';
    // dp[0][0][0] = ss[0][0] == '.' ? 0
    // dp[0][0][1] = 
    // queue<pair<int, int>> qu;
    // qu.emplace(0, 0);
    // while(qu.size()){
    //     auto p = qu.front(); qu.pop();
    //     if(p.first == h || p.second == w){ continue; }
    //     qu.emplace(p.first + 1, p.second);
    //     qu.emplace(p.first, p.second + 1);
    // }
}


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

int main(){
	int n,r;
	int p,c;
	int yama[50];
	int workspace[50];

	while(1){
		cin >> n >> r;

		if(n==0&&r==0) break;

		for(int i=1;i<=n;i++){
			yama[i-1] = i;
		}

		for(int i=0;i<r;i++){
			cin >> p >> c;

			for(int i=0;i<=n;i++){
				workspace[(n-1)-i] = yama[(n-1)-i];
			}

			for(int i=0;i<=(c-1);i++){
				yama[(n-1)-i] = yama[(n-1)-i-(p-1)];
			}

			for(int i=0;i<=((p-1)-1);i++){
				yama[(n-1)-i-c] = workspace[(n-1)-i];
			}

		}

		cout << yama[n-1] << endl;
	}
}

Measured memory_bytes: 0
s = gets.chomp
k = gets.to_i
ichi = -1
num = -1
len = s.length
i = 0
while i < len
  if s[i] == "1"
    ichi = i
  else
    num = s[i].to_i
    break
  end
  i += 1
end
if k-1 <= ichi
  puts "1"
else
  puts num
end


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

    typedef long long ll;
    typedef long double ld;
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
    #define endl '\n'
    #define max3(a,b,c) max(a,max(b,c))

    const int q = 1e9+9;




    int main()
    {
        int n,k;
        cin>>n>>k;
        double ans = 0;
        for(int i=1;i<=n;i++){
            double t = 1.0/n;
            int now = i;
            while(now<k){
                now*=2;
                t/=2;
            }
            ans+=t;
        }
        printf("%.12f\n",ans);



        return 0;
    }
        // gotcha;


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

const string YES = "YES";
const string NO = "NO";
const string AKIBA = "AKIHABARA";
void solve(std::string S){
  for(long long i = 0; i < AKIBA.size(); i++) {
    if(S.size() <= i && S.size() < AKIBA.size()) S.push_back('A');
    else if(AKIBA[i] == 'A' && S[i] != 'A') S.insert(i, "A");
  }

  cout << ((S == AKIBA) ? YES : NO) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/math/common_factor.hpp>
#define f(i,a,b) for(long long i=a;i<b;i++)
typedef long long ll;
using namespace std;

int main(){
	ll n,m;cin>>n>>m;
	ll ans=boost::math::lcm(n,m);
	cout<<ans<<"\n";
}

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

int main(){
    double N,M; cin>>N>>M;
    vector<int> A(N,0);
    double zen=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        zen=zen+A[i];
    }
    int count=0;
    for(int i=0;i<N;i++){
        if(A[i]<(zen/(4*M))){
            count++;
        }
    }
    int tmp=N-count;
    if(tmp<M){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
#include <time.h>
using namespace std;
int main() {
	long long int a, l[1000], r[1000], c = 0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> l[i] >> r[i];
		c += r[i] - l[i] + 1;
	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  
  int c = 0;//カウンタ変数
  int d1 = 0;//左から読んだSのAの位置を記憶する変数
  int d2 = 0;//右から読んだSのZの位置を記憶する変数
  
  //左から文字を読み込み、Aを取得したらその添え字を記憶し、操作終了
  for(int i = 0; i < S.size(); i++){
    if(S[i] == 'A'){
      d1 = i;
      break;
    }
  }
  //右から文字を読み込み、Zを取得したらその添え字を記憶し、操作終了
    for(int i = S.size() - 1; i > 0; i--){
    if(S[i] == 'Z'){
      d2 = i;
      break;
    }
  }
  cout << d2 - d1 + 1 << endl;
 
}


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

bool judge_f(int N,int K, vector<int> D){
  bool judge=false;
  while(!judge && N>0){
    rep(i,K){
      if(N%10 == D.at(i)){
        judge = true;//trueなら入っている
        return judge;
      }
    }
    N = N/10;
  }
  return judge;
}

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> D(K);
  rep(i,K) cin >> D.at(i);
  bool judge = true;
  while(judge){
    judge = judge_f(N,K,D);
    N++;
  }
  cout << N-1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main(){
  ll n;
  cin >> n;
  ll w;
  cin >> w;
  ll weights[n],value[n]; 
  ll temp = 0;
  for(ll i = 0;i < n;i++){
  	cin >> weights[i] >> value[i];
  	temp += value[i];
  }
  ll dp[temp + 1];
  for(ll i = 0;i <= temp;i++){
      dp[i] = 1e10;
  }
  dp[0] = 0;
  for(ll i = 0;i < n;i++){
      for(ll j = temp;j >= 0;j--){
          if(j - value[i] < 0) break;
          dp[j] = min(dp[j - value[i]] + weights[i],dp[j]);
      }
  }
  ll ans = 0;
  for(ll i = 0;i <= temp;i++){
      if(dp[i] <= w){
          ans = i;
      }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
	using namespace std;
	
	typedef long long ll;
	#define pi 3.14159265 
	#define EPS 1e-8
	
	#define mod 5000000
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define endl "\n"

	const ll INF=(ll)3e17;
	
	
	
	int main()
	{
		 ios_base::sync_with_stdio(false);
		 cin.tie(NULL);
		 
		map<ll,ll> cnt;
		ll n;
		cin>>n;
		for(ll i=2;i<=n;i++)
		{
			ll val;
			cin>>val;
			cnt[val]++;
		}
		for(ll i=1;i<=n;i++)
		{
			cout<<cnt[i]<<endl;
		}
	}


Measured memory_bytes: 16116
package main

import "fmt"

func getBeginning(s string) (b string){
  for _, x:=range s{
    b = string(x)
    break
  }
  return
}     

func main() {
  var s1, s2, s3 string
  fmt.Scan(&s1, &s2, &s3)
  fmt.Println(getBeginning(s1) + getBeginning(s2) + getBeginning(s3))
}


Measured memory_bytes: 512
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong P,Q,R;
    cin >> P >> Q >> R;
    llong ans=INF;
    ans = min(ans, R+Q);
    ans = min(ans, R+P);
    ans = min(ans, P+Q);
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 3132
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean high=false;
		boolean low=false;
		int zero=0;
		long sum=0;
		ArrayList<Integer> llist=new ArrayList<>();
		ArrayList<Integer> hlist=new ArrayList<>();
		for(int i=0; i<n; i++){
			int a=sc.nextInt();
			sum+=Math.abs(a);
			if(a>0){
				hlist.add(a);
				high=true;
			}else if(a<0){
				llist.add(a);
				low=true;
			}else{
				zero++;
			}
		}
		if(sum==0){
			System.out.println(sum);
			for(int i=1; i<zero; i++){
				System.out.println("0"+" "+"0");
			}
			return;
		}
		int cl=0;
		int ch=0;
		String s="";
		if(!(high && low)){
			if(zero>0){
				if(low){
					hlist.add(-llist.get(cl++));
					s="0 "+String.valueOf(llist.get(0));
					zero--;
				}else{
					llist.add(-hlist.get(ch++));
					s="0 "+String.valueOf(hlist.get(0));
					zero--;
				}
			}else{
			if(low){
				Collections.sort(llist);
				Collections.reverse(llist);
				hlist.add(llist.get(0)-llist.get(1));
				cl+=2;
				sum+=2*llist.get(0);
				s=String.valueOf(llist.get(0))+" "+String.valueOf(llist.get(1));
			}else{
				Collections.sort(hlist);
				llist.add(hlist.get(0)-hlist.get(1));
				ch+=2;
				sum-=2*hlist.get(0);
				s=String.valueOf(hlist.get(0))+" "+String.valueOf(hlist.get(1));
			}
			}
		}
		int ii=0;
		int jj=0;
		System.out.println(sum);
		if(!s.equals("")){
			System.out.println(s);
		}
		int lsize=llist.size();
			while(lsize>cl+1){
				ii=hlist.get(ch++);
				jj=llist.get(cl++);
				hlist.add(ii-jj);
				System.out.println(ii+" "+jj);
			}
		int hsize=hlist.size();
			while(hsize>ch+1){
				 ii=llist.get(cl++);
				 jj=hlist.get(ch++);
				llist.add(ii-jj);
				System.out.println(ii+" "+jj);
			}
			System.out.println(hlist.get(ch)+" "+llist.get(cl));
		for(int i=0; i<zero; i++){
			System.out.println(sum+" "+0);
		}
	}
}


Measured memory_bytes: 75392
from collections import deque
N, M = map(int, input().split())
*A, = map(int, input().split())
S = [[] for i in range(N)]
for i in range(M):
    l, r = map(int, input().split())
    S[l-1].append(r)

N0 = 2**(N).bit_length()
INF = 2**31-1
data = [INF]*(2*N0)
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])
def query(l, r):
    L = l + N0; R = r + N0
    s = -INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

update(0, 0)
que = deque()
for i in range(N):
    while que and que[0][1] <= i:
        que.popleft()

    r = (que[0][0] if que else i)+1
    v = query(0, r) + A[i]
    update(i+1, v)

    for r in S[i]:
        que.append((i, r))
print(query(0, N+1))


Measured memory_bytes: 64888
using System;
using System.Linq;

class B
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int n = h[0], m = h[1];
		var a = Read();

		var d = a.Sum() / (4D * m);
		Console.WriteLine(a.Count(x => x >= d) >= m ? "Yes" : "No");
	}
}


Measured memory_bytes: 28288
#include <iostream>
#include<string>
using namespace std;
string a,b,c;
int d;
int main() {
   cin>>a>>b;
   d=b.size();
   for(int i=0;i<d;i++){
   c.push_back(*a.begin());a.erase(a.begin());
   c.push_back(*b.begin());b.erase(b.begin());
}
if(a.empty()==false)c.push_back(*a.begin());
cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
//81
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<(x)<<endl
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf=1e18;
const int N=2e5+10;
ll factorial(ll x){//階乗の計算
    if(x==0||x==1) return 1;
    return x*factorial(x-1);
}
ll gcd(ll a ,ll b){return b ? gcd(b,a%b) : a;}//最大公約数
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}//最小公倍数
int num_digit(ll a){//桁数を求める
    int num_dig = 0;
    while(a!=0){
        a /= 10;
        ++num_dig;
    }
    return num_dig;
}
vector<ll> digit(ll a){//桁の数字を求める
    vector<ll> dig(num_digit(a));
    for(int i=num_digit(a)-1; i>=0; --i){
        dig[i] = a%10;
        a /= 10; 
    }
    return dig;
}


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

    bool can = false; 
    for(int i=1; i<=9; ++i){
        for(int j=1; j<=9; ++j){
            if(i*j == n) {
                can = true;
            }
        }
    }

    if(can) cout("Yes");
    else cout("No");
    return 0;
}

Measured memory_bytes: 256
N, M, T = map(int, input().split())
A = list(map(int, input().split()))
prv = 0
cnt = 0
for a in A:
    if prv == 0:
        cnt += a - M
    else:
        if prv + M < a - M:
            cnt += (a - M) - (prv + M)
    prv = a
if prv + M < T:
    cnt += T - (prv + M)

print(cnt)



Measured memory_bytes: 5596
nk=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nk[0]
k=nk[1]
def min(A):
  min=1000000
  for x in range(len(A)):
    if A[x]<=min:
      min=A[x]
  return min
m=0
for i in range(n):
  if a[i]==1:
    m=i
l=[]
if n<=k:
  l.append(1)
else:
  for j in range(k):
    if j<k-1:
      l.append(100000)
    elif j>=k-1 and j%(k-1)==0 and (n-j-1)%(k-1)==0:
      l.append(j//(k-1)+(n-j-1)//(k-1))
    elif j>=k-1 and j%(k-1)!=0 and (n-j-1)%(k-1)!=0:
      l.append(j//(k-1)+1+(n-j-1)//(k-1)+1)
    elif j>=k-1 and j%(k-1)!=0 and (n-j-1)%(k-1)==0:
      l.append(j//(k-1)+1+(n-j-1)//(k-1))
    elif j>=k-1 and j%(k-1)==0 and (n-j-1)%(k-1)!=0:
      l.append(j//(k-1)+(n-j-1)//(k-1)+1)
print(min(l))

Measured memory_bytes: 14008
from numpy import*


n=int(input())
a=array(list(map(int,input().split())))
b=abs(a)


if 0 in a:
  print(sum(b));exit()
  
  
minus_cnt=sum(a<0)


if minus_cnt%2==0:
  print(sum(b));exit()
  
  
print(sum(b)-min(b)*2)

  



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

int main(void) {
    int64_t N;
    int64_t h,maxh = 0;
    string output = "Yes\n";
    cin >> N;

    for(int i=0;i<N;i++) {
        cin >> h;
        if(maxh > (h+1)) output = "No\n";
        if(maxh < h) {
            maxh = h;
        }
    }

    cout << output;
    return 0;
}


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

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

  double ans = 0.0;

  for(int i=1; i<= N; i++){
    int count = 0;
    int tmp = i;
    while(tmp <= K-1){
      tmp *= 2;
      count++;
    }

    ans += pow(0.50, count);
  }

  ans /= N;

  cout << fixed << setprecision(12);
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n,m,i,j;
  string s;
  vector<string> ss;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>s;
    ss.push_back(s);
  }
  cin>>m;
  for(i=0;i<m;i++){
    cin>>s;
    ss.push_back(s);
  }
  int ma=0;
  int c;
  for(i=0;i<n+m;i++){
    c=0;
    for(j=0;j<n+m;j++){
      if(ss[i]==ss[j]&&j<n){
        c++;
      }
      else if(ss[i]==ss[j]&&j>=n){
        c--;
      }
    }
    ma=max(c,ma);
  }
  cout<<ma<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(){
	char s[202],p[101],a[101];
	int i;
	scanf("%s%s",s,p);
	strcpy(a,s);
	strcat(s,a);
	if(strstr(s,p)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}
	


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int a;
    cin >> a;
    string s;
    cin >> s;

    if (a >= 3200) {
        cout << s << endl;
    } else if (a < 3200) {
        cout << "red" << endl;
    }

    return 0;
}


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

int main()
{
    string s;
    int n;
    cin >> n;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        s[i] = s[i] + n;
        if(s[i] >= 'A' && s[i] <= 'Z')
            s[i]=s[i];
        else{
        s[i] = ((s[i] % 90) + 64);
        }
    }
    cout << s << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,a,b;
  cin >> n >> a >> b;
  int ans=n;
  rep(i,n) {
    int x;
    R x;
    if(a<=x&&x<b) ans--;
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 892
n,m = map(int, input().split())

ac = [False]*n
c_ac = 0
c_wa = 0
wa = [0]*n
for _ in range(m):
    pi,si = input().split()
    pi = int(pi) - 1
    
    if ac[pi] == False:
        if si == 'WA':
            wa[pi] += 1
        elif si == 'AC':
            c_ac += 1
            c_wa += wa[pi]
            ac[pi] = True

print(c_ac, c_wa)

Measured memory_bytes: 4596
#include <stdio.h>

int convrt(char c)
{
    switch (c) {
        case 'A' : return 10;
        case 'B' : return 11;
        case 'C' : return 12;
        case 'D' : return 13;
        case 'E' : return 14;
        case 'F' : return 15;
    }
}

int main(void)
{
    char x, y;
    scanf("%c %c", &x, &y);
    int a, b;
    a = convrt(x);
    b = convrt(y);
    if (a < b)
        puts("<");
    else if (a == b)
        puts("=");
    else
        puts(">");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k,sum;
  cin >> n >> k;
  for (int i = 0; i < n; i++){
    int x;
    cin >> x;
    if ((k / 2.0) < x) sum += (k - x) * 2;
    else sum += x * 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main() {
    int K, S, ans = 0;
    cin >> K >> S;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S - x - y;
            if (0 <= z && z <= K) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

macro_rules! get_vec {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_vec!($t)).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get_one!(usize);
    let a = get_vec!(usize);

    let mut subs = vec![0; n];

    a.iter().for_each(|&i| subs[i - 1] += 1);

    subs.iter().for_each(|i| println!("{}", i));


}


Measured memory_bytes: 4908
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()
#define lowbit(x) x&-x
#define pb push_back
#define ls (id<<1)
#define rs (id<<1|1)
#define Rint register int
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MAXN=1e6+10,MAXM=4e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int MOD=1e9+7,mod=998244353;
const int inv2=5e8+4;
const int Lim=1<<20;

ll dp[2][2200];
char s[MAXN];

void solve()
{
    R(s);
    ll ans=0;
    int n=LEN(s);
    for(int i=0;i<n;i++)
    {
        int u=i&1;
        memset(dp[u],0,sizeof(dp[u]));
        dp[u^1][0]++;
        for(int j=0;j<2019;j++)
        {
            dp[u][(j*10+s[i]-'0')%2019]+=dp[u^1][j];
        }
        ans+=dp[u][0];
    }
    W(ans);
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	int t=1;
	//R(t);
	while(t--)solve();
	return 0;
}


Measured memory_bytes: 4044
#include<stdio.h>
#define N 111
int G[N][N],X[N],Y[N],n;
void bfs(int,int);

int main(){
  int i, j, num;

  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    X[i] = 151210;
    scanf("%d",&num);
    scanf("%d",&Y[num]);

    for(j=1;j<=Y[num];j++) scanf("%d",&G[num][j]);
  }
  bfs(1, 0);
  for(i=1;i<=n;i++){
    if(X[i] == 151210) X[i] = -1;
  }
  for(i=1;i<=n;i++) printf("%d %d\n",i,X[i]);
  return 0;
}

void bfs(int x,int y){
  int i;
  X[x] = y;
  for(i = 1; i <= Y[x]; i++){
     if(y + 1 < X[G[x][i]]) bfs(G[x][i], y + 1);
  }
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    cout << max(0, A - 2 * B);
    return 0;
}


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

int r, D, x2000;
int prevYear;

int main() {
  ios_base::sync_with_stdio(false);
  cin >> r >> D >> x2000;
  prevYear = x2000;
  for (int i = 1; i < 11; i++) {
    prevYear = prevYear * r - D;
    cout << prevYear << endl;
  }
  cin >> r;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGacha solver = new CGacha();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGacha {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            HashSet<String> hs = new HashSet<>();
            for (int i = 0; i < n; i++) {
                hs.add(in.next());
            }
            out.println(new ArrayList<String>(hs).size());
        }

    }
}



Measured memory_bytes: 77372
N=int(input())
def sq(n):
    c=0
    A=[0 for j in range(n+1)]
    for i in range(n//2):
        p=(i+1)**2
        if p>n:
            for j in range(i**2,n+1):
                A[j]=i
            break
        else:
            for j in range(i**2,p):
                A[j]=i
    return A
A=sq(N)
a=A[N]
L=[0 for j in range(N+1)]
for x in range(1,a+1):
    for y in range(1,a+1):
        for z in range(1,a+1):
            p=x**2+y**2+z**2+x*y+y*z+z*x
            if p<=N:
                L[p]=L[p]+1
            else:
                break
for i in range(1,N+1):
    print(L[i])

Measured memory_bytes: 9196
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


def main():
    """エントリーポイント"""
    N, K = input(int, int)
    n = N
    ans = 0
    while 1 < n:
        n //= K
        ans += 1
    print(ans + (n == 1))


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3444
D(S,d,s,n){if(d==0)return S==s;int r=0;for(;n<10;n++)r+=D(S,d-1,s+n,n+1);return r;}
main(n,s){for(;scanf("%d%d",&n,&s),n|s;)printf("%d\n",D(s,n,0,0));exit(0);}

Measured memory_bytes: 596
import java.util.*;
import java.io.*;

public class Main{
	public static int sum(int a, int b, int n){
		int sum = 0;
		while( n-- > 0 ){
			a %= b;
			sum += a*10/b;
			a = a*10%b;
		}
		return sum;
	}
	
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		List<Integer> result = new ArrayList<Integer>();
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				int a = stdIn.nextInt();
				int b = stdIn.nextInt();
				int n = stdIn.nextInt();
				result.add(sum(a, b, n));
			}
			
			for(Integer sum : result){
				System.out.println(sum);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>

int asc(const void *b, const void *a) {
  return *(int *)a - *(int *)b;
}

int main()
{
    int n,k,h[200000],i,j;
    long long ans = 0;
    scanf("%d %d",&n,&k);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&h[i]);
    }
    qsort(h,n,sizeof(int),asc);
    if(k >= n)printf("0");
    else
    {
        for (i = k; i < n; i++)
        {
            ans += h[i];
        }
        printf("%lld",ans);
    }
    
}


Measured memory_bytes: 1788
a=[]
c=[]
for i in range(10):
    b=int(input())
    a.append(b)
a.sort()
A=a[7]+a[8]+a[9]
for i in range(10):
    d=int(input())
    c.append(d)
c.sort()
C=c[7]+c[8]+c[9]
print(A,C)


Measured memory_bytes: 5600
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	/** 変換用マップ */
	private static final Map<String, String> MAP = new HashMap<>();
	static {
		MAP.put("A", "T");
		MAP.put("T", "A");
		MAP.put("C", "G");
		MAP.put("G", "C");
	}

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.next();
			System.out.println(MAP.get(s));
		}
	}
}


Measured memory_bytes: 35556
H, W = map(int, raw_input().split(' '))

M = []

for i in range(H):
    M.append(raw_input())

M2 = []

for i in range(H):
    if '#' in M[i]:
        M2.append(M[i])

idx = []
for i in range(W):
    flag = True
    for j in range(len(M2)):
        if M2[j][i] == '#':
            flag = False

    if flag == False:
        idx.append(i)

M3 = []
for i in range(len(M2)):
    s = ''
    for j in range(W):
        if j in idx:
            s += M2[i][j]
    M3.append(s)

print '\n'.join(M3)


Measured memory_bytes: 2692
N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

ans = -(10**7) * 10 * 100

for i in range(1,2**10):  
  counter = [0]*N #店iとjoisinoのかぶっている数
  tmp = 0 #  
  for j in range(10):    
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] ==1:
          counter[k] += 1
  for l in range(N):
    tmp += P[l][counter[l]]
      #tmp += P[k][counter[k]]
  ans = max(tmp,ans)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main() {
	int yj[18] = {};
	for(int i = 0; i < 18; i++){
		 cin >> yj[i];
	}
	for(int i = 0; i < 3; i++){
		if(yj[6 * i + 5] < yj[6 * i + 2]) {
		yj[6 * i + 5] = yj[6 * i + 5] + 60;
		yj[6 * i + 4] = yj[6 * i + 4] - 1;
		}
		if(yj[6 * i + 4] < yj[6 * i + 1]) {
		yj[6 * i + 4] = yj[6 * i + 4] + 60;
		yj[6 * i + 3] = yj[6 * i + 3] - 1;
		}
	}
	for(int i = 0; i < 3; i++){
	cout <<yj[6 * i + 3] - yj[6 * i]<<" "<<yj[6 * i + 4] - yj[6 * i + 1]<<" "<<yj[6 * i + 5] - yj[6 * i + 2]<<endl;
	}
 
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
import math
import numpy as np
p = np.array(list(map(int, input().split())))
q = np.array(list(map(int, input().split())))

flg = False
cnt = 0
for pi, qi in zip(p, q):
  if pi != qi:
    break
  cnt += 1
p[cnt:]
q[cnt:]
if cnt == n:
  print(0)
elif cnt == 0:
  bigger = p if p[cnt] > q[cnt] else q
  smaller = p if p[cnt] < q[cnt] else q

  perm = math.factorial(len(bigger[cnt+1:]))
  c = bigger[0] - smaller[0] - 1
  before = c * perm
  
  summation = 1
  for i in range(cnt+1, n):
    c = np.array(list(map(int, bigger[:i]<bigger[i]))).sum()
    perm = math.factorial(len(bigger[i+1:]))
    summation += (bigger[i]-c-1)*perm
    
  perm = math.factorial(len(smaller[cnt+1:]))
  #"perm-rest"
  summation2 = 1
  for i in range(cnt+1, n):
    c = np.array(list(map(int, smaller[:i]<smaller[i]))).sum()
    perm2 = math.factorial(len(smaller[i+1:]))
    summation2 += (smaller[i]-c-1)*perm2

  after = perm-summation2
  print(before + summation + after)  

else:
  bigger = p if p[cnt] > q[cnt] else q
  smaller = p if p[cnt] < q[cnt] else q
  u = bigger[cnt] - smaller[cnt] #until this
  c = np.array(list(map(int, bigger[:cnt]<u))).sum()
  #c*permutation
  perm = math.factorial(len(bigger[cnt+1:]))
  before = (bigger[cnt]-c) * perm
  #bigger, smaller
  summation = 0
  for i in range(cnt+1, n):
    c = np.array(list(map(int, bigger[:i]<bigger[i]))).sum()
    perm = math.factorial(len(bigger[i+1:]))
    summation += (bigger[i]-c-1)*perm
  
  perm = math.factorial(len(smaller[cnt+1:]))
  #"perm-rest"
  summation2 = 0
  for i in range(cnt+1, n):
    c = np.array(list(map(int, smaller[:i]<smaller[i]))).sum()
    perm = math.factorial(len(smaller[i+1:]))
    summation2 += (smaller[i]-c-1)*perm
  after = perm-summation2
  
  print(before + summation + after)

Measured memory_bytes: 21288