akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N, K;
    cin >> N >> K;
    vi lamps(N, 0);

    REP(i, N) {
        cin >> lamps[i];
    }

    if (K > 42) {
        REP(i, N) {
            cout << N;
            if (i != N - 1) {
                cout << " ";
            }
        }
        return;
    }

    REP(i, K) {
        vi tmp(N + 1);
        REP(j, N) {
            debug(lamps[j]);
            int start = max(j - lamps[j], (int)0);
            int end = min(j + lamps[j] + 1, N);
            tmp[end]--;
            tmp[start]++;
        }
        REP(j, N) {
            debug(tmp[j]);
            if (j == 0) {
                lamps[j] = tmp[j];
                continue;
            }
            lamps[j] = tmp[j] + lamps[j - 1];
        }
    }

    REP(i, N) {
        cout << lamps[i];
        if (i != N - 1) {
            cout << " ";
        }
    }
}

#pragma region main
main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 6312
S = input()
listS = list(S)
N = []
dic = ['A', 'T', 'G', 'C']
count = 0
for i in range(len(listS)):
    if listS[i] in dic:
        count += 1
        N.append(count)
    else:
        count = 0
        N.append(count)
print(max(N))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  char X,Y;
  cin>>X>>Y;
  int A=10;
  int B=11;
  int C=12;
  int D=13;
  int E=14;
  int F=15;
 
  if(X-'0'>Y-'0'){
    cout<<'>'<<endl;
  }
  else if(X-'0'<Y-'0'){
    cout<<'<'<<endl;
  }
  else if(X-'0'==Y-'0'){
    cout<<'='<<endl;
  }
}

    
  


Measured memory_bytes: 256
K,S = map(int,input().split())
x = y = S//3
z = S - x - y
if z < y:
    x = z
    z = y
ans = 0
while 0 <= x <= y and 0<= y <=K and z <= K:
    while 0 <= x and z <= K:
        if x == y == z:
            ans += 1
        elif x == y or y == z:
            ans += 3
        else:
            ans += 6
        x -= 1
        z += 1
    y -= 1
    x = y
    z = S - x - y
    if z < y:
        x = z
        z = y
x = y = S//3 + 1
z = S - x - y
if z < y:
    x = z
    z = y
while 0 <= x <= y and 0 <= y <= K and y <= z <= K:
    while 0 <= x and z <= K:
        if x == y == z:
            ans += 1
        elif x == y or y == z:
            ans += 3
        else:
            ans += 6
        x -= 1
        z += 1
    y += 1
    x = y
    z = S - x - y
    if z < y:
        x = z
        z = y
print(ans)

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

using namespace std;

int main() {


	int A, B, C;
	cin >> A >> B >> C;

	if ((A == B && A != C) || (A == C && B != C) || (A != B && B == C)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}



}

Measured memory_bytes: 256
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
  a,b,c = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

from collections import deque

ans = 0
visited = [False]*N
d = deque()
for i in range(N):
  if visited[i]==False:
    visited[i]=True
    d.append(i)
    while len(d)>0:
      v = d.popleft()
      for w in edge[v]:
        if visited[w]==False:
          visited[w]=True
          d.append(w)
    ans += 1
print(ans)

Measured memory_bytes: 28164
#include <cstdio>

using namespace std;

typedef long long ll;

int main() {
    ll n, ans = 0;
    scanf("%lld", &n);
    for (ll i = 1; i * (i + 2) <= n; ++i) if (n % i == 0) ans += n / i - 1;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;

void main() {
  auto S = readln.chomp;
  auto T = readln.chomp;
  
  int correct_count = 0;
  for(int i=0; i<S.length; i++) {
    if (S[i] == T[i]) correct_count++;
  }

  writeln(correct_count);
}


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

count = 0
m = 10**9
sum = 0
for i in a:
    if i < 0:
        count += 1
    i = abs(i)
    m = min(m,i)
    sum += i


if count % 2 == 1:
    sum -= m * 2

print(sum)

Measured memory_bytes: 14332
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

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

    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    n = 0
    for i in range(N):
        res += min(a[i], b[i]+n)
        c = max(a[i]-n, 0)
        n = max(b[i]-c, 0)
    res += min(n, a[-1])
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 73444
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

const int MAX_M = 12;

int main() {
	while (true) {
		int L, M, N;
		int info[MAX_M] = {0};

		int temp = 0;

		cin >> L;
		if (L == 0) break;
		
		for (int i = 0; i < 12; i++) {
			M = 0; N = 0;
			cin >> M >> N;
			info[i] = M - N;
		}

		for (int i = 1; i <= 12; i++) {
			temp += info[i-1];
			
			if (temp >= L) {
				cout << i << endl;
				break;
			}
		}
		
		if (temp < L) {
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = [[0]*19 for i in range(19)]
for i in range(n):
    A = int(float(input())*10**9+0.5)
    m2 = m5 = 0
    while A % 2 == 0:
        A //= 2
        m2 += 1
    while A % 5 == 0:
        A //= 5
        m5 += 1
    m2 = min(m2, 18)
    m5 = min(m5, 18)
    a[m2][m5] += 1

ans = 0
for i in range(19):
    for j in range(19):
        for k in range(19):
            for l in range(19):
                if i + k >= 18 and j + l >= 18:
                    if i == k and j == l:
                        ans += a[i][j] * ( a[k][l] - 1 )
                    else:
                        ans += a[i][j] * a[k][l]
ans //= 2
print(ans)

Measured memory_bytes: 10188
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function abmp(a,b,p);if b==0;1;elseif b%2==0;k=abmp(a,div(b,2),p);(k*k)%p;else;(a*abmp(a,b-1,p))%p;end;end;;
function binarr(n,p);z=1;for i in 1:n;z=z*i%p;end;fac=Array{Int}(n+1);inv=Array{Int}(n+1);inv[n+1]=abmp(z,p-2,p)
for i in 0:n-1;inv[n-i]=(inv[n+1-i]*(n-i))%p;end;for i in 0:n;fac[i+1]=(((z*inv[i+1])%p)*inv[n+1-i])%p;end;fac;end;
function euc(a,m)
	b = m
	x = 1
	u = 0
	while b>0
		q = div(a,b)
		tmp = u
		u = x-q*u
		x = tmp
		tmp = b
		b = a-q*b
		a = tmp
	end
	x<0?x+abs(m):x
end

function main()
	p = 10^9+7
	r1,c1,r2,c2 = readline() |> split |> parseMap
	ans = 0
	x = binarr(r2+c1,p)[c1+1]
	for i in 1:c2-c1+1
		x = (x*(r2+c1+i)%p)*euc(c1+i,p)%p
		ans = (ans+x)%p
	end
	y = binarr(r1+c1-1,p)[c1+1]
	for i in 1:c2-c1+1
		y = (y*(r1+c1-1+i)%p)*euc(c1+i,p)%p
		ans = mod(ans-y,p)
	end
	println(ans)
end

main()

Measured memory_bytes: 170728
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a, b := iSScan(n), iSScan(n)
	for i := 1; i < n; i++ {
		a[i] = a[i-1] + a[i]
	}
	for i := n - 2; i >= 0; i-- {
		b[i] = b[i+1] + b[i]
	}
	ans := 0
	for i := 0; i < n; i++ {
		ans = larger(a[i]+b[i], ans)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<long, long>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007
#define INF 1e12

vector<vector<vector<pii>>> G(100010,vector<vector<pii>>(3));
vector<vector<long>> dist(100010,vector<long>(3,INF));

void dfs(long v,long vs,long depth){
  if(depth >= dist.at(v).at(vs)) return;
  
  dist.at(v).at(vs) = depth;
  for(pii P : G.at(v).at(vs)){
    long nv,nvs;
    tie(nv,nvs) = P;
    dfs(nv,nvs,depth+1);
  }
}

int main(){
  long n,m;
  cin >> n >> m;
  
  rep(i,m){
    long x,y;
    cin >> x >> y;
    x--;y--;
    G.at(x).at(0).push_back(pii(y,1));
    G.at(x).at(1).push_back(pii(y,2));
    G.at(x).at(2).push_back(pii(y,0));
  }
  
  long s,t;
  cin >> s >> t;
  s--;t--;
  dist.at(s).at(0) = 0;
  //dfs(s,0,0);
  
  
  
  //if(dist.at(t).at(0) == INF) cout << -1 << endl;
  //else cout << dist.at(t).at(0)/3 << endl;
  
  priority_queue<tuple<long,long,long>, vector<tuple<long,long,long>>, greater<tuple<long,long,long>>> que;
  que.push(tuple<long,long,long>(0,s,0));
  while(que.size()){
    tuple<long,long,long> P = que.top();
    que.pop();
    long pos,v,vs;
    tie(pos,v,vs) = P;
    if(dist.at(v).at(vs) < pos) continue;
    for(pii nP : G.at(v).at(vs)){
      long nv,nvs;
      tie(nv,nvs) = nP;
      if(dist.at(nv).at(nvs) > dist.at(v).at(vs) + 1){
        dist.at(nv).at(nvs) = dist.at(v).at(vs) + 1;
        que.push(tuple<long,long,long>(dist.at(nv).at(nvs),nv,nvs));
      }
    }
  }
  if(dist.at(t).at(0) == INF) cout << -1 << endl;
  else cout << dist.at(t).at(0)/3 << endl;
}

Measured memory_bytes: 25336
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int result = (N%2==0) ? N : 2*N;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>

#define Lens 250
#define Nil -1
using namespace std;

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

int N,sum;
Node Tr[Lens];

void maketree()
{
	int m, l, r;
	for (int i = 0; i < N; i++)
	{
		cin >> m >> l >> r;
		Tr[m].l = l;
		Tr[l].p = m;
		Tr[m].r = r;
		Tr[r].p = m;
	}
}

void Preorder(int i)
{
	if (i == Nil)
		return;
	cout << ' '<< i;
	Preorder(Tr[i].l);
	Preorder(Tr[i].r);
}

void Inorder(int i)
{
	if (i == Nil)
		return;
	Inorder(Tr[i].l);
	cout << ' ' << i;
	Inorder(Tr[i].r);
}

void Postorder(int i)
{
	if (i == Nil)
		return;
	Postorder(Tr[i].l);
	Postorder(Tr[i].r);
	cout << ' ' << i;
}

int main()
{
	int root;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		Tr[i].p = Tr[i].l = Tr[i].r = Nil;
	}
	maketree();
	for (int i = 0; i < N; i++)
	{
		if (Tr[i].p == Nil)
			root = i;
	}
	cout << "Preorder" << endl;
	Preorder(root);
	cout << endl;
	cout << "Inorder" << endl;
	Inorder(root);
	cout << endl;
	cout << "Postorder" << endl;
	Postorder(root);
	cout << endl;


	return 0;
}


Measured memory_bytes: 3116
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>


int main() {
	int N;
	std::cin>>N;
	int K;
	std::cin>>K;
	if (N == 1) {
		printf("0\n");
		return 0;
	}
	std::vector<int> height(N);
	for (int i = 0; i < N; ++i) {
		int h;
		std::cin >> h;
		height[i] = h;
	}
	std::vector<int> f(N);
	if (N == 2) {
		printf("%d\n", abs(height[1]-height[0]));
		return 0;
	}
	f[0] = 0;
	f[1] = abs(height[1] - height[0]);
	for (int i = 2; i < N; ++i) {
		int step = 0x7FFFFFFF;
		for (int j = K; j > 0; --j) {
			if (i - j >= 0) {
				int val = f[i-j] + abs(height[i] - height[i - j]);
				if (val < step) {
					step = val;
				}
			}
		}
		f[i] = step;
	}
	printf("%d\n", f[N-1]);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s;
	cin>>n>>s;
	ll ans=0;
	rep(i,s.size()-2){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
let nil = -1

type tree = {
  mutable parent : int;
  mutable child : int;
  mutable bro : int;
  mutable depth : int;
}

let make () = { parent = nil; child = nil; bro = nil; depth = nil }

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1)
  in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1);
  in
  doit (root 0) 0

let print_tree t =
  let print i =
    print_string "node "; print_int i;
    print_string ": parent = "; print_int t.(i).parent;
    print_string ", depth = "; print_int t.(i).depth;
    print_string (if t.(i).parent = nil then ", root, [" else if t.(i).child = nil then ", leaf, [" else ", internal node, [");
    let rec print_children c =
      if c <> nil then begin
        if c <> t.(i).child then print_string ", ";
        print_int c;
        print_children t.(c).bro
      end
    in
    print_children t.(i).child;
    print_string "]\n";
  in
  Array.iteri (fun i _ -> print i) t

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  let rec read i =
    if i < n then begin
      let id, k = Scanf.scanf "%d %d " (fun id k -> id, k) in
      let rec read_node j left_child =
        if j < k then begin
          let c = Scanf.scanf "%d " (fun i -> i) in
          t.(c).parent <- id;
          if j = 0 then t.(id).child <- c else t.(left_child).bro <- c;
          read_node (j + 1) c
        end
      in
      read_node 0 0;
      read (i + 1)
    end
  in
  read 0;
  set_depth t n;
  print_tree t

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

long long N, K, P[5005], C[5005];
vector<long long> scores[5005];

bool visited[5005];

int start = 0;
void dfs(int src)
{
	if(visited[src])
		return;
		
	visited[src] = true;
	if(scores[start].empty())
		scores[start].push_back(C[P[src]]);
		
	else
		scores[start].push_back(scores[start].back() + C[P[src]]);
		
	dfs(P[src]);
}

int main()
{
	scanf("%lld%lld", &N, &K);
	for(long long i = 1; i <= N; i++)
	{
		scanf("%lld", &P[i - 1]);
		P[i - 1]--;
	}
	
	for(long long i = 1; i <= N; i++)
		scanf("%lld", &C[i - 1]);
		
	for(long long int i = 0; i < N; i++)
	{
		for(long long int j = 0; j < N; j++)
			visited[j] = false;
		
		start = i;
		dfs(i);
	}
	
	/*for(long long int i = 0; i < N; i++)
	{
		for(long long int j = 0; j < (long long)(scores[i].size()); j++)
			printf("%lld ", scores[i][j]);
			
		printf("\n");
	}*/
	
	//printf("\n");
	
	long long grandMax = 0;
	for(long long int i = 0; i < N; i++)
	{
		long long maxScore = scores[i][0];
		if(K <= (long long)(scores[i].size()) )
		{
			maxScore = scores[i][0];
			for(long long int j = 1; j <= K; j++)
				maxScore = max(maxScore, scores[i][j - 1]);
				
			//printf("i = %lld, maxScore = %lld\n", i, maxScore);
		}
		
		else
		{
			if(scores[i].back() >= 0)
			{
				for(long long j = 0; j < (long long)(scores[i].size()); j++)
				{
					long long numCycles = (K - j - 1) / (long long)(scores[i].size());
					maxScore = max(maxScore, scores[i][j] + numCycles * scores[i].back());
				}
			}
			
			else
			{
				long long maximum = scores[i][0];
				for(long long j = 0; j < (long long)(scores[i].size()); j++)
					maximum = max(maximum, scores[i][j]);
				
				maxScore = maximum;
			}
		}
		
		if(i != 0)
			grandMax = max(grandMax, maxScore);
			
		else
			grandMax = maxScore;
	}
	
	printf("%lld", grandMax);
}


Measured memory_bytes: 219220
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










template <typename T>
class LazySegmentTree {
private:
    int n;      // 配列の要素数
    T init;     // 遅延伝搬用の配列の初期の値
    vector<T> node, lazy;   // セグメントツリーを持つ配列
    
    // 二項演算
    T f(T a, T b){
        return min(a, b); // RMQ;
        // return a + b; // RSQ;
    };
    
    // 区間に対しての操作
    void g(T &a, T b, ll r = 1){
        a = b; // range update
        // a += b * r; // range add
    }
    
    // 子ノードへ伝搬するときの演算
    void h(T &a, T b){
        a = b; // range update
        // a += b / 2; // range add
    }
    
    void eval(int k, int l, int r){
        if(lazy[k] != init){            
            g(node[k], lazy[k]);
            
            if(r - l > 1){
                h(lazy[k * 2 + 1], lazy[k]);
                h(lazy[k * 2 + 2], lazy[k]);
            }
            
            lazy[k] = init;
        }
    }
    
public:
    LazySegmentTree(vector<T> v, T init = 0) : n(1), init(init) {
        int sz = v.size();
        while(n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.assign(2 * n - 1, init);
        
        for(int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) node[i] = f(node[i * 2 + 1], node[i * 2 + 2]);
    }
    
    LazySegmentTree(ll n, T init = 0) : LazySegmentTree(vector<T>(n, init), init) {}
    
    // [a, b) を x で更新
    void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        
        eval(k, l, r);
        
        if(b <= l || r <= a) return;
        
        if(a <= l && r <= b){
            g(lazy[k], x, (r - l));
            eval(k, l, r);
        }
        else{
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = f(node[2 * k + 1], node[2 * k + 2]);
        }
    }
    
    // [a, b) の値を求める
    T query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        
        eval(k, l, r);
        
        if(b <= l || r <= a) return init;
        if(a <= l && r <= b) return node[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
};



int main(){
    ll n, q;
    cin >> n >> q;
    LazySegmentTree<ll> tree(n, (1LL << 31) - 1);
    REP(i, q){
        ll query;
        cin >> query;
        if(query == 0){
            ll s, t, x;
            cin >> s >> t >> x;
            tree.update(s, t + 1, x);
        }
        else{
            ll s, t;
            cin >> s >> t;
            cout << tree.query(s, t + 1) << endl;
        }
    }
}


Measured memory_bytes: 7608
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m/2)cout << i+1 << " " << m-i << endl;
    rep(i, (m+1)/2)cout << i+1+m << " " << 2*m+1-i << endl;
}	


Measured memory_bytes: 3632
using System;
class aoj
{
    static void Main()
    {

        while (true)
        {
            char g='k';
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            char[,] b = new char[3,3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    b[i,j] = a[i * 3 + j];
                }
            }
            for (int i = 0; i < 3; i++)
            {
                if (b[i,0] == b[i,1] && b[i,1] == b[i,2] && b[i,2] != 's') { g = b[i,0];  goto stop;}
            }
            for (int i = 0; i < 3; i++)
            {
                if (b[0,i] == b[1,i] && b[1,i] == b[2,i] && b[2,i] != 's') { g = b[0, i]; goto stop; }
            }
            if (b[0,0] == b[1,1] && b[1,1] == b[2,2] && b[2,2] != 's') { g = b[0,0]; goto stop; }
            if (b[0,2] == b[1,1] && b[1,1] == b[2,0] && b[2,0] != 's') { g= b[0,2];  goto stop; }
            g = 'd';
            stop:;
            Console.WriteLine(g);
        }
    }
}

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

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

using namespace std;
const int INF = 2e16;
const int MB = 20;
const int MOD = 2019;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		g[from].push_back(to);
		g[to].push_back(from);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		bool good = true;
		for (int j : g[i]) {
			if (a[j] >= a[i]) good = false;
		}
		ans += good;
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 9780
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    uint N;
    cin >> N;
    uint a0{0}, a1{0}, a2{0};
    for (auto &&i: irange(0U, N)) {
        uint a;
        cin >> a;
        if (a % 2 == 0) {
            a /= 2;
            if (a % 2 == 0) {
                a2++;
            } else {
                a1++;
            }
        } else {
            a0++;
        }
    }
//    cout << a0 << " " << a1 << " " << a2 << endl;
    if (a1==0){
        if (a0 <= a2+1){
            cout << "Yes";
        }else {
            cout << "No";
        }
    } else {
        if (a0 <= a2){
            cout << "Yes";
        } else {
            cout << "No";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int i, j;
   char c[3][4];

   for(i=0;i<3;i++){
      scanf("%s", c[i]);
      }
   
   for(i=0;i<3;i++)
      printf("%c", c[i][i]);
   
   printf("\n");
   
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  string s;
  cin>>n>>s;
  int ret = 0;
  for(int i=0;i+2<s.size();i++)if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ret++;
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
ls_bf = list(map(int,input().split()))
ls_af = []
ls_sum = 0
am = 0
for i in range(n):
    ls_af.append(ls_bf[i] + ls_sum)
    ls_sum += ls_bf[i]

for i in ls_af:
    if abs(2*i - ls_af[n-1]) < abs(2 * am - ls_af[n-1]):
        am = i
# print(ls_af)
# print(ls_af[n-1])
print(abs(2*am - ls_af[n-1]))


Measured memory_bytes: 26060
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int n, k;
  readf("%s %s\n", &n, &k);
  auto h = readln.chomp.split.to!(long[]);
  sort!("a > b")(h);
  h[min(k,$)..$].sum.writeln;
}


Measured memory_bytes: 11248
module union_find_mod
    use,intrinsic :: iso_fortran_env
    private
    type,public:: union_find
        integer(int32),allocatable:: parent(:)
    contains
        procedure:: unite => uf_unite
        procedure:: root => uf_root
    end type

    interface union_find
        module procedure:: uf_init
    end interface
contains
    function uf_init(n) result(uf)
        type(union_find):: uf
        integer(int32):: n
        allocate(uf%parent, source=[(i,i=1,n)])
    end function


    recursive function uf_root(uf,x) result(ret)
        class(union_find):: uf
        integer(int32):: x,ret
        if (uf%parent(x) == x) then
            ret = x
        else
            uf%parent(x) = uf%root(uf%parent(x))
            ret = uf%parent(x)
        end if
    end function


    subroutine uf_unite(uf,a,b)
        class(union_find):: uf
        integer(int32),intent(in):: a,b
        integer(int32):: ra, rb

        ra = uf%root(a); rb = uf%root(b)
        if (ra == rb) return
        uf%parent(ra) = rb
    end subroutine
end module


program main
    use,intrinsic :: iso_fortran_env
    use union_find_mod
    implicit none
    integer(int32):: n,m,i,a,b,ans
    type(union_find):: uf
    integer(int32), allocatable:: cnt(:)


    read*, n,m
    uf = union_find(n)
    allocate(cnt(n),source=0)

    do i=1,m
        read*, a,b
        call uf%unite(a,b)
    end do

    do i=1,n
        cnt(uf%root(i)) = cnt(uf%root(i)) + 1
    end do
    ans=0
    do i=1,n
        if (cnt(i) > 0) ans=ans+1
    end do
    print'(i0)',ans-1
end program main

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

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int count = 1;
	for (int i = 1; i < N; ++i)
	{
		if (S[i] != S[i-1])
			count++;
	}
	cout << count << '\n';
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int result = (int) Math.round((Double.parseDouble(br.readLine()) / 2));
            
            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

int main()
{
    int n, x;
    cin >> n >> x;
    while (n || x)
    {
        int count = 0;
        for (int i = 1; i < n - 1; i++)
        {
            if(i + i + 1 + i + 2 > x)
            {
                break;
            }
            for (int j = i + 1; j < n; j++)
            {
                if(i + j + j + 1 > x)
                {
                    break;
                }
                if (i + j + n < x)
                {
                    continue;
                }
                
                for (int k = j + 1; k <= n; k++)
                {
                    if(i + j + k == x)
                    {
                        count++;
                        break;
                    }
                }
            }
        }
        cout << count << endl;
        cin >> n >> x;
}

        return 0;
}



Measured memory_bytes: 3092
H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]
B = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            B[i][j] = 1
C = []
for i in range(H-1,-1,-1):
    if sum(B[i])==0:
        C.append(i)
B1 = []
for i in range(H):
    if i not in C:
        B1.append(B[i])
C = []
for j in range(W):
    flag = 0
    for i in range(len(B1)):
        if B1[i][j]==1:
            flag = 1
            break
    if flag==0:
        C.append(j)
B2 = []
for i in range(len(B1)):
    row = []
    for j in range(W):
        if j not in C:
            row.append(B1[i][j])
    B2.append(row)
B3 = []
for i in range(len(B2)):
    x = ""
    for j in range(len(B2[i])):
        if B2[i][j]==0:
            x += "."
        else:
            x += "#"
    B3.append(x)
for i in range(len(B3)):
    print(B3[i])

Measured memory_bytes: 69768
'use strict';
const p = s => console.log(s);

// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  let X = input[0].split(" ")[0];
  let sum =100;
  let i=0;

  while(sum < X) {
    sum = Math.floor(sum * 1.01);
    i++;
  }
  p(i);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29788
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//var min, min2, count: Int!
//for i in 1...10 {
//    let x = Int(readLine()!)!
//    if i == 1 {
//        min = x
//        count = 1
//    } else if x < min {
//        min2 = min
//        min = x
//        count = 1
//    } else if x == min && count == 1 {
//        min2 = x
//        count = 2
//    }
//}
//print(min2)

/*************** メインプログラム ***************/

let N = Int(readStringSplit(by: " ").joinWithSeparator(""))!
var ans = "No"
for i in 1..<317 {
    if N == exponentiate(i, 2) {
        ans = "Yes"
        break
    }
}
print(ans)


Measured memory_bytes: 7908
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int n;
string s;

bool check(int x){
	int l, r;
	static bool isUseI[1000001], isUseO[1000001];
	int cntI = 0;
	
	for( r = 0; r < n; r++ ){ isUseI[r] = false; isUseO[r] = false; }
	
	for( r = n-1; r >= 0; r-- ){
		if( cntI == x ){
			break;
		}
		if( s[r] == 'I' ){
			isUseI[r] = true;
			cntI++;
		}
	}
	if( cntI < x ) return false;
	
	l = n-1;
	for( r = n-1; r >= 0; r-- ){
		if( isUseI[r] ){
			bool f = false;
			for( l = min(l, r); l >= 0; l-- ){
				if( s[l] == 'O' ){
					isUseO[l] = true;
					l--;
					f = true;
					break;
				}
			}
			if( !f ) return false;
		}
	}
	
	l = n-1;
	for( r = n-1; r >= 0; r-- ){
		if( isUseO[r] ){
			bool f = false;
			for( l = min(l, r); l >= 0; l-- ){
				if( s[l] == 'J' || (s[l] == 'I' && !isUseI[l]) ){
					l--;
					f = true;
					break;
				}
			}
			if( !f ) return false;
		}
	}
	return true;
}

int main(){
	int i;
	
	cin >> n;
	cin >> s;
	
	int st = 0, ed = n, medi;
	while( ed - st > 1 ){
		medi = (st + ed) / 2;
		if( check(medi) ){
			st = medi;
		}
		else{
			ed = medi - 1;
		}
	}
	medi = (st + ed) / 2;
	if( check(medi+1) )
		cout << medi+1 << endl;
	else
		cout << medi << endl;
	return 0;
}

Measured memory_bytes: 4176
#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int INF = 1e9+5;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a;
    for(int i=0,val;i<n;++i){
        cin>>val;
        a.push_back(val);
    }
    vector<int> dp(n , INF);
    dp[0] = 0;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<=i+k && j<n;++j){
            dp[j] = min(dp[j],dp[i] + abs(a[i]-a[j]));
        }
    }
    // for(auto i:dp) cout<<i<<' ';
    //     cout<<'\n';
    cout<<dp[n-1]<<'\n';
    return 0;
}

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

using namespace std;

typedef long long int lli;

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

    int n;
    vector<int> a(100000), b(100000), c(100000);
    vector<vector<int>> dp(3, vector<int>(100000, 0));

    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i] >> b[i] >> c[i];

    dp[0][0] = a[0]; dp[1][0] = b[0]; dp[2][0] = c[0];
    for (int day=1; day<n; day++) {
        dp[0][day] = max(dp[1][day-1], dp[2][day-1]) + a[day];
        dp[1][day] = max(dp[0][day-1], dp[2][day-1]) + b[day];
        dp[2][day] = max(dp[0][day-1], dp[1][day-1]) + c[day];
    }

    cout << max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1])) << endl;


    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){      
     string s;
     cin>>s;
     lint n=s.size();
     reverse(all(s));
     lint a[n];
     lint mul=1;
     rep(i,n){
         lint x=s[i]-'0';
         x*=mul;
         x%=2019;
         a[i]=x;
         mul*=10;
         mul%=2019;
     }
     lint b[n+1];
     lint ans=0;
     map<lint,lint> mp;
     b[0]=0;
     mp[0]++;
     rep(i,n){
         b[i+1]=b[i]+a[i];
         b[i+1]%=2019;
         mp[b[i+1]]++;
     }
     for(auto x:mp){
         ans+=x.second*(x.second-1)/2;
     }
     cout<<ans<<endl;
          }
  
     


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int N = (int)1e5 + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e13;
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n;
ll dp[N][5], a[N], b[N], c[N];
int main ()
{
    scanf ("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf ("%lld %lld %lld", a + i, b + i, c + i);
    }
    dp[1][1] = a[1], dp[1][2] = b[1], dp[1][3] = c[1];
    for (int i = 2; i <= n; ++i)
    {
        dp[i][1] = (max(dp[i - 1][2], dp[i - 1][3]) + a[i]);
        dp[i][2] = (max(dp[i - 1][1], dp[i - 1][3]) + b[i]);
        dp[i][3] = (max(dp[i - 1][1], dp[i - 1][2]) + c[i]);
    }
    printf ("%lld\n", max({dp[n][1], dp[n][2], dp[n][3]}));
    return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;
import java.util.ArrayList;


class Main{

	

	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}
	
}

class Solve{
	Solve(){}

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

	boolean f;
	int n;
	ArrayList<Integer> vx, vy;

	void solve(){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			int sx = in.nextInt(), sy = in.nextInt();
			if(sx == 0 && sy == 0) return;
			n = in.nextInt();
			f = false;
			vx = new ArrayList<Integer>();
			vy = new ArrayList<Integer>();
			for(int i = 0; i < n; i++){
				int x = in.nextInt(), y = in.nextInt();
				vx.add(x);
				vy.add(y);
			}
			dfs(sx, sy, 0);
			if(f) System.out.println("OK");
			else System.out.println("NA");
		}
	}

	void dfs(int x, int y, int k){
		if(k == n) {
			f = true;
			return;
		}
		for(int i = 0; i < 12; i++){
			int nx = x + dx[i],ny = y + dy[i];
			if(nx > 0 && ny > 0 && nx < 10 && ny < 10){
				for(int j = 0; j < 9; j++){
					if(nx + ddx[j] == vx.get(k) && ny + ddy[j] == vy.get(k)) {
						dfs(nx, ny, k + 1);
					}
				}
			}
		}
	}

}

Measured memory_bytes: 26320
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

signed main(){
    llin(n);
    llin(k);
    vll h(n);
    FOR(i,0,n-1){
        cin >>h[i];
    }
    rSORT(h);
    vll d(n-k+1);
    FOR(i,0,n-k){
        d[i]=h[i]-h[i+k-1];
    }
    SORT(d);
    sal(d[0]);
}


Measured memory_bytes: 1792
n = int(input())
l = list(map(int,input().split()))

c = True
for i in l:
    if i % 2 == 0:
        if (i%3 == 0) or (i%5 == 0):
            continue
        
        else:
            c = False
    
if c:
    print('APPROVED')

else:
    print('DENIED')

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>

using namespace std;
int main() {
    int k, a, b;

    cin >> k >> a >> b;

    int kk = k;
    if (k <= a || a >= b) {
        cout << k+1 << endl;
        return 0;
    }

    long long int cookie = 1;
    k -= a-1;
    cookie += a-1;
    while (k >= 2) {
        cookie += b-a;
        k -= 2;
    }

    if (k) cookie++;

    if (cookie > kk+1) cout << cookie << endl;
    else cout << kk+1 << endl;

    return 0;
 }

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;
using pr  = pair<ll, ll>;

const ll MOD = 998244353;

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

	if (S[2] == S[3] && S[4] == S[5])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "No"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if (0) cerr

void solve() {
    int n, m;
    cin >> n >> m;
    vector <pi> ans;
    int l = 1, r = n + 1 >> 1;
    while (l < r) {
        ans.pb({ l, r });
        ++l; --r;
    }
    r = n; l = (n + 1 >> 1) + (n % 2 ? 1 : 2);
    while (l < r) {
        ans.pb({ l, r });
        ++l; --r;
    }
    loop(i, m)
        cout << ans[i].F << " " << ans[i].S << "\n";
}
    

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


Measured memory_bytes: 5312
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;
const int inf = (int)1e9;

int main()
{
	int n;
	vector<int> t;
	
	scanf("%d", &n);
	t.resize(n - 1);
	for(int i = 0; i < n - 1; ++i)
		scanf("%d", &t[i]);
	
	int dpa[2][6000], dpb[2][6000];
	int *cura, *curb, *nexta, *nextb;
	
	cura = dpa[0];
	nexta = dpa[1];
	curb = dpb[0];
	nextb = dpb[1];
	
	for(int i = 0; i <= n / 2; ++i) {
		cura[i] = inf;
		curb[i] = 0;
	}
	cura[0] = curb[0] = 0;
	
	for(int a = 1; a <= n / 2; ++a) {
		
		nexta[0] = 0;
		nextb[0] = inf;
		
		for(int b = 1; b <= n / 2; ++b) {
			
			int cost = t[a + b - 2];
			int vala = inf, valb = inf;
			
			vala = min(cura[b], curb[b] + cost);
			valb = min(nexta[b - 1] + cost, nextb[b - 1]);
			
			nexta[b] = vala;
			nextb[b] = valb;
			//printf("[debug] (%d, %d, a) -> %d\n", a, b, vala);
			//printf("[debug] (%d, %d, b) -> %d\n", a, b, valb);
		}
		
		swap(cura, nexta);
		swap(curb, nextb);
	}
	
	int ans = min(cura[n / 2], curb[n / 2]);
	
	printf("%d\n", ans);
	
	return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

Measured memory_bytes: 1320