akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

size_t N, M;
vector<int> g[100010];

vector<int64_t> dp(100010, -1LL);

int64_t rec(size_t node) {
    if (~dp[node]) return dp[node];

    int64_t ret = 0;
    for (auto &elem: g[node]) {
        chmax(ret, rec(elem) + 1);
    }

    return dp[node] = ret;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for (size_t i = 0; i < M; ++i) {
        size_t from, to;
        cin >> from >> to;
        from--, to--;
        g[from].emplace_back(to);
    }

    int64_t res = 0;
    for (size_t node = 0; node < N; ++node) {
        chmax(res, rec(node));
    }

    cout << res << "\n";

    return 0;
}


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

using namespace std;

using ll = long long;

int INF = 1e9 + 5;

template<typename T>
void min_self(T& a, T b)
{
    a = min(a,b);
}

template<typename T>
void max_self(T& a, T b)
{
    a = max(a,b);
}

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

    string s, t;
    
    cin >> s >> t;
    
    int n = s.size(), m = t.size();
    
    vector<vector<int>>  dp(n+1,vector<int>(m+1,0));
    
    for(int i=1; i<=n; ++i)
    {
        for(int j=1; j<=m; ++j)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    
    int L = dp[n][m];
    
    //cout << L;
    
    string answer(L,' ');
    
    int i=n, j=m;
    while(i>0 && j>0)
    {
        if(s[i-1] == t[j-1])
        {
            answer[--L] = s[i-1];
            --i; --j;
        }
        else if(dp[i][j] == dp[i-1][j])
        {
            --i;
        }
        else
        {
            --j;
        }
        
    }
    
    
    
    
    

    cout << answer;
    
}


Measured memory_bytes: 35584
def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        break

    if len(S) == 0:
        print("YES")
    else:
        print("NO")

main()

Measured memory_bytes: 3188
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1) :
    if ((x-500*i) > 100*b + 50*c) or (500*i > x) :
        ans += 0
    else :
        for j in range(b+1) :
            if ((x-500*i-100*j) > 50*c) or (100*j > (x-500*i)) :
                ans += 0
            else :
                ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,i;
  cin >> n;
  string s1,s2;
  int t=0,h=0;
  
  for(i=0;i<n;i++){
    cin >> s1 >> s2;
    if(s1.compare(s2)==0) {
      t++;h++;
    }else if(s1.compare(s2)>0) t+=3;
    else h+=3;
  }
  cout << t << " " << h << endl;
}


Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <queue>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)

using namespace std;

int main(void){
  int n,ret = 0,in,d;
  cin>>n>>d;
  rep(i,n){
    cin>>in;
    ret += (in>d?in-d:0);
  }
  if(ret==0){
    cout<<"kusoge"<<endl;
  }else{
    cout<<ret<<endl;
  }

}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint X, A, B;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> X >> A >> B;
	if (abs(X - A) < abs(X - B)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
}


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

using vi = std::vector<int>;

const int NMAX = (int)1e7+20, INF = (int)1e9;

const vi minDiv = [](){
// предподсчет минимальных простых делителей для каждого числа
    vi d(NMAX,INF);
    for (int i = 2; i * i < NMAX; i++) {
        if (d[i] < INF) continue; // число i - составное
        for (int j = i * i; j < NMAX; j += i) {
            d[j] = std::min(d[j], i);
        }
    }
    for (int i = 1; i < NMAX; i++) {
        if (d[i] == INF) { // число i - простое
            d[i] = i;
        }
    }
    return d;
}();

const vi powMinDiv = [](){
// предподсчет вхождений минимальных простых делителей для каждого числа
    vi answ(NMAX,0);
    for (int x = 2; x < NMAX; x++) {
        const int p = minDiv[x];
        answ[x] = (minDiv[x/p] == p ? answ[x/p] : 0) + 1;
    }
    return answ;
}();

const vi cntDivs = [](){
// предподсчет количества делителей для каждого числа
    vi answ(NMAX,1);
    for (int x = 2; x < NMAX; x++) {
        const int p = minDiv[x];
        const int k = powMinDiv[x];
        answ[x] = answ[x/p] / k * (k+1);
    }
    return answ;
}();

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    int n; std::cin >> n;
    int64_t answ(0);
    for (int k = 1; k <= n; k++) {
        answ += 1LL * k * cntDivs[k];
    }
    std::cout << answ << std::endl;
    return 0;
}

Measured memory_bytes: 120328
MOD = 10**9 + 7
X, Y = map(int, input().split())


def f(n):
    res = n
    for i in range(1, n):
        res *= i
        res %= MOD
    return res


def solve():
    ans = 0
    if (X + Y) % 3 == 0:
        n = (2 * X - Y) // 3
        m = (2 * Y - X) // 3
        if n == 0 or m == 0:
            ans += 1
        elif n > 0 and m > 0:
            ans += (f(n + m) * pow(f(n), MOD - 2, MOD) * pow(f(m), MOD - 2, MOD)) % MOD

    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 63048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

    int n;
    cin >> n;
    ll A, B;
    cin >> A >> B;
    vector<ll> h(n);
    ll high = 0;
    rep(i,n) {
        cin >> h[i];
        high = max(high, h[i]);
    }
    ll diff = A-B;
    ll left = 0;
    ll right = (high + B - 1) / B;
    ll ans = 0;
    while(right > left){
        int mid = (left + right)/2;
        ll cnt = 0;
        for(int i = 0;i < n; i++){
            if(h[i] <= B*mid) continue;
            cnt += (h[i] - B*mid + diff - 1)/diff;
        }
        if(cnt <= mid) right = mid;
        else left = mid + 1;

        mid = (left + right)/2;
        ans = mid;
    }
    cout << ans <<endl;
    return 0;
}


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

int main()
{
    int x[5];
    for (int i = 0; i < 5; i++)
    {
        cin >> x[i];
    }

    for (int i = 0; i < 5; i++)
    {
        if(x[i] != i + 1)cout << i + 1 << endl;
    }
    
}


Measured memory_bytes: 3616
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	cout << N * M - N - M + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    n, m = map(int, args[0].split())
    AC = [False]*n
    WA = [0]*n
    for p, s in map(str.split, args[1:]):
        i = int(p)-1
        if s == 'AC':
            AC[i] |= True
        elif s == 'WA' and not AC[i]:
            WA[i] += 1

    penalty = 0
    for i, ac in enumerate(AC):
        if ac:
            penalty += WA[i]

    return '{} {}'.format(sum(AC), penalty)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 13868
#include<iostream>
 #include<string>
 #include<iomanip>
 #include<cmath>
 #include<math.h>

 #define rep(i,start,n) for(int i=0 ; i<n ; i++)

 using namespace std;

 int main(){

int a , b , C;
double S=0,h=0,c=0;
cin >> a >> b >> C;

S = 0.5 * a * b * sin(C * M_PI / 180);                               //??¢???
h = 2 * S / a;                                                       //??????
c = sqrt(a * a + b * b - 2 * a * b * cos(C * M_PI / 180));           //?????????????????????

cout << fixed << setprecision(8) << S << endl;                 //??¢?????¨???
cout << fixed << setprecision(8) << a+b+c << endl;            //??????????????¨???
cout << fixed << setprecision(8) << h << endl;                //????????¨???

return 0;

 }

Measured memory_bytes: 1240
// Codeforces 1.12.6
// AtCoder 1.6
// Paiza 1.7.3

package main

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

type io struct {
	Scanner *bufio.Scanner
}

func (io *io) s() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *io) i() int {
	i, _ := strconv.Atoi(io.s())
	return i
}

func (io *io) ss(n int) []string {
	a := make([]string, n)
	for i := range a {
		a[i] = io.s()
	}
	return a
}

func (io *io) is(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = io.i()
	}
	return a
}

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func stdin() io {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	return io{Scanner: scn}
}

func main() {
	io := stdin()
	m, d := io.i(), io.i()

	// solve here
	ans := 0
	for i := 1; i <= m; i++ {
		for j := 1; j <= d; j++ {
			if j/10 < 2 {
				continue
			}
			if j%10 < 2 {
				continue
			}
			if i != (j/10)*(j%10) {
				continue
			}
			ans++
		}
	}

	fmt.Println(ans)
}


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

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

    int N, W;
    cin >> N >> W;
    vector<vector<long long>> val(N+1, vector<long long>(100001, 1e9+1));

    val[0][0] = 0;
    int max_j = 0;
    for (int i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;
        max_j += v;
        for (int j = 0; j <= max_j; j++) {
            if (j >= v && val[i][j-v] + w <= W) val[i+1][j] = min(val[i][j], val[i][j-v] + w);
            else val[i+1][j] = val[i][j];
        }
    }
    int max_v;
    for (int i = 0; i <= max_j; i++) if (val[N][i] < 1e9+1) max_v = i;
    cout << max_v << endl;
    return 0;
}



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

int main(){
    string s;
    cin >> s;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') cout << 3 << endl;
    else if(s[0]=='R'&&s[1]=='R'||s[1]=='R'&&s[2]=='R') cout << 2 << endl;
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R') cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3620
import sys
import bisect
N, K = map(int, sys.stdin.readline().split())
V = list(map(int, sys.stdin.readline().split()))

# 累積和を計算しとく
sum_list = [V[0]]
for i in range(1, N):
    add = V[i] + sum_list[-1]
    sum_list.append(add)

ans = 0

max_take = min(N, K)

for A in range(max_take + 1):
    for B in range(max_take - A + 1):
        if A > 0 and B > 0:
            list = V[:A] + V[N - B:]
            total_sum = sum(list) #sum_list[A - 1] + (sum_list[N - 1] - sum_list[N - 1 - B])
            list.sort()
            n = bisect.bisect_left(list, 0)
            if n <= K - (A + B):
                total_sum -= sum(list[:n])
            else:
                total_sum -= sum(list[:K - (A + B)])
        elif A == 0 and B > 0:
            list = V[N - B:]
            total_sum = sum(list) #sum_list[N - 1] - sum_list[N - 1 - B]
            list.sort()
            n = bisect.bisect_left(list, 0)
            if n <= K - (A + B):
                total_sum -= sum(list[:n])
            else:
                total_sum -= sum(list[:K - (A + B)])
        elif A > 0 and B == 0:
            list = V[:A]
            total_sum = sum(list) #sum_list[A - 1]
            list.sort()
            n = bisect.bisect_left(list, 0)
            if n <= K - (A + B):
                total_sum -= sum(list[:n])
            else:
                total_sum -= sum(list[:K - (A + B)])
        else:
            continue
        
        #print("A = " + str(A) + " B = " + str(B))
        #print(total_sum)
        ans=max(ans,total_sum)
            
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

#define LENGTH 4

int main(void) {
    char input[LENGTH];
    int a=0,b=0,c=0,n;

    scanf("%d %d %d",&a,&b,&c);

    int trainFee = a * b;
    int taxiFee = c;

    if(trainFee >= taxiFee){
        printf("%d\n",taxiFee);
    }else{
        printf("%d\n",trainFee);
    }

    return 0;
}

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

int N,K;
int schedule[100];
int dp[100][3][3];

int solve(int now, int kind, int t){ //now日目の予定を決める、前日はkindのパスタを食べていてt日連続
    if(t >= 3) return 0;
    if(now == N) return 1;
    if(dp[now][kind][t] != -1) return dp[now][kind][t];
    if(schedule[now] != -1){
        //予定が決まっている場合
        if(schedule[now] == kind) dp[now][kind][t] = solve(now+1,kind,t+1);
        else dp[now][kind][t] = solve(now+1,schedule[now],1);
    }
    else{
        //予定が決まっていない場合
        dp[now][kind][t] = solve(now+1,kind,t+1) + solve(now+1,(kind+1)%3,1) + solve(now+1,(kind+2)%3,1);
    }
    dp[now][kind][t] %= 10000;

    return dp[now][kind][t];
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        schedule[i] = -1;
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                dp[i][j][k] = -1;
            }
        }
    }
    for(int i=0; i<K; i++){
        int tmp;
        cin >> tmp;
        cin >> schedule[tmp-1];
        schedule[tmp-1]--;
    }

    cout << solve(0,0,0) % 10000 << endl;
    return 0;
}


Measured memory_bytes: 3096
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
a = l.shift() * 1
b = l.shift() * 1 
as = a + ''
bs = b + ''
for (i=0;i<b-1;i++) {
    as += a 
}
for (i=0;i<a-1;i++) {
    bs += b
}
console.log(as < bs ? as : bs)

Measured memory_bytes: 7372
eval'N,K,*A='+`dd`.split*?,
A.sort!
l=0
r=N
s=K%2>0?A[r-=1]:1
b=s>0?1:-1
(x,y=A[l]*A[l+1],A[r-2]*A[r-1]
s=s*(x*b>y*b ?(l+=2;x):(r-=2;y))%(10**9+7)
K-=2)while K>1
p s

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

// 素因数を列挙
vector<pair<ll, ll>> enumeratePrimeFactors(ll n) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= n; a++) {
    if (n % a != 0) {
      continue;
    }
    ll ex = 0; // 指数
    // 割れるだけ割る
    while (n % a == 0) {
      ++ex;
      n /= a;
    }
    res.emplace_back(a, ex);
  }
  // nが一度も割られなかった場合
  if (n != 1) {
    res.emplace_back(n, 1);
  }
  return res;
}

int main() {
  ll n, p;
  cin >> n >> p;
  vector<pair<ll, ll>> primeFactors = enumeratePrimeFactors(p);
  vector<ll> pp;
  ll res = 1;
  if (n == 1) {
    res = p;
  } else {
    for (auto pf : primeFactors) {
      if (pf.second >= n) {
        rep(i, pf.second / n) {
          pp.push_back(pf.first);
        }
      }
    }
  }
  for (ll ppp : pp) {
    res *= ppp;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;
int a[22][22];
int dp[22][1<<22];
int n;
int solve(int i,int m)
{
    if(i==n)
    {
        if(m==0)
            return 1;
        return 0;
    }
    if(dp[i][m]!=-1)
      return dp[i][m];
    int ans=0;
    for(int women=0;women<n;women++)
    {
        if(a[i][women]==1&&(1<<women&m))
        {
            ans+=solve(i+1,m^(1<<women));
            ans=ans%1000000007;
        }
    }
    return dp[i][m]=ans;
}

signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    }
    cout<<solve(0,(1<<n)-1);
}



Measured memory_bytes: 721152
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct obj{
	struct obj *prev;
	struct obj *next;
	int key;
}obj;

typedef struct{
	struct obj *root;
	struct obj *last;
	int size;
	int csum;
}dlist;

obj *createObj(int n){
	obj *ob;
	mymalloc(ob,1);
	ob->prev=NULL;
	ob->next=NULL;
	ob->key=n;
	return ob;
}

dlist *createDlist(){
	dlist *list;
	mymalloc(list,1);
	list->root=NULL;
	list->last=NULL;
	list->size=0;
	list->csum=0;
}

void insert(dlist *list,int key){
	obj *input;
	input=createObj(key);
	if(list->root==NULL){
		list->root=input;
		list->last=input;
	}
	else{
		list->root->prev=input;
		input->next=list->root;
		list->root=input;
	}
	list->size++;
	list->csum+=key;
}


void append(dlist *list1,dlist *list2){
	if(list2->size==0){
		return;
	}
	if(list1->last==NULL){
		list1->root=list2->root;
		list1->last=list2->last;
	}
	else{
		list1->last->next=list2->root;
		list2->root->prev=list1->last;
		list1->last=list2->last;
	}
	list1->size+=list2->size;
	list1->csum+=list2->csum;
	list2->root=NULL;
	list2->last=NULL;
}

obj *deleteF(dlist *list){
	obj *output;
	if(list->root==NULL){
		return NULL;
	}
	else{
		output=list->root;
		if(list->root->next==NULL){
			list->root=NULL;
			list->last=NULL;
		}
		else{
			list->root=list->root->next;
			list->root->prev=NULL;
		}
		return output;
	}
}

void reverse(dlist *list,dlist *slist){
	int cumH,sum,c1;
	obj *ob;
	dlist *blist;
	blist=createDlist();
	cumH=0;
	sum=0;
	ob=deleteF(list);
	while(1){
		if(ob==NULL){break;}
		c1=ob->key;
		if(c1==1){
			sum+=2*cumH+1;
			cumH++;
		}else{
		if(c1==0){
			sum+=2*cumH;
		}else{
		if(c1==-1){
			if(cumH!=0){
				sum+=2*cumH-1;
				cumH--;
				if(cumH==0){
					insert(blist,sum/2);
					sum=0;
				}
			}
		}}}
		ob=deleteF(list);
	}
	append(slist,blist);
}
	
		
		
main(){
	int cumH,tmpH,n;
	char c1;
	dlist *slist,*list;
	obj *ob;
	cumH=0;
	list=createDlist();
	slist=createDlist();
	while(scanf("%c",&c1)!=EOF){
		if(c1=='\\'){
			cumH--;
			insert(list,-1);
		}else{
		if(c1=='_'){
				insert(list,0);
		}else{
		if(c1=='/'){
			cumH++;
			if(cumH>0){
				cumH=0;
			}else{
			insert(list,1);
			if(cumH==0){
				reverse(list,slist);
			}}
		}}}
	}
	reverse(list,slist);
	printf("%d\n",slist->csum);
	printf("%d",slist->size);
	ob=deleteF(slist);
	if(ob!=NULL){
		printf(" ");
		while(1){
			printf("%d",ob->key);
			ob=deleteF(slist);
			if(ob!=NULL){
				printf(" ");
			}else{break;}
		}	
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1272
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long sqrt = (long)Math.sqrt(n);

        for(long i = sqrt; i > 0; i--) {
        	if(n % i == 0) {
        		long j = n/i;

        		System.out.println(i+j-2);
        		return;
        	}
        }

        return;
    }
}

Measured memory_bytes: 23764
fun main(args: Array<String>) {
    val K = nextInt()
    val ans = mutableListOf<Long>()
    (0 .. 9).forEach { ans.add(it.toLong()) }
    var p = 1
    while (p < K) {
        val x = ans[p++]
//System.err.println(x)
        val r = x % 10
        if (r != 0L) ans.add(10 * x - 1 + r)
        ans.add(10 * x + r)
        if (r != 9L) ans.add(10 * x + 1 + r)
    }
    println(ans[K])
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 40476
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

	int a;
	cin>>a;
	int flag=0;
	forr(i,0,a)
	{
		int x;
		cin>>x;
		if(x%2==0)
		{
			if(x%3==0 or x%5==0)
				{}
			else flag=1;
		}
	}
	if(!flag)	cout<<"APPROVED";
	else cout<<"DENIED";
	
	return 0;	
}

Measured memory_bytes: 256
// ref: https://img.atcoder.jp/arc098/editorial.pdf
// ref: https://drken1215.hatenablog.com/entry/2018/06/26/125054

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    vector<int64> vA(N); for(int i=0; i<N; ++i){ cin>>vA[i]; }
    
    int64 cnt=0;
    int64 sum=0;
    int l=0, r=0;
    for(int i=0; i<N; ++i){
        
        while(r<N && ((sum^vA[r])==(sum+vA[r]))){ sum+=vA[r]; ++r; }
        cnt += r-l;
        
        sum -= vA[l]; ++l;
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int vis[N];
int dp[N];
int cnt ;
vector<int>v[N];
map<pair<int,int>,int>color;
// map<int,int>yo;

signed main(){
 	// #ifndef ONLINE_JUDGE
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// #endif
	SaveTime;
	int T=1;
	// cin >> T;
	while(T--){
		int n ;
		cin >> n ;
		vector<pair<int,int>>edg;
		for(int i =0 ;i < n -1; i++){
			int x, y;
			cin >> x >> y;
			x--;
			y--;
			edg.pb({x,y});
			dp[x]++;
			dp[y]++;
			cnt = max(cnt , dp[x]);
			cnt =max(cnt,dp[y]);
			v[x].pb(y);
			v[y].pb(x);
		}
		cout <<cnt<<endl;
		fn{
			int co = dp[i];
			int yo[cnt+2];
			memset(yo,0,sizeof(yo));
			int poss=0;
			vector<int>chi;
			for(auto it  : v[i]){
				if(color[{i,it}]){
					yo[color[{i,it}]]=1;
				}
				else{
					chi.pb(it);
				}
			}
			// for(auto ii : chi)cout<<ii << " ";
			// 	cout<<endl;
			for(int j=1;j<=cnt && poss < chi.size() ;j++){
				if(yo[j]==0){
					// cerr<<i << " " <<j<<endl;
					color[{i,chi[poss]}]=j;
					color[{chi[poss++],i}]=j;
				}
			}
			
		}
		for(int i =0 ; i < n-1;i++){
			cout << color[{edg[i].fi,edg[i].se}]<<endl;
		}

	
	}
	
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, m;
    cin >> n >> m;
    LL lc = 1;
    LL div_cnt;
    for( int i = 0; i < n; ++i ) {
        LL a;
        cin >> a;
        int cnt = 0;
        LL tmp = a;
        while( tmp % 2 == 0 ) {
            tmp /= 2;
            ++cnt;

        }
        if( i == 0 ) div_cnt = cnt;
        else {
            if( cnt != div_cnt ) {
                lc = -1;
                continue;

            }
        }
        a /= 2;
        if( lc == -1 ) continue;
        lc = lcm(lc, a);
        if( lc > m ) {
            lc = -1;

        }

    }

    if( lc == -1 ) {
        cout << 0 << endl;
        return 0;

    }

    LL res = m / lc;
    res -= res / 2;
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int
#define Vec vector

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N,M;
	ll P;
	cin >> N >> M >> P;
	Vec<int> A(M), B(M);
	Vec<ll> C(M);
	for(int i=0;i<M;i++){
		cin >> A[i] >> B[i] >> C[i];
		A[i]--; B[i]--;
		C[i]-=P;
	}
	
	
	ll Inf = (ll) 1e18;
	Vec<Vec<ll>> ma(N);
	for(int i=0;i<N;i++){
		ma[i].resize(N * 3 + 1);
		for(int j=0;j<=N*3;j++){
			ma[i][j] = -Inf;
		}
	}
	
	ma[0][0] = 0;
	for(int i=0;i<3*N;i++){
		for(int j=0;j<M;j++){
			int a = A[j];
			int b = B[j];
			ll c = C[j];
			if(ma[a][i] == -Inf) continue;
			ma[b][i + 1] = max(ma[b][i + 1], ma[a][i] + c);
		}
	}
	
/*	
	for(int i=0;i<=2*N;i++){
		ma[N-1][i] = max((ll) 0, ma[N-1][i] - i * P); 
	}
*/	
	ll ma0 = -Inf;
	for(int i=0;i<=N;i++){
		ma0 = max(ma0, ma[N-1][i]);
	}
	ll ma1 = -Inf;
	for(int i=N+1;i<=2*N;i++){
		ma1 = max(ma1, ma[N-1][i]);
	}
	ll ma2 = -Inf;
	for(int i=2*N+1;i<=3*N;i++){
		ma2 = max(ma2, ma[N-1][i]);
	}
	
	if(ma2 > ma1){
		cout << -1 << endl;
	} else {
		cout << max((ll) 0, max(ma1,ma0)) << endl;
	}
	
	
	
	
	
	
	
	
	
    return 0;
}

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

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

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

ll mod = 1000000007;

ll gcd(ll a, ll b){
  if (a%b == 0)return(b);
  else return(gcd(b, a%b));
}

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}


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

  int n;
  cin >> n;
  int ret = 0;
  rep(i,n){
    int a;
    cin >> a;
    if(i % 2 == 0 && a % 2 == 1)ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int gcd(int a, int b)
{
	if (b == 0)
	{
		return a;
	}

	return gcd(b, a % b);
}

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

	vector<int> list(N);
	for (int i = 0; i < N; i++)
	{
		cin >> list[i];
	}

	sort(list.begin(), list.end());

	for (int i = 0; i < N - 1; i++)
	{
		list[i + 1] = gcd(list[i], list[i + 1]);
	}

	cout << list[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 640
import numpy as np
n,k = map(int, input().split())

two = 0
for i in range(1, n+1):
    two_count =0
    score = i
    while score <= k-1:
        score *= 2
        two_count += 1

    two += (1/2) ** two_count

print((1/n) * two)

Measured memory_bytes: 12500
#include<stdio.h>

void mergeSort(int*, int, int);
void merge(int*, int, int, int);
int count;

int main(){
  int n, S[500005], i;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);

  mergeSort(S, 0, n);
  
  for(i = 0; i < n - 1; i++)
    printf("%d ", S[i]);
  printf("%d\n", S[n -1]);

  printf("%d\n", count);

  return 0;
}

void  merge(int *A, int left, int mid, int right){
  int n1= mid - left, n2 = right - mid, L[250005], R[250005], i, j = 0, k;

  for(i = 0; i < n1; i++)
    L[i] = A[left + i];

  for(i = 0; i < n2; i++)
    R[i] = A[mid + i];
  
  L[n1] = 2000000000;
  R[n2] = 2000000000;
  
  i = 0;
    
  for(k = left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }else{
      A[k] = R[j];
      j = j + 1;
    }
  }
}
void mergeSort(int *A, int left, int right){
  int mid;

  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
  

Measured memory_bytes: 4504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5+6;
const int mod = 1e9+7;
const int inf = 1e8;
int dp[44][404][404];
int a[44][3];
int n,ma,mb;
int go(int idx,int ca,int cb){
    if(idx==n){
        if(ca==0 and cb==0)return inf;
        int g = __gcd(ca,cb);
        ca/=g;
        cb/=g;
        if(ca==ma and cb==mb)return 0;
        else return inf;
    }
    int ret = dp[idx][ca][cb];
    if(ret!=-1)return ret;
    ret = inf;
    ret = min(ret,go(idx+1,ca,cb));
    ret = min(ret,go(idx+1,ca+a[idx][0],cb+a[idx][1])+a[idx][2]);
    return dp[idx][ca][cb] = ret;
}
void solve(){
    cin>>n>>ma>>mb;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)cin>>a[i][j];
    }
    memset(dp,-1,sizeof dp);
    int ans = go(0,0,0);
    if(ans>=inf)ans = -1;
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 28288
s = int(input())
c = 0
a = [s]
while c < 100000:
    if s % 2 == 0:
        s = s//2
        c += 1
    else:
        s = 3*s+1
        c += 1
    a += [s]
for i in range(c):
    if a[i] in a[:i]:
        print(i+1)
        exit()

Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define f first 
#define s second
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAX 1000005
#define pb push_back
int flag[1000006];
ll gcd(ll a, ll b)
{
  if(a == 0)
    return b;
  return gcd(b%a,a);
}

int main(){
  FIO;
  int r,d,x;
  cin >> r >> d >> x;
  for (int i = 0; i < 10; ++i)
  {
    x = r*x -d;
    cout << x << "\n"; 
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vii;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 




int N,Q;
int c,q,mxc;
bool f;

int main(){
	while(cin>>N>>Q){
		//cout<<N<<" "<<Q<<endl;
		set<int> s;
		mxc=-1;
		rep(i,N){
			cin>>c;
			mxc=max(mxc,c);
			s.insert(c);
		}
		s.insert(0);
		for(int i=0; i<Q; i++){
			f=false;
			cin>>q;
			int qp=q;
			while(qp>0){
				for(int i=qp-1; i<=mxc; i+=q){
					if(s.count(i)){
						cout<<qp-1<<endl;
						//cout<<"i:"<<i<<endl;
						f=true;
						break;
					}
				}
				if(f) break;
				qp--;
			}
		}
	}
}



// int N,Q;
// vi c;
// int q;


// int main(){
// 	while(cin>>N>>Q){
// 		c=vi(N,0);
// 		rep(i,N) cin>>c[i];
// 		sort(all(c));

// 		rep(i,Q){
// 			cin>>q;
// 		}
// 	}

// }

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

typedef long long int ll; 
#define int long long
const int mod = 998244353;
const int mex = 1e5 + 0;
int fact[mex+5], inv[mex+5];

int toPower(int a, int p){
    swap(a, p);
    int res = 1;
    while (p){
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int Inv(int x){ 
    return toPower(x, mod - 2); 
}

void initialize(){
    inv[0] = Inv(fact[0]);fact[0] = inv[0] = 1;
    
    for(int i = 1; i < mex; i++){
        fact[i] = (ll(i) * fact[i - 1]) % mod;
        inv[i] = Inv(fact[i]);
    }
}

int C(int n, int k){
    if (n < 0 || k < 0 || k > n) return 0;
    return ll(fact[n]) * inv[k] % mod * inv[n - k] % mod;                 
}

signed main(){
      initialize();
      int n; cin >> n;
      
      int data[n+5];
      map <int, int> dis, ms;
      
      for(int i = 1; i <= n; i++){
          cin >> data[i];
          ms[data[i]]++;
      }
      
      ms[0]--;
      
      if(data[1] != 0 || ms[0] > 0){
          cout << "0\n"; return 0;
      }
      dis[0]++;
      ms.erase(0);
      
      auto it = ms.begin();
      
      int ans = 1;
      
      while(it != ms.end()){
          int temp = toPower(it->second, dis[it->first - 1]);
          ans = (ans % mod * temp % mod)%mod;
          dis[it->first] = it->second;
          it++;
      }
      cout << ans << '\n';
}

Measured memory_bytes: 15104
#include <iostream>
using namespace std;
using ll = long long;
// 9マスが偶数個→表
// 8マスが奇数個→表
//接する行が0行→両端だけ表
//接する行が1行→全部表
//接する行が2行→両端だけ表

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

    if(n==1 && m==1){
        cout << 1 << endl;
        return 0;
    }
    if(n==1 || m==1){
        cout << n*m-2 << endl;
        return 0;
    }

    cout << (n-2)*(m-2) << endl;
    return 0;
}

Measured memory_bytes: 256
K = gets.to_i

a_n = Array.new(10**6)
a_n[0] = 7 % K
1.upto(10**6-1) do |i|
  a_n[i] = (a_n[i-1] * 10 + 7) % K
end
a_n.each.with_index do |a, i|
  if a == 0
    p i + 1
    exit
  end
end

p -1

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

int N, A[100005];
int total = 0;

main()
{
    cin >> N;
    A[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        total += abs(A[i] - A[i-1]);
    }
    A[N+1] = 0;
    total += abs(A[N]);

    for (int i = 1; i <= N; i++) {
        int cost = total - (abs(A[i] - A[i-1]) + abs(A[i] - A[i+1]))
            + abs(A[i-1] - A[i+1]);
        cout << cost << endl;
    }
    return 0;
}

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

int n;
int lse(int,int S[]);

int main()
{
    /*n,qを変数宣言*/
    int q,i,j,count=0;
    /*n,q,S,Tの値代入*/
    scanf("%d",&n);
    int S[n];
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    } 
    scanf("%d",&q);
    int T[q];
    for(i=0;i<q;i++){
        scanf("%d",&T[i]);
    } 
    
    for ( i = 0; i < q; i++)
    {
      count=count+lse(T[i],S);
    }
    printf("%d\n",count);
    
    return 0;
}

  /*線形探索*/
int lse(int key,int S[]){
   int i;
   for ( i = 0; i < n; i++)
   {
       if(key==S[i]){
           return 1;
       }
   }
   return 0;
    
}



Measured memory_bytes: 2108
N = input()
l = input().split()

N=int(N)
a=range(1,N+1)
b=range(1,N+1)
a=[i*N for i in a]
b=[i*N for i in b]
b.reverse()

c=0
for i in l:
	i=int(i)
	b[i-1]+=c 
	c+=1

for i in a:
	print(i,end=" ")
print("")
for i in b:
	print(i,end=" ")


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

int n,q;
int dat[300000];

void init(){
	int nn = 1;
	while(nn < n) nn *= 2;
	n = nn;
	for(int i = 0;i < n * 2 - 1;i++){
		dat[i] = 0;
	}
}

void update(int a,int b,int x,int k,int l,int r){
	if(r <= a || b <= l) return;
	if(a <= l && r <= b){
		dat[k] += x;
		return;
	}
	update(a,b,x,k * 2 + 1,l,(l + r) / 2);
	update(a,b,x,k * 2 + 2,(l + r) / 2,r);
}

int get(int i){
	i = i + n - 1;
	int sum = dat[i];
	while(i){
		i = (i - 1) / 2;
		sum += dat[i];
	}
	return sum;
}

int main(){
	cin >> n >> q;
	init();
	for(int i = 0;i < q;i++){
		int v;
		cin >> v;
		if(v == 0){
			int s,t,x;
			cin >> s >> t >> x;
			update(s - 1,t,x,0,0,n);
		}
		else{
			int x;
			cin >> x;
			cout << get(x - 1) << endl;
		}
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second
const int maxn = 100006; 

ll n, m; 
int a[maxn]; 
bool r[maxn]; 

int main() {
	cin>>n>>m;
	r[1] = true;  
	for (int i = 1; i <= n; ++i) a[i] = 1; 
	for (int i = 1; i <= m; ++i) {
		int x, y; 
		scanf( "%d%d", &x, &y ); 
		if (r[x]) {
			if (a[x] == 1) r[x] = false; 
			r[y] = true; 
		}
		a[x]--; a[y]++;
	}
	int ans = 0; 
	for (int i = 1; i <= n; ++i) 
		if (r[i]) ans++; 
	cout<<ans<<endl; 
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> V(M);
  for (int i = 0, s, c; cin >> s >> c; i++) V.at(i) = {s, c};

  // 条件に矛盾がないかチェック(入力例2)
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (V.at(i).first == V.at(j).first && V.at(i).second != V.at(j).second)
        return cout << -1 << "\n", 0;
    }
  }

  // 桁数から探索範囲を決めて(←いらない)全探索
  for (int i = 0; i < 1000; i++) {
    string tmp = to_string(i);
    if (tmp.size() != N) continue;
    for (int j = 0; j < M; j++) {
      if (tmp.at(V.at(j).first - 1) - '0' != V.at(j).second) goto NG;
    }
    return cout << i << "\n", 0;
    NG:;
  }
  cout << -1 << "\n";
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    n,m,p = map(int, input().split())
    edge = [[] for _ in range(m)]
    adj = [[] for _ in range(n)]
    for i in range(m):
        a,b,c = map(int, input().split())
        edge[i] = [a-1,b-1,-(c-p)]
        adj[b-1].append(a-1)

    visited = [0]*n
    visited[-1] = 1
    dq = deque([n-1])
    while dq:
        v = dq.popleft()
        for nv in adj[v]:
            if visited[nv] == 0:
                visited[nv] = 1
                dq.append(nv)
    
    def bellmanford(n, s, edge):
        inf = 10**17
        d = [inf] * n
        d[s] = 0
        for i in range(n):
            for a,b,c in edge:
                if d[a] != inf and d[b] > d[a]+c:
                    d[b] = d[a] + c
                    if i == n-1 and visited[b] == 1:
                        return -inf
        return -d[-1]

    res = bellmanford(n,0,edge)
    if res == -inf:
        print(-1)
    elif res < 0:
        print(0)
    else:
        print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 44140
#include <bits/stdc++.h>
#define ri rd<int>
#define rl rd<LL>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
using namespace std;
typedef long long LL;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

LL gcd(LL x, LL y) { while (y) swap(x %= y, y); return x; }

bool solve1(LL A, LL B, LL C, LL D) {
	if (A < B) return false;
	if (D < B) return false;
	if (C > B) return true;
	A -= B * ((A - C + B - 1) / B);
	assert(A <= C);
	if (A < 0) return false;
	return C >= B - gcd(B, D);
}

int main() {

	rep (cas, 1, ri()) {
		LL A = rl(), B = rl(), C = rl(), D = rl();
		puts(solve1(A, B, C, D) ? "Yes" : "No");
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int min(vector<int> a);
int max(vector<int> a);
long long sum(vector<int> a);

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < a.size(); i++){
		cin >> a[i];
	}
	cout << min(a) << " " << max(a) << " " << sum(a) << endl;
}

int min(vector<int> a){
	int ans = a[0];
	for(int i = 0; i < a.size(); i++){
		if(ans > a[i])
			ans = a[i];
	}
	return ans;
}

int max(vector<int> a){
	int ans = a[0];
	for(int i = 0; i < a.size(); i++){
		if(ans < a[i])
			ans = a[i];
	}
	return ans;
}

long long sum(vector<int> a){
	long long ans = 0;
	for(int i = 0; i < a.size(); i++){
		ans += a[i];
	}
	return ans;
}

Measured memory_bytes: 3280
/*


*/

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

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

#define endl '\n'
#define ld long double
#define ll long long
#define PI acos(-1.0)
#define OO 1e13
#define EPS 1e-12
#define MLOG 20
#define MAX 1* 100 * 1000+5
const int mod = 1e9 + 7;
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }


void fast(){
#ifndef ONLINE_JUDGE
	freopen("E:\\Competitve\\solving\\input.txt", "r", stdin);
	freopen("E:\\Competitve\\solving\\output.txt", "w", stdout);
#endif
}
string a, b;
int dp[3005][3005];

int main(){
	//fast();

	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	cin >> a >> b;
	
	for (int i = a.size() - 1; i >= 0; i--){
		for (int j = b.size() - 1; j >= 0; j--){
			dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
			if (a[i] == b[j]){
				dp[i][j] = max(dp[i][j], 1 + dp[i + 1][j + 1]);
			}
		}
	}
	int ka = 0, kb = 0;

	while (ka < a.size() && kb < b.size()){
		if (a[ka] == b[kb] && dp[ka][kb] == 1 + dp[ka + 1][kb + 1]){
			cout << a[ka];
			ka++, kb++;
		}
		else if (dp[ka][kb] == dp[ka + 1][kb])
			ka++;
		else kb++;
	}

	return 0;

}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){

    string s;
    cin >> s;
    vector<pair<ll, ll>> a;
    ll mi = 0;
    bool f = 0;
    if(s[0] == '<'){
        f = 0;
    }else{
        f = 1;
    }
    ll num = 0;
    rep(i, 0, s.length()){
        if(s[i] == '<'){
            if(f == 1){
                pair<ll, ll> tmp;
                f = 0;
                tmp.first = 1;
                tmp.second = num;
                a.push_back(tmp);
                num = 0;
            }
            num++;
        }else if(s[i] == '>'){
            if(f == 0){
                pair<ll, ll> tmp;
                f = 1;
                tmp.first = 0;
                tmp.second = num;
                a.push_back(tmp);
                num = 0;
            }
            num++;

        }
    }

    pair<ll, ll> tmp;
    tmp.first = f;
    tmp.second = num;
    a.push_back(tmp);

    ll sum = 0;
    rep(i, 0, a.size()){
        if(a[i].first == 0){
            rep(j, 0, a[i].second){
                sum += j;
            }
            if(i == a.size() - 1){
                sum += a[i].second;
            }
        }else if(a[i].first == 1){
            if(i == 0){
                sum += a[i].second;
            }else{
                sum += max(a[i-1].second, a[i].second);
            }
            rrep(j, a[i].second - 1, 0){
                sum += j;
            }
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 6776