akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//頂点数がn,枝数がm
//bellman_ford bf(n,m);
//適宜add_edge
//bf.comp(出発点)でdに最短路長が入る
//負の有向閉路には3種類存在することに注意する

template<typename T> class BellmanFord {
public:
  struct edge {
    int from, to;
    T cost;
  };
  int V;
  T inf;
  vector<T> d;
  vector<edge> es;
  BellmanFord(int node_size) : V(node_size), inf(numeric_limits<T>::max() / 2), d(V, inf) {}
  void add(int from, int to, T cost) {
    es.push_back((edge) {from, to, cost});
  }
  //sからの最短路長およびsからたどり着ける負の閉路の検出(trueなら負の閉路が存在する)
  bool solve(int s) {
    int cnt = 0;
    d[s] = 0;
    while (cnt < V) {
      bool update = false;
      for (auto& e : es) {
        if (d[e.from] != inf && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          update = true;
        }
      }
      if (!update) break;
      cnt++;
    }
    return (cnt == V);
  }
  //すべての負の閉路の検出(trueなら負の閉路が存在する)
  bool find_negative_loop() {
    fill(d.begin(), d.end(), (T)0);
    int cnt = 0;
    while (cnt < V) {
      bool update = false;
      for (auto& e : es) {
        if (d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          update = true;
        }
      }
      if (!update) break;
      cnt++;
    }
    return (cnt == V);
  }
  // s, t 間の最短距離が非有界
  bool shortest_path_infinite(int s, int t) {
    d[s] = 0;
    for (int i = 0; i < 2 * V - 1; i++) {
      for (auto& e : es) {
        if (d[e.from] != inf && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          if (i >= V-1) {
            if (e.to == t) return true;
            d[e.to] = -inf;
          }
        }
      }
    }
    return false;
  }
};

int main() {
  int N, M, P;
  cin >> N >> M >> P;
  BellmanFord<long> BF(N);
  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    BF.add(--A, --B, P - C);
  }
  if (BF.shortest_path_infinite(0, N - 1)) return cout << -1 << "\n", 0;
  cout << max(0L, -BF.d.at(N - 1)) << "\n";
}

Measured memory_bytes: 512
#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"
#include "cassert"
#include "ctime"
 
using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  
  int counter = 0;
  for (int X=0; X<=K; X++) {
    for (int Y=0; Y<=K; Y++) {
      int Z = S - X - Y;
      if (0 <= Z & Z <= K) counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()

Measured memory_bytes: 14180
package main

import (
	"fmt"
)

func main() {
	var (
		n, q, l, r int
		s string
	)
	fmt.Scan(&n, &q, &s)

	t := make([]int, n)

	for i := 1; i < n; i++ {
		t[i] = t[i-1]
		if s[i-1] == 'A' && s[i] == 'C' {
			t[i]++
		}
	}

	for i := 0; i < q; i++ {
		fmt.Scan(&l, &r)
		fmt.Println(t[r-1] - t[l-1])
	}
}


Measured memory_bytes: 7684
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);

int n, m;
string s;

bool f(int pos, vint& history)
{
    if (pos <= m)
    {
        history.push_back(pos);
        return true;
    }
    for (int i = m; i > 0; --i)
    {
        if (s[pos - i] == '0')
        {
            history.push_back(i);
            return f(pos - i, history);
        }
    }
    return false;
}

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

    vint history;
    if (f(n, history))
    {
        //cout << "history.length " << history.size() << endl;
        auto rbegin = history.rbegin();
        auto rend = history.rend();
        RepItr(it, rbegin, rend)
        {
            if (it != rbegin)
            {
                cout << " ";
            }
            cout << (*it);
        }
        cout << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 7416
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <string>
using namespace std;
typedef struct{
    long long int B;
    long long int E;
}Robot;
int cmp(Robot A,Robot B){
    return A.B<B.B;
}
Robot r[100003];

int main(){
    int N;
    cin>>N;
    long long int temp1,temp2;
    for(int i=1;i<=N;i++){
        cin>>temp1>>temp2;
        r[i].B=temp1-temp2;
        r[i].E=temp1+temp2;
    }
    sort(r+1,r+1+N,cmp);
    if(N==1){
        cout<<1<<endl;
    }else{
        int p=1;
        int res=0;
        for(int i=2;i<=N;i++){
            if(r[p].E>r[i].B){
                if(r[p].E-r[i].E>=0){
                    p=i;
                }else{
                }
                res++;
            }else{
                p=i;
            }
        }
        cout<<N-res<<endl;
    }
    
}

Measured memory_bytes: 1792
<?php
    $dish = (int)fgets(STDIN);
    $ans = 0;
    $order = explode(" ", fgets(STDIN));
    $sat = explode(" ", fgets(STDIN));
    for($j=0; $j<$dish; $j++){
      $ans += (int)$sat[$j];
    }
    $bon = explode(" ", fgets(STDIN));
    for($k=0; $k<$dish-1; $k++){
      $bon[$k] = (int)$bon[$k];
    }
    
    $now = $order[0];
    
    for($i=0; $i<$dish; $i++){
      $order[$i] = (int)$order[$i];
      if($order[$i] - 1 === $now){
        $ans += $bon[$now-1];
      }
      $now = $order[$i];
    }
      
    echo $ans;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = c / b + (c % b > 0), y = a / d + (a % d > 0);
    if (x <= y) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 3612
S = input()

n = len(S)
counts = [0]*n
r_start = 0
rl_point = None
for i in range(n):
    if S[i:i+2] == "RL":
        rl_point = i
    if S[i:i+2] in ["LR", "L"]:
        r = rl_point+1 - r_start
        l = i - rl_point
        # print(r, l)
        counts[rl_point] += (-(-r//2)) + l//2
        counts[rl_point+1] += r//2 + (-(-l//2))
        r_start = i+1

print(" ".join(map(str, counts)))

Measured memory_bytes: 50544
#include <iostream>

using namespace std;

int main(){
	unsigned long long MONAY=100000;
	int n;

	cin>>n;

	for(n=n;n>0;n--){MONAY = MONAY*1.05;
			 MONAY=((MONAY+999)/1000)*1000;}

	cout<<MONAY<<endl;
	cin>>n;
return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define MOD 1000000007
#define dataSize 500005
#define INF 1e18+7
#ifndef LOCAL
#define map unordered_map
#define endl "\n"
#endif
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	LL n;
	cin>>n;
	LL a[n+1];
	for(LL i=0;i<n+1;i++) cin>>a[i];
	LL b[n];
	for(LL i=0;i<n;i++) cin>>b[i];
	LL p=0;
	for(LL i=0;i<n;i++){
		LL k=min(b[i],a[i]);
		p+=k;
		b[i]-=k;
		k=min(b[i],a[i+1]);
		a[i+1]-=k;
		p+=k;
	}
	cout<<p<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int INF = 1e9;
map<int,int> a;
int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int aa;
    cin >> aa;
    a[aa]++;
  }
  int ans = 0, cnt = 0;
  for (auto p: a) {
    if (p.second == 1) continue;
    if (p.second & 1) ans += p.second - 1;
    else {
      ans += p.second - 2;
      cnt++;
    }
  }
  ans += (cnt + 1) / 2 * 2;
  cout << n - ans << endl;
  return 0;
}


Measured memory_bytes: 4992
<?php
$n = intval(fgets(STDIN));
$a = array_map("intval", explode(" ", trim(fgets(STDIN))));
sort($a);
$c = $a[0];
for($i = 1; $i < $n; $i++){
  $c = ($c + $a[$i])/2;
}
echo $c;

Measured memory_bytes: 4728
n = int(input())
a = list(map(int, input().split()))

dp = [[0, 0] for _ in range(n+1)]

dp[0] = [(1000, 0), (1000, 0)]

for i in range(n):
    kabuka = a[i]
    money = max(dp[i][0][0], dp[i][1][0] + kabuka * dp[i][1][1])
    num_kabu = money // kabuka
    num_amari = money % kabuka
    dp[i+1] = [(money, 0), (num_amari, num_kabu)]


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


Measured memory_bytes: 9200
N, K = map(int, input().split())
A = list(map(int, input().split()))

# imos法して，もう一回同じことを行う
# K回のシミューレション，途中で全てがKになったら打ち切る
for _ in range(K):
    new = [0] * N
    imos = [0] * N
    for i, a in enumerate(A):  # 0-indexにしても問題ない
        imos[max(0, i-a)] += 1
        if i+a+1 <= N-1:  # 右端まで照らすなら，終端は管理しない
            imos[i+a+1] -= 1
    for i in range(N):
        new[i] = new[i-1] + imos[i]
    # Aを上書き
    A = new
    if sum(A) == N*N:
        break
print(*A)


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

int calc(int64_t n) {
  int64_t ok = 0, ng = 10000000;
  while (ng - ok > 1) {
    int64_t m = (ok + ng) / 2;
    if (m * (m + 1) > n)
      ng = m;
    else
      ok = m;
  }
  return ok;
}

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

  int ans = 0;
  for (int64_t a = 1; a <= s; ++a) {
    for (int64_t b = a; (b * b + a + b - a * a) / 2 <= s; ++b) {
      int64_t t = (b * b + a + b - a * a) / 2;
      for (int64_t c = 1; t * c <= s; ++c) {
        int64_t d = calc((2 * s) / t + c * c - c);
        if (t * (d * d + c + d - c * c) == 2 * s) ans++;
      }
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 3104
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int count,count2=0,ans[1000]={0};
	char number[1000];
	while(1){
		scanf("%s",&number);
		for(count=0;number[count]!='\0';count++){
			ans[count2]+=(number[count]-'0');
		}
		if(ans[count2]==0){break;}
		count2++;
	}
	for(count=0;count<count2;count++){
		cout<<ans[count]<<endl;
	}
	return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n;
int fa[maxn], par[maxn];
ll ans = 0;

class Node{
public:
	int zero, one, u;
	Node(): zero(0), one(0), u(0){}
	inline bool operator < (const Node &oth)const{
		ll vl = 1ll * one * oth.zero, vr = 1ll * oth.one * zero;
		return MP(MP(vl, -zero), u) < MP(MP(vr, -oth.zero), oth.u);
	}
	inline Node& operator += (const Node &oth){ zero += oth.zero; one += oth.one; return *this; }
}a[maxn];

set<Node> que;

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

inline void merge(int x, int y){
	a[y] += a[x];
	fa[x] = y;
	return;
}

int main(){
	scanf("%d", &n);
	FOR(i, 1, n){
		scanf("%d", par + i);
		--par[i];
	}
	FOR(i, 0, n){
		int x; scanf("%d", &x);
		if(!x)
			++a[i].zero;
		else
			++a[i].one;
		a[i].u = fa[i] = i;
		if(i)
			que.insert(a[i]);
	}
	
	while(que.size()){
		Node p = *que.begin(); que.erase(que.begin());
		int u = p.u, r = find(par[u]);
		if(r)
			que.erase(a[r]);
		ans += 1ll * a[r].one * a[u].zero;
		merge(u, r);
		if(r)
			que.insert(a[r]);
	}
	
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 20224
// 2011/03/22 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int bus[15];
	bus[0]  = 0;
	bus[1]  = 1;
	bus[2]  = 2;
	bus[3]  = 3;
	bus[4]  = 4;
	bus[5]  = 5;
	bus[6]  = 6;
	bus[7]  = 7;
	bus[8]  = 8;
	bus[9]  = 9;
	bus[10] = 5;
	bus[11] = 4;
	bus[12] = 3;
	bus[13] = 2;
	bus[14] = 1;

	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		int a, b;
		cin >> a >> b;

		if(a==1&&b<1)
			a = 14;
		if(a==2&&b<2)
			a = 13;
		if(a==3&&b<3)
			a = 12;
		if(a==4&&b<4)
			a = 11;
		if(a==5&&b<5)
			a = 10;

		cout << bus[a];
		do{
			a = (a+1)%15;
			cout << ' ' << bus[a];
		}while(bus[a]!=b);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  	string s;
  	cin >> s;
  	
  	bool jelTacno = false;
  
  	for(int i = 0; i < (int)s.size(); ++i)
    {
     	if(s[i]=='7')jelTacno = true; 
    }
  
  	cout << ((jelTacno)?("Yes"):("No")) << '\n';
  
 	return 0; 
}

Measured memory_bytes: 3572
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, a;
    cin >> n;
    map<int, int> m;
    rep(i, n) {
        cin >> a;
        if (a % 4 == 0)
            m[4]++;
        else if (a % 2 == 0)
            m[2]++;
        else
            m[1]++;
    }
    if (m[2] % 2 == 0) {
        if (m[4] >= m[1] - 1)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else {
        if (m[4] - 1 >= m[1] - 1)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

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

#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)                                      \
  cout << #v << ":";                                      \
  for (int i = 0; i < v.size(); i++) cout << " " << v[i]; \
  cout << endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >
#define vll vector<vector<ll> >
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
const int inf = 1000000001;
const ll INF = 1e18;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
  int n;
  cin >> n;
  int a;
  a = sqrt(n);
  cout << a*a << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

int N;
int a[300010];
priority_queue<int, vector<int>, greater<int> > pq1;
priority_queue<int> pq2;
long long sum1[300010], sum2[300010];

void solve()
{
	int i;
	sum1[0] = a[0];
	pq1.push(a[0]); 
	for(i=1; i<N; i++){
		pq1.push(a[i]);
		sum1[i] = sum1[i-1] + a[i];
	}
	for(i=N; i<2*N; i++){
		sum1[i] = sum1[i-1];
		if(pq1.top() < a[i]){
			sum1[i] -= pq1.top();
			sum1[i] += a[i];
			pq1.pop();
			pq1.push(a[i]);
		}
	}
	sum2[3*N-1] = a[3*N-1];
	pq2.push(a[3*N-1]); 
	for(i=3*N-2; i>=2*N; i--){
		pq2.push(a[i]);
		sum2[i] = sum2[i+1] + a[i]; 
	}
	for(i=2*N-1; i>=N; i--){
		sum2[i] = sum2[i+1];
		if(pq2.top() > a[i]){
			sum2[i] -= pq2.top();
			sum2[i] += a[i];
			pq2.pop();
			pq2.push(a[i]); 
		}
	}
	long long res = -1000000000;
	res *= 1000000;
	for(i=N-1; i<=2*N-1; i++){
		if(res < sum1[i] - sum2[i+1])
			res = sum1[i] - sum2[i+1];
	}
	printf("%lld\n", res);
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<3*N; i++)
		scanf("%d", &a[i]);
	solve();
	return 0;
}

Measured memory_bytes: 5624
/*
ID: simpgoo1
TASK: 
LANG: C++14            
*/
// timus 219263UI
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <ctime>
#include <queue>
#include <vector>
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define y1 needtrainharder
#define F first
#define S second
#define gg exit(0)
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()

#define pb push_back
#define mp make_pair
#define skip continue
#define all(x) x.begin(), x.end()
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define file(s,x) if(x == 1)freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define task "sorting"
const int INF = 1e9 + 100;  
const ll INFLL = 1e18 + 100;  
const int MAXN = 3e5 + 100; 

int a, n,m;
string s;


int main(){ 
  boost; 
  srand(time(NULL));
  if(fopen(task".in", "r")){  
    freopen(task".in", "r", stdin);
    freopen(task".out","w",stdout); 
  }
  
  cin>>n>>m;
  cin>>s;
  for(int i = 0;i<s.sz();++i){
    if(s[i]>='0'&&s[i]<='9')++a;
  }
  if(a != s.sz()-1 || s[n] != '-'){
    cout<<"No";
  }else{
    cout<<"Yes";
  }

  return 0;
}


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

using ll = long long;


int main() {
    int n; cin >> n;
    map<string, int> cnt;
    for(int i = 0; i < n; ++i) {
        string s; cin >> s;
        cnt[s] += 1;
    }
    int m; cin >> m;
    for(int i = 0; i < m; ++i) {
        string t; cin >> t;
        cnt[t] -= 1;
    }
    int ans = 0;
    for(auto& p : cnt) {
        ans = max(ans, p.second);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int n;

int main() {
    while (cin >> n) {
        cout << n*(n+1)/2 + 1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1164
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {
	
	int k;
	int cnt = 1;
	int sum = 0;
	cin >> k;
	vector<int> tako(k);

	rep(i, k) cin >> tako.at(i);

	for (int x : tako) {
		for (int i = 0; i < (tako.size() - cnt); i++) {
			sum += x * tako.at(i + cnt);
		}
		cnt++;
	}

	cout << sum << endl;



	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
 
n,l = map(int,input().split())

ans = 0

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

hiku = 0

if l > 0:
    hiku = l
elif l+n-1 < 0:
    hiku = l+n-1
else:
    hiku = 0

print(sum(l_a)-hiku)

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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N, X, M; cin >> N >> X >> M;

	if (N == 1)
	{
		std::cout << X << std::endl;
		return 0;
	}
	
	ll logk{0};
	while ((1ll<<logk) < N) ++logk;

	vector<vector<ll>> ding(logk, vector<ll>(M));
	vector<vector<ll>> ding2(logk, vector<ll>(M));
	REP(i, M)
		ding[0][i] = (i*i)%M;
	REP(k, logk-1)
	{
		REP(i, M)
		{
			ding[k+1][i] = ding[k][ding[k][i]];
		}
	}

	REP(i, M)
		ding2[0][i] = i;
	REP(k, logk-1)
	{
		REP(i, M)
		{
			ding2[k+1][i] = ding2[k][ding[k][i]] + ding2[k][i];
		}
	}

	ll now{X};
	ll res{0};
	--N;
	for (ll bit = 0;; bit++)
	{
		if (N & 1)
		{
			res += ding2[bit][now];
			now = ding[bit][now];
		}
		N = N >> 1;
		if (N == 0)
		{
			res += now;
			break;
		}
	}

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


Measured memory_bytes: 57136
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef  pair<int,int> P;

int main()
{
string s;
cin>>s;
int k;
k=s.size();
string t="s";
if(s[k-1]==t[0])cout <<s<<"es";
else cout <<s<<"s";

}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
	int x;
	
	cin >> x;
	
	if(x == 1){
		cout << "0" <<  std::endl;
		
	}else{
		cout << "1" <<  std::endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 3592
#pragma GCC optimize ("-O3")
    #include <bits/stdc++.h>  
     
    using namespace std;
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> p32;
    typedef pair<ll,ll> p64;
    typedef pair<double,double> pdd;
    typedef vector<ll> v64;
    typedef vector<int> v32;
    typedef vector<vector<int> > vv32;
    typedef vector<vector<ll> > vv64;
    typedef vector<vector<p64> > vvp64;
    typedef vector<p64> vp64;
    typedef vector<p32> vp32;
    ll MOD = 998244353;
    #define forn(i,e) for(ll i = 0; i < e; i++)
    #define forsn(i,s,e) for(int i = s; i < e; i++)
    #define rforn(i,s) for(ll i = s; i >= 0; i--)
    #define rforsn(i,s,e) for(ll i = s; i >= e; i--)
    #define ln "\n"
    #define dbg(x) cout<<#x<<" = "<<x<<ln
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define INF 1e18
    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    #define all(x) (x).begin(), (x).end()
    #define sz(x) ((ll)(x).size())
     
    ll mpow(ll a, ll b){
        if(b >= (MOD-1)) b %= (MOD-1);
        if(b==0) return 1;
        ll t1 = mpow(a,b/2);
        t1 *= t1;
        t1 %= MOD;
        if(b%2) t1 *= a;
        t1 %= MOD;
        return t1;
    }
     
    ll mpow(ll a, ll b, ll p){
        if(b==0) return 1;
        ll t1 = mpow(a,b/2,p);   t1 *= t1;
        t1 %= p;
        if(b%2) t1 *= a;
        t1 %= p;
        return t1;
    }
    ll modinverse(ll a, ll m){
        ll m0 = m; 
        ll y = 0, x = 1; 
        if (m == 1) return 0; 
        while (a > 1){
            ll q = a / m; 
            ll t = m; 
            m = a % m, a = t; 
            t = y; 
            y = x - q * y; 
            x = t; 
        }
        if (x < 0) x += m0; 
        return x; 
    }
    ll range(ll l, ll r){
        return l + rand()%(r-l+1);
    }
    
    int main()
    {
        ll t=1;//cin>>t;
        while(t--)
        {
            int a,b;
            cin>>a>>b;
            cout<<a*b<<endl;
        }
    }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string x;cin>>x;
    if ('A'<=x[0]&&'Z'>=x[0]){
        cout<<"A"<<endl;
    }
    else cout<<"a"<<endl;

}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pi;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head




void solve(){
    string s;
    cin >> s;
    int n = s.size();
    rep(i,0,n) cout << 'x';
    cout << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3560
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    lint x, y;
    cin >> x >> y;

    if(abs(x - y) > 1LL){
        cout << "Alice" << endl;
    }else{
        cout << "Brown" << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    string s;
    int n;
    int k;
    cin >> n;
    cin >> s;
    cin >> k;
    rep(i, n) {
        if (s[k - 1] == s[i]) {
            cout << s[i];
        } else {
            cout << "*";
        }
    }
    cout << endl;
    return 0;
    
}


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

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;

int main()
{
	char c;
	cin >> c;

	cout << (char)(c + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 32;
const int MOD = 998244353;

bool good = false;
int k, cnt = 0;

vector<int> res;

void rec(int now, int last, int len) {
    if (good) return;
    if (now == len) {
        cnt++;
        if (k == cnt) {
            for (int i : res) cout << i;
            good = true;
        }
        return;
    }
    if (last - 1 >= 0) {
        res.push_back(last - 1);
        rec(now + 1, last - 1, len);
        res.pop_back();
    }
    res.push_back(last);
    rec(now + 1, last, len);
    res.pop_back();
    if (last + 1 < 10) {
        res.push_back(last + 1);
        rec(now + 1, last + 1, len);
        res.pop_back();
    }
}

void solve() {
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;

    vector<int> ans;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'o') {
            ans.push_back(i);
            i += c;
        }
    }
    if (ans.size() > k) return;
   

    vector<bool> bad(ans.size());
    int id = ans.size() - 1;

    for (int i = n - 1; i >= 0; i--) {
        while (id >= 0 && ans[id] > i) id--;
        if (id == -1) break;
        if (s[i] != 'x' && i != ans[id] && (id == ans.size() - 1 || ans[id + 1] - c > i)) {
            bad[id] = true;
            ans[id] = i;
            id--;
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        if (!bad[i]) cout << ans[i] + 1 << '\n';
    }
}

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

Measured memory_bytes: 3464
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = new int[N];
		int[] dp = new int[N];
		for(int i = 0;i < N;i++){
			h[i] = sc.nextInt();
		}
		dp[0] = 0;
		dp[1] = (int)Math.abs(h[1] - h[0]);
		for(int i = 2;i < N;i++){
			dp[i] = dp[i - 1] + (int)Math.abs(h[i - 1] - h[i]);
			for(int j = 1;j < K + 1;j++){
				if(i - j < 0){
					break;
				}
				dp[i] = Math.min(dp[i - j] + (int)Math.abs(h[i - j] - h[i]),dp[i]);
			}
		}
		System.out.println(dp[N-1]);
	}
}

Measured memory_bytes: 59656
import sys
n = int(input())
input_lines = [[int(i) for i in lines.split()] for lines in sys.stdin.read().splitlines()]
for i in range(n):
    out_list = ['0'] * n
    m = len(input_lines[i])
    for j in range(m-1, 1, -1):
        out_list[input_lines[i][j]-1] = '1'
    print(' '.join(out_list))



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}
// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}







  


int main() {
 string s,t;
 cin >> s >> t;
 sort (s.begin(),s.end());
 sort (t.begin(),t.end(),greater<char>());
 //cout << s <<  " " << t << endl;
 if (t > s) cout << "Yes" << endl;
 else cout<< "No" << endl;
 
}





Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll t; t=1; while(t--)
typedef long long int ll;
int main() {
    FIO;
    test{
        ll n,i,x,j,k;
        cin>>n>>k;
        ll a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        ll dp[n+1];
        memset(dp,0,sizeof(dp));
        dp[1]=0;
        dp[2]=abs(a[1]-a[0]);
        for(i=3;i<=n;i++){
            x=mod;
            for(j=i-1;j>max(0ll,i-k-1);j--){
                x=min(x,dp[j]+abs(a[i-1]-a[j-1]));
                dp[i]=x;
            }
        }
        cout<<dp[n]<<"\n";
    }
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=32000;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

bitset<N>bit;
char s[N];
VI a,b;
bool check(VI a,int to) {
	bit.reset();bit.set(16000);
	for (int t:a)
		bit=bit>>t|bit<<t;
	return bit[to];
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),i,t,x=gi()+16000,y=gi()+16000;bool o=0;
	for (i=1;s[i]=='F';i++) x--;
	while (i<=n) {
		t=0;
		while (s[++i]=='F'&&i<=n) t++;
		if (o^=1) b.pb(t);
		else a.pb(t);
	}
	puts(check(a,x)&&check(b,y)?"Yes":"No");
	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 n = sc.nextInt();
		double[] x = new double[n];
		double[] y = new double[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextDouble();
			y[i] = sc.nextDouble();
		}
		double ans = 0;
		double mul = 2;
		for(int i = 1; i < n; i++) {
			mul *= i;
		}
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				ans += mul * Math.sqrt(Math.pow(x[i] - x[j], 2) + Math.pow(y[i] - y[j], 2));
			}
		}
		double fac = 1;
		for(int i = 1; i < n + 1; i++) {
			fac *= i;
		}
		ans /= fac;
		System.out.println(ans);
	}

}


Measured memory_bytes: 25172
import math

inputted = list(map(int, input().split()))
tax_price_a = inputted[0]
tax_price_b = inputted[1]

price_8 = math.ceil(tax_price_a / 0.08)
price_10 = math.ceil(tax_price_b / 0.10)

if tax_price_b == int(price_8 * 0.1):
    print(price_8)
elif tax_price_a == int(price_10 * 0.08):
    print(price_10)
else:
    print('-1')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#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()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int x1, x2;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> x1 >> x2;
    int ans = abs(x1 - x2);
    cout << ans << endl;
}



Measured memory_bytes: 3168
<?php
list($summer_vacation_day, $homework_count) = explode(' ', trim(fgets(STDIN)));
$done_period = explode(' ', trim(fgets(STDIN)));

$amount = 0;
foreach ($done_period as $done) {
    $amount += (int)$done;
}

$play_day_count = (int)$summer_vacation_day - $amount;
echo ($play_day_count >= 0) ? $play_day_count : '-1'; 

Measured memory_bytes: 16936
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void merge_sort(long long arr[], long long first, long long last);
int main(void)
{
    long long n,i,k,cha;
    scanf("%lld %lld",&n,&k);
    long long a[n];
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    merge_sort(a,0,n-1);
    cha=a[n-1];
    for(i=0;i<n-k+1;i++)
    {
        if(cha>a[i+k-1]-a[i])cha=a[i+k-1]-a[i];
    }
    printf("%lld\n",cha);
    return 0;
}
void merge(long long arr[], long long low, long long mid, long long high){
    long long i, k;
    long long *tmp = (long long *)malloc((high-low+1)*sizeof(long long));
    //申请空间，使其大小为两个
    long long left_low = low;
    long long left_high = mid;
    long long right_low = mid + 1;
    long long right_high = high;

    for(k=0; left_low<=left_high && right_low<=right_high; k++){  // 比较两个指针所指向的元素
        if(arr[left_low]<=arr[right_low]){
            tmp[k] = arr[left_low++];
        }else{
            tmp[k] = arr[right_low++];
        }
    }

    if(left_low <= left_high){  //若第一个序列有剩余，直接复制出来粘到合并序列尾
    //memcpy(tmp+k, arr+left_low, (left_high-left_low+l)*sizeof(int));
    for(i=left_low;i<=left_high;i++)
        tmp[k++] = arr[i];
    }

    if(right_low <= right_high){
    //若第二个序列有剩余，直接复制出来粘到合并序列尾
    //memcpy(tmp+k, arr+right_low, (right_high-right_low+1)*sizeof(int));
        for(i=right_low; i<=right_high; i++)
            tmp[k++] = arr[i];
    }

    for(i=0; i<high-low+1; i++)
        arr[low+i] = tmp[i];
    free(tmp);
    return;
}

void merge_sort(long long arr[], long long first, long long last){
    long long mid = 0;
    if(first<last){
        mid = (first+last)/2; /* 注意防止溢出 */
        /*mid = first/2 + last/2;*/
        //mid = (first & last) + ((first ^ last) >> 1);
        merge_sort(arr, first, mid);
        merge_sort(arr, mid+1,last);
        merge(arr,first,mid,last);
    }
    return;
}



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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 3e3 + 5;
int dp[N][N][4];
    
  
void solve() {

   int r,c,k;
   cin>>r>>c>>k;
   vvi a(r+1,vi(c+1));
   rep(_,0,k){
    int i,j,cs;
    cin>>i>>j>>cs;
    a[i][j]=cs;
   }
   //if(a[1][1])
     //dp[1][1][1]=a[1][1];
   fr(i,1,r){
     fr(j,1,c){
       
          if(j>1){
            fr(l,0,3)
              dp[i][j][l]=dp[i][j-1][l];
          
          }
          if(i>1){
            int x = 0;
            fr(l,0,3)
              x=max(x,dp[i-1][j][l]);
            dp[i][j][0]=max(dp[i][j][0],x);
          }
          if(a[i][j]){
          frev(k,1,3)
          dp[i][j][k]=max(dp[i][j][k-1]+a[i][j],dp[i][j][k]);
          }
       }
   }
   int ans = 0;
   fr(l,0,3)
     ans=max(ans,dp[r][c][l]);
   cout<<ans;
          
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


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


Measured memory_bytes: 355280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

bool ok(P a, P b, int t) {
    t -= abs(a.first - b.first) + abs(a.second - b.second);
    if (t < 0) return false;
    return t % 2 == 0;
}

int main() {
    int n;
    cin >> n;
    bool fl = true;
    int t, x, y;
    int tp = 0;
    P a = P(0,0);
    REP(i,n) {
        cin >> t >> x >> y;
        P b = P(x,y);
        fl *= ok(a, b, t - tp);
        a = b;
        tp = t;
    }
    if (fl) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,x;
    cin>>n>>x;
    ll cnt=1;
    int mn=x;
    for(int i=1;i<n;i++)
       {
           cin>>x;
           if(x>=mn)
            {
                mn=x;
                cnt++;
            }
       }
       cout<<cnt<<endl;
    return 0;
}


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

using namespace std;

int n;
int a[200005];

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    a[0] = -1;
    for (int i = 1; i <= n; ++i) if (a[i] - a[i-1] > 1) return cout << -1 << endl, 0;
    long long ans = 0;
    for (int i = 2; i <= n; ++i) {
        if (a[i] - a[i-1] == 1) ans += 1;
        else ans += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
# define PI           3.14159265358979323846  /* pi */

using namespace std;

int main()
{	

	string s, t;
	cin >> s;
	cin >> t;
	t.pop_back();
	cout<<(s==t?"Yes":"No");
	
	return 0;
}


Measured memory_bytes: 3612
def f(n):
    if n % 2 == 0:
        return n/2
    else:
        return 3*n + 1

def main():
    s = int(input())
    A = [0]
    A.append(s)
    flag = True
    count = 0
    while flag:
        count += 1
        A.append(f(A[count]))
        for i in range(1, len(A)):
            for j in range(i + 1, len(A)):
                if A[i] == A[j]:
                    flag = False
                    print(j)
main()

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  string s;
  cin >> s;
  int k = sz(s);
  int cnt = 0;
  rep(i,k) if(s[i] == 'o') cnt++;
  if(cnt + (15-k) >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

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

int cost=0;
int arr[100001];

int calculate(int N)
{
	int dp[N];
	for(int i=0;i<N;i++)
	{
		if(i==0)
			dp[i]=0;
		else if(i==1)
			dp[i]=abs(arr[i]-arr[i-1]);
		else
		{
			dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
		}
	}
	return dp[N-1];
}

int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>arr[i];
	cout<<calculate(N)<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N=1e9+7;
int32_t main()
{
	IOS;
	int n;
	cin>>n;
	int dp[n][3];
	for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
         cin>>dp[i][j];

    }
    for(int i=1;i<n;i++)
    {
            dp[i][0]=max(dp[i][0]+dp[i-1][1],dp[i][0]+dp[i-1][2]);
            dp[i][1]=max(dp[i][1]+dp[i-1][0],dp[i][1]+dp[i-1][2]);
            dp[i][2]=max(dp[i][2]+dp[i-1][1],dp[i][2]+dp[i-1][0]);
    }
    int ans = max(dp[n-1][0],dp[n-1][1]);
    ans = max(ans , dp[n-1][2]);
    cout<<ans;
}


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

using namespace std;
typedef long long ll;

#define N 100005
int a[N], f[N];

int main()
{
    int n, m;
    cin >> n >> m;
    memset(a, 1, sizeof(a));
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= n; i++)
        a[i] = 1;
    f[1] = 1;
    while (m--)
    {
        int x, y;
        cin >> x >> y;
        a[x]--;
        a[y]++;
        if (f[x])
        {
            f[y] = 1;
            if (a[x] == 0)
                f[x] = 0;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
        if (f[i])
            res++;
    cout << res << endl;
}

Measured memory_bytes: 1024