akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            # candidate_pond = []
            area2 = 0
            while ponds and left < ponds[-1][0]:
               # candidate_pond.append(ponds.pop(-1))
               area2 += ponds.pop(-1)[1]

            # new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            new_pond = (left, area + area2)
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Measured memory_bytes: 7000
import numpy as np

H,W = map(int, input().split())
a = []
for h in range(H):
    a.append(list(map(int, input().split())))

# 各行に対して列1->Wの向きに、奇数を追いやる
O = [] #operation
for h in range(H):
    for w in range(W-1):
        if a[h][w] %2 == 1:
            a[h][w] -= 1
            a[h][w+1] += 1
            O.append([h+1,w+1,h+1,w+2]) # indexが1始まり

# 最後に W列で1->Hの向きに追いやる
for h in range(H-1):
    if a[h][W-1] %2 == 1:
        a[h][W-1] -= 1
        a[h+1][W-1] += 1
        O.append([h+1, W, h+2, W])

print(len(O))
for o in O:
    print("{} {} {} {}".format(*o) )


Measured memory_bytes: 38812
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
sys.setrecursionlimit(100000)
MOD = 10**9 + 7

def dijkstra(g, v_size, st):
    """Dijkstra method"""

    d = [float('inf')] * v_size
    d[st] = 0

    que = [(0, st)]     # (min_dist, vertex)
    heapq.heapify(que)

    while len(que) > 0:
        dist, v0 = heapq.heappop(que)
        if d[v0] < dist: continue
        for v1, dist in g[v0]:
            if d[v1] > d[v0] + dist:
                d[v1] = d[v0] + dist
                heapq.heappush(que, (d[v1], v1))

    return d

def solve(f):
    n, m = f.read_int_list()
    s, t = f.read_int_list()
    g = collections.defaultdict(list)
    for m in xrange(m):
        u, v, d = f.read_int_list()
        g[u-1].append((v-1, d))
        g[v-1].append((u-1, d))

    d = dijkstra(g, n, s-1)

    cand = []
    for i in xrange(n):
        if d[t-1] == d[i]*2: cand.append((i,i))

    memo = [0]*n
    memo[t-1] = 1
    ary = [(d[i], i) for i in xrange(n)]
    ary.sort(reverse=True)

    for _, v in ary:
        for vi, di in g[v]:
            if d[v]-di == d[vi]:
                memo[vi] = (memo[vi]+memo[v])%MOD
                if d[vi]*2 < d[t-1] < (d[vi] + di)*2:
                    cand.append((vi, v))

    memo2 = [0]*n
    memo2[s-1] = 1

    ary.sort()
    for _, v in ary:
        for vi, di in g[v]:
            if d[v]+di == d[vi]:
                memo2[vi] = (memo2[vi]+memo2[v])%MOD

    cnt = []
    for v1, v2 in cand:
        cnt.append((memo2[v1]*memo[v2])%MOD)

    s = sum(cnt)
    ans = 0
    for ci in cnt:
        ans = (ans+ci*(s-ci))%MOD

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 1e9+7;

struct SegmentTree {
private:
    int n;
    vector<ll> node;

public:
    SegmentTree(vector<int> v) {
	      int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[2*i+1] + node[2*i+2];
    }

    void update(int x , int v) {
      x += (n - 1);
      node[x] = v;
      while(x > 0) {
          x = (x - 1) / 2;
          node[x] = node[2*x+1] + node[2*x+2];
      }
    }

    ll get(int a, int b, int k=0, int l=0, int r=-1) {
      if(r < 0) r = n;

      if(r-1 < a || b < l) return 0;

      if(a <= l && r-1 <= b) return node[k];

      ll vl = get(a, b, 2*k+1, l, (l+r)/2);
      ll vr = get(a, b, 2*k+2, (l+r)/2, r);
      return vl + vr;
    }
};

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  vvi cnts(26,vi(n));

  rep(i,n){
    cnts[s[i] - 'a'][i]++;
  }
  
  vector<SegmentTree> segs;
  rep(i,26){
    segs.push_back(SegmentTree(cnts[i]));
  }

  int q;
  cin >> q;
  while(q--){
    int t;cin >> t;
    if(t == 1){
      int i; char c;
      cin >> i >> c;
      i--;
      if(s[i] != c){
        segs[s[i] - 'a'].update(i,0);
        segs[c - 'a'].update(i,1);
        s[i] = c;
      }
    }else{
      int l,r;
      cin >> l >> r;
      l--;r--;
      int ret = 0;
      rep(i,26){
        if(segs[i].get(l,r)){
          ret++;
        }
      }
      cout << ret << endl;
    }
  }
}

Measured memory_bytes: 266744
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            int a = int.Parse(inputs[0]);
            int p = int.Parse(inputs[1]);

            int pieces = a * 3 + p;
            int remain;
            int pieCount = Math.DivRem(pieces, 2, out remain);

            Console.WriteLine(pieCount);
        }
    }
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n % 2 == 1) {
    cout << "No\n";
    return 0;
  }
  for (int i = 0; i < n; i += 2) {
    if (s.substr(i, 2) != "hi") {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int N, X, D=0;
    scanf("%d %d",&N,&X);
    int L[N];
    for(int i=0;i<N;++i){
        scanf("%d", &L[i]);
    }
    int count=1;
    for(int i=0; i<N;++i){
        D+=L[i];
        if(D<=X){
            ++count;
        }else{
            break;
        }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
b = set()
for i in range(2**n):
  t = 0
  for j in range(n):
    if i>>j&1:
      t += a[j]
  b.add(t)
for ele in m:
  if ele in b:
    print("yes")
  else:
    print("no")


Measured memory_bytes: 5652
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc.chars();
    for _ in 0..s.len() {
        print!("x");
    }
    println!();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;
using ll = long long int;

int main()
{
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll bn = min(a, b);
  bn = min(bn, c);
  bn = min(bn, d);
  bn = min(bn, e);
  ll nc = n / bn + 1ll;
  if(bn == 1) {
    nc = n;
  }
  cout << 5ll + nc - 1ll << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int num[4][100005];
LL dp[4][100005];
int main(void) {
    int n;
    cin>>n;
    for(int i = 1; i <= 3; i++) {
        for(int j = 1; j <= n; j++) {
            cin>>num[i][j];
        }
        sort(num[i]+1,num[i]+n+1);
    }
    memset(dp,0,sizeof(dp));
    for(int i = 1; i <= n; i++)
        dp[1][i] = i;
    for(int i = 2; i <= 3; i++) {
        for(int j = 1; j <= n; j++) {
            dp[i][j]+=dp[i][j-1];
            int l = 0,r = n;
            int id = 0;
            while(l <= r) {
                int mid = (l+r)/2;
                if(num[i-1][mid] < num[i][j])
                    id = mid,l = mid + 1;
                else r = mid - 1;
            }
            //printf("%d\n",id);
            dp[i][j] += dp[i-1][id];
        }
    }
    printf("%lld\n",dp[3][n]);
    return 0;
}


Measured memory_bytes: 4992
public class Main {

    public static void main(String[] args) {

        java.util.Scanner sc = new java.util.Scanner(System.in);

        int n = sc.nextInt();

        int count = 0;

        for (int i = 1; i <= n; i++) {
            if (("" + i).length() % 2 == 1) {
                count++;
            }
        }

        System.out.println(count);

    }

}


Measured memory_bytes: 43944
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
//begin cut here//
 
//n!
ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
}
 
// 繰り返し二乗法 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
 
//nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    //a=n!/(n-r)!=n~n-r+1までの総積->O(r)
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    //b=inv(r!)
    ll b=pow_mod(fact_mod(r), mod-2);
    return (a%mod)*(b%mod)%mod;
}
 
ll inv_mod(ll n){
    // フェルマーの小定理
    return pow_mod(n,mod-2);
}
//end cut here//

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

    ll x,y;cin>>x>>y;
    if((2*x-y)%3||2*x-y<0){
        cout<<0<<endl;return 0;
    }
    if((2*y-x)%3||2*y-x<0){
        cout<<0<<endl;return 0;
    }
    ll a=(2*x-y)/3,b=(2*y-x)/3;
    ll ans=fact_mod(a+b);
    ans=(ans*inv_mod(fact_mod(a)))%mod;
    ans=(ans*inv_mod(fact_mod(b)))%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n, q; cin >> n >> q;

  vector<P> E;
  V x(n);
  rep(i, n) {
    int s, t;
    cin >> s >> t >> x[i];
    E.emplace_back(s-x[i], i);
    E.emplace_back(t-x[i], i);
  }
  sort(all(E));

  set<P> S;
  int i = 0;
  rep(_, q) {
    int d; cin >> d;
    for (; i < 2*n && E[i].first <= d; ++i) {
      int &j = E[i].second;
      auto p = P({x[j], j});
      if (S.find(p) == S.end()) S.insert(p);
      else S.erase(p);
    }
    if (S.empty()) cout << -1 << "\n";
    else cout << (*S.begin()).first << "\n";
  }
  return 0;
}


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

typedef complex<double> CD;
typedef long long LL;
const double PI = acos(-1);

struct FFT {
    int N;
    vector<int> perm;

    void precalculate() {
        perm.resize(N);
        perm[0] = 0;

        for (int k=1; k<N; k<<=1) {
            for (int i=0; i<k; i++) {
                perm[i] <<= 1;
                perm[i+k] = 1 + perm[i];
            }
        }
    }

    void fft(vector<CD> &v, bool invert = false) {
        if (v.size() != perm.size()) {
            N = v.size();
            assert(N && (N&(N-1)) == 0);
            precalculate();
        }

        for (int i=0; i<N; i++)
            if (i < perm[i])
                swap(v[i], v[perm[i]]);

        for (int len = 2; len <= N; len <<= 1) {
            double angle = 2 * PI / len;
            if (invert) angle = -angle;
            CD factor = polar(1.0, angle);

            for (int i=0; i<N; i+=len) {
                CD w(1);
                for (int j=0; j<len/2; j++) {
                    CD x = v[i+j], y = w * v[i+j+len/2];
                    v[i+j] = x+y;
                    v[i+j+len/2] = x-y;
                    w *= factor;
                }
            }
        }
        if (invert)
            for (CD &x : v) x/=N;
    }

    vector<LL> multiply(const vector<LL> &a, const vector<LL> &b) {
        vector<CD> fa(a.begin(), a.end()), fb(b.begin(), b.end());

        int n = 1;
        while (n < a.size()+ b.size())  n<<=1;
        fa.resize(n);
        fb.resize(n);

        fft(fa);
        fft(fb);
        for (int i=0; i<n; i++) fa[i] *= fb[i];
        fft(fa, true);

        vector<LL> ans(n);
        for (int i=0; i<n; i++)
            ans[i] = round(fa[i].real());
        return ans;
    }
} fft;


const int P = 200003, G = 2;
int pg[P], ind[P];
long long con[P];

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

    pg[0] = 1;
    ind[1] = 0;
    for (int i=1; i<P-1; i++) {
        pg[i] = (pg[i-1]*G)%P;
        ind[pg[i]] = i;
    }

    vector<long long> cnt(P-1);
    int n;
    cin>>n;

    long long ans = 0;
    for (int i=1; i<=n; i++) {
        long long x;
        cin>>x;
        if (x == 0) continue;
        ans -= (x*x)%P;
        cnt[ind[x]]++;
    }

    vector<long long> sum = fft.multiply(cnt, cnt);

    long long ss = 0;
    for (auto x: sum)   ss += x;

    for (int i=0; i<sum.size(); i++) {
        con[i%(P-1)] += sum[i];
    }

    for (int i=0; i<P-1; i++) {
        ans += con[i]*pg[i];
    }
    cout<<ans/2<<endl;
}


Measured memory_bytes: 29484
/*input
11 10 9
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	ll a, b, n;
	cin >> a >> b >> n;
	auto f = [&](ll a, ll b, ll x) {
		return ((a * x) / b) - (a * (x / b));
	};
	ll l=0, r=n, ret = 0;
	while(l <= r) {
		ll m1 = (l + l + r) / 3ll;
		ll m2 = (l + r + r) / 3ll;
		ll f1 = f(a, b, m1);
		ll f2 = f(a, b, m2);
		if(f1 > f2) {
			ret = max(ret, f1);
			r = m2 - 1;
		}
		else {
			ret = max(ret, f2);
			l = m1 + 1;
		}
		// cout << "ret: " << ret << endl;
	}
	for(; l<=r; l++) {
		ret = max(ret, f(a, b, l));
	}
	cout << ret << endl;
}

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


Measured memory_bytes: 3648
import sys
from pprint import pprint

def solve(h, n, a):
    print("Yes" if sum(a) >= h else "No")

if __name__ == '__main__':
    h, n = map(int, sys.stdin.readline().strip().split(" "))
    a = map(int, sys.stdin.readline().strip().split(" "))
    solve(h, n, a)

Measured memory_bytes: 51824
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int64_t R = 1e9 + 7;

int64_t factors[1'001];

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

    fill(factors, factors + 1'001, 0);
    for (int k = 1; k <= n; k++) {
        int kk = k;
        for (int i = 2; i * i <= kk; i++) {
            bool isPrime = true;
            for (int j = 2; j * j <= i; j++) {
                isPrime = isPrime && i % j != 0;
            }

            while (kk % i == 0) {
                kk /= i;
                factors[i]++;
            }
        }
        if (kk != 1) {
            factors[kk]++;
        }
    }

    int64_t result = 1;
    for (const int64_t f : factors) {
        result = result * (f + 1) % R;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int comp(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return (*(int*)a<*(int*)b)-(*(int*)a>*(int*)b);}

#define putchar(c) putc_unlocked((c), stdout)
#define getchar() getc_unlocked(stdin)
char nextchar(void){ char c=getc_unlocked(stdin); while(c==' '||c=='\n') c=getc_unlocked(stdin); return c; }
int32_t nextint(void){ char c=getc_unlocked(stdin); while(c!='-'&&(c<'0'||'9'<c)) c=getc_unlocked(stdin); int s=0; if(c=='-'){s=1;c=getc_unlocked(stdin);} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return s?-x:x; }
int64_t nextlong(void){ char c=getc_unlocked(stdin); while(c!='-'&&(c<'0'||'9'<c)) c=getc_unlocked(stdin); int s=0; if(c=='-'){s=1;c=getc_unlocked(stdin);} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return s?-x:x; }
uint32_t nextpint(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
uint64_t nextplong(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
uint32_t nextstr(char *s){ char c=getc_unlocked(stdin); while(c==' '||c=='\n') c=getc_unlocked(stdin); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getc_unlocked(stdin); } *s='\0'; return len; }
uint32_t nextstrln(char *s){ char c=getc_unlocked(stdin); while(c==' '||c=='\n') c=getc_unlocked(stdin); uint32_t len=0; while(c!='\n'){ *s++=c; len++; c=getc_unlocked(stdin); } *s='\0'; return len; }

void printint(int x){ if(x<0){x=-x; putc_unlocked('-', stdout);}else if(x==0){putc_unlocked('0', stdout);} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putc_unlocked(s[i], stdout); putc_unlocked('\n', stdout); }
void printlong(long x){ if(x<0){x=-x; putc_unlocked('-', stdout);}else if(x==0){putc_unlocked('0', stdout);} int d=0; char s[20]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putc_unlocked(s[i], stdout); putc_unlocked('\n', stdout); }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}
inline int abs2(const int a){return a>=0?a:-a;}

int main(void){
	if(getchar()=='7' ||getchar()=='7' ||getchar()=='7'){
		puts("Yes");
	}else{
		puts("No");
	}
}


Measured memory_bytes: 1496
<?php
  define("N", intval(trim(fgets(STDIN))));
	$weightList = explode(' ',trim(fgets(STDIN)));
	$preDif = null;
	$curDif = 0;
	for($t=1; $t<N; $t++){

    $s1 = array_sum(array_slice($weightList,0,$t));
    $s2 = array_sum(array_slice($weightList,$t));
		$curDif = abs($s1 - $s2);
    if($curDif > $preDif && is_numeric($preDif)){
      break;
    }
      $preDif = $curDif;
    }

    echo $preDif;

?>


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

using namespace std;

int main()
{
    lli a,b,c;
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0)
    {
        cout<<0<<endl;
    }
    else{
        if(a>=b&&a>=c)
        {
            cout<<b*c<<endl;
        }
        else if(b>=a&&b>=c)
        {
            cout<<a*c<<endl;
        }
        else
        {
            cout<<a*b<<endl;
        }
    }
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
answer = []

while True:
    n = int(input())
    if n == 0:
        break

    ans = 0
    for i in range(55):
        for j in range(96):
            temp = i * i * i + (j * (j + 1) * (j + 2) // 6)
            if temp <= n:
                if ans < temp:
                    ans = temp
            else:
                break

    answer.append(ans)

for i in answer:
    print(i)


Measured memory_bytes: 5672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int k = sc.nextInt();
		boolean[] hate = new boolean[10];
		
		for (int i = 0; i < k; i++) {
			int digit = sc.nextInt();
			hate[digit] = true;
		}
		
		for (int i = n; i < 10*n; i++) {
			int num = i;
			boolean isHate = false;
			
			while (num > 0) {
				int m = num % 10;
				if (hate[m]) {
					isHate = true;
					break;
				}
				num /= 10;
			}
			
			if (!isHate) {
				System.out.println(i);
				System.exit(0);
			}
		}
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


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

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

  if (a<b && b<c) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  size_t n; int X; std::cin >> n >> X;
  std::vector<int> a(n), b(n);
  for (size_t i = 0; i < n; i++) {
    std::cin >> a[i] >> b[i];
  }
  int max = *std::max_element(a.begin(), a.end());
  std::sort(b.begin(), b.end(), std::greater<int>());
  unsigned ret = 0;
  while (X > 0) {
    if (!b.empty() && b.front() > max) {
      X -= b.front();
      ret++;
      b.erase(b.begin());
    } else {
      ret += (X + max - 1) / max;
      X = 0;
    }
  }
  std::cout << ret << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, k;
H a[200000];
int b[200000];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i].y >> a[i].x;
	}
	sort(a, a + n);
	reverse(a, a + n);
	//おいしさ、種類
	int sum = 0, res = 0;
	//おいしさの総和、種類の数、種類があるか
	priority_queue<H, vector<H>, greater<H>>p;
	for (int i = 0; i < k; i++) {
		sum += a[i].x;
		if (!b[a[i].y]) {
			res++;
		}
		b[a[i].y]++;
		p.push(H{ a[i].x,a[i].y });
	}
	int ans = sum + res * res;
	for (int i = k; i < n; i++) {
		if (b[a[i].y]) {
			continue;
		}
		if (p.empty()) break;
		H t = p.top(); p.pop();
		while (!p.empty() && b[t.y] == 1) {
			t = p.top(); p.pop();
		}
		if (p.empty()) break;
		sum -= t.x;
		sum += a[i].x;
		b[a[i].y]++;
		p.push(H{ a[i].x,a[i].y });
		res++;
		ans = max(ans, sum + res * res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5748
($n,$y) = split/ /,<>;

for($i=0;$i<=$n;$i++){
	for($j=0;$j<=$n;$j++){
    	$z=$n-$i-$j;
    	$sum=10000*$i+5000*$j+1000*$z;
        if($sum==$y && $z >= 0){
            print "$i"." "."$j"." "."$z";
            exit;
        }
    }
}
print "-1 -1 -1";


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

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N = 1e5 + 5;
int dp[N];

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int a[n+1];
    FOR(i,1,n+1)cin>>a[i];
    dp[1] = 0,dp[2] = abs(a[2] - a[1]);
    FOR(i,3,n+1) dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]),dp[i-2] + abs(a[i] - a[i-2]));
    cout<<dp[n]<<"\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[100010],w[105],v[105];
int main(){
	cin>>n>>m;
	for(long long i=0;i<n;i++) cin>>w[i]>>v[i];
	for(long long i=0;i<n;i++){
		for(long long j=m;j>=w[i];j--){
			a[j]=max(a[j],a[j-w[i]]+v[i]);
		}
	}
	cout<<a[m]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 5e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}

int main()
{   
    ll n;
    cin>>n;
    ll a[n+1];
    FOR(i,1,n)cin >> a[i];
    ll dp[n+1] = {0};
    dp[1] = 0;
    dp[2] = abs(a[2]-a[1]);
    FOR(i,3,n){
        dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout << dp[n];

    return 0;
}

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

int main()
{
    string a, b;
    cin >> a >> b;
    vector<char> vc;
    for (int i = 0; i < b.size(); i++) {
        vc.push_back(a[i]);
        vc.push_back(b[i]);
    }
    
    if (a.size() > b.size()) vc.push_back(a[a.size() - 1]);
    for (int i = 0; i < vc.size(); i++) cout << vc[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
ch-=1
cw-=1
dh-=1
dw-=1
s=[input() for _ in range(h)]
def bfs(sx,sy):
    q=deque([(sx,sy)])
    d=[[10**18]*w for _ in range(h)]
    d[sx][sy]=0
    while q:
        x,y=q.popleft()
        for dx in range(-2,3):
            for dy in range(-2,3):
                nx,ny=x+dx,y+dy
                if not (0<=nx<h and 0<=ny<w):
                    continue
                if dx==0 and dy==0:
                    continue
                if s[nx][ny]=="#":
                    continue
                if abs(dx)+abs(dy)==1:
                    if d[nx][ny]>d[x][y]:
                        d[nx][ny]=d[x][y]
                        q.appendleft((nx,ny))
                else:
                    if d[nx][ny]>d[x][y]+1:
                        d[nx][ny]=d[x][y]+1
                        q.append((nx,ny))
    return d
d=bfs(ch,cw)
if d[dh][dw]==10**18:
    print(-1)
else:
    print(d[dh][dw])

Measured memory_bytes: 98328
#include<iostream>

using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n,greater<int>());
  long long int tot=a[0];
  int ptr=1,cnt=0;
  for(int i=2;i<n;i++)
  {
    if(cnt==2)
    {
      ptr++;
      tot=tot+a[ptr];
      cnt=1;
    }
    else
    {
      tot=tot+a[ptr];
      cnt++;
    }
  }
  cout<<tot;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int N;
ll A[100010];
ll ans;
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    ans += A[0] - 1;
    int me = 2, mo = 3; 
    for(int i = 1; i < N; i++){
        if(me < mo && A[i] == me){
            me += 2;
            continue;
        }
        if(me > mo && A[i] == mo){
            mo += 2;
            continue;
        }
        int m = min(me, mo);
        ans += A[i] / m;
        if(A[i] % m == 0) ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define LP(i, a, n) for(int i = a; i < n; i++)
#define lpp(i, n) for(int i = 0; i < n; i++)
#define INF 1e9+7
using namespace std;
int c;
void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];
  lp(n1)
    L[i] = A[left + i];
  lp(n2)
    R[i] = A[mid + i];
  L[n1] = INF;
  R[n2] = INF;
  int i = 0;
  int j = 0;
  LP(k,left,right){
    c++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else {
      A[k] = R[j];
      j = j + 1;
    }
  }
}
void mergeSort(int A[], int left, int right) {
  if(left+1 < right) {
    int mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main(){
  int n, S[500000];
  cin >> n;
  lp(n) cin >> S[i];
  mergeSort(S, 0, n);
  lp(n) cout << S[i] << (n-1 == i ? "\n":" ");
  cout << c << endl;
  return 0;
}




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

int main() {
	int n,i;
	string s;
	cin >> s;
	n=s.size();
	for(i=0; i<n; i++){
		if(i%2==0 && s[i]=='L'){
			cout << "No"; return 0;
		}else if(i%2==1 && s[i]=='R'){
			cout << "No"; return 0;
		}
	}
	cout << "Yes";
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,(ll)b)
#define rM(a,b) min(a,(ll)b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  st s;
  	ci(s);
 int k;
  	ci(k);
  ll S=s.sz;
  ll all=rM(S,k);
  ll sum=0;
  
  FOR(i,0,all){
    if(s.at(i)!='1') {
      co(s.at(i));
      break;
    }
    else {
      sum+=1;
    }
  }
  
  if(sum==all) co(1);
}

Measured memory_bytes: 256
from sys import stdin

INF = 1000000007

def merge(A, l, m, r):
    global count
    L = A[l:m] + [INF]
    R = A[m:r] + [INF]
    li = 0
    ri = 0
    for j in range(l, r):
        count += 1
        if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1

def mergeSort(A, l, r):
    if r-l > 1:
        mid = l + (r-l)//2
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r)

n = int(stdin.readline().rstrip())
S = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
mergeSort(S, 0, n)
print(*S)
print(count)


Measured memory_bytes: 61652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k <= a + b){
    cout << min(a,k) << endl;
  }
  else{
    cout << a - (k - a - b) << endl;
  }
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int w, h, n;
  std::cin >> w >> h >> n;
  int mi_x = w, mi_y = h, ma_x = 0, ma_y = 0;
  rep(i, n) {
    int x, y, a;
    std::cin >> x >> y >> a;
    if (a == 1)
      chmax(ma_x, x);
    else if (a == 2)
      chmin(mi_x, x);
    else if (a == 3)
      chmax(ma_y, y);
    else if (a == 4)
      chmin(mi_y, y);
  }
  std::cout << max(mi_x - ma_x, 0) * max(mi_y - ma_y, 0) << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#define MAX 100000
int n, k;
long long T[MAX];

int check(long long p){
	int i = 0;
	for (int j = 0; j < k; j++){
		long long s = 0;
		while (s + T[i] <= p){
			s += T[i];
			i++;
			if (i == n)return n;
		}
	}
	return i;
}


int solve(){
	int v;
	long long left = 0;
	long long right = 100000 * 10000;
	long long mid;
	while (right > left + 1){
		mid = (left + right) / 2;
		v = check(mid);
		if (v >= n)right = mid;
		else left = mid;
	}
	return right;
}
int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &T[i]);
	}
	long long p = solve();
	printf("%d\n", p);
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_H = (int)(1e3 + 5);
const int MAX_W = (int)(1e3 + 5);

int h, w, a, b;
int field[MAX_H][MAX_W];

int main(void) {
  // Here your code !
  scanf("%d %d %d %d", &h, &w, &a, &b);

  for (int i = 0; i < b; ++i) {
    for (int j = 0; j < a; ++j) {
      field[i][j] = 0;
    }
  }

  for (int i = 0; i < b; ++i) {
    for (int j = a; j < w; ++j) {
      field[i][j] = 1;
    }
  }

  for (int i = b; i < h; ++i) {
    for (int j = 0; j < a; ++j) {
      field[i][j] = 1;
    }
  }

  for (int i = b; i < h; ++i) {
    for (int j = a; j < w; ++j) {
      field[i][j] = 0;
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      printf("%d", field[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 5120
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }    

int main() {
    int N;
    cin >> N;
    vector<queue<int>> data(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N-1; j++) {
            int a; cin >> a; --a;
            data[i].emplace(a);
        }
    }
    
    int ans = 0;
    bool play[N] = {0};
    queue<int> que;
    for (int i = 0; i < N; i++) que.emplace(i);
    
    while (que.size()) {
        fill(play, play + N, false);
        queue<int> next;
        while (que.size()) {
            int me = que.front(); que.pop();
            if (data[me].empty()) continue;
            int you = data[me].front();
            if (data[you].front() == me && !play[me] && !play[you]) {
                next.emplace(me); next.emplace(you);
                if (data[me].size()  > 0) data[me].pop();
                if (data[you].size() > 0) data[you].pop();
                play[me] = play[you] = true;
            }
        }
        swap(que, next);
        ans++;
    }
    
    bool fin = true;
    for (int i = 0; i < N; i++) if (data[i].size() > 0) fin = false;
    
    cout << ((fin) ? ans-1 : -1) << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>

int main(void){
  long long int N,A,B,C,D;
  int i,j,k;
  scanf("%lld %lld %lld %lld %lld",&N,&A,&B,&C,&D);
  for(k=0;k<N;k++){
    if(A+C*(N-k-1)-D*k <= B && B <= A+D*(N-k-1)-C*k){
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
  return 0;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int l;
    cin>>l;
    cout<<fixed<<setprecision(10)<<1.0l*l*l*l/27<<endl;
}

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

Measured memory_bytes: 256
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  string str;

  cin>>str;

  for(int i=0;i<4;i++){
    cout<<str[i];
  }
  cout<<" ";

  for(int i=4;i<str.length();i++){
    cout<<str[i];
  }

  cout<<endl;
  
  return 0;
  
}




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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

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;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int n,a;
LL ans=0;
LL f[N],sum;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>a;
	for(int i=0;i<a&&i<=n;i++){
		if(i==0)f[0]=n/a;
		else f[i]=(n-i)/a+1;
		sum+=f[i];
	}
	if(f[0]>=3)ans+=f[0]*(f[0]-1)*(f[0]-2);
	if(f[0]>=2)for(int i=1;i<=f[0];i++)ans+=3*(f[0]-1);
	ans+=f[0];
	if(a%2==0){
		if(f[a/2]>=3)ans+=f[a/2]*(f[a/2]-1)*(f[a/2]-2);
		if(f[a/2]>=2)for(int i=1;i<=f[a/2];i++)ans+=3*(f[a/2]-1);
		ans+=f[a/2];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}


void solve()
{
  ll N, K;
  std::cin >> N >> K;

  std::vector<ll> va(N+1, 0LL);
  for (ll i = 1; i <= N; i++) {
    std::cin >> va[i];
  }

  std::map<ll, ll> mp;
  ll pos = 1LL;
  ll cnt = INF;
  ll start = INF;

  mp[1] = 0LL;
  ll i = 1;
  for (i = 1; i <= K; i++) {
    pos = va[pos];
    if (mp[pos] != 0) {
      start = pos;
      cnt = i - mp[pos];
      break;
    }
    mp[pos] = i;
  }

  if (i == K+1) {
    print(pos);
    return;
  }

  K -= mp[start];
  K %= cnt;

  for (i = 1; i <= K; i++) {
    pos = va[pos];
  }

  print(pos);
  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  solve();
  return 0;
}



Measured memory_bytes: 14744
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    ll tpx = A[0], tps = A[0], r = 1,ans = 0;
    rep(l,N){
        while(r < N){
            if((tpx^A[r]) != tps+A[r]) break;
            tpx = tpx^A[r];
            tps = tps+A[r];
            r++;
        }
        if(tpx == tps) ans += r-l;
        tpx ^= A[l];
        tps -= A[l];
    }
    pr(ans);
}


Measured memory_bytes: 1024