akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

const int MAX = 3005;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 COM(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;
}

// youtube editorial
void solve() {
  int p;
  cin >> p;
  mod = p;
  vector<int> a(p);
  cin >> a;

  vector<int> b(p);
  COMinit();
  // f'(x) = f(x) + 1 - (x - i)^{p - 1}
  // これを, 対応する x の冪乗の係数に足す
  rep(i, p) {
    if (a[i] == 0) continue;
    (b[0] += 1) %= p;
    /*
    rep(j, p) {
      (b[j] += p - COM(p - 1, j) * modpow(-i, p-1 - j, p) % p) %= p;
    }*/
    int mul = 1;
    for (int j = p - 1; j >= 0; --j) {
      (b[j] += p - COM(p - 1, j) * mul % p) %= p;
      (mul *= -i) %= p;
      if (mul < 0) mul += p;
    }
  }
  cout << b << endl;
}


Measured memory_bytes: 512
import sys

input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = 10**5
    l = [0]*m
    for i in range(n):
        if a[i] >= 1:
            l[a[i]-1] += 1
        l[a[i]] += 1
        if a[i] < m-1:
            l[a[i]+1] += 1
    print(max(l))

if __name__ == '__main__':
    main()

Measured memory_bytes: 20788
N = int(input())
S = [input() for _ in range(N)]

alpha = [float('inf') for i in range(26)]

for s in S:
    d = [0 for _ in range(26)]
    for ss in s:
        d[ord(ss) - ord('a')] += 1
    for i in range(26):
        alpha[i] = min(alpha[i], d[i])

ans = ""
for i in range(26):
    ans += chr(i + ord('a')) * alpha[i]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
int main() {
    int n, a, b; cin >> n >> a >> b;
    vector<int> x(n); repeat (i,n) cin >> x[i];
    ll acc = 0;
    repeat (i,n-1) acc += min<ll>(b, a *(ll) (x[i+1] - x[i]));
    cout << acc << endl;
    return 0;
}


Measured memory_bytes: 768
#include "iostream"
#include <string>
using namespace std;
 
int main(){
 int N; 
 string S;
  
  cin >> N;
  cin >> S;
   
  for(int i=0; i<=S.size(); i++){
   
    for(int j=1; j<=N; j++){
     
      if(S[i] == 'Z') S[i]= 'A';
      else S[i]++;
      
    }
   
  }
  
  cout << S;
 
 if(S[0] == 'S' && S[1]=='A' && S[2]=='T') cout << 1; 
return 0;
  
}

Measured memory_bytes: 256
X, Y = map(int, input().split())
ans = 0
if X == 1:
    ans += 300000
elif X == 2:
    ans += 200000
elif X == 3:
    ans += 100000
else:
    ans += 0

if Y == 1:
    ans += 300000
elif Y == 2:
    ans += 200000
elif Y == 3:
    ans += 100000
else:
    ans += 0

if X == 1 and Y == 1:
    ans += 400000

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#define N 100000
#define NIL -1

typedef struct node{
  int parent;
  int left;
  int right;
}Node;

Node T[N];

int n,root;

int Calc_depth(int x){
  if(T[x].parent == NIL) return 0;
  return Calc_depth(T[x].parent) + 1;
}

void type_pri(int y){
  if(T[y].parent == NIL){
    printf("root");
    root = y;
  }
  else if((T[y].left == NIL) && (T[y].right == NIL)) printf("leaf");
  else printf("internal node");
}

int calc_deg(int z){
  int cnt = 0;
  if(T[z].left != NIL) cnt++;
  if(T[z].right != NIL) cnt++;
  return cnt;
}

int get_height(int i){
  int x = 0,y = 0;
  if(T[i].left == NIL && T[i].right == NIL) return 0;
  if(T[i].left != NIL) x = get_height(T[i].left) + 1;
  if(T[i].right != NIL) y = get_height(T[i].right) + 1;
  if(x > y) return x;
  else return y;
}

int get_sib(int i){
  if(T[i].parent == NIL) return NIL;
  if((T[T[i].parent].right != NIL) && (T[T[i].parent].right != i))  return T[T[i].parent].right;
  else if((T[T[i].parent].left != NIL) && (T[T[i].parent].left != i)) return T[T[i].parent].left;
  else return -1;
}

void print(void){
  int i;
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].parent,get_sib(i),calc_deg(i),Calc_depth(i),get_height(i));
    type_pri(i);
    printf("\n");
  }
}

void preParse(int u){
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u){
  if(u == NIL) return;
  inParse(T[u].left);
  printf(" %d",u);
  inParse(T[u].right);
}

void postParse(int u){
  if(u == NIL) return;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d",u);
}



int main()
{
  int i,id,n1,n2;
  scanf("%d",&n);
  for(i = 0; i < n;i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  for(i = 0; i < n;i++){
    scanf("%d%d%d",&id,&n1,&n2);
    T[id].left = n1;
    T[id].right = n2;
    if(n1 != NIL && n2 != NIL){
      T[n1].parent = id;
      T[n2].parent = id;
    }
    else if(n1 == NIL && n2 != NIL) T[n2].parent = id;
    else if(n1 != NIL && n2 == NIL) T[n1].parent = id;
  }
  
  for(i = 0; i < n; i++){
    if(T[i].parent == NIL) root = i;
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;    
}



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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a;
    cin >> a;
    if (a >= 30)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3632
K = int(input())

if K<=9:
    print(K)
    exit()

K-=9

def append_ll(array, t, ll):
    global k
    
    array[t].append(ll)
    k += 1
    if k==K:
        print(ll)
        exit()

k = 0
N = 2
lunlun = [None, [None, [1],[2],[3],[4],[5],[6],[7],[8],[9]]]
# lunlun[s][t] := list of s digits lunlun numbers with first number t
while True:
    lunlun_N = [[] for _ in range(10)]

    p = 10**(N-1)
    append_ll(lunlun_N, 1, p)
    
    for d in range(1, N):
        for ll in lunlun[d][1]:
            append_ll(lunlun_N, 1, p+ll)

    for ll in lunlun[N-1][2]:
        append_ll(lunlun_N, 1, p+ll)
    
    for x in range(2, 10):
        for ll in lunlun[N-1][x-1]:
            append_ll(lunlun_N, x, x*p+ll)
            
        for ll in lunlun[N-1][x  ]:
            append_ll(lunlun_N, x, x*p+ll)

        if x==9: continue
        for ll in lunlun[N-1][x+1]:
            append_ll(lunlun_N, x, x*p+ll)

    N+=1
    lunlun.append(lunlun_N)


Measured memory_bytes: 7156
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

//Eratosthenes O(N)
vector<bool> Eratosthenes(int N) {
    vector<bool> res(N + 1, true);
    res[0] = res[1%(N+1)] = false;
    for (int i = 1; i*i <= N; i++) if (res[i]) for (int j = 2 * i; j <= N; j += i) res[j] = false;
    return res;
}


int main(void){
	
	VB prime = Eratosthenes(100000);
	VI like2017(100000 + 1, 0);
	for (int i = 3; i < 100000 + 1; i += 2) if ((prime[i]) && (prime[(i + 1) / 2])) like2017[i] = 1;
	for (int i = 3; i < 100000 + 1; i++) like2017[i] += like2017[i - 1];
	
	int Q;
	cin >> Q;
	
	VI l(Q), r(Q);
	REP(i, Q) cin >> l[i] >> r[i];
	REP(i, Q) cout << like2017[r[i]] - like2017[l[i] - 1] << endl;
	return 0;
}





Measured memory_bytes: 1792
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]
 
setrecursionlimit(1000000)
INF = 10**10
 
(N, M) = reads()
 
edges = [[] for _ in range(N)]
 
for _ in range(M):
    (L, R, D) = reads()
    (L, R) = (L-1, R-1)
    edges[L].append((R, D))
    edges[R].append((L, -D))
 
visited = [False] * N
place = [None] * N
 
def walk(i):
    if visited[i]:
        return (place[i], place[i])
    visited[i] = True
    (m, M) = (INF, -INF)
    for (j, d) in edges[i]:
        if visited[j] and place[j] != place[i] + d:
            # print("v = ", visited)
            # print("p = ", place)
            print("No")
            exit()
        place[j] = place[i] + d
        (x, y) = walk(j)
        (m, M) = (min(m, x), max(M, y))
    return (m, M)
 
for i in range(N):
    if not visited[i]:
        place[i] = 0
        (m, M) = walk(i)
        if M - m > 10**9:
            # print("(m, M) = ", (m, M))
            print("No")
            exit()
 
print("Yes")

Measured memory_bytes: 131816
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
    		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		
      	//入力された文字数と同じだけxを出力
		for (int i=1; i<=s.length(); i++){
			System.out.print("x");
		}
		
    	}
  
}

Measured memory_bytes: 35780
def main():
    n = int(input())
    s = input()
    r_set, g_set, b_set = set(), set(), set()

    for i, c in enumerate(s):
        if c == "R":
            r_set.add(i)
        elif c == "G":
            g_set.add(i)
        elif c == "B":
            b_set.add(i)

    cnt = 0
    for i in range(n):
        for j in range(i + 1, n):
            k = 2 * j - i

            if i in r_set and j in g_set and k in b_set:
                cnt += 1
            elif i in r_set and j in b_set and k in g_set:
                cnt += 1
            elif i in g_set and j in r_set and k in b_set:
                cnt += 1
            elif i in g_set and j in b_set and k in r_set:
                cnt += 1
            elif i in b_set and j in r_set and k in g_set:
                cnt += 1
            elif i in b_set and j in g_set and k in r_set:
                cnt += 1

    print(len(r_set) * len(g_set) * len(b_set) - cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73920
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;

bool check(const vector<vector<pair<int, int>>>&humans, int x, int y) {
	for (int i = 0; i < 4; ++i) {
		auto it=find(humans[i].begin(),humans[i].end(),make_pair(x,y));
		if(it!=humans[i].end())return false;
	}
	return true;
}
int dx[] = { -1,0,1,0,0 };
int dy[] = { 0,1,0,-1,0 };

template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}

};
struct sale {
	int id;
	int d;
	int s;
	int e;
};

struct aa {
	int flag;
	int x;
	int y;
	int cost;
};

bool operator <(const vector<int>&l, const vector<int>&r) {
	for (int i = 0; i < l.size(); ++i) {
		if(l[i]<r[i])return true;
		else if(l[i]>r[i])return false;
	}
	return false;
}
int solve(vector<int>haves, vector<int>nums) {
	map<pair<vector<int>,int>,int>mp;
	mp[make_pair(nums,0)]=1;

	int ans=1;
	queue<pair<vector<int>,int>>que;
	que.push(make_pair(nums,0));
	while (!que.empty()) {
		auto atop(que.front());
		que.pop();

		int x=atop.second;
		vector<int>v(atop.first);

		int cost=mp[make_pair(atop.first,atop.second)];
		ans=max(ans,cost);
		for (int i = 0; i < haves.size(); ++i) {
			if (v[i]){
				if (x+haves[i] >= 11) {

				}
				else if (x + haves[i] == 10) {
					v[i]--;
					auto np=make_pair(v,0);
					if (mp[np] < cost + 1) {
						mp[np]=cost+1;
						que.push(np);
					}
					v[i]++;
				}
				else {
					v[i]--;
					auto np=make_pair(v,x+haves[i]);
					if (mp[np] < cost) {
						mp[np]=cost;
						que.push(np);
					}
					v[i]++;
				}
			}
		}
	}
	return ans-1;
}
int dfs(const int now, const int pre,const vector<vector<int>>&edges, vector<int>&memo) {
	if(memo[now])return false;
	else {
		memo[now]=true;
		for (auto e : edges[now]) {
			if (e != pre) {
				int k=dfs(e,now,edges,memo);
				if(!k)return false;
			}
		}
	}
	return true;
}
int main()
{
	while (true) {
		int N,M;cin>>N>>M;
		if(!N)break;
		vector<vector<int>>edges(N);
		for (int i = 0; i < M; ++i) {
			int a,b;cin>>a>>b;
			edges[a-1].push_back(b-1);
			edges[b-1].push_back(a-1);
		}
		bool ok = all_of(edges.begin(), edges.end(), [](const vector<int>&v) {return v.size() <= 2; });

		vector<int>memo(N);
		for (int i = 0; i < N; ++i) {
			if (!memo[i]) {
				int k=dfs(i,-1,edges,memo);
				if(!k)ok=false;
			}
		}
		if(ok)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;

using ll = long long; using VI=vector<int>; using pii=pair<int, int>; using VL=vector<ll>; const int MD=1e9+7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VL a(n), dp(k+2);
	rep(i, n) cin >>a[i];
	dp[0] = 1;
	
	rep(i, n){
		VL np(k+2), sum(k+3, 0);
		rep(j, k+1) sum[j+1] = (dp[j] + sum[j]) %MD;
		rep(j, k+1) np[j] = (sum[j+1] - sum[max(0LL, j-a[i])] + MD ) %MD;
		swap(dp, np);
	}
	cout <<dp[k] <<"\n";
	return 0;
}



Measured memory_bytes: 5580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,i,p,q;
    map<int,int>a;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>p>>q;
        a[p]++;
        a[q]++;
    }
    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }
}






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

long long int a[500],n;

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		long long int ans=0;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n-i-1;j++){
				if(a[j]>a[j+1]){
					swap(a[j],a[j+1]);
					ans++;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main()
{
	int n,i,s=0,x=0;
	cin>>n;
	int a[n];
	for (i=0; i<n; i++)
	{
		cin>>a[i];
		if (a[i]%2==0)
		{
			x++;
			if (a[i]%3==0 || a[i]%5==0)
			{
				s++;
			}
		}
	}
	if (x==s)
	  cout<<"APPROVED";
	else
	  cout<<"DENIED";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
const int N(2e5 + 5);
int n, a[N], cnt, res;
bool bila[N];
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = n; i >= 1; --i) {
        cnt = 0;
        for (int j = i + i; j <= n; j += i)
            cnt += bila[j];
        if ((cnt & 1) != (a[i] & 1))
            bila[i] = true, ++res;
    }
    cout << res << '\n';
    for (int i = 1; i <= n; ++i)
        if (bila[i])
            cout << i << '\n';
    PLEC
}


Measured memory_bytes: 4516
#include<stdio.h>
int main(void) 
{
    double hankei,menseki,ensyuu;

    scanf("%lf", &hankei);

    menseki = hankei * hankei*3.141592653589;
    ensyuu = 2 * 3.141592653589*hankei;

    printf("%f %f ",menseki,ensyuu);
    
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  string S, T;
  cin >> S >> T;
  int N = S.size(), M = T.size();
  S = S + S;
  vector<int> vec[27];
  for(int i=0;i<N*2;i++){
    vec[S[i]- 'a'].push_back(i);
  }
  int ans = 0, iti = -1;
  for(int i=0;i<M;i++){
    int c = upper_bound(vec[T[i] - 'a'].begin(), vec[T[i] - 'a'].end(), iti) - vec[T[i] - 'a'].begin();
    if(c == vec[T[i] - 'a'].size()){
      cout << -1 << endl;
      return 0;
    }
    ans += vec[T[i] - 'a'][c] - iti;
    iti = vec[T[i] - 'a'][c] % N;
  }
  cout << ans << endl;

}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }

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

    int N, K;
    std::cin >> N >> K;
    std::vector<int> L(N);

    REP(i, N) {
        std::cin >> L[i];
    }

    RSORT(L);

    std::cout << accumulate(L.begin(), L.begin() + K, 0LL) << std::endl;

    return 0;
}


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

using namespace std;

int main() {
  int N, M;
  vector<int> list;
  
  cin >> N >> M;
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int _in;
    
    cin >> _in;
    
    sum += _in;
    list.push_back(_in);
  }
  
  int index = 0;
  for (int i = 0; i < N; i++) {
      if (list[i] * 4 * M >= sum) {
          index++;
      }
  }
  
  cout << (index >= M ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] ch =  s.toCharArray();
		for (int i = 0; i < s.length(); i++) {
			if (i % 2 == 0) {
				System.out.print(ch[i]);
			}
		}
		System.out.println("");
 	}
}

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

int main() {
    int N;
    cin >> N;
    vector<int> inp(N);
    for (int i = 0; i < N; i++){
        cin >> inp.at(i);
    }
    int m, M, max_pro, pro;
    m = inp.at(0);
    max_pro = -2000000000;
    for (int i = 1; i < N; i++){
        max_pro = max(max_pro, inp.at(i) - m);
        m = min(m, inp.at(i));
    }
    cout << max_pro << endl;

}


Measured memory_bytes: 3580
#include <stdio.h>

int main() {
	int W = 0;
	int H = 0;
	int x = 0;
	int y = 0;
	int r = 0;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (r <= x  && r <= y && r <= W - x && r <= H - y) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 1824
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	while(cin>>a>>b>>c)
	{
		if(a%2!=0||b%2!=0||c%2!=0)cout<<"0"<<endl;
		else if(a==b&&b==c){cout<<"-1"<<endl;}
		else
		{
		    int count=0;
		    for(;;)
		    {
			    int t1,t2,t3;
			    t1=(b+c)/2;t2=(a+c)/2;t3=(a+b)/2;
			    a=t1;b=t2;c=t3;
			    count++;
			    if(a%2!=0||b%2!=0||c%2!=0)
			    {  
				    cout<<count<<endl;break;
			    }
		    }   
		}
	}
	return 0;
}

Measured memory_bytes: 256
module Point = struct

  type t = { x : float; y : float }

  let make x y = { x; y }

  let equal_p a b = abs_float (a.x -. b.x) < 1e-10 && abs_float (a.y -. b.y) < 1e-10

  let sum a b = { x = a.x +. b.x; y = a.y +. b.y }

  let diff a b = { x = a.x -. b.x; y = a.y -. b.y }

  let multi p k = { x = p.x *. k; y = p.y *. k }

  let div p k = { x = p.x /. k; y = p.y /. k }

  let norm p = p.x *. p.x +. p.y *. p.y

  let abs p = norm p |> sqrt

  let dot a b = a.x *. b.x +. a.y *. b.y

  let cross a b = a.x *. b.y -. a.y *. b.x

  let project p1 p2 p =
    let base = diff p2 p1 in
    dot (diff p p1) base /. norm base
    |> multi base
    |> sum p1

  let reflect p1 p2 p =
    multi (diff (project p1 p2 p) p) 2.
    |> sum p

  let parallel_p (p0, p1) (p2, p3) =
    let a = diff p0 p1 in
    let b = diff p2 p3 in
    cross a b = 0.

  let orthogonal_p (p0, p1) (p2, p3) =
    let a = diff p0 p1 in
    let b = diff p2 p3 in
    dot a b = 0.

end

module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_fs () = read_line () |> split_on_char ' ' |> List.map float_of_string

end

open Point

let () =
  let q = read_int () in
  for _ = 0 to q - 1 do
    match IO.read_fs () with
    | x0 :: y0 :: x1 :: y1 :: x2 :: y2 :: x3 :: y3 :: _ ->
      let s = (make x0 y0, make x1 y1) in
      let t = (make x2 y2, make x3 y3) in
      print_endline
        (if parallel_p s t then "2" else if orthogonal_p s t then "1" else "0")
    | _ -> assert false
  done

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    using Tile = array<int, 4>;
    auto normalize = [&](Tile &a) {
        Tile b = a;
        for (int i = 1; i < 4; i++) {
            Tile c;
            for (int j = 0; j < 4; j++) c[j] = b[(i+j)%4];
            if (c < a) a = c;
        }
    };
    auto type = [&](Tile &a) {
        if (a[0] == a[2] && a[1] == a[3]) {
            if (a[0] == a[1]) return 4;
            else return 2;
        }
        return 1;
    };
    vector<Tile> v(n);
    map<Tile, long long> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) cin >> v[i][j];
        normalize(v[i]); m[v[i]]++;
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        m[v[i]]--;
        for (int j = i+1; j < n; j++) {
            m[v[j]]--;
            for (int r = 0; r < 4; r++) {
                vector<Tile> w;
                long long curr = 1;
                for (int c = 0; c < 4; c++) {
                    Tile a = {v[i][(c+1)%4], v[i][c], v[j][(r-c+5)%4], v[j][(r-c+4)%4]};
                    normalize(a); w.emplace_back(a);
                    curr *= m[a] * type(a);
                    m[a]--;
                }
                for (auto &x: w) m[x]++;
                ans += curr;
            }
            m[v[j]]++;
        }
        m[v[i]]++;
    }
    cout << ans / 3 << "\n";
    return 0;
}

Measured memory_bytes: 80128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  //  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if(!( 0 <= key && key <= 2000000000)){printf("error") ;}
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++;
      }
      size--;
    }
    if ( size > 1000000 ) { printf("error"); }
  }


  if(!( np+nd <= 2000000)){printf("error") ;}
  if(!( nd <= 20)){printf("error") ;}
  printList();


  return 0;
}

Measured memory_bytes: 34976
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  vector<int> w;
  rep(i,N){
    int x = i+1;
    int y = v[i];
    w.push_back(y-x);
  }

  sort(ALLOF(w));
  int md = w[w.size()/2];

  ll dret = 0;
  rep(i,N){
    dret += abs( v[i] - (md + i+1) );
  }

  cout << dret << endl;
  
  return 0;
}



Measured memory_bytes: 2548
#include<stdio.h>
#include<stdlib.h>
 
struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
 
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum (Node x ){
 
}
 
Node treeSearch (Node u, int k ){
    if (u == NIL || u->key == k ) return u;
    else
    if (u->key < k ){
        return treeSearch (u->right, k );
    }else{
        return treeSearch (u->left, k );
    } // end if 
}
 
Node treeSuccessor (Node x ){
 
}
 
void treeDelete (Node z ){
    Node y; // node to be deleted
    Node x; // child of y
}
 
void insert (int k ){
    Node y = NIL;
    Node x = root;
    Node z;
 
    z = malloc (sizeof (struct node ) );
    z->key = k;
    z->left = NIL;
    z->right = NIL;
 
    if (x == NIL ){
        root = z;
    }else{
        do{
            if (x->key < k ){
                y = x->right;
            }else{
                y = x->left;
            } // end if
 
            if (y != NIL ){
                y->parent = x;
            }else{
                if (x->key < k )
                    x->right = z;
                else
                    x->left = z;
            } // end if
            x = y;
        }while (x != NIL ); // end while
    } // end if
}
 
void inorder (Node u ){
    if (u == NIL ) return;
    inorder (u->left );
    printf (" %d", u->key );
    inorder (u->right );
}
 
void preorder (Node u ){
    if (u == NIL ) return;
    printf (" %d", u->key );
    preorder (u->left );
    preorder (u->right );
}
 
int main()
{
    int n, i, x;
    char com[20];
 
    root = NIL;
    scanf ("%d", &n );
    for (i = 0; i < n; i++ ){
        scanf ("%s", com );
        if (com[0] == 'i' ){    // case insert 
            scanf ("%d", &x );
            insert (x );
        }else
        if (com[0] == 'p' ){ // case print
            inorder (root );
            printf ("\n" );
            preorder (root );
            printf ("\n" );
        }else
        if (com[0] == 'f' ){    // case find
            scanf ("%d", &x );
            Node t = treeSearch (root, x );
            if ( t != NIL ) printf ("yes\n" );
            else printf ("no\n" );
        } // end if
    } // end for
 
    return 0;
}



Measured memory_bytes: 20448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807


int main()
{
ll n,a,b;
cin >> n>>a>>b;
ll h[n] = {};
rep(i, n)
{
    cin >> h[i];
}
sort(h,h+n);
int lower=0,upper=h[n-1];
int seenow,oklowest;
bool ok2butan;
while(true){
seenow=(lower+upper)/2;

//todo:seenowに対して処理
//条件を満たすならok2butan=trueにする
ok2butan=true;
ll count=0;
rep(i,n){
    if(h[i]-b*seenow>0)count+=(h[i]-b*seenow-1)/(a-b)+1;
    if(count>seenow){ok2butan=false;break;}
}


if(ok2butan){
    upper=seenow;
    if(upper==lower+1){oklowest=seenow;break;}
    }
else {
    lower=seenow;
    if(upper==lower+1){oklowest=seenow+1;break;}
    }
}

cout << oklowest << endl;
return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int main()
{
	int n;char a[100];bool book=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf(" %c",&a[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]=='Y')
		book=1;
	}
	if(book==1)
	printf("Four");
	else
	printf("Three");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=3e3+5;
const int mod=1e9+7;
const ll oo=1e18+5;

int mul(int a,int b){
	return (ll)a*b%mod;
}

int poww(int a,int b){
	int r=1;
	while(b){
		if(b%2){
			r=mul(a,r);
		}
		a=mul(a,a);
		b/=2;
	}
	return r;
}

int my_inv(int a){
	return poww(a,mod-2);
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n;
	cin>>n;
	map<int,int> ans;
	vector<int> a(n);
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		a[i]=x;
		map<int,int> cnt;
		for(int i=2;i*i<=x;++i){
			while(x%i==0){
				++cnt[i];
				x/=i;
			}
		}
		if(x!=1) ++cnt[x]; 
		for(pair<int,int> p:cnt){
			ans[p.first]=max(ans[p.first],p.second);
		}
	}
	int lcm=1;
	for(pair<int,int> p:ans){
		int prime=p.first;
		int k=p.second;
		for(int i=0;i<k;++i){
			lcm=mul(lcm,prime);
		}
	}
	cerr<<lcm<<endl;
	int res=0;
	for(int x:a){
		//~ cout<<"my inv : "<<my_inv(x)<<endl;
		res=(res+mul(lcm,my_inv(x)))%mod;
	}
	cout<<res;
	return 0;
}
        


Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;
    int l = S.length();
    int x, y;
    x = y = 0;
    for (int i = 0; i < l; i++) {
        if (i % 2 == 0) {
            if (S[i] == '0') {
                y++;
            } else {
                x++;
            }
        } else {
            if (S[i] == '0') {
                x++;
            } else {
                y++;
            }
        }
    }
    printf("%d", min(x, y));
}


Measured memory_bytes: 512
n = int(input())
s = [input() for i in range(n)]
m = 0
a = 0
r = 0
c = 0
h = 0
for j in range(n):
    if s[j][0] == "M":
        m += 1
    elif s[j][0] == "A":
        a += 1
    elif s[j][0] == "R":
        r += 1
    elif s[j][0] == "C":
        c += 1
    elif s[j][0] == "H":
        h += 1
print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)

Measured memory_bytes: 9752
import fractions

n, x = map(int, input().split())
l = list(map(int, input().split()))

l.append(x)
l.sort()

l_dif = [l[i+1]-l[i] for i in range(n)]

ans = l_dif[0]

for i in range(1, n):
    ans = fractions.gcd(ans, l_dif[i])

print(ans)

Measured memory_bytes: 16284
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 300000;

string s, t;

int check(int j)
{
    int c = 0;
    for (int i = j; i < j + t.length(); i++)
        c += s[i] != t[i - j];
    return c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> s >> t;
    
    int ans = 1e9;
    for (int i = 0; i <= s.length() - t.length(); i++)
        ans = min(ans, check(i));
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void) {
    int around = 0;
    int N = 0;
    scanf("%d %d", &around, &N);
    
    int house[N];
    for (int i=0; i<N; i++) {
        scanf("%d", &house[i]);
    }

    int dist[N];
    int max_dist = 0;

    for (int i=0; i<N-1; i++) {
        dist[i] = house[i+1] - house[i];
        if (max_dist < dist[i]) {
            max_dist = dist[i];
        }
    }
    dist[N-1] = around - house[N-1] + house[0];
    if (max_dist < dist[N-1]) {
        max_dist = dist[N-1];
    }
    
    printf("%d\n", around - max_dist);

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"


template <class T,
         class Container = std::vector<T>,
         class Compare = less<typename Container::value_type>>
         class priority_queue
{
  Container v;
  int size = 0;
  public:
  void push(T val) {
    int index = size;
    v.push_back(val);
    ++size;

    for (int parent = (index-1) / 2;
        parent >= 0 && Compare()(v[parent], v[index]);
        index = parent, parent = (index-1)/2) {
      T tmp = v[index];
      v[index] = v[parent];
      v[parent] = tmp;
    }
  }
  void pop() {
    v[0] = v[size-1];
    v.pop_back();
    --size;

    for (int index = 0, l = 1, r = 2;
        l < size && (Compare()(v[index], v[l]) || Compare()(v[index], v[r]));
        l = index * 2 + 1, r = index * 2 + 2) {
      int target = l;
      if (Compare()(v[index], v[r])) target = r;
      if (Compare()(v[index], v[l]) && Compare()(v[index], v[r]))
        if (Compare()(v[r], v[l])) target = l;
        else target = r;

      T tmp = v[index];
      v[index] = v[target];
      v[target] = tmp;
      index = target;
    }
  }
  T top() { return v.front(); }
  bool empty() { return size == 0; }
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; in(N); in(M);

  priority_queue<int> A;
  rep(i, N) {
    int a; in(a);
    A.push(a);
  }
  rep(i, M) {
    int p = A.top(); A.pop();
    A.push(p / 2);
  }
  ll sum = 0;
  while (!A.empty()) {
    int p = A.top(); A.pop();
    sum += p;
  }
  out(sum);

  return 0;
}


Measured memory_bytes: 892
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int h, w;
string s[100];

int dp[100][100][2];

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

	cin >> h >> w;
	rep(i,h) {
		cin >> s[i];
	}
	rep(i, h)rep(j, w)rep(k, 2)dp[i][j][k] = INF;

	if (s[0][0] == '.') dp[0][0][0] = 0;
	else dp[0][0][1] = 1;

	int dy[] = { 1,0 };
	int dx[] = { 0,1 };
	rep(y, h)rep(x, w)rep(f, 2) {
		int v = dp[y][x][f];
		if (v == INF)continue;
		rep(d, 2) {
			int ny = y + dy[d];
			int nx = x + dx[d];
			if (ny == h || nx == w)continue;

			if (s[ny][nx] == '.') {
				dp[ny][nx][0] = min(dp[ny][nx][0], v);
			}
			else {
				if (f == 0) {
					dp[ny][nx][1] = min(dp[ny][nx][1], v + 1);
				}
				else {
					dp[ny][nx][1] = min(dp[ny][nx][1], v);
				}
			}
		}
	}
	cout << min(dp[h - 1][w - 1][0], dp[h - 1][w - 1][1]) << endl;


	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int b = sc.nextInt();
		int a = (int)Math.ceil(b/1.08);
		if(taxout(b,a) != 0)System.out.println(a);
		else System.out.println(":(");
	}
	
	static int taxin(int a) {
		int b = (int)(a*1.08);
		return b;
	}
	
	static int taxout(int b, int a) { //aが元の値
		if(b == taxin(a)) return a;
		else return 0;
	}
}

Measured memory_bytes: 23636
from collections import deque
N,Q = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
A = [0 for _ in range(N+1)]
for _ in range(Q):
    p,x = map(int,input().split())
    A[p] += x
que = deque([1])
hist = [0 for _ in range(N+1)]
hist[1] = 1
while que:
    i = que.popleft()
    for j in G[i]:
        if hist[j]==0:
            A[j] += A[i]
            que.append(j)
            hist[j] = 1
print(*A[1:])

Measured memory_bytes: 119648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <queue>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(m), b(m), c(m);
    REP(i, 0, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = c[i] - p;
    }
    const ll inf = 1LL << 60;
    auto Cost = make_v(n, -inf);
    Cost[0] = 0;
    REP(i, 0, 2 * n) {
        REP(j, 0, m) {
            if (Cost[a[j]] == -inf) continue;
            if (chmax(Cost[b[j]], Cost[a[j]] + c[j]) && i >= n) {
                Cost[b[j]] = inf;
            }
        }
    }
    if (Cost[n - 1] >= inf) {
        cout << -1 << endl;
    } else {
        cout << max(Cost[n - 1], 0LL) << endl;
    }

    return 0;
}


Measured memory_bytes: 512
N = int(input())
heights = list(map(int, input().split()))

ans = heights[0]
sa =[0 for _ in range(N-1)]

for i in range(N-1):
    sa[i] += heights[i+1] - heights[i]

for i in range(N-1):
    if sa[i] > 0:
        ans += sa[i]

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<string>
using namespace std;
#define ll long long int
#define maxn 100005

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


vector<int> adj[maxn];


vector<int> dist(maxn, 0);
vector<int> indegree(maxn, 0);
vector<bool> vis(maxn, 0);

void dfs(int i) {
	vis[i] = 1;
	for (int x : adj[i]) {
		dist[x] = max(dist[x], 1 + dist[i]);
		indegree[x]--;
		if (indegree[x] == 0)dfs(x);
	}
}

int main() {
	_init();

	int n, m;
	cin >> n >> m;
	for (int i = 0, a, b; i < m; ++i)
	{
		cin >> a >> b, a--, b--;
		adj[a].push_back(b);
		++indegree[b];
	}

	int maxDepth = 0;
	for (int i = 0; i < n; i++) {
		if (!vis[i] && indegree[i] == 0)
		{
			dfs(i);
		}
	}

	for (int i = 0; i < n; ++i)
	{
		maxDepth = max(maxDepth, dist[i]);
	}

	cout << maxDepth << endl;

	return 0;
}









Measured memory_bytes: 14220
<?php
while (true) {
    list($a, $operator, $b) = explode(' ', trim(fgets(STDIN)));
    switch ($operator) {
        case '+':
            echo $a + $b, PHP_EOL;
            break;
        case '-':
            echo $a - $b, PHP_EOL;
            break;
        case '*':
            echo $a * $b, PHP_EOL;
            break;
        case '/':
            echo floor($a / $b), PHP_EOL;
            break;
        case '?':
            exit;
            break;
    }
}

Measured memory_bytes: 15352
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x,int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
		return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
signed main() {
	int k;
	cin >> k;
	if (k % 2 == 1)cout << k / 2 * (k / 2 + 1) << endl;
	else cout << k / 2 * (k / 2) << endl;
	ll
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> Pair;

const int N = 100005;
const ll INF = INT_MAX - 1;

ll n, w, p[N], c[N], dp[105][N];

ll get(int in, int wg){
  if(in == n) return 0;
  if(dp[in][wg] != -1) return dp[in][wg];
  ll ans = get(in + 1, wg);
  if(p[in] + wg <= w) ans = max(ans, c[in] + get(in + 1, wg + p[in]));
  return dp[in][wg] = ans;
}

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

  cin >> n >> w;
  for(int i = 0; i < n; i++) cin >> p[i] >> c[i];
  memset(dp, -1, sizeof dp);
  cout << get(0, 0) << endl;
}


Measured memory_bytes: 82304
//============================================================================
// Name        : ITP_1_11_D.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

class dice {
public:
    int getTopFace(void);
    int getBottomFace(void);
    void rotate(char dir);
    void setFaceNumber(int *number);
    bool compareDice(dice d2);
private:
    int face[6];
    int getFaceIndex(int number);
    bool compareDiceFace(dice d2);
};

int dice::getTopFace(void) {
    return face[0];
}

int dice::getBottomFace(void) {
    return face[5];
}

int dice::getFaceIndex(int number) {
    int i;
    for(i=0; i<6; ++i) {
        if (face[i]==number) {
            return i;
        }
    }
    return -1;
}

void dice::rotate(char dir) {
    int temp;
    switch(dir) {
    case 'N' :
        temp=face[0];
        face[0]=face[1];
        face[1]=face[5];
        face[5]=face[4];
        face[4]=temp;
        break;
    case 'S' :
        temp=face[0];
        face[0]=face[4];
        face[4]=face[5];
        face[5]=face[1];
        face[1]=temp;
        break;
    case 'W' :
        temp=face[0];
        face[0]=face[2];
        face[2]=face[5];
        face[5]=face[3];
        face[3]=temp;
        break;
    case 'E' :
        temp=face[0];
        face[0]=face[3];
        face[3]=face[5];
        face[5]=face[2];
        face[2]=temp;
        break;
    }
}

void dice::setFaceNumber(int *number) {
    for(int i=0; i<6; ++i) {
        face[i]=*(number+i);
    }
}

bool dice::compareDiceFace(dice d2) {
    for(int i=0;i<6;++i) {
        if(d2.face[i]!=face[i]) {
            return false;
        }
    }
    return true;
}

bool dice::compareDice(dice d2) {
    for(int j=0;j<3;++j) {
        if(compareDiceFace(d2)) return true;
        for(int i=0;i<3;++i) {
            d2.rotate('E');
            if(compareDiceFace(d2)) return true;
        }
        d2.rotate('E');
        d2.rotate('N');
        d2.rotate('N');
        if(compareDiceFace(d2)) return true;
        for(int i=0;i<3;++i) {
            d2.rotate('E');
            if(compareDiceFace(d2)) return true;
        }
        d2.rotate('N');
    }
    return false;
}

int main() {
    int n,num[6];
    vector<dice> d;
    bool ans=true;

    cin >> n;
    d.resize(n);

    for(int i=0; i<n; ++i) {
    	for(int j=0; j<6; ++j) {
    		cin >> num[j];
    	}
    	d[i].setFaceNumber(num);
    }

    for(int i=0; i<n-1; ++i) {
    	for(int j=i+1; j<n; ++j) {
    		ans = (ans && !(d[i].compareDice(d[j])));
    	}
    }
    cout << (ans?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 3088