akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

// int getelement(char H[],char c)
// {
//     int i, j;
//     for (i = 0;i<)
// }

int main()
{
    int i, j, k,n,h[100000],H[100000],max=0,MAX=0;
    scanf("%d", &n);
    scanf("%d", &h[0]);
    for (i = 1; i < n;i++)
    {
        scanf("%d", &h[i]);
        //printf("qwert\n");
        if(h[i]<=h[i-1])
            H[i - 1] = 1;
        else
            H[i - 1] = 0;
    }
    // for (i = 0; i < n-1; i++)
    // {
    //     printf("%d", H[i]);
    // }
    for (i = 0; i < n - 1;i++)
    {

        if (H[i]==1)
        {
            MAX++;
            j = 1;
            while (H[i+j] == 1)
            {
                MAX++;
                j++;
            }
            if(MAX>max)
                max = MAX;
            i += j;
            MAX = 0;
            continue;
        }    
    }
    printf("%d", max);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
        
        
int main() {
        int a,b,m,amin = INF,bmin =INF;
        cin >> a >>b >> m;
        vector<int> A(a);
        vector<int> B(b);
        rep(i,a) cin >> A.at(i);
        rep(i,b) cin >>B.at(i);
        
        vector<int> x(m),y(m),c(m);
        rep(i,m){
                 int p,q,r;
                cin >> p >> q >>r;
                --p;--q;
                x.at(i) = p;
                y.at(i) = q;
                c.at(i) = r;
        }
        
        
        rep(i,a) amin= min(amin,A.at(i));
        rep(i,b) bmin = min(bmin,B.at(i));
        int ans = amin + bmin;
        
        rep(i,m){
                 ans = min(ans,A.at(x.at(i)) + B.at(y.at(i)) - c.at(i));
        }
        
        cout << ans <<endl;
                 
        
        
        return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define MAXN 4096

using namespace std;

int n, m, a, b, c, f[MAXN];

int main() {
	scanf("%d%d", &n, &m); int S = 1 << n; f[0] = 0;
	for(register int i = 1; i < S; ++i) f[i] = 0x3f3f3f3f;
	while(m--) {
		scanf("%d%d", &a, &b); int t = 0;
		while(b--) scanf("%d", &c), t |= (1 << --c);
		for(register int i = 0; i < S; ++i) if(f[i] != 0x3f3f3f3f) f[i | t] = min(f[i | t], f[i] + a);
	}
	printf("%d\n", f[S - 1] == 0x3f3f3f3f ? -1 : f[S - 1]);
	return 0;
}

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

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;

	bool ok = false;
	for (int i = s.size() - t.size(); i >= 0; --i) {
		if ((s[i] == t[0]) || (s[i] == '?')) {
			bool ok2 = true;
			for (int j = 0; j < t.size(); ++j) {
				if (s[i + j] == '?') { continue; }
				if (s[i + j] != t[j]) { ok2 = false; }
			}
			
			if (ok2) {
				for (int j = 0; j < t.size(); ++j) {
					s[i + j] = t[j];
				}
				ok = true;
				break;
			}
		}
	}

	if (ok) {
		for (int i = 0; i < s.size(); ++i) {
			if (s[i] == '?') { s[i] = 'a'; }
		}
		cout << s << endl;
	} else {
		cout << "UNRESTORABLE" << endl;
	}

	return 0;
}


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

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

    long long a,b;
    long long ans=0;
    for(long long i=1;i<=N;i++){
        ans+=i*(N+1-i);
    }
    for(int i=0;i<N-1;i++){
        cin>>a>>b;
        if(a>b){
            ans-=b*(N+1-a);
        }else{
            ans-=a*(N+1-b);
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main() {
	char a[102];
	char b[102];
	int c;

	scanf("%s", a);
	fflush(stdin);
	scanf("%s", b);
	fflush(stdin);
	c = strlen(a);
	for (int i = 0;i < c;i++) {
		if (b[i] == NULL) {
			printf("%c", a[i]);
		}
		else {
			printf("%c%c", a[i], b[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 128
'use strict'
function Main(input) {
    input = input.split("\n")
    const lineOne = input[0].split(' ').map(str => parseInt(str, 10))
    const S = input[1]
    const K = lineOne[1] - 1
 
    let strings = S.split('')
    strings[K] = strings[K].toLowerCase()
    const result = strings.join('')
    
    console.log(result)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
const int N=308;
int n;
int dis[N][N];
int nume;
struct edge{
	int fro,to,f;
}e[N*N];
inline void add_edge(int x,int y,int z)
{
	e[++nume]=(edge){x,y,z};
}
inline bool cmp(const edge &a,const edge &b)
{
	return a.f<b.f;
}
bool vis[N][N];
LL ans;
int main()
{
	n=read();
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			dis[i][j]=read();
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			add_edge(i,j,dis[i][j]);
		}
	}
	sort(e+1,e+nume+1,cmp);
	for(int i=1;i<=nume;++i){
		int x=e[i].fro,y=e[i].to;
		for(int k=1;k<=n;++k){
			if(vis[x][k]&&vis[y][k]){
				if(dis[x][k]+dis[y][k]<dis[x][y]){
					puts("-1");
					return 0;
				}	
				if(dis[x][k]+dis[y][k]==dis[x][y]){
					break;
				}
			}
			if(k==n){
				ans+=dis[x][y];
			}
		}
		vis[x][y]=vis[y][x]=1;
	}
	printf("%lld",ans);
	return 0;
}

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

int main() {
  int n,m,d,max;
  max = 0;
  string c;
  cin >> n;
  vector<string> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  cin >> m;
  vector<string> b(m);
  for(int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  for(int i = 0; i < n; i++) {
    d = 0;
    c = a.at(i);
    for(int j = 0; j < n; j++) {
      if(a.at(j) == c) {
        d++;
      }
    }
    for(int t = 0; t < m; t++) {
      if(b.at(t) == c) {
        d--;
      }
    }
    if(max < d) {
      max = d;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define print(x) cout<<x;
#define printl(x) cout<<x<<endl;
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
using namespace std;
typedef long long int ll;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<int>nums;
    int cnt=0,srch=1;;
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        if(tmp==srch)
            srch++;
        else
            cnt++;
    }
    if(cnt<n)
    cout<<cnt;
    else
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
/*EX2_3
	L40S38*/

#include <stdio.h>

int main() {
  int N,A ;
  scanf("%d\n",&N);//N*Nのマス目
  scanf("%d",&A);//Aマスを白く塗る
  printf("%d",N*N-A); 
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};
const long long INF = 1LL << 60;

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

int main(){
    int n,k; 
    cin >> n >> k;
    vector<bool> okashi(n,false);
    for(int i=0;i<k;i++){
        int d; cin >> d;
        vector<int> a(d);
        rep(j,d){ 
            cin >> a[j];
            a[j]--;
        }
        rep(k,d){
            okashi[a[k]] = true;
        }
    }
    int ans = 0;
    rep(i,n){
        if(okashi[i] == false) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int h, w;
    ostringstream os;
    while(1){
        cin >> h >> w;
        if (h + w == 0)
            break;
        REP(i, h){
            REP(j, w) {
                if ((i+j) % 2 == 0)
                    os << "#";
                else
                    os << ".";
            }
            os << endl;
        }
        os << endl;
    }
    cout << os.str();
    return 0;
}

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

int main()
{
    int N;
    string S;
    
    cin >> N;
    cin >> S;
    
    int L = S.length();
    int count=0;
    
    for(int i=1; i<L; i++){
        if(S[i] == S[i-1]){
            count++;
        }
    }

    cout << L - count << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
from collections import deque

input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))

visited = set()
q = deque()
q.append(1)

root = []
while q:
    pos = q.pop()
    if pos in visited:
        start = root.index(pos)
        s_len = len(root[:start])
        l_len = len(root[start:])
        break
    visited.add(pos)
    root.append(pos)

    q.append(A[pos-1])

if K <= s_len:
    print(root[K])
else:
    r = (K - s_len) % l_len
    print(root[start+r])

Measured memory_bytes: 32688
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class BVotingJudges {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n, v, p;
        ll m;
        in >> n >> m >> v >> p;
        vector<ll> a(n);
        rep(i, n){
            in >> a[i];
        }

        sort(all(a));

        int left = -1, right = n-p;
        while(left + 1 < right){
            int mid = left + (right - left) / 2;
            if(a[mid] + m < a[n - p]) left = mid;
            else if(v - 1 - mid < p) right = mid;
            else {
                int over = v - 1 - mid - (p-1);
                ll cnt = 0;
                reps(j, mid+1, n-p){
                    cnt += a[mid] + m - a[j];
                }
                if(over * m <= cnt) right = mid;
                else left = mid;
            }
        }

        out << n - right << endl;
	}
};


int main() {
	BVotingJudges solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

namespace B___Theater
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ln = Enumerable.Range(1, N).Select(x => Console.ReadLine()).ToArray();
            var cnt = 0;

            foreach (var l in Ln)
                cnt += int.Parse(l.Split()[1]) - int.Parse(l.Split()[0]) + 1;

            Console.WriteLine(cnt);
        }
    }
}


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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        k: i32,
        a: [i32; n],
    }
    puts!("{}\n", a.into_iter().filter(|&a| a >= k).count());
}

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


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int MAX = 26;
vector <int> v[MAX];
int freq[MAX];
int search(int ind, int x)
{
	int l = lower_bound(v[ind].begin(), v[ind].end(), x) - v[ind].begin();
	return (l < v[ind].size() ? v[ind][l] : INT_MAX);
}
int main()
{
	boost;
	string s, t;
	int prev, n, i;
	bool poss = true;
	ll ans = 0;
	cin >> s >> t;
	n = s.length();
	fo(i, 0, s.length())
	{
		v[s[i] - 'a'].pb(i);
		++freq[s[i] - 'a'];
	}
	fo(i, 0, t.length())
	freq[t[i] - 'a'] == 0 ? poss = false : 0;
	if(!poss)
	cout << -1;
	else
	{
		prev = -1;
		fo(i, 0, t.length())
		{
			prev = search(t[i] - 'a', prev + 1);
			if(prev == INT_MAX)
			{
				ans += n;
				prev = search(t[i] - 'a', 0);
			}
		}
		cout << ans + 1ll * (prev + 1);
	
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
  	int  x;
  	cin >> x;
  	string a[x];
  	for(int i = 0; i < x; ++i)
  	{
  		cin >> a[i];
  		if(i)
  		{
  			int n = a[i-1].length();
  			if(a[i][0] != a[i - 1][n-1])
  				{	
  				cout << "No";
  				return 0;
  				}
  		}
  		for(int l = 0; l < i; l++)
  		{
  			if(a[i] == a[l])
  			{	
  				cout << "No";
  				return 0;
  			}
  		}
  	}

  	cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;

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

template <typename T>
std::ostream &operator<<(std::ostream &ostr, const std::vector<T> &v) {
  for (const auto &i : v | boost::adaptors::indexed())
    ostr << (i.index() > 0 ? " " : "") << i.value();
  return ostr;
}

using P = pair<int, int>;
const int INF = 1e9;
const int NX[4] = {-1, 1, 0, 0};
const int NY[4] = {0, 0, -1, 1};

int h, w;
vector<vector<bool>> chizu;
vector<vector<int>> vvi;
queue<P> qp;
int result = 0;

inline void input() {
  cin >> h >> w;
  char c;

  rep(i, h) {
    vector<bool> vb(w, false);
    vector<int> vi(w, INF);
    rep(j, w) {
      cin >> c;
      if(c=='#') {
        qp.push(P(i, j));
        vi.at(j) = 0;
      }
    }
    chizu.push_back(vb);
    vvi.push_back(vi);
  }
}

inline void bfs() {
  P p;
  int dx, dy, re;

  while(!qp.empty()) {
    p = qp.front();qp.pop();

    result = max(result, vvi.at(p.first).at(p.second));

    rep(i, 4) {
      dx = p.first  + NX[i];
      dy = p.second + NY[i];
      re = vvi.at(p.first).at(p.second) + 1;

      if(!(0<=dx && dx<h && 0<=dy && dy<w)) continue;
      if(chizu.at(dx).at(dy)) continue;
      if(vvi.at(dx).at(dy) <= re) continue;

      qp.push(P(dx, dy));
      vvi.at(dx).at(dy) = re;
    }
  }
}

inline void Main() {
  // code
  input();
  bfs();
  cout << result << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 12560
X = int(input())
Num = 1
Check = "NG"

while Check == "NG":
    A_list = [i for i in range(Num)]
    B_list = [i for i in range(Num)]
    for i in range(Num):
        for j in range(Num):
            A5 = A_list[i] ** 5
            B5 = B_list[j] ** 5
            if A5 + B5 == X or A5 - B5 == X or -A5 + B5 == X:
                Check = "OK"
                break
        if Check == "OK":
            break
    if Check == "OK":
        break
    Num += 1
if A5 + B5 == X:
    print("{} -{}".format(i, j))
elif A5 - B5 == X:
    print("{} {}".format(i, j))
elif -A5 + B5 == X:
    print("-{} -{}".format(i, j))

Measured memory_bytes: 9076
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer>[] adjacents = new List[N];
        for (int i = 0; i < N; i++) {
            adjacents[i] = new ArrayList<>();
        }
        for (int i = 0; i < N - 1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            adjacents[a].add(b);
            adjacents[b].add(a);
        }
        int[] fromFennec = new int[N];
        Arrays.fill(fromFennec, N);
        Stack<Integer> stk = new Stack<>();
        fromFennec[0] = 0;
        stk.push(0);
        while (!stk.empty()) {
            int start = stk.pop();
            int dist = fromFennec[start] + 1;
            for (int i : adjacents[start]) {
                if (fromFennec[i] == N) {
                    fromFennec[i] = dist;
                    stk.push(i);
                }
            }
        }
        int[] fromSnuke = new int[N];
        Arrays.fill(fromSnuke, N);
        fromSnuke[N - 1] = 0;
        stk.push(N - 1);
        while (!stk.empty()) {
            int start = stk.pop();
            int dist = fromSnuke[start] + 1;
            for (int i : adjacents[start]) {
                if (fromSnuke[i] == N) {
                    fromSnuke[i] = dist;
                    stk.push(i);
                }
            }
        }
        int sum = 0;
        for (int i = 0; i < N; i++) {
            if (fromFennec[i] > fromSnuke[i]) {
                sum++;
            }
        }
        if (sum >= N - sum) {
            System.out.println("Snuke");
        } else {
            System.out.println("Fennec");
        }
    }
}


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

vector<int>apply_repl(vector<int>v, vector<int>O){
  for(int i=0; i<O.size(); i++){
    v[i]=O[v[i]];
  }
  return v;
}

vector<int>getketa(long n){
  vector<int>ret;
  while(n>0){
    ret.push_back(n%2);
    n/=2;
  }
  return ret;
}

int main(){
  int n;
  long k;
  cin >> n >> k;
  vector<vector<int>>powa(70, vector<int>(n));
  for(int i=0; i<n; i++){
    cin >> powa[0][i];
    powa[0][i]--;
  }
  for(int i=1; i<70; i++){
    powa[i] = apply_repl(powa[i-1], powa[i-1]);
  }
  vector<int>kketa = getketa(k);
  int ret = 0;
  for(int i=0; i<kketa.size(); i++){
    if(kketa[i])ret=powa[i][ret];
  }
  cout << ++ret;
  return 0;
}

Measured memory_bytes: 59200
#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 all(v) (v).begin(), (v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
const int INF = 999999999;
int dp[101010];
int main(){
    int n;
    cin >> n;
    vector<int> h(n+1, INF);
    rep(i, n) cin >> h[i];
    rep1(i, n+2) dp[i] = INF;
    rep(i, n){
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
MOD = 998244353

N = int(input())
D = list(map(int, input().split()))
M = [0 for _ in range(N)]

for d in D:
    M[d] += 1

if M[0] == 0:
    print(0)
    exit()

res = 1
for i in range(1, N):
    res = (res * M[D[i] - 1]) % MOD

print(res)


Measured memory_bytes: 14020
//Kaori Miyazono, did I reach you ?
//"I can't die because... I'm the one who will protect you." -Asuna Yuuki
 
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> dp(n);
	for(int i = 1; i < n; i++) {
		dp[i] = dp[i - 1];
		if (a[i] == a[i - 1]) {
			dp[i] = dp[i - 1] + 1;
			if (i >= 2) dp[i] = min(dp[i], 1 + dp[i - 2]);
		}
	}
	cout << dp[n - 1] << '\n';
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import queue

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b, w):
        self.graph[a].append([b, w])
        self.graph[b].append([a,w])

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
    def __init__(self, graph, N):
        self.g = graph.graph
        self.dist = [0] * (N + 1)
        self.visit = [0] * (N + 1)
        self.Q = queue.Queue()
        #self.visit[1] = 1
        self.Q.put(1)

        while not self.Q.empty():
            v = self.Q.get()
            for i, w in self.g[v]:
            	if self.visit[i] == 0:
            		self.dist[i] = self.dist[v] + w
            		self.Q.put(i)
            		self.visit[i] = 1

    def weight(self):
        return self.dist

N = int(input())
G = Graph()
for i in range(N - 1):
	u, v, w = getlist()
	G.add_edge(u, v, w)
XX = BFS(G, N)
ans = XX.weight()
for i in range(1, N + 1):
	if ans[i] % 2 == 0:
		print(0)
	else:
		print(1)


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

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

    int cou = 0;

    d = d + d + 1;

    while(1){
        if(n <= 0){
            break;
        }

        n -= d;
        cou++;
    }

    cout << cou << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string t; cin >> t;
    rep(i,t.size())if(t[i] == '?')t[i] = 'D';
    cout << t << endl;
}

Measured memory_bytes: 3804
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b, t) = scan!(usize, usize, usize);
    println!("{}", t / a * b);
}


Measured memory_bytes: 4352
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;
typedef long long ll;

int main(){
	ll D,G,p[101],c[101],ans=999999999;
	cin>>D>>G;
	for(int i=1;i<=D;i++){
		cin>>p[i]>>c[i];
	}
	for(int i=0;i<(1<<D);i++){
		ll score=0;
		ll solve=0;
		ll yet=0;
		for(ll j=1;j<=D;j++){//100j点の問題はコンプされているか？
			if(i&(1<<(j-1))){
				score+=100*j*p[j]+c[j];
				solve+=p[j];
			}else{
				yet=max(yet,j);//未コンプでいちばんおおきいやつは100yetてんです
			}
		}
		if(G<=score){//tariteru
			ans=min(ans,solve);
		}else{
			int last=(G-score)/(100*yet);//残り問題数
			if((G-score)%(100*yet)!=0){
				last++;
			}
			if(p[yet]>last){
				ans=min(ans,solve+last);
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int ans = 0;
int k;

void dfs(LL n, bool i3, bool i5, bool i7){
    if(n > k) return;
    if(i3&&i5&&i7) ans++;
    dfs(n*10+3, 1, i5, i7);
    dfs(n*10+5, i3, 1, i7);
    dfs(n*10+7, i3, i5, 1);
}

int main(){
    cin >> k;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    final Main application = new Main();
    application.run();
  }
  public void run() {
    final Places places = this.scanFromStdin();
    final int marbleCount = new MarbleCounter().count(places);
    printMarbleCount(marbleCount);
  }
  Places scanFromStdin() {
    final Scanner scanner = new Scanner(System.in);
    final String placesString = scanner.next();
    final boolean firstPlace = placesString.charAt(0) == '1';
    final boolean secondPlace = placesString.charAt(1) == '1';
    final boolean thirdPlace = placesString.charAt(2) == '1';
    return new Places(firstPlace, secondPlace, thirdPlace);
  }
  void printMarbleCount(int count) {
    System.out.println(count);
  }
}
class Places {
  public final boolean firstPlace;
  public final boolean secondPlace;
  public final boolean thirdPlace;
  public Places(boolean firstPlace, boolean secondPlace, boolean thirdPlace) {
    this.firstPlace = firstPlace;
    this.secondPlace = secondPlace;
    this.thirdPlace = thirdPlace;
  }
}
class MarbleCounter {
  public int count(Places places) {
    int count = 0;
    if (places.firstPlace) {
      count++;
    }
    if (places.secondPlace) {
      count++;
    }
    if (places.thirdPlace) {
       count++;
    }
    return count;
  }
}


Measured memory_bytes: 24276
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const n: number = Number(tmp[0]);
    let height: number = 0;
    let count: number = 0;
    tmp[1].split(" ").map(Number).forEach(h => {
      if (h >= height) {
        height = h;
        ++count;
      }
    });
    return `${count}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7372
A,B,K = map(int,input().split())
if A+K-1>B:
    cnt = A
    while cnt <B+1:
        print(cnt)
        cnt += 1
else:
    for i in range(K):
        print(A+i)
    if B-K+1>A+K-1:
        for i in range(K):
            print(B-K+1+i)
    else:
        cnt = A+K
        while cnt<B+1:
            print(cnt)
            cnt += 1

Measured memory_bytes: 3064
#include<stdio.h>
#define N 2000
#define Q 2000
int i,n,q,key[N],a[N],m[Q];
void solve(int,int);
 
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&m[i]);
   
  for(i=0;i<q;i++){
    key[i]=0;
    solve(0,m[i]);
    if(key[i]==1)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
 
void solve(int c,int sum){
  if(sum==0) key[i]=1; 
  if(sum>0&&c<n){
    solve(c+1,sum-a[c]);
    solve(c+1,sum);
  }
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int dp[100000];

int main()
{
	fastio;
	int n;
	cin >> n;
	int h[n];
	for(int i = 0; i < n; i++) cin >> h[i];
	dp[1] = abs(h[0] - h[1]);
	for(int i = 2; i < n; i++) {
		dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 4332
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  int N;
  cin >> N;
  vi L(N);
  rep(i,0,N) cin >> L[i];
  if(vec_max(L) < vec_sum(L) - vec_max(L)) Yes;
  else No;

  return 0;
}


Measured memory_bytes: 256
import math
N,W = list(map(int, input().split(" ")))

items= [list(map(int, input().split(" "))) for _ in range(N)]


dp = [[0 for _ in range(W+1)] for _ in range(N + 1) ]
for w_sum in range(W + 1):
    for i in range(N):


        w,v = items[i]
        if w_sum - w >= 0:
            dp[i + 1][w_sum]  = dp[i][w_sum - w] + v
        # print(dp[i + 1][w],dp[i][w])
        a,b = dp[i + 1][w_sum],dp[i][w_sum]
        dp[i + 1][w_sum] = max(a,b)

print(dp[-1][-1])




Measured memory_bytes: 171784
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <math.h>

using namespace std;
typedef long double cdb;
cdb d,x,ans;int n;
int main()
{
	#ifdef Amberframe
		freopen("agc007c.in","r",stdin);
		freopen("agc007c.out","w",stdout);
	#endif
	for (cin>>n>>d>>x;n;n--) {
		cdb t=2.0*n;
		ans+=d+(t-1)/2.0*x;
		d=5.0/t*x+d*(n+1)/n;
		x=(1+2.0/n)*x;
	}
	printf("%.12lf",(double)ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, f; cin >> n >> f;
    map<pair<string, string>, int> list;
    for(int i = 0; i < n; i++)
    {
        int m; cin >> m;
        vector<string> v;
        for(int j = 0; j < m; j++)
        {
            string item; cin >> item;
            v.push_back(item);
        }
        for(int j = 0; j < v.size(); j++)
        {
            for(int k = j + 1; k < v.size(); k++)
            {
                pair<string, string> p = {v[j], v[k]};
                if(p.first > p.second) swap(p.first, p.second);
                list[p]++;
            }
        }
    }
    int cnt = 0;
    for(auto x : list) if(x.second >= f) cnt++;
    cout << cnt << endl;
    for(auto x : list) if(x.second >= f) cout << x.first.first << " " << x.first.second << endl;
    return 0;
}




Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));

int main(int argc, const char *argv[])
{
    //ABC141 A

    int N;
    cin>>N;

    vector<vector<int> > match (N,vector<int>(N-1,0));

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N-1; j++)
        {
            cin>>match[i][j];
            match[i][j]--;
        }
    }

    vector<int> matched (N,0);
    vector<int> match_num(N,0);
    vector<int> match_yest(N,1);
    int match_check = 0;//if == 1 match is occur
    int opponent;
    int sum = 0;
    int day = 0;



    while(true)
    {
        day++;
        for (int i = 0; i < N; i++)
        {
            matched[i] = 0;
        }

        match_check = 0;
        
        for(int i = 0; i < N ; i ++)
        {
            if((match_num[i] !=  N - 1)&& !matched[i] &&(match_yest[i]))
            {
                opponent = match[i][match_num[i]];
                if((match[opponent][match_num[opponent]] == i)&& !matched[opponent])
                {
                    match_num[i]++;
                    match_num[opponent]++;
                    sum++;
                    matched[i] = 1;
                    matched[opponent] = 1;
                    match_check = 1;
                }
            }
        }

        for (int i = 0; i < N; i++)
        {
            if(matched[i] == 1)
            {
                match_yest[i] = 1;
            }
            else
            {
                match_yest[i] = 0;
            }
        }
        

        if(sum == (N)*(N-1)/2) break;
        if(!match_check) 
        {
            cout<<"-1"<<std::endl;
            return 0;
        }
    }


    cout<<day<<std::endl;
    return 0;
}


Measured memory_bytes: 4224
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def main():
    K = int(input())
    ans = 0
    #全てが同じ数字
    for i in range(1,K+1,1):
        ans += gcd(i,i,i)
    #2つ同じ数字
    tmp = 0
    for i in range(1,K+1,1):
        for j in range(1,K+1,1):
            if j != i:
                tmp += gcd(i,i,j)
    ans += tmp*3
    #3つの異なる数字
    tmp2 = 0
    for i in range(1,K+1,1):
        for j in range(i+1,K+1,1):
            for h in range(j+1,K+1,1):
                tmp2 += gcd(i,j,h)

    ans += tmp2*6

    return ans

print(main())


Measured memory_bytes: 9612
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int N; cin>>N;

  if(N%2==0){
    if((N/2-1>=1)){
      cout<<N/2-1<<endl;
    }else{
      cout<<0<<endl;
    }
  }else{
    if((N/2-1>=1)){
      cout<<N/2<<endl;
    }else{
      cout<<0<<endl;
    }
  }

}


Measured memory_bytes: 256
h,n=map(int,input().split(' '))
moves=[]
for i in range(n):
    moves.append(list(map(int, input().split(' '))))


dp=(h+1)*[float('inf')]
dp[0]=0
          

for i in range(1,h+1):
    for j in range(n):
        dp[i]=min(dp[i], dp[max(0, i-moves[j][0])]+moves[j][1])

print(dp[h])
                  


Measured memory_bytes: 74232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;
vector<string> vs;

string table[3] = { "ABC", "DEF", "GHI" };

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

int main(){
	REP(i, 1000){
		cin >> s;
		bool f = 0;
		REP(j, s.size() - 1){
			REP(k, 3){
				REP(l, 3){
					if (s[j] == table[k][l]){
						REP(m, 4){
							if (k + dx[m] >= 0 && k + dx[m] <= 2 && l + dy[m] >= 0 && l + dy[m] <= 2){
								if (s[j + 1] == table[k + dx[m]][l + dy[m]]){
									break;
								}
							}
							if (m == 3)f = 1;
						}
					}
				}
			}
		}
		if (!f)vs.push_back(s);
	}
	REP(i, vs.size()){
		cout << vs[i] << endl;
	}
}

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

using namespace std;

template <class T>
using lim = numeric_limits<T>;

typedef long long ll;
typedef long double ld;

const int maxN = 55555;
vector<int> primes;
vector<int> fiveList;

void sieve(int n){
	for (int i = 2; i <= n; i++){
		bool isPrime = true;
		for (int p : primes){
			if (p*p > i) break;
			
			if (i%p == 0){
				isPrime = false;
				break;
				}
			}
		
		if (!isPrime) continue;
		
		primes.push_back(i);
		
		// grabbing all primes that are 1 mod 5
		if (i%5 == 1) fiveList.push_back(i);
		}
	
	}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	sieve(maxN);
	for (int i = 0; i < n; i++){
		cout << fiveList[i] << " ";
		}
	cout << endl;
	}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef ll Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    FORO(i, X) cin >> A[i];
    FORO(i, Y) cin >> B[i];
    FORO(i, Z) cin >> C[i];
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));

    vector<ll> AB(X * Y);
    FORO(i, X) {
        FORO(j, Y) {
            AB[i * X + j] = A[i] + B[j];
        }
    }
    sort(ALL(AB));
    int XY = X * Y;
    priority_queue<pii> pq;
    vector<int> idx(XY);
    FORO(i, XY) {
        pq.push(pii(AB[i] + C[Z - 1], i));
        idx[i] = Z - 1;
    }
    while(K--) {
        pii p = pq.top(); pq.pop();
        cout << p.A << endl;
        if(idx[p.B] > 0) {
            idx[p.B]--;
            pq.push(pii(AB[p.B] + C[idx[p.B]], p.B));
        }
    }
    return 0;
}

Measured memory_bytes: 30444
#include<stdio.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char GET(void)
{
  static char buf[1<<15],*ptr=buf,*end=buf;
  if(ptr==end){ptr=buf,end=buf+fread(buf,1,1<<15,stdin);}return *ptr++;
}
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  long x=0,f=0;char c=GET();while(c<48||c>57){f^=c==45,c=GET();}
  while(c>47&&c<58){x=x*10+c-48,c=GET();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int min(const int x,const int y){return x<y?x:y;}
int main(void)
{
  int ten[19][19]={{0}},N=IN();long count=0;
  rep(i,N)
  {
    long A=0;char c=GET();int digit=1e9,even=0,five=0;
    while(c<48||c>57){c=GET();}while(c>47&&c<58){A=A*10+c-48,c=GET();}A*=digit;
    if(c==46){c=GET();}while(c>47&&c<58){digit/=10;A+=digit*(c-48);c=GET();}
    while(!(A&1)){A/=2,even++;}while(A%5==0){A/=5,five++;}
    ten[min(even,18)][min(five,18)]++;
  }
  rep(i,19){rep(j,19){rep(x,19){rep(y,19)
  {
    if(i==x&&j==y){if(i+x>17&&j+y>17){count+=1l*ten[i][j]*(ten[x][y]-1);}continue;}
    if(i+x>17&&j+y>17){count+=1l*ten[i][j]*ten[x][y];}
  }}}}
  return OUT(count/2),0;
}

Measured memory_bytes: 1516
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;


int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    int res = 0;
    int i=0,j=0;
    while(i < n){
	while(i < n && s[i] == '1')++i;
	res = max(res, i-j);
	while(i < n && s[i] == '0')++i;
	--k;
	if(k < 0){
	    while(j < n && s[j] == '1')++j;
	    while(j < n && s[j] == '0')++j;
	}
	res = max(res, i-j);
    }
    cout << res << endl;
}


Measured memory_bytes: 888
"use strict";
    
const main = arg => {
    let text = arg.trim().split("");
  	let ans = "No";
  	// 全部同じだった時の処理
  	if(text.every(elm => { return elm == text[0]})){
    	ans = "No"; 
    } 
  	else if(
      (text[0] == text[1] && text[2] == text[3])
      ||
      (text[0] == text[2] && text[1] == text[3])
      ||
      (text[0] == text[3] && text[1] == text[2])
  	)
    {
    	ans = "Yes";
    }
  	console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n;
	cin>>n;
	ll a[n];
	scan(a, 0, n);
	ll c = 0;
	forn(i, 0, n){
		if(a[i] != i+1)c++;
	}
	if(c>2){
		cout<<"NO"<<endl;

	}
	else {
		cout<<"YES"<<endl;
	}
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
 
int main() {
    
 
    
    int k, x;
    cin >> k >> x;
    k--;
    for (int i = max(x - k, -1000000); i <= min(x + k, 1000000); ++i)
    {
        if (i == min(x + k, 1000000))
        {
            cout << i << endl;
            break;
        }
        cout << i << " ";
    }
    
    
    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T>
vector<vector<T>> MakeVector2D(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  vector<tuple<int64, int>> tuples(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    tuples[i] = {xs[i], i};
  }
  sort(tuples.begin(), tuples.end());
  reverse(tuples.begin(), tuples.end());

  auto dp = MakeVector2D<int64>(n + 1, n + 1, 0LL);
  for (int k = 0; k < n; k++) {
    auto [x, p] = tuples[k];
    for (int i = 0; i <= k; i++) {
      // dp[k][i]
      UpdateMax(dp[k + 1][i + 1], dp[k][i] + x * abs(p - i));
      UpdateMax(dp[k + 1][i], dp[k][i] + x * abs(p - (n - 1 - (k - i))));
    }
  }

  // cout << dp[1][0] << " " << dp[1][1] << endl;

  int64 answer = 0;
  for (int i = 0; i <= n; i++) {
    UpdateMax(answer, dp[n][i]);
  }
  cout << answer << endl;
}

Measured memory_bytes: 34616
N, M = map(int,input().split())

A = list(map(int,input().split()))
D = dict()

for a in A:
    if a in D:
        D[a] += 1
    else:
        D[a] = 1

for _ in range(M):
    B, C = map(int,input().split())
    if C in D:
        D[C] += B
    else:
        D[C] = B

D = sorted(D.items(), reverse = True)

ans, cnt = 0, 0
for d in D:
    x = min(d[1], N-cnt)
    cnt += x
    ans += d[0] * x

    if cnt == N: break


print(ans)


Measured memory_bytes: 44428