akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define int ll
template< class T >
struct CumulativeSum2D {
  vector< vector< T > > data;

  CumulativeSum2D(int W, int H) : data(W + 1, vector< int >(H + 1, 0)) {}

  void add(int x, int y, T z) {
    ++x, ++y;
    if(x >= data.size() || y >= data[0].size()) return;
    data[x][y] += z;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      for(int j = 1; j < data[i].size(); j++) {
        data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
      }
    }
  }

  T query(int sx, int sy, int gx, int gy) {
    return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
  }
};

using bs=bitset<30>;

bool solve(){
  ll n,m,q;cin>>n>>m>>q;
  CumulativeSum2D<ll>c(n,n);
  rep(i,m){
    ll l,r;cin>>l>>r;
    l--;r--;
    c.add(l,r,(ll)1);
  }
  c.build();
  rep(i,q){
    ll l,r;cin>>l>>r;l--;
    cout<<c.query(l,l,r,r)<<endl;
  }
  return false;
}


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

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

  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll now = 0;
  map<ll, ll> mp;
  mp[0]++;//
  rep(i, n) {
    now += a[i];
    mp[now]++;
  }

  ll ans = 0;
  for(auto elem : mp) {
    ans += elem.second*(elem.second-1)/2;
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    char a; cin >> a;
    int b = (a-'a');
    if(b >= 0) cout << "a\n";
    else cout << "A\n";
    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

priority_queue<ll> minpq;
priority_queue<ll> maxpq;
ll n;
ll a[300010];
ll sumf = 0, sumb = 0;
ll af[300010];
ll ab[300010];

int main() {
    cin >> n;
    for (ll i = 0; i < 3 * n; i++) {
        cin >> a[i];
        if (i <= n - 1) {
            minpq.push(-a[i]);
            sumf += a[i];
        }
        if (i >= 2 * n) {
            maxpq.push(a[i]);
            sumb += a[i];
        }
    }
    for (ll i = n - 1; i <= 2 * n - 1; i++) {
        af[i] = sumf;
        minpq.push(-a[i + 1]);
        sumf += a[i + 1];
        sumf -= -minpq.top();
        minpq.pop();
        
        ab[(3 * n - 1) - i] = sumb;
        maxpq.push(a[(3 * n - 1) - i - 1]);
        sumb += a[(3 * n - 1) - i - 1];
        sumb -= maxpq.top();
        maxpq.pop();
    }
    ll maxv = -99999999999999999;
    for (ll i = n - 1; i <= 2 * n - 1; i++) {
        //cout << af[i]  << " " << ab[i + 1] << endl;
        if (af[i] - ab[i + 1] > maxv) {
            maxv = af[i] - ab[i + 1];
        }
    }
    cout << maxv << endl;
}

Measured memory_bytes: 7668
#!/usr/bin/env python3


def compute(le, ri, d):
    return sum(x % d == 0 for x in range(le, ri + 1))


def main():
    le, ri, d = (int(z) for z in input().split())
    res = compute(le, ri, d)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, m := iScan(), iScan()
	p := PrimeFactors(m)
	d := make(map[int]int)
	for _, v := range p {
		d[v]++
	}
	f := make([]int, 1000000)
	inv := make([]int, 1000000)
	f[0] = 1
	inv[0] = 1
	for i := 1; i < 1000000; i++ {
		f[i] = f[i-1] * i % mod
		inv[i] = modinv(f[i], mod)
	}
	ans := 1
	for _, v := range d {
		ans *= f[v+n-1] * inv[v] % mod * inv[n-1] % mod
		ans %= mod
	}
	fmt.Println(ans)
}
func PrimeFactors(n int) (pfs []int) {
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}
	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}
	if n > 2 {
		pfs = append(pfs, n)
	}
	return
}
func modinv(a, m int) int {
	b, u, v := m, 1, 0
	for {
		t := a / b
		a -= t * b
		u -= t * v
		a, b, u, v = b, a, v, u
		if b == 0 {
			break
		}
	}
	u %= m
	if u < 0 {
		u += m
	}
	return u
}


Measured memory_bytes: 17996
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int a, b;
	cin >> a >> b;

	if (a % 3 == 0 ||
		b % 3 == 0 ||
		(a + b) % 3 == 0)
		cout << "Possible";
	else
		cout << "Impossible";

    cout << endl;
			

	return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int d,g;
  cin >> d >> g;
  vector<int> v(d),c(d);
  ll res = (1ll << 60);
  rep(i,d)cin >> v[i] >> c[i];
  for(int bit = 0;bit < (1 << d);bit++){
    vector<bool> use(d,0);
    ll val = 0,sum = 0;
    rep(i,d)if(bit >> i & 1)use[i] = true,val += 100*(i+1)*v[i]+c[i],sum += v[i];
    for(int i = d-1;i >= 0;i--){
      if(use[i])continue;
      if(val >= g)break;
      int k =  min((g-val)/(100*(i+1)),1ll*v[i]);
      sum += k;
      val += (100*(i+1))*k;
    }
    res = min(res,sum);
  }
  cout << res << endl;




  

  return 0;
}

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

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    int sump = 12000000;

    for(int bit = 0; bit < (1<<n); bit++){
        vector<int> sk(m, 0);
        int tmp = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                for(int j = 0; j < m; j++){
                    sk[j] += a[i][j];
                }
                tmp+=c[i];
            }
        }

        int k = 0;
        for(int i = 0; i < m; i++) if(sk[i]>= x) k++;

        if(k == m){
            sump = min(sump, tmp);
        }

    }

    if(sump == 12000000) cout << -1 << endl;
    else cout << sump << endl;

}

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

const int N = 3005;
int a,b,c,d,e,f;
bool w[N],s[N];

int main() {
    cin >> a >> b >> c >> d >> e >> f;
    w[0] = 1, s[0] = 1;
    for(int i=1;i<=f;i++) {
        if(i-(100*a) >= 0) w[i] |= w[i-(100*a)];
        if(i-(100*b) >= 0) w[i] |= w[i-(100*b)];
        
        if(i-c >= 0) s[i] |= s[i-c];
        if(i-d >= 0) s[i] |= s[i-d];
    }
    pair<int,int> ans = {-1,1}; //{water,sugar}
    for(int i=0;i<N;i++) { //water
        for(int j=0;j<N;j++) { //sugar
        	if(w[i] && s[j] && (i+j <= f) && (j <= e*(i/100))) {
        	    if((ans.second / (1.0*ans.first)) < (j / (1.0*i))) {
        	        ans = {i,j};
        	    }
        	}
        }
    }
    if(!(ans.first+ans.second)) cout << "0 0" << endl;
    else cout << ans.first+ans.second << " " << ans.second;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#define F first
#define S second
#define PI pair<int, int>
using namespace std;

int n, v[100005];
deque<PI> qu;
int main()
{
	PI t;
	cin >> n;
	qu.push_front(PI(1,1));
	while (!qu.empty()) {
		t = qu.front(); qu.pop_front();
		if (v[t.S]) continue;
		v[t.S] =1;
		if (t.S == 0) {
			cout << t.F;
			return 0;
		}
		qu.push_front(PI(t.F, (t.S * 10) % n));
		qu.push_back(PI(t.F+1, (t.S + 1) % n));
	}
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

// にぶたんVER

int main() {
    string s, t;
    cin >> s >> t;
    set<long> ids[26];
    long i=0, slen = s.size();
    for (auto c:s) {
        ids[c-'a'].insert(++i);
        ids[c-'a'].insert(i+slen);
    }
    long ans = 0, prev = 0;
    for (auto c:t) {
        if (ids[c-'a'].empty()) {
            cout << -1 << '\n';
            return 0;
        }
        long next = *ids[c-'a'].upper_bound(prev);
        if (next >= slen) ans += slen;
        prev = next % slen;
    }
    cout << ans + prev << '\n';
    return 0;
}

Measured memory_bytes: 9856
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n; cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    sort(ALL(a));
    ll x = a[n-1];
    ll y = -1;

    for(ll i=0;i<n-1;i++){
        ll tmp = a[i];
        if(a[i] >= x/2) tmp = x - a[i];
        if(y < tmp) y = a[i];
    }

    cout << x << " " << y << endl;
    return 0;
}



Measured memory_bytes: 3952
import sys
sys.setrecursionlimit(10 ** 6)


def main():
    N = int(input())

    abc = []
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        abc.append((a, b, c))

    Q, K = map(int, input().split())
    xy = []
    for _ in range(Q):
        x, y = map(int, input().split())
        xy.append((x, y))

    ans = ref_pypy(N, abc, Q, K, xy)
    print(*ans, sep="\n")


def ref_pypy(N, abc, Q, K, xy):
    """https://atcoder.jp/contests/abc070/submissions/5331379"""
    L = [-1 for i in range(N+1)]
    L[K] = 0
    n = [[] for i in range(N+1)]
    for a, b, c in abc:
        n[a].append([b, c])
        n[b].append([a, c])

    def dfs(x):
        for i in n[x]:
            if L[i[0]] == -1:
                L[i[0]] = L[x]+i[1]
                dfs(i[0])

    dfs(K)

    ans = []
    for x, y in xy:
        ans.append(L[x] + L[y])

    return ans


if __name__ == "__main__":
    main()


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

int main()
{
  int sx, sy, tx , ty;
  cin >> sx >> sy >> tx >> ty;
  int dx, dy;
  dx = tx - sx;
  dy = ty - sy;
  int i;
  for(i = 0; i < dy; i++)
  {
    cout << "U";
  }
  for(i = 0; i < dx; i++)
  {
    cout << "R";
  }
  for(i = 0; i < dy; i++)
  {
    cout << "D";
  }
  for(i = 0; i < dx; i++)
  {
    cout << "L";
  }
  cout << "L";
  for(i = 0; i < dy+1; i++)
  {
    cout << "U";
  }
  for(i = 0; i < dx+1; i++)
  {
    cout << "R";
  }
  cout << "D";
  cout << "R"; 
  for(i = 0; i < dy+1; i++)
  {
    cout << "D";
  }
  for(i = 0; i < dx+1; i++)
  {
    cout << "L";
  }
  cout << "U" << endl;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), B(N);
    vector<pair<ll, ll>> work;
    REP(i, N)
    {
        cin >> A[i] >> B[i];
        work.push_back(make_pair(A[i], B[i]));
    }
    sort(ALL(work));
    ll ans = 0;
    ll day = M - 1;
    priority_queue<ll> q;
    ll index = 0;
    while(day != -1)
    {
        while(true)
        {
            if (index < N && work[index].first + day <= M)
            {
                q.push(work[index].second);
                index++;
            }
            else
            {
                break;
            }
        }
        if (!q.empty())
        {
            ans += q.top();
            q.pop();
        }
        day--;
    }

    cout << ans << endl;
}


Measured memory_bytes: 5232
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
int ans=1,sum=1;
struct edge{
	int yi;
	int pii;
	int cnt;
	int L;
	int R;
}a[100001];
bool cmp(edge a,edge b){
	if(a.pii==b.pii)
		return a.yi<b.yi;
	return a.pii<b.pii;
}
bool cmp1(edge a,edge b){
	return a.cnt<b.cnt;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i].pii>>a[i].yi;
		a[i].cnt=i;
	}
	sort(a+1,a+m+1,cmp);
	a[1].L=a[1].pii,a[1].R=sum;
	sum++;

	for(int i=2;i<=m;i++){
		if(a[i].pii==a[i-1].pii){
			a[i].L=a[i].pii,a[i].R=sum;
			sum++;		
			}
		else{
			sum=1;
			a[i].L=a[i].pii;
			a[i].R=sum;
			sum++;
		}
	}
//	for(int i=1;i<=m;i++){
//	cout<<a[i].L<<" "<<a[i].R<<endl;
//	}
	sort(a+1,a+m+1,cmp1);

	for(int i=1;i<=m;i++){
		int flag=100000;
		while(a[i].L<flag) cout<<0,flag/=10;
		cout<<a[i].L;
		 flag=100000;
		while(a[i].R<flag) cout<<0,flag/=10;
		cout<<a[i].R;
		cout<<endl;
	}
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  vector<vector<int>> c(3, vector<int>(3));
  rep(i,3)rep(j,3) cin >> c.at(i).at(j);

  bool flag=true;
  vector<int> sa(4);
  sa.at(0) = c.at(0).at(0)-c.at(0).at(1);
  sa.at(1) = c.at(0).at(1)-c.at(0).at(2);
  sa.at(2) = c.at(0).at(0)-c.at(1).at(0);
  sa.at(3) = c.at(1).at(0)-c.at(2).at(0);

  rep(i,3){
    if(sa.at(0)!=(c.at(i).at(0)-c.at(i).at(1))) flag=false;
    if(sa.at(1)!=(c.at(i).at(1)-c.at(i).at(2))) flag=false;
    if(sa.at(2)!=(c.at(0).at(i)-c.at(1).at(i))) flag=false;
    if(sa.at(3)!=(c.at(1).at(i)-c.at(2).at(i))) flag=false;
  }

  if(flag) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n, m;
    cin >> n >> m;
    vector<int> num_list;
    vector<vector<int>> g(n, vector<int> (n, 0));
    for (int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a][b] = 1;
        g[b][a] = 1;
    }
    
    for (int i=0; i<n; i++){
        num_list.push_back(i);
    }
    
    int ans = 0;
    do{
        bool flag = true;
        if(num_list[0] != 0) flag = false;
        for (int i=0; i<n-1; i++){
            if (g[num_list[i]][num_list[i+1]] == 0) flag = false;
        }
        if(flag) ans++;
    }while(next_permutation(num_list.begin(), num_list.end()));
    
    cout << ans << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;

const int MOD = 1000000007; // 10^9 + 7
/****************************** START ******************************/
signed main(){
  int N;
  cin >> N;
  Vi x(N),y(N),z(N),w(N);
  rep(i,0,N){
    cin >> x.at(i) >> y.at(i);
    z.at(i) = x.at(i) + y.at(i);
    w.at(i) = x.at(i) - y.at(i);
  }
  int zmax,zmin,wmax,wmin;
  zmax = z.at(0);
  zmin = z.at(0);
  wmax = w.at(0);
  wmin = w.at(0);
  rep(i,1,N){
    if (z.at(i) > zmax){
      zmax = z.at(i);
    }
    if (z.at(i) < zmin){
      zmin = z.at(i);
    }
    if (w.at(i) > wmax){
      wmax = w.at(i);
    }
    if (w.at(i) < wmin){
      wmin = w.at(i);
    }
  }
  cout << max(zmax - zmin,wmax - wmin);
}

Measured memory_bytes: 9576
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main()
{
  int N;
  int f[105][10];
  int p[105][10];

  cin >> N;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 10; ++j) cin >> f[i][j];
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= 10; ++j) cin >> p[i][j];
  }

  auto slv = [&](bitset<10> bit) {
    i64 ans = 0;
    for (int i = 0; i < N; ++i) {

      int cnt = 0;
      for (int j = 0; j < 10; ++j) {
        if (f[i][j] && bit[j]) ++cnt;
      }

      ans += p[i][cnt];
    }
    return ans;
  };

  i64 ans = -LINF;
  for (int i = 1; i < (1 << 10); ++i) {
    chmax(ans, slv(i));
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int INF=99999999999999,inf=199999;
const long long int mod=1000000007;



long long int n,m,sum=0,now=0,up=0,down=0,res=0,dp[200005]={};


struct STRUCT{
	long long int a,b;
};
bool cmp(STRUCT A,STRUCT B){
	return A.a<B.a;
}
typedef pair<long long int,long long int> P;
priority_queue<long long int >pq;

STRUCT task[200005];
int main() {
    long long int count=0;
	
    map<long long int,long long int>mp;
	cout << fixed << setprecision(10);
    cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>task[i].a>>task[i].b;
	}
	sort(task,task+n,cmp);
	//cout<<n<<endl;
	for(int i=0;i<n;i++){
		//cout<<task[i].a<<" "<<task[i].b<<endl;
	}
	for(int i=1;i<=m;i++){
		for(int j=now;task[j].a==i&&j<n;j++){
			pq.push(task[j].b);
			//cout<<j<<" ";
			now=j+1;
		}
		//cout<<endl;
		if(pq.empty()){continue;}
		else{
			res+=pq.top();
			pq.pop();
			//cout<<res<<endl;
		}

	}
	cout<<res;
} 


Measured memory_bytes: 4984
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

vector<vector<pair<long, long> > > vv;
long a[100005];
long def[100005];

bool dfs( long i, long value ) {
    if( def[i] == 0 ) {
        a[i] = value;
        def[i] = 1;

        long k;
        for(k=0; k<(long)vv[i].size(); k++) {
            bool tmp = dfs(vv[i][k].first, a[i]+vv[i][k].second);
            if( !tmp ) {
                return false;
            }
        }
    }
    else {
        if(a[i] != value)
            return false;
    }
    return true;
}

int main(int argc, char* argv[])
{
    long n, m;
    scanf("%ld%ld", &n, &m);

    vv.resize(n);
    long i;
    for(i=0; i<m; i++) {
        long ll, rr, dd;
        scanf("%ld%ld%ld", &ll, &rr, &dd);
        vv[ll-1].push_back( make_pair(rr-1, dd));
        vv[rr-1].push_back( make_pair(ll-1, -dd));
    }

    for(i=0; i<n; i++) {
        if(!def[i]) {
            if( !dfs(i, 0) ) {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");

    return 0;
}


Measured memory_bytes: 16256
<?php
    fscanf(STDIN,"%d%d",$A,$B);
    
    // echo 1250*8/100;
    //1 ≤ A ≤ B ≤ 100なので1010円以上はない
    for($N=1;$N<1010;$N++){
        if(intval(floor($N*8/100)) == $A){
            if(intval(floor($N*10/100)) == $B){
                echo $N;
                exit;
            }
        }
    }
    echo "-1";

?>

Measured memory_bytes: 16260
#include <iostream>
#include <set>
#include <cassert>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        if (i & 1) {
            const int l = n / 2 - i / 2;
            std::cout << l << ' ' << l + i << '\n';
        } else {
            const int l = i / 2;
            std::cout << l << ' ' << l + n - i << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 3672
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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


struct edge{
    int to, cost;
    edge(int To, int Cost): to(To), cost(Cost){};
};

void initialFromGraphList_Cost(std::vector<std::vector<edge>>& G, std::vector<std::vector<long long>>& d){
    int V(G.size());
    d.resize(V);
    for(int i(0); i < V; ++i){
        d[i].resize(V, LINF);
        d[i][i] = 0;
    }
    for(int i(0); i < V; ++i){
        for(auto& e: G[i])
            d[i][e.to] = e.cost;
    }
}

void warshallFloyd(std::vector<std::vector<long long>>& d){
    int V(d.size());
    for(int k(0); k < V; ++k)
        for(int i(0); i < V; ++i)
            for(int j(0); j < V; ++j)
                chmin(d[i][j], d[i][k] + d[k][j]);
}

bool find_negative_loop(std::vector<std::vector<long long>>& d){
    //warshallFloyd()をしてから
    int V(d.size());
    for(int i(0); i < V; ++i)
        if(d[i][i] < 0) return true;
    return false;
}

int main(){
    int V, E; std::cin >> V >> E;
    std::vector<std::vector<edge>> G(V);
    {
        int s, t, d; 
        for(int i(0); i < E; ++i){
            std::cin >> s >> t >> d;
            G[s].emplace_back(t, d);
        }
    }
    std::vector<std::vector<long long>> d;
    initialFromGraphList_Cost(G, d);
    warshallFloyd(d);
    if(find_negative_loop(d)){
        std::cout << "NEGATIVE CYCLE" << std::endl;
        return 0;
    }
    for(int i(0); i < V; ++i){
        for(int j(0); j < V; ++j){
            if(j) std::cout << " ";
            if(d[i][j] > 1'980'000'000) std::cout << "INF";
            else std::cout << d[i][j];
        }
        std::cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 3204
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[3005][3005][5];
ll varr[3005][3005];

int main() {
  ll R, C, K;
  cin>>R>>C>>K;
  ll r, c, v;
  for(int i=0;i<K;++i) {
    cin>>r>>c>>v;
    r--;
    c--;
    varr[r][c] = v;
  }
  if(varr[0][0]>0) {
    DP[0][0][1] = varr[0][0];
  }
  for(int j=1;j<C;++j) {
    if(varr[0][j]>0) {
      DP[0][j][1] = max(DP[0][j-1][1], varr[0][j]);
      if(DP[0][j-1][1]>0) {
        DP[0][j][2] = max(DP[0][j-1][2], DP[0][j-1][1]+varr[0][j]);
      }
      if(DP[0][j-1][2]>0) {
        DP[0][j][3] = max(DP[0][j-1][3], DP[0][j-1][2]+varr[0][j]);
      }
    }
    else {
      DP[0][j][1] = max(DP[0][j][1], DP[0][j-1][1]);
      DP[0][j][2] = max(DP[0][j][2], DP[0][j-1][2]);
      DP[0][j][3] = max(DP[0][j][3], DP[0][j-1][3]);
    }
  }
  for(int i=1;i<R;++i) {
    DP[i][0][0] = max(DP[i-1][0][0], max(DP[i-1][0][1], max(DP[i-1][0][2], DP[i-1][0][3])));
    if(varr[i][0]>0) DP[i][0][1] = DP[i][0][0] + varr[i][0];
  }
  for(int i=1;i<R;++i) {
    for(int j=1;j<C;++j) {
      if(varr[i][j]>0) {
        DP[i][j][0] = max(DP[i][j-1][0], max(DP[i][j][0], max(DP[i-1][j][0], max(DP[i-1][j][1], max(DP[i-1][j][2], DP[i-1][j][3])))));
        DP[i][j][1] = max(DP[i][j-1][1], max(DP[i][j][0], max(DP[i-1][j][0], max(DP[i-1][j][1], max(DP[i-1][j][2], DP[i-1][j][3]))))+varr[i][j]);
        DP[i][j][1] = max(DP[i][j-1][1], DP[i][j][1]);
        DP[i][j][2] = max(DP[i][j-1][2], DP[i][j][2]);
        DP[i][j][3] = max(DP[i][j-1][3], DP[i][j][3]);
        if(DP[i][j-1][0]>0) {
          DP[i][j][1] = max(DP[i][j][1], DP[i][j-1][0]+varr[i][j]);
        }
        if(DP[i][j-1][1]>0) {
          DP[i][j][2] = max(DP[i][j][2], DP[i][j-1][1]+varr[i][j]);
        }
        if(DP[i][j-1][2]>0) {
          DP[i][j][3] = max(DP[i][j][3], DP[i][j-1][2]+varr[i][j]);
        }
      }
      else {
        DP[i][j][0] = max(DP[i][j-1][0], max(DP[i][j][0], max(DP[i-1][j][0], max(DP[i-1][j][1], max(DP[i-1][j][2], DP[i-1][j][3])))));
        DP[i][j][1] = max(DP[i][j-1][1], DP[i][j][1]);
        DP[i][j][2] = max(DP[i][j-1][2], DP[i][j][2]);
        DP[i][j][3] = max(DP[i][j-1][3], DP[i][j][3]);
      }
    }
  }
  /**
  for(int i=0;i<R;++i) {
    for(int j=0;j<C;++j) {
      for(int k=0;k<=3;++k) {
        cout<<DP[i][j][k]<<" ";
      }
      cout<<" ";
    }
    cout<<endl;
  }
  **/
  cout<<max(DP[R-1][C-1][0], max(DP[R-1][C-1][1], max(DP[R-1][C-1][2], DP[R-1][C-1][3])))<<endl;
}


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

int main()
{
  int a[3],tmp,i,j;

  cin>>a[0]>>a[1]>>a[2];
  for(j=0;j<2;j++)
    for(i=0;i<2;i++)
      if(a[i]>a[i+1]){
        tmp=a[i]; a[i]=a[i+1]; a[i+1]=tmp;
  }
  cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
}


Measured memory_bytes: 1164
using System;

public class Hello
{
    public static void Main()
    {
        var x = int.Parse(Console.ReadLine().Trim());
        var a = int.Parse(Console.ReadLine().Trim());
        var b = int.Parse(Console.ReadLine().Trim());
        var w1 = x - a;
        var w2 = w1 - (w1 / b) * b;
        Console.WriteLine(w2);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll a, pos = 0;
    for(int i = 0; i < 5; i++){
        cin >> a;
        if(a == 0) pos = i + 1;
    }
    cout << pos << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e9+1

void d_m_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input_dp.txt", "r", stdin);
	freopen("output_dp.txt", "w", stdout);
#endif
}

int knapsack2(vector<int> &weight, vector<int> &value, int W, int n)
{
	int maxVal = n * 1000;
	int dp[n + 1][maxVal + 1];

	for (int i = 0; i <= maxVal; i++)
		dp[1][i] = inf;
	dp[1][value[1]] = weight[1];
	dp[1][0] = 0;

	for (int i = 2; i <= n; i++)
	{
		for (int val = 1; val <= maxVal; val++)
		{
			dp[i][val] = dp[i - 1][val];
			if (val - value[i] >= 0)
				dp[i][val] = min(dp[i][val], weight[i] + dp[i - 1][val - value[i]]);
		}
	}

	int ans = INT_MIN;
	for (int x = 0; x <= maxVal; x++)
	{
		if (dp[n][x] <= W)
			ans = x;
	}

	return ans;
}

int32_t main()
{
	d_m_c();

	int n, W;
	cin >> n >> W;

	vector<int> w(n + 1), v(n + 1);

	for (int i = 1; i <= n; i++)
	{
		cin >> w[i] >> v[i];
	}

	cout << knapsack2(w, v, W, n);


	return 0;
}

Measured memory_bytes: 81740
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	char s[1020];
	char c[] = "keyence";
	cin >> s;
	int j = 0, k = 0;

	for (j = 0; s[j] != '\0'; j++);

	int i;
	for (i = 0;i<7; i++) {
		if (s[i] != c[i])break;
	}
	
	for (k = 0; k < 7; k++) {
		if (s[j-k-1] != c[7-k-1])break;
	}
	if (i == 7||k==7||i+k>=7)cout << "YES";
	else cout << "NO";

}


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

int main() {
    string str, order, p;
    int q,a,b;
    
    cin >> str >> q;
    
    for(int i=0;i<q;i++){
        cin >> order;
        
        if(order == "print"){
            cin >> a >> b;
            cout << str.substr(a,b-a+1) << endl;
        }else if(order == "reverse"){
            cin >> a >> b;
            string buf = str.substr(a,b-a+1);
            reverse(buf.begin(), buf.end());
            str = str.substr(0,a) + buf + str.substr(b+1,str.length()-a-1);  
        }else if(order == "replace"){
            cin >> a >> b >> p;
            str = str.substr(0,a) + p + str.substr(b+1,str.length()-a-1); 
        }
    }
}


Measured memory_bytes: 3216
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;

int main(){
    int n;
    while(scanf("%d",&n),n){
        map<string, int> data;
        rep(i,n){
            string str;
            int val;
            cin >> str >> val;
            data[str] = val;
        } 
        int m;
        scanf("%d",&m);
        rep(i,m){
            string o;
            cin >> o;
            int k;
            scanf("%d",&k);
            int sum = 0;
            rep(i,k){
                string from;
                cin >> from;
                sum += data[from];
            }
            data[o] = min(data[o],sum);
        }
        string want;
        cin >> want;
        cout << data[want] << endl;
    }
    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<math.h>
#include<vector>
using namespace std;
int N,D,X;
int main(){
    cin>>N>>D>>X;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int x[N];
    for(int i=0;i<N;i++){
        x[i]=0;
        int day1=0;
        int day2=0;
        while(day2<=D){
            day2=day1*A[i]+1;
            day1++;
            x[i]++;
        }
        x[i]--;
    }
    int sum=0;
    for(int i=0;i<N;i++){
        sum+=x[i];
    }
    cout<<X+sum<<"\n";
    return 0;


}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, int[] A)
        {
            int x = 0;
            long sum = 0;
            for (int i = N - 1; i >= 0; --i)
            {
                if (A[i] > i) { return -1; }
                if (A[i] < x) { return -1; }
                if (A[i] > x)
                {
                    x = A[i];
                    sum += A[i];
                }
                x = Math.Max(x - 1, 0);
            }
            return sum;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] A = new int[N];
            for (int i = 0; i < N; ++i) { A[i] = ReadInt(); }
            Console.WriteLine(Solve(N, A));
        }
    }
}


Measured memory_bytes: 17884
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var A1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var A2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int top = A1[0];
        int bottom = A2.Sum();
        int max = top + bottom;
        for (int i = 1; i < N; i++)
        {
            top += A1[i];
            bottom -= A2[i - 1];
            max = Math.Max(max, top + bottom);
        }
        Console.WriteLine(max);
    }
}

Measured memory_bytes: 13396
def main():
    n, x, y = [int(i) for i in input().split()]
    adj = {i: [i+1, i-1] for i in range(1, n-1)}
    adj[0] = [1]
    adj[n-1] = [n-2]
    adj[x-1].append(y-1)
    adj[y-1].append(x-1)
    res = [0] * n
    for i in range(n):
        memo = [-1] * n
        pos = i
        cand = [pos]
        memo[pos] = 0
        while len(cand) > 0:
            pos = cand.pop(0)
            for nx in adj[pos]:
                if memo[nx] != -1:
                    continue
                memo[nx] = memo[pos] + 1
                res[memo[nx]] += 1
                cand.append(nx)
    for r in res[1:]:
        print(int(r/2))

if __name__ == '__main__':
    main()



Measured memory_bytes: 46684
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  vector<P> sub(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,n){
    sub[i].first=a[i]-b[i];
    sub[i].second=i;
  }
  sort(ALL(sub));
  int j=n;
  rep(i,n){
    if(sub[i].first>=0){
      j=i;
      break;
    }
  }
  if(j==0){
    cout<<0<<endl;
    return 0;
  }
  if(j==n){
    cout<<-1<<endl;
  }
  vector<int> pos(n-j,0);
  vector<int> neg(j,0);
  pos[n-j-1]=sub[n-1].first;
  neg[0]=sub[0].first;
  rep1(i,j-1){
    neg[i]=neg[i-1]+sub[i].first;
  }
  int t=neg[j-1]*(-1);
  int res=n;
  for(int i=n-2;i>=j;--i){
    pos[i-j]=pos[i-j+1]+sub[i].first;
    if(pos[i-j+1]>=t){
      res=j+n-1-i;
      break;
    }
  }
  if(pos[0]<t&&res==n){
    res=-1;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 4096
package main

import "fmt"

func main() {
	var x, a, b int
	fmt.Scanf("%d %d %d", &x, &a, &b)
	var ans = "dangerous"
	switch {
	case b <= a:
		ans = "delicious"
		break
	case b <= a+x:
		ans = "safe"
		break
	}
	fmt.Println(ans)
}


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

#define LL long long
#define hell 1000000007
#define PI acos(-1.0)



int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << showpoint;
cout << setprecision(11);

char c;cin>>c;
if(c>='A' && c<='Z')
{
    cout<<"A";
}
else
{
    cout<<"a";
}



return 0;
} 

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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll A, B, K;

    cin >> A >> B;
    
    K = (A + B) / 2;

    cout << (abs(A - K) == abs(B - K) ? to_string(K) : "IMPOSSIBLE") << endl;

    return 0;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 2e5+3;
int g[T];
vector<int> cycle[T];
ll id[T];
int pai[T], peso[T], low[T], d[T], st[T];
bool vis[T];
int t, sz;

void init() {
    for(int i = 0; i < T; i++) pai[i] = i, peso[i] = 1;
}

int find(int x) {
    return (x == pai[x]? x : pai[x] = find(pai[x]));
}

void join(int x, int y) {
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(peso[x] < peso[y]) swap(x,y);
    pai[y] = x;
    peso[x] += peso[y];
}

void dfs(int u) {
    st[sz++] = u;
    d[u] = low[u] = ++t;
    int v = g[u];

    if(!d[v]) {
        dfs(v);
        low[u] = min(low[u],low[v]);
    } else low[u] = min(low[u],d[v]);

    if(low[u] >= d[u]) {
        int a;
        do {
            a = st[--sz];
            join(a,u);
            d[a] = INF;
        } while(a != u);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    init();
    for(int i = 1; i <= n; i++) cin >> g[i];
    for(int i = 1; i <= n; i++) if(!d[i]) dfs(i);

    for(int i = 1; i <= n; i++) {
        if(vis[i]) continue;
        vis[i] = 1;
        if(peso[find(i)] > 1) {
            int a = i;
            do {
                id[a] = cycle[find(i)].size();
                cycle[find(i)].pb(a);
                a = g[a];
                vis[a] = 1;
            } while(a != i);
        }
    }

    int at = 1;
    while(k) {
        if(peso[find(at)] > 1) {
            ll x = (k+id[at])%((ll)cycle[find(at)].size());
            cout << cycle[find(at)][x] << endl;
            return 0;
        }
        if(at == g[at]) break;
        at = g[at];
        k--;
    }

    cout << at << endl;

    return 0;
}



Measured memory_bytes: 26848
#include <bits/stdc++.h>
using namespace std;
int read()
{
    int d = 0, w = 1;
    char ch = getchar();
    while (ch != '-' && (ch < '0' || ch > '9'))
        ch = getchar();
    if (ch == '-')
        w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9')
        d = d * 10 + ch - '0', ch = getchar();
    return d * w;
}
void write_(int x)
{
    if (x < 0)
        x = -x, putchar('-');
    if (x > 9)
        write_(x / 10);
    putchar(x % 10 + '0');
}
void writeln(int x)
{
    write_(x);
    putchar('\n');
}
void writesp(int x)
{
    write_(x);
    putchar(' ');
}
int vis[111000];
int main()
{
#ifdef __clang__
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    using P = pair<int, int>;
    int K = read();
    deque<P> de;
    de.push_back({1, 1});
    memset(vis, 0x3f, sizeof(vis));
    while(1)
    {
        P p = de.back();
        de.pop_back();
        if(p.second >= vis[p.first])
            continue;
        vis[p.first] = p.second;
        if(p.first == 0)
        {
            writeln(p.second);
            return 0;
        }
        de.push_back({p.first * 10 % K, p.second});
        de.push_front({(p.first + 1) % K, p.second + 1});
    }
    return 0;
}

Measured memory_bytes: 1536
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum_a = sum(a)
for i in range(n):
    if b[i] >= a[i]:
        a[i+1] -= (b[i] - a[i])
        a[i] = 0
        if a[i+1] < 0:
            a[i+1] = 0
    else:
        a[i] -= b[i]

print(sum_a - sum(a))


Measured memory_bytes: 82020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const* argv[])
{
	int a, b;
	char op;
	while(1) {
		scanf("%d %c %d", &a, &op, &b);
		if ( op != '?') {
			if (op == '+') printf("%d\n", a + b);
			else if (op == '-') printf("%d\n", a - b);
			else if (op == '*') printf("%d\n", a * b);
			else if (op == '/') printf("%d\n", a / b);
		} else {
			break;
		}
	}
}




Measured memory_bytes: 2760
#include<stdio.h>
#include<string.h>
int main(void){
   int N,X,m[1000],kosu,min=1000;
   scanf("%d %d",&N,&X);
   for(int i=0;i<N;i++){
      scanf("%d",&m[i]);
      X-=m[i];
      kosu++;
      if(min>m[i]){
         min=m[i];
      }
   }
   kosu+=X/min;
   printf("%d",kosu);


   return 0;
}

Measured memory_bytes: 128
import bisect
import sys,io
import math
from collections import deque
from heapq import heappush, heappop

input = sys.stdin.buffer.readline

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As,mod=DIV):
    s = 0
    for a in As:
        s += a
        if mod !=None:
            s = s%mod
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N = iRaw()
    As = isRaw()
    sumAs = list(cumsum(As,DIV))
    ans = 0
    for aidx in range(len(As)-1):
        ans = (ans+As[aidx]*(sumAs[-1]-sumAs[aidx]))%DIV
    print(ans)

main()


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

using namespace std;

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

    int a, b;
    cin >> a >> b;
    if (a <= 9 && b <= 9) {
        cout << a * b;
    }
    else {
        cout << -1;
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong(),b=sc.nextLong(),k=sc.nextLong();
        System.out.println(Math.max(a-k,0)+" "+Math.max(Math.min(b,b-(k-a)),0));
    }
}


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

#define int long long int

const int INF=1e9+5;

#undef int
int main()
{
	
	int n;
	scanf("%d",&n);
	vector<int> dp(n+5,INF);
	vector<int> arr(n,0);
	dp[0]=0;
	
	for(int i=0;i<n;i++)
		scanf("%d",&arr[i]);
	
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=2;j++)
		{
			if(i+j<n)
				dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i+j]-arr[i]));
		}
	}
	
	printf("%d",dp[n-1]);
	
	
}

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;

#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int a, b;
	while (cin >> a >> b) {
		int ans = (b-1) / (a-1);
		if((b-1) % (a-1)) ans++;
		cout << ans << '\n';
	}
}



Measured memory_bytes: 256