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

int main() {
  int A , B , C , D ;
  cin >> A >> B >> C >> D ;
  
  int a = A+B ; int b = C+D ;
  
  if(a>b) cout << "Left" << endl;
  if(a==b) cout << "Balanced" << endl;
  if(a<b) cout << "Right" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	}

	public static boolean isLoopContinue(final int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	}

}


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

void ss(string a,long long &ans){
  int x=0;
  for(int j=0;j<a.size();j++){
    if (a.at(j)=='+'){
      long long num = stoll(a.substr(x,j-x+1));
      ans+=num;
      x=j+1;
    }
    else if(j==a.size()-1){
      long long num = stoll(a.substr(x,j-x+1));
      ans+=num;
    }
  }
  return;
}

void s(int i,string a,long long &ans){

  if(i<a.size()){
    s(i+1,a,ans);
    a.insert(a.begin()+i,'+');
    s(i+2,a,ans);
  }
  if(i==a.size())ss(a,ans);
  return;
}

int main() {
  string a;
  cin>>a;
  long long ans=0;
  s(1,a,ans);
  cout << ans << endl;
}

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

static const int NIL = -1;

struct Node {
    int parent, left, right;
};

int n;
Node T[100001];
int D[100001];

void setDepth(int u, int p) {
    D[u] = p;
    if (T[u].right != NIL) setDepth(T[u].right, p);
    if (T[u].left != NIL) setDepth(T[u].left, p + 1);
}

void print_node(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].parent == NIL) cout << "root, ";
    else if (T[u].left == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for (int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right) {
        if (i > 0) cout << ", ";
        cout << c;
    }
    cout << "]";
    cout << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
        T[i].parent = T[i].left = T[i].right = NIL;

    for (int i = 0; i < n; i++) {
        int id, k;
        cin >> id >> k;
        int l;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            if (T[id].left == NIL) T[id].left = c;
            else T[l].right = c;
            l = c;
            T[c].parent = id;
        }
    }

    int root;
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) root = i;
    }

    setDepth(root, 0);

    for (int i = 0; i < n; i++) {
        print_node(i);
    }
    return 0;
}


Measured memory_bytes: 7696
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;
ll cal(ll x){
  ll res=1;
  for(ll i=1;i<=x;i++){
    res*=i;
    res%=mod;
  }
  return res;
}
int main(void){
  ll n,m;
  cin>>n>>m;
  if(abs(n-m)>1) cout<<0<<endl;
  else{
    if(n!=m) cout<<(cal(n)*cal(m))%mod<<endl;
    else cout<<(cal(n)*cal(m)*2)%mod<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    class Bit():
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)
            return

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x=1):
            # i==0 はだめ => 全部+1するとか
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def search(self, x):
            # 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
            # maspyさんの参考
            i = 0
            s = 0
            step = 1 << ((self.size).bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < x:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return i + 1

        def debug(self, k):
            return [self.sum(i) for i in range(k)]

    N = I()
    P = LI()
    Order = [[i+1] for i in range(N)]
    for i,p in enumerate(P):
        Order[i].append(p)
    Order.sort(key=lambda x:x[1],reverse=True)
    #print(Order)
    ans = 0
    bit = Bit(N+2)

    for i,p in Order:
        L = bit.sum(i)
        R = bit.sum(N)-L
        bit.add(i)
        l0, l1, r0, r1 = 0, 0, N+1, N+1
        if L>=2:
            l0 = bit.search(L-1)
        if L>=1:
            l1 = bit.search(L)
        if R>=1:
            r0 = bit.search(L+2)
        if R>=2:
            r1 = bit.search(L+3)
        #print(L,R)
        #print(l0,l1,r0,r1)
        #print(bit.debug(N+2))
        cnt = 0
        if l1>0:
            cnt += (l1-l0)*(r0-i)
        if r0>0:
            cnt += (i-l1)*(r1-r0)
        ans += cnt * p
        #print(ans)
    print(ans)
    return

def examF():
    def bfs(n, e, S):
        W = [0]*(2**n)
        cur = 1
        que = deque()
        que.append(e)
        while cur<2**n:
            now = que.popleft()
            depth = W[now]
            if S[now]<=S[cur]:
                return "No"
            for ne in range(n-depth):
                cur +=1
                W[now+1+ne] = depth+1
                que.append(now+1+ne)
        return "Yes"
    N = I()
    S = LI(); S.sort(reverse=True)
    ans = bfs(N,0,S)
    print(ans)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE()

"""

"""

Measured memory_bytes: 72936
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

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

const int INF = 1001001001;
const double EPS = 1e-10;

struct Data {
	int y, x, t, mask;
	Data(int y, int x, int t, int m) : y(y), x(x), t(t), mask(m) {}
};

struct Sale {
	int d, s, e;
};

const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
bool visited[20][20][100][1<<8];
int main()
{
	int h, w;
	while(scanf("%d%d", &w, &h), w){
		char field[20][20];
		rep(i, h) rep(j, w){
			char c[4];
			scanf("%s", c);
			field[i][j] = c[0];
		}

		int n;
		scanf("%d", &n);

		int dict[10];
		fill(dict, dict+10, -1);
		Sale sale[8];
		rep(i, n){
			int g;
			scanf("%d%d%d%d", &g, &sale[i].d, &sale[i].s, &sale[i].e);
			dict[g] = i;
		}

		rep(i, h) rep(j, w){
			if(isdigit(field[i][j])){
				int v = dict[field[i][j] - '0'];
				if(v == -1)
					field[i][j] = 'x';
				else
					field[i][j] = v + '0';
			}
		}

		int mask[20][20];
		rep(i, h) rep(j, w){
			if(isdigit(field[i][j]) || field[i][j] == 'x')
				mask[i][j] = -1;
			else{
				mask[i][j] = 0;
				rep(k, 4){
					int py = i + dy[k];
					int px = j + dx[k];
					if(py<0 || h<=py || px<0 || w<=px)
						continue;
					if(isdigit(field[py][px]))
						mask[i][j] |= 1 << (field[py][px] - '0');
				}
			}
		}

		int money[1<<8];
		rep(m, 1<<n){
			money[m] = 0;
			rep(i, n){
				if((m>>i)&1)
					money[m] += sale[i].d;
			}
		}
		
		queue<Data> Q;
		rep(i, h) rep(j, w){
			if(field[i][j] == 'P'){
				Q.push(Data(i, j, 0, 0));
				goto next;
			}
		}

next:
		int ans = 0;
		rep(y, h) rep(x, w) rep(t, 100) rep(m, 1<<n)
			visited[y][x][t][m] = false;
		
		while(!Q.empty()){
			Data d = Q.front();
			Q.pop();
			rep(i, n){
				if(((mask[d.y][d.x]>>i)&1) && sale[i].s<=d.t && d.t<sale[i].e)
					d.mask |= 1 << i;
			}
			ans = max(ans, money[d.mask]);
			if(d.t == 100 || visited[d.y][d.x][d.t][d.mask])
				continue;
			visited[d.y][d.x][d.t][d.mask] = true;

			Q.push(Data(d.y, d.x, d.t+1, d.mask));
			rep(k, 4){
				int py = d.y + dy[k];
				int px = d.x + dx[k];
				if(py<0 || h<=py || px<0 || w<=px || mask[py][px]==-1)
					continue;
				Q.push(Data(py, px, d.t+1, d.mask));
			}
		}

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

Measured memory_bytes: 15768
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <math.h>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	int count = 0;
	for (int j = 1; j <= n - 2; ++j) {
		if ((p[j - 1] < p[j] && p[j] < p[j + 1]) || (p[j - 1] > p[j] && p[j] > p[j + 1])) {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
S = gets.chomp!

temp = S.gsub(/[AGCT]/, "1")
temp = temp.gsub(/[^1]/, "-")
list = temp.split("-")
output = "0"
list.each do |i|
    if i.empty? then
        next
    end
    if output.to_i < i.to_i then
        output = i
    end
end
puts output.count("1")


Measured memory_bytes: 1788
dishes = []
lags = []

5.times do |i|
  dishes << gets.to_i
end

for i in 0..4
  lags << ((dishes[i] % 10 == 0) ? 0 : (10 - (dishes[i] % 10)))
end

puts dishes.inject(:+) + lags.sort!.inject(:+) - lags[4]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename T>
void printvec(vector<T> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    //コンストラクタ
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

struct gengo {
    vector<int> hi;
};

bool aru(vector<int> &p, int k){
    if (upper_bound(p.begin(),p.end(),k) - lower_bound(p.begin(),p.end(),k) > 0){
        return true;
    }
    else return false;
}

int main(){
    int n, m; cin >> n >> m;
    vector<int> ar(n);
    vector<gengo> sr(m);
    rep(i,n){
        cin >> ar[i];
        int rang;
        rep(j,ar[i]){
            cin >> rang;
            sr[rang-1].hi.push_back(i);
        }
    }
    UnionFind tree(n);
    rep(i,m){
        if(sr[i].hi.size()){
            for (int j:sr[i].hi) tree.unite(sr[i].hi[0],j);
        }
    }
    bool nt = true;
    repp(i,n,1){
        if (!tree.same(0,i)){
            nt = false;
            break;
        }
    }
    if (nt) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < 5; ++i){
     cout << s[i];
  }
  cout << " ";
  for(int i = 6; i < 13; ++i){
     cout << s[i];
  }
  cout << " ";
  for(int i = 14; i < 19; ++i){
     cout << s[i];
  }
  cout << endl;
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  int tmp = 0;
  for (int i = 0; i < S.size()/2; i++) {
    if (S.at(i) != S.at(S.size() - 1 - i)) {
      tmp++;
    }
  }
        cout << tmp << endl;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);

    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    float sum = accumulate(a.begin(), a.end(), 0);
    float mean = sum / N;
    int m1 = floor(mean), m2 = ceil(mean);

    int ans1 = 0, ans2 = 0;

    for (int i = 0; i < N; i++)
    {
        ans1 += pow((a[i] - m1), 2);
        ans2 += pow((a[i] - m2), 2);
    }

    cout << min({ans1, ans2}) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int N;
void dfs1(int pi, int i, vector<vector<int> >&T, int d, vector<int>&D1)
{
  D1[i] = d;
  for(int j=0; j < T[i].size(); j++){
    if(T[i][j] != pi){
      dfs1(i, T[i][j], T, d+1, D1);
    }
  }
}
void dfs2(int pi, int i, vector<vector<int> >&T, int d, vector<int>&D2)
{
  D2[i] = d;
  for(int j=0; j < T[i].size(); j++){
    if(T[i][j] != pi){
      dfs1(i, T[i][j], T, d+1, D2);
    }
  }
}

int main()
{
  cin >> N;
  vector<vector<int> >T(N);
  for(int i=0; i < N-1; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    T[a].push_back(b);
    T[b].push_back(a);
  }
  vector<int>D1(N);
  vector<int>D2(N);
  dfs1(0, 0, T, 0, D1);
  dfs2(N-1, N-1, T, 0, D2);
  int num=0;
  for(int i=1; i < N-1; i++){
    if(D1[i] <= D2[i])
      num++;
  }
  if(num > (N-2)-num)
    cout << "Fennec" << endl;
  else
    cout << "Snuke" << endl;
  return 0;
}


Measured memory_bytes: 14336
// ARC096
// C - Half and Half

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int solve(int a, int b, int c, int x, int y) {
    int ans = 0;
    if (a + b > 2 * c) {
        int m = min(x, y);
        ans += m * 2 * c;
        x -= m;
        y -= m;
    }
    if (x > 0 && a > 2 * c) {
        ans += x * 2 * c;
        x = 0;
        y = max(0, y - x);
    }
    if (y > 0 && b > 2 * c) {
        ans += y * 2 * c;
        y = 0;
        x = max(0, x - y);
    }
    ans += x * a + y * b;

    return ans;
}

int main() {
    int A, B, C, X, Y;

    cin >> A >> B >> C >> X >> Y;

    cout << solve(A, B, C, X, Y) << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::stdin;

fn read_num_array(input: &String) -> Vec<u64> {
    let row: Vec<&str> = input.split_whitespace().collect();
    let splitted_int: Vec<u64> = row.into_iter().map(|x| x.parse().unwrap()).collect();
    return splitted_int;
}

fn main() {
    let stdinput = stdin();
    let mut input = String::new();
    stdinput.read_line(&mut input).unwrap();
    let mut splitted_int = read_num_array(&input);
    splitted_int.reverse();
    let _ = splitted_int.pop().unwrap();
    let mut rest_skill_num = splitted_int.pop().unwrap();

    let mut input = String::new();
    stdinput.read_line(&mut input).unwrap();
    let mut splitted_int = read_num_array(&input);
    
    splitted_int.sort();
    while rest_skill_num > 0 {
        let pop_num = splitted_int.pop();
        if pop_num == None {
            println!("{}", 0);
            return;
        }
        rest_skill_num -= 1;
    }
    
    let mut sum: u64 = 0;
    for hp in splitted_int.into_iter() {
        sum += hp;
    }
    println!("{}", sum);
}


Measured memory_bytes: 13428
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
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;}

void solve(ll h, ll w, ll n){
    ll ma=max(h,w);
    cout<<(n+ma-1)/ma<<endl;
}

int main(){
    ll h;
    scanf("%lld",&h);
    ll w;
    scanf("%lld",&w);
    ll n;
    scanf("%lld",&n);
    solve(h, w, n);
}


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

const int NUM = 1000000;

int main() {
  int n;
  bool isPrime[NUM];
  int dp[NUM];
  for (int i=0;i<NUM;i++) {
    isPrime[i] = 1;
    dp[i] = 0;
  }
  isPrime[0] = isPrime[1] = 0;
  for (int i=2;i<NUM;i++) {
    if (isPrime[i]) {
      dp[i] = 1;
      for (int j=i*2;j<NUM;j+=i) {
        isPrime[j] = 0;
      }
    }
  }
  for (int i=1;i<NUM;i++) {
    dp[i] += dp[i-1];
  }

  while (cin >> n) {
    cout << dp[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 7976
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF (llong)1e18+5
#define INF 1e9+1
#define endl '\n'

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

//struct cmp {
//	bool operator() (pair<PII, int> a, pair<PII, int> b)
//	{
//		return a.ss > b.ss;
//	}
//};

int n;
VLL a;
vector<vector<llong>> dp;

llong dfs(int ll, int rr) {
	llong& ret = dp[ll][rr];
	if (ret != LLINF) return ret;
	if (ll == rr) return ret = a[ll];
	llong dfs1 = -dfs(ll + 1, rr) + a[ll];
	llong dfs2 = -dfs(ll, rr - 1) + a[rr];
	return ret = max(dfs1, dfs2);
}

int main()
{
	cin >> n;
	a = VLL(n);
	dp = vector<vector<llong>>(n, vector<llong> (n, LLINF));
	rep(i, 0, n) cin >> a[i];
	cout << dfs(0, n - 1);
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int sum = 0;
  for(int i = 0; i < 2; i++) {
  if(A < B) { sum += B; B--; }
  else { sum += A; A--; }
  }

  cout << sum;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let n: usize = io.read();
    let a = io.readn::<usize>(n);

    //all: 3^n
    let mut od = 1;
    for &i in a.iter() {
        if i % 2 == 0 {
            od *= 2;
        } else {
            od *= 1;
        }
    }
    // 3^n - od

    let ans = 3usize.pow(n as u32) - od;
    io.writeln(ans);
}

static MOD: i64 = 1000000007;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  if(N%10==3){
    cout << "bon" << endl;
    return 0;
  }
  if(N%10==0 || N%10==1 || N%10==6 || N%10==8){
    cout << "pon" << endl;
    return 0;
  }
  cout << "hon" << endl;
  return 0;
}


Measured memory_bytes: 3612
void main() {
	auto ip = readAs!(int[]), N = ip[0], M = ip[1];
	alias Pair = Tuple!(int, "P", int, "Y", int, "index", int, "bangou");
	Pair[][int] pairs;
	auto rbt = redBlackTree!int;
	foreach(i; 0..M) {
		auto ip2 = readAs!(int[]), P = ip2[0], Y = ip2[1];
		pairs[P] ~= Pair(P, Y, i, -1);
		rbt.insert(P);
	}
	Pair[] res;
	foreach(i; rbt.array) {
		auto arr = pairs[i].sort!"a.Y < b.Y";
		foreach(j; 0..arr.length) {
			auto v = arr[j];
			res ~= Pair(v.P, v.Y, v.index, (j+1).to!int);
		}
	}
	foreach(v; res.sort!"a.index < b.index"()) {
		writefln("%.6d%.6d", v.P, v.bangou);
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

const int maxn = 3e5 + 7;

char s[maxn];
int S[maxn];

int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) 
		if (s[i] == 'W') S[i] = S[i - 1] + 1;
		else S[i] = S[i - 1];

	int ans = n;
	for (int i = 1; i <= n; i++) {
		ans = min(ans, S[i - 1] + (n - i) - (S[n] - S[i]));
		// cout << S[i - 1] << ' ' << (n - i) - (S[n] - S[i]) << endl;
	}
	cout << ans << endl;
	return 0;
}	

Measured memory_bytes: 1664
import sys


def main():
    N = int(input())
    P = tuple(map(int, input().split()))

    Kcost = [min(row, N - 1 - row, clm, N - 1 - clm) for row in range(N) for clm in range(N)]

    Sitting = [1] * (N * N)
    Kcount = 0


    def Kcheck(qsn, cdsn):
        if Kcost[cdsn] > Kcost[qsn] + Sitting[qsn]:
            Kcost[cdsn] = Kcost[qsn] + Sitting[qsn]
            queue.append(cdsn)


    for sn in P:
        csn = sn - 1
        Kcount += Kcost[csn]
        Sitting[csn] = 0
        queue = [csn]

        while queue:
            qsn = queue.pop()
            div, mod = divmod(qsn, N)
            if mod: Kcheck(qsn, qsn - 1)
            if mod != N - 1: Kcheck(qsn, qsn + 1)
            if div: Kcheck(qsn, qsn - N)
            if div != N - 1: Kcheck(qsn, qsn + N)

    print(Kcount)


if __name__ == '__main__':
    main()

sys.exit()


Measured memory_bytes: 149256
N, K = map(int, input().split())
A = list(map(int, input().split()))
X = [0 for _ in range(N)]
D = {0: [-1]}
E = {0: 1}
X[0] = (A[0] - 1) % K
if X[0] in D:
  D[X[0]].append(0)
  E[X[0]] += 1
else:
  D[X[0]] = [0]
  E[X[0]] = 1
for i in range(1, N):
  X[i] = (X[i-1] + A[i] - 1) % K
  if X[i] in D:
    D[X[i]].append(i)
    E[X[i]] += 1
  else:
    D[X[i]] = [i]
    E[X[i]] = 1
S = 0
for i in D:
  n = E[i]
  if n > 1:
    L = D[i][:]
    m = L[-1]
    for j in range(n-1):
      x = L[j]
      if m - x < K:
        S += n - 1 - j
      else:
        l, r = j, n
        d = (l + r) // 2
        tmp = 2 * n
        while tmp != 0:
          if L[d] - x <= K - 1:
            l = d
            d = (l + r) // 2
          else:
            r = d
            d = (l + r) // 2
          tmp //= 2
        S += d - j
print(S)

Measured memory_bytes: 71460
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,l,r,i,c,p;
  string s;
  cin>>s;
  n=s.size();
  s=s+"R";
  vector<int> v(n,0);
  for(i=l=r=c=p=0;i<=n;++i){
    if(c&&s[i]=='R'){
      if(r%2==l%2)v[p]=v[p+1]=(l+r)/2;
      else{
        v[p]=v[p+1]=(l+r)/2;
        v[p+(r<l?1:0)]++;
        if(max(l,r)%2==0)swap(v[p],v[p+1]);
      }
      c=l=0;r=1;
    }
    else if(c&&s[i]=='L')l++;
    else if(!c&&s[i]=='R')r++;
    else if(!c&&s[i]=='L')p=i-1,c=1,l++;
  }
  for(int i=0;i<n;++i){
    if(i)cout<<" ";
    cout<<v[i];
  }
}

Measured memory_bytes: 1020
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        String s = scan.next();
        switch(s){
            case "SAT":
                System.out.println("1");
                break;
            case "FRI":
                System.out.println("2");
                break;
            case "THU":
                System.out.println("3");
                break;
            case "WED":
                System.out.println("4");
                break;
            case "TUE":
                System.out.println("5");
                break;
            case "MON":
                System.out.println("6");
                break;
            case "SUN":
                System.out.println("7");
                break;
        }
    }
}

Measured memory_bytes: 21844
N=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
A,B=[],[]
for i in range(N):
  if i % 2 == 0:
    A.append(a[i])
  else:
    B.append(a[i])
print(sum(A)-sum(B))

Measured memory_bytes: 9152
#include <iostream>

using namespace std;

#define INFTY 1000000000;

int ct = 0;

void merge(int* A, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int i, j;

  int* L = new int[n1+1];
  int* R = new int[n2+1];

  for (int i = 0; i < n1; i++) {
    L[i] = A[left+i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid+i];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  
  for (int k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
    ct++;
  }

  delete[] L;
  delete[] R;
}

void mergeSort(int* A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);

    merge(A, left, mid, right);
  }
}

int main() {
  int n = 0;
  int S[500000];

  cin >> n;

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

  mergeSort(S, 0, n);

  for (int i = 0; i < n; i++) {
    if (i != 0) cout << " ";
    cout << S[i];
  }

  cout << endl << ct << endl;

  return 0;
}



Measured memory_bytes: 6816
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        a: Chars,
        b: Chars,
        c: Chars,
    }

    let mut index = (0usize, 0usize, 0usize);
    let mut now = a[index.0];
    index.0 += 1;
    while index.0 <= a.len() && index.1 <= b.len() && index.2 <= c.len() {
        //println!("{}", now);
        if now == 'a' {
            if index.0 == a.len() {
                println!("A");
                break;
            }
            now = a[index.0];
            index.0 += 1;
        } else if now == 'b' {
            if index.1 == b.len() {
                println!("B");
                break;
            }
            now = b[index.1];
            index.1 += 1;
        } else {
            if index.2 == c.len() {
                println!("C");
                break;
            }
            now = c[index.2];
            index.2 += 1;
        }
    }
}


Measured memory_bytes: 2184
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
using namespace std;
const int N=1e5+5;

vi ad[N];
bool visw[N],visb[N];
ll dpw[N],dpb[N],par[N];


ll dfsw(int x);

ll dfsb(int x){
    if(visb[x])return dpb[x];
    visb[x]=true;
    dpb[x]=1;

    for(auto y:ad[x]){
        if(y==par[x])continue;
        par[y]=x;
        dpb[x]=(dpb[x]*dfsw(y))%hell;


    }
    return dpb[x];
}

ll dfsw(int x){
    if(visw[x]==true)return dpw[x];
    visw[x]=true;
    dpw[x]=1;
    ll val1=1,val=0;

    for(auto y:ad[x]){
       
        if(y==par[x])continue;
        par[y]=x;
        val=0;
        val=(val+dfsb(y))%hell;
        val=(val+dfsw(y))%hell;

        val1=(val1*val)%hell;

    }

    dpw[x]=val1;
    return dpw[x];
}
 
void solve(){
    
    int n;
    cin>>n;
    int u,v;
    rep(i,0,n-1){
        cin>>u>>v;
        ad[u].pb(v);
        ad[v].pb(u);
    }

    par[1]=-1;
    dfsw(1);
    dfsb(1);

    cout<<(dpb[1]+dpw[1])%hell;
    

}
 
 
 
int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
   
 
    int t=1,i=1;
   // cin>>t;
    
 
    while(t--){
       // cout<<"Case #"<<i++<<": ";
        solve();
    
    }
 
    return 0;
}

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

void solve() {
	int ae=0,bb=0,aebb=0;
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;

		int j = 0;
		int m = (int)s.length();
		while (j < m-1) {
			if (s[j] == 'A' && s[j+1] == 'B') {
				++cnt;
				j++;
			}
			++j;
		}

		if (s[0] == 'B' && s[s.length()-1] == 'A') {
			++ae,++bb,++aebb;
		} else if (s[0] == 'B') {
			++bb;
		} else if (s[s.length()-1] == 'A') {
			++ae;
		}

	}

	ae -= aebb;
	bb -= aebb;
	bool fl = false;
	if (ae) {
		cnt += aebb;
		--ae;
		fl = true;
	} else  {
		if (aebb >= 2) {
			cnt += aebb-1;
			fl = true;
		} else if (aebb == 1) {
			fl = true;
			aebb = 0;
		}
	}
	if (bb && fl) {
		++cnt;
		--bb;
	}
	cnt += min(ae,bb);

	cout << cnt << '\n';
}


/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    ll ai,ao,at,aj,al,as,az;
    cin>>ai>>ao>>at>>aj>>al>>as>>az;
    ll cnt=0,cnt2=0;
    cnt+=ai/2*2+ao+aj/2*2+al/2*2;
    cnt+=min(ai%2,min(aj%2,al%2))*3;
    if(ai>0&&aj>0&&al>0){
        --ai,--aj,--al;
        cnt2+=ai/2*2+ao+aj/2*2+al/2*2+3;
    }
    cout<<max(cnt,cnt2)<<endl;
    return 0;
}

Measured memory_bytes: 256
/**************
 *
 *ALDS_1_8_C
 *TreeWalk
 *
 *2020/07/17
 **************/

#include<stdio.h>

typedef struct{
  int parent;
  int left;
  int right;
} Node;

const int max_node = 25;

void print_preorder(Node *node,int node_id){

  printf(" %d",node_id);

  if(node[node_id].left != -1) print_preorder(node,node[node_id].left);
  if(node[node_id].right != -1) print_preorder(node,node[node_id].right);

  return;
}

void print_inorder(Node *node,int node_id){

  if(node[node_id].left != -1) print_inorder(node,node[node_id].left);
  printf(" %d",node_id);
  if(node[node_id].right != -1) print_inorder(node,node[node_id].right);

  return;
}

void print_postorder(Node *node,int node_id){

  if(node[node_id].left != -1) print_postorder(node,node[node_id].left);
  if(node[node_id].right != -1) print_postorder(node,node[node_id].right);
  printf(" %d",node_id);

  return;
}


int main(void){

  Node node[max_node];
  int n=0;
  int parent_id=-1;
  /*入力*/
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int id;
    int left,right;
    scanf("%d %d %d",&id,&left,&right);
    node[id].parent = -1;
    node[id].left = left;
    node[id].right = right;
  }

  /*処理*/

  //各ノードの親を調べる
  for(int i=0;i<n;i++){
    if(node[i].left != -1) node[node[i].left].parent = i;
    if(node[i].right != -1) node[node[i].right].parent = i;
  }
  //rootのノードを探す
  for(int i=0;i<n;i++){
    if(node[i].parent == -1){
      parent_id = i;
      break;
    }
  }
  
  /*出力*/
  puts("Preorder");
  print_preorder(node,parent_id);
  printf("\n");

  puts("Inorder");
  print_inorder(node,parent_id);
  printf("\n");

  puts("Postorder");
  print_postorder(node,parent_id);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2708
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,x,gc=0;
    cin>>n>>x;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        if(!i)
            gc=abs(x-a);
        else
        {
            int b=abs(x-a);
            gc=__gcd(gc,b);
        }
    }
    cout<<gc<<endl;


    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    string s;
    cin >> n >> s;
    map<char, set<ll>> idx;
    rep(i, n) idx[s[i]].insert(i);
    ll ans = 0;
    for(auto x : idx['R']) {
        for(auto y : idx['G']) {
            ll diff = abs(y - x);
            ll tmp = sz(idx['B']);
            tmp -= idx['B'].count(x - diff);
            tmp -= idx['B'].count(x + diff);
            tmp -= idx['B'].count(y - diff);
            tmp -= idx['B'].count(y + diff);
            if (diff % 2 == 0) tmp -= idx['B'].count((x + y) / 2);
            ans += tmp;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3848
#include<cstdio>
#include<algorithm>
#define N 100000
using namespace std;
long long A[N] = { 0 }, T[4 * N], lazy[4 * N] = { 0 };

void build(int l, int r, int k) {
    if (l == r) {
        T[k] = A[l];
        return;
    }
    int mid = (l + r) / 2;
    build(l, mid, k * 2);
    build(mid + 1, r, k * 2 + 1);
    T[k] = max(T[2 * k], T[2 * k + 1]);
}
void pushdown(int k) {
    if (lazy[k]) {
        lazy[2 * k] += lazy[k];
        lazy[2 * k + 1] += lazy[k];
        T[2 * k] += lazy[k];
        T[2 * k + 1] += lazy[k];
        lazy[k] = 0;
    }
}
void updata(int L, int R, int l, int r, int k) {
    if (L <= l && r <= R) {
        T[k] += 1;
        lazy[k] += 1;
        return;
    }
    int mid = (l + r) / 2;
    pushdown(k);
    if (mid >= L) updata(L, R, l, mid, 2 * k);
    if (mid < R) updata(L, R, mid + 1, r, 2 * k + 1);
    T[k] = max(T[2 * k], T[2 * k + 1]);
}
long long find(int L, int R, int l, int r, int k) {
    if (L <= l && r <= R) return T[k];
    int mid = (l + r) / 2;
    pushdown(k);
    long long ans = 0;
    if (mid >= L) ans = max(ans, find(L, R, l, mid, k * 2));
    if (mid < R) ans = max(ans, find(L, R, mid + 1, r, k * 2 + 1));
    return ans;
}
int main() {
    int n, q;
    scanf("%d%d", &q, &n);
    build(0, n - 1, 1);
    int com, s, t, x, y;
    while (q--) {
        scanf("%d%d", &s, &t);
        updata(s, t-1, 0, n - 1, 1);
    }
    printf("%lld\n", T[1]);
    return 0;
}


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

int main() {
  ll n; cin >> n;
  vector<string>v(n);
  for(ll i = 0; i<n; i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  ll ans = 1;
  for(ll i = 1; i<n; i++){
    if(v[i]!=v[i-1]) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 9596
#include <iostream>
#include <queue>
#define INF (1e9)
#define N 101
#define C 11
using namespace std;
void dijkstra(int);
int M[N][N],d[N][C],c,n;
typedef struct data{
  int cost,pos,ticket;
  bool operator<(const data & right)const{
    return cost > right.cost;
  }
} data;
int main(){
  int m,s,id,a,b,f;
  while(1){
    cin >> c >> n >> m >> s >> id;
    if(c==0&&n==0&&m==0&&s==0&&id==0) break;
    for(int i=0;i<=n;i++)
      for(int j=0;j<=n;j++)
	M[i][j]=INF;
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      M[a][b]=M[b][a]=f;
    }
    dijkstra(s);
    int mincost=INF;
    for(int i=0;i<=c;i++){
      mincost=min(mincost,d[id][i]);
    }
    cout << mincost << endl;
  }
  return 0;
}
void dijkstra(int s){
  priority_queue<data> q;
  for(int i=1;i<=n;i++)
    for(int j=0;j<=c;j++)
      d[i][j]=INF;
  d[s][0]=0;
  q.push((data){0,s,0});
  while(!q.empty()){
    data t=q.top();
    q.pop();
    int cost=t.cost,pos=t.pos,ticket=t.ticket;
    if(d[pos][ticket]>cost) continue;
    for(int i=1;i<=n;i++){
      if(d[i][ticket]>d[pos][ticket]+M[pos][i]){
	d[i][ticket]=d[pos][ticket]+M[pos][i];
	q.push((data){d[i][ticket],i,ticket});
      }
      if(ticket==c) continue;
      if(d[i][ticket+1]>d[pos][ticket]+M[pos][i]/2){
	d[i][ticket+1]=d[pos][ticket]+M[pos][i]/2;
	q.push((data){d[i][ticket+1],i,ticket+1});
      }
    }
  }
}

Measured memory_bytes: 1300
#include <stdio.h>
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;


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

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N, D, A;
  cin >> N >> D >> A;
  vector<pair<int, int> > M;
  for (int i = 0; i < N; ++i) {
    int X, H;
    cin >> X >> H;
    M.push_back(make_pair(X, H));
  }
  sort(M.begin(), M.end());
  
  ll ans = 0;

  // for (int i = 0; i < N; ++i) {
  //   int n = (M[i].second + A - 1) / A;
  //   M[i].second = 0;
  //   ans += n;
  //   for (int j = i + 1; j < N; ++j) {
  //     if (M[j].first <= M[i].first + 2 * D) {
  // 	M[j].second -= n * A;
  // 	if (M[j].second < 0) M[j].second = 0;
  //     }
  //   }
  // }

  ll n_total = 0;
  deque<int> dq;
  
  for (int i = 0; i < N; ++i) {
    while ((not dq.empty()) and M[dq.front()].first < M[i].first - 2 * D) {
      int j = dq.front();
      int nj = (M[j].second + A - 1) / A;
      n_total -= nj;
      dq.pop_front();
    }
    
    M[i].second -= n_total * A;
    if (M[i].second < 0) M[i].second = 0;
    int n =  (M[i].second + A - 1) / A;
    ans += n;
    
    n_total += n;
    dq.push_back(i);
  }

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


Measured memory_bytes: 2672
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
#include <iterator>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------
//提出するときC++に帰る
//--------------------------

ll n, k, a, b;
map<ll, ll> m;
vector<ll> v;
vector<ll> w;

int main() {

  cin >> n >> k;
  rep(i, n) {
    cin >> a >> b;
    m[a] += b;
  }

  for(auto it : m) {
    if(v.empty()) {
      v.push_back(it.first);
      w.push_back(it.second);
    }else {
      v.push_back(it.first);
      w.push_back(it.second+w[w.size()-1]);
    }
  }

  vector<ll>::iterator itr = lower_bound(w.begin(), w.end(), k);
  cout << v[distance(w.begin(), itr)] << endl;

  return 0;
}


Measured memory_bytes: 5364
///Nahid Hasan Raju
#include <bits/stdc++.h>
#define ll long long
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
using namespace std;

#define P1(XX) cerr<<"db1: "<<XX<<endl
#define P2(XX,YY) cerr<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cerr<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007ll
#define MX 2000006  ///200005


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

ll m, n;
ll a[MX], b[MX];
string s,s1;
map<ll,int>mp;

void precalc(ll p)
{

}

///cerr<<   how to use it?
int main()
{
    #ifndef ONLINE_JUDGE
    Fin;
    #endif
    int test=1, tc=0, i, j;
    ll k, ans;
    //scanf("%d", &test);
    //precalc(1);
    while(test--)
    {
        j=0;
        cin>>n;
        if(n>=30)puts("Yes");
        else puts("No");
        //printf("%lld\n", ans);
    }
    return 0;
}



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

using namespace std;

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

int main() {
    long long a, b, x, y;
    cin >> a >> b;

    extgcd(a, b, x, y);
    cout << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 3100