akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    if(N == 3){
        cout << "2 5 63" << endl;
        return 0;
    }
    ll k = 1;
    ll l = 2;
    ll m = 1;
    vector<ll> ans;
    ans.push_back(2);
    ans.push_back(4);
    ans.push_back(3);
    ans.push_back(9);
    ll cnt = N - 4;
    if(cnt < 1){
        PR(ans,N);
        return 0;
    }
    while(cnt > 1){
        if(k*6+4 > 30000) break;
        ans.push_back(k*6+2);
        ans.push_back(k*6+4);
        cnt -= 2;
        k++;
    }
    while(cnt > 1){
        if(l*6+3+6 > 30000) break;
        ans.push_back(l*6+3);
        l++;
        ans.push_back(l*6+3);        
        cnt -= 2;
        l++;
    }
    while(cnt > 0){
        if(m*6 > 30000) break;
        ans.push_back(m*6);
        m++;
        cnt--;
    }
    PR(ans,N);
}

Measured memory_bytes: 3756
n = int(input())
p = []
a = []
q = 2
while len(a) < n:
  f = 0
  for x in p:
    if q%x == 0:
      f = 1
      break
  if f == 0:
    p += [q]
    if q%5 == 1:
      a += [str(q)]
  q += 1
print(" ".join(a))


Measured memory_bytes: 2940
n, m = gets.split.map(&:to_i)
ary1 = []
ary2 = []
n.times do
    ary1 << gets.split.map(&:to_i)
end
m.times do
    ary2 << gets.to_i
end

(0..n-1).each do |i|
    sum = 0
    (0..m-1).each do |j|
        sum += ary1[i][j] * ary2[j] if ary2[j]
    end
    puts sum
end


Measured memory_bytes: 6980
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	long long int N;
	cin >> N;
	vector<long long int> A(N), diff(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	if(N == 1){
		cout << "YES" << endl;
		return 0;
	}
	diff[0] = A[0] - A[N - 1];
	long long int rem = (diff[0] % N + N) % N;
	long long int cnt = diff[0];
	for(int i = 1; i < N; i++){
		diff[i] = A[i] - A[i - 1];
		if(rem != (diff[i] % N + N) % N){
			cout << "NO" << endl;
			return 0;
		}
		cnt = max(cnt, diff[i]);
	}
	for(int i = 0; i < N; i++){
		if(cnt != diff[i]){
			A[N - 1] -= (cnt - diff[i]) / N * (N - i);
		}
	}
	if(A[N - 1] >= 0 && A[N - 1] % (N * (N + 1) / 2) == 0){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
// 参考: https://atcoder.jp/contests/abc165/submissions/12633891
// mailさんありがとうございました。

package main

import (
	"fmt"
	"math"
)

func main() {
	var A, B, N int
	fmt.Scan(&A, &B, &N)

	var x int = int(math.Min(float64(B-1), float64(N)))
	fmt.Println(f(A, B, x))
}

// f は、まんま数学の関数
func f(A int, B int, x int) int {
	return (A * x / B) - A*(x/B)
}


Measured memory_bytes: 1756
/*
 *
 *
 */

#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

int main() {
  int n;
  while(cin >> n, n) {
    vpi trees(n);
    int w, h, s, t;

    cin >> w >> h;
    REP(i, n){
      cin >> trees[i].first >> trees[i].second;
      trees[i].first--;
      trees[i].second--;
    }
    cin >> s >> t;

    int res = 0;
    REP(y, h - t + 1){
      REP(x, w - s + 1){
        int cnt = 0;
        for(auto tree : trees) {
          if (x <= tree.first && tree.first < x + s)
            if (y <= tree.second && tree.second < y + t) {
              cnt++;
            }
        }
        res = max(res, cnt);
      }
    }
    cout << res << endl;
  }
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
typedef pair <int, int> P;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;




int main() {
	int n, k;
	cin >> n >> k;
	VI v(n);
	REP(i, n)cin >> v[i];
	sort(ALL(v));
	int res = INF;
	REP(i, n - k+1) {
		res = min(res, v[i + k-1] - v[i]);
	}
	cout << res << endl;
	return 0;

}


Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
set< pair<LL, pair<LL,LL> > > vis;
bool inloop;

bool iseven(const LL x)
{ return x % 2 == 0; }
bool isodd(const LL x)
{ return !iseven(x); }

int dfs(const LL A, const LL B, const LL C)
{
    if (isodd(A) || isodd(B) || isodd(C))
        return 0;
    LL x[] = { A,B,C };
    sort(x,x+3);
    pair< LL, pair<LL,LL> > k = make_pair(x[0],make_pair(x[1],x[2]));
    if (in_(k,vis)) {
        inloop = true; return 0;
    }
    vis.insert(k);
    const LL a = (B+C)/2;
    const LL b = (A+C)/2;
    const LL c = (A+B)/2;
    const int res = dfs(a,b,c);
    return res+1;
}

int main()
{
    /* #ifndef ONLINE_JUDGE */
    /*     freopen("foo", "rt", stdin); */
    /* #endif */
    LL A,B,C;
    while (cin >> A >> B >> C) {
        inloop = false; vis.clear();
        int ans = dfs(A,B,C);
        if (inloop)
            cout << -1 << endl;
        else
            cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define vi vector<int>
using namespace std;
int main()
{ 
    int h1,a1,h2,a2;
    cin>>h1>>a1>>h2>>a2;
    while( h1 > 0 && h2 >0)
    {
        h2-=a1;
        if(h2 <=0)
        {
            cout<<"Yes";
            break;
        }
        h1-=a2;
        if(h1 <= 0)
        {
            cout<<"No";
            break;
        }
    }
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}

int parent[100005];
int height[100005];
int   size[100005];

int find(int a){
	if(parent[a]==a){
		return a;
	}else{
		return parent[a] = find(parent[a]);
	}
}

ll unite(int a,int b){
	int pa = find(a);
	int pb = find(b);
	if(pa==pb){
		return 0;
	}else{
		if(height[pa]<height[pb]){
			int tmp = pa;
			pa=pb;
			pb=tmp;
		}
		//height[pa]>=height[pb]

		if(height[pa]==height[pb]){
			height[pa] += 1;
		}
		ll retval = (ll)size[pa] * (ll)size[pb];
		size[pa] += size[pb];
		parent[pb] = pa;
		return retval;

	}
}

int main(void){
	int n,m;
	int a[100005],b[100005];
	cin>>n>>m;
	ll ans[100005];
	rep(i,m){
		cin>>a[i]>>b[i];
	}
	rep(i,n){
		parent[i+1] = i+1;
		height[i+1]=1;
		size[i+1]=1;
	}
	ll sum = ((ll)n * (ll)(n-1))/2;
	ans[m-1] = sum;
	rep(i,m-1){
		int j = m-1-i;
		//cout<<find(a[j])<<" "<<find(b[j])<<endl;
		sum -= unite(a[j],b[j]);
		ans[j-1] = sum;
	}
	rep(i,m){
		cout<<ans[i]<<endl;
	}

 
	return 0;
}

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

int main(){
    int N,Ans=0;
    cin >> N;
    vector<int> C(N),V(N),A(N);

    for(int i = 0; i < N; i++){
        cin >> V.at(i);
    }
    for(int i = 0; i < N; i++){
        cin >> C.at(i);
    }
    for(int i = 0; i < N; i++){
        A.at(i) = V.at(i) - C.at(i);
    }
    
    sort(A.begin(),A.end(),greater<int>());
    for(int i= 0; i < N ; i++){
        if(A.at(i) > 0){
            Ans += A.at(i);
        }else{
            break;
        }
        
    }
    cout << Ans;
}

Measured memory_bytes: 256
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1001016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll i,j,k,x,a,b,c,ans=0;
    cin>>a>>b>>c>>x;

    x /= 50;
    for(i=0; i<=a; i++)
    {
        for(j=0; j<=b; j++)
        {
            for(k=0; k<=c; k++)
            {
                if(10*i + 2*j+ k == x)
                {
                    ans++;
                }
            }
        }
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 256
def calc_temp(t, h):
	return t - h * 0.006

n = int(input())
ta = input().split()
t = int(ta[0])
a = int(ta[1])

h = list(map(int,input().split()))

h_len = len(h)

best_abs = None
best_i = None

i = 1
i_abs = None

for h_item in h:

	temperature = calc_temp(t = t, h = h_item)
	i_abs = abs(temperature - a)



	if best_abs == None:
		best_abs = i_abs
		best_i = i

	if best_abs > i_abs:
		best_abs = i_abs
		best_i = i	

	i = i + 1	


print(best_i)

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int n;
    cin >> n;
    double ans = 0;

    rep(i, n) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") {
            ans += x;
        }
        else {
            ans += x * 380000;
        }
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 256
use std::cmp;

#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (s,) = input!(String);

    let mut count_1 = 0;
    for (i, c) in s.char_indices() {
        if i % 2 == 0 {
            if c == '0' {
                count_1 += 1;
            }
        } else {
            if c == '1' {
                count_1 += 1;
            }
        }
    }

    let mut count_2 = 0;
    for (i, c) in s.char_indices() {
        if i % 2 == 0 {
            if c == '1' {
                count_2 += 1;
            }
        } else {
            if c == '0' {
                count_2 += 1;
            }
        }
    }

    println!("{}", cmp::min(count_1, count_2));
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=1e10+7;
double power(double a,int b)
{
    double ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;

    int x;
    cin>>x;
    int cnt=1,curr=100;
    while(1)
    {
        double val=curr*1.01;
        curr=val;

        if(val>=x)
        {
            cout<<cnt<<endl;
            break;
        }
        cnt++;
    }
}

Measured memory_bytes: 3648
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    assert_eq!(!0usize, std::usize::MAX); //🙊
    assert!(0 == 0); //😇
    let a = io.read::<i64>();
    let b = io.read::<i64>();
    let c = io.read::<i64>();
    io.writeln(if 2 * b == a + c { "YES" } else { "NO" });
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;
 
class tree{
public:
    void putparent(int n);
    void putleft(int n);
    void putright(int n);
    int getparent();
    string gettype();
    int getleft();
    int getright();
    tree();
private:
    int parent;
    int left_child;
    int right;
};
 
typedef struct tree Tree;
 
tree::tree()
{
    parent = -1;
    left_child = -1;
    right = -1;
}
 
void tree::putparent(int n)
{
    parent = n;
    return;
}
 
void tree::putleft(int n)
{
    left_child = n;
    return;
}
 
void tree::putright(int n)
{
    right = n;
    return;
}
 
int tree::getparent()
{
    return parent;
}
 
string tree::gettype()
{
    if(getparent() == -1) return "root";
    else if(getleft() == -1) return "leaf";
    else return "internal node";
}
 
int tree::getleft()
{
    return left_child;
}
 
int tree::getright()
{
    return right;
}
 
int getdepth(Tree a[], int n)
{
    int ans = 0;
    if(a[n].getparent() != -1) return getdepth(a, a[n].getparent()) + 1;
    else return 0;
}
 
int main()
{
    int n;
    cin >> n;
    Tree t[100000];
    int v, d, c, l;
    for(int i = 0; i < n; i++){
        cin >> v >> d;
        for(int j = 0; j < d; j++){
            cin >> c;
            if(j == 0) t[v].putleft(c);
            else t[l].putright(c);
            l = c;
            t[c].putparent(v);
        }
    }
    for(int i = 0; i < n; i++){
        cout << "node " << i << ": ";
        cout << "parent = " << t[i].getparent() << ", ";
        cout << "depth = " << getdepth(t, i) << ", ";
        cout << t[i].gettype() << ", ";
        cout << "[";
        if(t[i].getleft() != -1){
            cout << t[i].getleft();
            l = t[i].getleft();
            while(t[l].getright() != -1){
                cout << ", ";
                cout << t[l].getright();
                l = t[l].getright();
            }
        }
        cout << "]" << endl;
    }
}

Measured memory_bytes: 2376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
int n = 100005;
vector<vector<int>> tree(n,vector<int>());
vector<int> dis_0(n);
vector<int> dis_n(n);

void dfs(int i,int before,int d,int par){
  if(par == 0) dis_0.at(i) = d;
  else dis_n.at(i) = d;
  
  for(int p:tree.at(i)){
    if(p == before) continue;
    dfs(p,i,d+1,par);
  }
}
 
int main() {
  cin >> n;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  
  dfs(0,-1,0,0);
  dfs(n-1,-1,0,n-1);
  
  int cnt_0 = 0;
  int cnt_n = 0;
  
  rep(i,n){
    if(dis_0.at(i) <= dis_n.at(i)) cnt_0 ++;
    else cnt_n ++;
  }
  
  if(cnt_0 > cnt_n) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
    
 
  return 0;
}




Measured memory_bytes: 12800
from collections import Counter
def check(n):
    d = Counter([input() for _ in range(n)])
    result = d.most_common()
    max_cnt = result[0][1]
    namelist = []
    for name, cnt in result:
        if max_cnt == cnt:
            namelist.append(name)
    for name in sorted(namelist):
        print(name)
    
n = int(input())
check(n)

Measured memory_bytes: 47636
n, m, x = map(int, input().split())
c, a = [0] * n, [0] * n
for i in range(n):
    c[i], *a[i] = map(int, input().split())
l = []
b = [[a[j][i] for j in range(n)] for i in range(m)]
nums = [("0"*n + bin(i)[2:])[-n:] for i in range(1, 2 ** n)]

for i in nums:
    if min(sum(k[j]*int(i[j]) for j in range(len(i))) for k in b) >= x:
        l.append(sum(c[j]*int(i[j]) for j in range(len(i))))
print(min(l) if l else -1)

Measured memory_bytes: 9332
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for(int i=0;i<(n);i++)
#define REP(i, n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX;
constexpr lint LINF = LLONG_MAX;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
void printArray(std::vector<int>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
int n, a[3][4010];
std::string s;
signed main() {
	std::cin >> n >> s;
	lint ans = 0;
	rep(i, n) {
		if (s[i] == 'R')a[0][i]++;
		else if (s[i] == 'G')a[1][i]++;
		else a[2][i]++;
	}
	for (int i = n - 2; i >= 0; i--) {
		rep(j, 3) {
			a[j][i] += a[j][i + 1];
		}
	}
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j])continue;
			if (s[i] != 'R' && s[j] != 'R') {
				ans += a[0][j + 1];
				if (2 * j - i < n) {
					if (s[2 * j - i] == 'R')ans--;
				}
			}
			else if (s[i] != 'G' && s[j] != 'G') {
				ans += a[1][j + 1];
				if (2 * j - i < n) {
					if (s[2 * j - i] == 'G')ans--;
				}
			}
			else {
				ans += a[2][j + 1];
				if (2 * j - i < n) {
					if (s[2 * j - i] == 'B')ans--;
				}
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
const int base = (int) 1e9+7;
const int maxn = (int) 1e5 + 5;
int n, m;
int a[maxn];
int main() {
	cin >> n >> m;
	if (n < m) swap(n, m);
	if (n - m > 1) {
		cout << 0 << endl;
		return 0;
	}
	a[0] = 1;
	for(int i = 1; i < maxn; ++i)
		a[i] = (1LL*a[i-1]*i) % base;
	if (n == m) {
		cout << (1LL*a[m]*a[n]*2) % base << endl;
		return 0;
	}
	cout << (1LL*a[m]*a[n])% base << endl;
	return 0;
}

Measured memory_bytes: 640
mod = 10 ** 9 + 7

N, K = map(int, input().split())

dp = [[[0 for _ in range(2610)] for _ in range(51)] for _ in range(51)]
dp[0][0][0] = 1

for i in range(N):
    for j in range(N):
        for k in range(K + 1):
            dp[i + 1][j + 1][k + 2 * j + 2] += dp[i][j][k]
            if j > 0:
                dp[i + 1][j][k + 2 * j] += dp[i][j][k] * j
                dp[i + 1][j][k + 2 * j] += dp[i][j][k] * j

            dp[i + 1][j][k + 2 * j] += dp[i][j][k]

            if j > 0:
                dp[i + 1][j - 1][k + 2 * j - 2] += dp[i][j][k] * j * j


print(dp[N][0][K] % mod)

Measured memory_bytes: 152712
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a%3==0||b%3==0||(a+b)%3==0)
		{
			System.out.println("Possible");
		}
		else {
			System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 21844
import Foundation

////print("Hello, World!")
//
//let input = readLine()!
////print(input)
//
//let nums = input.components(separatedBy: " ")
////print(nums)
//
//let a = Int(nums[0])!
//let b = Int(nums[1])!
//print("\(a * b)")


let input = readLine()!
let nums = Int(input)!

if nums < 10 {
    if nums == 2 || nums == 4 || nums == 5 || nums == 7 || nums == 9{
        print("hon")
    } else if nums == 0 || nums == 1 || nums == 6 || nums == 8 {
        print("pon")
    } else {
        print("bon")
    }
 
} else if nums < 100 {
    let numsString = String(nums)
    let place1String = numsString.dropFirst()
    let place1 = Int(place1String)!
    
    
    
    if place1 == 2 || place1 == 4 || place1 == 5 || place1 == 7 || place1 == 9 {
        print("hon")
    } else if place1 == 0 || place1 == 1 || place1 == 6 || place1 == 8 {
        print("pon")
    } else {
        print("bon")
    }
} else if nums < 1000 {
    let numsString = String(nums)
    let place1String = numsString.dropFirst(2)
    let place1 = Int(place1String)!
    
    if place1 == 2 || place1 == 4 || place1 == 5 || place1 == 7 || place1 == 9 {
        print("hon")
    } else if place1 == 0 || place1 == 1 || place1 == 6 || place1 == 8 {
        print("pon")
    } else {
        print("bon")
    }
}


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

///    ____ ____ ____ ____ ____
///   ||a |||t |||o |||d |||o ||
///   ||__|||__|||__|||__|||__||
///   |/__\|/__\|/__\|/__\|/__\|
///

using namespace std;

const int N_MAX = 302;
const int M_MAX = 302;

int n, m;

int a[N_MAX][M_MAX];

bool del[N_MAX];

int pos[N_MAX];

int cnt[M_MAX];

queue <int> q;

bool f (int mx)
{
    for(int i = 1; i <= m; i++)
    {
        del[i] = false;
        cnt[i] = 0;
    }
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; i++)
    {
        pos[i] = 1;
        if(++cnt[a[i][1]] == mx + 1)
            q.push(a[i][1]);
    }
    while(!q.empty())
    {
        int f = q.front();
        q.pop();
        del[f] = true;
        for(int i = 1; i <= n; i++)
            if(del[a[i][pos[i]]] == true)
            {
                while(pos[i] <= m && del[a[i][pos[i]]] == true)
                    pos[i]++;
                if(pos[i] == m + 1)
                    return false;
                if(++cnt[a[i][pos[i]]] == mx + 1)
                    q.push(a[i][pos[i]]);
            }
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> a[i][j];
    int l = 1, r = n;
    while(l < r)
    {
        int mid = ((l + r) >> 1);
        if(f(mid) == true)
            r = mid;
        else
            l = mid + 1;
    }
    cout << l << "\n";
    return 0;
}


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

const double INF = 1e8;
const double eps = 1e-8;

class Point {
public:
    double x, y;
    Point(double x, double y) : x(x), y(y) {};
};

class LineSeg {
public:
    bool vertical;
    double a, b; // y = a * x + b
    Point p1, p2;
    double min_x, max_x, min_y, max_y;
    LineSeg(Point p1, Point p2) : p1(p1), p2(p2) {
        if (p1.x == p2.x) {
            vertical = true;
            a = 0;
            b = 0;
        } else {
            vertical = false;
            a = (p2.y - p1.y) / (p2.x - p1.x);
            b = p1.y - a * p1.x;
        }
        min_x = min(p1.x, p2.x); max_x = max(p1.x, p2.x);
        min_y = min(p1.y, p2.y); max_y = max(p1.y, p2.y);
    }
};

double eq(double x, double y) {
    return abs(x - y) < eps;
}

bool isParallel(LineSeg &L1, LineSeg &L2) {
    if (L1.vertical && L2.vertical) return true;
    if (!L1.vertical && !L2.vertical && abs(L1.a - L2.a) < eps) return true;
    return false;
}

Point intersection(LineSeg L1, LineSeg L2) {
    if (isParallel(L1, L2)) {
        return Point(INF, INF);
    }
    double x, y;
    if (L1.vertical) {
        x = L1.min_x;
        y = L2.a * x + L2.b;
    } else if (L2.vertical) {
        x = L2.min_x;
        y = L1.a * x + L1.b;
    } else {
        x = (L2.b - L1.b) / (L1.a - L2.a);
        y = L1.a * x + L1.b;
    }
    if (x < L1.min_x || L1.max_x < x || y < L1.min_y || L1.max_y < y ||
        x < L2.min_x || L2.max_x < x || y < L2.min_y || L2.max_y < y) {
        return Point(INF, INF);
    }
    return Point(x, y);
}

double areaOfTriangle(Point A, Point B, Point C) {
    return abs((B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x)) / 2.0;
}

int main() {
    int x1, y1, x2, y2;
    while (cin >> x1 >> y1 >> x2 >> y2, (x1 || y1 || x2 || y2)) {

        vector<LineSeg> L;
        L.push_back( LineSeg(Point(x1,y1), Point(x2,y2)) );
        for (int i=1; i<3; ++i) {
            cin >> x1 >> y1 >> x2 >> y2;
            L.push_back( LineSeg(Point(x1,y1), Point(x2,y2)) );
        }

        bool kyo = false;
        vector<Point> P;
        for (int i=0; i<3 && !kyo; ++i) {
            for (int j=i+1; j<3 && !kyo; ++j) {
                Point p = intersection(L[i], L[j]);
                if (p.x == INF) {
                    kyo = true;
                } else {
                    P.push_back(p);
                }
            }
        }

        if (kyo) {
            cout << "kyo" << endl;
        } else {
            double area = areaOfTriangle(P[0], P[1], P[2]);
            if (area < eps) {
                cout << "kyo" << endl;
            } else if (1900000 <= area + eps) {
                cout << "dai-kichi" << endl;
            } else if (1000000 <= area + eps) {
                cout << "chu-kichi" << endl;
            } else if (100000 <= area + eps) {
                cout << "kichi" << endl;
            } else {
                cout << "syo-kichi" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1188
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    bool isReturn = false;
    int T,F;
    string C;
    string left = "";
    string right = "";
    for(int i=0;i<Q;i++){
        cin >> T;
        if(T == 1) isReturn = !isReturn;
        else{
            cin >> F >> C;
            if((isReturn == false && F == 1) || (isReturn != false && F == 2)) left = C + left;
            else right = right + C;
        }
    }
    S = left + S + right;
    if(isReturn == true){
        char s = ' ';
        for(int i=0;i<S.length()/2;i++){
            s = S[i];
            S[i] = S[S.length()-1-i];
            S[S.length()-1-i] = s;
        }
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 1464
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_A() {}
#else

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int N, A, B; cin >> N >> A >> B;

    int ans = min(A*N, B);
    cout << ans << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define ll long long int
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    

 	int n,k;
 	cin >> n >> k;
 	int h[n];
 	for (int i=0;i<n;i++)
 	cin >> h[i];

 	int dp[n];
 	dp[0]=0;
 	dp[1]=abs(h[1]-h[0]);

 	if (n>2)
 	{
 		//dp[2]=min(dp[1]+abs(h[2]-h[1]),abs(h[2]-h[0]));
 		for (int i=2;i<n;i++)
 			{
 				int min = 1000000000;
 				for (int j=1;j<=k;j++)
 				{
 					if (i-j>=0)
 					{
 					if (min > dp[i-j] + abs(h[i-j]-h[i]))
 						min = dp[i-j] + abs(h[i-j]-h[i]);
 					//printf("dp[i-j]=%d h[i-j]=%d h[i]=%d\n",dp[i-j],h[i-j],h[i]);
 					}
 					//printf("i=%d j=%d min=%d \n",i,j,min);
 				}
 				dp[i]=min;
 			}
 	}   
 /*	for (int i=0;i<n;i++)
 		printf("%d ",dp[i]);
 	cout << endl;*/
 	cout << dp[n-1] << endl;
	return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

/*vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/
// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, m, r;
string s;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>> k>> n;
	ll sum = 0;
	for(ll i=0;i<n;i++) cin >> x,sum += x;
	if( sum >= k) cout<<"Yes\n";
	else cout<<"No\n";
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3560
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;

vector<pair<LL,LL> >vp;

int main() 
{
    int n,a,b,c,d;
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&d); 
    int left=(n-2);
    int dif=a-b;
    for(int i=0;i<=n-1;i++)
    {
        LL dr=i*1ll*d;
        LL mr=i*1ll*c;
        int fr=n-1-i;
        LL nr=fr*1ll*c;
        LL mx=fr*1ll*d;
        vp.push_back(make_pair(dr-mx,dr-nr));
        vp.push_back(make_pair(dr+nr,dr+mx));
        vp.push_back(make_pair(nr-dr,nr-mr));
        vp.push_back(make_pair(nr+mr,nr+dr));
    }
    int flg=0;
    for(int i=0;i<vp.size();i++)
    {
        if(dif<=vp[i].second&&dif>=vp[i].first)
        {
            flg=1;
            break;
        }
    }
    if(flg==0)
    {
        printf("NO\n");
    }
    else
    {
        printf("YES\n");
    }
    return 0;
}

Measured memory_bytes: 35172
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    N = int(input())
    shop = []
    for i in range(N):
        s, p = [x for x in input().split()]
        shop.append([i,s,int(p)])
    
    shop.sort(key=lambda x:x[2])
    shop.reverse()
    shop.sort(key=lambda x:x[1])

    for i in shop:
        print(i[0]+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
//secreterror
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define rev(i, n) for(ll i=n-1;i>=0;i--)
#define forr(i, x, y) for(ll i=x;i<y;i++)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>

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


    vector<vector<ll>>arr(n,vector<ll>(3));
    rep(i,n) rep(j,3) cin>>arr[i][j];

    vector<vector<ll>>dp(n+1,vector<ll>(3,INT_MIN));

    for(int i=0;i<3;i++){
        dp[1][i]=arr[0][i];
    }

    for(int i=2;i<=n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(k!=j){
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+arr[i-1][j]);
                }
            }
        }
    }
    ll maxi=INT_MIN;
    for(int i=0;i<3;i++){
        maxi=max(maxi,dp[n][i]);

    }
    cout<<maxi<<endl;






}

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

using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h[i];

  vector<int> dp(100'000, 0);
  dp[0]=0;
  dp[1]=dp[0]+abs(h[1]-h[0]);

  for (int i = 2; i < N; i++) {
    dp[i]+=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

//            int[] map = new int[1 << 20];
//            HashSet<Integer> numbers = new HashSet<>();
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < N; i++) {
                Integer count = map.get(A[i]);
                map.put(A[i], 1 + (count == null ? 0 : count.intValue()));
//                map[A[i]]++;
//                numbers.add(A[i]);
            }

            ArrayList<Pair<Integer, Integer>> list = new ArrayList<>();
            for (Integer number : map.keySet()) {
                list.add(new Pair<Integer, Integer>(-map.get(number), number));
            }
            Collections.sort(list);

            int res = 0;
            while (list.size() > K) {
                res += -list.get(list.size() - 1).first.intValue();
                list.remove(list.size() - 1);
            }

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

class Pair<T extends Comparable<T>, S> implements Comparable<Pair<T, S>> {
    public T first;
    public S second;

    public Pair(T t, S s) {
        this.first = t;
        this.second = s;
    }

    private int hash = 0;

    @Override
    public int hashCode() {
        if (hash == 0) {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((first == null) ? 0 : first.hashCode());
            result = prime * result + ((second == null) ? 0 : second.hashCode());
            hash = result;
        }
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pair<T, S> other = (Pair<T, S>) obj;
        if (first == null) {
            if (other.first != null)
                return false;
        } else if (!first.equals(other.first))
            return false;
        if (second == null) {
            if (other.second != null)
                return false;
        } else if (!second.equals(other.second))
            return false;
        return true;
    }

    @Override
    public int compareTo(Pair<T, S> o) {
        return first.compareTo(o.first);
    }
}


Measured memory_bytes: 90992
N = int(input())
M = 10**6 + 1

counts = [0 for _ in range(M)]
for a in map(int, input().split()):
  counts[a] += 1

max_count = 0
for i in range(2,M):
  max_count = max(max_count,sum(counts[i::i]))

if max_count == N:
  answer = 'not coprime'
elif max_count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N, M, L; cin >> N >> M >> L;
	vvll dist(N, vll(N, LLINF));
	for (int i = 0; i < N; i++) dist[i][i] = 0;
	while (M--) {
		int a, b, c;
		cin >> a >> b >> c; --a, --b;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				chmin(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (dist[i][j] <= L) dist[i][j] = 1;
			else dist[i][j] = LLINF;
		}
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				chmin(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	int Q; cin >> Q;
	while (Q--) {
		int s, t; cin >> s >> t; --s, --t;
		cout << (dist[s][t] == LLINF ? -1 : dist[s][t]-1) << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 1280
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val xs = BooleanArray(Math.pow(10.0, n.toDouble()).toInt()) { true }
    for (i in xs.indices) {
        if (i.toString().length != n) xs[i] = false
    }
    repeat(m) {
        val (s, c) = readLine()!!.split(' ').map { it.toInt() }
        for (i in xs.indices.filter { xs[it] }) {
            if (i.toString()[s - 1] - '0' != c) xs[i] = false
        }
    }
    var ans = -1
    for (i in xs.indices) {
        if (xs[i]) {
            ans = i
            break
        }
    }
    println(ans)
}


Measured memory_bytes: 38340