akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    vector<bool> wall(n, false);
    for(int i=0; i<m; ++i){
        int a, l;
        cin >> a >> l;
        for(int j=0; j<l; ++j)
            wall[(a+j)%n] = true;
    }

    if(wall == vector<bool>(n, true)){
        cout << n << ' ' << 1 << endl;
        return 0;
    }

    map<int, int> ans;
    int i = 0;
    while(wall[i])
        ++ i;

    while(i < n){
        while(!wall[i%n])
            ++ i;
        if(i > n)
            break;

        int cnt = 0;
        while(wall[i%n]){
            ++ cnt;
            ++ i;
        }
        ++ ans[cnt];
    }

    for(auto it=ans.rbegin(); it!=ans.rend(); ++it)
        cout << it->first << ' ' << it->second << endl;

    return 0;
}


Measured memory_bytes: 1200
import           Data.Array.Unboxed

minus :: [Int] -> [Int] -> [Int]
minus (x : xs) (y : ys) = case (compare x y) of
  LT -> x : minus xs (y : ys)
  EQ -> minus xs ys
  GT -> minus (x : xs) ys
minus xs _ = xs

primesToG :: Int -> [Int]
primesToG m = 2 : sieve [3, 5 .. m]
 where
  sieve (p : xs) | p * p > m = p : xs
                 | otherwise = p : sieve (xs `minus` [p * p, p * p + 2 * p ..])
  sieve _ = []

primesToA :: Int -> [Int]
primesToA m = sieve
  3
  (array (3, m) [ (i, odd i) | i <- [3 .. m] ] :: UArray Int Bool)
 where
  sieve :: Int -> UArray Int Bool -> [Int]
  sieve p a
    | p * p > m = 2 : [ i | (i, True) <- assocs a ]
    | a ! p =  sieve (p + 2)
    $  a
    // [ (i, False) | i <- [p * p, p * p + 2 * p .. m] ]
    | otherwise = sieve (p + 2) a

lowerBound'' :: (Ord a) => a -> Int -> Int -> [a] -> Int
lowerBound'' num left right arr
  | right == left + 1 = right
  | midValue < num    = lowerBound'' num mid right arr
  | otherwise         = lowerBound'' num left mid arr
 where
  mid      = (left + right) `div` 2
  midValue = arr !! mid

lowerBound :: (Ord a) => a -> [a] -> Int
lowerBound num arr | num <= head arr = 0
                   | last arr < num  = length arr
                   | otherwise       = lowerBound'' num 0 (length arr - 1) arr

lowerBoundValue :: (Ord a) => a -> [a] -> Maybe a
lowerBoundValue num arr | i == length arr = Nothing
                        | otherwise       = Just (arr !! i)
  where i = lowerBound num arr

main :: IO ()
main = do
  [x] <- map read . words <$> getLine
  let Just ans = lowerBoundValue x (primesToG $ 2 * x)
  putStrLn $ show ans

Measured memory_bytes: 2428
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n,d;
  cin>>n>>d;
  int x[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      int temp=0;
      for(int k=0;k<d;k++){
        temp+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      if(temp==(int)sqrt(temp)*(int)sqrt(temp)) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl



int main(){
    ll n,m;cin >> n >> m;
    vector<vector<ll>> jobs(m+1);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if(a>m)continue;
        jobs[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans=0;
    for(ll i=m-1;i>=0;i--){
        for(ll b:jobs[i]){
            q.push(b);
        }
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

    int ans = N;
    for(int i=1; i<N; i++) {
        if(S[i-1] == S[i]) {
            --ans;
        }
    }

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


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = 1000000007;
const int MN = 1000010;

inline void add(ll &x, ll y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {
	int n; cin >> n;
	vector<ll> dp(n + 1), pref(n + 1);
	ll two = (ll)(n - 1) * (n - 1) % MOD;
	dp[1] = pref[1] = n;
	dp[2] = (ll)n * n % MOD; pref[2] = (pref[1] + dp[2]) % MOD;

	for (int i = 3; i <= n; ++i) {
		dp[i] = dp[i-1]; //a1=1
		add(dp[i], two); //a1!=1,a2!=1
		add(dp[i], max<ll>(0, n - i + 2)); //a1!=1,a2=an=1
		add(dp[i], pref[i - 3]);
		pref[i] = pref[i-1];
		add(pref[i], dp[i]);
	}

	//cout << dp << endl;
	cout << dp[n] << endl;
	return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int p = (int)((double)N/1.08);
    while(p*1.08 < N +1){
        if((int)((double)p*1.08) == N){
            cout << p << endl;
            return 0;
        }
        p++;
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 888
process.stdin.resume();
process.stdin.setEncoding("utf8");
let input = "";
process.stdin.on("data", function(chunk) {input += chunk;});
process.stdin.on("end", function() {main(input.split("\n"));});

let time = 0;

function allocNode(u,k) {
	const p = {};
	p.value = u;
	p.forward = 0;
	p.backward = 0;
	p.chldNum = k;
	p.children = k > 0 ? [] : null;
	return p;
}

function dfs(nodes,u) {
	let i;
	const p = nodes[u];
	if (p.forward > 0) return;
	p.forward = ++time;
	for (i = 0; i < p.chldNum; i++) 
		dfs(nodes,p.children[i]);
	p.backward = ++time;
}

function main(lines){
	const n = Number(lines[0]);
	const nodes = [];
	let i, j , u, k, line;
	for (i = 0; i < n; i++) {
		line = lines[1 + i].split(" ").map(Number);
		u = line[0];
		k = line[1];
		nodes[i] = allocNode(u,k);
		for (j = 0; j < k; j++)
			nodes[i].children[j] = line[2 + j] - 1;
	}

	for (i = 0; i < n; i++) 
		if (nodes[i].forward === 0) dfs(nodes,i);

	for (i = 0; i < n; i++) 
		console.log(`${nodes[i].value} ${nodes[i].forward} ${nodes[i].backward}`);
}



Measured memory_bytes: 16436
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
vector<int>G[100006];
int life[100006];

void dfs(int now,int par,int home) {
	int e;
	rep(i, G[now].size()) {
		int f = G[now][i];
		if (f == par)continue;
		if (life[f] == 0)continue;
		e = f;
		break;
	}
//	cout << now << ' ' << e << endl;
		life[now]--;
		if (e == home)return;
		dfs(e, now,home);
	return;
}

signed main(){
	int n, m; cin >> n >> m;
	rep(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int flg1 = 0, maxo = 0;
	rep(i, n) {
		if (G[i].size() & 1)flg1++;
		maxo = max(maxo, (int)G[i].size());
	}
	if (flg1||maxo<3) {
		cout << "No" << endl; return 0;
	}
	if (maxo >= 6) {
		cout << "Yes" << endl; return 0;
	}
	int cnt4 = 0;
	rep(i, n)if (G[i].size() == 4)cnt4++;
	if (cnt4 == 1) {
		cout << "No" << endl; return 0;
	}
	if (cnt4 == 3) {
		cout << "Yes" << endl; return 0;
	}

	rep(i, n)life[i] = G[i].size() / 2;

	int v1=-1, v2;
	rep(i, n) {
		if (G[i].size() == 4) {
			if (v1 == -1)v1 = i; else v2 = i;
		}
	}
	dfs(v1, -1, v1);
	life[v2]++;
	dfs(v2, -1, v2);
	life[v2]--;
	rep(i, n) {
		if (life[i]) {
			cout << "Yes" << endl; return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 6528
#include<iostream>

using namespace std;

int d[100010];
int outp[100010];
int N;

int main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		scanf("%d",&d[i]);
		outp[d[i]]=i;
	}
	for(int i=1;i<=N;i++){
		printf("%d ",outp[i]);
	}
	
}

Measured memory_bytes: 1536
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a + b + c >= 22){
    	cout << "bust" << endl;
	}else{
		cout << "win" << endl;
	}
    
    return 0;
}

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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

vector<ll> v(200010);

signed main() {
    ll n,k;
    cin>>n>>k;
    rep(i,0,n){
        ll a;
        cin>>a;
        v[a]++;
    }
    sort(begin(v),end(v),greater<ll>());
    ll ans=0;
    rep(i,k,200010){
        ans+=v[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
k,n=map(int,input().split())
a=list(map(int,input().split()))
M=0
for i in range(n-1):
    if a[i+1]-a[i]>M:
        M=a[i+1]-a[i]
la=a[0]+(k-a[n-1])
if la>M:
    M=la
print(k-M)


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

using namespace std;

#define REP(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define DREP(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define FOR(i, a, n) for (int i = a, _n = n; i < _n; ++i)
#define EREP(i, a) for (int i = first[a]; i; i = edge[i].nxt)
#define debug(x) cout << #x << " = " << x << endl

int n;

int a[1000000];

int main () {
	scanf ("%d", &n);

	long long sum = 0;
	REP (i, 1, n) {
		scanf ("%d", a + i);
		if (i & 1) sum += a[i] * 2;
		else sum -= a[i] * 2;
	}

	long long x = sum / 2;
	printf ("%lld\n", x);

	REP (i, 1, n - 1) {
		printf ("%lld\n", a[i] * 2 - x);
		x = a[i] * 2 - x;
	}
	return 0;
}


Measured memory_bytes: 1664
s = input()
n = len(s)
alphabet = [chr(ord("a")+i) for i in range(26)]
if n != 26:
    for i in alphabet:
        if i not in s:
            s += i
            break
    print(s)
else:
    for i in range(n-1, -1, -1):
        t = s[:i]
        n = alphabet.index(s[i])
        for j in range(n+1, 26):
            if alphabet[j] not in t:
                print(t+alphabet[j])
                exit()
    print(-1)

Measured memory_bytes: 38384
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
int rint();char rch();long long rlong();
string s="AKIHABARA";
void fail() {
  printf("NO\n");
  exit(0);
}
int main() 
{
  ios_base::sync_with_stdio(false); cin.tie(0);
  string inp; cin>>inp;
  int n=s.length();
  bool ans=true;
  int i=0;
  for (auto &x:inp) {
    if (i==n) fail();
    if (x==s[i]) {
      //printf("1: x:%c i:%d s[i]:%c\n",x,i,s[i]);
      i++;
    }
    else if (s[i]=='A'&&i+1<n&&s[i+1]==x) {
      //printf("2: x:%c i:%d s[i]:%c s[i+1]:%c\n",x,i,s[i],s[i+1]);
      i+=2;
    }
    else fail();
  }
  if (i==n||i==n-1) printf("YES\n");
  else fail();
}




static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int rint()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
char rch()
{
    readAhead(16);
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    char ans=*stdinPos;
    ++stdinPos;
    return ans;
}
long long rlong()
{
    readAhead(32);

    long long x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;

long long exp2(int p) {
	long long ret = 1;
	for (int i = 0; i < p; i++) {
		ret = (ret * 2) % 1000000007;
	}
	return ret;
}
long long N;
long long A[300000];
long long ans = 0;
long long cnt;

int main() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (int i = 0; i < 60; i++) {
		cnt = 0;
		for (int j = 0; j < N; j++) {
			if ((A[j] >> i) & 1 == 1) {
				cnt += 1;
			}
		}
		ans += (((cnt * (N - cnt)) % 1000000007) * exp2(i));
		ans = ans % 1000000007;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 2560
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, d;

int x[11][11];

int main(){
	cin >> n >> d;
	REP(i, n){
		REP(j, d){
			cin >> x[i][j];
		}
	}
	int ans = 0;
	REP(i, n){
		for(int j = i + 1;j < n;j++){
			int di = 0;
			REP(k, d){
				di += abs(x[i][k] - x[j][k])*abs(x[i][k] - x[j][k]);
			}
			if((int)sqrt(di) * (int)sqrt(di) == di)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define PP std::pair<int,int>
#define LL long long
int N;
int A[200010];
LL ans;
int main(){
    int N;
    int S=0;
    std::cin>>N;
    for(int i=0;i<N;i++){
        std::cin>>A[i];
    }
    for(int i=0;i<N;i++){
        if(A[i]>S){
            std::cout<<-1<<std::endl;
            return 0;
        }
        if(A[i-1]+1==A[i])ans++;
        else ans+=A[i];
        S=A[i]+1;
    }
    std::cout<<ans<<std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define fi first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define msi map<string,int>
#define si set<int>
#define all(v) v.begin(),v.end()
#define sz(v)  int((v).size())
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define dep(i,a,b)  for(int i=a;i>=b;i--)
#define isinarr(i,n) ((i>=0)?((i<n)?1:0):0)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppb pop_back
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mp make_pair
#define  endl '\n'

using namespace std;
void solve()
{
  int n;
  cin>>n;
  int dp[n+1][3];
  int x,y,z;
  dp[0][0]=0;
  dp[0][1]=0;
  dp[0][2]=0;
  rep(i,0,n)
  {
    cin>>x>>y>>z;
    dp[i+1][0]=x+max(dp[i][1],dp[i][2]);
    dp[i+1][1]=y+max(dp[i][0],dp[i][2]);
    dp[i+1][2]=z+max(dp[i][1],dp[i][0]);
  }
  
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
} 



signed main()
{
    fastio
    int t=1;
    while(t--)
      solve();
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
using namespace std;
int main() {
	int a;
	string str;
	cin >> a >> str;
	if (a >= str.length()) {
		cout << str << endl;
		return 0;
	}
	cout << str.substr(0, a)+"..." << endl;
}

Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <complex>

// http://www.prefield.com/algorithm/geometry/area2.html

using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=(a); i<ll(b); i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

#define next(P, i) P[(i-1+P.size())%P.size()]
#define curr(P, i) P[i]

typedef vector<P> polygon;
double area2(const polygon& P) {
    double A = 0;
    for (int i = 0; i < P.size(); ++i)
        A += cross(curr(P, i), next(P, i));
    return A;
}


int solve(string const& s){
    vi v(10);
    rep(i, 10) v[i] = s[i] - '0';
    while (v.size() != 1){
        vi w(v.size() - 1);
        rep(i, w.size()){
            w[i] = v[i] + v[i + 1];
            w[i] %= 10;
        }
        swap(v, w);
    }
    return v.front();
}

int main(){
    double x, y;
    polygon p;
    while (scanf("%lf,%lf", &x, &y) != EOF){
        p.emplace_back(x, y);
    }
    printf("%.100lf", abs(area2(p)) / 2);
}

Measured memory_bytes: 1236
N = int(input())
A = [int(input()) for _ in range(N)]
if N == 2:
    for j in A[::-1]:
        print(j)
else:
    tmp = sorted(A)
    del tmp[0:(N-2)]
    for i in range(N):
        if A[i] == tmp[1]:
            print(tmp[0])
        else:
            print(tmp[1])


Measured memory_bytes: 14136
n, m = map(int, input().split())

ab = []

for i in range(m):
    a, b = map(int, input().split())
    ab.append((a,b))

ab = sorted(ab, key = lambda x: x[1])

left = 0
ans = 0


for a, b in ab:
    if a > left:
        ans += 1
        left = b-1
    
print(ans)
        

Measured memory_bytes: 18960
# kartikay26

from math import *
from collections import *
from itertools import *
from functools import *
from random import *
def getl(t=int): return [t(x) for x in input().split()]
def get(t=int): return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z')+1)]
alnum = lambda x: ord(x) - ord('a')

def main():
	s = input()
	prev = ""
	curr = ""
	ans = 0
	for c in s:
		curr += c
		if curr != prev:
			prev = curr
			curr = ""
			ans += 1
	print(ans)


if __name__ == "__main__":
	main()


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

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class AAirplane {
public:
        int A[3];
void solve(std::istream& cin, std::ostream& cout) {
    _for(i,3)cin >> A[i];
    sort(A, A+3);
    cout << A[0] + A[1] << endl;
}
};


#undef int
int main() {
	AAirplane solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
#define enl << endl
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n, a, b;
    ll x[100010];
    cin >> n >> a >> b;
    rep(i, n){
        cin >> x[i];
    }

    ll sum = 0;
    rep(i, n-1){
        if((x[i+1] - x[i])*a < b){
            sum += (x[i+1] - x[i])*a;
        }else{
            sum += b;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1024
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
inline double getDouble(){ double s; scanf("%lf", &s); return s; }

#include <queue>
#include <set>

using namespace std;

vector<pair<int, int> > g[100000];
double pp[100000];
double p;

double dfs(int pos, double prob = 1, int prev = -1){
  ::pp[pos] = prob;

  double ans = 0;
  REP(i,g[pos].size()){
    const int next = g[pos][i].first;
    const int c = g[pos][i].second;

    if(next != prev){
      ans += p * (c + dfs(next , prob * p, pos));
    }
  }

  return ans;
}

int main(){
  ::p = getDouble();
  const int n = getInt();

  REP(i,n-1){
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    const int c = getInt();

    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }

  const double t = dfs(0);

  double ans = t;
  REP(i,n){
    ans += pp[i] * t;
  }

  printf("%.10f\n", ans);
}

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

int main() {
  int N,A;
  cin >>N>>A;
  if(N%1000>500 && N%1000-500<=A){
    cout <<"Yes"<<endl;
  }
  else if(N%1000<500 && N%1000<=A) {
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
const int mod=1e9+7;
 
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    int ans=0;
    cin>>s;
    cin>>t;
    for(int i=0;i<s.size();i++){
    	if(s[i]!=t[i])ans++;
    }
    cout<<ans;

    
}





Measured memory_bytes: 3744
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Node {
    int id;
    Node left;
    Node right;
}

class Main {
    static Node root;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            String command = sc.next();
            if (command.charAt(0) == 'i') {
                int id = sc.nextInt();
                insert(id);
            } else if (command.charAt(0) == 'p') {
                System.out.println(inParse(root));
                System.out.println(preParse(root));
            }
        }
    }

    public static void insert(int id) {
        Node insertedNode = new Node();
        insertedNode.id = id;

        if (root == null) {
            root = insertedNode;
            return;
        }

        Node node = root;
        while(true) {
            if (id < node.id) {
                if (node.left == null) {
                    node.left = insertedNode;
                    return;
                }
                node = node.left;
            } else {
                if (node.right == null) {
                    node.right = insertedNode;
                    return;
                }
                node = node.right;
            }
        }
    }

    public static String preParse(Node node) {
        if (node == null) {
            return "";
        }
        return " " + node.id + preParse(node.left) + preParse(node.right);
    }

    public static String inParse(Node node) {
        if (node == null) {
            return "";
        }
        return inParse(node.left) + " " + node.id + inParse(node.right);
    }
}



Measured memory_bytes: 474600
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,x,y;
lol i[100001];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    lol c,d=0,e=0,f=0,g=1,h=0;
    cin >>a>>b;
    b=b*2+1;
    if(a%b==0) cout <<a/b<<'\n';
    else cout <<a/b+1<<'\n';
    return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<ll> pos(k+1);
    const ll MOD = 1e9+7;
    pos[0]=1;
    rep(i,0,n) {
        int a;
        cin >> a;
        vector<ll> next(k+1);
        ll sum = 0;
        rep(j,0,k+1) {
            sum=(sum+pos[j])%MOD;
            if(j-a-1>=0) sum=(sum+MOD-pos[j-a-1])%MOD;
            next[j] = sum;
        }
        swap(next,pos);
    }
    cout<<pos[k]<<"\n";
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

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

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, 0, N) {
    cin >> A[i];
  }

  bool flag = true;
  int cnt = 0;
  rep(i, 0, N) {
    int ai = A[i];
    if (ai == cnt + 1) {
      cnt++;
    }
  }

  if (cnt == 0) {
    cout << -1 << endl;
  } else {
    cout << N - cnt << endl;
  }

  return 0;
};


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

int main() {
      int N, M;
      cin >> N >> M;
      vector<int> p(M);
      vector<string> S(M);
      set<int> AC;
      rep(i, M){
            cin >> p[i];
            cin >> S[i];
            if(S[i] == "AC") AC.insert(p[i]);
      }

      int cr = AC.size();
      int pn = 0;
      vector<int> pnnum(N+1);
      vector<bool> doneAC(N+1, false);
      rep(i, M){
            if(S[i] == "WA" && doneAC[p[i]] == false){
                  pnnum[p[i]]++;
            }
            if(S[i] == "AC" && doneAC[p[i]] == false){
                  pn += pnnum[p[i]];
                  doneAC[p[i]] = true;
            }
      }

      cout << cr << " " << pn << endl;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
 
    vector<vector<int> > grid(h, vector<int>(w));
    int i = 0;
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            if(y % 2 == 0)
                grid[y][x] = i + 1;
            else
                grid[y][w-1-x] = i + 1;
            -- a[i];
            if(a[i] == 0)
                ++ i;
        }
    }
 
    for(int y=0; y<h; ++y){
        cout << grid[y][0];
        for(int x=1; x<w; ++x)
            cout << ' ' << grid[y][x];
        cout << endl;
    }
 
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
int n;
int gcd(int a, int b) { 
    if (a == 0) return b; 
    return gcd(b % a, a); 
} 
void solve() {
	cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				sum += gcd(i,gcd(j,k));
			}
		}
	}
	printf("%lld\n",sum);
}
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin >> t;
	// for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	// }
}

Measured memory_bytes: 3772
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		for(int i=1; i<=b; i++){
		    int sum = a*i;
		    if(sum%b==c){
		        System.out.println("YES");
		        return;
		    }
		}
		
		System.out.println("NO");   
        
    }
}


Measured memory_bytes: 35580
#include <stdio.h>
int main (void){
    int K, T;
    int a[100] = {0};
    int maxfactor, sum = 0, max = -1;
    scanf("%d %d", &K, &T);
    for(int i = 0; i < T; i++) scanf("%d", &a[i]);
    for(int i = 0; i < T; i++){
        if(max < a[i]){
            max = a[i];
            maxfactor = i;
        }
    }
    /*int pair = (max+1)/2;
    int counter = 0;
    for(int i = 0; i < T; i++){
        if(i != maxfactor){
            while(counter/2 == pair){
                if(a[i] <= 0) break;
                a[i]--;
                counter++;
            }
        }
    }
    if(counter/2 == pair){
        printf("0\n");
    }*/

    for(int i = 0; i < T; i++){
        if(i != maxfactor){
            sum += a[i];
        }
    }
    if(sum+1 < a[maxfactor]){
        printf("%d\n",a[maxfactor]-sum-1);
    } else {
        printf("0\n");
    }
    return 0;
}

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

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

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

	int n,m; cin >> n >> m;
	P a[1005];
	for (int i = 0;i < m;i++){
		int t1,t2; cin >> t1 >> t2;
		a[i] = P(t1,t2);
	}

	sort(a,a+m);

	int ans = 0;

	for (int i = 1;i < m;i++){
		ans += max(0,n-a[i].first);
	}
	
	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 3196
#include <iostream>

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

  int a = n % 10;
  if (a == 3) {
    std::cout << "bon" << std::endl;
  } else if (a == 0 || a == 1 || a == 6 || a == 8) {
    std::cout << "pon" << std::endl;
  } else {
    std::cout << "hon" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int main() {
    string S; cin >> S;
    int count =0;
    for(int i=1;i<S.size();i++){
        if(S[i-1]!=S[i])count++;
    }
    cout << count << endl;
}



Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a<b)
    for(int i=0;i<b;i++)
      cout<<a;
  else
    for(int i=0;i<a;i++)
      cout<<b;
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
class Edge
{
public:
  int t,w;
  Edge(){}
  Edge(int t,int w): t(t),w(w){}
};
vector<Edge> G[100005];
int V,d[100005];
bool visited[100005];
int cnt;
void bfs(int s)
{
  for(int i=0;i<V;i++) d[i]=inf;
  queue<int> q;
  q.push(s);
  d[s]=0;
  int u;
  while(!q.empty())
    {
      int u=q.front();q.pop();
      for(int i=0;i<G[u].size();i++)
	{
	  Edge e=G[u][i];
	  if(d[e.t]==inf)
	    {
	      d[e.t]=d[u]+e.w;
	      q.push(e.t);
	    }
	}
    }
}
void solve()
{
  bfs(0);
  int maxv=0;
  int tgt=0;
  for(int i=0;i<V;i++)
    {
      if(d[i]==inf) continue;
      if(maxv<d[i])
	{
	  maxv=d[i];
	  tgt=i;
	}
    }
  bfs(tgt);
  maxv=0;
  for(int i=0;i<V;i++)
    {
      if(d[i]==inf) continue;
      maxv=max(maxv,d[i]);
    }
  cout << maxv << endl;
}


int main(void)
{
  cin >> V;
  for(int i=0;i<V-1;i++)
    {
      int s,t,w;
      cin >> s >> t >> w;
      G[s].push_back(Edge(t,w));
      G[t].push_back(Edge(s,w));
    }
  solve();
  return 0;
}



Measured memory_bytes: 9780
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
// all_of
// partial_sum, adjacent_difference

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N, K;
int A[300][300];
bool used[300];

PP Sub() {
	map<int, int> M;
	REP(i, 0, N) {
		REP(j, 0, K) {
			if (!used[A[i][j]]) {
				++M[A[i][j]];
				break;
			}
		}
	}

	PP mx;
	int mxv = 0;
	for (auto&& p : M) {
		if (p.second > mxv) {
			mxv = p.second;
			mx = p;
		}
	}
	return mx;
}

int main() {
	cin >> N >> K;
	REP(i, 0, N) {
		REP(j, 0, K) {
			cin >> A[i][j];
		}
	}

	int ans = INF;
	REP(z, 0, K) {
		PP p = Sub();
		ans = min(ans, (int)p.second);

		int sp = p.first;
		
		used[sp] = true;
	}

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

Measured memory_bytes: 640
from fractions import gcd

N=int(input())
A=[int(i) for i in input().split()]


X=[0 for i in range(N)]
Y=[0 for i in range(N)]

for i in range(1,N):
    X[i]=gcd(X[i-1],A[i-1])
for i in range(N-1)[::-1]:
    Y[i]=gcd(Y[i+1],A[i+1])

Z=[gcd(X[i],Y[i]) for i in range(N)]
print(max(Z))


Measured memory_bytes: 16132
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#define bye return 0
#define speedOne ios::sync_with_stdio(false)
#define speedtwo cin.tie(0)
typedef long long int lli;
typedef long long ll;
using namespace std;
int main()
{
    ll a;
    cin >> a;
    cout << (a)+(a*a)+(a*a*a) << endl;
	bye;
}

Measured memory_bytes: 3564
# ARC064C - Boxes and Candies (ABC048C)
def main():
    n, x = list(map(int, input().rstrip().split()))
    A = list(map(int, input().rstrip().split()))

    # modify A[0] if >x
    ans = 0 if A[0] < x else A[0] - x
    A[0] = min(A[0], x)
    
    prv = A[0]
    for i in range(1, n):
        dif = prv + A[i] - x
        if dif > 0:
            A[i] -= dif
            ans += dif
        prv = A[i]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14060
N = int(input())
S = input()
hidari = 0
migi = 0
for i in range(N):
  if S[i] == '(':
    hidari += 1
  else:
    if hidari > 0:
      hidari -= 1
    else:
      migi += 1
S = '(' * migi + S + ')' * hidari
print(S)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 1e6 + 11;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int n; cin >> n;

  vector<int> a(n);
  vector<int> aC(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    aC[i] = a[i];
  }
  sort(aC.rbegin(), aC.rend());

  for (int i = 0; i < n; i++) {
    if (a[i] == aC[0]) cout << aC[1] << "\n";
    else cout << aC[0] << "\n";
  }


  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;

#define ll long long

int N,A,B,C;
int l[10];

int dfs(int n, int a, int b, int c){
    int t1, t2;
    //a,b,c それぞれに対しどの竹か決めるのにそれぞれ10コスト払っている分 -30
    if(n == N){
        if(a != 0 && b != 0 && c != 0){
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        }else{
            return 1e9; 
        }
    }
    int ret0 = dfs(n + 1, a, b, c);
    int ret1 = dfs(n + 1, a + l[n], b, c) + 10;
    int ret2 = dfs(n + 1, a, b + l[n], c) + 10;
    int ret3 = dfs(n + 1, a, b, c + l[n]) + 10;

    t1 = min(ret0,ret1);
    t2 = min(ret2,ret3);
    return min(t1, t2);
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }
    
    cout << dfs(0,0,0,0) << endl;

}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


N = int(input())
A = [int(i) for i in input().split()]


def f(m):
    global A
    return sum([m % x for x in A])


m = lcm_list(A) - 1


print(f(m))


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

int main()
{
	vector<int> h;
	int n, max = 0, cnt = 0;
	cin >> n;
	h.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		if (max <= h[i])
		{
			cnt++;
			max = h[i];
		}
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, s[30], ans = 0;
int main() {
	cin >> n;
	REP(i, n)cin >> s[i];
	REP(i, n) {
		bool ok = true;
		REP(j, i) {
			if (s[j] > s[i])ok = false;
		}
		if (ok)ans++;
	}
	cout << ans << endl;
}

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

int main(){
    ll a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(k<=a)    ans=k;
    else if(k<=a+b) ans=a;
    else    ans=a+a-k+b;
    // ans+=min(k,a),k-=min(k,a);
    // k-=min(k,b);
    // ans-=min(k,c);
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3624
if __name__ == '__main__':
    a,b, c = map(int, input().split())

    n = int(input())
    count = 0
    while a >= b:
        count+=1
        b=b*2

    while b >= c:
        count+=1
        c=c*2

    if count <= n:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 9164
#include <stdio.h>

int main() {
	int a;
	int b;
	
	scanf("%d", &a);
	scanf("%d", &b);
	
	if(a<=9 && b<=9)
	printf("%d\n", a*b);
	
	else
	printf("-1\n");
	
	
	
	
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;

int dig(int n){
    int ans =0;
    while (n>0) {
        n/=10;
        ans++;
    }
    return ans;
}

int main(){
    int a,b;
    while (cin >> a and cin >>b) {
        cout << dig(a+b)<<endl;
    }
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int, input().split()))
cnt = [[a[0], 0]]
for i in a:
    if cnt[0][0] == i:
        cnt[0][1] += 1
    else:
        if len(cnt) == 1:
            cnt.append([i, 1])
            if not abs(cnt[0][0] - cnt[1][0]) == 1:
                print("No")
                exit()
        else:
            if cnt[1][0] == i:
                cnt[1][1] += 1
            else:
                print("No")
                exit()
cnt.sort()
if len(cnt) == 1:
    print("Yes" if cnt[0][0] <= cnt[0][1] // 2 or cnt[0][0] + 1 == n else "No")
else:
    print("Yes" if 1 <= cnt[1][0] - cnt[0][1] <= cnt[1][1] // 2 else "No")

Measured memory_bytes: 20756