akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll h,w,a,b,ans;
char c[600][600],d;
ll rop[600][600];
 
void mon(ll x,ll y)
{
  if(x<0||y<0||x>=h||y>=w)return;
  if(rop[x][y]==1)return;
  if(c[x][y]!=d)return;
  rop[x][y]=1;
  if((x+y)%2==1)a++;
  if((x+y)%2==0)b++;
  mon(x+1,y);
  mon(x,y-1);
  mon(x,y+1);
  mon(x-1,y); 
  return;
}
int main()
{
  cin >> h >> w;
  ans=0;
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
      rop[i][j]=INF;
    }
  }
  rep(i,h){
    rep(j,w){
      if((i+j)%2==0&&c[i][j]=='#')c[i][j]='.';
      else if((i+j)%2==0&&c[i][j]=='.')c[i][j]='#';
    }
  }
  rep(i,h){
    rep(j,w){
      a=0;
      b=0;
      d=c[i][j];
      mon(i,j);
      ans+=a*b;
    }
  }
  printf("%lld",ans);
}

Measured memory_bytes: 14848
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define inf 1e9
#define pp pop_back
#define pii pair<int,int>
#define vec vector<int>
#define mp make_pair
using namespace std;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t=1;
  //cin>>t;
  while(t--)
  {
    int n,k;
    cin>>n>>k;
    int i,h[n+1];
    for(i=1;i<=n;i++)
        cin>>h[i];
    int dp[n+1]={0};
    for(i=2;i<=n;i++)
    {
      int res=inf;
      for(int j=1;j<=min(k,i-1);j++)
            res=min(res,abs(h[i]-h[i-j])+dp[i-j]);
      dp[i]=res;
    }
    cout<<dp[n];
  }
}


Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	string S;
  	cin>>S;
  	bool is=false;
  	for(int i=1;i<S.length();i++)
    {
    	if(S[i]!=S[i-1])
        {
        	is=!is;
          break;
        }
    }
  	is?cout<<"Yes"<<endl:cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]

n_AB = sum([s.count("AB") for s in S])
n_endA = 0
n_beginB = 0
flg = True

for s in S:
    if s[0] == 'B': n_beginB += 1
    if s[-1] == 'A': n_endA += 1
    if (s[0] == 'B') ^ (s[-1] == 'A'):
        flg = False
        
n_joined =  min(n_endA, n_beginB) - flg

print(n_AB + max(0, n_joined))

Measured memory_bytes: 3700
n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[[] for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
ans=0
for i in range(n):
  f=1
  for j in l[i]:
    if h[i]<=h[j]:
      f=0
  if f:
    ans+=1
print(ans)

Measured memory_bytes: 92756
#include <bits/stdc++.h>
using namespace std;
 
 
void solve()
{
  int n;
    cin>>n;
  double dp[n+1][n+1];
  double prob[n];
    for(int i=0;i<n;i++)
        cin>>prob[i];
  
  dp[0][0]=1;
  for(int i=1;i<=n;i++)
  {
    dp[i][0]=(1-prob[i-1])*dp[i-1][0];
    dp[0][i]=0;
  }
  
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
       dp[i][j]=prob[i-1]*(dp[i-1][j-1]);
       dp[i][j]+=(1-prob[i-1])*(dp[i-1][j]);
       
    }
  double ans=0;
  for(int i=n/2+1;i<=n;i++)
    ans+=dp[n][i];
  printf("%.9f\n", ans);
 
 
 
}
 
int32_t main()
{
    
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 74048
#include <iostream>
using namespace std;
//(N-1)A+B,A+(N-1)B
int main(void)
{

    long long int n,a,b;
    cin>>n>>a>>b;
    if(n==1)
    {
        if(a==b) cout<<1<<endl;
        else cout<<0<<endl;
    }
    else if(n > 1)
    {
        if(a > b) cout<<0<<endl;
        else    cout<<(a+(n-1)*b)-((n-1)*a+b)+1<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	int a,b,c;
	cin>>a>>b>>c;
	if((b/a)>c)
		cout<<c<<endl;
	else
		cout<<b/a<<endl;
}

Measured memory_bytes: 256
<?php
$n = (int)trim(fgets(STDIN));

$x = ($n / 1.08);
$x1 = (int)floor($x);
$x2 = (int)ceil($x);

if ((int)floor($x1 * 1.08) === $n) {
	echo $x1;
}elseif ((int)floor($x2 * 1.08) === $n) {
	echo $x2;
}else{
	echo ':(';
}

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

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

int main(){
	int N,K;
	cin >> N >> K;

	vector<P> G;
	rep(i,N-1){ G.push_back(make_pair(1,i+2)); }
	int E = (N-1)*(N-2) / 2;
	if(E<K){ cout <<-1<<endl; return 0;}
	bool f=false;
	for(int i=2; i<=N; i++){
		for(int j=i+1; j<=N; j++){
			if(E==K){f=true; break;}
			G.push_back(P(i,j));
			E--;
			if(E<0){f=true; break;}
		}
		if(f)break;
	}

	if(E<0)cout << -1 << endl;
	else {
		cout << G.size() << endl;
		for(P p: G){
			cout << p.first << " " << p.second << endl;
		}
	}
}




Measured memory_bytes: 384
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    f = [int(i) for i in ipt().split()]
    a.sort()
    f.sort(reverse=True)
    l = 0
    r = 10**12
    while l < r:
        mid = l+(r-l)//2
        cst = 0
        for i in range(n):
            cst += max(0,a[i]-math.floor(mid/f[i]))
        if cst <= k:
            r = mid
        else:
            l = mid+1
    print(l)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 106056
#include <bits/stdc++.h>
#define re register
#define LL long long
#define SIZE 305 
using namespace std;
int n;
int t[SIZE];
double dp[SIZE][SIZE][SIZE];
int s1=0,s2=0,s3=0;
double ans=0;
inline double dfs(int a,int b,int c)
{
	if(dp[a][b][c]==-1)
		return 0;
	if(dp[a][b][c]!=0)
		return dp[a][b][c];
	if(a>0)
		dp[a][b][c]+=dfs(a-1,b,c)*a/(double) (a+b+c);
	if(a<s1+s2+s3 && b>0)
		dp[a][b][c]+=dfs(a+1,b-1,c)*b/(double) (a+b+c);
	if(b<s2+s3 && c>0)
		dp[a][b][c]+=dfs(a,b+1,c-1)*c/(double) (a+b+c);
	if(a || b || c)
		dp[a][b][c]+=n/(double) (a+b+c);
	return dp[a][b][c];
}
int main()
{
	cin>>n;
	for(re int i=1;i<=n;++i)
	{
		cin>>t[i];
		if(t[i]==1)	++s1;
		if(t[i]==2)	++s2;
		if(t[i]==3)	++s3;
	}
	for(re int i=0;i<=n;++i)
		for(re int j=0;j<=n;++j)
			for(re int k=0;k<=n;++k)	
				dp[i][j][k]=-1;
	for(re int i=0;i<=n;++i)
		for(re int j=0;j<=s2+s3;++j)
			for(re int k=0;k<=s3;++k)
				dp[i][j][k]=0;
	dfs(s1,s2,s3); 
	cout<<fixed<<setprecision(14)<<dp[s1][s2][s3]<<endl;
	return 0;
} 

Measured memory_bytes: 219520
import sys,queue,math,copy
LI = lambda : [int(x) for x in input().split()]

H,W,K = LI()
C = [[int(x) for x in input()] + [0] for _ in range(H)]

max_p = 0
for i in range(H):
    for j in range(W):
        c = copy.deepcopy(C)
        c[i][j] = 0
        p = 0
        for ii in range(i,0,-1):
            c[ii][j] = c[ii-1][j]
        c[0][j] = 0


        update = True
        cnt = 0
        while update:
            update = False

            for ii in range(H):
                n = c[ii][0]
                nc = n > 0
                for jj in range(1, W + 1):
                    if c[ii][jj] == n and n > 0:
                        nc += 1
                    else:
                        if nc >= K:
                            for k in range(nc):
                                c[ii][jj-k-1] = 0
                            p += nc * n * (2 **cnt)
                            update = True
                        n = c[ii][jj]
                        nc = n > 0

            for ii in range(H-1, 0, -1):
                for jj in range(W):
                    if c[ii][jj] > 0: continue
                    x = ii
                    while x > 0:
                        x -= 1
                        if c[x][jj] > 0:
                            c[ii][jj] = c[x][jj]
                            c[x][jj] = 0
                            break
            cnt += 1

        max_p = max(max_p,p)
print (max_p)


Measured memory_bytes: 61016
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;




int main() {
	int i, j, k;
	ll N, M, K;
	cin >> N;

	for (i = N;; i++) {

		int n = sqrt(i);
		for (j = 2; j <= n; j++) {
			if (i % j == 0) {
				break;
			}

		}
		if (j == n + 1) {
			cout << i;
			return 0;
		}


	}

	return 0;
}


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

int main() {
	string str ;
  	cin >> str;
  	bool match = false;
  	int ans = 0;
  	int pre = 0;
  	for(int i = 0;i < str.size();i++){
    	if(str.at(i)=='A' ||str.at(i)=='T'||str.at(i) == 'C'||str.at(i) == 'G'){
        	match = true;
          	pre++;
        }
      	else{
        	match = false;
        }
    	if(match == true && pre > ans ){
        	ans =pre;
        }
      	else if(match == false){
        	pre = 0;
        }
    	
    }
  	cout << ans <<endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MIN -1*pow(10,9)-1;
using namespace std;
int main()
{
	int t;
	while(cin>>t)
	{
		int a,l;
		pair<int,int> p[t];
		//cin>>n[0];
		for(int i=0;i<t;i++)
		{
			cin>>p[i].first>>p[i].second;
			p[i].first+=p[i].second;
		}
		sort(p,p+t);
		int num=1,pos=p[0].first;
		for(int i=1;i<t;i++)
		{
			if(p[i].first-2*p[i].second>=pos) num++,pos=p[i].first;
		}
		cout<<num<<"\n";
	}
  return 0;
}

Measured memory_bytes: 1024
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    ll k;cin>>k;

    ll x = 0;
    rep(i, 1, 10000001){
        x *= 10;
        x += 7;
        x %= k;
        if (x == 0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    cout << n*(n-1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

void divisor(ll N, vll& ret) {

}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N;
    cin >> N;

    ll ans = INF;
    for(ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }

    print(ans);
}


Measured memory_bytes: 3608
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
ll GetDigit(ll num){ 
    ll digit=0; 
    while(num!=0){num/=10;digit++;} 
    return digit; 
} 


using namespace std;
//-------------------------------------------
ll N;
void func(string s,int n){
  if(s.size()==N){
    cout<<s<<"\n";
  }
  else{
    REP(i,n+1){
      char c='a'+i;
      func(s+c,max(n,int(i+1)));
    }
  }
}
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin>>N;
  func("a",1);
  return 0;
}



Measured memory_bytes: 1536
#include<stdio.h>

int main(void){
    int a,b,c;
    
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    
    if(a<b&&b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int h1,m1,h2,m2,k;cin >> h1 >> m1 >> h2 >> m2 >> k;
    int hoge1 = h1*60+m1;
    int hoge2 = h2*60+m2;
    int ans = hoge2 - hoge1 - k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=1;i<n+1;i++) scanf("%d", &A[i]);

  for(i=0;i<VMAX+1;i++) C[i]=0;

  for(j=1;j<n+1;j++) C[A[j]]++;

  for(i=1;i<VMAX+1;i++) C[i]=C[i]+C[i-1];

  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<n+1;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");


  return 0;
}



Measured memory_bytes: 9548
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))


long long gcd(long long a, long long b) {
  if (b == 0) { return a; }
  return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}
//a x + b y = gcd(a, b)
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

long long InvMod(long long a, long long mod) {
  long long x, y;
  if (extgcd(a, mod, x, y) == 1) { return (x + mod) % mod; }
  return 0;
}

const ull BASE = 1e+9+7;
int n, m;
char str[400000];
ull hash[400000];
ull powBase[400000];
int l[400000];
int r[400000];
set<ull> open;
char temp[100];

void Print(int s, int e) {
  FOR(i, s, e) {
    putchar(str[i]);
  }
  puts("");
}

int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    MEMSET(hash, 0);
    MEMSET(powBase, 0);
    open.clear();
    scanf("%s", str);
    hash[0] = 0;
    powBase[0] = 1;
    REP(i, n) {
      hash[i + 1] = hash[i] * BASE + str[i];
      powBase[i + 1] = powBase[i] * BASE;
    }
    l[0] = 0;
    r[0] = 0;
    REP(i, m) {
      scanf("%s", temp);
      l[i + 1] = l[i]; r[i + 1] = r[i];
      if (temp[0] == 'L' && temp[1] == '+') {
        l[i + 1]++;
      }
      if (temp[0] == 'R' && temp[1] == '+') {
        r[i + 1]++;
      }
      if (temp[0] == 'L' && temp[1] == '-') {
        l[i + 1]--;
      }
      if (temp[0] == 'R' && temp[1] == '-') {
        r[i + 1]--;
      }
      assert(abs(l[i + 1] - l[i]) + abs(r[i + 1] - r[i]) == 1);
      ull v = hash[r[i + 1] + 1] - hash[l[i + 1]] * powBase[r[i + 1] + 1 - l[i + 1]];
      //if (open.count(v)) { cout << "Hit" << endl; }
      //cout << v << endl;
      //Print(l[i + 1], r[i + 1] + 1);
      open.insert(v);
    }
    cout << open.size() << endl;
  }
}

Measured memory_bytes: 24568
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	double N,x,y,b,p;
        cin >> N;
        for(int i=0;i<N;i++){
		cin >> x >> y >> b >> p;
        	int temp = 0;
        	if(b < 5 && p < 2){
        		temp = min(x*b+y*p,(((5-b)+b)*x+((2-p)+p)*y)*0.8);
        	}
        	else if(b < 5 && p>=2){
        		temp = min(x*b+y*p,(((5-b)+b)*x+p*y)*0.8);
        	}
        	else if(b>=5 && p < 2){
        		temp = min(x*b+y*p,(b*x+((2-p)+p)*y)*0.8);
        	}
        	else if(b>=5&&p>=2){
        		temp = min(x*b+y*p,(b*x+p*y)*0.8);
        	}
        	cout << temp << endl;
        }
	return 0;
}

        

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main() {
    int n, flag, cnt=0;
    cin >> n;
    int A[n];
    for (int i=0; i<n; i++){
        cin >> A[i];
    }
    flag = 1;
    while (flag){
        flag = 0;
        for (int j=n-1; j>0; j--){
            if (A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                flag = 1;
                cnt += 1;
            }
        }
    }
    for (int i=0; i<n; i++){
        if (i==n-1){
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3044
#include <iostream>
using namespace std;
int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if ((((x+r)<=W)&&((y+r)<=H))&&(((x-r)>=0)&&((y-r)>=0))) {
		cout <<"Yes"<<endl;
	} else {
		cout <<"No"<<endl;
	} 
    return 0;
	}


Measured memory_bytes: 3092
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);

		while (true) {

			final int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			int ans = 0;
			
			for(int i = 1; i <= 54; i++){
				if(i*i*i <= N){
					ans = Math.max(ans, i*i*i);
					
					for (int j = 1; j <= 96; j++) {
						if ((j * (j + 1) * (j + 2)) / 6 <= N) {
							ans = Math.max(ans, (j * (j + 1) * (j + 2)) / 6);
							
							if((i*i*i) + ((j * (j + 1) * (j + 2)) / 6) <= N){
								ans = Math.max(ans, (i*i*i) + ((j * (j + 1) * (j + 2)) / 6));
							}
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	}

}

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

typedef long long ll;
const int N = 1e5 + 10;
string s;
map<string, int> mp;
int n;

void solve() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> s;
		mp[s]++;
	}	
	
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
}

int main()
{
	int T = 1;
	//scanf("%d", &T);
	while(T--) {
		solve();
	}
}

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

int main()
{
    int a, b,c;
    cin >> a >> b >> c;
    if(a==b&&b==c&&c==a){
        cout << "No" << endl;
    }
    else if(a!=b&&b!=c&&c!=a){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}


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

typedef long long ll;
const int maxn = 55;
int n, K, S, T, a[maxn], b[maxn];
ll ans, C[maxn][maxn], coef[maxn], cnt[1 << 18];

int main() {
    scanf("%d %d %d %d", &n, &K, &S, &T);
    auto chk = [&](int x, int y) { return (x & y) == y; };
    if (!chk(T, S)) printf("0\n"), exit(0);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (!chk(a[i], S) || !chk(T, a[i])) { i--, n--; continue; }
    }
    T ^= S;
    for (int i = 1; i <= n; i++) {
        a[i] ^= S;
        for (int j = 0; j < 18; j++) if (T >> j & 1) {
            if (!(a[i] >> j & 1)) b[i] |= 1 << j;
        }
    }
    auto FWT = [&](ll *a, int lim) {
        for (int i = 1; i < lim; i <<= 1) {
            for (int j = 0; j < lim; j += i << 1) {
                for (int k = 0; k < i; k++) {
                    a[j + k] += a[i + j + k];
                }
            }
        }
    };
    for (int i = 0; i <= n; i++) {
        for (int j = C[i][0] = 1; j <= i; j++) {
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
        for (int j = 0; j < K; j++) {
            coef[i] += C[i][j];
        }
    }
    for (int i = 1; i <= n; i++) {
        memset(cnt, 0, sizeof(cnt));
        for (int j = i + 1; j <= n; j++) {
            cnt[b[i] ^ a[j]]++;
        }
        FWT(cnt, 1 << 18);
        for (int j = 0; j < 1 << 18; j++) {
            if (__builtin_popcount(j) & 1) ans -= coef[cnt[j]];
            else ans += coef[cnt[j]];
        }
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
    int h,w,m;
    cin >> h >> w >> m;
    vector<pair<int,int>> bomb(m);
    rep(i,m){
        cin >> bomb[i].first >> bomb[i].second;
        --bomb[i].first;--bomb[i].second;
    }

    vector<int> r(h,0);
    vector<int> c(w,0);

    rep(i,m){
        r[bomb[i].first]++;
        c[bomb[i].second]++;
    }

    int rmax = *max_element(r.begin(),r.end());
    int cmax = *max_element(c.begin(),c.end());

    set<int> max_r_inds;
    set<int> max_c_inds;

    rep(i,h)if(r[i] == rmax)max_r_inds.insert(i);
    rep(i,w)if(c[i] == cmax)max_c_inds.insert(i);

    ll cross_bomb_cnt = 0;
    ll cross = max_r_inds.size()*max_c_inds.size();

    rep(i,m){
        if(max_r_inds.count(bomb[i].first)){
            if(max_c_inds.count(bomb[i].second)){
                cross_bomb_cnt++;
            }
        }
    }
    
    if(cross_bomb_cnt < cross)cout << rmax + cmax;
    else cout << rmax + cmax - 1;
    cout << endl;


}

Measured memory_bytes: 35988
def Rally():
    # 入力
    N = int(input())
    X = list(map(int, input().split()))
    # リストの最大値と最小値
    max_num = max(X)
    min_num = min(X)
    # Pの座標を移動させて各座標の体力消耗を調べる
    min_sum = list()
    for P in range(min_num, max_num+1):
        sum = 0
        for i in range(N):
            sum += (X[i] - P)**2
        min_sum.append(sum)
    # 戻り値
    return min(min_sum)

result = Rally()
print(result)

Measured memory_bytes: 9132
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n, a[110000],b[110000];
signed main(){
  cin>>n;rep(i,n+1)cin>>a[i];rep(i,n)cin>>b[i];
  int ans = 0;

  rep(i,n){
    ans += min(b[i], a[i]);
    b[i] -= min(a[i], b[i]);
    ans += min(b[i], a[i+1]);
    a[i+1] -= min(b[i], a[i+1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[110000],f1[110000],f2[110000];
int main()
{
	int n,k,st=0;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (a[i]<=0) st=i;
	}
	f1[1]=abs(a[st]); 
	for (int i=1;i<=k;i++)
	{
		if (st-i>0) f1[i+1]=abs(a[st-i]);
		if (st+i<=n) f2[i]=a[st+i];
	}
	int ans=999999999;
	if (st-k+1>0) ans=min(ans,f1[k]);
	if (st+k<=n) ans=min(ans,f2[k]);
	for (int i=1;i<k;i++)
	{
		if (st-i+1>0&&st+k-i<=n) ans=min(ans,f1[i]*2+f2[k-i]);
		if (st+i<=n&&st-k+i>0) ans=min(ans,f2[i]*2+f1[k-i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back

using namespace std;
typedef pair<ll,ll> pll;

ll n;
map<string , vector<pll> > mp;
ll ans[1002];
ll haha[2002];
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++) {
                string s;
                cin >> s;
                ll x;
                cin >> x;
                mp[s].pb(make_pair(x,i));
        }
        ll cnt=0;
        for(auto &i : mp) {
                if(i.second.size() == 0) continue;
                vector<pll> S = i.second;
                sort(S.rbegin(), S.rend());
                for(auto &j : S) {
                        ans[j.second] = ++cnt;
                        haha[cnt] = j.second;
                }
        }
        for(ll i=1;i<=n;i++) cout << haha[i] << "\n";
        return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


int main(void){
  string S;
  cin >> S;
  ll N = S.size();
  if(S[0] == '0' || S[N-1] == '1'){
    cout << -1 << endl;
    return 0;
  }

  rep(i, N/2){
    if(S[i] != S[N-2-i]){
      cout << -1 << endl;
      return 0;
    }
  }

  ll top = 1;
  rep(i, N-1){
    if(S[i] == '1'){
      cout << top << " " << i + 2 << endl;
      top = i + 2;
    }else{
      cout << top << " " << i + 2 << endl;
    }
  }
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int peper[15][15];

void paint(int x, int y)
{
	if (x * y >= 0 && x >= 0){
		peper[y][x]++;
	}
}

int main()
{
	int x, y;
	int size;
	
	while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
		peper[y][x]++;

		paint(x, y - 1);
		paint(x, y + 1);
		paint(x - 1, y);
		paint(x + 1, y);

		if (size >= 2){
			paint(x + 1, y - 1);
			paint(x + 1, y + 1);
			paint(x - 1, y + 1);
			paint(x - 1, y - 1);
		}
		if (size == 3){
			paint(x, y - 2);
			paint(x, y + 2);
			paint(x - 2, y);
			paint(x + 2, y);
		}
	}
	int dark = 0;
	int blank = 0;
	
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			if (peper[i][j] == 0)	blank++;
			dark = max(dark, peper[i][j]);
		}
	}
	printf("%d\n%d\n", blank, dark);
	return (0);
}

Measured memory_bytes: 1188
N, x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
a_new = sorted(a)

for i in range(0, N):
	count += a_new[i]
	if x == count:
		index = i + 1
		break
	if count > x:
		index = i
		break
	index = i

print(str(index))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//static const long long INF = 1000000000000000;
typedef long long ll;
int main(void){
    // Your code here!
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X);
    vector<ll> B(Y);
    vector<ll> C(Z);
    for(int i = 0; i < X; i++)cin >> A.at(i);
    for(int i = 0; i < Y; i++)cin >> B.at(i);
    for(int i = 0; i < Z; i++)cin >> C.at(i);
    vector<ll> AB(X * Y);
    
    int cnt = 0;
    for(int i = 0; i < X; i++){
        for(int j = 0; j < Y; j++){
            AB.at(cnt) = A.at(i) + B.at(j);
            cnt++;
        }
    }
    sort(C.begin(),C.end());
    reverse(C.begin(),C.end());
    sort(AB.begin(),AB.end());
    reverse(AB.begin(),AB.end());
    
    
    
    int m = min(3010, X * Y);
    
    vector<ll> ANS(m * Z + 10);
    for(int i = 0; i < m * Z + 10; i++){
        ANS.at(i) = 0;
    }
    
    
    
    int count = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < Z; j++){
            ANS.at(count) = AB.at(i) + C.at(j);
            count++;
        }
    }
    
    
    sort(ANS.begin(),ANS.end());
    reverse(ANS.begin(),ANS.end());
    for(int i = 0; i < K; i++){
        cout << ANS.at(i) << endl;
    }
    
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 31616
#include <stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int X[N][N];

void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
	printf("Q");
      }else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==N){
    printBoard();
    return ;
  }

  for(j=0;j<N;j++){
    if(NOT_FREE==col[j]|| NOT_FREE==dpos[i+j]||NOT_FREE==dneg[i-j+N-1])continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}
int main(){
  initialize();
  int i,j,k,r,c;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j]=0;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c]=1;
  }

  recursive(0);
  return 0;
}

Measured memory_bytes: 572
///
// File:  c.cpp
// Author: ymiyamoto
//
// Created on Sun Oct  1 01:51:42 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  uint64_t N;
  cin >> N;

  for (uint32_t h = 1; h <= 3500; h++) {
    for (uint32_t n = 1; n <= 3500; n++) {
      int64_t val2 = 4 * h * n - N * h - N * n;
      int64_t val1 = N * h * n;
      if (val2 > 0 && val1 % val2 == 0) {
        cout << h << " " << n << " " << val1 / val2 << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> x, y;

int AtCoder(int p, int q) {
  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (x[i] - p == x[j] and y[i] - q == y[j]) cnt++;
    }
  }
  return N - cnt;
}

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b; cin >> a >> b;
    x.push_back(a);
    y.push_back(b);
  }

  int ans = N;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (i == j) continue;
      ans = min(ans, AtCoder(x[i] - x[j], y[i] - y[j]));
      ans = min(ans, AtCoder(x[j] - x[i], y[j] - y[i]));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[200010][3];

int main(){
  rep(i,200010)rep(j,3) dp[i][j]=-1e18;
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  if(n%2==1){
    dp[0][0]=a[0];
    dp[1][1]=a[1];
    dp[2][2]=a[2];
  }
  else{
    dp[0][0]=a[0];
    dp[1][1]=a[1];
  }
  rep(i,n){
    rep(j,3){
      if(i-2>=0) chmax(dp[i][j],dp[i-2][j]+a[i]);
      if(i-3>=0&&j-1>=0) chmax(dp[i][j],dp[i-3][j-1]+a[i]);
      if(i-4>=0&&j-2>=0) chmax(dp[i][j],dp[i-4][j-2]+a[i]);
    }
  }
  ll ans=-1e18;
  if(n%2==1){
    chmax(ans,dp[n-1][2]);
    chmax(ans,dp[n-2][1]);
    chmax(ans,dp[n-3][0]);
  }
  else{
    chmax(ans,dp[n-1][1]);
    chmax(ans,dp[n-2][0]);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 9560
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
  double a, b, c, d, e, f;
  while ((cin >> a >> b >> c >> d >> e >> f)) {
    // cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
    c /= a;
    b /= a;
    a = 1.0;
    // cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
    double tmp = d / a;
    // cout << "tmp " << tmp << endl;
    d -= a * tmp;
    e -= b * tmp;
    f -= c * tmp;
    // cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
    f /= e;
    e = 1.0;
    // cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
    tmp = b / e;
    // if (b * e >= 0) {
    b -= e * tmp;
    c -= f * tmp;
    /*} else {
      b += e * tmp;
      c += f * tmp;
      }*/
    // cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
    // cout << setprecision(4) << c << " " << setprecision(4) << f << endl;
    printf("%2.3f %2.3f\n", c, f);
  }
  return 0;
}

Measured memory_bytes: 3040
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
AC=Counter(A)
goukei=0
for i, e in AC.items():
    goukei+=(e*(e-1))//2
for a in A:
    p=AC[a]
    print(goukei - (p*(p-1))//2 + ((p-1)*(p-2))//2)

Measured memory_bytes: 27028
#include <bits/stdc++.h>
#include<limits.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
int main()
{
	ll n,W;
	cin>>n>>W;
	ll w[n+1];
	ll v[n+1];
	for(ll i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
	}
	ll dp[n+1][100003];
	fillv(dp,0);
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=100000;j++)
		{
			dp[i][j]=INT_MAX-1;
		}
	}
	ll maxx=0;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=100000;j++)
		{
			if(j-v[i]<0)
			{
				dp[i][j]=dp[i-1][j];
				continue;
			}

			if(dp[i-1][j-v[i]]<INT_MAX-1||j==v[i])
			{
				if(j==v[i])
					dp[i][j]=min(w[i],dp[i-1][j]);
				else
				dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
				if(maxx<j&&dp[i][j]<=W)
				{
					maxx=j;
				}
			}
			else 
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<maxx<<endl;

}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string ans="";
    REP(i,tx-sx){
        ans+="R";
    }
    REP(i,ty-sy){
        ans+="U";
    }
    REP(i, tx - sx)
    {
        ans += "L";
    }
    REP(i,ty-sy){
        ans+="D";
    }
    ans+="D";
    REP(i, tx - sx+1)
    {
        ans += "R";
    }
    REP(i, ty - sy+1)
    {
        ans += "U";
    }
    ans+="L";
    ans+="U";
    REP(i, tx - sx+1)
    {
        ans += "L";
    }
    REP(i, ty - sy+1)
    {
        ans += "D";
    }
    ans+="R";
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N, &S)
	max := 0
	current := 0
	for _, r := range S {
		switch r {
		case 'I':
			current++
		case 'D':
			current--
		}
		if current > max {
			max = current
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int long long

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1000 + 20 , mod = 1e9 + 7 ;
int n , m , k ;
int t , z , ss ;
bool f1 , f2 ;
string s[N] ;

struct mat {
	int a[2][2] ;

	mat (int x = 0) {
		a[0][1] = a[1][0] = 0 ;
		a[0][0] = a[1][1] = x ;
	}

	void print () {
		cout << a[0][0] << ' ' << a[0][1] << '\n' ;
		cout << a[1][0] << ' ' << a[1][1] << '\n' ;
	}
} mt , a ;

mat operator * (mat a , mat b) {
	mat res ;
	for (int i = 0 ; i < 2 ; i ++)
		for (int j = 0 ; j < 2 ; j ++)
			for (int k = 0 ; k < 2 ; k ++)
				res.a[i][j] = (res.a[i][j] + a.a[i][k] * b.a[k][j]) % mod ;
	return res ;
}

mat operator ^ (mat a , int b) {
	mat res(1) ;
	while (b) {
		if (b & 1) res = res * a ;
		a = a * a ;
		b >>= 1 ;
	}
	return res ;
}

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

	cin >> n >> m >> k ;

	if (!k) return cout << "1\n" , 0 ;

	for (int i = 0 ; i < n ; i ++) cin >> s[i] ;

	for (int i = 0 ; i < n ; i ++) f1 |= (s[i][0] == '#' && s[i][m - 1] == '#') ;
	for (int i = 0 ; i < m ; i ++) f2 |= (s[0][i] == '#' && s[n - 1][i] == '#') ;

	if (f1 && f2) return cout << "1\n" , 0 ;
	

	for (int i = 0 ; i < n ; i ++)
		for (int j = 0 ; j < m ; j ++)
			t += s[i][j] == '#' ;

	if (!f1 && !f2) {
		mt.a[0][0] = t ;
		mt.a[0][1] = mt.a[1][0] = mt.a[1][1] = 0 ;
	}
	else if (f1) {
		for (int i = 0 ; i < n ; i ++) ss += s[i][m - 1] == '#' && s[i][0] == '#' ;
		for (int i = 0 ; i < n ; i ++)
			for (int j = 0 ; j + 1 < m ; j ++)
				if (s[i][j] == '#' && s[i][j + 1] == '#') z ++ ;

		mt.a[0][0] = t , mt.a[1][0] = mod - z , mt.a[0][1] = 0 , mt.a[1][1] = ss ;
	}
	else {
		for (int i = 0 ; i < m ; i ++) ss += s[n - 1][i] == '#' && s[0][i] == '#' ;
		for (int i = 0 ; i + 1 < n ; i ++)
			for (int j = 0 ; j < m ; j ++)
				if (s[i][j] == '#' && s[i + 1][j] == '#') z ++ ;

		mt.a[0][0] = t , mt.a[1][0] = mod - z , mt.a[0][1] = 0 , mt.a[1][1] = ss ;
	}

	a.a[0][0] = a.a[0][1] = a.a[1][0] = a.a[1][1] = 1 ;

	mt = mt ^ (k - 1) ;

	a = a * mt ;

	cout << a.a[0][0] << '\n' ;
}


Measured memory_bytes: 1280
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto x = readln.chomp.split.to!(int[]);

  int cnt;
  foreach (i; 0..x[0]) {
    auto y = readln.chomp.split.to!(int[]);
    if (x[1] <= y[0] && x[2] <= y[1]) {
      cnt++;
    }
  }
  cnt.writeln;
}


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

const int N=1005,P=1e9+7;
int n,m,cnt_r=0,cnt_v=0,cnt_hh=0,cnt_vv=0; ll k,a,b,c; char s[N][N];

ll Pow(ll x,ll k) {
    ll ret=1;
    for (; k; k>>=1,x=x*x%P) if (k&1) ret=ret*x%P;
    return ret;
}

int main() {
//    file_put();
    
    scanf("%d%d%lld",&n,&m,&k);
    if (k==0) return 0*printf("1\n");
    rep(i,1,n+1) scanf("%s",s[i]+1);
    rep(i,1,n+1) cnt_r+=(s[i][1]=='#' && s[i][m]=='#');
    rep(i,1,m+1) cnt_v+=(s[1][i]=='#' && s[n][i]=='#');
    rep(i,1,n+1) rep(j,1,m) cnt_hh+=(s[i][j]=='#' && s[i][j+1]=='#');
    rep(i,1,m+1) rep(j,1,n) cnt_vv+=(s[j][i]=='#' && s[j+1][i]=='#');
    rep(i,1,n+1) rep(j,1,m+1) a+=(s[i][j]=='#'); 
    if (cnt_r && cnt_v) return 0*printf("1\n");
    if (cnt_r) b=cnt_hh,c=cnt_r; else b=cnt_vv,c=cnt_v;
    if (!cnt_r && !cnt_v) return 0*printf("%lld\n",Pow(a,k-1));
//    assert(a!=c);
//    if (a!=c) {
        ll t=b*Pow(a-c,P-2)%P;
        ll ans=Pow(a,k-1)*(1-t)%P;
        ans+=t*Pow(c,k-1)%P; ans%=P; 
        return 0*printf("%lld\n",(ans+P)%P);
        assert(0);
//    }
//    ll ans=Pow(c,k-1);
//    ans*=(1-b*Pow(c,P-2)%P*(k-1)%P)%P; ans%=P;
//    printf("%lld\n",(ans+P)%P); 
    
	return 0;
}



Measured memory_bytes: 1280