akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
map <int, int> m;
vector <pair<int, int>> g[16];
void sol() {
  int bit[16];
  int n;
  int a;
  cin >> n;
  int val = (int)pow(2, n);
  for(int i=0; i<n; i++) {
    int x, y;
    cin >> a;
    for(int j=0; j<a; j++) {
      cin >> x >> y;
      g[i].pb(mp(x, y));
    }  
  }
  int ans = 0;
  for(int pp=0; pp<val; pp++) {
    int cnt = 0;
    int v = 1;
    m.clear();
    memset(bit, 0, sizeof(bit));
    int k = pp, q = 0;
    while(k) {
      bit[q++] = k % 2;
      if(k % 2) cnt++;
      k/=2;
    }
    for(int i=0, j=n-1; i<n/2; i++, j--) {
    	swap(bit[i], bit[j]);
    }
    for(int i=0; i<n; i++) {
      
      if(!bit[i]) { 
        ;
      }
      else {
        for(auto j: g[i]) {
          int x = j.first;
          int y = j.second;
          if(y != bit[x-1]) v = 0;
        }
      }
    }
    if(v) {
      ans = max(ans, cnt);
    }
  }
  cout << ans << "\n";
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int H, N, A[1001], B[1001];
int DP[20003]; // 0-idx番目の魔法を使える, 減らせる体力0-H. 最小の魔力
typedef pair<int, int> P;
P C[1001];
int max_tai;

void calc(int idx) {
  P p = C[idx];
  int b = p.first, a = p.second; //bは魔力、aは体力
  rep(i, H+a) {
    DP[i] = min(DP[max(i-a, 0)]+b, DP[i]);
  }
}

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

  cin >> H >> N;
  rep(i, N) {
    cin >> A[i] >> B[i];
    C[i] = P(B[i], A[i]);
    max_tai = max(max_tai, A[i]);
  }
  sort(C, C+N);
  rep(j, H+max_tai) DP[j+1] = INF;
  rep(i, N) calc(i);
  int ans = INF;
  rep(i, max_tai) {
    ans = min(ans, DP[H+i]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S;
    cin >> S;

    for(char& c : S)
        if (c == ',')
            c = ' ';
    cout << S << endl;
    return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main()
{
    double n;
 
    while (cin >> n, n >= 0) {
	string ans, tmp;
	int integer = n;
 
	n -= integer;
 
	while (integer) {
	    tmp += (integer % 2) + '0';
	    integer /= 2;
	}
 
	int len = (int)tmp.size();
	for (int i = len; i < 8; i++) {
	    tmp += "0";
	} 
 
	reverse(tmp.begin(), tmp.end());
	ans += tmp + ".";
 
	tmp = "";
 
	for (int i = 0; i < 4; i++) {
	    double b = pow(2.0, -(i+1));
 
	    if (n == b) {  
		tmp += "1";
		n -= b;
		break;
	    }
 
	    if ((int)(n / b) == 0) {
		tmp += "0";
	    } else {
		tmp += "1";
		n -= b;
	    }
	}
 
	len = (int)tmp.size();
	for (int i = len; i < 4; i++) {
	    tmp += "0";
	}  
 
	if (!n) cout << ans + tmp << endl;
	else cout << "NA" << endl;
    }
    return 0;
}

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

using namespace std;

#define int long long

const int mod = 1e9 + 7;

main()
{
	int n;
	cin >> n;
    
	vector <int> v(n);
	
	for(auto& i : v)
		cin >> i;
	
	if(v[0] != 0)
	{
		cout << 0;
		return 0;
	}
	
    int col[3] = {1, 0, 0};
	int res = 1;
	
    for(int i = 1; i < n; i++)
	{
        int k = v[i];
        int c = 0;
 
        for(int j = 0; j < 3; j++)
		{
            if(k == col[j])
			{
               c++;
            }
        }
 
        res = (res * c) % mod;
		
        for(int j = 0; j < 3; j++)
		{
            if(k == col[j])
			{
                col[j]++;
                break;
            }
        }
    }
 
    res = res * 3;
    res %= mod;
 
 
    cout << res;
}

Measured memory_bytes: 1024
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A = cin.getIntArray(N);
    const gcd = (a, b) => b ? gcd(b, a % b) : a;
    let L = new Array(N + 1); L[0] = 0;
    let R = new Array(N + 1); R[N] = 0;
    for (let n = 0; n < N; n++) {
        L[n + 1] = gcd(L[n], A[n]);
    }
    for (let n = N - 1; n >= 0; n--) {
        R[n] = gcd(R[n + 1], A[n]);
    }
    let M = new Array(N);
    for (let n = 0; n < N; n++) {
        M[n] = gcd(L[n], R[n + 1]);
    }
    console.log(Math.max(...M));
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 49076
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($($args),*), ($($args),*));
    };
}

fn ok(a: i32, b: i32, c: i32) -> bool {
    if a == 0 && b == 0 {
        true
    }
    else if b > 0 {
        ok(a + 1, 0, c)
    }
    else if c >= a - 1 {
        ok(0, b, c - a + 1)
    } else {
        false
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut a = 0;
    let mut b = 0;
    let mut c = 0;
    for _ in 0..n {
        let x: i32 = sc.cin();
        if x % 4 == 0 {
            c += 1;
        } else if x % 2 == 0 {
            b += 1;
        } else {
            a += 1;
        }
    }
    println!("{}", if ok(a, b, c) { "Yes" } else { "No" });
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


Measured memory_bytes: 10492
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void Main()
{
    map<char,char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['C'] = 'G';
    m['G'] = 'C';

    char c;cin>>c;
    cout<<m[c]<<endl;

    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}
int A[N];
int cnt[3] = {};

bool check(){

  //cout<<cnt[0]<<" "<<cnt[1]<<" "<<cnt[2]<<endl;

  cnt[1] %= 2;
  cnt[0] += cnt[1];
  return cnt[2] >= cnt[0]-1;
}

signed main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];

  for(int i=0;i<n;i++){
    int a=A[i],c = 0;
    while(a%2 == 0) a/=2, c++;
    cnt[min(c,2LL)]++;
  }

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

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
typedef long long int ll;

int main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
 
    int n;
    double k;
    cin >> n >> k;
 
    double ans = 0;
    for(int i = 1; i <= n; i++){
        double tmp = 1 / (double)n;
        double now = i;
        int cnt = 1;
        double m = 1;
        while(now < k){
            now *= 2;
            m *= 2;
            cnt++;
        }
        tmp *= 1 / m;
        ans += tmp;
    }
 

    cout <<fixed << setprecision(12)<< ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

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

// lcm(a.b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[]){
	int N[10],temp;
	for (int i = 0; i < 10; ++i)	N[i] = 0;
	for (int i = 0; i < 4; ++i){
		scanf("%d",&temp);
		++N[temp];
	}
	if(N[1] == 1 && N[9] == 1 && N[7] == 1 && N[4] == 1)	puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>


int main(void)
	{

		int i, j, tmp,kosuu,sum=0;

		/* 数値を格納する配列 */
		int number[1000];

		/* 数値の総数を入力 */
		int total;
		scanf("%d", &total);
		scanf("%d", &kosuu);
		/* 配列に格納する数値を入力 */
		for (i = 0; i<total; ++i)
			scanf("%d", &number[i]);

		/* 数値を昇順にソート */
		for (i = 0; i<total; ++i) {
			for (j = i + 1; j<total; ++j) {
				if (number[i] > number[j]) {
					tmp = number[i];
					number[i] = number[j];
					number[j] = tmp;
				}
			}
		}
		for (i = 0; i < kosuu; i++)
		{
			sum = number[i] + sum;
		}
		printf("%d", sum);
	return 0;
}

Measured memory_bytes: 1740
#include <iostream>

using namespace std;

int main()
{
    int n, mmax = -10, x;
    long long sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> x;
        if(x > mmax)
            mmax = x;
        else {
            sum += mmax - x;
        }
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int MAX_XY = 210;
const int D = 7;
const int INF = 1e9;

int sx, sy, gx, gy, lx, ly, N;
int mx[] = {0, 1, 1, 0, -1, -1, 0};
int my0[] = {1, 0, -1, -1, -1, 0, 0};
int my1[] = {1, 1, 0, -1, 0, 1, 0};

class C{
  public:
    int x, y, t, cost;
    C(){}
    C(int xx, int yy, int tt, int cc) { x = xx; y = yy; t = tt; cost = cc; }
    bool operator > (const C &c) const { return cost > c.cost; }
};

int solve(map<P, bool> &M){
  priority_queue<C, vector<C>, greater<C> > open;
  open.push(C(sx, sy, 0, 0));
  int closed[MAX_XY][MAX_XY][D];
  REP(i, MAX_XY) REP(j, MAX_XY) REP(k, D) closed[i][j][k] = INF;
  while(!open.empty()){
    C c = open.top(); open.pop();
    int x = c.x, y = c.y, t = c.t, cost = c.cost;
    //cout <<"x = " <<x - 100 <<", y = " <<y - 100 <<", t = " <<t <<", cost = " <<cost <<endl;
    if(x == gx && y == gy) return cost;
    if(closed[x][y][t % 6] <= cost) continue;
    closed[x][y][t % 6] = cost;
    REP(i, D){
      int ny = y + (x % 2 ? my1[i] : my0[i]);
      int nx = x + mx[i], nc = cost + (abs((x - 100) * (y - 100) * t) % 6 == i ? 0 : 1);
      if(abs(nx - 100) > lx || abs(ny - 100) > ly || M.find(P(nx, ny)) != M.end()) continue;
      //cout <<"  -> " <<nx - 100 <<", " <<ny - 100 <<", " <<nc <<" ( " <<i <<" ) " <<endl;
      open.push(C(nx, ny, t + 1, nc));
    }
  }
  return -1;
}

int main() {
  cin >>sx >>sy >>gx >>gy;
  sx += 100; sy += 100; gx += 100; gy += 100;
  cin >>N;
  map<P, bool> M;
  REP(i, N){
    int x, y; cin >>x >>y;
    M[P(x + 100, y + 100)] = 1;
  }
  cin >>lx >>ly;
  cout <<solve(M) <<endl;
  return 0;
}

Measured memory_bytes: 3312
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
enu=max(a)

k=(enu)/2
sa=10000000000000000000000000000

for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=k-a[i]
        aru=a[i]

print(enu,aru)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,s[1000],t[1000],S,T,ans=1,mod=1e9+7;
int main(void){
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>s[i];
  for(int i=0;i<m;i++)cin>>t[i];
  S=n,T=m;
  sort(s,s+n),sort(t,t+m);
  for(int i=n*m;i>0;i--){
    if(s[S-1]==i&&t[T-1]==i&&S*T)S--,T--;
    else if(s[S-1]==i&&S){ans*=m-T;S--;}
    else if(t[T-1]==i&&T){ans*=n-S;T--;}
    else ans*=(n-S)*(m-T)-(n*m-i);
    ans%=mod;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>

int answer=0;
char str[200];

int main()
{
	while(scanf("%s",str)!=EOF)
	{
		int len;
		for(int i=0;i<200;i++)
		{
			if(str[i]=='\0')
			{
				len=i-1;
				break;
			}
		}
		bool b=true;
		for(int i=0;i<len;i++)
		{
			if(str[i]!=str[len-i])b=false;
		}
		if(b==true)answer++;
	}
	printf("%d\n",answer);
}

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


int main(){
int n;
cin>>n;
    vector<int> p(n);
    vector<int> q(n);
    int countp=0;
    int countq=0;
    
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    while(prev_permutation(p.begin(),p.end())){
countp++;
    }
    while(prev_permutation(q.begin(),q.end())){
countq++;
    }
    cout<<abs(countp-countq)<<endl;
    
    return 0;

}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int x, i;
    cin >> x;
    bool ok = false;
    while(!ok){
        ok = true;
        for(i=2; i<x/2+1;i++){
            if(x % i == 0) ok = false;
        }
        if(!ok)x++;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
												//end  number
void sortnum(vector<tuple<string, int, int>> &data, int x, int y) {
  vector<pair<int, int>> pii(y+1);
  
  for (int i = 0; i < y+1; i++) {
    pii.at(i).first = get<1>(data.at(x-i));
    pii.at(i).second = get<2>(data.at(x-i));
  }
  
  sort(pii.begin(), pii.end());
  
  for (int i = 0; i < y+1; i++) {
    get<1>(data.at(x-i)) = pii.at(i).first;
    get<2>(data.at(x-i)) = pii.at(i).second;
  }
  return;
}

int main() {
  int N;
  cin >> N;
  
  using tsii = tuple<string, int, int>;
  
  vector<tsii> data(N);
  for (int i = 0; i < N; i++) {
    int a;
    string st;
    cin >> st >> a;
    data.at(i) = make_tuple(st, a, i+1);
  }
  
  sort(data.begin(), data.end());
  
  int y = 0;
  for (int i = 0; i < N-1; i++) {
    if (get<0>(data.at(i)) == get<0>(data.at(i+1))) {
      y++;
    }
    else if (y != 0) {
      sortnum(data, i, y);
      y = 0;
    }
    if (y != 0 && i == N - 2) sortnum(data, i+1, y);
  }
  
  for (int i = 0; i < N; i++) {
    cout << get<2>(data.at(i)) << endl;
  }
}

Measured memory_bytes: 256
n = gets.chomp.to_i
h = Array.new(10**5,0)
sum = 0

gets.chomp.split.each do |num|
  num = num.to_i
  h[num-1] += 1
  sum += num
end

q = gets.chomp.to_i

q.times do
  b,c = gets.chomp.split.map(&:to_i)
  b -= 1
  c -= 1
  sum += (c-b)*h[b]
  puts sum 
  h[c] += h[b]
  h[b] = 0
end

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

int main(void)
{
    int N;
    cin >> N;
    vector<int> x(N), y(N);

    vector<int> indices(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i];
        indices[i] = i;
    }
    double sum = 0;
    int totalCases = 0;
    do{
        for (int i = 1; i < N; i++)
        {
            int from = indices[i-1];
            int to = indices[i];
            int sqrDist = (x[to] - x[from])*(x[to] - x[from]) + (y[to]- y[from])*(y[to] - y[from]);
            sum += sqrt(sqrDist);
        }
        totalCases++;
    } while(next_permutation(indices.begin(), indices.end()));
    double ans = sum / totalCases;
    cout << fixed << setprecision(8) << ans << endl;
    return 0;
}


Measured memory_bytes: 3748
using System;

namespace ABC051B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var k = int.Parse(input[0]);
            var s = int.Parse(input[1]);

            var answer = 0;
            for (var x = 0; x <= k; x++)
            {
                for (var y = 0; y <= k; y++)
                {
                    var z = s - x - y;
                    if (z >= 0 && z <= k)
                    {
                        answer++;
                    }
                }
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27520
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order() - 0 indexing
// order_of_key() - number of elements strictly smaller
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
//---------------------------------------GL HF------------------------------------------------------
// -------------------------------------ManavJ07----------------------------------------------------
ll seive[10000005];
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        for(ll i=0;i<10000005;i++){
            seive[i]=1;
        }
        for(ll i=2;i<10000005;i++){
            if(seive[i]>1)
                continue;
            for(ll j=i*2;j<=10000005;j+=i){
                ll copy=j;
                ll x=0;
                while(copy%i==0){
                    copy/=i;
                    x++;
                }
                seive[j]*=(x+1);
            }
        }
        ll N,ans=1;
        cin>>N;
        for(ll i=2;i<=N;i++){
            if(seive[i]==1)
                seive[i]++;
            ans+=seive[i]*i;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 81776
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  cin >> N;

  string S1,S2;
  cin >> S1 >> S2;

  int now = 0;
  long long ans;
  char con;
  if(S1.at(0) == S2.at(0)) {
    con = 'l';
    ans = 3;
    now++;
  }else {
    con = 'c';
    ans = 6;
    now += 2;
  }

  for(int i = now;i < N;i++) {
    if(con == 'l') {
      ans *= 2;
      if(S1.at(i) != S2.at(i)) {
        con = 'c';
        i++;
      }
    }else {
      if(S1.at(i) == S2.at(i)) con = 'l';
      else {
        ans *= 3;
        i++;
      }
    }
    ans %= MOD;
  }

  cout << ans << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int r, c;
char grid[105][105];
int dp[105][105];
int main(){
	scanf("%d%d", &r, &c);
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			scanf(" %c", &grid[i][j]);
		}
	}
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			if (i == 0 && j == 0){
				dp[i][j] = (grid[i][j] == '#');
				continue;
			}
			if (i == 0){
				dp[i][j] = dp[i][j - 1] + (grid[i][j - 1] == '.' && grid[i][j] == '#');
				continue;
			}
			if (j == 0){
				dp[i][j] = dp[i - 1][j] + (grid[i - 1][j] == '.' && grid[i][j] == '#');
				continue;				
			}
			dp[i][j] = min(dp[i - 1][j] + (grid[i - 1][j] == '.' && grid[i][j] == '#'), dp[i][j - 1] + (grid[i][j - 1] == '.' && grid[i][j] == '#'));
		}
	}
	printf("%d\n", dp[r - 1][c - 1]);
	
}

Measured memory_bytes: 256
import math
import itertools

N, D = list(map(int, input().split()))

coordinate = []
for i in range(N):
  coordinate.append(list(map(int, input().split())))
  
cnt = 0
c_list = list(itertools.combinations(coordinate, 2))

for i in range(len(c_list)):
  combined = [(x - y)**2 for (x, y) in zip(c_list[i][0], c_list[i][1])]
  combined = math.sqrt(sum(combined))
  if combined.is_integer():
    cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int f[1111];
int g[1111][5005];
bool la[1111][5005];
short to[1111][5005];
int fa[1111];
int x[1111];
int w[1111],co[1111];
struct edge
{
	int to;
	int next;
}e[2222];
int pe=1111;
void insert(int a,int to)
{
	e[pe]=(edge){to,e[a].next};
	e[a].next=pe++;
}
int v[1111];
int siz[1111][2];
int main()
{
	int n=io::F();
	for(register int i=2;i<=n;++i)fa[i]=io::F(),insert(fa[i],i);
	for(register int i=1;i<=n;++i)x[i]=io::F();
	memset(g[0],63,sizeof(g[0]));
	for(register int i=n;i;--i)
	{
		g[0][0]=0;
		memset(g[1],63,sizeof(g[1]));
		int k=1;
		for(register int p=e[i].next;p;p=e[p].next,k++,memset(g[k],63,sizeof(g[k])))
			for(register int j=0;j<=x[i];++j)
			{
				if(j>=x[e[p].to])if(cmin(g[k][j],g[k-1][j-x[e[p].to]]+f[e[p].to]))la[k][j]=0,to[k][j]=j-x[e[p].to];
				if(j>=f[e[p].to])if(cmin(g[k][j],g[k-1][j-f[e[p].to]]+x[e[p].to]))la[k][j]=1,to[k][j]=j-f[e[p].to];
			}
		f[i]=0x3f3f3f3f;
		for(register int j=0;j<=x[i];++j)if(cmin(f[i],g[k-1][j]))w[i]=x[i]-j;
		for(register int now=x[i]-w[i],s=k-1;s;now=to[s][now],--s)v[s]=la[s][now];
		for(register int p=e[i].next,s=1;p;p=e[p].next,++s)co[e[p].to]=v[s];
		if(f[i]==0x3f3f3f3f){puts("IMPOSSIBLE");return 0;}
	}
	for(register int i=2;i<=n;++i)co[i]^=co[fa[i]];
	//for(register int i=1;i<=n;++i)printf("%d %d\n",co[i],w[i]);
	for(register int i=n;i;--i)
	{
		siz[i][co[i]]+=w[i];
		if(siz[i][co[i]]!=x[i]){puts("IMPOSSIBLE");return 0;}
		siz[fa[i]][0]+=siz[i][0];
		siz[fa[i]][1]+=siz[i][1];
	}
	puts("POSSIBLE");
	return 0;
}



Measured memory_bytes: 35840
#include<bits/stdc++.h> 
using namespace std; 
  
int main()
{
     int a,b;
    cin>>a>>b;
    int flag=0;
    
    for(int i=1;i<2000;i++)
    {
        if((i*1)/10 ==b && (i*8)/100 ==a)
        {
            cout<<i<<endl;
            flag=1;
            break;
        }
    }
    
    
    if(flag==0)
    {
        cout<<-1<<endl;
    }
    
    
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log, sqrt
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

a, b, c = LI()
if c - a - b <= 0:
    print('No')
else:
    if (c - a - b) ** 2 > 4 * a * b:
        print('Yes')
    else:
        print('No')





Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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() {
    ll n;
    cin >> n;
    vector<ll> v(3,0);
    rep(i,0,n){
        ll in;
        cin >> in;
        if(in%4 == 0)v[2]++;
        else if(in%2 == 0)v[1]++;
        else v[0]++;
    }
    if(!v[1]){
       if(v[0] <= v[2]+1)cout << "Yes\n";
       else cout << "No\n"; 
    }else if(v[0] <= v[2])cout << "Yes\n";
    else cout << "No\n";
    
    return 0;
}

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

// #define ANS  //for answer
#define CMP  //for compe
#ifdef CMP
using namespace std;
#else
#endif

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x, (x)
#define ncv(x) #x, ":", (x)
#define ncvc(x) #x, ":", (x), ","
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>
void pPRINT(std::ostream& ost, const T t, const U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T>
void PRINT(const T... t) { pPRINT(std::cout, t...); }
template <class... T>
void PRINTl(const T... t) {
  pPRINT(std::cout, t...);
  std::cout << "\n";
}
template <class T>
void PRINTa(const T* const t, const ll size) {
  REP(i, size)
  PRINT(t[i]);
  PRINTl();
}
template <class T>
void PRINTal(const T* const t, const ll size) {
  REP(i, size)
  PRINTl(i, ":", t[i]);
}
#ifndef DBG
#define DEBUG(...)
void init() {}
#else
#define DEBUG(...)                                                     \
  {                                                                    \
    PRINT("##DEBUG##", "file :", __FILE__, ", line :", __LINE__, "["); \
    PRINT(__VA_ARGS__);                                                \
    PRINTl("]");                                                       \
  }
void init() {
  DEBUG("INIT");
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

int main(int argc, char* argv[]) {
  DEBUG("MAIN");
  init();
  solve();

  return 0;
}

void solve() {
  DEBUG("SOLVE START");

  ll a, b, x;
  cin >> a >> b >> x;

  //assume h<b
  //a*a*h*0.5+a*a*(b-h) = x
  //b * 2 - x/(a*a) * 2 = h
  //
  //assume h=b
  //a*b*c = x
  //c = x/(a*b)

  double c, h;
  c = (2 * x < b * a * a) ? 2 * x / ((double)a * b) : a;
  h = (2 * x < b * a * a) ? b : 2 * (b - x / (double(a * a)));

  DEBUG(c, h);
  // PRINT(atan(h / c) * 180 / M_PI);
  cout << setprecision(10) << atan(h / c) * 180 / M_PI;

  // PRINT(atan((2 * x < b * a * a ? a * b * b / (double)x : 2 * (b - x / (double)(a * a)) / (double)a)) * 180 / M_PI);

  // double ans = (h <= c ? atan(h / c) * 180 / M_PI : (90 - atan(c / h) * 180 / M_PI));
  // PRINT(ans);
  // DEBUG(tan(ans * M_PI / 180.0) * c);

  return;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define clr(x) memset(x, 0, sizeof(x))
#define all(a) a.begin(),a.end()
#define forn(i, a,b) for(int i = int(a); i < int(b); ++i)
#define forn_r(i, b, a) for(int i = int(b); i > int(a); i--)
#define trav(a,x) for (auto& a : x)
#define printArray(array, length) for(int i = 0; i < length; i++) cout<< array[i] << (i == length - 1 ? '\n' : ' '); 
#define print(x) cout << x << '\n'
#define print2(x, y) cout << x << ' ' << y << '\n'
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t =1;
    //cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	int count=0;
    	ll rem = 7; 
  		if(n==1 || n==7) {print(1);return 0;}
     	if(n%2==0 || n%5==0){print(-1); return 0 ;}
     	
    	while (rem != 0) { 
  
        	rem = (rem * 10 + 7) % n; 
        	count++; 
       }	
       print(count+1);
       	 
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    string a, b;
    cin >> a >> b;
    int n = a.size();
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += a[i] != b[i];
    cout << ans << endl;
}

Measured memory_bytes: 3784
class dice:
    def __init__(self,label):
        self.spots = label

    def roll(self,way):
        if way == "N":
            self.spots = [self.spots[1],self.spots[5],self.spots[2],self.spots[3],self.spots[0],self.spots[4]]
        if way == "E":
            self.spots = [self.spots[3],self.spots[1],self.spots[0],self.spots[5],self.spots[4],self.spots[2]]
        if way == "W":
            self.spots = [self.spots[2],self.spots[1],self.spots[5],self.spots[0],self.spots[4],self.spots[3]]
        if way == "S":
            self.spots = [self.spots[4],self.spots[0],self.spots[2],self.spots[3],self.spots[5],self.spots[1]]
    def output(self):
        return self.spots


dice_1 = list(map(int,input().split()))
label = list(map(int,input().split()))
dice_2 = []

rotation = dice(label)
for i in range(3):
    dice_2.append(rotation.output())
    for j in range(3):
        rotation.roll("E")
        dice_2.append(rotation.output())
    rotation.roll("N")

rotation.roll("N")
rotation.roll("N")

for i in range(3):
    dice_2.append(rotation.output())
    for j in range(3):
        rotation.roll("W")
        dice_2.append(rotation.output())
    rotation.roll("N")

if dice_1 in dice_2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7656
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

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

const int MOD = 1e9 + 7;
const int maxn = 123456;
const double EPS = 1e-8;

bool vis[maxn];
class CUnification {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s;
		in >> s;
		memset(vis, 0, sizeof(vis));
		int n  = s.size();
		for(auto it = s.begin(); it != s.end() && s.size() > 1;){
			if(it != s.end()-1 && *it != *(it+1)){
				cerr << *it << endl;
				s.erase(it);
				cerr << *it << endl;
				s.erase(it);
				if(it != s.begin())--it;
			}
			else ++it;
		}
		out << n - s.size()<< endl;
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CUnification solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 592
/*
Hanit Banga
Problem: 
*/

#include <iostream>
#include <vector>
#include <set>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 505, N2 = N*N;

int x[N], a[N2] = {0}, rev[N2] = {0}, used[N2] = {0};
vector <int> store, ans, order;

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

	for (int i = 1; i <= n; ++i)
	{
		cin >> x[i];
		rev[x[i]] = i;
	}

	int slots = 0;

	for (int i = 1; i <= n*n; ++i)
	{
		if (rev[i])
		{
			int elem = rev[i];
			order.pb(elem);

			if (slots < elem-1)
			{
				cout << "No";
				return 0;
			}

			a[i] = elem;
			slots -= elem-1;
			
			for (int j = 0; j < elem-1; ++j)
				store.pb(elem);
		}

		else
			++slots;
	}

	for (int i = 0; i < n; ++i)
		for (int j = order[i]+1; j <= n; ++j)
			store.pb(order[i]);

	// cout << "Yes\n";
	auto j = store.begin();

	for (int i = 1; i <= n*n; ++i)
	{
		if (a[i])
			ans.pb(a[i]);

		else
		{
			ans.pb(*j);
			++j;
		}
	}

	for (int i = 1; i <= n*n; ++i)
	{
		if (rev[i])
		{
			if (used[rev[i]] != rev[i]-1)
			{
				cout << "No";
				return 0;
			}
		}

		used[ans[i-1]]++;
	}

	cout << "Yes\n";

	for (auto i : ans)
		cout << i << ' ';
}

Measured memory_bytes: 4728
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=50005;
int a[100005],n;
int main()
{
    scanf("%d",&n);
    int mx=0;
    int mn=0x3f3f3f3f;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
    }
    if(mx-1>mn)
    {
        printf("No\n");
        return 0;
    }
    if(mx==mn)
    {
        if(mn==n-1)
        {
            printf("Yes\n");
            return 0;
        }
        if(2*mn<=n)
        {
            printf("Yes\n");
            return 0;
        }
        else
        {
            printf("No\n");
            return 0;
        }
    }
    else
    {
        int ant=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]==mn)
                ant++;
        }
        if(mn<ant)
        {
            printf("No\n");
            return 0;
        }
        if(n-ant<2*(mx-ant))
        {
            printf("No\n");
            return 0;
        }
        else
        {
            printf("Yes\n");
            return 0;
        }
    }
}


Measured memory_bytes: 640
input()
A=list(map(int,input().split()))
s=0
for a in A:
  if a < 0:
    s += 1
S=0
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)

Measured memory_bytes: 15020
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

const int MAX_N=100000;
int N;
ll a[MAX_N+1],b[MAX_N+1],c[MAX_N+1];
ll dp[3][MAX_N+2];

void solve(){
    dp[0][1]=a[0];
    dp[1][1]=b[0];
    dp[2][1]=c[0];
    for(int i=2;i<=N;i++){
        for(int j=0;j<3;j++){
            if(j==0) dp[j][i]=max(dp[1][i-1]+a[i-1],dp[2][i-1]+a[i-1]);
            if(j==1) dp[j][i]=max(dp[0][i-1]+b[i-1],dp[2][i-1]+b[i-1]);
            if(j==2) dp[j][i]=max(dp[0][i-1]+c[i-1],dp[1][i-1]+c[i-1]);
        }
    }
    cout<<max3(dp[0][N],dp[1][N],dp[2][N])<<endl;
}

int main(){
    cin>>N;
    rep(i,N) cin>>a[i]>>b[i]>>c[i];
    solve();
}

Measured memory_bytes: 4992
import java.util.*;

import static java.lang.System.*;

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

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

        int[][] ans = new int[H][W];
        int aIndex = 1;
        for (int h = 0; h < H; h++) {
            if (h % 2 == 0) {
                int w = 0;

                while (w < W) {
                    int tmpW = a[aIndex];

                    boolean next = true;
                    if (w + tmpW > W) {
                        tmpW = W - w;
                        a[aIndex] -= tmpW;
                        next = false;
                    }

                    for (int j = w; j < w + tmpW; j++) {
                        ans[h][j] = aIndex;
                    }

                    w += tmpW;
                    if (next) {
                        aIndex++;
                    }
                }
            } else {
                int w = W;

                while (w > 0) {
                    int tmpW = a[aIndex];

                    boolean next = true;
                    if (w - tmpW < 0) {
                        tmpW = w;
                        a[aIndex] -= tmpW;
                        next = false;
                    }

                    for (int j = w - 1; j >= w - tmpW; j--) {
                        ans[h][j] = aIndex;
                    }

                    w -= tmpW;
                    if (next) {
                        aIndex++;
                    }
                }
            }
        }

        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                out.print(ans[h][w]);
                if (w != W - 1) {
                    out.print(" ");
                }
            }
            out.println();
        }
    }
}

Measured memory_bytes: 31972
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


int f(int a,int b)
{
	return 60*a+b;
}
void solve(std::vector<long long> H, std::vector<long long> M, long long K){
	int d=f(H[1],M[1])-f(H[0],M[0])-K;
	cout << d << endl;
	

}

int main(){
    std::vector<long long> H(2);
    std::vector<long long> M(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&H[i]);
        scanf("%lld",&M[i]);
    }
    long long K;
    scanf("%lld",&K);
    solve(std::move(H), std::move(M), K);
    return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s; cin >> s;
  int year = stoi(s.substr(0,4)), month = stoi(s.substr(5,2)), day = stoi(s.substr(8,2));
  if(year < 2019) cout << "Heisei" << endl;
  else if(month <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;

  return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    double counter = 0;
    for(int i = 0;i <= a;i++){
      int b = i % 2;
      if(b == 1){
        counter++;
      }
    }
    System.out.println(counter/(double)a);
  }
}

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

int x[26];

int main(){
  string s; cin >> s;
  for (int i = 0; i < s.size(); i++) {
    x[s[i]-'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (x[i] % 2 == 1) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rep1(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define repU(i,s,t) for(auto (i) = (s); (i) <= (t); ++(i))
#define repD(i,t,s) for(auto (i) = (t); (i) >= (s); --(i))
#define all(v)  begin(v),end(v)
#define clr(v) fill(all(v),0)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1)/(d) + 1)
#define parity(a,b) ((a)^(b) & 1LL ^ 1LL)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = -1 + (1 << 30);
const ll INF_64 = -1 + (1LL << 62);
const int MOD = 1e9 + 7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,a; cin>>n;
	ll s[100001];
	s[0] = 0;
	rep(i,n){
		cin>>a;
		s[i + 1] = s[i] + a;
	}
	ll ans1 = 0, ans2 = 0,cur1 = 0,cur2 = 0,r1 = 1,r2 = -1,t1,t2;
	rep1(i,n){
		t1 = s[i] + cur1;
		if(r1 * t1 <= 0){
			ans1 += abs(r1 - t1);
			cur1 += r1 - t1;
		}
		r1 = -r1;
		t2 = s[i] + cur2;
		if(r2 * t2 <= 0){
			ans2 += abs(r2 - t2);
			cur2 += r2 - t2;
		}
		r2 = -r2;
	}
	cout<<min(ans1,ans2)<<endl;
	
	return 0;
}





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

typedef long double ld;
#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vpi vector< pair<int,int> >
#define F first
#define S second 
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())

ld pi= 3.14159265358979;
//const int mod=998244353; 
const int mod = 1e9+7;
const int maxn=2e5+5;

void solve()
{   
	ld a, b, h ,m ; cin>>a>>b>>h>>m;
	h+=m/60;
	m = (m/60)*360; 
	h = (h/12)*360;
	ld ang = abs(h-m);
	ang = min(ang, 360-ang);
	ang = ang*(pi / 180);
	ld ans = b*b + a*a - 2*a*b*cos(ang);
	ans = sqrt(ans);
	cout<<ans;
}

signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cout<<setprecision(20);
    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 4184
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long luca[100];
    luca[0]=2;
    luca[1]=1;
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        luca[i]=luca[i-1]+luca[i-2];
    }
    cout<<luca[n];
}

Measured memory_bytes: 256
#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;
typedef long long ll;




int main()
{
    
    int N;
    cin >> N;
    ll x;cin >> x;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        if(a[i]+a[i-1] <= x) continue;
        if(a[i-1] <= x){
            ans += a[i]+a[i-1]-x;
            a[i] = x - a[i-1];
        }else{
            ans += a[i]+a[i-1]-x;
            a[i] = 0;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


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

#define ll long long int
#define ull unsigned long long int

#define INF 100000000000L

using namespace std;

int main(){
    int N;
    cin >> N;
    int count = 0;
    int max = 0;
    for(int i=0;i<N;i++){
        int H;
        cin >> H;
        if(max > H) continue;
        else{
            max = H;
            count++;
        }
    }
    cout << count << endl;
    return 0;

}

Measured memory_bytes: 256