akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,m,i,j,ii,jj;
  	cin>>n;
  	m=floor(sqrt(n));
    for(;m>0;m--){
    	if(n%m==0){
        	cout<<m+n/m-2<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
struct inf{
	int k;
	lld l,r;
};
bool tmr(inf a,inf b){
	if(a.k!=b.k) return a.k < b.k;
	return -a.l + a.r > -b.l + b.r; 
}
vector<inf> a,b;
int main(void){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		a.clear();
		b.clear();
		lld ans = 0;
		for(int e=0;e<n;e++){
			int aa;
			lld bb,c;
			scanf("%d%lld%lld",&aa,&bb,&c);
			if(bb==c) ans += bb;
			else if(bb>c){
				inf now = {aa,bb,c};
				a.push_back(now);
			}
			else{
				if(n-aa==0) ans += bb;
				else{
					inf now2 = {n-aa,c,bb};
					b.push_back(now2);
				}
			}
		}
		sort(all(a),tmr);
		sort(all(b),tmr);
		priority_queue<lld> p,q;
		for(int e=0;e<sz(a);e++){
			if(sz(p)<a[e].k){
				ans += a[e].l;
				p.push(-a[e].l+a[e].r);	
			}else{
				lld tt = p.top();
				if(a[e].l>-tt){
					p.pop();
					ans += (tt+a[e].l);
					p.push(-a[e].l+a[e].r);
				}else ans += (a[e].r);
			}
		}
		for(int e=0;e<sz(b);e++){
			if(sz(q)<b[e].k){
				ans += b[e].l;
				q.push(-b[e].l+b[e].r);
			}else{
				lld tt = q.top();
				if(b[e].l>-tt){
					q.pop();
					ans += (tt+b[e].l);
					q.push(-b[e].l+b[e].r);
				}else ans += b[e].r;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 10588
# 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;
LL x[101], y[101];

struct UnionFind {
	UnionFind(size_t size){
        for(int i = 0;i < (int)size;i++){
            par.emplace_back(i);
            rnk.emplace_back(0);
        }
    }
	vector<int> par, rnk;

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

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)return;
        if(rnk[x] < rnk[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rnk[x] == rnk[y])rnk[x]++;
        }
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};

int main(){
    cin >> n;
    REP(i, n)cin >> x[i] >> y[i];
    int ans = n;
    REP(u, n)REP(v, n){
        LL p = x[u] - x[v];
        int q = y[u] - y[v];
        UnionFind uf(n);
        REP(i, n)REP(j, n){
            if(x[i] - x[j] == p && y[i] - y[j] == q)uf.unite(i, j);
        }
        set<int> st;
        REP(i, n)st.insert(uf.find(i));
        ans = min(ans, (int)st.size());
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#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<ll, ll>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    bool ok = true;
    int a[5], k;
    rep(i, 5) cin >> a[i];
    cin >> k;

    rep(i, 5) rep(j, 5) {
        if (i == j) continue;
        int d = abs(a[i]-a[j]);
        if (d > k) ok = false;
    }

    cout << (ok ? "Yay!" : ":(") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] t = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            t[i] = a;
            sum += a;
        }
        int m = Integer.parseInt(sc.next());
        for (int i = 0; i < m; i++) {
            int p = Integer.parseInt(sc.next());
            int x = Integer.parseInt(sc.next());
            int temp = sum;
            temp += x - t[p - 1];
            System.out.println(temp);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> > a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    int ct=0;
    int curr=0;
    for(int i=0;i<n;i++)
    {
        if(a[i].first==a[i].second)
        {
            ct++;
        }
        else
        {
            curr=max(curr,ct);
            ct=0;
        }
        
    }
    curr=max(curr,ct);
    if(curr>=3)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
}

Measured memory_bytes: 3620
# include<cstdio>
# include<cmath>

int main() {
    double res, x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    printf("%lf\n", sqrt(pow(x2-x1,2.0) + pow(y2-y1,2.0)));
    return 0;
}


Measured memory_bytes: 2744
#![allow(unused)]
use std::io::{self, Read};

fn get_stdin() -> String {
    let mut buf = String::new();
    let mut stdin = io::stdin();
    stdin.read_to_string(&mut buf);
    return buf
}

fn to_nums(ss: &str) -> Vec<i64> {
    ss.split_whitespace()
        .map(|x| x.parse::<i64>().unwrap())
        .collect()
}

fn main() {
    let input = get_stdin();
    let ss: Vec<&str> = input.split('\n').collect();
    let nums = ss[1];
    let nums = to_nums(nums);
    let mn = nums.iter().min().unwrap();
    let mx = nums.iter().max().unwrap();
    let s: i64 = nums.iter().sum();
    println!("{} {} {}", mn, mx, s);
}



Measured memory_bytes: 5036
#pragma region Template

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <bitset>
#include<map>
#include<cmath>
#include <set>
#include<limits.h>
#include<fstream>

#define lli long long int
#define l long
#define us unsigned short
#define mod 1000000007
#define INF 1e9+5

#define vi vector<int>
#define vus vector<unsigned short>
#define vlli vector<long long int>
#define vs vector<string>
#define mii map<int,int>

#define w(t) int t; cin>>t;while(t--)

using namespace std;

#pragma endregion

int main()
{
	lli n;
	cin>>n;
	vlli dp(3);
	
	for (int i = 0; i < n; i++)
	{
		vlli c(3);
		vlli ndp(3,-1);
		for (int j = 0; j < 3; j++)
		{
			cin>>c[j];
		}

		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				if (j != k)
				{
					ndp[k] = max(ndp[k], dp[j] + c[k]);
				}
			}
		}
		dp = ndp;
	}
	
	lli m = max({dp[0],dp[1],dp[2]});

	cout<<m<<endl;

	return 0;
}


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

using namespace std;

const int md = (int) 1e9 + 7;

inline int add(int x, int y) {
  x += y;
  if (x >= md) x -= md;
  if (x < 0) x += md;
  return x;
}

inline int mul(int x, int y) {
  return (long long) x * y % md;
}

int power(int b, long long p) {
  int res = 1;
  while (p > 0) {
    if (p & 1) res = mul(res, b);
    b = mul(b, b);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, md - 2);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> pref(n + 1);
  for (int i = 0; i < n; i++) {
    pref[i + 1] = add(pref[i], inv(i + 1));
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans = add(ans, mul(x, add(pref[i + 1] - 1, pref[n - i])));
  }
  for (int i = 0; i < n; i++) ans = mul(ans, i + 1);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3664
# your code goes here
N = int(input())

cnt = [0]*5

for i in range(N):
	name = input()
	if name[0] == 'M':
		cnt[0] += 1
	elif name[0] == 'A':
		cnt[1] += 1
	elif name[0] == 'R':
		cnt[2] += 1
	elif name[0] == 'C':
		cnt[3] += 1
	elif name[0] == 'H':
		cnt[4] += 1
ans = 0
for i in range(3):
	for j in range(i+1,4):
		for k in range(j+1,5):
			ans += cnt[i]*cnt[j]*cnt[k]
print(ans)

Measured memory_bytes: 3064
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
    }

    if a%2==0 || b%2==0 {
        println!("Even");
    } else {
        println!("Odd");
    }

}


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

namespace Template
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            //出力
            if (a<=b)
            {
                Console.WriteLine(a);
            }
            else
            {
                Console.WriteLine(a-1);
            }
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int H, W, N;
map<PII, int> cnt;
int ans[10];


void solve(){
	ans[0] = (H-2)*(W-2)-SIZE(cnt);
	for(auto p : cnt) ans[p.se]++;
	rep(i, 0, 10) cout << ans[i] << endl;
}


signed main(){
	cin >> H >> W >> N;
	rep(i, 0, N){
		int a, b;
		cin >> a >> b;
		rep(j, 0, 3)
			rep(k, 0, 3)
				if(1 <= a-j && a-j <= H-2 && 1 <= b-k && b-k <= W-2) cnt[{ a-j, b-k }]++;
	}

	solve();

	return 0;
}

Measured memory_bytes: 56448
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int X; cin >> X;
  if (X >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#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 DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e5+10;
int x[SIZE],y[SIZE];
int u[401];
bitset<401>v[401];
int main(){
    DRII(N,M);
    REP(i,M){
        RII(x[i],y[i]);
    }
    REPP(i,1,N+1){
        for(int j=M-1;j>=0;j--){
            int v1=(u[x[j]]==i);
            int v2=(u[y[j]]==i);
            if(v1&&v2){
                v[i][i]=1;
                break;
            }
            if(v1)u[y[j]]=i;
            if(v2)u[x[j]]=i;
            if(x[j]==i)u[y[j]]=i;
            if(y[j]==i)u[x[j]]=i;
        }
        REPP(j,1,N+1)
            if(u[j]==i)v[i][j]=1;
    }
    int an=0;
    REPP(i,1,N+1)REPP(j,1,i){
        if(!(v[i]&v[j]).count()&&!v[i][i]&&!v[j][j]&&!v[i][j]&&!v[j][i])an++;
    }
    printf("%d\n",an);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  
  int count=0;
  if(N>1) {
    if(S[0]=='R'&&S[1]=='R') count++;
    if(S[N-1]=='L'&&S[N-2]=='L') count++;
    rep2(i,1,N-1) {
      if(S[i]=='L'&&S[i-1]=='L'||S[i]=='R'&&S[i+1]=='R') count++;
    }
  }
  
  cout << min(N-1,count+K*2) << endl;
}

Measured memory_bytes: 3736
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const double PI = acos(-1);

int main()
{
    ll sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    int n;
    cin >> n;
    P p[200002];
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        p[i] = P(x, y);
    }
    if(sx > gx){
        sx = -sx, gx = -gx;
        for(int i = 0; i < n; i++) p[i] = P(-p[i].first, p[i].second);
    }
    if(sy > gy){
        sy = -sy, gy = -gy;
        for(int i = 0; i < n; i++) p[i] = P(p[i].first, -p[i].second);
    }
    if(gx - sx < gy - sy){
        swap(sx, sy);
        swap(gx, gy);
        for(int i = 0; i < n; i++) p[i] = P(p[i].second, p[i].first);
    }
    sort(p, p + n);
    vector<int> v;
    for(int i = 0; i < n; i++){
        if(p[i].first < sx || p[i].first > gx) continue;
        if(p[i].second < sy || p[i].second > gy) continue;
        int k = upper_bound(v.begin(), v.end(), p[i].second) - v.begin();
        if(k == (int)v.size()) v.push_back(p[i].second);
        else v[k] = p[i].second;
    }
    int k = v.size();
    double ans = -1;
    if(k != gy - sy + 1) ans = ((gx - sx) + (gy - sy)) * 100 - 20 * k * (1 - PI / 4);
    else ans = ((gx - sx) + (gy - sy)) * 100 - 20 * (k - 1) * (1 - PI / 4) + 10 * PI - 20;
    cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n,sum=0;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  sort(a.begin(),a.end());
  if(sum%10!=0){
    cout << sum;
    return 0;
  }else{
    rep(i,n){
      if(a.at(i)%10!=0){
        sum=sum-a.at(i);
        break;
      }
    }
    if(sum%10==0){
    cout << 0;
    return 0;
    }
  }
  cout << sum;
}
  

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

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

const int INF = 1000000007;

int main(void){
	int n; cin>>n;
	int a[110000]={0};
	for(int i=0;i<n;i++) cin>>a[i];

	int pos = a[0], cnt=1;
	bool can = false;
	while(cnt<n){
		//cout<<"pos:"<<pos<<endl;
		if(a[0] == 2){
			can = true;
			break;
		}
		if(a[pos-1] == 2){
			cnt++;
			can = true;
			break;
		}
		else{
			pos = a[pos-1];
			cnt++;
		}
	}

	if(can) printf("%d\n", cnt);
	else printf("-1\n");

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

int N;
map<string, int> cnt;

int main() {
	cin >> N;
	int M = 0;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		cnt[s]++;
		M = max(cnt[s], M);
	}

	vector<string> ans;
	for (auto it = cnt.begin(); it != cnt.end(); it++) {
		if ((*it).second == M) {
			ans.push_back((*it).first);
		}
	}
	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 23916
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector< vector <int> >a(n,vector<int>(3));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	vector< vector <int> >dp(n,vector<int>(3,0));
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for(int i=1;i<n;i++)
	{
		for(int j = 0;j<3;j++)
		{
			int val = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
			dp[i][j] = val + a[i][j];
		}
	}
	int ans = max(dp[n-1][0],dp[n-1][1]);
	ans = max(ans,dp[n-1][2]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14340
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) cout << mat[i][j] << " "; cout << endl; }

using namespace std;

typedef long long int ll;
typedef pair <int, char> ii;
typedef pair <int, ii> iiii;


int main(){
	
	int c[3][3];
	rep(i, 0, 3) rep(j, 0, 3) cin >> c[i][j];
	
	
	rep(a1, -1000000, 1000000){
		int b1, b2, b3;
		b1 = c[0][0] - a1;
		b3 = c[0][1] - a1;
		b3 = c[0][2] - a1;
		if((c[1][0]-b1 == c[1][1]-b2 && c[1][0]-b1 == c[1][2]-b3) &&
			(c[2][0]-b1 == c[2][1]-b2 && c[2][0]-b1 == c[2][2]-b3)){
				puts("Yes");
				return 0;
			}
	}
	
	puts("No");
}

Measured memory_bytes: 256
n= int(input())
a= []
for i in range(n):
    s,p=input().split()
    a.append([s,int(p),i+1])
tmp = sorted(a,key=lambda a: a[1], reverse=True)
a = sorted(tmp, key=lambda a: a[0])
for i in a:
    print(i[2])

Measured memory_bytes: 38512
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

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

    if (n <= 2) {
        cout << 1 << endl;
        return 0;
    }

    int cnt = 0;
    int flag = 0;
    rep(i, 1, n) {
        if (a[i] > a[i - 1]) {
            if (flag == 0)
                flag = 1;
            else if (flag == -1) {
                cnt++;
                flag = 0;
            }
        }
        else if (a[i] < a[i - 1]) {
            if (flag == 0) {
                flag = -1;
            }
            else if (flag == 1) {
                cnt++;
                flag = 0;
            }
        }
    }
    cnt++;
    cout << cnt << endl;
    return 0;
}

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

int main(void){
    int n, a[10010], s = 0;
    while(1) {
        cin >> n;
        if (n == 0) break;
        s = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            s += a[i];
        }
        
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] * n <= s) ans++;
        }
        
        cout << ans << endl;
    }
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

int num_coin(int k, int s) {
  for (int i = 1; i <= 32; i++) {
    s *= 2;
    if (s >= k) return i;
  }
  return -1;
}

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

  ll n, k; cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i < k) {
      ans += (1/double(n)) * (1/double(1 << num_coin(k, i)));
    } else {
      ans += (1/double(n));
    }
  }

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

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] a = new int[n];
    for(int i=0;i<n;i++)a[i]=sc.nextInt();
    int[] dp = new int[k+1];
    for(int i=1;i<=k;i++){
      for(int j=0;j<n;j++){
        if(i>=a[j]&&dp[i-a[j]]==0){
          dp[i]=1;
          break;
        }
      }
    }
    System.out.println((dp[k]==1)?"First":"Second");
  }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] values = new int[w];
        for (int i = 0; i < values.length; i++) {
            values[i] = i + 1;
        }
        for (int i = 0; i < n; i++) {
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            int swap = values[a];
            values[a] = values[b];
            values[b] = swap;
        }
        for(int i=0; i<w; ++i){
            System.out.println(values[i]);
        }
    }
}

Measured memory_bytes: 26220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define f first
#define s second
#define pb push_back
#define mp make_pair 
using namespace std;
typedef unsigned long ul;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vii;
typedef vector<vector<int>> Graph;
typedef pair<int, int> pi;
const ll INF = 1LL << 60;
const unsigned int MOD = 1000000007;
const int dx4[4] = { 1, 0, -1, 0 };
const int dy4[4] = { 0, 1, 0, -1 };
const int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
const int dy8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; 

bool is_prime(int n) { for (int i = 2; i*i <= n; ++i) { if (n % i == 0) return false; } return true; }
long long mod(long long val, long long m) { long long res = val % m; if (res < 0) res += m; return res; }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }

void dfs() {
}

int H, W;
int dp[1450][1450];
int grid[1450][1450];

int main() {
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> grid[i][j];
    rep(i, H) if(grid[i][0] != 1) dp[i][0] = 1;
    rep(i, W) if(grid[0][i] != 1) dp[0][i] = 1;
    
    int ans = 0;
    for(int i = 1; i < H; ++i) {
        for(int j = 1; j < W; ++j) {
            if(grid[i][j] == 1) continue;
            int tmp = min(dp[i-1][j-1], min(dp[i][j-1], dp[i-1][j]));
            dp[i][j] = tmp + 1;
            chmax(ans, dp[i][j]);
        }
    }
    int lastC = 0;
    rep(i, W) chmax(lastC, dp[H-1][i]);
    chmax(ans, lastC); 
    cout << ans * ans << endl;
    
}


Measured memory_bytes: 16692
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  
  int cnt=0;
  rep(i,n){
    if(i%2==0 && A[i]%2==1) cnt++;
  }
  
  cout<<cnt<<endl;
 
  return 0;
}

Measured memory_bytes: 3624
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
long long modMult(long long a, long long b, long long m) {
  long long res = 0;
  long long exp = a % m;
  while (b) {
    if (b & 1) {
      res += exp;
      if (res > m) res -= m;
    }
    exp <<= 1;
    if (exp > m) exp -= m;
    b >>= 1;
  }
  return res;
}
long long powMod(long long a, long long b, long long m) {
  long long res = 1;
  long long exp = a % m;
  while (b) {
    if (b & 1) res = modMult(res, exp, m);
    exp = modMult(exp, exp, m);
    b >>= 1;
  }
  return res;
}
//powMod(a,b,MOD)
//O(log(b))?
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s;
    cin>>s;
    vector<int> vec(2019);
    ll now=0;
    reverse(all(s));
    rep(i,s.size()){
        now+=powMod(10,i,2019)*(s[i]-'0');
        now%=2019;
        ///cout<<now<<endl;
        vec[now]++;
    }
    ll res=0;
    vec[0]++;
    for(auto i:vec){
        if(i>=2){
            res+=(i-1)*i/2;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
template<class T,class U>void cinpb(T &v, U n) { rep(i, n){cill(a);v.pb(a);} }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(n);
    string ans = "No";
    rep1(i, 9){
        rep1(j, 9){
            if (i * j == n){
                ans = "Yes";
            }
        }
    }
    
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define MOD 1000000007
using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll p[n];
    for(ll i=0;i<n;i++)
        p[i]=0;
    p[n-1]=a[n-1];
    for(ll i=n-2;i>0;i--)
    {
        p[i]=p[i+1]+a[i];
    }
    ll sum=0;
    for(ll i=0;i<n-1;i++)
    {
       sum+=((a[i]%MOD)*(p[i+1]%MOD))%MOD;
    }
    cout<<sum%MOD<<"\n";
}


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


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            String s = Console.ReadLine();
            String[] arr = s.Split(' ');
            int a = int.Parse(arr[0]);
            int b = int.Parse(arr[1]);

            int intArea = a * b;

            int intLength = (a + b) * 2;

            Console.WriteLine(intArea + " " + intLength);
        }
    }
}


Measured memory_bytes: 17900
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll l=in(),r=in(),d=in();
    ll ans=0;
    for(ll i=l;i<=r;++i)if(i%d==0)++ans;
    cout<<ans<<endl;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
struct edge{
	int to;
	double dist;
	int conf;
};
typedef pair<double,int> P;
double d[30*30*31],ans,inf=1e9;
vector<edge> G[31];
int s,g;
void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,30*30*31) d[i]=inf;
	d[s]=0;
	ans=inf;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int ii=p.sc/900,jj=p.sc%900/30,kk=p.sc%30+1;
		if(p.fs>d[p.sc]) continue;
		int v=G[ii][jj].to;
		if(v==g && kk==1) ans=min(ans,p.fs);
		rep(i,G[v].size()){
			edge e=G[v][i];
			if(e.to==ii) continue;
			for(int j=-1;j<=1;j++){
				if(ii==30 & kk+j!=1) continue;
				if(1<=kk+j && kk+j<=e.conf){
					int nx=900*v+30*i+(kk+j-1);
					if(d[nx]>d[p.sc]+e.dist/(kk+j)){
						double aa=d[p.sc],bb=e.dist,cc=kk+j;
//						cout << d[p.sc] << " " << e.dist/(kk+j) << endl;
//						cout << aa << " " << bb << " " << cc << " " << aa+bb/cc << endl;
						d[nx]=aa+bb/cc;
//						printf("%lf\n",aa+bb/cc);
//						printf("(from=%d , to=%d , speed=%d)    d=%lf\n",v,G[v][i].to,kk+j,d[nx]);
						que.push(P(d[nx],nx));
					}
				}
			}
		}
	}
}
int main(){
	while(true){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==0) break;
		scanf("%d%d",&s,&g);
		s--,g--;
		rep(i,31) G[i].clear();
		rep(i,m){
			int x,y,c;
			double dd;
			scanf("%d%d%lf%d",&x,&y,&dd,&c);
			x--,y--;
			G[x].push_back({y,dd,c});
			G[y].push_back({x,dd,c});
		}
		G[30].push_back({s,0,1});
		dijkstra(30*900);
/*		rep(i,n){
			rep(j,G[i].size()){
				rep(k,G[i][j].conf){
					printf("(from=%d , to=%d , speed=%d)    d=%lf\n",i,G[i][j].to,k+1,d[i*900+j*30+k]);
				}
			}
		}*/
		if(ans==inf) printf("unreachable\n");
		else printf("%.6f\n",ans);
	}
}

Measured memory_bytes: 1864
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a-1);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
const int INF = 1e18;
const int MOD = 1e9+7;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<string> vstr;
void print() {cout<<'\n';}template<class Head,class...Tail>void print(Head&&head,Tail&&...tail){cout<<head;if(sizeof...(tail)!=0)cout<<" ";print(forward<Tail>(tail)...);}template<class T>void print(vector<T>&vec){for(auto&a:vec){cout<<a;if(&a!=&vec.back())cout<<" ";}cout<<'\n';}template<class T>void print(vector<vector<T>>&df){for(auto&vec:df){print(vec);}}
template<class T=int>T in() {T x;cin>>x;return(x);}
template<class T=int>vector<T> input_to_vector(int n) {vector<T>x;rep(i,n){T a;cin>>a;x.push_back(a);}return(x);}

signed main(){
     int n, i;
     cin >> n >> i;
     print(n - i + 1);
}


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

vector<int> card;

int main(void){
  int N, Q, c, q;
  cin >> N >> Q;
  for(int i = 0; i < N; i++){
    cin >> c;
    card.push_back(c);
  }
  sort(card.begin(), card.end());
  int me = card[N - 1];
  for(int i = 0; i < Q; i++){
    cin >> q;
    int M = -1;
    int u = int(1.0 * me / q + 0.9);
    for(int i = 1; i <= u; i++){
      vector<int>::iterator it = lower_bound(card.begin(), card.end(), q * i);
      if(it != card.begin()) M = max(M, *(it - 1) % q);
    }
    cout << M << endl;
  }
  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (a <= 9 && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  double a=0;
  double p[n];
  for(int i=0;i<n;i++){
    cin >> a;
    p[i] = (1+a)/2;
  }

  double s[n];
  s[0]=p[0];
  for(int j=1;j<n;j++){
    s[j] = p[j] + s[j-1];
  }
  double max=s[k-1];
  for(int i=k+1;i<n;i++){
    if(max < s[i]-s[i-k])
      max = s[i]-s[i-k];
  }
  cout <<fixed << setprecision(12) <<max;
  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

struct Edge{
  int to,cost;
  bool operator < (const Edge& e)const{
    return cost > e.cost;
  }
};

const int IINF = INT_MAX;

int V,E;
vector<Edge> G[10100];
int mincost[10100];
bool used[10100];

int main(){
  cin >> V >> E;
  rep(i,E){
    int s,t,w;
    cin >> s >> t >> w;
    G[s].push_back((Edge){t,w});
    G[t].push_back((Edge){s,w});
  }

  rep(i,V) mincost[i] = IINF, used[i] = false;
  mincost[0] = 0;

  priority_queue<Edge> Q;
  Q.push((Edge){0,0});
  int ans = 0;
  while(!Q.empty()){
    Edge e = Q.top(); Q.pop();
    if( used[e.to] ) continue;
    used[e.to] = true;
    ans += mincost[e.to];
    int cur = e.to;
    rep(i,G[cur].size()){
      int next = G[cur][i].to;
      if( used[next] ) continue;
      if( mincost[next] > G[cur][i].cost ){
        mincost[next] = G[cur][i].cost;
        Q.push((Edge){next,G[cur][i].cost});
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4428
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(3); cin >> a[0] >> a[1] >> a[2];
    int c = 0;
    while(1){
        sort(a.begin(),a.end());
        c++;
        if(a[0] != a[1] && a[1] != a[2]){
            a[0]++; a[1]++;
        }else if(a[0] != a[1] && a[1] == a[2]){
            a[0] += 2;
        }else if(a[0] == a[1] && a[1] != a[2]){
            a[0]++; a[1]++;
        }else if(a[0] == a[1] && a[1] == a[2]){
            c--;
            break;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
A = prime_factorize(N)

if N ==1:
    print(0)
    exit()

cnt = 0
B = []
a,b = 0,0
for i in range(10**3):
    a += 1
    b += a
    B.append(b)

ls = collections.Counter(A)

for k in ls.values():
    i = 0
    while k >= B[i]:
        i +=1
    cnt += i
print(cnt)

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

int main() {
  int N;
  cin >> N;
  int a[N-1], b[N-1], c[N-1];
  for(int i=0; i<N; i++)
    cin >> a[i] >> b[i] >> c[i];
  int A[N-1], B[N-1], C[N-1];
  A[0] = a[0];
  B[0] = b[0];
  C[0] = c[0];
  for(int i=1; i<N; i++) {
    A[i] = a[i] + max(B[i-1],C[i-1]);
    B[i] = b[i] + max(C[i-1],A[i-1]);
    C[i] = c[i] + max(A[i-1],B[i-1]);
  }
  cout << max({A[N-1], B[N-1], C[N-1]}) << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
const ll MOD = 1E9+7;
const int INF = 1E9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

const int N=777;
int n,m,b,w;
int col[N];
bool adj[N][N],dp[N][N];
vector<int> rev[N];
vector<pair<int,int>> c;

bool dfs(int u){
	bool ok=true;
	if(!col[u]) b++;
	else w++;
	FOR(v,1,n) if(v!=u&&!adj[u][v]){
		if(col[v]==-1){
			col[v]=col[u]^1;
			ok&=dfs(v);
		} else if(col[v]!=-1) ok&=col[v]!=col[u];
	}
	return ok;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	REP(i,m){
		int u,v;
		cin>>u>>v;
		adj[u][v]=adj[v][u]=true;
	}
	memset(col,-1,sizeof col);
	dp[0][0]=true;
	int token=0;
	FOR(u,1,n)
		if(col[u]==-1){
			col[u]=0;
			w=b=0;
			bool ok=dfs(u);
			if(!ok) exit(puts("-1\n")*0);
			memset(dp[token^1],false,sizeof dp[token^1]);
			FOR(i,0,n) 
				if(dp[token][i])
					dp[token^1][i+b]=dp[token^1][i+w]=true;
			token^=1;
		}
	int res=INF;
	FOR(i,0,n/2)
		if(dp[token][i])
			res=min(res,i*(i-1)/2+(n-i)*(n-i-1)/2);
	cout<<res<<'\n';
}



Measured memory_bytes: 4164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int count = 0;
			boolean flag = false;
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt();
				if (a > 0)
					count++;
				if (a > 1)
					flag = true;
			}
			System.out.println(flag ? count + 1 : "NA");
		}
	}
}

Measured memory_bytes: 158440
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
int main() {
  int n;cin>>n;
  int k;cin>>k;
  vector<int> stones(n,0);
  vector<int> dp(1,0);
  for(int& i:stones)cin>>i;
  for(int i=1;i<n;i++) {
  	int minVal=INT_MAX;
    for(int j=1;j<=min(k,i);j++) {
    	int tmp=dp[i-j]+abs(stones[i]-stones[i-j]);
      	minVal=tmp<minVal?tmp:minVal;
    }
    dp.push_back(minVal);
  }
  //for(int &i:dp)cout<<i<<" ";
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1276
fun main() {
    val n = readLine()!!.toInt()

    fun sieve(n: Int): List<Int> {
        val xs = BooleanArray(n + 1) { true }
        var i = 2
        while (i * i <= n) {
            if (xs[i]) {
                for (j in i + i..n step i) {
                    xs[j] = false
                }
            }
            i++
        }
        return (2..n).filter { xs[it] }
    }

    val primes = sieve(55555)
    println(primes.filter { it % 5 == 1 }.take(n).joinToString(" "))
}


Measured memory_bytes: 38568
import bisect
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=[i for i in primes if (i+1)//2 in primes]
q=int(input())
for i in range(q):
    a,b=map(int, input().split())
    print(bisect.bisect_right(primes, b)-bisect.bisect_left(primes, a))

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	#ifdef LOCAL
	((std::cout << args << " "), ...);
	cout << endl;
	#endif
}
 */
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e5 + 5;
const int INF = 2e9;


int main() {
	//usaco("milkvisits");

#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
#endif

	ll n;
	cin >> n;

	if(n & 1){
		finish(0);
	}

	n /= 2;

	ll p = 5;
	ll ans = 0;
	for(; n >= p; p *= 5){
		ans += (n / p);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int h, w, c[10][10], a[200][200];
int ta[10][10];
int ans;

signed main() {
	cin >> h >> w;
	rep(i, 10) {
		rep(j, 10) {
			cin >> c[i][j];
			ta[i][j] = c[i][j];
		}
	}
	rep(i, 10) {
		rep(j, 10) {
			rep(k, 10) {
				ta[j][k] = min(ta[j][k], ta[j][i] + ta[i][k]);
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			if (a[i][j] != -1)ans += ta[a[i][j]][1];
		}
	}
	cout << ans << endl;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<int> A(N + 1, 0);

  int a;
  REP(i, N - 1) {
    cin >> a;
    ++A.at(a);
  }

  REPI(i, 1, N + 1) { cout << A.at(i) << endl; }
  return 0;
}


Measured memory_bytes: 3988
# -*- coding: utf-8 -*-
###########　入力
# 整数の入力
S,T = input().split()
A,B = map(int, input().split())
U = input()

if U==S:
    A = A-1
elif U==T:
    B = B-1

###########　出力
print("{} {}".format(A, B))

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

int main(){
    int n, m, s=0;
    cin>>n>>m;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        s+=a[i];
    }
    int c=0;
    for(int i=0; i<n; i++){
        if(a[i]*4*m >= s ) c++;
    }
    cout<<( c>=m  ? "Yes": "No" );
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

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

    string s;
    cin >> s;

    string t = "KIHBR";
    int ti = 0, a = 0;

    rep((int)s.length()){
        if(s[i] == 'A'){
            if(a == 0 && ti != 2) a++;
            else{
                cout << "NO";
                return 0;
            }
            if(ti == 1){
                cout << "NO";
                return 0;
            }
        }else{
            a = 0;
            if(ti < 5 && s[i] == t[ti]) ti++;
            else{
                cout << "NO";
                return 0;
            }
        }
    }
    if(ti == 5) cout << "YES";
    else cout << "NO";
    return 0;


    return 0;
}

Measured memory_bytes: 256