akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	const int mod = 998244353;
	vector<ll> two(500000, 1);
	rep(i, two.size() - 1) two[i + 1] = two[i] * 2 % mod;
	
	int n; cin >> n;
	string x; cin >> x;
	
	vector<ll> cnt(n + 1);
	vi div;
	for(int i = 1; i * i <= n; i++) if(n % i == 0){
		div.pb(i);
		if(i * i != n) div.pb(n / i);
	}
	sort(all(div));
	for(int l : div) if(n / l % 2){
		vector<vi> same(2, vi(l, inf)), diff(2, vi(l, inf));
		rep(i, n){
			if(i / l % 2) diff[x[i] - '0'][i % l] = min(diff[x[i] - '0'][i % l], i);
			else same[x[i] - '0'][i % l] = min(same[x[i] - '0'][i % l], i);
		}
		ll ans = 0;
		int diffpos = inf, sml = 0;
		rep(i, l){
			int d = x[i] - '0';
			int p = same[1 - d][i], q = diff[d][i];
			if(p < diffpos) diffpos = p, sml = 1 - d;
			if(q < diffpos) diffpos = q, sml = d;
			ans += d * two[l - 1 - i];
		}
		//if(l == 1) dbg(diffpos, sml, ans);
		if(diffpos == inf || sml) ans++;
		cnt[l] = ans % mod;
	}
	ll tot = 0;
	//dbg(cnt);
	for(int i : div) if(n / i % 2){
		vi div2;
		for(int j = 1; j * j <= i; j++) if(i % j == 0){
			div2.pb(j);
			if(j * j != i) div2.pb(i / j);
		}
		//dbg(i, div2);
		for(int j : div2) if(i != j) (cnt[i] += mod - cnt[j]) %= mod;
		tot += 2ll * i * cnt[i] % mod;
	}
	//dbg(cnt);
	cout << tot % mod << endl;
	
	return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
//#define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;

const int N = 1e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    string s, t;
    cin >> s >> t;
    int change = sz(t);
    int n = sz(s);
    int m = sz(t);
    for (int i = 0; i <= n - m; i++) {
        int req = 0;
        for (int j = 0; j < m; j++) {
            req += s[i + j] != t[j];
        }
        change = min(change, req);
    }
    cout << change;
}


Measured memory_bytes: 3596
#![allow(unused_macros, unused_imports, dead_code, non_snake_case)]

use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn main() {
    loop {
        from_line!(x:u32, y:u32, s:u32);
        if s == 0 { break; }
        let mut ans = 0;
        for i in 1..s/2 + 1 {
            let v = (i * 100 + 99) / (100 + x);
            let u = ((s - i) * 100 + 99) / (100 + x);
            if v * (100 + x) / 100 + u * (100 + x) / 100 != s {
                continue;
            }
            let cur = v * (100 + y) / 100 + u * (100 + y) / 100;
            if ans < cur { ans = cur; }
        }
        println!("{}", ans)
    }
}



Measured memory_bytes: 5020
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<cstring>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<numeric>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll q[2020];
int main()
{
    ll l,r;
    cin>>l>>r;
    for(ll i=l;i<=min(l+2019,r);i++)
    {
        q[i%2019]=1;
    }
    ll ans=2019;
    for(ll i=0;i<=2019;i++)
    {
        if(q[i]==0)
            continue;
        for(int j=i+1;j<=2019;j++)
        {
            if(q[j]==0)
            continue;
            if(i*j%2019<ans)
                ans=i*j%2019;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = int(input())

edge = [tuple(map(int, input().split())) for _ in range(n-1)]
adj = [set() for _ in range(n)]
ans_dict = {}
c_max = 1
for a, b in edge:
    adj[a-1].add(b-1)

que = deque()
c = 1
for l in adj[0]:
    #l is the next vertext, c is the color used.
    que.append([l,c])
    ans_dict[(1,l+1)] = c
    c += 1
c_max = max(c-1, c_max)
while que:
    c = 1
    #new_v is [current vertex, color used to reach the vortex]
    new_v = que.popleft()
    for l in adj[new_v[0]]:
        if c == new_v[1]:
            c += 1
        #l is the next vertex
        que.append([l,c])
        ans_dict[(new_v[0]+1, l+1)] = c
        c += 1
    c_max = max(c-1, c_max)

print(c_max)
for l in edge:
    print(ans_dict[l])

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

int n, m;
int a[25][25], b[25], c;
int main()
{
	std::cin >> n >> m >> c;
	for (int i = 0; i < m; ++i)
		std::cin >> b[i];
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			std::cin >> a[i][j];

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int res = 0;
		for (int j = 0; j < m; ++j)
			res += a[i][j] * b[j];
		if (res + c > 0)
			++ans;
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr char sp=' ';
constexpr ll mod=1000000007;

int A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
	int K;
	cin>>K;
	cout<<A[K-1]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long a,b,c,k,i,s=-1,j,t=-1;
    cin>>a>>b>>c;
    cin>>k;
    for(i=b;i>=b;i*=2)
    {
        s++;
        if(i>a)
        {
            b=i;
            break;
        }
    }
    for(j=c;j>=c;j*=2)
    {
        t++;
        if(j>b)
        {
            c=j;
            break;
        }
    }
    if((s+t)<=k)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>

using namespace std;

int main (void)
{
    int N, K;

    cin >> N >> K; 
    vector<int> sunuke_list(N, 0);

    for (int i =0; i<K;++i){
        int di;
        cin >> di;
        for (int j=0;j<di;j++){
            int tmp;
            cin >> tmp;
            sunuke_list[tmp-1]=1;
        }
    }
  	cout<<count(sunuke_list.begin(),sunuke_list.end(), 0)<<endl;
    return 0;
}

Measured memory_bytes: 3188
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in) ;
    int N = sc.nextInt();
    int L = sc.nextInt();
    int min =300, total =0;
    for (int i=1; i<=N; i++) {
      total += L + i -1;
    }
    if (L >= 0) {
      System.out.println(total - L);
    } else if (L < 0) {
      if (L + N > 0) {
        System.out.println(total);
      } else {
        System.out.println(total - (L + N - 1));
      }
    }
  }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
string debug_string(const string& s) {
	return '"' + s + '"';
}
string debug_string(bool b) {
	return (b ? "true" : "false");
}
string debug_string(const char* s) {
	return debug_string((string)s);
}
template<class T, class U>
string debug_string(const pair<T, U>& p);
template<class U>
struct can_be_string {
	template<typename...>
	static int f(...) {
		return 0;
	}
	template<typename T>
	static char f(decltype(to_string(T()), char())) { 
		return 'a';
	}
	static const bool value = sizeof(f<U>(char())) == sizeof(char);
};
template<class T> 
typename enable_if<can_be_string<T>::value, string>::type debug_string(const T& a) {
	string s = to_string(a);
	return s;
}
template<class T>
typename enable_if<!can_be_string<T>::value, string>::type debug_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += debug_string(x);
	}
	s += "}";
	return s;
}
template<class T, class U>
string debug_string(const pair<T, U>& p) {
	string s = "(";
	s += debug_string(p.first);
	s += ", ";
	s += debug_string(p.second);
	s += ")";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << debug_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 9;
const int inf = 1e9 + 100;
const ll inf64 = 1e18l + 100;
void max_self(int& a, int b) {
	a = max(a, b);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<vector<pair<int, int>>> hash(n, vector<pair<int, int>>(n));
	for (int i = 0;i < n;++i) {
		int h1 = 0, h2 = 0;
		for (int j = i;j < n;++j) {
			h1 = (h1 * 14 + (s[j] - '0')) % mod;
			h2 = (h2 * 15 + (s[j] - '0')) % mod2;
			hash[i][j].first = h1;
			hash[i][j].second = h2;
		}
	}
	int answer = 0;
	for (int i = 0;i < n;++i) {
		for (int j = i + 1;j < n;++j) {
			int size = min(n - j, j - i);
			int l = 1, r = size;
			while (l <= r) {
				int mid = l + (r - l) / 2;
				bool ok = hash[i][mid + i - 1].first == hash[j][mid + j - 1].first;
				ok &= hash[i][mid + i - 1].second == hash[j][mid + j - 1].second;
				if (ok) {
					max_self(answer, mid);
					l = mid + 1;
				}
				else {
					r = mid - 1;
				}
			}
		}
	}
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 197504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define mci map<char,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define repr(i,l,r) for (int i=r;i>=l;i--)
#define ins insert
#define inf 10000000000000000ll
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-7
#define endl "\n"
/*ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b%a,a);}
ll modexp(ll x,ll y,ll p)
{ll res=1;x%=p;while(y){if(y&1){res=(res*x)%p;}y=y>>1;x=(x*x)%p;}return res;}
int x[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int y[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; */

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin >> n;
    double ans = 0;
    vector<double> a(n); rep(i,0,n-1) cin >> a[i], ans += 1 / a[i];
    cout << fixed << setprecision(15) << 1/ans << endl;

    return 0;

    /*check for long long or int*/
}


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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define print(x) cout << x << endl
#define debug print("reaching\n")
#define mll map<ll,ll>
#define lsb(i) i&(-i)
#define printv(x) \
	FORALL(i, x.size()) \
	{ \
		cout << x[i] << ' '; \
	} \
	cout << endl \
;
#define printm(m) \
	for(auto i: m){\
		cout<<i.ff<<' '<<i.ss<<endl; \
	}\
;
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
	if(b<=0) return 1;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res%MOD * a%MOD)%MOD;
        a = (a%MOD * a%MOD)%MOD;
        b >>= 1;
        b%=MOD;
    }
    res%=MOD;
    return res;
}



template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	else
	{
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m)
{
	T x, y;
	extGcd(a, m, x, y);
	return (x % m + m) % m;
}


int main()
{
	fast;
	// cin.tie(0);
	// cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int t=1;
	// cin>>t;
	ll tot=t;
	while(t--){
		ll s;
		cin>>s;
		if(s<3){
			cout<<0<<endl;
			continue;
		}
		vll coins;
		vll dp(s+1, 0);
		dp[0] = 1;
		FORALL(i, s+1){
			FOR(c, 3, s+1){
				if(c + i <= s){
					dp[c+i]+=dp[i];
					dp[c+i]%=MOD;
				}
			}
		}
		print(dp[s]);
	}
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch TrickOrTreat | diff TrickOrTreat.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address TrickOrTreat.cpp && ./a.out

/*
 
 5/3/2020
 
 5:02-
 
 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N,K;

void solve() {
  int res=count(A,A+N,0);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  REP(_,K) {
    int m; cin>>m;
    REP(i,m) {
      int u; cin>>u;
      --u;
      A[u]++;
    }
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n;
    cin >> n;
    string s[n];
    ll t[n];
    string x;

    rep(i, n) { cin >> s[i] >> t[i]; }
    cin >> x;

    ll sum_temp = 0, sum_all = 0;
    rep(i, n) { sum_all += t[i]; }
    rep(i, n) {
        sum_temp += t[i];
        if (s[i] == x) {
            break;
        }
    }

    ll ans = sum_all - sum_temp;
    cout << ans << endl;

    return 0;
}



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

struct Card{ char suit, value; };

void bubble( struct Card A[], int N ){
  for( int i=0; i<N; i++ ){
    for( int j=N-1; j>=i; j-- ){
      if( A[j].value < A[j-1].value ){
        swap( A[j], A[j-1] );
      }
    }
  }
}

void selection( struct Card A[], int N){
  for( int i=0; i<N; i++ ){
    int minj=i;
    for( int j=i; j<N; j++ ){
      if( A[j].value < A[minj].value ) minj=j;
    }
    swap(A[i],A[minj]);
  }
}

void print( struct Card A[], int N){
  for( int i=0; i<N; i++ ){
    if( i>0 )cout << ' ';
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable( struct Card C1[], struct Card C2[], int N){
  for( int i=0; i<N; i++ ){
    if( C1[i].suit != C2[i].suit ) return false;
  }
  return true;
}

int main(){
  Card C1[100], C2[100];
  int N;
  char ch;

  cin >> N;

  for( int i=0; i<N; i++ ) cin >> C1[i].suit >> C1[i].value;
  for( int i=0; i<N; i++ ) C2[i] = C1[i];

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" << endl;

  print(C2, N);
  if( isStable(C1, C2, N) ){
    cout << "Stable" << endl;
  }
  else cout << "Not stable" << endl;

  return 0;

}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long ans=0;
    vector <string>  M ;
    vector <string>  A ;
    vector <string>  R ;
    vector <string>  C ;
    vector <string>  H ;
    int n; cin>>n;
    for(int i=0;i<n;i++){
        string s; cin>>s;
        //cout<<s<<endl;
        if(s[0]=='M' ) M.push_back(s);
        if(s[0]=='A' ) A.push_back(s);
        if(s[0]=='R' ) R.push_back(s);
        if(s[0]=='C' ) C.push_back(s);
        if(s[0]=='H' ) H.push_back(s);
    }
    long long m=M.size(), a=A.size(), r = R.size(), c = C.size(), h= H.size();
    //cout<<h<<endl;
    ans+=m*a*r; ans+=m*a*c; ans+=m*a*h; ans+=m*r*c; ans+=m*r*h; 
    ans+=m*c*h;  
    ans+=a*r*c; ans+=a*r*h; ans+=a*c*h; 
    ans+=r*c*h;
    cout<<ans<<endl;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

int main(int argc, char *argv[])
{
	LL x;
	cin >> x;
	for (; ; ++x) {
		if(isPrime(x)) {cout << x << endl; return 0;}
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a,b,c,d,e,f,g[4][3][10]={0};
  scanf("%d",&a);
  for(b=0;b<a;b++){
    scanf("%d %d %d %d",&c,&d,&e,&f);
    g[c-1][d-1][e-1]=g[c-1][d-1][e-1]+f;
  }
  for(b=0;b<4;b++){
  for(int u=0;u<3;u++){
  for(int o=0;o<10;o++){
  printf(" %d",g[b][u][o]);
    }
    printf("\n");
  }
  if(b!=3)
   printf("####################\n");
 }
return 0;
}


Measured memory_bytes: 2084
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

int main()
{
	int n,m,t,p;
	while(true)
	{
		cin >> n >> m >> t >> p;
		if(n==0)break;
		vector<vector<int> > mp(70,vector<int>(70,0));
		vector<vector<int> > tmpmp(70,vector<int>(70,0));
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				mp[i][j]=1;
		for(int i=0;i<t;i++)
		{
			int d,c;
			cin >> d >> c;
			tmpmp=vector<vector<int> >(70,vector<int>(70,0));
			if(d==1)
			{
				for(int i=c;i<c*2;i++)
					for(int j=0;j<m;j++)
						tmpmp[i][j]=mp[i][j]+mp[c-(i-c+1)][j];
				for(int i=c*2;i<n;i++)
					for(int j=0;j<m;j++)
						tmpmp[i][j]=mp[i][j];
				mp=vector<vector<int> >(70,vector<int>(70,0));
				for(int i=0;i<n;i++)
					for(int j=0;j<m;j++)
						mp[i][j]=tmpmp[i+c][j];

			}
			else if(d==2)
			{
				for(int i=c;i<c*2;i++)
					for(int j=0;j<n;j++)
						tmpmp[j][i]=mp[j][i]+mp[j][c-(i-c+1)];
				for(int i=c*2;i<m;i++)
					for(int j=0;j<n;j++)
						tmpmp[j][i]=mp[j][i];
				mp=vector<vector<int> >(70,vector<int>(70,0));
				for(int i=0;i<m;i++)
					for(int j=0;j<n;j++)
						mp[j][i]=tmpmp[j][i+c];


			}
			
			for(int i=0;i<n;i++)
			{
//				for(int j=0;j<m;j++)
//					cout << mp[i][j] << " ";
//				cout << endl;
			}

		}

		for(int i=0;i<p;i++)
		{
			int x,y;
			cin >> x >> y;
			cout << mp[x][y] << endl;
		}

		
	}


}



Measured memory_bytes: 3232
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;


int main(){
    ll n;
    cin >> n;
    bool flag = true;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(x%2==0){
            if(x%3!=0&&x%5!=0) flag = false;
        }
    }
    if(flag)    cout << "APPROVED";
    else cout << "DENIED";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include<numeric>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, q;
	cin >> n >> m >> q;
	vector<vector<int>> data(n+1, vector<int>(n+1, 0));
	int l, r;
	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		for (int j = r; j <= n; j++) {
			data[l][j]++;
		}
	}
	int pi, qi;
	int anss;
	vector<int> ans(q);
	for (int i = 0; i < q; i++) {
		cin >> pi >> qi;
		anss = 0;
		for (int j = pi; j <= qi; j++) {
			anss += data[j][qi];
		}
		//cout << ans << endl;
		ans[i] = anss;
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


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

int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;

	priority_queue<pair<int, int>> apple;

	for (int i = 0, p; i < a; i++) {
		cin >> p;
		apple.push( { p, 0 });
	}
	for (int i = 0, q; i < b; i++) {
		cin >> q;
		apple.push( { q, 1 });
	}
	for (int i = 0, r; i < c; i++) {
		cin >> r;
		apple.push( { r, 2 });
	}

	int n = x + y;
	long long sum = 0;
	while (n) {
		switch (apple.top().second) {
		case 0:
			if (x) {
				sum += apple.top().first;
				x--, n--;
			}
			break;
		case 1:
			if (y) {
				sum += apple.top().first;
				y--, n--;
			}
			break;
		case 2:
			sum += apple.top().first;
			n--;
			break;
		}
		apple.pop();
	}
	cout << sum << endl;
}


Measured memory_bytes: 6384
import java.util.Scanner;

public class Main {
	/**
	 * UOIAUAI
	 * @param c
	 */
	public static void main(String... args) {
		try (Scanner sc = new Scanner(System.in)) {
			String c = sc.next();
			String ans = "consonant";
			String[] vowels = {"a", "i", "u", "e", "o"};
			for (String vowel : vowels) {
				if (c.equals(vowel)) {
					ans = "vowel";
					break;
				}
			}
			System.out.println(ans);
		}
	}
}

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


int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if(C>A+B) cout << A+2*B+1 << endl;
	else if (C==A+B) cout << A+2*B << endl;
	else cout << B + C << endl;	

}













Measured memory_bytes: 3564
#include <iostream>
#include <string>

using namespace std;

int main ( void )
{
	string in;

	while ( cin >> in )
	{
		string out = "";
		
		for (int i = 0; i < in.size();)
		{
			if ( in[i] == '@' )
			{
				int len = in[i + 1] - '0';
				for (int j = 0; j < len; ++j)
					out += in[i + 2];
				i += 3;
			}
			else
				out += in[i++];
		}

		cout << out << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n,x = [int(i) for i in readline().split()]
n = int(input())
MOD = 10**9+7

dp = [[[0]*4 for j in range(4)] for i in range(4)]
dp[3][3][3] = 1
for _ in range(n):
    ndp = [[[0]*4 for j in range(4)] for i in range(4)]

    for i in range(4):
        for j in range(4):
            for k in range(4):
                for l in range(4):
                    if j == 0 and k == 1 and l == 2: continue
                    if i == 0 and k == 1 and l == 2: continue
                    if j == 1 and k == 0 and l == 2: continue
                    if j == 0 and k == 2 and l == 1: continue
                    if i == 0 and j == 1 and l == 2: continue
                    ndp[j][k][l] += dp[i][j][k]
                    ndp[j][k][l] %= MOD
                
    dp = ndp
#    print(dp)

print(sum(sum(sum(j) for j in i) for i in dp)%MOD)

 


Measured memory_bytes: 3064
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  int q;
  cin >> q;
  string s, t;
  int ls, lt;
  for (int p=0; p<q; ++p){
    cin >> s >> t;
    ls = s.length();
    lt = t.length();
    int dp[ls+1][lt+1];
    for(int i=0; i<=ls; ++i){
      for(int j=0; j<=lt; ++j){
        if(i == 0 || j == 0){
          dp[i][j] = 0;
        }
        else {
          dp[i][j] = (s[i-1] == t[j-1]) ? max(max(dp[i-1][j-1] + 1, dp[i-1][j]), dp[i][j-1]) : max(dp[i-1][j], dp[i][j-1]);
        }
      }
    }
    cout << dp[ls][lt] << endl;
  }
}


Measured memory_bytes: 7072
n, k = map(int, input().split())
R, S, P = map(int, input().split())

dic = {'r': P, 's': R, 'p': S}
t = list(input())
tf_list = [0] * n
ans = 0

u = [[] for _ in range(k)]


for i in range(k):
    u[i%k] = t[i]
    ans += dic[t[i]]

for i in range(k, n):
    if u[i%k] != t[i]:
        ans += dic[t[i]]
        u[i%k] = t[i]
    elif u[i%k] == t[i] and tf_list[i-k] == 1:
        ans += dic[t[i]]
        tf_list[i] = 0
    elif u[i%k] == t[i] and tf_list[i-k] == 0:
        tf_list[i] = 1

print(ans)





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

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

    string ans = "No";
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i*m+j*n-2*i*j == k) ans = "Yes";
        }
    }
    cout << ans << endl;
    return 0;
}

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

struct PotentializedUnionFind{
    vector<int> par, rank, diff_weight;
    PotentializedUnionFind(int n) {
        par = vector<int>(n);
        iota(par.begin(), par.end(), 0);
        rank = vector<int>(n, 0);
        diff_weight = vector<int>(n, 0);
    }
    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = root(par[x]);
        }
    }
    bool unite(int x, int y, int w) {
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (rank[x] < rank[y]) {
            diff_weight[x] -= w;
            par[x] = y;
        } else {
            diff_weight[y] += w;
            par[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int weight(int x) {
        root(x);
        return diff_weight[x];
    }
    int diff(int x, int y) {
        assert(same(x, y));
        return weight(y) - weight(x);
    }
};

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

    int N,M,L,R,D;
    cin >> N >> M;
    PotentializedUnionFind PUF(N);
    for(int i = 0;i < M;++i){
        cin >> L >> R >> D;
        --L,--R;
        if(PUF.same(L,R)){
            int diff = PUF.diff(L,R);
            if(diff != D){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            PUF.unite(L,R,D);
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  vector<int> C(N);
  for (int i = 0; i < N-1; i++) {
    cin >> C.at(i);
  }

  int ans=0;
  for (int i = 0; i < N; i++) {
    ans+=B.at(i);
  }
  for (int i = 0; i < N-1; i++) {
    if(A.at(i+1)-A.at(i)==1){
      ans+=C.at(A.at(i)-1);
    }
  }
  cout<<ans<<endl;
}

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

const int M=2e5+5;
int a[M],pos[M];

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pos[a[i]]=i;
	}
	int pre=n+1,cnt=0;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(pos[i]>pre)
			cnt++;
		else
			cnt=1;
		pre=pos[i];
		ans=max(ans,cnt);
	}
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 1792
n, m = gets.strip.split.map(&:to_i)
as = m.times.map { gets.strip.to_i }

mod = 1_000_000_007

broken = Array.new(n, false)
as.each do |a|
    broken[a] = true
end

dp = Array.new(n + 1, 0)
dp[0] = 1

n.times do |i|

    if !broken[i + 1]
        dp[i + 1] += dp[i]
        dp[i + 1] %= mod
    end

    if i + 2 <= n && !broken[i + 2]
        dp[i + 2] += dp[i]
        dp[i + 2] %= mod
    end

end

puts dp[n]


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



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

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

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













#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

int main(){
    int n;
    char s[11];
    scanf("%d", &n);
    int128_t k[26];
    k[0] = 1;
    for(int i = 1; i < 26; i++){
        k[i] = k[i - 1] * 11;
    }
    map<int128_t, ll> mp;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        scanf("%s", s);
        int128_t x = 0;
        for(int j = 0; j < 10; j++){
            x += k[s[j] - 'a'];
        }
        ans += mp[x]++;
    }
    printf("%lld", ans);
}


Measured memory_bytes: 9600
/* author:hellojim */
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
vector<int>pl;
bool pri[1001000];
int num[1001000];
int n;
int a[1001000];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	for(int i=2;i<=1000000;i++)
	{
		if(!pri[i])
		{
			pl.pb(i);
			for(int j=i+i;j<=1000000;j+=i)
				pri[j]=1;
		}
	}
//	cout<<pl.size()<<endl;
//	rep(i,pl.size())
//		cout<<pl[i]<<" ";
//	cout<<endl;
	cin>>n;
	rep(i,n)cin>>a[i];
	ll ans=a[0];
	forn(i,1,n-1)
		ans=__gcd(ans,(ll)(a[i]));
	rep(i,n)
	{
	//	if(pri[a[i]]==0)num[a[i]]++;
		rep(j,200)
		{
			if(pl[j]>1000)break;
			if(a[i]%pl[j]==0&&pl[j]!=a[i])
			{
				num[pl[j]]++;
				while(a[i]%pl[j]==0)a[i]/=pl[j];
			}
		}
	}
	rep(i,n)num[a[i]]++;
	bool ok=0;
	forn(i,2,1000000)if(num[i]>=2)ok=1;
	if(!ok)
	{
		cout<<"pairwise coprime";
		return 0;
	}
	if(ans==1)
		cout<<"setwise coprime";
	else cout<<"not coprime";
	return 0;
}



Measured memory_bytes: 12452
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int n,d;
    cin>>n>>d;

    if( n % (2*d+1) == 0){
        cout<<n/(2*d+1)<<endl;
    } else {
        cout<<n/(2*d+1)+1<<endl;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std; 
typedef unsigned int uint; typedef long long ll;
typedef unsigned long long ull; typedef pair<int, int> pii;
typedef pair<ll,ll> pll; typedef long double ld;
void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0);}
template<typename T> T __lcm(T a, T b){return (a*b)/__gcd(a,b);}
template<typename T> T fpow(T a, T b, T p) {
	a %= p; T res = 1; while (b > 0) { 
	if (b & 1) res = res * a % p;
	a = a * a % p; b >>= 1;} return res;}
template<typename T> T binpow(T a, T b) {
		T res = 1; while (b > 0) {if (b & 1) res = res * a;
		a = a * a; b >>= 1;} return res;}
const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1e5;

int n, a[maxn][3];
int dp[maxn][3];

int main() {
	ri(n);
	forn(i, n){
		forn(j, 3) ri(a[i][j]);
	}
	forn(i, 3) dp[0][i] = a[0][i];
	forr(i, 1, n){
		forn(j, 3){
			dp[i][j] = a[i][j];
			int aux = 0;
			forn(k, 3) if(j != k) aux = max(dp[i-1][k], aux);
			dp[i][j]+= aux;
		}
	}
	int ans = 0;
	forn(i, 3) ans = max(ans, dp[n-1][i]);
	printf("%d\n", ans);
	
	
	return 0;
}

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

using namespace std;

const int N = 55;
const int MOD = 1e9 + 7;

int n; 
long long k, base[N][N], res[N][N], tmp[N][N];

void copy (long long a[N][N], long long b[N][N]) {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      b[i][j] = a[i][j];
    }
  }
}

void mult (long long a[N][N], long long b[N][N], long long c[N][N]) {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      c[i][j] = 0;
      for (int k = 1; k <= n; ++k) {
        c[i][j] += a[i][k] * b[k][j] % MOD;
      }
      c[i][j] %= MOD;
    }
  }
}

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    res[i][i] = 1;
    for (int j = 1; j <= n; ++j) {
      scanf("%lld", base[i] + j);
    }
  }
  while (k) {
    if (k & 1) mult(res, base, tmp), copy(tmp, res);
    mult(base, base, tmp), copy(tmp, base), k >>= 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      ans += res[i][j];
    }
  }
  cout << ans % MOD << endl;
  return 0;
}



Measured memory_bytes: 256
n,ma,mb=map(int,input().split())
ab=[[[10**6]*401 for _ in range(401)] for _ in range(n+1)]
ab[0][0][0]=0

for p in range(1,n+1):
    a,b,c=map(int,input().split())
    for i in range(400):
        for j in range(400):
            ab[p][i][j]=min(ab[p][i][j],ab[p-1][i][j])
            if i+a<=400 and j+b<=400:
                ab[p][i+a][j+b]=min(ab[p][i+a][j+b],ab[p-1][i][j]+c)

ans=10**6-1
for i in range(401):
    for j in range(401):
        if i!=0 and j!=0:
            if i*mb==j*ma:
                ans=min(ans,ab[n][i][j])

if ans==10**6-1:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 98268
log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = Number(lines[0].split(" ")[0]);
var M = Number(lines[0].split(" ")[1]);
lines = lines.splice(1).filter(v => v !== "");
cities = lines.map((v, i) => {
  P = Number(v.split(" ")[0]);
  Y = Number(v.split(" ")[1]);

  return {
    cityIndex: i,
    prefecture: P,
    year: Y
  };
});

cities.sort((a, b) => {
  return a.year - b.year;
});

count = [];

cities = cities.map(c => {
  count[c.prefecture] === undefined
    ? (count[c.prefecture] = 1)
    : (count[c.prefecture] += 1);

  P = "000000" + c.prefecture.toString();
  P = P.substr(P.length - 6, 6);
  id = "000000" + count[c.prefecture].toString();
  id = id.substr(id.length - 6, 6);

  return {
    cityIndex: c.cityIndex,
    prefecture: P,
    year: Y,
    id: id
  };
});

cities.sort((a, b) => {
  return a.cityIndex - b.cityIndex;
});

cities.forEach(c => console.log(c.prefecture.toString() + c.id.toString()));

Measured memory_bytes: 77152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

int main(void) {
    long long q, h, s, d;
    scanf("%lld%lld%lld%lld", &q, &h, &s, &d);
    long long n;
    scanf("%lld", &n);
    q *= 8;
    h *= 4;
    s *= 2;
    if (n % 2 == 0) {
        long long mini = min(min(q, d), min(h, s));
        printf("%lld\n", (n / 2) * mini);
    } else {
        long long mini = min(min(q, d), min(h, s));
        printf("%lld\n",  min(min(q / 2, h / 2), s / 2) + (n / 2) * mini);
    }
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  bool big_dif = false;
  bool all_same = true;
  ll x = 0;
  vector<ll> A(N);
  ll big;
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
    if (i == 0) {
      big = A.at(0);
    }
    if (abs(A.at(i) - big) >= 2) {
      big_dif = true;
    }
    if (A.at(i) != big) {
      all_same = false;
    }
    if (A.at(i) > big) {
      big = max(big, A.at(i));
      x = 1;
    }
    else {
      if (A.at(i) == big) {
        x += 1;
      }
    }
  }
  // cout << x << ' ' << big << "\n";
  if (big_dif) {
    cout << "No" << "\n";
  }
  else if (all_same) {
    if ((big * 2 > N) && (big != N - 1)) {
      cout << "No" << "\n";
    }
    else {
      cout << "Yes" << "\n";
    }
  }
  else {
    if (1 + (N - x) <= big && big <= x / 2 + N - x) {
      cout << "Yes" << "\n";
    }
    else {
      cout << "No" << "\n";
    }
  }
}


Measured memory_bytes: 3996
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl L(n), R(n);
    ll p = 0, q = 0;  // L[p]はLの最大値で、R[q]はRの最小値
    ll MAXL = 0, MINR = INF;
    rep(i, n) {
        cin >> L[i] >> R[i];
        R[i]++;
        if(MAXL < L[i]) {
            MAXL = L[i];
            p = i;
        }
        if(MINR > R[i]) {
            MINR = R[i];
            q = i;
        }
    }

    ll ans = 0;
    // 区間pと区間qを同じ集合に入れる場合
    rep(i, n) {
        if(i == p || i == q) {
            continue;
        }
        chmax(ans, max(0LL, R[q] - L[p]) + R[i] - L[i]);
    }

    // 区間pと区間qを違う集合に入れる場合
    vector<pair<ll, ll>> c(n);
    rep(i, n) {
        ll a = max(0LL, R[i] - L[p]);
        ll b = max(0LL, R[q] - L[i]);
        c[i] = make_pair(a, -b);
    }
    sort(all(c));
    ll u = INF;
    rep(i, n) {
        c[i].second *= -1;
        if(i > 0) {
            chmax(ans, c[i].first + u);
        }
        chmin(u, c[i].second);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 3328