akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;


int main(){
  int a,b;
  cin >> a >> b;
  int ans[3]={a+b,a-b,a*b};
  auto itr = max_element(ans,ans+3);
  
  cout << ans[itr-ans] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st S;
  ci(S);
  S.at(3) = '8';
  co(S);
}


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

#define MAX 110
#define MENMAX 6
#define DICEMAX 100

typedef struct {
	int top;
	int S;
	int E;
	int W;
	int N;
	int down;
} stDicInfo;

typedef union {
	int Array[MENMAX];
	stDicInfo Dic;
} unionDiceInfo;

void input(int *dice)
{
	char *c;
	char str[MAX];
	int i;

	fgets(str, sizeof(str), stdin);
	if ((c=strchr(str,'\n')) != NULL) {
		*c = '\0';
	}

	for (i=0; i<MENMAX; i++) {
		if (i == 0) {
			c = strtok(str, " ");
		}
		else {
			c = strtok(NULL, " ");
		}
		dice[i] = strtol(c, NULL, 10);
	}
}

void input2(int *dice)
{
	char *c;
	char str[MAX];
	int i;

	fgets(str, sizeof(str), stdin);
	if ((c=strchr(str,'\n')) != NULL) {
		*c = '\0';
	}

	*dice = strtol(str, NULL, 10);
}


int main(void)
{
	unionDiceInfo dice[DICEMAX];
	stDicInfo *Rp1, *Rp2;
	int tmp, search;
	int num;
	int i;
	int cnt;
	int cnt1;
	unsigned char flg;
	bool isNo = false;

	input2(&num);

	for (i=0; i<num; i++) {
		input(dice[i].Array);
	}

	Rp1 = &dice[0].Dic;
	for (i=1; i<num; i++) {
		cnt = 0;
		cnt1 = 4;
		flg = 0;
		Rp2 = &dice[i].Dic;
		while (1) {
			if ((flg&0x01) == 0x01) {
				search = 2;
			}
			else if ((flg&0x02) == 0x02) {
				search = 1;
			}
			else if ((flg&0x04) == 0x04) {
				search = 0;
			}
			else {
				if (cnt < 4) {
					search = 0;
				}
				else if ((cnt >=4) && (cnt<8)) {
					search = 1;
				}
				else {
					search = 2;
				}
			}
			switch(search) {
			case 0:
				tmp = Rp2->top;
				Rp2->top	= Rp2->S;
				Rp2->S		= Rp2->down;
				Rp2->down	= Rp2->N;
				Rp2->N		= tmp;
				break;
			case 1:
				tmp = Rp2->top;
				Rp2->top	= Rp2->W;
				Rp2->W		= Rp2->down;
				Rp2->down	= Rp2->E;
				Rp2->E		= tmp;
				break;
			case 2:
				tmp		= Rp2->S;
				Rp2->S	= Rp2->W;
				Rp2->W	= Rp2->N;
				Rp2->N	= Rp2->E;
				Rp2->E	= tmp;
				break;
			default:
				break;
			}
			if ((Rp1->top == Rp2->top) && (Rp1->down == Rp2->down)) {
				flg |= 0x01;
			}
			if ((Rp1->S == Rp2->S) && (Rp1->N == Rp2->N)) {
				flg |= 0x02;
			}
			if ((Rp1->W == Rp2->W) && (Rp1->E == Rp2->E)) {
				flg |= 0x04;
			}
			if (flg == 0) {
				cnt++;
			}
			else {
				cnt1--;
			}
			if ((flg == 3) || (flg >= 7)) {
				if (memcmp(dice[0].Array,dice[i].Array,sizeof(stDicInfo)) == 0) {
					isNo = true;
				}
				break;
			}
			if ((cnt1 <= 0) || (cnt >= 11)) {
				break;
			}
		}
		if (isNo == true) {
			printf("No\n");
			break;
		}
	}
	if (isNo == false) {
		printf("Yes\n");
	}
	return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <stdlib.h>
#include <stack>
#include<vector>
#include<queue>
#include<algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(){
	int n; cin >> n;
	vector<int>v(n);
	rep(i, n)
		cin >> v[i];

	vector<int>s = v;
	sort(s.rbegin(), s.rend());
	rep(i, n){
		int ans = s[0];
		if(s[0] == v[i])
			ans = s[1];

		cout << ans << endl;

	}

    return 0;
}


Measured memory_bytes: 3200
# cook your dish here
a,b,c = map(int,input().split())

res = float("inf")

if a % 2 ==0:
    res = 0
else:
    res = min(res,b*c)

if b % 2 ==0:
    res = 0
else:
    res = min(res,a*c)

if c % 2 ==0:
    res = 0
else:
    res = min(res,b*a)
print(res)

Measured memory_bytes: 3064
#!/usr/bin/env pypy3

import collections


def solve(n, m, hs, adj_list):
    res = 0
    for u, vs in enumerate(adj_list):
        heights = collections.Counter(hs[v] for v in vs)
        heights[hs[u]] += 1
        if max(heights.keys()) == hs[u] and heights[hs[u]] == 1:
            res += 1
    return res


def main():
    n, m = (int(z) for z in input().split())
    hs = [int(z) for z in input().split()]
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        a, b = (int(z) - 1 for z in input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    res = solve(n, m, hs, adj_list)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 119308
import java.util.Scanner;

//  ABC 081 A - Placing Marbles

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    int index = 0;
	int count = 0;

   while(true) {
	   index = a.indexOf("1", index) + 1;
	   if(index == 0) break;
	   count++;
   }
   System.out.println(count);
  }
}

Measured memory_bytes: 23764
import sys
from collections import namedtuple


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    sword = namedtuple('sw', ('wield', 'throw'))
    n, h = map(int, input().split())
    swords = [sword(next_int(), next_int()) for _ in range(n)]
    cnt = 0

    swords.sort(key=lambda x: x.throw, reverse=True)
    swords.sort(key=lambda x: x.wield)
    main_sword = swords.pop()
    swords.sort(key=lambda x: x.throw)

    while h > 0:
        cnt += 1
        if main_sword.throw >= h:
            h -= main_sword.throw
        elif len(swords) > 0 and main_sword.wield < swords[-1].throw:
            h -= swords.pop().throw
        else:
            h -= main_sword.throw
            cnt += 1 + (h - 1) // main_sword.wield
            break

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 69340
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(n: i64) -> i64 {
    800 * n - (n / 15) * 200
}

fn main() {
    input! {
        n: i64
    }
    println!("{}", solve(n));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
vector<string> create(int n, int m){
	vector<string> a(n, string(m, '.'));
	return a;
}
vector<string> solve(vector<string> g, int n, int m, int a, int b, int has_a, int has_b, bool &bad){
	for(int i = 0; i < n; i += 2){
		for(int j = 0; j < m; j += 2){
			if(i + 1 < n && j + 1 < m){
				if(g[i][j] == '.' && g[i][j+1] == '.' && g[i+1][j] == '.' && g[i+1][j+1] == '.'){
					g[i][j] = '<';
					g[i][j + 1] = '>';
					g[i + 1][j] = '<';
					g[i + 1][j + 1] = '>';
					has_a += 2;
				}
			}
		}
	}
	for(int i = 0; i < n; i++) for(int j = 0; j < m - 1; j++) if(g[i][j] == '.' && g[i][j + 1] == '.'){
		g[i][j] = '<';
		g[i][j + 1] = '>';
		has_a++;
	}
	if(has_a < a){
		bad = true;
		return g;
	}
	for(int i = 0; i < n - 1; i++) for(int j = 0; j < m; j++) if(g[i][j] == '.' && g[i + 1][j] == '.'){
		if(has_b < b){
			g[i][j] = '^';
			g[i+1][j] = 'v';
			has_b++;
		}
	}
	for(int i = 0; i < n; i += 2){
		for(int j = 0; j < m; j += 2){
			if(i + 1 < n && j + 1 < m){
				if(g[i][j] == '<' && g[i][j + 1] == '>' && g[i+1][j] == '<' && g[i+1][j+1] == '>'){
					if(has_a - 2 >= a){
						has_a -= 2;
						g[i][j] = '.';
						g[i][j+1] = '.';
						g[i+1][j] = '.';
						g[i+1][j+1] = '.';
						if(has_b + 2 <= b){
							g[i][j] = '^';
							g[i][j+1] = '^';
							g[i+1][j] = 'v';
							g[i+1][j+1] = 'v';
							has_b += 2;
						}
					}
				}
			}
		}
	}
	for(int i = n - 1; i >= 0; i--) for(int j = 0; j < m - 1; j++) if(g[i][j] == '<' && g[i][j+1] == '>'){
		if(has_a > a){
			g[i][j] = '.';
			g[i][j + 1] = '.';
			has_a--;
		}
	}
	assert(has_a == a);	
	for(int i = 0; i < n - 1; i++) for(int j = 0; j < m; j++) if(g[i][j] == '.' && g[i + 1][j] == '.'){
		if(has_b < b){
			g[i][j] = '^';
			g[i+1][j] = 'v';
			has_b++;
		}
	}
	bad = has_a != a || has_b != b;
	return g;
}
void print(vector<string> g, int n){
	cout << "YES" << endl;
	for(int i = 0; i < n; i++) cout << g[i] << endl;
	exit(0);
}
int main(){
	int n, m, a, b; cin >> n >> m >> a >> b;
	{
		bool ok = true;
		vector<string> ans = solve(create(n, m), n, m, a, b, 0, 0, ok);
		if(!ok) print(ans, n);
	}
	{
		if(n >= 3 && m >= 3){
			vector<string> g = create(n, m);
			g[n - 3][m - 3] = '<';
			g[n - 3][m - 2] = '>';
			g[n - 3][m - 1] = '^';
			g[n - 2][m - 3] = '^';
			g[n - 2][m - 1] = 'v';
			g[n - 1][m - 3] = 'v';
			g[n - 1][m - 2] = '<';
			g[n - 1][m - 1] = '>';
			bool ok = true;
			vector<string> ans = solve(g, n, m, a, b, 2, 2, ok);
			if(!ok) print(ans, n);
		}
	}
	cout << "NO" << endl;
	return 0;
}




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

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

#define fr first
#define sc second

int main(){
	int n;
	int h[22];
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&h[i]);
	}
	
	int ret = 0;
	int MAX = 0;
	for(int i = 0 ; i < n ; i ++){
		if(MAX <= h[i]){
			ret ++;
			MAX = h[i];
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
};

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

	UnionFind uf(n + 1);
	for(int i = 0; i < m; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		uf.merge(x, y);
	}

	bool f[N + 1];
	for(int i = 1; i <= n; i++) f[i] = false;
	for(int i = 1; i <= n; i++) f[uf.root(i)] = true;

	int ans = 0;
	for(int i = 1; i <= n; i++) if(f[i]) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
const int inf = 1<<28;

int limit, n, m, x;
int e0[102], s0[102], e1[102], s1[102];
int dp[102][1002];

void solve() {
  int i, j, k, l, ii, jj;
  string in;
  rep (i,n) cin >> in >> e0[i] >> s0[i];
  rep (i,m) cin >> in >> e1[i] >> s1[i];

  memset(dp, -1, sizeof dp);
  //rep (i,102) fill(dp[i], dp[i] + 1002, -inf);
  // dp[A][B] := AlÌlðB~ÅÙÁ½êÌÅåÌ«x
  // 0lð0~ÅÙÁ½êÍ«x0ÆÝÈµ
  // »êÈOÌê(1lð0~Æ©-1~Æ©ÁÄ¢¤ÌÍ
  // á¦Îdp[2][0] = -1¾Æ0~Åñlð«x-1É·é±Æªoé©ç
  // vZÊÅdp[3][..]Å©ÈèÀ­3lÚð¤±ÆªÅ«éæ¤ÉÈé½ß)
  // -INFµÄ¨­Kvª Á½±ÆÉCÃ¢½
  // «xÌlªå«­ÈéêÍ±ê¶áÊÚ©àË
  // æÁÄdp[0][0] = 0ÌÝú»µÄ¨­
  dp[0][0] = 0;
  for (i = 0; i < m; ++i) {
    for (j = i; j >= 0; --j) {
      for (k = e1[i]; k <= limit; ++k) {
        if (dp[j][k - e1[i]] < 0) continue;
        dp[j+1][k] = max(dp[j+1][k], dp[j][k - e1[i]] + s1[i]);
      }
    }
  }
  
  int ans = -inf;
  for (i = x; i <= m; ++i) {
    for (j = 0; j <= limit; ++j) if (dp[i][j] >= 0) {
      for (k = 0; k < n; ++k) {
        if (j + e0[k] <= limit) ans = max(ans, dp[i][j] + s0[k]);
        for (l = 0; l < k; ++l) {
          if (j + e0[k] + e0[l] <= limit) {
            ans = max(ans, dp[i][j] + s0[k] + s0[l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

int main() {
  while (cin >> limit >> n >> m >> x, limit) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 1324
<?php

fscanf(STDIN, "%d %d %d %d", $sx, $sy, $tx, $ty);
$width = $tx - $sx;
$height = $ty - $sy;

for($i = 0; $i < $width; $i++)
{
  echo "R";
}
for($i = 0; $i < $height; $i++)
{
  echo "U";
}
echo "U";
for($i = 0; $i < $width; $i++)
{
  echo "L";
}
echo "L";
for($i = 0; $i < $height; $i++)
{
  echo "D";
}
echo "D";
echo "R";
echo "D";
for($i = 0; $i < $width; $i++)
{
  echo "R";
}
echo "R";
for($i = 0; $i < $height; $i++)
{
  echo "U";
}
echo "U";
echo "L";
for($i = 0; $i < $width; $i++)
{
  echo "L";
}
for($i = 0; $i < $height; $i++)
{
  echo "D";
}
echo "\n";

Measured memory_bytes: 3576
n, *H = map(int, open(0).read().split())

inc = True
maxes, mins = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            maxes.append(h0)
            inc = False
    else:
        if h0 < h1:
            mins.append(h0)
            inc = True
if inc:
    maxes.append(H[-1])
print(sum(maxes)-sum(mins))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < 26; ++i)
        cin >> c[i];
    for (int i = 0; i < D; ++i)
        for (int j = 0; j < 26; ++j)
            cin >> s[i][j];
    vector<int> t(D);
    vector<int> last(26), ans(D + 1);
    for (int i = 0; i < D; ++i) {
        int ma = 0;
        for (int k = 0; k < 26; ++k) {
            int res = ans[i];
            res += s[i][k];
            for (int j = 0; j < 26; ++j)
                if (j != k)
                    res -= c[j] * (i + 1 - last[j]);
            if (ans[i + 1] < res) {
                ans[i + 1] = res;
                ma = k;
            }
        }
        t[i] = ma + 1;
        last[ma] = i + 1;
        cout << t[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[200005];
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d",a+i);
		a[i]-=i;
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    sort(a,a+n);
	int b=a[n/2];
	LL ret=0LL;
	for(i=0;i<n;++i){
		ret+=(LL)ABS(a[i]-b);
	}
	printf("%lld\n",ret);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    s = input()
    k = int(input())
    s2 = []
    s2a = s2.append
    for se in s:
        if ord(se) - 97:
            s2a(123 - ord(se))
        else:
            s2a(0)
    s2_ac = tuple(accumulate(s2))
    lens = len(s)
    if s2_ac[-1] < k:
        k -= s2_ac[-1]
        k = k % 26
        r = 'a' * (lens - 1) + chr(97 + k)
        print(r)
    elif s2_ac[-1] == k:
        r = 'a' * lens
        print(r)
    else:
        pos = bisect(s2_ac, k)
        if pos == 0:
            r = chr(k + ord(s[0])) + s[1:]
            print(r)
        elif s2_ac[pos-1] == k:
            r = 'a' * pos + s[pos:]
            print(r)
        else:
            r = 'a' * pos
            k -= s2_ac[pos-1]
            for i1 in range(pos, len(s)):
                if s2[i1] <= k:
                    r += 'a'
                    k -= s2[i1]
                else:
                    r += s[i1]
            if k:
                lastc = chr(ord(r[-1]) + k)
                r = r[:-1] + lastc
            print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14132
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[10];
int prim(int n)
{
	int b, flag = 1;
	while(n)
	{
		b = n % 10;
		if(a[b])
		{
			flag = 0;
			break;
			}
		n /= 10;
		}
	if(flag)return 1;
	return 0;
	}
int main()
{
	int n, k, s, t;
	scanf("%d %d", &n, &k);
	memset(a, 0, sizeof(a));
	for(int i = 0; i < k; i++)
	{
		scanf("%d", &t);
		a[t] = 1;
		}
	for(int i = n;;i++)
	{
		if(prim(i))
		{
			printf("%d\n", i);
			break;
			}
		}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll A;
	double B;
	cin >> A >> B;
	B *= 100;
	ll b = round(B);
	A *= b;
	A /= 100;
	cout << A << endl;
}

Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool func(pair< int, int > a, pair< int, int > b){
	return a.second < b.second;
}

int main() {
	int n;
	int c, m1, s1, m2, s2, m3, s3, m4, s4;
	vector< pair< int, int > > data;
	
	while(cin >> n, n){
		
		data.clear();
		
		for(int i = 0; i < n; ++i){
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			data.push_back(make_pair(c, (m1+m2+m3+m4) * 60 + s1+s2+s3+s4));
		}
		
		sort(data.begin(), data.end(), func);
		
		cout << data[0].first << endl;
		cout << data[1].first << endl;
		cout << data[n - 2].first << endl;
	}
	return 0;
}

Measured memory_bytes: 1304
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a + b == c || a + c == b || b + c == a) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}



	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
int main()
{
  int d[] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1};
  int ans[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int n, i, b = 0;
  while(scanf("%d", &n) != EOF)
  {
    for(i = 9; i >= 0; i--)
    {
      d[9 - i] = pow(2, i);
      ans[i] = 0;
    }
    b = 0;
    for(i = 0; i < 10; i++)
    {
      if(d[i] <= n)
      {
        n -= d[i];
        ans[i] = 1;
      }
    }
    for(i = 9; i >= 0; i--)
    {
      if(ans[i])
      {
        if(b)
          printf(" ");
        else
          b = 1;
        printf("%d", d[i]);
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> V(N), C(N);
	for(int i = 0; i < N; i++)
		cin >> V.at(i);
	int sum = 0;
	for(int i = 0; i < N; i++){
		cin >> C.at(i);
		int dif = V.at(i)-C.at(i);
		if(0 < dif)
			sum += dif;
	}
	cout << sum << endl;
}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;



void solve()
{
      
      int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      int k; cin >> k;
      cout << arr[k-1] ;

}


int32_t main()
{
      
      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

      int t = 1;
      //cin >> t;
      while(t--) solve();

}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






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

#define int long long

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

int N, M;
int num[100001] = {};
bool possible[100001] = {};

signed main() {
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        num[i] = 1;
    }
    possible[1] = true;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        if (possible[x]) {
            possible[y] = true;
        }
        num[x]--;
        num[y]++;
        if (num[x] == 0) {
            possible[x] = false;
        }
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (possible[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
from collections import deque
N = int(input())
A = list(map(int, input().split()))
B = deque([])
c = 1
for a in A:
  if c:
    B.append(a)
  else:
    B.appendleft(a)
  c = 1-c
if N%2:
  B.reverse()
print(*B)

Measured memory_bytes: 32472
import java.util.Scanner;

public class Main{
  static int n;
  static int[] a;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int max = 0, min = n;
    for(int i = 0; i < n; i++){
      max = Math.max(max, a[i]);
      min = Math.min(min, a[i]);
    }

    if(max - min >= 2){
      System.out.println("No");
      return;
    }

    if(max == min){
      if(max == n - 1 || 2 * max <= n){
        System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }
    }
    else{
      int x = 0, y = 0;
      for(int i = 0; i < n; i++){
        if(a[i] == max){
          ++x;
        }
        if(a[i] == min){
          ++y;
        }
      }
      if(y < max && 2 * (max - y) <= x){
        System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 50588
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
/*
    vec1.size();
    str1.length();
    vec1.pop_back;
*/
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<pll> vplll;
#define rep(i,l,r) for (ll i = l; i < r; ++i)
#define reprev(i,l,r) for (ll i = r; i >= l; --i)
ll mod = 1e9+7;
ll expo_mod(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p; 
    if (x == 0) 
        return 0; 
    while (y > 0) 
    {
        if (y%2==1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,w;
    cin>>h>>w;
    string str1[h+1];
    ll dp[h+1][w+1];
    rep(i,0,h)
    {
        cin>>str1[i];
    }
    rep(i,0,h)
    {
        rep(j,0,w)
        {
            if(str1[i][j]=='#')
            {
                dp[i][j]=0;
            }
            else
            {
                if(i==0 && j==0)
                {
                    dp[i][j]=1;
                }
                else if(i==0)
                {
                    dp[i][j]=dp[i][j-1];
                }
                else if(j==0)
                {
                    dp[i][j]=dp[i-1][j];
                }
                else
                {
                    dp[i][j]=dp[i-1][j]+dp[i][j-1];
                    dp[i][j]%=mod;
                }
                
            }
            
        }
    }
    cout<<(dp[h-1][w-1]%mod)<<"\n";
    return 0;
}

Measured memory_bytes: 9088
#include <cstdio>
#include <vector>

int main(int argc, const char *argv[]) {
  int N, K;
  std::vector<int> A;

  scanf("%d", &N);
  scanf("%d", &K);

  for (int i = 0; i < N; i++) {
    int a;
    scanf("%d", &a);
    A.push_back(a);
  }

  int sum = 0;
  for (auto it = A.begin(); it != A.end(); it++) {
    sum += *it;
  }

  int n, t;
  for (n = sum; n >= 0; n--) {
    if (sum % n != 0) continue;

    std::vector<std::pair<int, int> > tbl;
    t = 0;
    for (auto it = A.begin(); it != A.end(); it++) {
      int l = (*it / n) * n;
      int m = *it - l, p = (l + n) - *it;
      tbl.push_back(std::make_pair(m, p));
      t += p;
    }
    std::sort(tbl.begin(), tbl.end());

    int aaa = 0;
    for (auto it = tbl.begin(); it != tbl.end(); it++) {
      aaa += it->first;
      t -= it->second;

      if (aaa == t) break;
    }

    if (t <= K) {
      printf("%d\n", n);
      return 0;
    }
  }
}

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

//	データセットの終わりを処理したら0,
//	それ以外なら1を返す関数
//	問題を解く部分
int solve();

int main() 
{
	while(solve()){}
	return 0;
}

int solve() 
{
	//	入力ここから
	int n;
	cin >> n;
	if(!n) { return 0; }
	
	vector<int> a(n);
	for(int& i: a)
		cin >> i;
	//	入力ここまで
	
	//	差の絶対値の最小値を調べる
	//	全探索でO(n^2)
	
	int ans = 1000000+1;
	for(int i = 0; i < n; i++)
		for( int j = i + 1; j < n; j++)
			ans = min( abs(a[i]-a[j]), ans);
			
	//	出力
	cout << ans << endl;
	
	return 1;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	string S;
	cin >> S;
	S[3]='8';
	cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<map>
#include<string>
#include<stdio.h>
#include<math.h>
#include <algorithm>

#define PI		3.14159265358979
#define IMAX	2147483647

using namespace std;

int main(void) {

	char c;
	cin >> c;
	switch (c) {
	case 'A':
		cout << 'T';
		break;
	case 'C':
		cout << 'G';
		break;
	case 'G':
		cout << 'C';
		break;
	case 'T':
		cout << 'A';
		break;
	}



//	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
#include <set>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,M;
    int a,b,c;
    cin>>N>>M;
    vector<pair<int,int>> vec;
    rep(i,N){
        cin>>a;
        vec.push_back(make_pair(a,1));
    }
    rep(i,M){
        cin>>b>>c;
        vec.push_back(make_pair(c,b));
    }
    sort(vec.begin(),vec.end());
    ll ans=0;
    int num=0;
    pair<int,int> p;
    while(true){
        p=vec.back();
        vec.pop_back();
        if(N<(num+p.second)) {
            ans+=(ll)(N-num)*p.first;
            break;
        }else{
            ans+=(ll)p.first*p.second;
            num+=p.second;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
int main(){

    int a,b,c;
    cin>>a>>b>>c;
    
    if(a>c){
        cout<<"NO"<<endl;
    }else if(a==c||a+b>=c){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
return 0;
}

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

using namespace std;
typedef long long ll;

int main(void){
   int n;
   scanf("%d", &n);
   vector<int> p(n), q(n),ans(n);

   for (int i = 0; i < n; i++)
      cin >>p.at(i);
   for (int i = 0; i < n; i++)
      cin >> q.at(i);

   for (int i = 0; i < n;i++)
      ans[i] = i + 1;

   int x, y;
   int cnt = 0;

   do{
      if(p == ans)
         x = cnt;
      if(q == ans)
         y = cnt;
      cnt++;
   } while (next_permutation(ans.begin(), ans.end()));

   cout << abs(x - y) << endl;

   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        while(true) {
            int n = scan.nextInt();
            if(n == 0) {
                break;
            }
            
            double[] s = new double[n];
            double sum = 0;
            for(int i = 0; i < n; i++) {
                s[i] = scan.nextDouble();
                sum += s[i];
            }
            
            double m = sum / n;
            double sigma_result = 0;
            for(int i = 0; i < n; i++) {
                sigma_result += Math.pow(s[i] - m, 2);
            }
            
            double a2 = sigma_result / n;
            double a = Math.sqrt(a2);

            System.out.println(a);
        }
    }
}



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

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		int[] values = new int[N];
		for(int i=0; i<N; i++) {
			values[i] = in.nextInt();
		}
		
		ArrayList<Integer> minus;
		long max = Long.MIN_VALUE;
		for(int l=0; l<=K; l++) {
			for(int r=0; r<=Math.min(K-l,N-l); r++) {
				long point = 0;
				minus = new ArrayList<>();
				for(int li=0; li<l; li++) {
					point += values[li];
					if(values[li]<0) minus.add(values[li]);
				}
				for(int ri=0; ri<r; ri++) {
					point += values[N-1-ri];
					if(values[N-1-ri]<0) minus.add(values[N-1-ri]);
				}
				minus.sort((i,j)->Integer.compare(i, j));
				for(int back=0; back<K-(l+r); back++) {
					if(minus.size()<=back) break;
					point -= minus.get(back);
				}
				max = Math.max(max, point);
			}
		}
		System.out.println(max);
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    vi h;
    ll n,m,i,j,k;

    cin>>n;
    SIZE(h,n);
    rep(i,n){
        cin>>h[i];
    }
    m=0;
    j=0;
    k=n-1;
    while(k>=1){
        if(h[k-1]>=h[k]){
            j++;
            k--;
        }
        else{
            m=max(m,j);
            j=0;
            k--;
        }
    }
    m=max(m,j);
    cout<<m;
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector <int> lst[200005];
int x[200005], y[200005];
int doLeft(){
    for(int i=0;i<=m;i++)   lst[i].clear();

    for(int i=1;i<=n;i++)
        lst[x[i]].push_back(y[i]);

    int lim = 0;
    for(int i=0;i<=m;i++){
        int counter = lst[i].size();
        while(lim < i && counter)
            lim ++,
            counter --;
    }

    priority_queue <int, vector <int>, greater<int> > pq;
    for(int i=m;i>=0;i--){
        for(auto v: lst[i])
            pq.push(v);
        if (i && i <= lim)
            pq.pop();
    }
    int leftRes = lim;
    lim = 0;
    for(int i=0;i<=m;i++)   lst[i].clear();
    while(pq.size()) lst[pq.top()].push_back(1), pq.pop();

    for(int i=0;i<=m;i++){
        int counter = lst[i].size();
        while(lim < i && lim < m - leftRes && counter)
            lim ++,
            counter --;
    }

    return n - (leftRes + lim);
}
int doRight(){
    for(int i=0;i<=m;i++)   lst[i].clear();

    for(int i=1;i<=n;i++)
        lst[y[i]].push_back(x[i]);

    int lim = 0;
    for(int i=0;i<=m;i++){
        int counter = lst[i].size();
        while(lim < i && counter)
            lim ++,
            counter --;
    }

    priority_queue <int, vector <int>, greater<int> > pq;
    for(int i=m;i>=0;i--){
        for(auto v: lst[i])
            pq.push(v);
        if (i && i <= lim)
            pq.pop();
    }
    int leftRes = lim;
    lim = 0;
    for(int i=0;i<=m;i++)   lst[i].clear();
    while(pq.size()) lst[pq.top()].push_back(1), pq.pop();

    for(int i=0;i<=m;i++){
        int counter = lst[i].size();
        while(lim < i && lim < m - leftRes && counter)
            lim ++,
            counter --;
    }

    return n - (leftRes + lim);
}
int main(){
    iostream::sync_with_stdio(0);
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin >> x[i] >> y[i];
        y[i] = m+1 - y[i];
    }
    cout << min(doLeft(), doRight());
}

Measured memory_bytes: 11708
s = gets.chomp.chars
hs = Hash.new(false)
n = s.size

if n < 26
  s.each do |c|
    hs[c] = true
  end
  lb = "a"
else
  cur = "a"
  while !s.empty? && s[-1] >= cur
    hs[s[-1]] = true
    cur = s.pop
  end

  if s.empty?
    puts "-1"
    exit
  end
  lb = (s.pop.ord + 1).chr
end

(lb.."z").each do |c|
  if hs[c] == (n >= 26)
    puts s.join("") + c
    break
  end
end

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


int main(){
  int N , K , cnt; 
  cin >> N >> K ; 
  vector<int> h(N) ; 
  cnt = 0 ; 
  
  for (int i = 0 ; i < N ; i++){
    cin >> h[i] ;
    if(h[i] >= K){
      cnt++ ; 
    }
  }
  
  cout << cnt << endl ; 
  
  
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  vector<int> N(3); int K;
  cin >> N[0] >> N[1] >> N[2] >> K;
  sort(N.begin(), N.end());
  rep(i, K) N[2] = N[2]*2;
  cout << N[0] + N[1] + N[2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define Int long long




int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    Int n;
    cin>>n;
    Int cv=(n*(n+1))/2;
  	cv*=n;
  	for(int i = 1;i<=n;i++)
    {
        Int j = (n*(n+1))/2;
      	j-=(i)*(n-i+1);
        cv-=j;
    }
    for(int i = 1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
      	if(x>y)swap(x,y);
        cv-=x*(n-y+1);
    }
  	assert(cv>=0);
    cout<<cv<<endl;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            string todey = Console.ReadLine();
            string[] next_holidey = { null, "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

            for(int i = 1; i < 8; i++)
            {
                if (todey == next_holidey[i]) Console.WriteLine(8-i);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
vector <vector<int>> a(3),h(3);
int n,tmp;
//int n,a[3][3];
cin >> n;
for (int i=0;i<n;i++){
  for (int j=0;j<3;j++){
    cin >>tmp;
    a[j].push_back(tmp);
  }
}

h[0].push_back(a[0][0]);
h[1].push_back(a[1][0]);
h[2].push_back(a[2][0]);
for (int i=1;i<n;i++){
  h[0].push_back(a[0][i]+max(h[2][i-1],h[1][i-1]));
  h[1].push_back(a[1][i]+max(h[2][i-1],h[0][i-1]));
  h[2].push_back(a[2][i]+max(h[1][i-1],h[0][i-1]));
  //cout <<h[0][i]<<' '<<h[1][i]<<' '<<h[2][i]<<' '<<endl;
}
cout << max(h[0][n-1],max(h[1][n-1],h[2][n-1]));
return 0;
}


Measured memory_bytes: 2924
import java.util.*;

public class Main {
    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        if(N%2==0){
            System.out.println(N/2);
        }else{
            System.out.println(N/2+1);
        }

    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <set>
#include <vector>

using namespace std;

#define forsn(i,s,n) for(int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)

char word[32];

int main() {
	string s; cin >> s;
	
	forn(i,s.size()) {
		word[i] = (s[i] - 'a' + 1);
	}
	word[s.size()] = 0;
	
	string best = "-1";
	
	set<int> current; forn(i, ('z' - 'a') + 5) current.insert(i);
	forn(i, s.size() + 1) {
		int possible_next = *current.upper_bound(word[i]);
		if (possible_next <= ('z' - 'a' + 1)) {
			best = s.substr(0, i) + (char)('a' + possible_next - 1);
			//~ options.push_back(s.substr(0, i) + (char)('a' + possible_next - 1));
		}
		current.erase(word[i]);
	}
	
	cout << best << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int s[n],sum=0;
  for(int i=0;i<n;i++){
    cin >> s[i];
    sum+=s[i];
  }
  int sum1=sum;
  sort(s,s+n);
  if(sum%10!=0) cout <<sum<<endl;
  else{
    for(int i=0;i<n;i++){
      sum-=s[i];
      if(sum%10!=0) {
        cout << sum<<endl; return 0;
      }
      sum=sum1;
    }
    cout << 0<<endl;
  }
}


Measured memory_bytes: 256
open Printf

let n = int_of_string @@ read_line ()
let a =
  Str.split (Str.regexp " ") @@ read_line ()
  |> List.map int_of_string
  |> (fun l -> 0 :: l)
  |> Array.of_list

let memo = Array.make_matrix (n+1) (n+1) max_int

let rec solve: int -> int -> bool -> int = fun bg ed turn ->
  if memo.(bg).(ed) <> max_int then
    memo.(bg).(ed)
  else (
    if bg = ed then begin
      memo.(bg).(ed) <- a.(bg) * (if turn then 1 else -1);
      memo.(bg).(ed)
    end
    else (
      let left = solve (bg+1) ed (not turn) in
      let right = solve bg (ed-1) (not turn) in
      if turn then
        memo.(bg).(ed) <- max (left + a.(bg)) (right + a.(ed))
      else
        memo.(bg).(ed) <- min (left - a.(bg)) (right - a.(ed));
      memo.(bg).(ed)
    )
  )

let () =
  solve 1 n true
  |> string_of_int
  |> print_endline


Measured memory_bytes: 74104
import sys
myin = [x.rstrip() for x in sys.stdin.readlines()]

n = int(myin[0])
a = [int(x) for x in myin[1].split()]

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

Measured memory_bytes: 81872
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;ll n;
	           cin>>n;
	           ll a[n+1];
	for (int i = 1; i <= n; i+=1)cin>>a[i];
	ll minn=2147483647,ans=0;
	for (int i = 1; i <= n; i+=1)
	{
		minn = min(minn, a[i]);
		if (minn == a[i]) ++ans;
	}
	cout << ans << endl;
	return 0;

}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

void solve() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  ll l = a - (a / c + a / d) + a / lcm(c, d);
  ll r = b - (b / c + b / d) + b / lcm(c, d);
  cout << r - l << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int m = Integer.parseInt(tokenizer.nextToken());
        int [] data = new int[m];
        Arrays.fill(data, n/m);
        int index = 0;
        int reminder = n % m;
        while (reminder > 0){
            data[index]++;
            index++;
            index %= m;
            reminder--;
        }
        System.out.println(data[0]  - data[m -1]);
    }
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(0);
	int H, W;
	char a[105][105];
	int cnt[255]={};

	cin >> H >> W;
	rep(i,H) rep(j,W){
		cin >> a[i][j];
		cnt[ a[i][j]-'a' ]++;
	}

	if( H > W ) swap(H, W);

	bool ans = false;
	if( H == 1 && W == 1 ) ans = true;
	if( H == 1 ){
		int odd=0;
		rep(i,30) if(cnt[i] % 2) odd++;
		if( W % 2 == 0 ){
			ans = (odd == 0);
		}else{
			ans = (odd == 1);
		}
	}else if( H % 2 == 0 ){
		int c[5]={};
		rep(i,26){
			if(cnt[i] % 4 == 0) c[4]++;
			else if( cnt[i] % 2 == 0 ) c[2]++;
			else c[1]++;
		}
		if( W % 2 == 0 ){
			ans = (c[1] == 0 && c[2] == 0);
		}else{
			ans = (c[1] == 0 && c[2] <= H/2);
		}
	}else{
		int c[5]={};
		rep(i,26){
			if(cnt[i] % 4 == 0) c[4]++;
			else if( cnt[i] % 2 == 0 ) c[2]++;
			else c[1]++;
		}
		if( W % 2 == 0 ){
			ans = (c[1] == 0 && c[2] <= W/2);
		}else{
			ans = (c[1] == 1 && c[2] <= W/2 + H/2);
			//rep(i,26){
			//	if(cnt[i] % 4 == 0) cnt[i] %= 4;
			//}
		}
	}

	cout << (ans?"Yes":"No") << endl;

	return 0;
}

Measured memory_bytes: 256