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

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

	int x=0;
	if (s[0] == '1') {
		x++;
	}
	if(s[1] == '1') {
		x++;
	}
	if (s[2] == '1') {
		x++;
	}

	cout << x << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, m int

	fmt.Scan(&n)
	blue := map[string]int{}
	for i := 0; i < n; i++ {
		var name string
		fmt.Scan(&name)
		blue[name]+=1
	}

	fmt.Scan(&m)
	red := map[string]int{}
	for i := 0; i < m; i++ {
		var name string
		fmt.Scan(&name)
		red[name]+=1
	}	

	var result int
	for k, v := range blue {
		_, exist := red[k]
		if exist {
			if v - red[k] > result {
				result = v - red[k]
			}
		} else {
			if v > result {
				result = v
			}
		}
	}

	fmt.Println(result)
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A;
int main()
{
    cin >> N;
    A.resize(N);
    for (auto &val : A)
    {
        cin >> val;
    }

    queue<int> que;
    ll result = 0;
    ll sum = 0;
    ll res_xor = 0;
    int right = 0;
    while (right < N)
    {

        sum += A[right];
        res_xor ^= A[right];
        que.push(right);
        while (sum != res_xor)
        {
            int p = que.front();
            que.pop();
            sum -= A[p];
            res_xor ^= A[p];
        }
        result += que.size();
        right++;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 1792
M = []
for i in 0..30
  M << 2**i
end

N, K = gets.split.map(&:to_r)
ans = 0
for i in 1..N
  ans += Rational(1, 2** M.bsearch_index{|x| x*i >= K})
end
ans /= N
p ans.to_f

Measured memory_bytes: 14272
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

const ll p = 1000000007;

int main(){
  ll n; cin >> n;
  str s; cin >> s;
  ll dp[n][n]; //i+1個目まで並べたときに最後がそれまででj+1番目に小さい並べ方の数
  fill(dp[0],dp[n],0);
  dp[0][0] = 1;
  REP(i,n-1){
    if(s[i]=='<'){
      dp[i+1][0] = 0;
      REP(j,i+1){
        dp[i+1][j+1] = dp[i+1][j] + dp[i][j];
        dp[i+1][j+1] %= p;
      }
    }else{
      dp[i+1][i+1] = 0;
      for(ll j = i; j >= 0; j--){
        dp[i+1][j] = dp[i+1][j+1] + dp[i][j];
        dp[i+1][j] %= p;
      }
    }
  }
  ll ans = 0;
  REP(i,n) ans += dp[n-1][i], ans %= p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 70528
a, b, k = map(int, input().split())
ans = []
for i in range(k):
    p = b -i
    m = a + i
    if a <= p and b >= p:
        ans.append(p)
    if a <= m and b >= m:
        ans.append(m) 
ans = sorted(list(set(ans)))   
for i in ans:
    print(i)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    tez;
   ll int n,ans;
    cin>>n;
    int ar[n];
    for( ll int i=0;i<n;i++)
    cin>>ar[i];
    int k=1;
    for(ll int i=0;i<n;i++)
    {
        if(ar[i]==k)
        k++;
    }
 
      ans=n-k+1;
  if(ans==n)
  cout<<"-1"<<"\n";
  else
  cout<<ans<<"\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using lli = long long int;
using pii = std::pair<int, int>;

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

constexpr int inf = 2e9;
std::vector<lli> S;
std::vector<pii> A;


int main(void){
    int n; scanf("%d", &n);
    A.resize(n+1); S.resize(n);
    REP(i, n){
        scanf("%d", &A[i].first);
        A[i].second = i;
    }
    A[n] = {0, 0};
    std::sort(A.begin(), A.end(), std::greater<pii>());

    int addr = n-1; int prev = inf;
    for(int i = 0; i <= n; ++i){
        lli K = i; K *= (prev - A[i].first);
        S[addr] += K;
        prev = A[i].first;
        chmin(addr, A[i].second);
    }
    

    // 解の出力
    REP(i, n) printf("%lld\n", S[i]);


    return 0;
}

Measured memory_bytes: 2688
H, W = map(int,input().split())
s = [list(input()) for _ in range(H)]
for i in range(H):
    s[i] = [0] + s[i] + [0]
s = [[0]*(W+2)] + s + [[0]*(W+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == '#':
            if s[i-1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#' or s[i+1][j] == '#':
                continue
            else:
                print('No')
                exit()
print('Yes')


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <fstream>

using namespace std;

#define ll long long
#define pb push_back
/*void usacosolve(string x){
    ofstream fout(x+".out");
    ifstream fin(x+".in");
}*/
void solve() {
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    ll dp[n];
    for(ll i=0;i<n;i++){
        cin>>arr[i];
        dp[i]=0;
    }
    dp[0]=0;
    for(ll i=1;i<min(k,n);i++){
        dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
        for(ll j=i;j>1;j--){
            dp[i]=min(dp[i-j]+abs(arr[i]-arr[i-j]),dp[i]);
        }
    }
    if(k<=n) {
        for (ll i = k; i < n; i++) {
            dp[i] = dp[i - 1] + abs(arr[i] - arr[i - 1]);
            for (ll j = 2; j <= k; j++) {
                dp[i] = min(dp[i - j] + abs(arr[i] - arr[i - j]), dp[i]);

            }
        }
    }else{
        //donothing
    }
    cout<<dp[n-1]<<endl;
}
int main(){
    /*//usaco:
    string x="";
    usacosolve(x);*/
    //codechef and others
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        //cout<<t<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <bitset>

using namespace std;
using ll = long long;

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(h + 1, 1e18));
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < min(h + 1, a[i - 1]); ++j) {
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            dp[i][j] = min(dp[i][j], dp[i - 1][0] + b[i - 1]);
        }
        for (int j = a[i - 1]; j <= h; ++j) {
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            dp[i][j] = min(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]);
        }
    }
    cout << dp[n][h] << "\n";
    return 0;
}


Measured memory_bytes: 78592
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if (T[u].p == NIL ) cout << "root, ";
    else if (T[u].l == NIL ) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for (i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for (i = 0; i < n; i++) {
        cin >> v >> d;
        for (j = 0; j < d; j++) {
            cin >> c;
            if (j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
    
    rec(r, 0);
    
    for (i = 0; i < n; i++) print(i);
    return 0;
}


Measured memory_bytes: 7672
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
    int n; cin>>n;
    string s;
    for(int i=0; i<n; i++){
        char c; cin>>c;
        if(c!='-') s+=c;
    }
    n=s.size();
    ll dp[202][202]={};
    dp[0][0]=1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=i; j++){
            if(s[i]=='U'){
                (dp[i+1][j]+=j*dp[i][j])%=MOD;
                (dp[i+1][j+1]+=dp[i][j])%=MOD;
            }else{
                (dp[i+1][j]+=j*dp[i][j])%=MOD;
                if(j) (dp[i+1][j-1]+=j*j*dp[i][j])%=MOD;
            }
        }
    }
    cout<<dp[n][0]<<endl;
    return 0;
}


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

int main() {
    Int n, T; cin >> n >> T;
    vector<Int> t(n);
    rep(i, n) cin >> t[i];
    Int ans = 0;
    Int time_start = t[0];
    Int time_end = t[0]+T;
    ans = 0;

    for (int i = 1; i < n; i++) {
        if (t[i] < time_end) {
            time_end = t[i] + T;
        }
        else {
            ans += time_end-time_start;
            time_start = t[i];
            time_end = t[i] + T;
        }
    }
    ans += time_end-time_start;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main()
{
  int N;
  while(cin >> N,N)
    {
      int G[N+1][N+1];
      for(int i=1;i<=N;i++)
    for(int j=0;j<=N;j++)
      cin >> G[i][j];
 
      int dp[(1<<(N+1))];
      for(int i=0;i<(1<<(N+1));i++)
    dp[i] = (1<<29);
 
      dp[0] = 0;
 
      for(int i=0;i<=(1<<(N+1))-2;i++)
    for(int j=1;j<=N;j++)
      if(!((i>>j)&1))
        for(int k=0;k<=N;k++)         
          if(k == 0 || ( (i>>k)&1 ))
        dp[i|(1<<j)] = min(dp[i|(1<<j)],dp[i]+G[j][k]);
      cout << dp[(1<<(N+1))-2] << endl;
    }
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    bool ans = true;
    for (int i = 0;i < s.size();i++){
        if (i % 2 == 0){
            if (s[i] == 'L') ans = false;
        }

        if (i % 2 != 0){
             if (s[i] == 'R') ans = false;
        }
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
MAXK = int(N + 10)
ll = [k for k in range(MAXK) if k * (k - 1) == N * 2]
if len(ll) == 0:
  print('No'); exit()

K = ll[0]

S = [[] for _ in range(K)]
cnt = 1
for i in range(K):
  for j in range(i+1, K):
    S[i].append(cnt)
    S[j].append(cnt)
    cnt += 1

assert(cnt == N + 1)
print("Yes")
print(K)
for s in S:
  print(len(s), " ".join(str(c) for c in s))

Measured memory_bytes: 9700
import scala.io.{StdIn => in}
import java.lang.{Character => char}

object Main extends App {
  val s = in.readLine.map(char.getNumericValue)

  val res0 = s./:(0,0) { case ((acc, i), c) => 
    if(c == i) (acc, i^1) else (acc+1, i^1)
  }._1

  val res1 = s./:(0,1) { case ((acc,i), c) =>
    if(c == i) (acc, i^1) else (acc+1, i^1)
  }._1

  val ans = res0 min res1
  println(ans)
}

Measured memory_bytes: 38096
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
 
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

//const int mod= 998244353; 

signed main() {
 
	fastio();
//	#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif	
	int n;
	cin>>n;
	int arr[n+1];
	int arr1[n];
	int res=0;
	for(int i=0;i<=n;i++)
	{
		cin>>arr[i];
		res+=(arr[i]);
	}
	for(int i=0;i<n;i++)
	{
		cin>>arr1[i];
	}
	for(int i=0;i<n;i++)
	{
		//arr[i]=arr[i]-min(arr[i],arr1[i]);
		if(arr[i]>arr1[i])
		{
			arr[i]=(arr[i]-arr1[i]);
			//cout<<arr[i]<<endl;
		}else{

			arr[i+1]=arr[i+1]-min(arr[i+1],(arr1[i]-arr[i]));
			arr[i]=0;
			//cout<<arr[i+1]<<endl;

		}
		//cout<<arr[i]<<endl;
	}
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		ans+=(arr[i]);
	}
	//cout<<ans<<endl;
	
	cout<<(res-ans);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size()) 
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
#define rep(i, n) for(int i=0;i<n;i++)

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-12;

int mymerge(int a, int b) {
	if (a == 2 || b == 2) return 2;
	return a ^ b;
}
int r[100050][2];
int root(int x) {
	if (x == r[x][0]) return x;
	int p = r[x][0];
	r[x][0] = root(p);
	r[x][1] = mymerge(r[x][1], r[p][1]);
	return r[x][0];
}

vector <int> Vl[100050][3];
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) r[i][0] = i;
	for (i = 1; i <= M; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		int t3 = root(t1), t4 = root(t2);
		if (t3 == t4) {
			if (r[t1][1] == r[t2][1]) r[t3][1] = 2;
			continue;
		}
		r[t3][0] = t4;
		if (r[t1][1] == 2 || r[t2][1] == 2 || r[t3][1] == 2) r[t3][1] = 2;
		else r[t3][1] = r[t1][1] ^ r[t2][1] ^ 1;
	}
	for (i = 1; i <= N; i++) {
		int t = root(i);
		Vl[r[i][0]][r[i][1]].push_back(i);
	}

	ll ans = -M;
	for (i = 1; i <= N; i++) {
		if (Vl[i][0].empty() && Vl[i][1].empty() && Vl[i][2].empty()) continue;
		
		int tot = Vl[i][0].size() + Vl[i][1].size() + Vl[i][2].size();
		if (Vl[i][2].size()) ans += (ll)tot * (tot - 1) / 2;
		else {
			int sz1 = Vl[i][0].size(), sz2 = Vl[i][1].size();
			ans += (ll)sz1 * sz2;
		}
	}
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 8828
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    D = list(map(int,input().split()))
    mod = 998244353

    from collections import Counter

    node_cnt = Counter(D)
    set_d = sorted(list(set(D)))
    if D[0]!=0:
        print(0);exit()
    if set_d[-1]!=len(set_d)-1:
        print(0);exit()
    
    ans = 0
    pre = 1
    
    if 0 in node_cnt:
        if node_cnt[0]==1: 
            ans = 1
    for k,v in sorted(node_cnt.items()):
        ans*=pow(pre,v)
        ans%=mod
        pre = v
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 27124
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 Q = sc.nextInt();
		int P[] = new int[N];
		int A;
		for(int i = 0; i < N; i++) {
			P[i] = K;
		}
		for(int i = 0; i < Q; i++) {
			A=sc.nextInt();
			P[A-1]++;
		}
		for(int i = 0; i < N; i++) {
			P[i] = P[i]-Q;
		}
		for(int i = 0; i < N; i++) {
			if(P[i] > 0) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
	}	
}

Measured memory_bytes: 74740
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1<<30;
enum full = (1<<26) - 1;

void main() {
    string s;
    scan(s);

    int n = s.length.to!int;

    long ans;

    void dfs(int i, long val, long d) {
        if (i == n) {
            debug {
                writeln(val + d);
            }
            ans += val + d;
            return;
        }
        dfs(i + 1, val, d*10 + s[i] - '0');
        dfs(i + 1, val + d, s[i] - '0');
    }

    dfs(1, 0, s[0] - '0');

    writeln(ans);
}










































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define inf 1e9
using namespace std;

struct activity
{
    int A, B, C;
};

int solve(vector<activity> ar, int n)
{
    int dp[n+1][3];
    dp[1][0] = ar[1].A;
    dp[1][1] = ar[1].B;
    dp[1][2] = ar[1].C;
    
    for(int i = 2; i <= n; i++)
    {
        dp[i][0] = ar[i].A + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = ar[i].B + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = ar[i].C + max(dp[i-1][0], dp[i-1][1]);
    }
    
    return max(dp[n][0], max(dp[n][1], dp[n][2]));
}

int main() {
    int n, k;
    cin >> n ;
    vector<activity> ar(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> ar[i].A;
        cin >> ar[i].B;
        cin >> ar[i].C;
    }
    cout << solve(ar, n);
}


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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s1 = Console.ReadLine();
            var s2 = Console.ReadLine();

            var r1 = string.Join("",s2.Reverse()); 
            var r2 = string.Join("",s1.Reverse()); 

            if(s1.Equals(r1) && s2.Equals(r2)){
                Console.WriteLine("YES");
            }else{
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin>>N;
  vector<string> vec(N);
  for (int i=0; i<N; i++){
    cin>>vec.at(i);
  }
  int AC=0;
  int WR=0;
  int TLE=0;
  int RE=0;
  for (int i=0; i<N; i++){
    if(vec.at(i)=="AC") AC++;
    if(vec.at(i)=="WA") WR++;
    if(vec.at(i)=="TLE") TLE++;
    if(vec.at(i)=="RE") RE++;
  }
  cout<<"AC x "<<AC<<endl;
  cout<<"WA x "<<WR<<endl;
  cout<<"TLE x "<<TLE<<endl;
  cout<<"RE x "<<RE<<endl;
}

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

int main() {
    string S;
    cin >> S;

    int ans = 700;
    if (S[0] == 'o') ans += 100;
    if (S[1] == 'o') ans += 100;
    if (S[2] == 'o') ans += 100;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;


int n;
int box[15][15];

bool magic(int x, int y, int num){
    if(num>n*n){
        return false;
    }
    if(x==n){
        return magic(0, y, num);
    }
    if(x==-1){
        return magic(n-1, y, num);
    }
    if(y==n){
        return magic(x, 0, num);
    }
    if(y==-1){
        return magic(x, n-1, num);
    }
    if(box[y][x]!=0){
       return  magic(x-1, y+1, num);
    }
    if(num<=n*n){
        box[y][x]=num;
        return magic(x+1, y+1, num+1);
    }
    
}



int main(void)
{
    while(cin>>n){
        if(n==0)break;
        for(int i=0; i<15; i++){
            for(int j=0; j<15; j++){
                box[i][j]=0;
            }
        }
        magic(n/2, n/2+1, 1);
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                cout<<setw(4)<<right<<box[i][j];
                
            }
            cout<<endl;
        }
        
    }
    
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll mod=1e9+7;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

//階乗,factで初期化
vector<ll> tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

//nCk 繰り返し高速
ll comb(ll n, ll k) {
  return tfact.at(n)*mpow(tfact.at(k),mod-2)%mod*mpow(tfact.at(n-k),mod-2)%mod;
}

int main() {
  ll n,k;
  cin >> n >> k;
  fact(n+1);
  ll temp=0;
  for(ll i=1;i<=k;i++) {
    if(n-k+1>=i) {
      cout << comb(n-k+1,i)%mod*comb(k+i-1-i,i-1)%mod << endl;
    }
    else {
      cout << 0 << endl;
    }
  }
}

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

  int N ,K ,S ;
  cin >> N >> K >> S ;
  rep(i,K) cout << S << endl;
  if(S-1>0) rep(i,N-K) cout << S-1 << endl;
  else rep(i,N-K) cout << S+1 << endl;

}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
   int a, b;
   cin >> a >> b;
   int ans = 0;
   int i = 0;
   while(i < a){
       i += 2*b+1;
       ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
n = int(input())

m = n % 10
ans = ''
if m == 3:
  ans = 'bon'
elif m == 0:
  ans = 'pon'
elif m == 1:
  ans = 'pon'
elif m == 6:
  ans = 'pon'
elif m == 8:
  ans = 'pon'
else:
  ans = 'hon'
print(ans)

Measured memory_bytes: 9180
import bisect
n=int(input())
a=[int(input()) for _ in range(n)][::-1]
dp=[]
for i in a:
  if bisect.bisect_right(dp,i)==len(dp):
    dp.append(i)
  else:
    dp[bisect.bisect_right(dp,i)]=i
print(len(dp))

Measured memory_bytes: 13552
package main

import "fmt"

func main() {
	c := [3][3]int{}
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&c[i][j])
		}
	}

	x := [3]int{}
	y := [3]int{}

	x[0] = 0

	for i := 0; i < 3; i++ {
		y[i] = c[0][i] - x[0]
	}
	for i := 0; i < 3; i++ {
		x[i] = c[i][0] - y[0]
	}

	good := true
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			if x[i]+y[j] != c[i][j] {
				good = false
			}
		}
	}

	if good {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false);}
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
typedef vector <int> vi;
const int mod = 1e9+7;
const int inf = 1e9+10;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
const int W = 1e9;
#define maxn 20100

bool jest[1500];

int main()
{
	boost;
	string s;
	cin >> s;
	int sz = s.size();
	for (int i=0; i<sz; ++i) jest[s[i]]++;
	if (jest['W'] && !jest['E']) OUT("No");
	if (jest['E'] && !jest['W']) OUT("No");
	if (jest['N'] && !jest['S']) OUT("No");
	if (jest['S'] && !jest['N']) OUT("No");
	cout << "Yes";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
int a,b,c;
int main()
{
	scanf("%d %d %d",&a,&b,&c);
	int d=a*100+b*10+c;
	if (d%4==0) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x=0,y=0,t=0,n,i,fx,fy,ft;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&ft,&fx,&fy);
		if(abs((fx-x))+abs((fy-y))==ft-t||abs((fx-x))+abs((fy-y))<ft-t&&(ft-t-(abs((fx-x))+abs((fy-y))))%2==0)
		{
			x=fx;
			y=fy;
			t=ft;	
		}	
		else
		{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <assert.h>
#include <cstdio>
using namespace std;

#define EPS (1e-10)
#define equal(a,b) (fabs((a)-(b)) < EPS)

class Point{
public:
    double x,y;
    
    Point(double x = 0,double y = 0):x(x),y(y){}
    
    Point operator + (Point p){
        return Point(x+p.x,y+p.y);
    }
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
    Point operator * (double a){
        return Point(a*x,a*y);
    }
    
    double abs(){
        return sqrt(norm());
    }
    double norm(){
        return x*x+y*y;
    }

    bool operator < (const Point &p)const{
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator == (const Point &p)const{
        return equal(x,p.x) && equal(y,p.y);
    }
};

typedef Point Vector;

double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
    return a.x*b.y - a.y*b.x;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0,Point p1,Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    
    if(cross(a,b) > EPS) return COUNTER_CLOCKWISE;
    if(cross(a,b) < -EPS) return CLOCKWISE;
    if(dot(a,b) < -EPS) return ONLINE_BACK;
    if(a.norm() < b.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

struct Segment{
    Point p1,p2;
};

bool isIntersect(Point p1,Point p2,Point p3,Point p4){
    return (ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 &&
            ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0);
}

Point getCrossPoint(Segment s1,Segment s2){
    assert(isIntersect(s1.p1,s1.p2,s2.p1,s2.p2));
    Vector base = s2.p2 - s2.p1;
    double d1 = abs(cross(base,s1.p1-s2.p1));
    double d2 = abs(cross(base,s1.p2-s2.p1));
    
    double t = d1/(d1+d2);
    return s1.p1 + (s1.p2 - s1.p1) * t;
}

int main(){
    Segment s1,s2;
    Point ans;
    int n;
    
    cin >> n;
    for(int i = 0 ; i < n ; i++){
    cin >> s1.p1.x >> s1.p1.y >> s1.p2.x >> s1.p2.y
        >> s2.p1.x >> s2.p1.y >> s2.p2.x >> s2.p2.y;
        ans = getCrossPoint(s1,s2);
        printf("%.10f %.10f\n" ,ans.x ,ans.y);
    }
    
    return 0;
}

Measured memory_bytes: 1248
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
int ans[MAXN], indeg[MAXN];
int a[MAXN], rem[5];
int visit[MAXN];
set<pii> pq;
set<int> cand;
int ans_idx = 0, pre = 0;

void solve(int sz) {
    while ((int)cand.size() > sz) {
        int tpcand = *cand.begin(), nxt;
        auto tp = pq.rbegin();
        if (tp->first == (int)cand.size() - 1) {
            int cur = tp->second;
            pq.erase(prev(pq.end()));
            ans[ans_idx++] = cur;
            cand.erase(cur);
            nxt = cur;
        } else if (a[pre] == tpcand) {
            cand.erase(cand.begin());
            int cur = *cand.begin();
            cand.erase(cand.begin());
            ans[ans_idx++] = cur;
            cand.insert(tpcand);
            nxt = cur;
        } else {
            cand.erase(cand.begin());
            ans[ans_idx++] = tpcand;
            nxt = tpcand;
        }
        visit[nxt] = 1;
        if (!visit[a[nxt]]) {
            int to = a[nxt];
            pq.erase(make_pair(indeg[to], to));
            indeg[to]--;
            pq.insert(make_pair(indeg[to], to));
        }
        pq.erase(make_pair(indeg[nxt], nxt));
        pre = nxt;
    }
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &a[i]);
        indeg[a[i]]++;
    }
    if (N == 2) return !printf("-1\n");
    for (int i = 1; i <= N; i++) {
        pq.insert(make_pair(indeg[i], i));
        cand.insert(i);
    }
    solve(3);
    for (int i = 0; i < 3; i++) {
        int tp = *cand.begin();
        cand.erase(cand.begin());
        rem[i] = tp;
    }
    int ans1 = MAXN, ans2 = MAXN, ans3 = MAXN;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (j == i) continue;
            for (int k = 0; k < 3; k++) {
                if (k == i || k == j) continue;
                if (a[pre] == rem[i]) continue;
                if (a[rem[i]] == rem[j]) continue;
                if (a[rem[j]] == rem[k]) continue;
                if (rem[i] < ans1) {
                    ans1 = rem[i];
                    ans2 = rem[j];
                    ans3 = rem[k];
                } else if (rem[i] == ans1) {
                    if (rem[j] < ans2) {
                        ans1 = rem[i];
                        ans2 = rem[j];
                        ans3 = rem[k];
                    }
                }
            }
        }
    }
    ans[ans_idx++] = ans1;
    ans[ans_idx++] = ans2;
    ans[ans_idx++] = ans3;
    for (int i = 0; i < N; i++)
        printf("%d ", ans[i]);
    puts("");
    return 0;
}


Measured memory_bytes: 11776
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int di[3] = {1, 0, -1};
int dj[3] = {1, 0, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    set<P> se;
    ll ans[10] = {};
    ans[0] = ll(h-2)*(w-2);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        rep(j, 3) rep(k, 3) {
            int ni = a+di[j], nj = b+dj[k];
            int ccn = 1;
            rep(l, 3) rep(hh, 3) {
                int nni = ni+di[l], nnj = nj+dj[hh];
                if(nni < 1 or nnj < 1 or nni > h or nnj > w) {
                    ccn = -10000;
                    continue;
                }
                if(se.find(P(nni, nnj)) != se.end()) ccn++;
            }
            if(ccn < 0) continue;
            ans[ccn-1]--;
            ans[ccn]++;
        }
        se.insert(P(a, b));
        //rep(i, 10) cout << ans[i] << (i == 9?'\n':' ');
    }

    rep(i, 10) cout << ans[i] << '\n';
}

Measured memory_bytes: 8288
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FOOR(i,a,b) for(int i=a;i<=b;i++)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  string S;
  cin>>S;
  S='0'+S+'0';
  bool M[100000];
  FOR(i,0,(int)S.size()-1){
    M[i]=(S[i]!=S[i+1]);
  }
  int m=INF;
  FOR(i,0,(int)S.size()-1){
    if(M[i]){
      m=min(m,max(i,(int)S.size()-i-2));
    }
  }
  if(m==INF){
    cout<<(int)S.size()-2<<endl;
  }else{
    cout<<m<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N, K, total = 0, Ans = 0;cin >> N >> K;
vector<ll> f;
vector<ll> b;

rep(i, 0, N + 1){

    total += i;total%=1000000007;

    if(i >= K - 1)f.push_back(total);

}

total = 0;

for(ll i = N; i >= 0; i--){

    total += i;

    if(i <= N - K + 1)b.push_back(total);
    
}

rep(i, 0, N - K + 2){

   if(b[i] - f[i] + 1 > 0){Ans += (b[i] - f[i] + 1)%1000000007;Ans%=1000000007;}
  
   else break;
  
}
  
cout << Ans;
  
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  int r;cin>>r;
  cout << 3*r*r << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
int a,b;
cin>>a;
cin>>b;

if(1<=a&&a<=100&&0<=b&&b<=a)
{
if(a==b)
    cout<<"Yes";
else
   cout<<"No";
}

else
{
    cout<<"error";
}
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/

signed main()/*Check flow ---question galat mat padhna yr*/
{
    fast;
    ll x;
    cin>>x;
    for(ll a=-200;a<=200;a++)
    {
        for(ll b=-200;b<=200;b++)
        {
            if(a*a*a*a*a-b*b*b*b*b==x)
            {
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
}   

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int,int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first 
#define s second 
using namespace std;
const int N=5e6+10;
const int mod=1e9+7;
int arr[N],iarr[N];
int logi(int n){int p=0;while(n/2){n=n/2;p++;}return p;}
int poww(int x,int y){int pro=1;while(y){if(y&1)pro=((pro%mod)*(x%mod)%mod);y=y>>1;x=((x%mod)*(x%mod)%mod);}return pro;}
int poww2(int x,int y){int pro=1;while(y){if(y&1)pro=pro*x;y=y>>1;x=x*x;}return pro;}
double poww1(double x,int y){double pro=1.000000000;while(y){if(y&1)pro=((pro)*(x));y=y>>1;x=((x)*(x));}return pro;}
map<int,int> mp1,mp2;
set<int> st;
int arr1[1000001],arr2[1000001];
/*

*/
void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int j=n-1,i=0,cnt=0;
	while(s[i]=='R'&&i<n) i++;
	while(s[j]=='W'&&j>=i) j--;
	while(i<j)
	{
		if(s[i]=='W'&&s[j]=='R') i++,j--,cnt++;
		else 
		{
			if(s[i]=='R') i++;
			if(s[j]=='W') j--;
		}
	}
	cout<<cnt;
}

int32_t main()																																	
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3760
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline LL fastpo(LL x, LL n, LL mod) {
	LL res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}

inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}
template<const LL mod> struct MI{
	LL a;
	MI operator + (const MI & b) {
		MI res{a + b.a};
		if(res.a >= mod) res.a -= mod;
		return res;
	}
	MI operator - (const MI & b) {
		MI res{a - b.a};
		if(res.a <= 0) res.a += mod;
		return res;
	}
	MI operator * (const MI & b) {
		return MI{a * b.a % mod};
	}
	MI operator / (const MI & b) {
		return MI{a * fastpo(b.a, mod - 2, mod) % mod};
	}
};
const int N = 300033;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
LL a[N], le[N], ri[N];
void no() {
	cout << -1 << endl;
	exit(0);
}
int main() {
	int n;
	cin >> n;
	int b;
	for(int i = 0; i <= n; i++) {
		cin >> a[i];
	}
	le[n] = ri[n] = 0;
	for(int i = n - 1; i >= 0; i--) {
		le[i] = (a[i + 1] + le[i + 1] + 1) / 2;
		ri[i] = a[i + 1] + ri[i + 1];
		//cout << le[i] << ' ' << ri[i] << endl;
		if(le[i] > ri[i]) no();
	}
	if(!(le[0] <= 1 - a[0] && 1 - a[0] <= ri[0])) no();
	LL ans = 1;
	le[0] = ri[0] = 1 - a[0];
	for(int i = 1; i <= n; i++) {
		le[i] = max(le[i], le[i - 1] - a[i]);
		ri[i] = min(ri[i], ri[i - 1] * 2 - a[i]);
		ans += ri[i] + a[i];
		//cout << le[i] << ' ' << ri[i] << endl;
	}
	cout << ans << endl;
	
}






Measured memory_bytes: 5992
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, m, bul, ans = 1e9, a[N];
vector < int > g[N];

int dfs(int node, int par, int der, int bul){
	// cout << par << " -> " << node << " " << der << " " << bul << endl;
	int say = 0;
	if(der > bul)
		say++;
	for(int i = 0; i < g[node].size(); i++)
		if(g[node][i] != par)
			say += dfs(g[node][i], node, der + 1, bul);
	return say;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&m);
	for(int i = 1; i < n; i++){
		int u, v;
		scanf("%d %d",&u ,&v);
		g[u].pb(v);
		g[v].pb(u);
	}
	if(m%2 == 0)
		for(int i = 1; i <= n; i++)
			ans = min(ans, dfs(i, 0, 0, m/2));
	else{
		for(int i = 1; i <= n; i++){
			int top = 0;
			for(int j = 0; j < g[i].size(); j++){
				top += a[j] = dfs(g[i][j], i, 1, m/2);
				// cout << a[j] << " ";
			}
			ans = min(ans, top);
			// cout << "AMK " << top << endl;
			// cout<< i << " " << top << endl;
			for(int j = 0; j < g[i].size(); j++){
				int x = dfs(g[i][j], i, 1, m/2 + 1);
				ans = min(ans, top - a[j] + x);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 25088
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll dp[3001][3001];

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

    for(int j=1;j<=n;++j) {
        dp[0][j] = 1LL + dp[0][j-1];
    }

    for(int i=1;i<n;++i) {
        for(int j=1;j<n-i+1;++j) {
            if(s[i-1] == '>') {
                dp[i][j] += (dp[i-1][n-i+1] - dp[i-1][j] + MOD) % MOD;
                dp[i][j] %= MOD;
            } else {
                dp[i][j] += dp[i-1][j];
                dp[i][j] %= MOD;
            }       
        }

        for(int j=1;j<n-i+1;++j) {
            dp[i][j] += dp[i][j-1];
            dp[i][j] %= MOD;
        }
    }
    
    cout << dp[n-1][1] << "\n";
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
    using namespace std;
    #define INF 2000000000
    typedef long long int ll;
    typedef pair<ll,ll> ii;
    typedef pair<ii,ll> iii;
    typedef vector<ll> vi;
    typedef vector<ii> vii;
    #define getbit(n,i) (((n)&(1<<(i)))!=0)
    #define setbit0(n,i) ((n)&(~(1<<(i))))
    #define setbit1(n,i) ((n)|(1<<(i)))
    #define togglebit(n,i) ((n)^(1<<(i)))
    #define lastone(n) ((n)&(-(n)))
    #define read freopen("debug\\in.txt","r",stdin)
    #define write freopen("debug\\out.txt","w",stdout)
    #define fi first
    #define se second
    #define getI(a) scanf("%d",&a)
    #define getII(a,b) scanf("%d%d",&a,&b)
    #define PI (acos(-1))
    #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
    #define mod (1000000007)
    #define asz 500005
    #define pb push_back
    #define ppf pop_front
    #define ppb pop_back
    #define pf push_front
    map<string,ll>mp;
    int main()
    {
        fastread;
        string s1,s2;
        cin>>s1>>s2;
        ll n,m;
        cin>>n>>m;
        mp[s1]=n;
        mp[s2]=m;
        string s;
        cin>>s;
        mp[s]--;
        cout<<mp[s1]<<" "<<mp[s2];
    	return 0;
    }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long input,i;
    i=1;
    
    while(input!=0)
    {
        cin>>input;
        if(input!=0)
        {
            cout<<"Case "<<i<<": "<<input<<endl;
        i++;

        }
    }
    
    

    
    
    
    
    return 0;
    
}



Measured memory_bytes: 3080
#include <stdio.h>

int main(){
  char p[101],s[101];
  int i=0,j=0,k=0,l=0,m=0;
  int ans=0;
  for(i=0; i<101; i++){
    scanf("%c",&s[i]);
    if(s[i]=='\n')break;
  }
  for(j=0; j<101; j++){
    scanf("%c",&p[j]);
    if(p[j]=='\n')break;
  }
  for(k=0;k<i;k++){
    if(s[k]==p[0]){
      for(l=0; l<j; l++){
        m=k+l;
        if(m>=i)m-=i;
        if(s[m]!=p[l])break;
        if(l==j-1)ans=1;
      }
    }
  }
  if(ans)printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 524
#include <iostream>
using namespace std;
int main(void){
    string s;
    int count = 0;
    int ans = 0;
    cin >> s;
    for (int i=0;i<s.length();i++){
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
            count++;
            if (ans < count) {
                ans = count;
            }
        } else {
            count = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int prime(int n, int k = 2)
{
    if(n < k * k) { return 1; }
    
    if(n % k == 0) { return 0; }
    
    return prime(n, k + 1);
}

int solve(int n)
{
    for(int i = n; i >= 3; i--)
    {
        if(prime(i) * prime(i - 2))
        {
            return i;
        }
    }
    
    return -1;
}

int main()
{
    int n;
    
    while(true)
    {
        cin >> n;
        
        if(n == 0) { break; }
        
        cout << solve(n) - 2 << ' ' << solve(n) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
int main() {
int N; 
cin >> N; 
int A[5000]; 
long long int S = 0; 
for (int i = 0; i < N; i++){
cin >> A[i]; 
S += A[i] - 1; 
}
cout << S << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int count_dividable(int a, int b, int x) {
    int div_x = b / x - a / x;
    if (a % x == 0)
        div_x++;
    return div_x;
}

int gcd(int x, int y) {
    if (x < y)
        return gcd(y, x);
    if (x % y != 0) {
        return gcd(y, x % y);
    }
    return y;
}

int lcm(int x, int y) {
    return x * y / gcd(x, y);
}

signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int div_c = count_dividable(a, b, c);
    int div_d = count_dividable(a, b, d);
    int div_cd = count_dividable(a, b, lcm(c, d));
    cout << b - a + 1 - (div_c + div_d - div_cd) << "\n";
}

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

int main() {
    int n;
    long long a[200001];
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a, a+n);
    long long nSum = a[n-1];
    int k = 2;
    int m = 2;
    for(int i=2; i<n; i++) {
        nSum += a[n-m];
        k--;
        if(k == 0) {
            m++;
            k = 2;
        }
    }
    printf("%lld\n", nSum);
    return 0;
}

Measured memory_bytes: 5396