akhauriyash/Code-Regression huggingface dataset:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

diff = sorted([A%10, B%10, C%10, D%10, E%10])
mindiff = 0
for x in diff:
    if x != 0:
        mindiff = x
        diff.remove(mindiff)
        break

sum = 0
for x in (A, B, C, D, E):
    sum = sum + x
for x in diff:
    if x != 0:
        sum = sum + (10 - x)

print(sum)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N,H,W;

void solve(){
	cout<<(N - H + 1)*(N - W + 1)<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>N>>H>>W;
		solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a,b;
    cin >>a>>b;

    int ans;
    if(a<6) ans=0;
    else if(a<13) ans = b/2;
    else ans = b; 

    cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  int n; cin >> n;
  int N = 1<<n;
  V a(N); cin >> a;

  VV v(N, V(2));
  rep(i, N) v[i][0] = a[i];

  rep(i, n) {
    rep(S, N) if (!(S>>i&1)) {
      int S2 = S | (1<<i);
      for (auto e : v[S]) {
        chmax(v[S2][1], e);
        if (v[S2][0] < v[S2][1]) swap(v[S2][0], v[S2][1]);
      }
    }
  }

  V ans(N);
  rep2(S, 1, N) {
    for (auto e : v[S]) ans[S] += e;
    chmax(ans[S], ans[S-1]);
    cout << ans[S] << '\n';
  }
  return 0;
}


Measured memory_bytes: 19780
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;

int main(){
  int m;
  string s;

  cin >> m;
  for(int x=0;x<m;x++){
    cin >> s;
    set<string> ans;
    for(int i=1;i<s.size();i++){
      string a[2],b[2];
      a[0] = a[1] = s.substr(0,i);
      b[0] = b[1] = s.substr(i);
      reverse(a[1].begin(),a[1].end());
      reverse(b[1].begin(),b[1].end());

      for(int j=0;j<2;j++){
	for(int k=0;k<2;k++){
	  ans.insert(a[j]+b[k]);
	  ans.insert(b[j]+a[k]);
	}
      }
    }
    cout << ans.size() << endl;
  }
}

Measured memory_bytes: 1292
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int N, C; cin >> N >> C;
	vector<vector<int>> s(32, vector<int>(100005));
	for (int i = 0; i < N; i++) {
		int a, b, c; cin >> a >> b >> c;
		s[c][a]++;
		s[c][b + 1]--;
	}
	for (int c = 0; c <= C; c++) {
		for (int i = 0; i < 100002; i++) s[c][i + 1] += s[c][i];
	}
	int ans = 0;
	for (int i = 0; i < 100002; i++) {
		int cnt = 0;
		for (int j = 0; j <= C; j++) {
			cnt += s[j][i] >= 1;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 13184
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/15/20 19:44:33
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,k,c; cin>>n>>k>>c;
  string s; cin>>s;
  vector<int> L(k), R(k);
  int d = 0;
  for (int i = 0; i < s.size() and d < k; i++) {
    if (s[i] == 'x') continue;
    L[d++] = i;
    i += c;
  }
  d = k-1;
  for (int i = n-1; i >= 0 and d >= 0; i--) {
    if (s[i] == 'x') continue;
    R[d--] = i;
    i -= c;
  }
  vector<int> ans;
  for (int i = 0; i < k; i++) {
    if (L[i] == R[i])
      cout << L[i]+1 << endl;
  }

  return 0;
}


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

int main() {
  char a;
  cin >> a;
  char b;
  cin >> b;
  char c;
  cin >> c;
  char d;
  cin >> d;
  char e;
  cin >> e;
  char f;
  cin >> f;
  
  if(a==f && b==e && c==d) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: i32
    }

    solve(n);
}

fn solve(n: i32) {
    match n % 10 {
        2 | 4 | 5 | 7 | 9 => println!("hon"),
        0 | 1 | 6 | 8 => println!("pon"),
        _ => println!("bon"),
    }
}


Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, m, q, i, j, a, b;
	cin >> num >> m >> q;
	vector<vector<int>> d(num + 1, vector<int>(num + 1, 0));
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		d[a][b]++;
	}
	for (i = 1; i <= num; i++) {
		for (j = 1; j <= num; j++) {
			d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];
		}
	}
	for (i = 0; i < q; i++) {
		cin >> a >> b;
		cout << d[b][b] - d[a - 1][b] << "\n";
	}
	return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  string ans1 = "";
  int ans2 = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      string s;
      cin >> s;
      if (s == "snuke") {
        ans1 = 'A' + j;
        ans2 = i + 1;
      }
    }
  }
  cout << ans1 << ans2 << endl;
  return 0;
}

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

int main() {
  vector<int>x(5);
  rep(i,5){
    cin >> x.at(i);
  }
  
  int k;
  
  rep(i,5){
    if(x.at(i)==0){
      k=i+1;
    }
  }
  cout << k << endl;
      
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
const long mod=998244353;
int N,K;
int L[10],R[10];
long dp[2<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<K;i++)cin>>L[i]>>R[i];
	dp[0]=1;
	dp[1]=-1;
	for(int i=0;i<N;i++)
	{
		long now=dp[i]=(dp[i]%mod+mod)%mod;
		dp[i+1]+=now;
		for(int j=0;j<K;j++)
		{
			if(i+L[j]<N)dp[i+L[j]]+=now;
			if(i+R[j]+1<N)dp[i+R[j]+1]-=now;
		}
	}
	cout<<dp[N-1]<<endl;
}


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

using namespace std;

typedef long long ll;

int main() {
  int a, b; cin >> a >> b;
  int origin = (b - 1 + a - 2) / (a - 1);
  int cur = 1;
  int cnt = 0;
  while(true) {
    if(cur * a >= b) {
      break;
    }
    cur *= a;
  }
  int has = (cur - 1) / (a - 1);
  for(int i = 0; i <= 50; i++) {
    if(i * (a - 1) >= b - cur and i <= cur) {
      assert(has + i == origin);
      cout << has + i << '\n';
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int n, i, num, min, max;
    long int sum;

    scanf("%d", &n);

    scanf("%d", &num);
    min = max = sum = num;
    for (i=1; i<n; i++){
        scanf("%d", &num);
        if (num > max) max = num;
        if (num < min) min = num;
        sum += num;
    }
    
    printf("%d %d %ld\n", min, max, sum);

    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 1; i <= n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
#define FI first
#define SE second
#define VI vector<int>
#define CLR(x) memset(x, 0, sizeof(x))
#define SZ(x) (x.size())
#ifdef QWERTIER
#define err(x) cerr<<x<<endl;
#else
#define err(x)
#endif
typedef long long LL;


#define M 10000010
int primes[M], prime_cnt, not_prime[M];
void get_primes() {
  not_prime[1] = 1;
  for (int i = 2; i <= M-10; i++) {
    if (!not_prime[i]) {
      primes[prime_cnt++] = i;
    }
    for (int j = 0; j < prime_cnt && i * primes[j] <= M-10; j++) {
      not_prime[i*primes[j]] = 1;
      if (i%primes[j] == 0)
        break;
    }
  }
}

#define N 110

int vis[N], g[N][N], cand[N], L, R;
bool dfs(int u) {
  if (vis[u])
    return false;
  vis[u] = 1;
  FOR (v, R) {
    if (g[u][v] && (!cand[v] || dfs(cand[v]))) {
      cand[v] = u;
      return true;
    }
  }
  return false;
}

int n, a[N], b[N];
int main() {
#ifdef QWERTIER
  freopen("in.txt", "r", stdin);
#endif
  get_primes();
  scanf("%d", &n);
  set<int> st;
  FOR (i, n) {
    scanf("%d", &a[i]);
    st.insert(a[i]);
  }
  vector<int> b;
  for (auto i : st) {
    if (st.count(i-1) == 0) {
      b.push_back(i);
    }
    if (st.count(i+1) == 0) {
      b.push_back(i+1);
    }
  }
  n = b.size();
  REP (i, n) {
    if (b[i]%2 == 1) {
      L++;
      R = 0;
      REP (j, n) {
        if (b[j] % 2 == 0) {
          R++;
          if (!not_prime[abs(b[i]-b[j])]) {
            g[L][R] = 1;
          }
        }
      }
    }
  }
  R = 0;
  REP (i, n)
    R += (b[i] % 2 == 0);
  int k = 0;
  FOR (i, L) {
    memset(vis, 0, sizeof(vis));
    if (dfs(i))
      k++;
  }

  printf("%d\n", k + ((L-k)/2+(R-k)/2)*2 + ((L-k)%2)*3);
  return 0;
}


Measured memory_bytes: 43264
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    int N,M,a[50],b[50],c[50],d[50];
    cin >> N >> M;
    for(int i = 0;i < N;i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0;i < M;i++){
        cin >> c[i] >> d[i];
    }
    for(int i = 0;i < N;i++){
        int mind = 1000000000,minn;
        for(int j = 0;j < M;j++){
            if(mind > abs(a[i]-c[j])+abs(b[i]-d[j])){
                mind = abs(a[i]-c[j])+abs(b[i]-d[j]);
                minn = j;
            }
        }
        cout << minn + 1 << endl;
    }
}

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

using namespace std;

int main()
{
	int d, g, p[10], c[10];
	cin >> d >> g;
	for (int i = 0; i < d; i++)
		cin >> p[i] >> c[i];
	int ans = 1000;
	for (int bit = 0; bit < (1 << d); bit++)
	{
		int sum = 0, cnt = 0, m = -1;
		for (int i = 0; i < d; i++)
		{
			if (bit >> i & 1)
			{
				sum += 100 * (i + 1) * p[i] + c[i];
				cnt += p[i];
			}
			else
				m = max(m, i);
		}
		if (sum < g)
			if ((g - sum + 100 * (m + 1) - 1) / (100 * (m + 1)) < p[m])
				cnt += (g - sum + 100 * (m + 1) - 1) / (100 * (m + 1));
			else
				continue;
		ans = min(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c,ans=0,ans2=0;
char ch;
int main(){
  while(cin>>a>>ch>>b>>ch>>c){
    if(a*a+b*b==c*c)ans++;
    if(a==b)ans2++;
  }
  cout<<ans<<endl<<ans2<<endl;
  return 0;
}



Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
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; }
inline ll pow2(const int n) { return 1ll << n; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
// 1. 問題よくよめえええええええええええええええええええええええええ
// 2. intオーバーフロー << * + あたり
// 3. 落ち着け

int AB, BC, CA;

int main() {
    cin >> AB >> BC >> CA;
    double s = (AB + BC + CA) / 2.0;
    double S = sqrt(s * (s - AB) * (s - BC) * (s - CA));

    int ans = (int)(S + EPS);
    write(ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  
  int H,N,a,i;
  int sum=0;
  
  scanf("%d",&H);
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a);
    sum += a;
  }
  
  if(sum < H) printf("No\n");
  if(sum >=H) printf("Yes\n");
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String N = sc.nextLine();
		if(N.charAt(0)==N.charAt(2))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}


Measured memory_bytes: 22100
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        double h = (double)2*x/(a*b);
        if (h>a) {
            double h_2 = (double)2*b/a-(double)2*x/(double)a/(double)a/(double)a;
            // System.out.println("h_2: " + h_2);
            // System.out.println("tan: " + )
            System.out.println(Math.toDegrees(Math.atan(h_2)));
        } else {
            System.out.println(90-Math.toDegrees(Math.atan(h/b)));
        }
        // System.out.println("h: " + h);
        // long N = Long.parseLong(sc.next());
        // System.out.println(Math.atan(N));
        // System.out.println(Math.toDegrees(Math.atan(N)));
    }
}

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

int Max = 0;
int Min = 110;

int water(vector<int> h) {
    rep(i, h.size()) h[i] -= Min;
    int count = Min;
    for(int i = 0; i <= Max; i++) {
        rep(j, h.size()) {
            if(h[j] != 0) {
                h[j]--;
                while(h[j + 1] != 0) {
                    h[j + 1]--;
                    j++;
                }
                count++;
            }
        }
    }
    return count;
}
int main () {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) {
        cin >> h[i];
        Max = max(h[i], Max);
        Min = min(h[i], Min);
    }
    cout << water(h) << endl;
}

Measured memory_bytes: 3572
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    long long a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    long long ans=1,odd=a[0]%2==0?2:1;
    for(int i=0;i<n;i++)ans*=3;
    for(int i=1;i<n;i++){
        if(a[i]%2==0)odd*=2;
    }
    printf("%lld",ans-odd);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int n = 10005; // グラフの頂点の個数
int c = 0; //強連結成分
vector<vector<int>> graph(n,vector<int>()); //普通のグラフ
vector<vector<int>> revgraph(n,vector<int>());//逆辺を貼ったグラフ
vector<bool> seen(n,false); //dfsですでにその頂点を見たかどうかの判定
vector<int> postorder; //１回目のdfsでのpostorder
vector<int> sccgroup(n,-1); //強連結分解index 小さいほうがDAGの前の方 

void dfs(int i){
    seen[i] = true;
    for(int v:graph[i]){
        if(seen[v]) continue;
        dfs(v);
    }
    postorder.push_back(i);
}

void revdfs(int i){
    sccgroup[i] = c;
    seen[i] = true;
    for(int v:revgraph[i]){
        if(seen[v]) continue;
        revdfs(v);
    }
}

void scc(){
    for(int i=0;i<n;i++){
        if(!seen[i]) dfs(i);
    }

    for(int i=0;i<n;i++) seen[i] = false;
    for(int i=n-1;i>=0;i--){
        if(!seen[postorder[i]]){
            revdfs(postorder[i]);
            ++c;
        }
    }
}

int main(){
    int e;
    cin >> n >> e;
    rep(i,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
        revgraph[t].push_back(s);
    }

    scc();

    int q;
    cin >> q;
    while(q--){
        int u,v;
        cin >> u >> v;
        if(sccgroup[u] == sccgroup[v]) cout << 1 << endl;
        else cout << 0 << endl;
    }    
    return 0;
}


Measured memory_bytes: 4704
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int a[100010], l[100010], r[100010]; 
int main() {
  int n;
  cin >> n;
  rep(i,n) cin >> a[i];
  l[0] = 0;
  rep(i,n) {
    l[i+1] = __gcd(l[i],a[i]);
  }
  r[n+1] = 0;
  irep(i,n) {
    r[i] = __gcd(r[i+1],a[i]);
  }
  int ans = 0;
  for (int i = 0; i <= n; i++)
  {
    int now = __gcd(l[i], r[i+1]);
    ans = max(ans,now);
  }
  cout << ans << endl;
  //rep(i,n+1) cout << r[i] << endl;
  return 0;
}

Measured memory_bytes: 4692
n = gets.to_i

act = Array.new(n)
for i in 0..n - 1
    act[i] = gets.chomp.split(" ").map(&:to_i)
end

happiness = Array.new(n).map{Array.new(3, 0)}
happiness[0] = [act[0][0], act[0][1], act[0][2]]

for i in 1..n - 1
    # day2~
    for j in 0..2
        # find the maximum value for a, b, c today
        max = 0
        for k in 0..2
            # find the maximum until yersterday
            if (k != j) && (max < happiness[i - 1][k])
                max = happiness[i - 1][k]
            end
        end
        happiness[i][j] = max + act[i][j]
    end
end

puts happiness[n - 1].sort[2]

Measured memory_bytes: 14588
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){

    long long int N,M,K;
    cin >> N >> M >> K;
    long long int A[N],B[M];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < M; i++){
        cin >> B[i];
    }

    long long int Atime = K;
    long long int last_num = 0;
    

    for(int i = 0; i < N; i++){
        last_num = i;
        Atime -= A[i];
        if(Atime < 0){
            Atime += A[i];
            last_num = i - 1;
            break;
        }
    }

    vector<int> ANS(M + 1,last_num + 1);

    bool OVER = false;

    for(int i = 0; i < M; i++){
        if(i >= 1){
            ANS[i] = ANS[i-1];
        }
        while(Atime - B[i] < 0){
            if(last_num == -1){
                OVER = true;
                break;
            }
            Atime += A[last_num];
            last_num --;
            ANS[i] --;
            
        }
        if(OVER){
            break;
        }
        
        Atime -= B[i];
        ANS[i] ++;
    }

    sort(ANS.begin(), ANS.end(),greater<int>());

    cout << ANS[0] << endl;

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> ii;
typedef std::pair<int, ii> iii;
typedef std::pair<ull, ull> ull2;
typedef std::pair<ll, ll> ll2;
typedef std::pair<ll, ll2> ll3;
typedef std::pair<double, double> dd;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

int main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int T;
    std::cin>>T;
    while(T--){
        ll N, A, B, C, D;
        std::cin>>N>>A>>B>>C>>D;
        std::priority_queue<ll2, std::vector<ll2>, std::greater<ll2>> Q;
        std::unordered_set<ll> vis;
        Q.push({0, N});
        ll res = D * N;
        if(res < 0) res = LLONG_MAX;
        while(!Q.empty()){
            ll2 cur = Q.top();
            Q.pop();
            if(vis.find(cur.se) != vis.end()) continue;
            vis.insert(cur.se);
            // std::cout<<cur.fi<<" "<<cur.se<<"\n";
            if(cur.se == 1){
                res = std::min(res, cur.fi + D);
                break;
            }
            if(cur.fi+cur.se*D > 0)
                res = std::min(res, cur.fi+cur.se*D);
            std::vector<ll2> div(3);
            div[0] = {2, A}; div[1] = {3, B}; div[2] = {5, C};
            for(ll2 d : div){
                if(cur.se%d.fi == 0) Q.push({cur.fi+d.se, cur.se/d.fi});
                else{
                    ll del1 = cur.se % d.fi;
                    ll del2 = (d.fi - del1) % d.fi;
                    Q.push({cur.fi+d.se+del1*D, (cur.se-del1)/d.fi});
                    Q.push({cur.fi+d.se+del2*D, (cur.se+del2)/d.fi});
                }
            }
        }
        std::cout<<res<<"\n";
    }
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

int sa(int x, int y){
    int ans;
    if (x < y){
        ans = ((y-x)+1) / 2 + (y-x)%2;
    } else {
        ans = x-y;
    }
    return ans;
}


int main()
{
    int a, b, c;
    cin >> a >> b >> c;
 
    int ans = sa(a, b) + sa(c, b);
    ans = min(ans, sa(a, c)+sa(b, c));
    ans = min(ans, sa(b, a)+sa(c, a));
    
    cout << ans << endl;
}



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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> high(N);
  for(int i =0;i<N;i++){
    cin >> high.at(i);
  }
  vector<char> michi(N,1);
  int A,B;
    for(int i=0;i<M;i++){
      cin >> A >> B;
      A--;
      B--;
      if(high.at(B) > high.at(A)){
        michi.at(A) = 0;
      }
       if(high.at(A) > high.at(B)){
        michi.at(B) = 0;
      }
      else if(high.at(B) == high.at(A)){
        michi.at(A) = 0;
        michi.at(B) = 0;
      }
              }

  int ans =0;
  for(int i=0;i<N;i++){
    if(michi.at(i) == 1){
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3760
using System;

namespace a
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int n = int.Parse(N);
            int sn = 0;
            for(int i = 0; i<N.Length;i++)
            {
                
                sn = sn + int.Parse(N[i].ToString());
            }
            if(n%sn==0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IN(type, n) type n; cin >> n
using namespace std;

int main() {
  IN(string, S);
  if (S.at(1) == 'S') {
    if (S.at(0) == 'R' || S.at(2) == 'R') {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    if (S.at(0) == 'S' && S.at(2) == 'S') {
      cout << 1 << endl;
    } else if (S.at(0) == 'R' && S.at(2) == 'R') {
      cout << 3 << endl;
    } else {
      cout << 2 << endl;
    }
  }

  return 0;
}


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

namespace _0001
{
    class Program
    {
        static void Main(string[] args)
        {
            // 山の高さ10個を読み込み、その中から上位3つを出力するプログラム

            int[] height = new int[10];

            for (int i=0;i<10;i++)
            {
                height[i] =int.Parse(Console.ReadLine());
            }
            Array.Sort(height);

            Console.WriteLine(height[9]);
            Console.WriteLine(height[8]);
            Console.WriteLine(height[7]);
        }
    }
}



Measured memory_bytes: 15888
/*package whatever //do not write package name here */

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

class Main {
	public static void main (String[] args) {
	    Scanner sc = new Scanner(System.in);
	    char s[] = sc.next().toCharArray();
	    if(s[2]==s[3] && s[4]==s[5])
		System.out.println("Yes");
		else 
		System.out.println("No");
	}
}

Measured memory_bytes: 21588
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <stdio.h>
#include <string.h>
int n;
char com[15];
char str[15];
 
int C[1777771];
 
int g(char ch){
  if(ch=='A')return 1;
  if(ch=='G')return 2;
  if(ch=='T')return 3;
  return 4;
}
 
int f(){
  int res=0;
  for(int i=0;str[i]!='\0';i++){
    res=res*4+g(str[i]);
  }
  return res;
}
 
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s %s",com,str);
 
    int key=f();
     
    if(com[0]=='f'){
      int ans=C[key%1777771];
      if(ans)printf("yes\n");
      else printf("no\n");
    }else{
      C[key%1777771]=1;
    }
  }
  return 0;
}


Measured memory_bytes: 8044
# coding: utf-8
import math
from functools import reduce

K = int(input())
tmp = []

c = 0
for i in range(K):
    for j in range(K):
        tmp.append(math.gcd(i + 1, j + 1))
        c = c + 1

tmp2 = []
for k in tmp:
    for m in range(K):
        tmp2.append(math.gcd(k, m+1))

print(sum(tmp2))

Measured memory_bytes: 72028
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var A = parseInt(input[0], 10);
	var B = parseInt(input[1], 10);
	var sumAB = A + B;
  	if(sumAB % 2){
    	console.log('%s',"IMPOSSIBLE");
    }else{
    	console.log('%d',sumAB / 2);
    }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k,x;
    cin >> k >> x;
    if(500*k>=x){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

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

int main() {
	int N;
  	cin >> N;
  
  	vector<int> vec(N);
  	
  for (int i = 0; i < N; i++){
  	cin >> vec[i];
  }
  
  	int Alice = 0;
  	int Bob = 0;
  	sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
  
  	for(int i = 0; i < N; i++) {
    	if(i % 2 == 0) {
         Alice += vec[i];
        }else {
         Bob += vec[i];
        }
    }
  
  	cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define db(x) cerr<<#x<<" = "<<x<<"\n"
using namespace std;

const int MAX=19,INF=1e9;
int n,a[2][MAX],f[1<<MAX][55];
bool mark[1<<MAX][55];

int getBit(int x,int k) {
	return (x>>k)&1;
}

int dp(int mask,int maxn) {
	if(mask==(1<<n)-1)
		return 0;
	if(mark[mask][maxn])
		return f[mask][maxn];
	f[mask][maxn]=INF;
	mark[mask][maxn]=true;
	int cnt=__builtin_popcount(mask),cnt0=0;
	for(int i=0;i<n;i++) {
		if(getBit(mask,i)==0&&maxn<=a[cnt%2][i])
			f[mask][maxn]=min(f[mask][maxn],dp(mask+(1<<i),a[cnt%2][i])+cnt0);
		cnt0+=1-getBit(mask,i);
	}
	return f[mask][maxn];
}

int main() {
	ios_base::sync_with_stdio(false);
	// freopen("input","r",stdin);
	cin>>n;
	for(int i=0;i<=1;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	for(int i=1;i<n;i+=2)
		swap(a[0][i],a[1][i]);
	cout<<(dp(0,0)==INF?-1:dp(0,0));
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 5;

int n, arr[maxN];

int main() {
	ios_base::sync_with_stdio(0);
	cin>>n;
	RI(i, n) cin>>arr[i];
	for (int i = n; i >= 1; i -= 2) {
		cout<<arr[i]<<" ";
	}
	int start = 1;
	if (n % 2 == 1) start++;
	for (int i = start; i <= n; i += 2) {
		cout<<arr[i]<<" ";
	}
	return 0;
}


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

int main() {
    std::string s;
    std::cin >> s;

    bool flag = false;
    for(int i; i < s.length(); i++) {
        if(s[i] == '7') {
            flag = true;
        }
    }

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


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int A[111111];

int dp[55][2];

signed main(){
    cin>>N>>K;
    rep(i,N)cin>>A[i];

    for(int i=0;i<50;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                if(j==0&&(K>>i&1)<k)continue;
                int tmp=0;
                rep(l,N)tmp+=((A[l]>>i&1)^k)<<i;
                chmax(dp[i+1][j],dp[i][j|((K>>i&1)!=k)]+tmp);
            }
        }
    }
    cout<<dp[50][0]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<unordered_map>
#include<utility>
template<typename T>
class UnionFind {
public:
  void unite(const T& a, const T& b) {
    T x = find(a), y = find(b);
    if(rank_[x] < rank_[y]) std::swap(x, y);
    parent_[y] = x;
    if(rank_[x] == rank_[y]) rank_[x] += 1;
  }
  const T find(const T& x) {
    if(!parent_.count(x)) {
      rank_[x] = 1;
      return parent_[x] = x;
    }
    return (parent_[x] == x) ? x : (parent_[x] = find(parent_[x]));
  }
private:
  std::unordered_map<T, T> parent_;
  std::unordered_map<T, int> rank_;
};

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

struct Query {int S, T;};

struct Edge {int from, to, weight;};

typedef vector<vector<Edge>> Graph;

const vector<int> Dijkstra(const Graph& G, const vector<int>& start) {
  vector<int> d(G.size(), -1);
  priority_queue<tuple<int,int>, vector<tuple<int,int>>, greater<tuple<int,int>>> q;
  for(auto v: start) q.emplace(0, v);
  while(!q.empty()) {
    int cost, v;
    tie(cost, v) = q.top();
    q.pop();
    if(~d[v]) continue;
    d[v] = cost;
    for(const auto& e: G[v]) q.emplace(cost + e.weight, e.to);
  }
  return d;
}

// Kruskal
const vector<int> solve(const Graph& G, const vector<int>& F, const vector<Query>& query) {
  vector<int> res(query.size());
  vector<set<int>> qset(G.size());
  for(int i = 0; i < query.size(); ++i) {
    qset[query[i].S].insert(i);
    qset[query[i].T].insert(i);
  }
  auto d = Dijkstra(G, F);
  set<Edge, function<bool(Edge, Edge)>> E([](Edge lhs, Edge rhs){
    if(lhs.weight != rhs.weight) return lhs.weight > rhs.weight;
    if(lhs.from != rhs.from) return lhs.from < rhs.from;
    return lhs.to < rhs.to;
  });
  for(const auto& list: G) for(const auto& e: list) E.insert({e.from, e.to, min(d[e.from], d[e.to])});
  UnionFind<int> group;
  while(!E.empty()) {
    auto e = *begin(E);
    E.erase(begin(E));
    int u = group.find(e.from);
    int v = group.find(e.to);
    if(u == v) continue;
    if(qset[u].size() > qset[v].size()) swap(u, v);
    for(const auto& q: qset[u]) {
      if(qset[v].count(q) && !res[q]) res[q] = e.weight;
      qset[v].insert(q);
    }
    group.unite(u, v);
    if(group.find(u) == v) {
      qset[u].clear();
    } else {
      qset[u] = qset[v];
      qset[v].clear();
    }
  }
  return res;
}

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

  Graph G(N + 1);
  for(int i = 0; i < M; ++i) {
    int A, B, L;
    cin >> A >> B >> L;
    G[A].push_back({A, B, L});
    G[B].push_back({B, A, L});
  }

  vector<int> F(K);
  for(auto& i: F) cin >> i;

  vector<Query> query(Q);
  for(auto& q: query) cin >> q.S >> q.T;

  for(const auto& i: solve(G, F, query)) cout << i << endl;
}

Measured memory_bytes: 55552
tmp = gets.chomp.to_i
ary = gets.chomp.split(" ").map(&:to_i)
m = 10 ** 18

if ary.include?(0)
  puts 0
else
  puts ary.inject { |v1, v2|
    if v1*v2 > m
      break -1
    end
    v1*v2
  }
end

Measured memory_bytes: 23388
S=input()
h=[1,-1]
e=[0,1]
f=["+","-"]
x=""
a=0
for i in e:
  for j in e:
    for k in e:
      a=int(S[0])+int(S[1])*h[i]+int(S[2])*h[j]+int(S[3])*h[k]
      if a==7:
        x=S[0]+f[i]+S[1]+f[j]+S[2]+f[k]+S[3]+"=7"
print(x)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#define F first
#define S second
using namespace std;
int n;
//long long int ph,pa,pd,ps;
long long int h[44444];
long long int a[44444];
long long int b[44444];
long long int s[44444];
pair<long double,int> p[44444];
long long int ad;
int main(void){
  cin >> n /*>> ph >> pa >> pd >> ps*/;
  for(int i = 0; i <= n; i++){
    cin >> h[i] >> a[i] >> b[i] >> s[i];
  }

  for(int i = 1; i <= n; i++){

    ad += max(a[i] - b[0],0LL);

    if(a[0] - b[i] <= 0){
      p[i-1].F = -1;
    }else{
      p[i-1].F = (long double)max(a[i] - b[0],0LL) / (long long int)((h[i]+a[0]-b[i]-1)/(a[0]-b[i]));
    }
    p[i-1].S = i;
  }
  sort(p,p+n,greater< pair<long double,int> >());

  long long int d = 0;
  for(int i = 0; i < n; i++){
    int pp = p[i].S;
    if(p[i].F >= 0){
      d += ad * ((h[pp]+a[0]-b[pp]-1)/(a[0]-b[pp]));
      if(s[0] > s[pp]) d -= max(a[pp] - b[0],0LL);
    }else if(max(a[pp]-b[0],0LL)){
      d += h[0];
    }
    if(h[0] <= d){
      cout << -1 << endl;
      return 0;
    }
    //cout << pp << endl;
    ad -= max(a[pp] - b[0],0LL);
  }
  cout << d << endl;
}

Measured memory_bytes: 3828
main :: IO ()
main = interact $ unlines . map (show . calc . words) . takeWhile ('?' `notElem`) . lines

calc :: [String] -> Int
calc [x,op,y] = calc' (read x) op (read y)
    where calc' x "+" y = x + y
          calc' x "-" y = x - y
          calc' x "*" y = x * y
          calc' x "/" y = x `div` y


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

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int[] count = new int[N];
        for (int i = 0; i < N; i++) {
            count[sc.nextInt() - 1]++;
        }
        int[] hist = new int[N + 1];
        for (int i = 0; i < N; i++) {
            hist[count[i]]++;
        }
        long[] used = new long[N + 1];
        int lack = 0;
        for (int i = 1; i <= N; i++) {
            lack += hist[i - 1];
            used[i] = used[i - 1] + lack;
        }
        int[] ans = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            ans[i] = N - (int) ((used[i] + i - 1) / i);
        }
        int[] out = new int[N + 1];
        for (int i = 1; i < N; i++) {
            for (int j = ans[i]; j > ans[i + 1]; j--) {
                out[j] = i;
            }
        }
        out[1] = N;
        PrintWriter writer = new PrintWriter(System.out);
        for (int i = 0; i < N; i++) {
            writer.println(out[i + 1]);
        }
        writer.flush();
    }
}


Measured memory_bytes: 92896
// 課題3_2 AtCoder Beginner Contest 168 A- (Therefore)
// nk777
 
#include <stdio.h>
 
int main(void){
    // 入力される整数N, Nの小数第1位を表すN_1
    int N, N_1;
 
    // Nを受け取る
    scanf("%d", &N);

    // Nの少数第1位を計算
    N_1 = N % 10;

    if (N_1 == 3)
    {
        // Nの少数第1位が3
        printf("bon\n");
    }
    else if (N_1 == 0 || N_1 == 1 || N_1 == 6 || N_1 == 8)
    {
        // Nの少数第1位が0,1,6,8
        printf("pon\n");
    }
    else
    {
        // Nの少数第1位が2,4,5,7,9
        printf("hon\n");
    }

    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;

  if (n <= 999) cout << "ABC" << endl;
  else cout << "ABD" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n;
string command;
list<int> lst;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> command;
		if (command == "insert") {
			int x;
			cin >> x;
			lst.push_front(x);
		}
		if (command == "delete") {
			int x;
			cin >> x;
			for (auto ite = lst.begin(); ite != lst.end(); ite++) {
				if (*ite == x) {
					lst.erase(ite);
					break;
				}
			}
		}
		if (command == "deleteFirst")lst.pop_front();
		if (command == "deleteLast")lst.pop_back();
	}
	if (lst.empty()) {
		cout << endl;
		return 0;
	}
	cout << *lst.begin();
	for (auto ite = ++lst.begin(); ite != lst.end(); ite++)cout << " " << *ite;
	cout << endl;
	return 0;
}


Measured memory_bytes: 34296
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, vector<ll> a) {
  int one = 0, two = 0, four = 0;
  for (ll i: a) {
    if (i % 4 == 0) ++four;
    else if (i % 2 == 0) ++two;
    else ++one;
  }
  cout << ((two == 0 && (four >= one - 1)) ||
           (four >= one)) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 1792
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 = new String[100100];  
        for(int i = 0; i < N; i++) S[i] = sc.next();
        int AC = 0;
        int WA = 0;
        int TLE = 0;
        int RE = 0;
        for(int i = 0; i < N; i++){
          if(S[i].equals("AC")) AC++;
          if(S[i].equals("WA")) WA++;
          if(S[i].equals("TLE")) TLE++;
          if(S[i].equals("RE")) RE++;
        }
      System.out.println("AC x " + AC);
      System.out.println("WA x " + WA);
      System.out.println("TLE x " + TLE);
      System.out.println("RE x " + RE);
    } 
}

Measured memory_bytes: 54676
n = int(input())
s = input()
r = []
g = []
b = [0]*40000
for i,j in enumerate(s):
  if j == 'R':
    r.append(i)
  if j == 'G':
    g.append(i)
  if j == 'B':
    b[i] += 1
cnt = len(r)*len(g)*sum(b)
for i in r:
  for j in g:
    if b[2*j-i] == 1 :
      cnt -= 1
    if b[2*i-j] == 1 :
      cnt -= 1
    if (i+j)%2 == 0 and b[(i+j)//2] == 1:
      cnt -= 1
print(cnt)

Measured memory_bytes: 9280
using System;
using System.Collections.Generic;
namespace ConsoleApplication27
{
    class Program
    {
        static void Main()
        {

            int n = int.Parse(Console.ReadLine());
 
            bool[] S = new bool[13];
            bool[] H = new bool[13];
            int[] C = new int[13];
            int[] D = new int[13];
 
            for (int i = 0; i < n; i++)
            {
                var data = Console.ReadLine().Split(' ');
                int rank = int.Parse(data[1]);
                if (data[0] == "S") S[rank - 1] = true;
                if (data[0] == "H") H[rank - 1] = true;
                if (data[0] == "D") D[rank - 1] = 1;
                if (data[0] == "C") C[rank - 1] = 1;
            }
 
            for (int i = 0; i < 13; i++)
                if (S[i] == false) Console.WriteLine("S {0}", i + 1);
            for (int i = 0; i < 13; i++)
                if (H[i] == false) Console.WriteLine("H {0}", i + 1);
            for (int i = 0; i < 13; i++)
                if (C[i] == 0) Console.WriteLine("C {0}", i + 1);
            for (int i = 0; i < 13; i++)
                if (D[i] == 0) Console.WriteLine("D {0}", i + 1);
        }
    }
}

Measured memory_bytes: 9104
from collections import defaultdict
from math import factorial


def perm(n, r):
    return factorial(n) // factorial(n - r)


def comb(n, r):
    return perm(n, r) // factorial(r)


n = int(input())
D = defaultdict(lambda: 0)
for _ in range(n):
    D["".join(sorted(input()))] += 1
print(sum([comb(v, 2) for v in D.values() if v > 1] + [0]))


Measured memory_bytes: 18224
#include <iostream>

 

using namespace std;

 

int main() 
{
    int i, x;
    for(i=1; i<=10000; i++)
    {
        cin >> x;
        if (x == 0)
            break;
        else
            cout << "Case " << i << ": " << x << endl;
    }
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

typedef long long ll;

#define MAXY 1000000000000000000

int main()
{
  ll X,Y;
  int cnt = 0;

  cin >> X >> Y;

  while ( X <= Y ) {
    ++cnt;
    X *= 2;
  }

  cout << cnt << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>



int main(){
  int n;
  double **X,**Y;
  int i,j;
  scanf("%d",&n);
  X=malloc((n+1)*sizeof(double *));
  for(i=0;i<=n;i++) X[i]=malloc(sizeof(double)*(pow(4,i)+1));
  Y=malloc((n+1)*sizeof(double *));
  for(i=0;i<=n;i++) Y[i]=malloc(sizeof(double)*(pow(4,i)+1));
  
  X[0][0]=0.0;
  X[0][1]=100.0;
  Y[0][0]=0.0;
  Y[0][1]=0.0;

  double cos60,sin60;
  cos60=0.5;
  sin60=pow(3,0.5)/2;
 
  int k,stop;
  for(i=1;i<=n;i++){
    k=0;
    stop=pow(4,i-1);
    for(j=0;j<stop;j++){
      X[i][4*j]=X[i-1][j];
      Y[i][4*j]=Y[i-1][j];
      X[i][4*j+1]=X[i][4*j] + (X[i-1][j+1]-X[i-1][j])/3;
      Y[i][4*j+1]=Y[i][4*j] + (Y[i-1][j+1]-Y[i-1][j])/3;
      X[i][4*j+2]=X[i][4*j+1] +cos60*(X[i-1][j+1]-X[i-1][j])/3 -sin60*(Y[i-1][j+1]-Y[i-1][j])/3;
      Y[i][4*j+2]=Y[i][4*j+1] +sin60*(X[i-1][j+1]-X[i-1][j])/3 +cos60*(Y[i-1][j+1]-Y[i-1][j])/3;
      X[i][4*j+3]=X[i][4*j] + 2*(X[i-1][j+1]-X[i-1][j])/3;
      Y[i][4*j+3]=Y[i][4*j] + 2*(Y[i-1][j+1]-Y[i-1][j])/3;
    }
    X[i][4*stop]=100.0;
    Y[i][4*stop]=0.0;
  }
  

  for(i=0;i<=pow(4,n);i++) printf("%lf %lf\n",X[n][i],Y[n][i]);
  return 0;
}






Measured memory_bytes: 2100
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LL long long
const int N = 100000+5;
using namespace std;
int x[N];
int dp[N][50];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++) scanf("%d",&x[i]);
    int L,Q;
    scanf("%d%d",&L,&Q);
    for(int i=1; i<=n ;i++){
        int left=i+1,right=n;
        while(left<=right){
            int mid=(left+right)/2;
            if(x[mid]<=L+x[i])left=mid+1;
            else right=mid-1;
        }
        if(x[i]+L>=x[n]) dp[i][0]=n;
        else dp[i][0]=left-1;
    }
    for(int i=1; i<=30; i++) for(int j=1; j<=n; j++) dp[j][i]=dp[dp[j][i-1]][i-1];
    while(Q--){
        int a,b;
        scanf("%d%d",&a,&b);
        if(b<a) swap(a,b);
        LL res=0;
        for(int i=30; i>=0; i--){
            if(dp[a][i]<b){
                res+=(1<<i);
                a=dp[a][i];
            }
        }
        printf("%lld\n",res+1);
    }
}

Measured memory_bytes: 20736
#include <iostream>
using namespace std; 
int main() {

	int a, b,c,d;
	int area1;
	int area2;
	cin >> a>> b>>c>>d;
	
	area1 = a * b;
	area2 = c * d;
	if (area1 > area2)
		cout << area1;
	else
		cout << area2;


}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int a,p;
    cin >> a >> p;
    p += a*3;
    cout << p/2 << endl;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    long long int ans = 0;
    s += 'x';
    int n = s.length(), a = 0, bc = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') a++;
        else if (i + 1 < n && s[i] == 'B' && s[i + 1] == 'C') {
            ans += a;
            i++;
        } else
            a = bc = 0;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640