akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

ll mod = 1e9+7;

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

  double a,b,x;
  cin >> a >> b >> x;
  x /= a;

  double ret = atan(a*a / (2 * (a*b - x)));
  if(ret < atan(a/b)){
    ret = atan(2*x / (b*b));
  }
  std::cout << std::fixed << std::setprecision(15);
  cout << 90.0 - ret * 180 / M_PI << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n, k, c; cin >> n >> k >> c;
  string s; cin >> s;
  int cur = 0;
  vector<int> l, r;
  rep(i, k) {
    while(s[cur] == 'x') cur++;
    l.emplace_back(cur), cur++;
    rep(j, c) cur++;
  }
  cur = 0;
  reverse(ALL(s));
  rep(i, k) {
    while(s[cur] == 'x') cur++;
    r.emplace_back(n-1-cur), cur++;
    rep(j, c) cur++;
  }
  reverse(ALL(r));
  rep(i, k) {
    if(l[i] == r[i]) cout << l[i]+1 << "\n";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 5552
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]

class Graph:
    def __init__(self,Vertex,Edge):
        self.V = Vertex
        self.E = Edge

Edge = [i+1 for i in range(N)]
Vertex = []
for i in range(N):
    for j in range(2,A[i][1]+2):
        Vertex.append((A[i][0],A[i][j]))

g = Graph(Vertex,Edge)

R = [[0 for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        if (i+1,j+1) in g.V:
            R[i][j] = 1

for i in range(N):
    for j in range(N):
        if j >= 1:
            print(" ",end="")
        print(R[i][j],end="")
    print()



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

using namespace std;
typedef long long ll;

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


    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j;
  
    ll K;
    vector<ll> a;

    ll Q,N;
    string S;
    cin>>N;
    ll flag=0;
    ll t1=0;
    ll t2=0;
    for(i=0;i<N;i++){
        cin>>Q;
        a.push_back(Q);
    }
for(i=0;i<N-2;i++){
if(a[i]>a[i+1]&&a[i+1]>a[i+2]){
    ans++;
}
if(a[i]<a[i+1]&&a[i+1]<a[i+2]){
    ans++;
}
}

        cout<< ans << endl;
 
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;



int main(){
  ll A;
  long double B;
  cin >> A >> B;
  cout << ll(A*B) << endl;
  return 0;
}


Measured memory_bytes: 3732
use proconio::input;
use std::collections::BTreeSet;
use std::ops::Bound::Excluded;
use std::ops::Bound::Unbounded;
use rand::Rng;

const C:usize = 26;
const N_ITER:usize = 4000000;

fn main() {

    input!{
        d:usize,
        c:[i32;C],
        s:[[i32;C];d],
    };
    let mut rng = rand::thread_rng();
    let mut occs = vec![BTreeSet::<i32>::new();C];
    for occ in &mut occs {
        occ.insert(-1);
    }

    let mut t:Vec<usize> = vec![0;d];
    let mut ans = 0;
    for day in 0..d {
        let mut tmp:Vec<i32> = s[day].iter().map(|&x|x).collect();
        for j in 0..C {
            let sc = (c[j] as i32) * ((day as i32) -*occs[j].iter().last().unwrap());
            tmp[j]+=sc;
        }
        let max_v = *tmp.iter().max().unwrap();
        let ti = tmp.iter().position(|&x|x==max_v).unwrap();

        t[day] = ti;
        ans += s[day][ti];
        occs[ti].insert(day as i32);
        for j in 0..26 {
            let sc = (c[j] as i32) * ((day as i32) -*occs[j].iter().last().unwrap());
            ans -= sc;
        }
    }
    for occ in &mut occs {
        occ.insert(d as i32);
    }    

    let sum_lr = |l,r,n| n*(l+r)/2;
    for _ in 0..N_ITER {
        let d = rng.gen::<usize>()%d;
        let q = rng.gen::<usize>()%C;
        let pre_q = t[d];
        let q = if q==pre_q {rng.gen::<usize>()%C} else {q};
        let pre_ans = ans;
        let mut try_change = |d:usize,q:usize|{
            let pre_q = t[d];
            ans-=s[d][pre_q];
            ans+=s[d][q];
            t[d]=q;
            let d = d as i32;
            // for pre_q
            let mut calc = |q:usize,is_ins:bool| {
                if is_ins {
                    occs[q].insert(d);
                }
                else {
                    occs[q].remove(&d);
                }
                let pre_d = *occs[q].range((Unbounded,Excluded(&d))).last().unwrap();
                let nex_d = *occs[q].range((Excluded(&d),Unbounded)).next().unwrap();
                let lbig = d - pre_d;
                let rbig = nex_d - pre_d -1;
                let lsml = 0;
                let rsml = nex_d-d-1;
                let sc = sum_lr(lbig,rbig,nex_d-d)-sum_lr(lsml,rsml,nex_d-d);
                sc
            };
            
            ans -= calc(pre_q,false)*c[pre_q];
            ans += calc(q,true)*c[q];
            ans
        };
        let now_ans = try_change(d,q);
        if now_ans<=pre_ans{
            try_change(d,pre_q);
        }
    }

    for tv in t {
        println!("{}",tv+1);
    }
}




Measured memory_bytes: 2708
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int N = 5e5 + 5;
const int M = 1e6 + 5;
const int Mod = 1e9 + 7;

int n, a[N];
vec G[N];
ll sum[N];
int sz[N];
ll ans[N];

ll f(ll x)
{
	return x * (x + 1) / 2;
}

void GetSz(int u, int p)
{
	sz[u] = 1;
	for (auto v : G[u])
	{
		if (v == p)continue;
		GetSz(v, u);
		sz[u] += sz[v];
	}
}

int Last[N];

void DFS(int u, int p)
{
	int color = a[u];
	int par = Last[color];
	sum[par] += sz[u];
	Last[color] = u;
	for (auto v : G[u])
	{
		if (v == p)continue;
		DFS(v, u);
		ans[color] += f(sz[v] - sum[u]);
		sum[u] = 0;
	}
	Last[color] = par;
}

int main()
{
	GO;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i < n; i++)
	{
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (int i = 1; i <= n; i++)
		Last[i] = n + i;
	GetSz(1, 1);
	DFS(1, 1);
	for (int i = 1; i <= n; i++)
	{
		if (i == a[1])
			continue;
		ans[i] += f(n - sum[i + n]);
	}
	for (int i = 1; i <= n; i++)
		cout << (f(n) - ans[i] )  << '\n';
	return 0;
}

Measured memory_bytes: 47384
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
 
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
int main() {
	int n,m;
	ll list[100][21] ={{0}};
	cin >> n >> m;
	list[0][m]=1;
	REP(i, n-2) {
		cin >> m;
		REP(j, 21){
			if(list[i][j]){
				if(j-m>=0)
					list[i+1][j-m]+=list[i][j];
				if(j+m<21)
					list[i+1][j+m]+=list[i][j];
			}
		}
	}
	cin >> m;

	cout << list[n-2][m] << endl;
}

Measured memory_bytes: 1180
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef pair<int, int> P;

#define INF (1<<29)

int n, m, res;
int a[1080], b[1080], c[1080];
int dist[108][108];

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

  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
      dist[i][j] = INF;
  
  for(int i = 0;i < m;i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
    dist[a[i]][b[i]] = c[i];
    dist[b[i]][a[i]] = c[i];
  }

  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
      for(int k = 0;k < n;k++)
	dist[j][k] = min(dist[j][i] + dist[i][k], dist[j][k]);
  
  for(int i = 0;i < m;i++){
    if(dist[a[i]][b[i]] != c[i])res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 888
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main(){

int N,M,Q;
cin>>N>>M>>Q;
ll table[N+1][N+1];
memset(table,0,sizeof(table));
rep(i,M){
    int L,R;
    cin>>L>>R;
    table[L][R]++;
}
rep3(i,N)rep3(j,N)table[i][j]+=table[i][j-1];
rep3(j,N)rep3(i,N)table[i][j]+=table[i-1][j];
ll ans[Q];
memset(ans,0,sizeof(ans));
rep(i,Q){
    int p,q;
    cin>>p>>q;
    ans[i]=table[q][q]-table[p-1][q];
}
rep(i,Q)cout<<ans[i]<<endl;
}

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

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

using namespace std;


void solve(int n){
	vector<string> v(n);
	rep(i,n){
		cin>>v[i];
	}
	map<string,int> used;
	vector<int> type(n),num(n);
	vector<int> par(n,-1);
	vector<int> start(n, 1);
	rep(i,n){
		string t = v[i];
		int val = 0;
		int pp = 1;
		if(t.back() == 'v'){
			t = t.substr(0, t.size()-1);
			par[i+1] = i;
			start[i] = 0;
		}
		if(t.size() == 0){
			continue;
		}
		if(t == "-"){
			continue;
		}
		int len = t.size();
		while(isdigit(t[len-1])){
			len--;
			val += pp*(t[len]-'0');
			pp *= 10;
		}
		t = t.substr(0, len);
		if(val > 1){
			start[i] = 0;
		}
		if(used.count(t) == 0){
			if(val > 1){
				used[t] = i;
			}
		}
		else{
			par[i] = used[t];
			if(val > 1){
				used[t] = i;
			}
			else{
				used.erase(t);
			}
		}
	}
	/*
	rep(i,n){
		cout<<i<<" "<<par[i]<<endl;
	}
	cout<<endl;
	*/
	int pos = 0;
	while(pos < n){
		if(start[pos]){
			int t = pos;
			while(t >= 0){
				cout<<t+1<<endl;
				t = par[t];
			}			
		}
		pos++;
	}
}			
					



int main(){
	int n;
	while(cin>>n, n){
		solve(n);
	}
}

Measured memory_bytes: 4348
#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i;
	long long int a[88];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int m[88], k[88], km[88];
	k[0] = 0;
	m[0] = 1000;
	km[0] = 0;
	for (i = 0; i < n; i++)
	{
		k[i + 1] = k[i];
		m[i + 1] = m[i];
		km[i + 1] = km[i];
		if (k[i + 1] < m[i] / a[i])
		{
			k[i + 1] = m[i] / a[i];
			km[i + 1] = m[i] % a[i];
		}
		else if (k[i + 1] == m[i] / a[i] && km[i + 1] < m[i] % a[i])
		{
			k[i + 1] = m[i] / a[i];
			km[i + 1] = m[i] % a[i];
		}
		if (m[i + 1] < a[i] * k[i] + km[i])
			m[i + 1] = a[i] * k[i] + km[i];
	}
	printf("%lld\n", m[n]);
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,D1,D2,i=0;
  cin>>N;
  while(N-->0){
    cin>>D1>>D2;
    if(D1==D2) i++;
    else i=0;
    if(i==3){cout<<"Yes"<<endl;return 0;}
  }
  cout<<"No"<<endl;return 0;
}


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

namespace ABC115 {
	class ABC115_B {
		static void Main(string[] args) {
			int N = int.Parse(Console.ReadLine());
			var input = new List<int>();
			for (int i = 0; i < N; i++)
				input.Add(int.Parse(Console.ReadLine()));

			Console.WriteLine(	GetTotalPrice(input));
		}
		private static int GetTotalPrice(List<int> input) {
			var sorted = input.OrderByDescending(n => n);
			return sorted.Skip(1).Sum() + sorted.First() / 2;
		}
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！
const double pi = 3.14159265359;


int main() {
  int A,B;
  cin >> A >> B;
  int ans = A*B;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  ll n;cin>>n;
  int d0[] = {3,5,7};
  vector<ll> now,old,ans;
  int d[] = {3,5,7};
  rep(i,3)now.push_back(d[i]);
  int ok = 1;
  while(ok){
    swap(now,old);
    now={};
    for(ll num:old){
      if(num>n){ok = 0;break;}
      rep(i,3){
        now.push_back(num*10+d[i]);
      }
    }
    for(ll num: now){
      if(num>n){ok=0;break;}
      ans.push_back(num);   
    }
  }
  
  int cnt=0;
  rep(i,ans.size()){
    if(ans[i]>n){break;}
    string s = to_string(ans[i]);
    int ch[]={0,0,0};
    rep(j,s.length()){
      if(s[j]=='3')ch[0] = 1;
      if(s[j]=='5')ch[1] = 1;
      if(s[j]=='7')ch[2] = 1;
    }
    if(ch[0]==1&&ch[1]==1&&ch[2]==1){cnt++;}
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include<math.h>
using namespace std;

int isprime(int x){
  if(x==2) return true;
  
  if(x<2 or x%2==0) return false;
  
  int i=3;
  while(i<=sqrt(x)){
    if(x%i==0) return false;
      i=i+2;
  }
  return true;
}


int main()
{
  int n,ans=0;
  while(cin>>n){
    if(isprime(n)==true) ans++;
  }
  cout<<ans<<endl;
 return 0;
}




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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int Q,H,S,D,N;
    cin >> Q >> H >> S >> D >> N;
    
    int L = min({Q*4,H*2,S});
    int d = min(2*L,D);
    
    int ans = 0,tea = 0;
    ans += N/2*d;
    tea += (N/2)*2;
    
    ans += (N-tea)*L;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var t = new string[]
			{ 
				"* = ****", "* =* ***", "* =** **", "* =*** *", "* =**** ",
				" *= ****", " *=* ***", " *=** **", " *=*** *", " *=**** "
			};

			var f = false;
			var n = "";
			while ((n = Console.ReadLine()) != null)
			{
				if (f) Console.WriteLine();
				else f = true;
				n = int.Parse(n).ToString("00000");
				for (int i = 0; i < 8; i++)
				{
					for (int j = 0; j < 5; j++)
					{
						Console.Write(t[n[j] - '0'][i]);
					}
					Console.WriteLine();
				}
			}
		}
	}
}

Measured memory_bytes: 5956
import numpy as np
n, m, c = list(map(int, input().split()))
b = np.asarray(list(map(int, input().split())))
ans = 0
for i in range(n):
    a = np.asarray(list(map(int, input().split())))
    if np.dot(a, b) + c > 0:
        ans = ans+1

print(ans)


Measured memory_bytes: 12488
#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>

#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())

#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 int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

struct edge {
    int from, to, cost;
    edge(int to): to(to), cost(1) {}
};

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() {
    LL n,m,s,t,u,v;
    cin >> n >> m;
    vector<vector<edge>> es(n);
    REP(i,0,m) {
        cin >> u >> v;
        --u; --v;
        swap(u, v);
        es[u].pb(v);
    } 
    cin >> s >> t;
    --s; --t;
    VVI visited(3, VI(n, -1));
    deque<PII> q;
    q.pb(t,0);
    visited[0][t] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        int index = p.first, d = p.second;
        for (auto &&e: es[index]) {
            if (visited[(d+1)%3][e.to] > -1) continue;
            visited[(d+1)%3][e.to] = d + 1;
            q.pb(e.to, d+1);
        }
    }
    if (visited[0][s] > -1) cout << visited[0][s] / 3 << endl;
    else cout << -1 << endl;
}

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

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

ll ans = 0;
int n;
vector<int> a;
int rec(vector<int> t){
    int l = t.size();
    if(l == n){
        ll prd = 1;
        for(int i=0; i<n; i++){
            prd *= t[i];
        }
        //cout << prd << endl;
        if(prd % 2 == 0) ans++;
        return 0;
    }
    vector<int> t1, t2, t3;
    t1 = t2 = t3 = t;
    t1.pb(a[l]+1);
    t2.pb(a[l]);
    t3.pb(a[l]-1);
    rec(t1);
    rec(t2);
    rec(t3);
}

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

    cin >> n;

    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        a.pb(t);
    }

    vector<int> init;
    rec(init);

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


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		ArrayList<Integer> m=new ArrayList<>();
		m.add(1);
		for(int x=6;x<=N;x*=6) m.add(x);
		for(int x=9;x<=N;x*=9) m.add(x);
		
		int[] a=new int[N+1];
		Arrays.fill(a, N+1);
		a[0]=0;
		int p=0;
		while(p<N){
			for(int x:m){
				if(p+x>N)continue;
				a[p+x]=Math.min(a[p]+1, a[p+x]);
			}
			p++;
		}
		
		System.out.println(a[N]);
	}

	public static int gcd(int a, int b) {
		return a%b==0 ? b : gcd(b,a%b);
	}
}


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

using lint = long long int;

int main(){
    int N;
    lint W;
    lint w1;
    lint temp_w;
    lint v4kind[4][102]={};
    int wcount[4]={};

    cin >> N >> W;
    cin >> w1 >> v4kind[0][1];
    wcount[0]++;
    for(int i=1;i<N;i++){
        cin >> temp_w;
        int diff = temp_w - w1;
        wcount[diff]++;
        cin >> v4kind[diff][wcount[diff]];
    }

    for(int i=0;i<4;i++){
        sort(v4kind[i]+1,v4kind[i]+wcount[i]+1,greater<lint>());
    }

    lint v_sum=0;
    lint tempv_i=0;
    for(int i=0;i<=wcount[0];i++){
        tempv_i += v4kind[0][i];
        lint tempv_j = tempv_i;
        for(int j=0;j<=wcount[1];j++){
            tempv_j += v4kind[1][j];
            lint tempv_k = tempv_j;
            for(int k=0;k<=wcount[2];k++){
                tempv_k += v4kind[2][k];
                lint tempv_l = tempv_k;
                for(int l=0;l<=wcount[3];l++){
                    tempv_l += v4kind[3][l];
                    if(w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l<=W){
                        v_sum = max(v_sum,tempv_l);
                    }
                }
            }
        }
    }
    
    cout << v_sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
	string s,t;
	cin>>s>>t;
	ll ans=0;
	for (int i = 0; i < s.length(); ++i)
	{
		ans+=(s[i]!=t[i]);
	}
	cout<<ans<<endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin>>T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3780
//




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


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        string s;
        cin>>s;
        if(s[s.length()-1]=='s') s+="es";
        else s+='s';
        cout<<s<<"\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    string s;

    cin >> s;

    int n = s.size();

    for(int i = 0; i < n; i++)
    {
        if(s[i] != s[n-1-i])
           cnt++;
    }

    cout << cnt/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;
use std::io::{Write, BufWriter};

// static MOD: usize = 998244353;
static MOD: usize = 1000000007;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! println_stderr(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

fn solve() {
    input! {
        n: usize,
        a: [i64;n],
    }  
    let mut ans = 0;
    for i in 0..n {
        for j in 0..n {
            if i==j {continue;}
            ans += a[i]*a[j];
        }
    }
    println!("{}", ans/2);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
n,t=map(int,input().split())
tl=list(map(int,input().split()))+[10**10]

ans=0
bef=0
for i in range(1,n+1):
  t_ans=t
  e_time=tl[i-1]+t
  if e_time>tl[i]:
    t_ans-=e_time-tl[i]
  ans+=t_ans
print(ans)

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

int heap[251];

int main(){
	ios_base::sync_with_stdio(false);

	int size;
	int val;
	cin >> size;
	
	for(int i = 1 ; i <= size; i ++){
		cin >> val;
		heap[i] = val;
	}
	for(int i = 1 ; i <= size; i ++){
		cout << "node " << i <<": ";
		//key
		cout << "key = " <<heap[i] << ", ";
		//pearent
		if(i!=1)cout << "parent key = " <<  heap[(i)/2] << ", " ;
		//left
		if(i*2 <= size)cout << "left key = " << heap[i*2] << ", "; 
		//right
		if(i*2 + 1 <= size)cout << "right key = " << heap[i*2 + 1] <<", ";
		//endl
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N;
    cin >> N;
    vector<ll> jousi(N),buka(N);

    for(ll i = 0;i < N - 1;i++){
        cin >> buka.at(i);
        jousi.at(i) = 0;
    }

    for(ll i = 0;i < N - 1;i++){
        jousi[buka[i] - 1]++;
    }

    for(ll i = 0;i < N;i++){
        cout << jousi[i] << endl;
    }





}

Measured memory_bytes: 6404
using System;
using System.IO;
using System.Linq;

namespace DBlueAndRedBalls
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputs[0];
            var k = inputs[1];

            var blueBalls = k;
            var redBalls = n - k;

            var answers = new ModNum[k];
            for (var i = 1; i <= k; i++)
            {
                if (i - 1 <= redBalls)
                {
                    var bluePatterns = MultiChoose(i, blueBalls - i);
                    var redPatterns = MultiChoose(i + 1, redBalls - i + 1);
                    answers[i - 1] = bluePatterns * redPatterns;
                }
                else
                {
                    answers[i - 1] = 0;
                }
            }

            // 解答の出力
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer.X);
            }
            Console.Out.Flush();
        }

        static ModNum MultiChoose(int i, int balls)
        {
            var n = i + balls - 1;
            ModNum numer = 1, denom = 1;
            for (var j = 1; j <= balls; j++)
            {
                denom *= j;
                numer *= n - j + 1;
            }
            return numer / denom;
        }
    }

    public struct ModNum : IEquatable<ModNum>
    {
        const int Mod = 1000000007;
        public long X { get; }

        public ModNum(long x) { X = x % Mod; }
        public static implicit operator ModNum(long x) => new ModNum(x);

        public bool Equals(ModNum other) => X == other.X;
        public override bool Equals(object obj) => obj is ModNum && Equals((ModNum)obj);
        public override int GetHashCode() => X.GetHashCode();
        public static bool operator ==(ModNum a, ModNum b) => a.X == b.X;
        public static bool operator !=(ModNum a, ModNum b) => a.X != b.X;

        public static ModNum operator +(ModNum a, ModNum b) => a.X + b.X;
        public static ModNum operator -(ModNum a, ModNum b) => Mod + a.X - b.X;
        public static ModNum operator *(ModNum a, ModNum b) => a.X * b.X;
        public static ModNum operator /(ModNum a, ModNum b) => a.X * Pow(b, Mod - 2);

        public static ModNum Pow(ModNum baseNum, int exponent)
        {
            switch (exponent)
            {
                case 0:
                    return 1;
                case 1:
                    return baseNum;
                default:
                    var pow = Pow(baseNum, exponent / 2);
                    return (exponent % 2) == 0 ? pow * pow : pow * pow * baseNum;
            }
        }
    }
}


Measured memory_bytes: 13396
#include<cstdio>
#include<functional>
#include<algorithm>
#include<queue>
using namespace std;
int main(void)
{
	priority_queue<int>  qq;
	long long sum;
	int n,m,i,a;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)	{
		scanf("%d",&a);
		qq.push(a);
	}
	for(i=0;i<m;i++)	{
		a=qq.top();
		qq.pop();
//		printf("a=%d\n",a);
		qq.push(a/2);
	}
	sum=0;
	for(i=0;i<n;i++)	{
		a=qq.top();
		qq.pop();
		sum=sum+a;
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 892
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,x,n) for(int i=x;i<n;i++)
#define breps(i,x,n) for(int i=x;i>=n;i--)
#define exrep(x,vec) for(auto&& x : vec);
#define PI 3.14159265358979323846264338327950288
const long long MOD = 1000000007;
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

/**
* ------------- ここからコード -------------
*/

ll powmod(ll x, ll y){
	ll ans = 1;
	for (ll i = 0; i < y; i++) {
		ans = ans * x % MOD;
	}
	return ans;
}

int main(void) {

	ll N;
	cin >> N;
	ll ans = powmod(10, N) - powmod(9, N) - powmod(9, N) + powmod(8, N);
	ans %= MOD;
	ans = (ans + MOD) % MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,k;
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if(abs(a-b)>1e18){printf("Unfair");return 0;}
	printf("%lld",k&1?b-a:a-b);
	return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A2150
Title Matuzaki
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
#define PRIME_MAX 101197 // from 10^5 100th prime
//Global data section
int N,P;
//
int prime_f[PRIME_MAX+1];

int prime_table[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,
                   53,59,61,67,71,73,79,83,89,97,
                   101,103,107,109,113,127,131,137,139,149,151,157,163,
                   167,173,179,181,191,193,197,199,211,223,
                   227,229,233,239,241,251,257,263,269,271,277,281,
                   283,293,307,311,313,317};
int prime_over_N[100];
void make_furui()
{
  int i,j,p;

  prime_f[0]=0;prime_f[1]=0;
  for(i=2;i<=PRIME_MAX+1;i++)
    prime_f[i]=1;
  for(i=0;i<sizeof(prime_table)/sizeof(int);i++)
    {
      p = prime_table[i];
      prime_f[p]=1;
      for(j=2;prime_table[i]*j<PRIME_MAX;j++)
              prime_f[p*j]=0;
    }
}
int isprime(int n)
{
  return(prime_f[n]);
}
void make_prime_table(int n,int p)
{
        int i,j;

        n++;
        for(j=0;p>0;n++)
        {
                if(isprime(n))
                {
                        prime_over_N[j]=n;
                        p--;
                        j++;
                }
        }
}
solve(int n,int p)
{
        int i,r2,j,k,s;

        make_prime_table(n,p);

        r2=prime_over_N[0]+prime_over_N[1];
        if(p==1)
                return(prime_over_N[0]*2);
        else if (p==2)
                return(r2);

        p-=2;
        for(i=r2+1;p;i++)
        {

                for(j=0;j<P;j++)
                {
                        for(k=0;k<=j;k++)
                        {
                                s=prime_over_N[j]+prime_over_N[k];
//printf("P1P2=%d P=%d\n",prime_over_N[j],prime_over_N[k]);
//printf("S=%d \n",s);
                                if(s<i)
                                        continue;
                                if(s==i)
                                        p--;
                                break;
                        }
                        if(p==0)
                                goto END;
                }
        }
        END:
        return(i);
}
//
main()
{
        make_furui();
        
        while(scanf("%d %d",&N,&P) && (!(N==-1 && P==-1)))
        {
                printf("%d\n",solve(N,P));
        }
return(0);
}

Measured memory_bytes: 992
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin);freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define MAX 1000001
#define v_n 5005
#define e_n 5000005
#define eps 0
#define MOD 12345
#define INF 0x3f3f3f3f3f3f3f3f
#define LL long long
using namespace std;
char str[MAX];
int sum[MAX];
int main(void)
{
	int i, j, k;
	//FAST_IO;
	//Relocate;
	int N;
	cin >> N;
	scanf("%s", str+1);
	int ans = INF;
	up(i, 1, N)
	{
		sum[i] = sum[i - 1] + (str[i] == '#');

	}
	up(i, 1, N)
	{
		int pb =sum[i];
		int pc =N-i-(sum[N]-sum[i]);
		//cout << pb << " " <<pc<< endl;
		ans = min(ans, pb + pc);
	}
	ans = min(ans, sum[N]);
	ans = min(ans, N - sum[N]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, k;
int a[5000];
bool dp[5001];
vector<int>v, r;
bool solve(int t) {
	for (int i = 0; i < k; i++)
		dp[i] = 0;
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		for (int x = 0; x < r[i] + (i == t ? -1 : 0); x++) {
			for (int j = k; j >= v[i]; j--) {
				if (dp[j - v[i]]) dp[j] = 1;
			}
		}
	}
	bool l = 0;
	for (int i = k - v[t]; i < k; i++)
		if (dp[i]) l = 1;
	return l;
}
signed main() {
	cin >> n >> k;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] >= k)
			i--, n--;
		else {
			sum += a[i];
		}
	}
	if (sum < k) {
		cout << n << endl;
		return 0;
	}
	sort(a, a + n);
	reverse(a, a + n);
	int m = n;
	for (int i = 0; i < n; ) {
		int j = i;
		while (j < n&&a[i] == a[j]) j++;
		v.push_back(a[i]);
		r.push_back(j - i);
		i = j;
	}
	n = v.size();
	int s = 0, e = n, t;
	while (e - s > 1) {
		t = (s + e) / 2;
		if (solve(t)) s = t;
		else e = t;
	}
	int ans = 0;
	for (int i = e; i < n; i++) ans += r[i];
	cout << ans << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const int INF = 1e9;
const int MXN = 3e2 + 5;
const int MXV = 0;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);
int n;
bool vis[MXN][MXN][MXN];
double ans[MXN][MXN][MXN];

double dfs(int x, int y, int z)
{
    if (x < 0 || y < 0 || z < 0)
    {
        return 0.0;
    }
    if (x == 0 && y == 0 && z == 0)
    {
        return 0.0;
    }
    if (vis[x][y][z])
    {
        return ans[x][y][z];
    }
    vis[x][y][z] = true;
    double &res = ans[x][y][z];
    double f = (double)(n - x - y - z) / n;
    res = dfs(x - 1, y, z) * ((double)x / n) +
          dfs(x + 1, y - 1, z) * ((double)y / n) +
          dfs(x, y + 1, z - 1) * ((double)z / n) + 1.0;
    res /= (1.0 - f);
    return res;
}

int main()
{
    IOS;
    int x = 0, y = 0, z = 0;
    cin >> n;
    FOR(i, 0, n)
    {
        int tmp;
        cin >> tmp;
        if (tmp == 1)
        {
            ++x;
        }
        else if (tmp == 2)
        {
            ++y;
        }
        else if (tmp == 3)
        {
            ++z;
        }
    }
    cout << fixed << setprecision(8) << dfs(x, y, z);
}


Measured memory_bytes: 127156
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

// numcnt,lastnum,sum
ll dp[10][102][2521];

int main(){
  dp[0][0][0] = 1;
  REPR(i,10){
    REP(l,102){
      FOR(x,l+1,102){
        REP(s,1001){
          dp[i][x][s+x-1] += dp[i-1][l][s];
        }
      }
    }
  }
  while(true){
    int a,b;
    cin>>a>>b;
    if(!a&&!b)break;
    ll sum = 0;
    REP(i,102)sum += dp[a][i][b];
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 18544
MAX_NUM = 10**6 + 1
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def combinations(n,k):
    if (n < k):
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

X,Y = map(int,input().split())

if (-Y + 2*X) % 3 != 0 or (2*Y - X) %3 != 0 or (-Y + 2*X) < 0 or (2*Y - X) <0:
    print(0)
else:
    x = (-Y + 2*X) // 3
    y = (2*Y - X) // 3
    
    result = combinations(x+y,min(x,y))
    print(int(result % MOD))


Measured memory_bytes: 129712
#include<iostream>
#include<cmath>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  unsigned long long int s;
  cin>>s;
  unsigned long long int k=s/500;
  s=s%500;
  unsigned long long int l=s/5;
  cout<<1000*k+l*5;

	return 0;
}


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

using namespace std;



int main()
{
    long long int n;
    cin>>n;
    long long int ara[n+5];
    int i;
    for(i=0;i<n;i++)cin>>ara[i];

    long long int cnt=0,mval=0;
    for(i=1;i<n;i++){
        if(ara[i-1]>=ara[i])cnt++;
        else cnt=0;
        if(cnt>mval)mval=cnt;
    }

    cout<<mval<<endl;

}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint K, T;
	cin >> K >> T;
	vector<lint>A(T);
	rep(i, T) {
		cin >> A[i];
	}
	lint M = -1;
	rep(i, T) {
		M = max(M, A[i]);
	}
	cout << max(lint(0), 2*M-K-1) << endl;
 }

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

using namespace std;

int main()
{
    int n, X, d=0, l, k=1;
    cin >> n >> X;
    for (int i = 0; i < n; i++)
    {
        cin >> l;
        d += l;
        if (d <= X)
        {
            k++;
        }
    }
    cout << k;
    return 0;
}


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

using namespace std;

int N;
int F[100][10];
int P[100][11];

int calc(int n)
{
	int c[100] = {0};
	int t[10];
	for (int i = 0; i < 10; i++) {
		t[i] = (n & 1);
		n >>= 1;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			if (t[j] && F[i][j]) {
				c[i]++;
			}
		}
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += P[i][c[i]];
	}
	return res;
}

void solve()
{
	int max = calc(1);
	for (int i = 2; i < 1024; i++) {
		int t = calc(i);
		max = max < t ? t : max;
	}
	cout << max << endl;
}


int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> F[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 11; j++) {
			cin >> P[i][j];
		}
	}
	solve();
	return 0;
}

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

string s;
string Out;

int main(){
	cin>>s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == 'B'){
			if( !Out.empty() ) Out.pop_back();
		}
		else Out += s[i];
	}
	cout<<Out<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#define int long long
using namespace std;
int n,m,cnt,Min_all,A,B,ans,ss,num;
const int MAXN=1e6;
const int OO=0x3f3f3f3f;
const int p=1e9+7;
int size[MAXN+10];
int c[MAXN+10],w[MAXN+10];
vector <int> v[MAXN+10];
int fac[MAXN+10],inv[MAXN+10];
int bac[MAXN+10],Min[MAXN+10];
int _bac[MAXN+10];
inline int Inv(int a,int b,int p){
	int ret=1;
	for(;b;a=(a*a)%p,b>>=1)if(b&1)ret=(ret*a)%p;
	return ret;
}
signed main(){
	if(fopen("keep.in","r")){
		freopen("keep.in","r",stdin);
		freopen("keep.out","w",stdout);
	}
	scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;++i)Min[i]=i;
	fac[0]=fac[1]=1;
	for(int i=2;i<=n;++i)fac[i]=(fac[i-1]*i)%p;
	inv[n]=Inv(fac[n],p-2,p)%p;
	inv[0]=inv[1]=1;
	for(int i=n-1;i>=2;--i)inv[i]=(inv[i+1]*(i+1))%p;
	for(int i=1;i<=n;++i)scanf("%lld%lld",&c[i],&w[i]);
	for(int i=1;i<=n;++i){
		if(!bac[c[i]])bac[c[i]]=++cnt,_bac[cnt]=c[i];
		v[bac[c[i]]].push_back(i);
	}
	
	for(int i=1;i<=cnt;++i)for(int j=0;j<(int)v[i].size();++j){
		if(j==0)Min[i]=v[i][j];
		else
		 Min[i]=(w[Min[i]]>w[v[i][j]])?v[i][j]:Min[i];
	}
	for(int i=1;i<=cnt;++i)size[Min[i]]=(int)v[i].size();
	Min_all=Min[1];
	for(int i=2;i<=cnt;++i)
		Min_all=(w[Min_all]>w[Min[i]])?Min[i]:Min_all;
	ss=OO;
	for(int i=1;i<=cnt;++i){
		if(Min_all==Min[i])continue;
		ss=min(ss,w[Min[i]]);
	}
	for(int i=1;i<=cnt;++i)for(int j=0;j<(int)v[i].size();++j){
		if(Min[i]!=v[i][j] && w[Min[i]]+w[v[i][j]]<=A)continue;
		if(c[Min_all]!=_bac[i] && w[v[i][j]]+w[Min_all]<=B)continue;
		if(c[Min_all]==_bac[i] && w[v[i][j]]+ss<=B)continue;
		size[Min[i]]--;
	}
	num=size[Min_all];
	for(int i=1;i<=cnt;++i){
		if(Min_all==Min[i])continue;
		if(w[Min[i]]+w[Min_all]<=B)
			num+=size[Min[i]];
	}
	ans=1;
	for(int i=1;i<=cnt;++i){
		if(w[Min[i]]+w[Min_all]<=B || Min_all==Min[i])
			ans=(ans*inv[size[Min[i]]])%p;
	}
	ans=(ans*fac[num])%p;
	printf("%lld\n",ans);
	return 0;
}
/*
5 100 99
3 31
1 109
2 66
5 126
3 1

*/

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

int main()
{
    int n,a,b,c;
    cin >> n;

    int dp[n][3];
    for(int i=0;i<n;++i)
    {
        cin >> a >> b >> c;
        if(i==0)
        {
            dp[0][0] = a;
            dp[0][1] = b;
            dp[0][2] = c;
        }
        else
        {
            dp[i][0] = max(dp[i-1][1]+a, dp[i-1][2]+a);
            dp[i][1] = max(dp[i-1][0]+b, dp[i-1][2]+b);
            dp[i][2] = max(dp[i-1][0]+c, dp[i-1][1]+c);
        }
    }
    int ans = max(dp[n-1][0],dp[n-1][1]);
    ans = max(ans,dp[n-1][2]);
    cout << ans << endl;
}

Measured memory_bytes: 4776