akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
ll T,n,m;
int a[maxn];
int main() {
	int k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int cnt = 0;
	for(int i=0;i<n;i++)
		if(a[i]>=k)
			cnt++;
	cout<<cnt<<endl;
    return 0;
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, k;
	cin >> n >> k;

	vector<ll> p(n + 2, 0);

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

	ll val = 0;
	for(int i = 0; i < k; ++i)
	{
		val += p[i];
	}

	ll ans = val;
 	for(int i = 0; i < n - k; ++i)
	{
		val = val - p[i] + p[i + k];
		ans = max(ans, val);
		// cout << i << " " << ans << endl;
	}

	printf("%.7lf\n", (double)(k + ans) / 2.0);
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 1792
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

ll f[2000010];

ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
ll binpow(ll a, ll b) {
     ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
 
ll find_ncr(ll n, ll r)
{
    ll m1=max(r,n-r);
    ll i,j,s,d=1,k;
    s=1;
 
    for(i=m1+1;i<=n;i++)
    {
        s=((s%m)*(i%m))%m;
    }
 
    m1=min(r,n-r);
 
    for(i=1;i<=m1;i++)
    {
        k=binpow(i,m-2);
        d=((d%m)*(k%m))%m;
    }
 
    k=(s%m*(d%m))%m;
 
    return k;
}

int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s;
  cin >> s;
  if(s == "ABC")
    cout << "ARC";
  else
    cout << "ABC";
  return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    long x;
    cin >> x;
    queue<long>q;
    q.push(0);
    bool chk=false;
    vector<bool>chkk(100001,false);
    while(!q.empty()){
        long tmp = q.front();
        q.pop();
        if(tmp == x){
            chk=true;
            break;
        }else if(tmp > x){
            continue;
        }else if(chkk[tmp]){
            continue;
        }else{
            chkk[tmp]=true;
        }
        for(int i=100;i<=105;i++){
            q.push(tmp+i);
        }
    }
    if(chk)cout<<1<<endl;
    else cout<<0<<endl;
}

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

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

    bool CheckPalindrome[3] = {true,true,true};
    int N = S.length();
    for(int i=0;i<=floor(N/2);i++){
        //check 1
        if(S[i] == S[N-i-1]){
            continue;
        }else{
            CheckPalindrome[0] = false;
            break;
        }
    }
    for(int r=0;r<=floor((N-1)/4);r++){
        //check2
        if(S[r] == S[(N-1)/2 -r -1]){
            continue;
        }else{
            CheckPalindrome[1] = false;
            break;
        }
    }
    int ka = (N+3)/2;//初期値設定
    for(int k=ka;k<=((N+3)/2+N)/2;k++){
        if(S[k-1] == S[N-(k-ka)-1]){
            continue;
        }else{
            CheckPalindrome[2] = false;
            break;
        }
    }
    

    if(CheckPalindrome[0]==true&&CheckPalindrome[1]==true&&CheckPalindrome[2]==true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
int c[MC];

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		int a;
		scanf("%d" , &a);
		++c[a];
		++c[a+1];
		++c[a+2];
	}
	int ans = 0;
	repp(i,0,MC){
		ans = max(ans , c[i]);
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int mod=998244353,N=3005;
int n,m,ans,f[N];



signed main(){
	read(n);read(m);
	for(int i=1,x;i<=n;i++){
		read(x);
		for(int j=m;j>x;j--) f[j]=(f[j]+f[j-x])%mod;
		f[x]=(f[x]+i)%mod;
		ans=(ans+f[m]*(n-i+1))%mod;
		f[m]=0;
	}
	write(ans);
}

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

struct Prime {
    int max_n;
    std::vector<int> primes;
    std::vector<bool> isp;

    explicit Prime(int max_n)
        : max_n(max_n), isp(max_n + 1, true) {
        isp[0] = isp[1] = false;
        for (int i = 2; i * i <= max_n; ++i) {
            if (isp[i]) {
                for (int j = i; i * j <= max_n; ++j) {
                    isp[i * j] = false;
                }
            }
        }

        for (int p = 2; p <= max_n; ++p) {
            if (isp[p]) primes.push_back(p);
        }
    }

    template <class T>
    bool isprime(T n) const {
        if (n <= max_n) return isp[n];
        for (T p : primes) {
            if (p * p > n) break;
            if (n % p == 0) return false;
        }
        return true;
    }

    template <class T>
    std::vector<std::pair<T, int>> factorize(T n) const {
        std::vector<std::pair<T, int>> facts;
        for (T p : primes) {
            if (p * p > n) break;
            if (n % p != 0) continue;
            int exp = 0;
            while (n % p == 0) {
                n /= p;
                ++exp;
            }
            facts.emplace_back(p, exp);
        }
        if (n > 1) {
            facts.emplace_back(n, 1);
        }
        return facts;
    }
};


const Prime P(100000);

int main() {
    int n;
    std::cin >> n;
    std::cout << n << ":";

    auto facts = P.factorize(n);
    for (auto p : facts) {
        while (p.second--) {
            std::cout << " " << p.first;
        }
    }
    std::cout << std::endl;
}



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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, pv, run;

int main(){
	scanf("%d", &n);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		if(x == pv){
			run++;
		}else{
			ans += run / 2;
			pv = x;
			run = 1;
		}
	}
	printf("%d\n", ans + run / 2);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int sum;
  int C[N-1],S[N-1],F[N-1];
  
  for(int i=0;i<N-1;i++){
  cin >> C[i] >> S[i] >> F[i];  
}
  for(int i=0;i<N;i++){ 
      sum = 0;
    
    for(int j=i;j<N-1;j++){
          
            
          if(sum < S[j]){
           sum = S[j];
          }else if(sum%F[j]!=0){
           sum=sum+F[j]-sum%F[j]; 
          }
         sum += C[j];
    }  
    cout << sum << endl;
  }
  
return 0;
}

Measured memory_bytes: 256
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

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

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;

const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;

const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/

intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

intt gcd (intt a, intt b) {
    while (b > 0) {
        intt t = a % b;
        a = b, b = t;
    }
    return a;
}

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

intt is_prime (intt n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/**************************/

const intt initt = (1 << 31) - 1;

intt n, q;
intt t[maxx << 2], lazy[maxx << 2];

void init () {
    memset (lazy, -1, sizeof (lazy));
}

void relax (intt v, intt l, intt r) {
    t[v] = (r - l + 1) * lazy[v];
    if (l != r)
        lazy[v << 1] = lazy[v << 1 | 1] = lazy[v];
    lazy[v] = -1;
}

void build (intt v, intt l, intt r) {
    if (l == r) {
        t[v] = initt;
        return;
    }
    intt mid = (l + r) >> 1;
    build (v << 1, l, mid);
    build (v << 1 | 1, mid + 1, r);
    t[v] = t[v << 1] + t[v << 1 | 1];
}

void update (intt v, intt l, intt r, intt i, intt j, intt val) {
    if (lazy[v] != -1)
        relax (v, l, r);
    if (j < l || i > r)
        return;
    if (i <= l && r <= j) {
        lazy[v] = val;
        relax (v, l, r);
        return;
    }
    intt mid = (l + r) >> 1;
    update (v << 1, l, mid, i, j, val);
    update (v << 1 | 1, mid + 1, r, i, j, val);
    t[v] = t[v << 1] + t[v << 1 | 1];
}

intt query (intt v, intt l, intt r, intt i, intt j) {
    if (j < l || i > r)
        return 0;
    if (lazy[v] != -1)
        relax (v, l, r);
    if (i <= l && r <= j)
        return t[v];
    intt mid = (l + r) >> 1;
    return query (v << 1, l, mid, i, j) +
           query (v << 1 | 1, mid + 1, r, i, j);
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    init();
    cin >> n >> q;
    build (1, 1, n);
    while (q --) {
        intt type, i, j, val;
        cin >> type;
        if (type == 0)
            cin >> i >> j >> val, i ++, j ++, update (1, 1, n, i, j, val);
        else
            cin >> i, i ++, cout << query (1, 1, n, i, i) << endl;
    }
    return 0;
}

Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n;  cin >> n;
    vector<ll> a(n+1);
    ll res=1, aSum=0;
    REP(i, n+1){
        cin >> a[i];    aSum += a[i];
    }
    
    if(0<n && a[0]) res = -1;
    if(!n && 1<a[0]) res = -1;
    if(0<res){
        ll cur=1;
        FOR(i, 1, n+1){
            aSum -= a[i-1];
            cur = 2*(cur-a[i-1]);
            if(cur<a[i]){
                cout << -1 << endl;
                return 0;
            }
            //cout << aSum << ' ' << ub << ' ';
            cur = min(aSum, cur);
            res += cur;
            
            //cout << b[i] << ' ' << res << endl;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 4028
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

double get_d(int a, int b, int c)
{
  int num[3];
  num[0] = a;
  num[1] = b;
  num[2] = c;
  sort(num, num + 3);
  return sqrt(pow(num[0], 2) + pow(num[1], 2));
}

int main()
{
  while(true)
  {
    int a, b, c, n;
    double d;
    cin >> a >> b >> c;
    if(!a && !b && !c)
      break;
    cin >> n;
    d = get_d(a, b, c);
    for(int i = 0; i < n; i++)
    {
      int r;
      cin >> r;
      cout << (r * 2 > d ? "OK" : "NA") << endl;
    }
  }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

typedef vector<vector<ll>> mat;

mat mul(mat &A, mat&B){
    mat C(A.size(),vector<ll>(B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int k=0;k<B.size();k++){
            for(int j=0;j<B[0].size();j++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
            }
        }
    }
    return C;
}

mat pow(mat A,ll n){
    mat B(A.size(),vector<ll>(A.size()));
    for(int i=0;i<A.size();i++){
        B[i][i]=1;
    }
    
    while(n>0){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n/=2;
    }
    return B;
}



int main(){
    
    int N;
    ll K;
    cin>>N>>K;
    mat A(N,vector<ll>(N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>A[i][j];
        }
    }
    
    mat D(N,vector<ll>(N));
    D=pow(A,K);
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ans+=D[i][j];
            ans=ans%mod;
        }
    }
    
    cout<<ans<<endl;
    
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  int a,b,c; cin >> a >> b >> c;
  cout << min(a+b,min(b+c,a+c)) << endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

int bld[4][3][10]={};

void solve()
{
	int n; cin >> n;
	rep(i, n)
	{
		int b,f,n,v; cin >> b >> f >> n >> v;
		b--;f--;n--;
		bld[b][f][n] += v;
	}
	rep(i, 4)
	{
		rep(j, 3)rep(k, 10)
		{
			cout<<" "<< bld[i][j][k];
			if(k==9)cout << endl;
		}
		if(i!=3)cout << string(20,'#') << endl;
	}
	return;
}

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



Measured memory_bytes: 3172
#違うアルゴリズム
#これはO(n)で終わる。素晴らしい。
n = int(input())
s = input()

#求める長さ
ans = 0

#iは、区切りのindex。すなわち、検索文字列の末尾index。
for i in range(n):
    if n<i+ans:
        break
    
    if s[i+1:].find(s[i-ans:i+1]) != -1:
        ans += 1
        
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll mergecount(vector<int> &a) {
    ll count = 0;
    int n = a.size();
    if (n > 1) {
        vector<int> b(a.begin(), a.begin() + n/2);
        vector<int> c(a.begin() + n/2, a.end());
        count += mergecount(b);
        count += mergecount(c);
        for (int i = 0, j = 0, k = 0; i < n; ++i)
        if (k == c.size())       a[i] = b[j++];
        else if (j == b.size())  a[i] = c[k++];
        else if (b[j] <= c[k])   a[i] = b[j++];
        else                   { a[i] = c[k++]; count += n/2 - j; }
    }
    return count;
}

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

    int a[n];
    rep(i,n)cin >> a[i];
    int b[n];
    rep(i,n)cin >> b[i];

    int ans = 1001001001;

    rep(i,(1<<n)){
        int ii = i;
        int f[n] = {};
        int pp = 0;
        rep(j,n){
            f[j] = ii % 2;
            ii /= 2;
            pp += f[j];
        }
        if(pp != n / 2)continue;

        vector<P> u, v;
        rep(j,n){
            if(f[j] == 0){
                if(j % 2 == 0){
                    u.push_back(P(a[j], j));
                }else{
                    u.push_back(P(b[j], j));
                }
            }else{
                if(j % 2 == 0){
                    v.push_back(P(b[j], j));
                }else{
                    v.push_back(P(a[j], j));
                }
            }
        }
        sort(u.begin(), u.end());
        sort(v.begin(), v.end());

        // cout << i << endl;
        // cout << u[0].first << ' ' << u[0].second << endl;

        int flag = 1;
        int tmp = 0;
        int now = -1;

        vector<int> x;

        rep(j,n){
            if(j % 2 == 0){
                if(u[j/2].first < now){
                    flag = 0;
                    break;
                }
                now = u[j/2].first;
                tmp += abs(u[j/2].second - j);
                x.push_back(u[j/2].second);
            }else{
                if(v[j/2].first < now){
                    flag = 0;
                    break;
                }
                now = v[j/2].first;
                tmp += abs(v[j/2].second - j);
                x.push_back(v[j/2].second);
            }
        }

        // cout << i << ' ' << tmp << ' ' << flag << endl;

        if(flag){
            tmp = mergecount(x);
            ans = min(ans, tmp);
        }
    }

    if(ans == 1001001001)ans = -1;
    // else ans /= 2;
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 384
import numpy as np

N,W = map(int,input().split())
w,v = [0]*N ,[0]*N
arr = [map(int,input().split()) for _ in range(N)]
dp = np.zeros(W+1,dtype= np.int64)

for w,v in arr:
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])
print(dp[-1])


Measured memory_bytes: 14600
#include <bits/stdc++.h>
#define MAX 10000007
#define INF 1000000000000000000
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int cnt[50];
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n,m, t;
    cin>>n>>m;

    t=n;

    int k,type;

    while(n--)
    {
        cin>>k;

        while(k--)
        {
            cin>>type;
            cnt[type]++;
        }
    }

    int c=0;

    for(int i=1;i<=m;i++)
    {
        if(cnt[i]==t)
            c++;
    }

    cout<<c<<endl;

    return 0;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = ((li)(start)); i < ((li)(to)); i++)
typedef pair<li, li> PI;


li num_v = 1;

int main(void)
{
	li l;
	cin >> l;
	li beki = 1;
	while (beki <= l) {
		beki *= 2;
		num_v++;
	}
	beki /= 2;
	num_v--;
	li diff = l - beki;

	vector<vector<PI>> edge(num_v);
	li now_rest = beki;
	repp(i, 1, num_v) {
		edge[i].push_back({i - 1, 0});
		edge[i].push_back({i - 1, 1ll << (i - 1)});
		if ((diff & (1ll << (i - 1))) > 0) {
			edge[num_v - 1].push_back({i - 1, now_rest});
			now_rest += (1ll << (i - 1));
		}
	}
	li num_e = 0;
	rep(i, num_v) {
		num_e += edge[i].size();
	}
	cout << num_v << " " << num_e << endl;

	rep(i, num_v) {
		for (auto& item : edge[i]) {
			cout << num_v - i << " " << num_v - item.first << " " << item.second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int ans=0;
	for(int i=1;i<=5;++i)
	{
		int d;
		cin>>d;
		if(d==0)
			ans=i;
	}
	cout<<ans;
	#ifdef ANIKET_GOYAL
		// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int n;
  while (cin >> n) {
    string s[n];
    for (int i : range(n)) cin >> s[i];
    int ret1=0, a=0, b=0, ba=0;
    for (int i : range(n)) {
      int k = (int)s[i].size();
      for (int j : range(k - 1)) {
        if (s[i][j] == 'A' && s[i][j+1] == 'B') ret1++;
      }
      if (s[i][0] == 'B' && s[i][k-1] == 'A') ba++;
      else {
        if (s[i][k-1] == 'A') a++;
        if (s[i][0] == 'B') b++;
      }
    }
    int ret = 0;
    if (a == 0 && b == 0) ba = max(ba - 1, 0);
    ret = max(ret, ret1 + min(a, b) + ba);

    cout << ret << endl;
  }
}


Measured memory_bytes: 768
N=int(input())
T=[]
I=[]

for i in range(N):
  s=int(input())
  if s%10==0:
    T.append(s)
  else:
    I.append(s)

I.sort()

if len(I)==0:
  print(0)
elif sum(I)%10==0:
  print(sum(T)+sum(I)-I[0])
else:
  print(sum(T)+sum(I))

Measured memory_bytes: 3064
N, M = map(int, input().split())
K = []
for i in range(N):
    K.append(list(map(int, input().split())))

count1 = 0
for i in range(M+1):
    count2 = 0
    for j in range(N):
        if i in K[j][1:M+1]:
            count2 += 1
    if count2 == N:
        count1 += 1
print(count1)

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

int main() {
	int a, b;
	int k;
	cin >> a >> b;

	k = (a + b) / 2;

	if (a==b){
		cout << 0;
	}
	else if ((a+b)%2==0) {

		cout << k;
	}
	else {
		cout << "IMPOSSIBLE";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll calcNumOfCombination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll calcNumOfPermutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

int main() {
  ll n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  }
  ll nc, mc;
  if ((n + m) % 2 == 0) {
    nc = calcNumOfPermutation(n, n) % mod;
    mc = calcNumOfPermutation(m, m) % mod;
    cout << 2 * (nc * mc) % mod << endl;
  } else {
    nc = calcNumOfPermutation(n, n) % mod;
    mc = calcNumOfPermutation(m, m) % mod;
    cout << nc * mc % mod << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,ans=0,r[4005]={},g[4005]={},b[4005]={},cnt=0;
  string s;
  cin >> n >> s;
  for(ll i=0; i<s.size(); i++) {
    if(s[i]=='R') {
      r[i+1]++;
    }
    else if(s[i]=='G') {
      g[i+1]++;
    }
    else {
      b[i+1]++;
    }
  }
  for(ll i=1; i<=s.size(); i++) {
    r[i]+=r[i-1];
    g[i]+=g[i-1];
    b[i]+=b[i-1];
  }
  for(ll i=0; i<s.size(); i++) {
    if(s[i]=='R') {
      cnt=0;
      for(ll j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='G'&&s[i+j]=='B') {
          cnt++;
        }
      }
      ans+=g[i]*(b[s.size()]-b[i])-cnt;
      cnt=0;
      for(ll j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='B'&&s[i+j]=='G') {
          cnt++;
        }
      }
      ans+=b[i]*(g[s.size()]-g[i])-cnt;
    }
    else if(s[i]=='G') {
      cnt=0;
      for(ll j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='R'&&s[i+j]=='B') {
          cnt++;
        }
      }
      ans+=r[i]*(b[s.size()]-b[i])-cnt;
      cnt=0;
      for(ll j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='B'&&s[i+j]=='R') {
          cnt++;
        }
      }
      ans+=b[i]*(r[s.size()]-r[i])-cnt;
    }
    else {
      cnt=0;
      for(ll j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='R'&&s[i+j]=='G') {
          cnt++;
        }
      }
      ans+=r[i]*(g[s.size()]-g[i])-cnt;
      cnt=0;
      for(ll j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='G'&&s[i+j]=='R') {
          cnt++;
        }
      }
      ans+=g[i]*(r[s.size()]-r[i])-cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3756
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  ll ans=0;
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b; j++){
      for(int k = 0; k <= c; k++){
        if(500*i+100*j+50*k==x) ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 384
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this.stox(this._s[n]);};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

function PriorityQueue(){
    this.heap = [];
}
PriorityQueue.prototype = {
    push : function(x){
        var h = this.heap, i = h.length++, j;
        while(i){
            j = i-1 >> 1;
            if(h[j] <= x)break;
            h[i] = h[j];
            i = j;
        }
        h[i] = x;
    },
    pop : function(){
        var h = this.heap, r = h[0], x = h.pop();
        var i = 0, k = h.length >> 1, j;
        while (i < k) {
            j = (i << 1) + 1;
            if(h[j+1] < h[j])++j;
            if(x <= h[j])break;
            h[i] = h[j];
            i = j;
        }
        if(h.length)h[i] = x;
        return r;
    },
    size : function(){return this.heap.length;},
    top : function(){return this.heap[0];},
};

console.log(main());

function main() {
    var N = o.getValue(0);

    if (N === 1) {
        return "Yes";
    }

    var i = 2;
    var v = N;
    var result = [];
    while (v !== 1) {
        if (v % i === 0) {
            result.push(i);
            v = v / i;
            continue;
        }
        i++;
    }
    result.push(1);
    result.sort((a, b) => b - a);

    var pq = new PriorityQueue();
    for (var j = 0; result.length > j; j++) {
        if (result[j] > 9) {
            return "No";
        }

        if (pq.size() < 2) {
            pq.push(result[j]);
            continue;
        }

        var v    = pq.pop();
        var sum = v * result[j];
        if (sum > 9) {
            return "No";
        }

        pq.push(sum);
    }

    return "Yes"
}


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

//Compiler version g++ 6.3.0

int main()
{
    int A,B,H,M;
    
    cin >> A >> B >> H >> M;
    
    //minute
    double min = (double) M*6;
   // cout << min <<endl;
    
    //Hour earlier
    double hr1 = (double) H*30;
    double hr2 = (double)M/60;
    double hr3 = (double)hr2 * 30;
    double hr = hr1 + hr3;
   // cout << hr3 << endl;
    //due to min
    
   
  //  cout << hr << endl;
    
    //cosine formula
    double diff = abs(hr - min);
  //  cout << diff << endl;
    diff = diff * (M_PI/180);
    double ans = (double)(A*A) + (double)(B*B) - (double)2*A*B*cos(diff);
    
  // cout << A*A<<endl<<B*B<<endl<<2*A*B*cos(diff); 
    
    cout <<fixed<<setprecision(18)<<sqrt(ans);
}

Measured memory_bytes: 4156
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	sort( A.begin(), A.end() );
	vector<int> B;
	B = A;
	B.erase(unique(B.begin(),B.end()),B.end() );
	map<int,int> num;
	int size = B.size();
	for(int i=0;i<size;++i){
		num[ B[i] ] = i;
	}

	vector<int> hist(size,0);
	for(int i=0;i<N;++i){//
		hist[ num[ A[i] ] ]++;
	}

	int ans = 0;
	for(int i=0;i<size;++i){
		ans += hist[i]&1;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 6144
n, k = map(int, input().split())
matrix = [list(map(int, input().split())) for i in range(n)]
MOD = 10**9 + 7

def _mul(A, B, MOD):
    C = [[0] * len(B[0]) for i in range(len(A))]
    for i in range(len(A)):
        for k in range(len(B)):
            for j in range(len(B[0])):
                C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % MOD
    return C

def pow_matrix(A, n, MOD):
    """A**nをダブリングによって求める"""
    B = [[0] * len(A) for i in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1
    while n > 0:
        if n & 1:
            B = _mul(A, B, MOD)
        A = _mul(A, A, MOD)
        n  = n // 2
    return B 
          
ans_matrix = pow_matrix(matrix, k, MOD)
ans = 0
for i in ans_matrix:
    ans += sum(i)
    ans %= MOD
print(ans)

Measured memory_bytes: 41580
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define N 30
#define MP make_pair
#define P pair<int, int>
using namespace std;

int v[N][N];
bool f[N][N];
int w, h;

int main()
{
	int x, y;
	while (cin >> w >> h, w) {
		fill((int*)v, (int*)(v+w), 0);
		fill((bool*)f, (bool*)(f+w), 0);

		for (int i = 0; i < w; i++) {
			v[i][0] |= 0b1000;
			v[i][h-1] |= 0b0100;
		}
		for (int i = 0; i < h; i++) {
			v[0][i] |= 0b0010;
			v[w-1][i] |= 0b0001;
		}
		for (int i = 0; i < h-1; i++) {
			for (int j = 0; j < w-1; j++) {
				cin >> x;
				v[j][i] |= x;
				x <<= 1;
				v[j+1][i] |= x;
			}
			for (int j = 0; j < w; j++) {
				cin >> x;
				x <<= 2;
				v[j][i] |= x;
				x <<= 1;
				v[j][i+1] |= x;
			}
		}
		for (int j = 0; j < w-1; j++) {
			cin >> x;
			v[j][h-1] |= x;
			x <<= 1;
			v[j+1][h-1] |= x;
		}
		int res = 0;
		queue<pair<pair<int, int>, int> > q;
		q.push(MP(MP(0,0),1));
		while (!q.empty()) {
			pair<pair<int, int>, int> a = q.front();
			q.pop();
			pair<int, int> xy = a.first;
			if (f[xy.first][xy.second]) continue;
			f[xy.first][xy.second] = 1;
			if (xy.first == w - 1 && xy.second == h - 1) {
				res = a.second;
				break;
			}
			if (!(v[xy.first][xy.second] & 0b1000))
				q.push(MP(MP(xy.first,xy.second-1), a.second+1));
			if (!(v[xy.first][xy.second] & 0b0100))
				q.push(MP(MP(xy.first,xy.second+1), a.second+1));
			if (!(v[xy.first][xy.second] & 0b0010))
				q.push(MP(MP(xy.first-1,xy.second), a.second+1));
			if (!(v[xy.first][xy.second] & 0b0001)) 
				q.push(MP(MP(xy.first+1,xy.second), a.second+1));
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
// Problem : L - Deque
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_l
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws Exception {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		//PrintWriter out = new PrintWriter("file.out");
		Task solver = new Task();
		//int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		static final long inf = Long.MAX_VALUE;
		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			int n = sc.nextInt();
			long[][] dp = new long[n+4][n+4];
			long[] arr = new long[n];
			for(int i=0;i<n;i++){
				arr[i]=sc.nextInt();
			}
			for(int i = n-1; i>= 0;i--){
				for(int j = i;j < n;j++){
					if(i==j)
					{
						dp[i][j]=arr[i];
					}
					else
					{
						dp[i][j]=Math.max(arr[i]-dp[i + 1][j], arr[j] - dp[i][j - 1]);
					}
				}
			}
			pw.println(dp[0][n-1]);
		}
	}
	long binpow(long a, long b, long m) {
		a %= m;
		long res = 1;
		while (b > 0) {
			if ((b & 1) == 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	static class tup implements Comparable<tup>{
		int a, b;
		tup(int a,int b){
			this.a=a;
			this.b=b;
		}
		@Override
		public int compareTo(tup o){
			return Integer.compare(o.b,b);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}

Measured memory_bytes: 127952
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    
    int x, y;
    cin >> x >> y;
    if(y >= 4 && y % 2 == 0 && 4 * x >= y && 2 * x <= y){
        cout << "Yes";
    }
    else if(y == 2 && 4 * x > y && 2 * x <= y){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll int n;
    cin>>n;
    ll int profile[n+1][3],dp[n+1][3];
    for(int i=1;i<=n;i++)
    {
        cin>>profile[i][0]>>profile[i][1]>>profile[i][2];
    }
    dp[0][0]=0,dp[0][1]=0,dp[0][2]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=profile[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=profile[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=profile[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}


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

ll grundy = 0;
ll L;

struct Trie {
    int csize = 2;
    char bc = '0';
    bool end;
    int depth;
    vector<bool> exist_child;
    Trie *child[2];
    
    Trie(int d) {
        depth = d;
        end = false;
        exist_child.resize(csize, false);
        fill(child, child+csize, (Trie*)0);
    }
    
    void insert(string::iterator const &c, string::iterator const &e) {
        if (c == e) {
            end = true;
            return;
        }
        if (!exist_child[*c-bc]) {
            child[*c-bc] = new Trie(depth+1);
            exist_child[*c-bc] = true;
        }
        child[*c-bc]->insert(c+1, e);
        return;
    }
    
    void insert(string &s) {
        insert(s.begin(), s.end());
        return;
    }
    
    void print(string &s) {
        if (end) cout << s << endl;
        for (int i = 0; i < csize; i++) {
            if (exist_child[i]) {
                s += (char)(bc+i);
                child[i]->print(s);
            }
        }
        if (s != "") {
            s.erase(s.end()-1, s.end());
        }
        return;
    }
    
    void print() {
        string s = "";
        print(s);
        return;
    }
    
    bool find(string::iterator const &c, string::iterator const &e) {
        if (c == e) {
            return end;
        }
        if (!exist_child[*c-bc]) {
            return false;
        }
        return child[*c-bc]->find(c+1, e);
    }
    
    bool find(string s) {
        return find(s.begin(), s.end());
    }
    
    void dfs() {
        if (count(exist_child.begin(), exist_child.end(), true) == 1) {
            ll t = 1;
            while (((L-depth)&t) == 0) t <<= 1;
            grundy ^= t;
        }
        for (int i = 0; i < csize; i++) {
            if (exist_child[i]) {
                child[i]->dfs();
            }
        }
        return;
    }
};


int main() {
    ll N;
    cin >> N >> L;
    vector<string> S(N);
    Trie trie(0);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        trie.insert(S[i]);
    }
    
    trie.dfs();
    
    cout << ((grundy == 0) ? "Bob" : "Alice") << endl;

    return 0;
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n;
    cin1(n);
    cout << (n+1)/2 - 1 << endl;
}


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

int main() 
{
	int N,ai,count = 0;
  	
  	cin >> N;
  	vector<int> a(N);
  	for(int i = 0; i < N; i++)
    {
    	cin >> a[i];
    }
  	ai = a[0];
  	for(int i = 0; i < N; i++)
    {
      	count++;
      if(ai == 2)
      {
      	cout << count << endl;
        exit(0);
      } 
    	ai = a[ai - 1];
    }
  	cout << -1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

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

    int N,M;cin >> N >> M;
    //vector<pair<pair<int,int>,int>> pq;
    vector<pair<LL,LL>> world;
    for(int a = 0;a < N;a++){
        int b,c,d;cin >> b >> c >> d;
        world.push_back(make_pair(d-b,d));
        world.push_back(make_pair(d-c,d));
    }
    for(int a = 0;a < M;a++){
        int b;cin >> b;
        world.push_back(make_pair(-b,-1));
    }
    sort(world.begin(),world.end());
    set<LL> se;
    for(int a = world.size()-1;a >= 0;a--){
        pair<LL,LL> pa = world.at(a);
        if(pa.second == -1){
            if(se.empty()){
                cout<<-1<<endl;
            }else{
              cout << *se.begin() << endl;
             }
        }else{
            if(se.find(pa.second) == se.end()){
                se.insert(pa.second);
            }else{
                se.erase(pa.second);
            }
        }
    }
}


Measured memory_bytes: 21092
#include <bits/stdc++.h>
#define rep(i, n, k) for(int i=k; i<n; ++i)
using namespace std;

int main(){
  int n, ans = 0, hight = 0;
  cin >> n;
  rep(i, n, 0){
    int a;
    cin >> a;
    if(a >= hight){
      ans++;
      hight = a;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<int> sum(N+1);
    map<int, int> cnt;
    cnt[0] = 1;
    REP(i, N)
    {
        sum[i+1] = (sum[i] + A[i]) % M;
        cnt[sum[i+1]]++;
    }

    int ans = 0;
    for(auto kv :cnt) {
        int t = kv.second;
        ans += t * (t-1) / 2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760