akhauriyash/Code-Regression huggingface dataset:
N = int(input())
hito = {c:0 for c in "MARCH"}
for _ in range(N):
    S = input()
    if S[0] in "MARCH":
        hito[S[0]] += 1
from itertools import combinations
ans = 0
for comb in combinations("MARCH", 3):
    temp = 1
    for head in comb:
        temp *= hito[head]
    ans += temp
print(ans)

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

using namespace std;

int main()
{
    int a, b, c;

    vector <int> v;

    cin >> a >> b >> c;

    v.push_back(a);
    v.push_back(b);
    v.push_back(c);

    sort(v.begin(),v.end());

    if(v[0] == v[1] && v[0] != v[2] || (v[1] == v[2] && v[1] != v[0]))
        cout << "Yes";
    else
        cout <<"No";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int r,c,k,x,y,z;
    cin >> r >> c >> k;
    VVI b(r,VI(c));
    REP(i,0,k) {
        cin >> x >> y >> z;
        --x;
        --y;
        b[x][y] = z;
    }
    VVVLL dp(r,VVLL(c,VLL(4)));
    dp[0][0][1] = b[0][0];
    REP(i,1,r) {
        dp[i][0][0] = *max_element(all(dp[i-1][0]));
        dp[i][0][1] = dp[i][0][0] + b[i][0];
    }
    REP(i,1,c) {
        REP(j,0,4) {
            dp[0][i][j] = dp[0][i-1][j];
            if (j > 0) chmax(dp[0][i][j], dp[0][i-1][j-1] + b[0][i]);
        }
    }
    REP(i,1,r) REP(j,1,c) {
        REP(k,0,4) {
            dp[i][j][k] = max(*max_element(all(dp[i-1][j])), dp[i][j-1][k]);
            if (k > 0) chmax(dp[i][j][k], max(*max_element(all(dp[i-1][j])), dp[i][j-1][k-1]) + b[i][j]);
        }
    }

    cout << *max_element(all(dp[r-1][c-1])) << endl;

    // REP(k,0,4) {
    //     cout << "---" << endl;
    //     REP(i,0,r) {
    //         REP(j,0,c) cout << dp[i][j][k] << " ";
    //         cout << endl;
    //     }
    // }
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 670984
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i32 N, K;
  cin >> N >> K;
  vi32 A(N);
  rep(i, N) cin >> A[i];
  vi32 b(N, false);
  sort(all(A), greater<i32>());
  for(int i = 0; i < N; i++) {
    i32 idx = i;
    i64 sum = 0;
    while (idx < N && sum < K) {
      sum += A[idx++];
    }
    if (sum < K) break;
    sum -= A[--idx];
    i32 ok = idx, ng = N;
    while (ng - ok > 1) {
      i32 md = (ok + ng) / 2;
      if (sum + A[md] >= K) {
        ok = md;
      } else {
        ng = md;
      }
    }
    for (int j = i; j < ng; j++) {
      b[j] = true;
    }
  }
  int ans = 0;
  rep(i, N) if (!b[i]) ans++;
  cout << ans << endl;
  return 0;
}

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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

ll dp[3010][3010][4];

using Graph=vector<vector<ll>>;
Graph  G(3010,vector<ll>(3010,0));

int main(){
    ll R,C,K;
    cin>>R>>C>>K;
    REP(i,K){
        ll r,c,v;
        cin>>r>>c>>v;
        r--;
        c--;
        G[r][c]=v;
    }
    REP(i,3010){
        REP(j,3010){
            REP(k,4){
                dp[i][j][k]=0;
            }
        }
    }
    REP(i,R){
        REP(j,C){
            //行チェンジ
            ll tmp1=max(dp[i][j+1][0],dp[i][j+1][1]);
            tmp1=max(tmp1,dp[i][j+1][2]);
            tmp1=max(tmp1,dp[i][j+1][3]);
            dp[i+1][j+1][0]=max(dp[i+1][j+1][0],tmp1);
            dp[i+1][j+1][1]=max(dp[i+1][j+1][1],tmp1+G[i][j]);
            dp[i+1][j+1][2]=max(dp[i+1][j+1][2],tmp1+G[i][j]);
            dp[i+1][j+1][3]=max(dp[i+1][j+1][3],tmp1+G[i][j]);
            
            //列チェンジ
            dp[i+1][j+1][0]=max(dp[i+1][j+1][0],dp[i+1][j][0]);

            
            dp[i+1][j+1][1]=max(dp[i+1][j+1][1],dp[i+1][j][0]+G[i][j]);
            dp[i+1][j+1][1]=max(dp[i+1][j+1][1],dp[i+1][j][1]);
            
            dp[i+1][j+1][2]=max(dp[i+1][j+1][2],dp[i+1][j][0]+G[i][j]);
            dp[i+1][j+1][2]=max(dp[i+1][j+1][2],dp[i+1][j][1]+G[i][j]);
            dp[i+1][j+1][2]=max(dp[i+1][j+1][2],dp[i+1][j][2]);

            dp[i+1][j+1][3]=max(dp[i+1][j+1][3],dp[i+1][j][0]+G[i][j]);
            dp[i+1][j+1][3]=max(dp[i+1][j+1][3],dp[i+1][j][1]+G[i][j]);
            dp[i+1][j+1][3]=max(dp[i+1][j+1][3],dp[i+1][j][2]+G[i][j]);
            dp[i+1][j+1][3]=max(dp[i+1][j+1][3],dp[i+1][j][3]);
            
        }
    }
    cout<<dp[R][C][3]<<endl;
    
}

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

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long D, long long G, std::vector<long long> p, std::vector<long long> c){
  ll ans = 1001001001;
  for(ll i=0; i< (1<<D); i++) {
    ll sum = 0;
    ll cnt = 0;
    for(ll j=0; j<D; j++) {
      if(i&(1<<j)) {
	sum+=p[j]*(j+1)*100 + c[j];
	cnt += p[j];
      }
    }
    if(sum >= G) {
      ans = min(ans, cnt);
      continue;
    } else {
      for(ll j=D-1; j>=0; j--) {
	if(i&(1<<j)) continue;
	for(ll k=0; k<p[j]; k++) {
	  sum+=(j+1)*100;
	  cnt++;
	  if(sum >= G) break;
	}
	break;
      }
      if(sum >= G)
	ans = min(ans, cnt);
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long D;
  scanf("%lld",&D);
  long long G;
  scanf("%lld",&G);
  std::vector<long long> p(D);
  std::vector<long long> c(D);
  for(int i = 0 ; i < D ; i++){
    scanf("%lld",&p[i]);
    scanf("%lld",&c[i]);
  }
  solve(D, G, std::move(p), std::move(c));
  return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[]
for i in range(n):
    a=[int(j) for j in input().split()]
    ab.append(a)

from operator import itemgetter
ab.sort(key=itemgetter(0))  

i=0
p=0
ans=0
while p==0:
    if m>ab[i][1]:
        ans+=ab[i][1]*ab[i][0]
        m-=ab[i][1]
        i+=1
    else:
        ans+=ab[i][0]*m
        p=1

print(ans)




Measured memory_bytes: 22880
#include<iostream>
#include<string>
int room[4][3][10];
template<typename T>
T input(){
	T t;
	std::cin>>t;
	return t;
}
int main(){
	for(int i=0;i<4;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<10;++k){
				room[i][j][k]=0;
			}
		}
	}
	const int n=input<int>();
	for(int i=0;i<n;++i){
		const int b=input<int>();
		const int f=input<int>();
		const int r=input<int>();
		const int v=input<int>();
		room[b-1][f-1][r-1]+=v;
	}
	for(int i=0;i<4;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<10;++k){
				std::cout<<" "<<room[i][j][k];
			}
			std::cout<<std::endl;
		}
		if(i!=3)std::cout<<std::string(20,'#')<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.nextLine();
		int b = Integer.parseInt(scanner.nextLine());
		for(int i=0;i<b;i++){
			String[] c = scanner.nextLine().split(" ");
			int d = Integer.parseInt(c[1]);
			int e = Integer.parseInt(c[2])+1;
			if(c[0].equals("print")){
				System.out.println(a.substring(d,e));
			}else if(c[0].equals("reverse")){
				StringBuffer stringBuffer = new StringBuffer(a.substring(d, e));
				StringBuffer gyaku  = stringBuffer.reverse();
				a = a.substring(0,d) +gyaku.toString()+a.substring(e);
			}else{
				a= a.substring(0,d)+c[3] +a.substring(e);
			}
			
		}
	}}

Measured memory_bytes: 24104
#include <stdio.h>

int main(void) {
	int l,r,d;
	int count = 0;
	int i;
	
	scanf("%d%d%d",&l,&r,&d);
	for(i=l;i<=r;i++){
		if(i%d == 0){
			count++;
		}
	}
	
	printf("%d",count);
	
	return 0;
}


Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner sc = new Scanner(System.in);
		int width, length;
		int tile[][];
		int mark[][];

		while (true) {
			length = sc.nextInt();
			width = sc.nextInt();
			if ((width | length) == 0) {
				break;
			}
			tile = new int[length][width];
			mark = new int[length][width];
			for (int i = 0; i < length; i++) {
				String s = sc.next();
				for (int j = 0; j < width; j++) {
					tile[i][j] = s.charAt(j);
				}
			}
			int x = 0;
			int y = 0;
			mark[y][x] = 1;
			while (true) {
				if (tile[y][x] == '>') {
					x++;
				} else if (tile[y][x] == '<') {
					x--;
				} else if (tile[y][x] == '^') {
					y--;
				} else if (tile[y][x] == 'v') {
					y++;
				} else if (tile[y][x] == '.') {
					System.out.println(x + " " + y);
					break;
				}
				if (mark[y][x] == 1) {
					System.out.println("LOOP");
					break;
				}
				mark[y][x] = 1;
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
void serch(int n,int now)
{
    n=n%1000000/100;
    cout<<n<<endl;
    if(now<10)serch(n*n,now+1);
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int num;
        cin>>num;
        cout<<"Case "<<i<<':'<<endl;
        serch(num*num,1);
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	int W, H, x, y, r;

	std::cin >> W >> H >> x >> y >> r;

	if (x + r > W || x - r<0 || y + r>H || y - r < 0) {
		std::cout << "No" << std::endl;
	}
	else {
		std::cout << "Yes" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M, Q; cin >> N >> M >> Q;
    vector<vector<int>> dp(N, vector<int>(N, 0));
    for (int i = 0; i < M; i++)
    {
        int L, R; cin >> L >> R;
        L--; R--;
        dp[L][R]++;
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if(j > 0) dp[i][j] += dp[i][j-1];
        }

    }


    vector<int> ans(Q, 0);
    for (int i = 0; i < Q; i++)
    {
        int p, q; cin >> p >> q;
        p--; q--;
        for (int j = p; j <= q; j++)
        {
            if(p > 0)ans[i] += dp[j][q] - dp[j][p-1];
            else ans[i] += dp[j][q];
        }
    }
    for (int i = 0; i < Q; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, m, comp[maxn], compCount, sz[maxn], color[maxn];
bool isBip[maxn];
vector<int> graph[maxn];

void dfs(int u, int clr)
{
	color[u] = clr;
	comp[u] = compCount;
	sz[compCount]++;
	for (int i : graph[u])
	{
		if (color[i] == -1)
			dfs(i, 1 - clr);
		else if (color[i] == color[u])
			isBip[compCount] = false;
	}
}

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

	memset(color, -1, sizeof(color));
	memset(isBip, true, sizeof(isBip));

	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		graph[--u].pb(--v);
		graph[v].pb(u);
	}
	for (int i = 0; i < n; i++)
		if (color[i] == -1)
			dfs(i, 0), compCount++;
	ll oneCount = 0, bipCount = 0;
	for (int i = 0; i < compCount; i++)
	{
		if (sz[i] == 1)
			oneCount++;
		else
			bipCount += isBip[i];
	}
	ll ans = compCount - oneCount + bipCount;
	ans += oneCount * oneCount + 2 * oneCount * (n - oneCount);
	ans += 2 * bipCount * (bipCount - 1);
	ans += 2 * bipCount * (compCount - oneCount - bipCount);
	ans += (compCount - oneCount - bipCount) * (compCount - oneCount - bipCount - 1);
	cout << ans << endl;
}



Measured memory_bytes: 10496
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a>>b;
  while(1){  
    bool f=0;
    if(a==0&&b==0)break;
    for(int i=a;i<=b;i++){
      if(i%400==0){cout<<i<<endl;f=1;}
      else if(i%4==0&&i%100!=0){cout<<i<<endl;f=1;}
    }
    if(f==0)cout<<"NA"<<endl; 
    if(cin>>a>>b&& a && b)cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int N;
ll A[200000], B[200000];
int main(void){
    cin >> N;
    REP(i, N){
        cin >> A[i] >> B[i];
    }
    sort(A, A+N);
    sort(B, B+N);
    if (N%2==1){
        cout << B[N/2] - A[N/2] + 1<< endl;
    }else{
        cout << ( (B[N/2]+B[N/2-1]) - (A[N/2]+A[N/2-1]) ) + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 6752
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,k;cin>>n>>k;
	ll ans = 0;
	for(int b = 1; b <= n; b++) {
		int p = n / b;
		int r = n % b;
		ans += (p * max(0,b - k) + max(0,r - k + 1));
		if (k == 0)ans--;

	}

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

Measured memory_bytes: 256
import string

N = input()

if N[0] == 'A' and N.count('A') == 1 and N.count('C') == 1 and N[2:-1].count('C') == 1 and sum(1 for c in N if c.isupper()) == 2:
  print('AC')
else:
  print('WA')

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

long long lcm(long long a, long long b) {
	return a * b / __gcd(a, b);
}

long long lcm(long long a, long long b, long long c) {
	return lcm(lcm(a, b), c);
}

int main() {
    long long a1, m1, a2, m2, a3, m3;
    while (cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3) {
        if (a1 == 0 && m1 == 0 && a2 == 0 && m2 == 0 && a3 == 0 && m3 == 0) break;
		long long cx = 0, cy = 0, cz = 0;
        long long x = 1, y = 1, z = 1;
        while (true) {
            x = a1 * x % m1; cx++;
			if (x == 1) break;
		}
		while (true) {
            y = a2 * y % m2; cy++;
			if (y == 1) break;
		}
		while (true) {
            z = a3 * z % m3; cz++;
			if (z == 1) break;
		}
		cout << lcm(cx, cy, cz) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.io.*;

class Main {




  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt();
    int[][] points = new int[N][3];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 3; j++) {
        points[i][j] = in.nextInt();
      }
    }

    int[][] dp = new int[N][3];
    dp[0][0] = points[0][0];
    dp[0][1] = points[0][1];
    dp[0][2] = points[0][2];

    for (int i = 1; i < N; i++) {
      for (int j = 0; j < 3; j++) {
        dp[i][j] = Math.max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + points[i][j];
      }
    }


    System.out.println(Math.max(dp[N - 1][0], Math.max(dp[N - 1][1], dp[N - 1][2])));
  }

  

  
}

Measured memory_bytes: 101316
q,h,s,d=map(int, input().split( ))
n=int(input())#ちょうど
n*=4
lst=[(q*4,q,1),(h*2,h,2),(s,s,4),(d/2,d,8)]
lst.sort()
ans=0
for _,t,x in lst:
    ans+=(n//x)*t
    n-=(n//x)*x
print(ans)


Measured memory_bytes: 38512
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

lint p=1000*1000*1000+7;

int main(){
  int N;
  cin>>N;
  int C[N];
  REP(i,N)cin>>C[i];
  lint dp[N];
  dp[0]=1;
  map<int,int> last;
  last[C[0]]=0;
  FOR(i,1,N){
    dp[i]=dp[i-1];
    if(last.find(C[i])!=last.end() and C[i]!=C[i-1]){
      dp[i]+=dp[last[C[i]]];
      dp[i]%=p;
    }
    last[C[i]]=i;
  }
  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 11904
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;

const int MAX_N = 1000002;

ll dp[MAX_N], subs[MAX_N];

bool sieve[MAX_N];

int main() {
  int T, i, j, temp;

  fill(dp, dp + MAX_N, -1);
  fill(subs, subs + MAX_N, 0);
  fill(sieve, sieve + MAX_N, true);

  sieve[0] = sieve[1] = false;
  for (i = 4; i < MAX_N; i+=2) sieve[i] = false;
  for (i = 3; i < MAX_N; i+=2) if (sieve[i]) {
    for (j = i+i; j < MAX_N; j+=i) sieve[j] = false;
  }
  
  dp[1] = 2;
  for (i = 2; i < MAX_N; i++) {
    if (sieve[i]) {
      dp[i] = dp[i-1] + i-1;
      for (j = i+i; j < MAX_N; j+=i) subs[j] += i-1;
      continue;
    }
    int add = i-1 - subs[i];
    dp[i] = dp[i-1] + add;
    for (j = i+i; j < MAX_N; j+=i) subs[j] += add;
  }
  
  cin >> T;
  rep (i,T) {
    cin >> temp;
    cout << dp[temp] << endl;
  }
  return 0;
}

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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
        int a,b;cin >> a >> b;
        string s;cin >> s;
        string frag = "Yes";
        for(int i = 0;i<a;i++){
                int c = s.at(i) - '0';
                if(c<0 or c>9) frag = "No";
        }
        if(s.at(a) != '-') frag = "No";
        for( int i = a+1;i<a+b+1;i++){
                int c = s.at(i) - '0';
                if(c<0 or c>9) frag = "No";
        }
        cout << frag << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  int l[N],r[N];
  int ans=0;
  for(int i=0;i<N;i++){
    cin>>l[i]>>r[i];
    ans+=r[i]-l[i]+1;
  }
  cout<<ans<<endl;
}

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

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

using namespace std;

const int MOD = 10000;
int dp[101][4][4];
int pasta[101];
int main(){
	int n, k;
	cin >> n >> k;
	rep(i, k){
		int d, p;
		cin >> d >> p;
		pasta[d] = p;
	}
	
	dp[0][0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int l = 1; l < 4; l++){
			if(pasta[i] && pasta[i] != l) continue;
			for(int j = 0; j < 4; j++){
				for(int k = 0; k < 4; k++){
					if(l == j && j == k) continue;
					dp[i][l][j] += dp[i-1][j][k];
					dp[i][l][j] %= MOD;
				}
			}
		}
	}
	int ans = 0;
	rep(i, 4) rep(j, 4) ans += dp[n][i][j];
	cout << ans%MOD << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){
  string N;
  cin >> N;
  ll flag = 0;
  for(ll i = 0; i < 3; i++){
    if(N[i] == '7'){
      flag = 1;
    }
  }

  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, m, k;

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow((b*b) % MOD, e >> 1)) % MOD : 1;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		ans += i * 1LL * (n - i);
		ans = ans % MOD;
	}
	ans = ans * m;
	ans = ans % MOD;
	ans = ans * m;
	ans = ans % MOD;
	long long tmp = ans;
	ans = 0;
	for (int i = 1; i < m; i++) {
		ans += i * 1LL * (m - i);
		ans = ans % MOD;
	}
	ans = ans * n;
	ans = ans % MOD;
	ans = ans * n;
	ans = ans % MOD;
	ans = ans + tmp;
	ans = ans % MOD;
	for (int i = 1; i <= k - 2; i++) {
		ans = ans * (n*m - 1 - i);
		ans = ans % MOD;
		ans = ans * quickpow(i, MOD - 2);
		ans = ans % MOD;
	}
	cout << ans << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#define mil 200001

using namespace std;


int main()
{
    int n,m,count = 0;
    cin>>n;
    int arr[mil];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int initial = arr[0];
    for(int i=0;i<n;i++)
    {
        if(arr[i] >= initial)
        {
            count++;
            initial = arr[i];
        }
    }
    cout<<count;


}


Measured memory_bytes: 256
n, x = gets.chomp.split.map(&:to_i)

lists = []
n.times do
  lists << gets.chomp.to_i
end

lists.sort!

sum = 0
count = 0
lists.each do |item|
  if sum + item < x
    sum += item
    count += 1
  end
end

puts count + (x - sum) / (lists).min


Measured memory_bytes: 3836
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		char[] str;
		try{
			scan = new Scanner(System.in);
			str = scan.next().toCharArray();
		}finally{
			if(scan !=null)scan.close();
		}
		for(int i =0 ;i <str.length;i++){
			System.out.printf("%c",change(str[i]));
		}
		System.out.println();
	}
	private static char change(char data){
		int d = (int)data;
		d -= 3;
		if(d < 'A')
				d +='Z' - 'A' +1;
		return (char) d;
	}
}

Measured memory_bytes: 20248
#include <stdio.h>
#include <string.h>
int main(void){
        char s[101];
        int len,n,i,j;
        while(scanf("%s",s) != EOF){
                len = strlen(s);

                for(i=0;i<len;i++){
                        if(s[i] == '@'){
                                n = s[i+1]-'0';
                                for(j=0;j<n;j++){
                                        printf("%c",s[i+2]);
                                }
                                i += 2;
                        }else
                                printf("%c",s[i]);
                }puts("");
        }
        return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

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

int main() {

	long long int n, w;
	cin >> n >> w;

	vector<P> vw(n);
	for (long long int i = 0; i < n; i++) {
		cin >> vw[i].first >> vw[i].second;
	}

	long long int pp = vw[0].first;

	for (long long int i = n - 1; i >= 0; i--) {
		vw[i].first -= pp;
	}

	long long int dp[310][110] = { 0 };
	long long int dp2[310][110] = { 0 };

	for (long long int i = 0; i < n; i++) {
		for (long long int j = 0; j < n; j++) {
			for (long long int k = 0; k + vw[i].first < 310; k++) {
				dp2[k + vw[i].first][j + 1] = max(dp[k + vw[i].first][j + 1], dp[k][j] + vw[i].second);
			}
		}
		for (long long int j = 0; j <= n; j++) {
			for (long long int k = 0; k < 310; k++) {
				dp[k][j] = dp2[k][j];
			}
		}
	}


	long long int ans = 0;

	for (long long int j = 0; j <= n; j++) {
		for (long long int k = 0; k < 310; k++) {
			if (k + pp*j <= w) {
				//cout << k << ' ' << j << ' ' << dp[k][j] << endl;
				ans = max(ans, dp[k][j]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000000000
const ll mod=1e9+7;

int main()
{
	int nT; nT=1; //cin>>nT;
	while(nT--)
	{
		int n; cin>>n;
		ll a[n]; ll dp[n];
		rep(i,n) cin>>a[i];
		if(n==1) cout<<"0";
		else
		{
			dp[0]=0;
			dp[1]=abs(a[1]-a[0]);
			for(int i=2; i<n; i++) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
			cout<<dp[n-1];
		}
	}
	
	return 0;
}


Measured memory_bytes: 1792
import itertools
from collections import defaultdict

N = int(input())

chs = ['A', 'C', 'G', 'T']
ngs = ['AGC', 'ACG', 'GAC']

memo = defaultdict(int)
for s in list(set(map(''.join, itertools.product(chs, repeat=3))) - set(ngs)):
    memo[s] += 1

# NG: AGC, ACG, GAC, AG*C. A*GC
for i in range(3, N):
    m = defaultdict(int)
    for key in memo.keys():
        m['C'+key[:2]] += memo[key]
        m['T'+key[:2]] += memo[key]
        if key[:2] != 'AC':
            m['G'+key[:2]] += memo[key]
        if key[:2] != 'CG' and key[:2] != 'GC' and key[0]+key[2] != 'GC' and key[1]+key[2] != 'GC':
            m['A'+key[:2]] += memo[key]
    memo = m
print(sum(memo.values()) % (10**9+7))

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  string s;
  cin>>s;
  int ans=1000000000;
  REP(i, s.size()-2){
    string c = s.substr(i, 3);
    ans = min(ans, abs(stoi(c)-753));
  }
cout<<ans<<endl;

  return 0;
}


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

#define FOR(i, a, b) for(int(i)=(a);(i)<(b);(i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	int a, b;
	cin>>a>>b;

	if(a <= 0 && b>= 0){
		cout<<"Zero"<<endl;
	}else if(a<0 && abs(min(b, -1))%2 == abs(a)%2){
		cout<<"Negative"<<endl;
	}else{
		cout<<"Positive"<<endl;
	}

	return 0;
}



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

int main() {
    ll k,x=0;
    cin >> k;
//    if (k%2==0 || k%5==0) {cout << -1 << endl; return 0;}
    for (int i=1;i<=k;i++) {
        x*=10;
        x+=7;
        if (x%k==0) {cout << i; return 0;}
        x%=k;
    }
    cout << -1 <<endl;
}


Measured memory_bytes: 3608
n = int(input())

num_of_votes = {}

for _ in range(n):
  s = input()
  if num_of_votes.get(s) == None:
    num_of_votes[s] = 0
  num_of_votes[s] += 1

ans = []
max_v = 0
for k, v in num_of_votes.items():
  if max_v < v:
    ans = [k]
    max_v = v
  elif max_v == v:
    ans.append(k)
  else:
    pass

print("\n".join(sorted(ans)))

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  while(1){
    int n; cin >> n;
    if(n == 0) break;

    vector<pii> pos(n);
    rep(i,n-1){
      int m,d; cin >> m >> d;
      if(d == 0){
	pos[i+1].fst = pos[m].fst - 1;
	pos[i+1].snd = pos[m].snd;
      }else if(d == 1){
	pos[i+1].fst = pos[m].fst;
	pos[i+1].snd = pos[m].snd - 1;
      }else if(d == 2){
	pos[i+1].fst = pos[m].fst + 1;
	pos[i+1].snd = pos[m].snd;
      }else if(d == 3){
	pos[i+1].fst = pos[m].fst;
	pos[i+1].snd = pos[m].snd + 1;
      }
    }
    int minx = inf, maxx= -inf, miny = inf, maxy = -inf;
    rep(i,n){
      minx = min(minx, pos[i].fst);
      maxx = max(maxx, pos[i].fst);
      miny = min(miny, pos[i].snd);
      maxy = max(maxy, pos[i].snd);
    }
    cout << maxx - minx + 1 << " " << maxy - miny + 1 << endl;
  }
}


Measured memory_bytes: 2976
#include<stdio.h>
int main(){
    int H,W;
    for(;;){
        scanf("%d%d",&H,&W);
        if(H == 0 && W == 0){
            break;
        }
        
        for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
                if(i == 0 || i == H -1){
                    printf("#");
                }
                else if(i != 0 && (j == 0 || j == W - 1)){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
        
    }
    return 0;
}


Measured memory_bytes: 2680
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
	    String S = sc.next();
	    
	    
	    String T = S.substring(0,n/2);
	    String U = S.substring(n/2);
	    
	   // System.out.println(T); 
	   // System.out.println(U);
	    
	    if(n % 2 == 1) {
	    	System.out.println("No");
	    } else {
	    	if(T.equals(U)) {
	    		System.out.println("Yes");
	    	} else {
	    		System.out.println("No");
	    	}
	    }

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003;

int n, m;
int a[N], b[N];
char s[N];

int main()
{
    scanf("%s", s + 1);
    if (s[1] == '7' || s[2] == '7' || s[3] == '7') puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;  cin>>n;
    int arr[n][3];
    f(n)
    {
        cin>>arr[i][0] >> arr[i][1] >> arr[i][2];
    }
    int dp[n][3];
    dp[0][0] = arr[0][0],dp[0][1] = arr[0][1],dp[0][2] = arr[0][2];
    for(int i= 1;i<n;i++)
    {
        dp[i][0] = arr[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = arr[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = arr[i][2] + max(dp[i-1][0],dp[i-1][1]);
    }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    
    return 0;
 }

Measured memory_bytes: 2560
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a >= N:
    a = N+1
    break
  else:
    d += L[a]
    a += 1 

print(a)
  

Measured memory_bytes: 3060
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()

ans=0
wait=[]
for i in range(N):
    t=T[i]
    if len(wait)>0 and t-wait[0]>K:
        ans+=1
        wait=[]
    wait.append(t)
    if len(wait)==C:
        ans+=1
        wait=[]
if len(wait)>0:
    ans+=1
print(ans)

Measured memory_bytes: 7420
#include <bits/stdc++.h>
using namespace std;
#define long long long
const int MAXN = 1e6 + 7;
const long MOD = 1e9 + 7;
const long INF = 1e15 + 7;


main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int i, j, k;

    long A, B; cin >> A >> B;
    long mid = A + B >> 1;
    if (abs(A - mid) == abs(B - mid)) cout << mid;
    else cout << "IMPOSSIBLE";
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  priority_queue<int> q;
  for(int i=0;i<n;i++){
    q.push(a[i]);
  }
  ll ans=0;
  for(int i=0;i<m;i++){
    int k=q.top();
    q.pop();
    k /=2;
    q.push(k);
  }
  for(int i=0;i<n;i++){
    ans +=q.top();
    q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 1276
# -*- coding: utf-8 -*-

n,m = list(map(int,input().split()))
a = []
dic = {}

ac = 0
wa = 0

for i in range(m):
    a.append(list(map(str,input().split())))

for i in a:
    if i[1] == "AC" and not(i[0]+i[1] in dic.keys()):
        if i[0] + "WA" in dic.keys():
            wa += int(dic[i[0] + "WA"])
        dic[i[0] + i[1]] = "OK"
        ac += 1
    elif i[1] == "WA" and not(i[0]+"AC" in dic.keys()):
        if i[0] + "WA" in dic.keys():
            dic[i[0] + "WA"] = int(dic[i[0] + "WA"]) + 1
        else:
            dic[i[0] + "WA"] = 1

print(str(ac) + " " + str(wa))


Measured memory_bytes: 46308
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		String[] S = W.split(" ");
		int A = Integer.parseInt(S[0]);
		int B = Integer.parseInt(S[1]);

		int st =0;
		if(A < B){
			st = B;
		}else{
			st = A;
		}


		long ans = lcm(A,B);

		System.out.println(ans);



	}

private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}

private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

using static System.Console;
using static System.Math;
using System.Numerics;
class MainClass
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        Solve();
        Out.Flush();
    }
    //ここにプログラムを入力
    static void Solve()
    {
        var AB = Console.ReadLine().Split().Select(_=>(BigInteger)(decimal.Parse(_)*1000)).ToArray();
        WriteLine(AB[0]*AB[1]/1000000);
    }
}


Measured memory_bytes: 28464
#s = input()
import sys
sys.setrecursionlimit(1000000)
df = [[0,0],[1,0],[0,1],[2,2],[3,0]]

i = 5
while i <= 2*10**5-1:
    df.append([df[i-1][1]+1,df[i-2][0]+1])
    i += 1
def f(n):
    if n < 1:
        return 0
    else:
        return max(df[n])

s = input()
count = 0
sp = s[0]
sl = []
for i in range(len(s)):
    if sp == s[i]:
        count += 1
    else:
        sl.append(count)
        count = 1
    sp = s[i]
sl.append(count)

g = []
for i in range(len(sl)):
    if i==0:
        g.append([f(sl[i]),f(sl[i]-1)])
    else:
        if sl[i] > 1:
            x = max(g[i-1][1]+f(sl[i]-1)+1,g[i-1][0]+f(sl[i]))
            y = max(g[i-1][0]+f(sl[i]-1),g[i-1][1]+1+f(sl[i]-2))
            g.append([x,y])
        else:
            x = max(g[i-1][0]+1,g[i-1][1]+1)
            y = g[i-1][0]
            g.append([x,y])
print(g[-1][0])

Measured memory_bytes: 66008
// ABC168C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>

#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long double ld;
int main()
{
	int A, B, H, M;
	cin >> A >> B >> H >> M;
	ld rad = PI * 2 * ((ld)H / 12.0 + ((ld)M / 60.0) / 12.0 - (ld)M/ 60.0);
	ld rsq = (ld)(A*A + B * B) - (ld)(2 * A*B)*cosl(rad);
	printf("%20.20Lf\n", sqrtl(rsq));
}


Measured memory_bytes: 3488
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n; i >= 0; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

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

ll md(PL a, PL b){
    return abs(a.ff-b.ff) + abs(a.ss-b.ss);
}

int main(){
    ll H, W, D; cin >> H >> W >> D;
    vpl AA(H*W+1);
    rep(i, H) rep(j, W){
        ll a; cin >> a;
        AA[a] = {i,j};
    }
    
    vl sum(H*W+1);
    FOR(i, D+1, H*W+1){
        sum[i] = sum[i-D] + md(AA[i], AA[i-D]);
    }
    
    ll Q; cin >> Q;
    rep(_, Q){
        ll l, r; cin >> l >> r;
        cout << sum[r] - sum[l] << endstr;
    }
    
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

/* BIEN CUC BO BEGIN*/
	int t, n, A[3][100002], k;
	
	int DD[100002];
/* BIEN CUC BO END*/

int main(){ FIO;
	cin >> n;
	for (int i=1; i<=n; ++i){
		for (int j=0; j<=2; ++j){
			cin >> A[j][i];
		}
		for (int j=0; j<=2; ++j){
			A[j][i] = max(A[(j+1)%3][i-1],A[(j+2)%3][i-1]) + A[j][i];
		}
	}
	cout << max(A[0][n],max(A[1][n],A[2][n]));
return 0;}	

Measured memory_bytes: 1408
#include<stdio.h>

int main(){

char ty;
char c1,c2,c3,c4,ch5;
int n1=0,n2=0,n3=0,n4=0,N=0,S=0,P=0,K=0;
int n[5]={};
int F=0;
while(1){
//n1=c1-'0';n2=c2-'0';n3=c3-'0';n4=c4-'0';
	
	bool f=false;
	bool FF=false;
	do{
	scanf("%c%c%c%c%c",&c1,&c2,&c3,&c4,&ch5);
	ty=c1;
	
     if(ty==c1&&ty==c3&&ty==c4&&ty==c2)f=false;
	else f=true;

	if(ty=='0')f=true;
	if(f==false)printf("NA\n");

	}while(f!=true);
	if(c1=='0'&&c2=='0'&&c3=='0'&&c4=='0')break;
	F++;
	if(F==10001)break;
	
	if(c1=='6'&&c2=='1'&&c3=='7'&&c4=='4')FF=true;



	for(int i=0;i<4;i++)
	n[i]=0;
int cnt=0;


n[0]=c1-'0';n[1]=c2-'0';n[2]=c3-'0';n[3]=c4-'0';


for(int i=0;i<3;i++)
for(int j=3;j>i;j--)
if(n[j]>n[j-1]){int t=n[j];n[j]=n[j-1];n[j-1]=t;}

N=1000*n[0]+100*n[1]+10*n[2]+n[3];
S=1000*n[3]+100*n[2]+10*n[1]+n[0];

P=N-S;
if(FF!=true)cnt++;

while(P!=6174){
N=P;
K=P;n[0]=N/1000;
K=N%1000;n[1]=K/100;
K=N%100;n[2]=K/10;
K=N%10;n[3]=K;

//printf(" %d\n",N);

for(int i=0;i<3;i++)
for(int j=3;j>i;j--)
if(n[j]>n[j-1]){int t=n[j];n[j]=n[j-1];n[j-1]=t;}


N=1000*n[0]+100*n[1]+10*n[2]+n[3];
S=1000*n[3]+100*n[2]+10*n[1]+n[0];

cnt++;
P=N-S;

}
printf("%d\n",cnt);
}
return 0;
}

Measured memory_bytes: 976
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> v(n);
  rep(i,0,n)cin>>v[i];
  sort(all(v));

  ll ans=0;
  rep(i,0,n-2)rep(j,i+1,n-1)rep(k,j+1,n){
    if(v[i]+v[j]>v[k] && v[i]!=v[j] && v[j]!=v[k])++ans;
  }

  cout<<ans<<ENDL;

}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3652
#include"bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>

using namespace std;

struct UF {
	vector<int> belong;
	vector<int> size;
	void resize(int n) {
		belong.assign(n + 1, -1);
		size.assign(n + 1, 1);
	}
	inline int root(int b) {
		if (belong[b] == -1) {
			return b;
		}
		belong[b] = root(belong[b]);
		return belong[b];
	}
	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		belong[a] = b;
		size[b] += size[a];
	}
};
UF uf;
#define MAX 100002
int col[MAX];
vector<int> v[MAX];

int ed ;
int c1;
int c2;
inline bool dfs(int b,int c,int pr=-1) {
	if (col[b] != -1) {
		if (col[b] == c) {
			return true;
		}
		return false;
	}
	if (c == 0) {
		c1++;
	}
	else {
		c2++;
	}
	col[b] = c;
	bool ok = true;
	for (int go : v[b]) {
		if (pr == go)continue;
		ok&=dfs(go, c ^ true, b);
		ed++;
	}
	return ok;
}

int main() {
	memset(col, -1, sizeof(col));
	int n;
	int m;
	scanf("%d%d", &n, &m);
	uf.resize(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		uf.merge(a, b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	long long int way = 0;
	for (int i = 0; i < n; i++) {
		ed = 0;
		if (uf.root(i) == i) {
			c1 = 0;
			c2 = 0;
			bool can=dfs(i,0);
			
			if (can == false) {
				long long int sz = uf.size[i];
				if (sz >= 3) {
					way += sz*(sz - 1) / 2LL;
				}
				else {
					way += ed;
				}
			}
			else {
				if (uf.size[i] >= 3) {
					long long int sz = uf.size[i];
					long long int f = c1;
					long long int ff = c2;
					way += f*ff;
					continue;
					way += f*(f - 1) / 2LL;
					f = sz - (sz / 2);
					way += f*(f - 1) / 2LL;
					way += ed;
				}
				else {
					way += ed;
				}
			}
		}
	}
	way -= m;
	printf("%lld\n", way);
	return 0;
}

Measured memory_bytes: 7296
n = int(input())
s = input()

m = n
turn = s[1:].count('E')
m = min(turn, m)
for i in range(1, n):
    if s[i-1] == 'W': turn += 1
    if s[i] == 'E': turn -= 1

    m = min(turn, m)

print(m)

Measured memory_bytes: 3672