akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
league = [0]*(n+1)
cnt = 0

while True:
  topop = []
  if cnt == 0:
    for i,player in enumerate(a):
      x = player[-1]
      if league[x] == i+1:
        topop.append(x)
        topop.append(i+1)
      else:
        league[i+1] = x
  else:
    for player in popped:
      if a[player-1] == []:
        continue
      x = a[player-1][-1]
      if league[x] == player:
        topop.append(x)
        topop.append(player)
      else:
        league[player] = x
  popped = []
  if topop == []:
    print(-1)
    exit()
  for t in topop:
    if a[t-1] == []:
      print(-1)
      exit()
    a[t-1].pop()
    popped.append(t)
  cnt += 1
  if not any(a[i] for i in range(n)):
    break
print(cnt)


Measured memory_bytes: 61404
/**
 *    author:  tourist
 *    created: 10.12.2017 16:17:19       
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int md = (int) 1e9 + 7;

int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  map< vector<long long>, vector< pair<long long, long long> > > mp;
  for (int d = 0; d <= 60; d++) {
    vector<long long> p;
    p.push_back(0);
    for (int i = 0; i < n; i++) {
      long long r = a[i] % (1LL << d) + 1;
      if (r < (1LL << d) && r <= a[0]) {
        p.push_back(r);
      }
    }
    sort(p.begin(), p.end());
    p.resize(unique(p.begin(), p.end()) - p.begin());
    p.push_back(1LL << d);
    for (int id = 0; id < (int) p.size() - 1; id++) {
      long long x = p[id];
      long long to = p[id + 1] - 1;
      long long best = 0;
      for (int bit = 60; bit >= 0; bit--) {
        long long bbb = (1LL << bit);
        if ((x & bbb) == (to & bbb)) {
          best += (x & bbb);
        } else {
          if ((x & (bbb - 1)) != 0) {
            best += (to & bbb);
          }
          break;
        }
      }
      vector<long long> new_a = a;
      for (long long &aa : new_a) {
        aa = (aa - x) >> d;
      }
      long long spent = __builtin_popcountll(best) + d;
      if (spent <= k) {
        long long extra = k - spent;
        extra = min(extra, new_a[0]);
        debug(d, x, new_a);
        vector<long long> diff(n - 1);
        for (int i = 0; i < n - 1; i++) {
          diff[i] = new_a[i + 1] - new_a[i];
        }
        mp[diff].push_back(make_pair(new_a[0] - extra, new_a[0]));
      }
    }
  }
  long long ans = 0;
  for (auto &p : mp) {
    auto &z = p.second;
    debug(p.first, z);
    sort(z.begin(), z.end());
    long long last = -1;
    for (int i = 0; i < (int) z.size(); i++) {
      if (z[i].first > last) {
        ans = (ans + (z[i].second - z[i].first + 1)) % md;
      } else {
        if (z[i].second > last) {
          ans = (ans + (z[i].second - last)) % md;
        }
      }
      last = max(last, z[i].second);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const int MAX = 500000;

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int H;
int A[MAX+1];


void max_heapify(int* A, int i) {
    int l = left(i), r = right(i), largest = i;
    if (l <= H && A[l] > A[i]) {
        largest = l;
    }
    if (r <= H && A[r] > A[largest]) {
        largest = r;
    }
    if (largest != i) {
        swap(A[i], A[largest]);
        max_heapify(A, largest);
    }
}


void build_max_heap(int* A) {
    for (int i = H / 2; i >= 1; i--) {
        max_heapify(A, i);
    }
}


int main() {
    cin >> H;
    for (int i = 1; i <= H; i++) { cin >> A[i]; }
    build_max_heap(A);
    for (int i = 1; i <= H; i++) {
        cout << " " << A[i];
    }
    cout << endl;
}



Measured memory_bytes: 5040
#include <cmath>
#include <iostream>

int main(int argc, char const* argv[]) {
  char c;
  std::cin >> c;
  if (c=='a' || c=='i' || c=='u' || c=='e' || c=='o') {
    std::cout << "vowel" << '\n';
  } else {
    std::cout << "consonant" << '\n';
  }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iterator>

std::string reverse_str(std::string str);

int main()
{
	std::string str;
	while (std::cin >> str)
	{
		str = reverse_str(str);
		std::cout << str << std::endl;
	}
	return 0;
}

std::string reverse_str(std::string str)
{
	std::string str_ans;
	for (unsigned long i = 1; i <= str.size(); ++i)
	{
		std::string::iterator it = std::prev(end(str), i);
		str_ans += *it;
	}
	return str_ans;
}

Measured memory_bytes: 1184
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, a: [usize; n],
        bc: [(usize, usize)],
    }
    const W: usize = 100_100;
    let mut freq = vec![0; W];
    let mut sum: i64 = 0;
    for a in a {
        freq[a] += 1;
        sum += a as i64;
    }
    for (b, c) in bc {
        let f = freq[b];
        freq[c] += f;
        freq[b] = 0;
        sum += (c as i64 - b as i64) * f;
        puts!("{}\n", sum);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 4024
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long n = s.nextLong();
        long total = 0;
        for(int i = 1; i <= n; i++) {
            if( i % 3 != 0 && i % 5 != 0) {
                total += (long)i;
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 35792
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int A, B, X; cin >> A >> B >> X;
  if (A<=X && A+B>=X) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,n1[3],i=3,r=0;
    scanf("%d",&n);
    while(n>0 && i>=0)
    {
        i--;
        r=n%10;
        n1[i]=r;
        n=n/10;
    }
    for(i=0;i<3;i++)
    {
        if(n1[i]==1)
        {
            n1[i]=9;
        }
        else if(n1[i]==9)
        {
            n1[i]=1;
        }
    }
    n=(n1[0]*100)+(n1[1]*10)+n1[2];
    printf("%d\n",n);
    return 0;
}

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

typedef long long ll;

int a[100005];

int main(){

    int n, m; cin >> n >> m;
    priority_queue<int> pq;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        pq.push(a[i]);
    }
    
    for(int i = 0; i < m; i++){
        int x = pq.top(); pq.pop();
        pq.push(x/2);
    }
    
    ll res = 0;
    while(!pq.empty()){
        res += pq.top();
        pq.pop();
    }
    cout << res << endl;
    
    return 0;
}

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

main = do
  lines <- map (map (read :: String -> Int) . words) . tail . lines <$> getContents
  mapM putStrLn . map (isRight . reverse . sort) $ lines
  where isRight [a, b, c] = if a * a == b * b + c * c then "YES" else "NO"

Measured memory_bytes: 4200
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  
  sort(a,a+3);
  
  cout<<(a[2]-a[1])+(a[1]-a[0])<<endl;
  
}


Measured memory_bytes: 256
/* به نام یزدان */
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100 * 1000 + 10;
int n, k, h[MAX_N], dp[MAX_N];

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> h[i];
}

void solve() {
	memset(dp, 63, sizeof dp);
	dp[0] = 0;
	for (int i = 1; i < n; i++)
		for (int j = max(0, i - k); j < i; j++)
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
}

void print_output() {
	cout << dp[n - 1];
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	solve();
	print_output();
}


Measured memory_bytes: 1024
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n, a;
vector<int> vec;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a;
		vec.push_back(a);
	}
	reverse(vec.begin(), vec.end());
	if (vec[0] >= 3) {
		cout << -1 << endl;
		return 0;
	}
	int l = 2, r = 2;
	rep(i, n) {
		if (r / vec[i] == (l - 1) / vec[i]) {
			cout << -1 << endl;
			return 0;
		}
		l = (l + vec[i] - 1) / vec[i] * vec[i];
		r = r / vec[i] * vec[i] + vec[i] - 1;
	}
	cout << l << " " << r << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#define rep(i,beg,end) for(int i=(beg);i<(end);i++)
typedef long long LL;
using namespace std;

int dp[3005][3005]={};
pair<int,int> las[3005][3005]={};
int v[3005][3005];
int main(){
	string a,b;
	cin>>a>>b;
	if(a.length()>b.length())
		swap(a,b);
	int ans=0;
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			las[i][j]=make_pair(i,j);
			v[i][j]=-1;
			if(i-1>=0&&j==0)
				dp[i][j]=dp[i-1][j],las[i][j]=las[i-1][j],v[i][j]=v[i-1][j];
			else if(i==0&&j-1>=0)
				dp[i][j]=dp[i][j-1],las[i][j]=las[i][j-1],v[i][j]=v[i][j-1];
			else if(i-1>=0&&j-1>=0){
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				if(dp[i-1][j]>dp[i][j-1])
					las[i][j]=las[i-1][j],v[i][j]=v[i-1][j];
				else
					las[i][j]=las[i][j-1],v[i][j]=v[i][j-1];
			}
			if(i-1>=0&&j-1>=0){
				if(a[i]==b[j]){
					if(dp[i-1][j-1]+1>dp[i][j])
						las[i][j]=make_pair(i-1,j-1),v[i][j]=a[i];
					dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
				}
			}else if(a[i]==b[j]){
				if(1>dp[i][j])
					las[i][j]=make_pair(i,j),v[i][j]=a[i];
				dp[i][j]=max(dp[i][j],1);
			}
			//cout<<dp[i][j]<<" ";
			//cout<<las[i][j].first<<","<<las[i][j].second<<" ";
			ans=max(ans,dp[i][j]);
		}
		//cout<<endl;
	}
	//cout<<ans<<endl;
	int cnt=0;
	string tmp;
	for(int i=a.length()-1,j=b.length()-1;;){
		if(cnt==ans)break;
		cnt++;
		tmp+=v[i][j];
		//cout<<char(v[i][j]);
		int ni=las[i][j].first;
		int nj=las[i][j].second;
		i=ni,j=nj;
	}
	for(int i=tmp.length()-1;i>=0;i--){
		cout<<tmp[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 144440
class Convolution:
    sum_e = (911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601, 842657263, 730768835, 942482514, 806263778, 151565301, 510815449, 503497456, 743006876, 741047443, 56250497, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    sum_ie = (86583718, 372528824, 373294451, 645684063, 112220581, 692852209, 155456985, 797128860, 90816748, 860285882, 927414960, 354738543, 109331171, 293255632, 535113200, 308540755, 121186627, 608385704, 438932459, 359477183, 824071951, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    ROOT = 3
    def __init__(self, mod):
        self.MOD = mod

    def __butterfly(self, arr):
        n = len(arr)
        h = (n - 1).bit_length()
        MOD = self.MOD
        for ph in range(1, h + 1):
            w = 1 << (ph - 1)
            p = 1 << (h - ph)
            now = 1
            for s in range(w):
                offset = s << (h - ph + 1)
                for i in range(p):
                    l = arr[i + offset]
                    r = arr[i + offset + p] * now
                    arr[i + offset] = (l + r) % MOD
                    arr[i + offset + p] = (l - r) % MOD
                now *= Convolution.sum_e[(~s & -~s).bit_length() - 1]
                now %= MOD

    def __butterfly_inv(self, arr):
        n = len(arr)
        h = (n - 1).bit_length()
        MOD = self.MOD
        for ph in range(1, h + 1)[::-1]:
            w = 1 << (ph - 1)
            p = 1 << (h - ph)
            inow = 1
            for s in range(w):
                offset = s << (h - ph + 1)
                for i in range(p):
                    l = arr[i + offset]
                    r = arr[i + offset + p]
                    arr[i + offset] = (l + r) % MOD
                    arr[i + offset + p] = (MOD + l - r) * inow % MOD
                inow *= Convolution.sum_ie[(~s & -~s).bit_length() - 1]
                inow %= MOD

    def __call__(self, a, b):
        n = len(a)
        m = len(b)
        MOD = self.MOD
        if not n or not m: return []
        if min(n, m) <= 50:
            if n < m:
                n, m = m, n
                a, b = b, a
            res = [0] * (n + m - 1)
            for i in range(n):
                for j in range(m):
                    res[i + j] += a[i] * b[j]
                    res[i + j] %= MOD
            return res
        z = 1 << (n + m - 2).bit_length()
        a += [0] * (z - n)
        b += [0] * (z - m)
        self.__butterfly(a)
        self.__butterfly(b)
        for i in range(z):
            a[i] *= b[i]
            a[i] %= MOD
        self.__butterfly_inv(a)
        a = a[:n + m - 1]
        iz = pow(z, MOD - 2, MOD)
        for i in range(n + m - 1):
            a[i] *= iz
            a[i] %= MOD
        return a




def atcoder_practice2_f():
    import sys
    input = sys.stdin.buffer.readline

    N, M = map(int, input().split())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    convolution = Convolution(998244353)
    print(*convolution(A, B))


if __name__ == "__main__":
    atcoder_practice2_f()


Measured memory_bytes: 197108
import sys
input = sys.stdin.readline

N,K = map(int,input().rstrip().split())
A = [int(x)-1 for x in input().rstrip().split()]

now = 0
d = {}
if N < K:
    for i in range(0,N):
        if now in d:
            K -= d[now]
            K %= i-d[now]
            for j in range(K):
                now = A[now]
            break
        else:
            d[now] = i

        now = A[now]
else:
    for j in range(K):
        now = A[now]
        
print(now+1)

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

const ll k_max = 100;

vector<P> cnt(k_max);

ll pow_mod(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res *= a;
    a = a*a;
    a %= mod;
    n >>= 1;
    res %= mod;
  }
  return res;
}

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

  for (ll i = 0; i < k_max; i++) {
    cnt[i].first = 0;
    cnt[i].second = 0;
  }

  ll ans = 0;
  
  for (ll i = 0; i < N; i++) {
    ll x = A[i];
    for (ll k = 0; k < k_max; k++) {
      if (x & 1) {
        cnt[k].first++;
        cnt[k].first %= 1000000007;
      }
      else {
        cnt[k].second++;
        cnt[k].second %= 1000000007;
      }
      x >>= 1;
    }
  }
  for (ll k = 0; k < k_max; k++) {
    ll c = (cnt[k].first % 1000000007) * (cnt[k].second % 1000000007);
    ans += (pow_mod(2, k, 1000000007) * (c % 1000000007)) % 1000000007;
    ans %= 1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n,int m){
	vvl dp(256,vl(n+1,LINF));
	vl c(m),x(n);
	rep(i,m)cin>>c[i];
	rep(i,n)cin>>x[i];dp[128][0]=0;
	rep(i,n){
		rep(j,256){
			rep(k,m){
				int next=max(0,min(255,j+(int)c[k]));
				chmin(dp[next][i+1],dp[j][i]+(next-x[i])*(next-x[i]));
			}
		}
	}
	ll ans=LINF;
	rep(i,256)chmin(ans,dp[i][n]);
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n)solve(n,m);
}



Measured memory_bytes: 44096
#include<bits/stdc++.h>
#define ll long long 
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int32_t main(){
    fast;
    int c{};
    string s;   cin>>s;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]!=s[i+1])    c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    char a, b;
    cin >> a >> b;

    if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) cout << 'H' << endl;
    else cout << 'D' << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define MAX 2e6 + 1
typedef long long ll;
int main() {
	int n;
	cin>>n;
	set<string> st;
	string s;
	for(int i = 0; i<n; i++){
	    cin>>s;
	    st.insert(s);
	}
	cout<<st.size()<<endl;
	    
	
}


Measured memory_bytes: 19224
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string a,b;cin>>a>>b;
    if(a==b){
        cout<<"EQUAL"<<endl;
    }
    else{
        if(a.size()<b.size())cout<<"LESS"<<endl;
        else if(a.size()>b.size())cout<<"GREATER"<<endl;
        else{
        rep(i,0,a.size()){
            if(i>=b.size()){
                cout<<"GREATER"<<endl;
                return 0;
            }
            int aa=a[i]-'0',bb=b[i]-'0';
            if(aa<bb){
                cout<<"LESS"<<endl;
                return 0;
            }
            else if(aa>bb){
                cout<<"GREATER"<<endl;
                return 0;
            }
            
        }
        cout<<"LESS"<<endl;
    }
    }
}


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

int linearsearch(int p, int s[], int t)
{
    for (int i = 0; i < p; i++)
    {
        if (s[i] == t)
        {
            return 1;
        }
    }
    return -1;
}

int main()
{
    int pindex, qindex;
    int s[10001];
    int t;
    int sum = 0;

    cin >> pindex;

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

    cin >> qindex;

    for (int j = 0; j < qindex; j++)
    {
        cin >> t;
        // check
        if (linearsearch(pindex, s, t) == 1)
        {
            sum += 1;
        }      

    }
    cout << sum << endl;

    return 0;
    
}


Measured memory_bytes: 3136
from collections import deque
s=input()
l=len(s)
ans=0
for i in range(1<<(l-1)):
  Q=deque()
  for j in range(l-1):
    if (i>>j)&1:
      Q.append(j)
  Q.append(l-1)
  start=0
  while Q:
    v=Q.popleft()
    goal=v+1
    ans+=int(s[start:goal])
    start=v+1
print(ans)

    

Measured memory_bytes: 9404
#include<bits/stdc++.h>
using namespace std;
#define N 8

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

bool X[N][N];

void initialize(){
  for(int i=0;i<N;i++){row[i]=-1;col[i]=-1;}
  for(int i=0;i<2*N-1;i++){dpos[i]=-1;dneg[i]=-1;}
}

void printboard(){
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(X[i][j]){
	if(row[i]!=j) return;
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cout<<( (row[i]==j)?"Q":".");
    }
    cout<<endl;
  }
}

void recursive(int i){
  if(i==N){
    printboard();return;
  }
  for(int j=0;j<N;j++){
    if(col[j]==1 || dpos[i+j]==1 || dneg[i-j+N-1]==1) continue;
    row[i]=j;col[j]=dpos[i+j]=dneg[i-j+N-1]=1;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=-1;
  }
}

int main(){
  initialize();
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      X[i][j]=0;
    }
  }
  int k;cin>>k;
  for(int i=0;i<k;i++){
    int r,c;cin>>r>>c;
    X[r][c]=true;
  }
  recursive(0);
  return 0;
}
  



Measured memory_bytes: 3096
// start: 2:41
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

#define REP(i, n) for ( int i = 0; i < n; i++ )
#define MP(a, b) make_pair(a, b)
#define MAX 101

using namespace std;

typedef pair<int, int> ab;

int sum(vector<int> arr) {
    int ret = 0;
    REP(i, arr.size()) ret += arr[i];
    return ret;
}

bool flg = false;
int N, M;

ab all_search(vector<int> &a, vector<int> &b) {
    int aa = MAX, bb = MAX;

    REP(ai, N) REP(bi, M) {
        // トレード
        int tmp = a[ai];
        a[ai] = b[bi];
        b[bi] = tmp;

        // 等しく、かつ最小
        if ( sum(a) == sum(b) && a[ai] + b[bi] < aa + bb ) {
            aa = b[bi];
            bb = a[ai];
        }

        // 戻す
        b[bi] = a[ai];
        a[ai] = tmp;
    }
    return MP(aa, bb);
}

int main() {
    while(cin >> N >> M, N||M) {
        vector<int> a(N), b(M);
        queue<ab> open;

        REP(i, N) cin >> a[i];
        REP(i, M) cin >> b[i];

        ab ans = all_search(a, b);

        if ( ans.first != MAX ) cout << ans.first << " " << ans.second << endl;
        else cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define getsize(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define g(a, b) __gcd((a), (b))
#define l(a, b) (a) / __gcd((a), (b)) * b
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;


int main()
{
    ll A, B;
    cin >> A >> B;
    cout << l(A, B) << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
result = 0
for i in range(1,n+1):
  flag = 1
  prob = 1/n
  point = i
  while flag:
    if 1<=point<=(k-1):
      prob *= 1/2
      point *= 2
    else:
      flag = 0
      result += prob
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long
typedef vector<vector<ll> > matrix;
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;

int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll f[2000001];



ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

bool prime[100005];
void seive()
{  memset(prime,true,sizeof(prime));
    for(int i=2;i*i<=100005;i++)
    {
         if(prime[i]==true) {
        for(int j=2*i;j<=(100005);j+=i)
           { prime[j]=false;}
           }

    }
}
bool in(float x1,float y1,float x,float y,float r )
{
    if(abs(x1-x)*abs(x1-x)+abs(y1-y)*abs(y1-y)<=r*r) return true;
    return false;
}
bool cmp(pair<int,int> &a,pair<int,int> &b)
{

        return (a.second<b.second);
}
//
//vector<vector<int> >matrix;
matrix mul(matrix A,matrix B)
{
    matrix C(3, vector<ll>(3));
    for(int i=1;i<=2;i++)
    for(int j=1;j<=2;j++)
     for(int k=1;k<=2;k++)
         C[i][j] = (C[i][j] + A[i][k] * B[k][j]);
    return C;

}
matrix pow(matrix A, int p)
{
    if (p == 1)
        return A;
    if (p % 2)
        return mul(A, pow(A, p-1));
    matrix X = pow(A, p/2);
    return mul(X, X);
}
ll fib(int N,int a,int b)
{
    vector<ll> F1(3);
    F1[1] = a;
    F1[2] = b;
    matrix T(3, vector<ll>(3));
    T[1][1] = 0, T[1][2] = 1;
    T[2][1] = -1, T[2][2] = 1;
    if (N == 1)
        return a;
    if(N==2) return b;
    T = pow(T, N-1);
    ll res = 0;
    for(int i=1;i<=2;i++)
        res = (res + T[1][i] * F1[i]+ MOD)%MOD ;
    return res;
}

//1 2 3 4 5
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int t =1;
 while(t--)
  {
      int n,m;
      cin>>n>>m;
      cout<<(n-1)*(m-1)<<"\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

bool func(int n, int a, int b){
  int now = 0;
  while(n){
    now += n%10;
    n /= 10;
  }
  if(a <= now && now <= b) return true;
  return false;
}

int main(){
  int n,a,b; cin >> n >> a >> b;

  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(func(i, a, b)) ans += i;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

const int MOD = (int)1e9 + 7;
int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    map<int, int> divisors;
    for (int i = 2; i <= n; i++){
        int m = i;
        for (int j = 2; j * j <= m; j++){
            while (m % j == 0){
                divisors[j]++;
                m /= j;
            }
        }
        if (m != 1) divisors[m]++;
    }
    ll prod = 1;
    for (auto &it : divisors){
        prod = prod * (it.Y + 1) % MOD;
    }
    cout << prod << endl;

}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
    int paSize = printArray.size();
    for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
    if (between != '\n') {cerr << endl;}
}

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

int N, W;
int v[111], w[111];
int dp[111][11111];

int main() {
    cin >> N >> W;
    repp (i, 1, N+1) { cin >> v[i] >> w[i]; }

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j >= w[i]) {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7396
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long x;
    cin >> x;
    long long i = 1;
    long long d = 1;
    while (d < x) {
        i++;
        d = i * (i + 1) / 2;
    }
    cout << i;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n,ma=-1,cnt=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i);
		if(v.at(i)>=ma)cnt++;
		ma=max(ma,v.at(i));
	}
	cout<<cnt<<endl;

	return 0;
}



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

using namespace std;
typedef long long ll;
map<ll,ll> mp1,mp2;
ll a[200010];
int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
        mp1[a[i] + i]++; mp2[i - a[i]]++;
    }
    ll ans = 0;
    for(i=0;i<n;i++){
        ans += mp1[i - a[i]];
        ans += mp2[a[i] + i];
    }
    cout << ans/2 << endl;
}

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

#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
  fio;
  ll t, a, n, q, k, i, l, m, c, u, f, j, p, r, x, y, s, b, d;
cin>>x;
if(x<=599)cout<<8;
else if(x<=799)cout<<7;
else if(x<=999)cout<<6;
else if(x<=1199)cout<<5;
else if(x<=1399)cout<<4;
else if(x<=1599)cout<<3;
else if(x<=1799)cout<<2;
else if(x<=1999)cout<<1;

  return 0;
}


Measured memory_bytes: 3644
n = gets.chomp.to_i
arr = n.times.map{gets.chomp.split(" ").map(&:to_i)}

a,b,c = arr[0]
dp = [[a,b,c]]

(1..n-1).each do |i|
  a, b, c = arr[i]
  prev_a, prev_b, prev_c = dp[i-1]
  dp[i] = [
    a + (prev_b > prev_c ? prev_b : prev_c),
    b + (prev_c > prev_a ? prev_c : prev_a),
    c + (prev_a > prev_b ? prev_a : prev_b),
  ]
end

puts dp[n-1].max

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

int main(void) {
	vector<int> array;
	while (1) {
		int tmp;
		cin >> tmp;
		if (tmp == 0) break;
		array.push_back(tmp);
	}
	for (int i = 0; i < array.size(); i++) {
		cout << "Case " << i + 1 << ": " << array.at(i) << endl;
	}
	return 0;
}



Measured memory_bytes: 3252
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
Scanner sc=new Scanner(System.in);

int n,x,y;
long min,max,sum;
n=sc.nextInt();
x=sc.nextInt();
sum=x;
min=x;
max=x;
for(int i=0;i<n-1;i++){
	y=sc.nextInt();
	if(max<y)
		max=y;
	if(min>y)
		min=y;
	sum+=y;
}
System.out.print(min+" ");
System.out.print(max+" ");
System.out.println(sum);

sc.close();

}

}


Measured memory_bytes: 42292
main :: IO()
main = do
  ws <-  getLine :: IO String
  print . head . foldl rpn [] $ words ws

rpn :: [Int] -> String -> [Int]
rpn (x:y:zs) "+" = (x + y):zs
rpn (x:y:zs) "-" = (y - x):zs
rpn (x:y:zs) "*" = (x * y):zs
rpn acc w = (read w):acc



Measured memory_bytes: 3932
/// Zhupengfei 2018 / public domain / abc103D

#include <bits/stdc++.h>

#define right right1

using namespace std;

int right[100001];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
    int N, M;
    cin>>N>>M;
    int a, b;
    fill(right+1, right+N+1, 1e9);
    for(int i=1;i<=M;i++) {
        cin>>a>>b;
        right[a]=min(right[a], b);
    }
    int R=-1e9, count=0;
    for(int i=1;i<=N;i++) {
        if(right[i]!=1e9) {
            if(i>=R) {
                count++;
                R=right[i];
            } else {
                R=min(R, right[i]);
            }
        }
    }
    cout<<count<<endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;

int n;
int arr[100][100];
int time_saver[100][2];
int now_time;
queue< pair < int, int > > q;

void search(int fi, int fnow_time){
    time_saver[fi][0] = fnow_time;
    for(int i=0; i<100; i++){
        if(arr[fi][i] && !time_saver[arr[fi][i]-1][0]){
            int a = fnow_time+1;
            q.push(make_pair(arr[fi][i]-1, a));
        }
    }
}

int main(int argc, const char * argv[]) {
    
    /////////
    //write//
    /////////
    
    cin >> n;
    now_time = 0;
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            arr[i][j] = 0;
        }
        for(int j=0; j<2; j++){
            time_saver[i][j] = 0;
        }
    }
    
    for(int i=0; i<n; i++){
        int node, degree; cin >> node >> degree;
        for(int j=0; j<degree; j++){
            int tmp; cin >> tmp;
            arr[node-1][tmp-1] = tmp;
        }
    }
    
    for(int i=0; i<1; i++){
        if(time_saver[i][0])continue;
        search(i, now_time);
        while(!q.empty()){
            int tmp = q.front().first;
            int tmp2 = q.front().second;
            now_time = max(now_time, q.front().second+1);
            q.pop();
            if(time_saver[tmp][0] || tmp == 0)continue;
            search(tmp, tmp2);
        }
    }
    for(int i=1; i<n; i++){
        if(!time_saver[i][0])time_saver[i][0] = -1;
    }
    
    for(int i=0; i<n; i++){
        for(int j=0; j<1; j++){
            if(j)cout << " ";
            else cout << i+1 << " ";
            cout << time_saver[i][j];
        }
        cout << endl;
    }
    
    return 0;
}





Measured memory_bytes: 3148
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = int(1e9) + 7
INF=float('inf')


s=data()
if s[-1]=='s':
    out(s+'es')
else:
    out(s+'s')

Measured memory_bytes: 77280
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

int32_t main()
{
    IOS
    
    
    string s,t;
    cin>>s>>t;
    map<int,int> m;
    map<int,int> m1;
    for(int i=0;i<s.length();++i)
    {
        m[s[i]-'a'+1]++;
    }
    for(int i=0;i<t.length();++i)
    {
        m1[t[i]-'a'+1]++;
    }
    for(auto i:m1)
    {
        //cout<<i.first<<" "<<i.second<<" "<<m[i.first]<<endl;
        if(m[i.first]==0)
        {
            cout<<-1;
            return 0;
        }

    }
   
    int j=0;
   // int ans=0;
    int n=s.length();
    int x[26][n+2];
    memset(x,-1,sizeof(x));
    for(int i=n-1;i>=0;--i)
    {
        for(int j=0;j<26;++j)
        {
            x[j][i]=x[j][i+1];
            if(s[i]==(char)('a'+j))
            {
                x[j][i]=i;
            }
        }
    }
    // for(int i=0;i<26;++i,cout<<endl)
    // {
    //     for(int j=0;j<s.length();++j)
    //         cout<<x[i][j]<<" ";
    // }
    int temp=-1,ans=0;
    for(int i=0;i<t.length();++i)
    {
        int y=x[t[i]-'a'][temp+1];
       // cout<<y<<endl;
        if(y==-1)
        {
            ans+=(n-1)-temp;
            
            
            temp=x[t[i]-'a'][0];
            ans+=temp+1;
        }
        else
        {
            ans+=(y-temp);
            temp=y;
            
        }
       // cout<<"ans="<<ans<<" "<<temp<<endl;
    }
    cout<<ans;

    
}



Measured memory_bytes: 20944
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int DX[8]={-1,0,1,0,-1,-1,1,1},DY[8]={0,-1,0,1,-1,1,-1,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int n;

int main(){
	EnumeratePrime();
	while(1){
		cin>>n;
		if(n==0) break;
		if(prime[n]) cout<<0<<endl;
		else{
			int t=2;
			for(int i=n-1;!prime[i];i--) t++;
			for(int i=n+1;!prime[i];i++) t++;
			cout<<t<<endl;
		}
	}
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string N;
    cin >> N;
    int cnt = 0;
    for(int i = 0; i < N.size(); i++) {
        cnt += N[i]-'0';
    }
    cout << ((cnt%9 == 0)?"Yes":"No") << endl;
}


Measured memory_bytes: 3752
#include <iostream>
using namespace std;
#define MAX_N 110
#define MAX_W 100100
int N, W;
int w[MAX_N], v[MAX_N];
long long dp[MAX_N][MAX_W];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,arr[100001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    //for (int i=0;i<n;i++){
        //cin>>arr[i];
    //}
    long long tot=0;
    for (int i=1;i<=n;i++){
        if (i%3!=0 && i%5!=0){
            tot+=i;
        }
    }
    cout<<tot;
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(void)
{
	int n,k,i,j;
	int num[100002];
	scanf("%d %d",&n, &k);
	
	double answer, total;
	total = 0.0;
	for(i=1;i<=n;i++){
		num[i] = i;
		while(num[i]<=k-1){
			num[i]*=2;
		}
	}
	for(i=1;i<=n;i++){
		total += (double)(1.0/(num[i]/i*n));
	}
	printf("%.16lf",total);
	return 0;
}

Measured memory_bytes: 512