akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
{
    static int[] p;
    static int[] c;
    static int G;
    static int D;

    static void Main(string[] args)
    {
        var dg = Console.ReadLine().Split(' ');
        D = int.Parse(dg[0]);
        G = int.Parse(dg[1]);
        p = new int[D];
        c = new int[D];
        for (int i = 0; i < D; i++)
        {
            var s = Console.ReadLine().Split(' ');
            p[i] = int.Parse(s[0]);
            c[i] = int.Parse(s[1]);
        }

        var ans = dfs(0, new bool[D]);
        Console.WriteLine(ans);
    }

    static int dfs(int n, bool[] v)
    {
        if (v.Length <= n)
        {
            return m1(v);
        }

        v[n] = true;
        var left = dfs(n + 1, v);
        v[n] = false;
        var right = dfs(n + 1, v);
        return Math.Min(left, right);
    }

    static int m1(bool[] v)
    {
        var g = 0;
        var ans = 0;

        for (int i = 0; i < D; i++)
        {
            if (v[i])
            {
                ans += p[i];
                g += (i + 1) * 100 * p[i];
                g += c[i];
            }
        }

        if (G <= g)
        {
            return ans;
        }

        var j = D - 1;
        for (; j >= 0 && v[j]; j--) { }

        var n = Math.Min(
            p[j],
            ceil(G - g, (j + 1) * 100));
        ans += n;
        g += (j + 1) * 100 * n;

        if (G <= g)
        {
            return ans;
        }
        else
        {
            return int.MaxValue;
        }
    }

    static int ceil(int a, int b)
    {
        return a / b + (a % b > 0 ? 1 : 0);
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+10;
long long a[N];
const long long mod=1e9+7;
int main()
{
    long long n;scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    long long sum=0;
    for(int k=0;k<60;k++){
        long long num1=0;
        for(int i=0;i<n;i++){
            if((a[i]>>k)&1){
                num1++;
            }

        }
        long long t=(1ll<<k)%mod;
        long long t1=(n-num1)*num1%mod;
        sum+=t1*t%mod;
    }
    printf("%lld\n",sum%mod);
    return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.math.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    for(int i = 0; i < str.length(); i += 2){
      System.out.print(str.charAt(i));
    }
    System.out.println();
  }
}

Measured memory_bytes: 29660
#include<stdio.h>
    int main()
    {
        int N,i,j,k;
        int data[100001];
        scanf("%d", &N);
        for(i = 0;i < N;i++){
        scanf("%d", &data[i]);
        }
        j = data[0];
        k = data[0];
        for(i = 0;i < N;i++){
          if(k == 2){
          printf("%d \n",i+1);
          break;
          }
          if(i == N-1) printf("-1\n");
          k = data[j-1];
          j = k;
        }
        return 0;
    }

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
vector<bool> isp(55557,true);
vi prime;
int main() {
  isp[0] = false;
  isp[1] = false;
  REP(i,250){
    if(isp[i]){
      for(ll j=i*2;j<55557;j+=i){
        isp[j] = false;
      }
    }
  }
  REP(i,55557) if(isp[i] && i%5==1) prime.push_back(i);
  ll n;
  cin >> n;
  REP(i,n) cout << prime[i] << " ";
  cout << endl;
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define pb push_back
#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define LOOP_IT(s) for(auto it=(s).begin();it!=(s).end();++it)
#define loop for(int i=0;i<n;++i)


int main(int argc,char* argv[])
{
    ZOOM

    ull n,a,b;
    cin>>n>>a>>b;
    ull z=n%(a+b);
    ull bb=min(a,z);
    bb+=((n/(a+b))*a);
    cout<<bb;


    return 0;
}



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

int main(void){
    
    long long X;
    cin >> X;
    
    for(long long A = -1000; A < 1000;A++){
        
        for(long long B = -1000; B < 1000;B++){
        
            if(A*A*A*A*A - B*B*B*B*B == X){
                cout << A <<" "<< B <<endl;
                return 0;
            }
        
        }    
        
    }
}


Measured memory_bytes: 3696
#include <iostream>
using
namespace std;
int main(void){
 int n,b,f,r,v,i,j,k,count[4][3][10]={{{0}}};
 cin >> n;
 for(i=0;i<n;i++){
 cin >> b >> f >> r >> v;
 count[b-1][f-1][r-1]=count[b-1][f-1][r-1]+v;
 }
 for(j=0;j<3;j++){
     for(k=0;k<10;k++){
         if(count[0][j][k]<0){
             count[0][j][k]=0;
         }else if(count[0][j][k]>9){
             count[0][j][k]=9;
         }
         cout << " ";
         cout << count[0][j][k];
     }
     cout << endl;
 }
 for(i=1;i<4;i++){
     cout << "####################";
     cout << endl;
     for(j=0;j<3;j++){
         for(k=0;k<10;k++){
             if(count[i][j][k]<0){
                 count[i][j][k]=0;
             }else if(count[i][j][k]>9){
                 count[i][j][k]=9;
             }
             cout << " ";
             cout << count[i][j][k];
         }
         cout << endl;
     }
 }
}




Measured memory_bytes: 3092
#include<stdio.h>

int main(void)
{
    char s[11];
    
    
    scanf("%s",s);
    

    if(s[5]=='0'&&s[6]<'4')
    {
         printf("Heisei\n");
    }
    else if(s[5]=='0'&&s[6]=='4'&&s[8]<='3')
    {
         printf("Heisei\n");
    }
    else 
    {
         printf("TBD\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int n;
    cin >> n;
    cout << 180*(n-2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    long long a,b,c,d,e,f,g,h;
    cin>>a>>b>>c>>d>>e>>f>>g>>h;
    if(!a||!d||!e) cout<<a/2*2+b+d/2*2+e/2*2;
    else cout<<a+b+d+e-(a%2!=d%2||d%2!=e%2);
    return 0;
}

Measured memory_bytes: 256
<?php
$a = explode(" ", str());
echo $a[1],$a[0];
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

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

int main()
{
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int> x(N);
	vector<int> y(M);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < M; i++)
	{
		cin >> y[i];
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	int xr = x[N - 1];
	int yl = y[0];

	if (xr<yl && xr+1<Y && X<yl-1)
	{
		cout << "No War" << endl;
	}
	else
	{
		cout << "War" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    cin>>n;
    int tmp =0 ;
    if(n%11 >6){
        tmp+=2;
    }else if(n%11  != 0){
        tmp++;
    }
    cout<<((n)/11 *2)+tmp<<endl;
   
}

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

using ll = long long;

struct edge{int from, to; ll cost; };

vector<edge> es;

int main() {
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        es.push_back({a, b, c});
    }

    vector<ll> d(N+1, -(1LL<<60));
    d[1] = 0;
    ll prev = d[N];
    for(int i = 0; i < 2 * N; i++) {
        for(auto e : es) {
            if(d[e.from] != -(1LL<<60) && d[e.to] < d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
            }
        }
        if(prev != d[N] && i > N) {
            cout << "inf" << endl;
            return 0;
        }
        prev = d[N];
    }

    cout << d[N] << endl;

    return 0;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
A=[1,3,5,7,8,10,12]
B=[4,6,9,11]
C=[2]

if x in A and y in A:
    print("Yes")
    exit()
elif x in B and y in B:
    print("Yes")
    exit()
elif x in C and y in C:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main(){
  int n;
  long long c;
  cin>>n>>c;
  long long x[n+2]={},v[n+2]={};
  for(int i=1;i<=n;i++){
    cin>>x[i]>>v[i];
  }
  vector<long long> g(n+2);
  g[0]=0ll;
  for(int i=1;i<=n;i++){
    g[i]=g[i-1]+v[i]+x[i-1]-x[i];
  }
  for(int i=1;i<=n;i++){
    g[i]=max(g[i-1],g[i]);
  }

  vector<long long> p(n+2);
  p[n+1]=0;
  x[n+1]=c;
  for(int i=n;i>0;i--){
    p[i]=p[i+1]+v[i]+(c-x[i+1])-(c-x[i]);
  }
  for(int i=n;i>0;i--){
    p[i]=max(p[i],p[i+1]);
  }

  long long ans=0;
  for(int i=1;i<=n+1;i++){
    ans=max(ans,g[i-1]+p[i]-x[i-1]);
    ans=max(ans,g[i-1]+p[i]-(c-x[i]));
    ans=max(ans,g[i]);
    ans=max(ans,p[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
using namespace std;

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

const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int a[maxn];
int main() {
    //freopen(".in", "r", stdin);
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    if(n%2==0)
    {
        for(int i=n;i>=2;i-=2) printf("%d ",a[i]);
        for(int i=1;i<=n-1;i+=2) printf("%d ",a[i]);
    }
    else
    {
        for(int i=n;i>=1;i-=2) printf("%d ",a[i]);
        for(int i=2;i<=n-1;i+=2) printf("%d ",a[i]);
    }
    return 0;
}



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

int main() {
	string s;
	for (char c; cin >> c; ) {
		s.push_back(c);
		if (s.size() >= 2 && s.back() == 'T' && s.rbegin()[1] == 'S') {
			s.pop_back();
			s.pop_back();
		}
	}
	cout << s.size();
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <array>
#include <map>

#define ll long long

using namespace std;

int ans[501][501];

signed main() {
	int n; cin >> n;
	if (n == 1) {
		cout << "Yes" << endl;
		cout << 1 << endl;
	}
	else if (n & 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
		for (int i = 0; i < n; ++i) {
			for (int j = i; j < n; ++j) {
				ans[i][j] = (i + j) % n + 1;
			}
		}
		for (int i = 1; i < n - 1; ++i) {
			for (int j = 0; j < i; ++j) {
				ans[i][j] = (i + j) % (n - 1) + n;
				if (ans[i][j] == n)
					ans[i][j] = 2 * n - 1;
			}
		}
		ans[n - 1][0] = 2 * n - 1;
		for (int j = 1; j < n - 1; ++j) {
			ans[n - 1][j] = ans[j][j - 1] + 1;
			if (ans[n - 1][j] == 2 * n)
				ans[n - 1][j] = n + 1;
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n - 1; ++j)
				cout << ans[j][i] << " ";
			cout << ans[n - 1][i] << endl;
		}
	}

	return 0;
}


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

using namespace std;

int a[15][15];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m + 1; j++) {
      cin >> a[i][j];
    }
  }
  long long ans = 2e18;
  for (int i = 0; i < (1 << n); i++) {
    long long cost = 0;
    vector<long long> b(m + 1);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        cost += a[j][0];
        for (int k = 1; k <= m; k++) {
          b[k] += a[j][k];
        }
      }
    }
    bool fail = false;
    for (int j = 1; j <= m; j++) {
      if (b[j] < x) {
        fail = true;
        break;
      }
    }
    if (!fail) {
      ans = min(ans, cost);
    }
  }
  if (ans == 2e18) {
    cout << "-1\n";
  } else {
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 3604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class arc092_d {
private:
    inline int count(int start_num, int end_num, const vector<int> &b) {
        auto it_start = lower_bound(begin(b), end(b), start_num);
        auto it_end = lower_bound(begin(b), end(b), end_num);
        int cnt = it_end - it_start;
        return cnt;
    }
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<int> a(N), b(N);
        for (int i = 0; i < N; ++i) {
            in >> a[i];
        }
        for (int i = 0; i < N; ++i) {
            in >> b[i];
        }
        vector<int> res(29, 0);
        for (int j = 0; j < 29; ++j) {
            int T = (1 << j);
            vector<int> cur_b(N);
            for (int i = 0; i < N; ++i) {
                cur_b[i] = (b[i] & (2 * T - 1));
            }
            sort(begin(cur_b), end(cur_b));
            for (int i = 0; i < N; ++i) {
                res[j] += count(T - (a[i] & (2 * T - 1)), 2 * T - (a[i] & (2 * T - 1)), cur_b);
                res[j] += count(3 * T - (a[i] & (2 * T - 1)), 4 * T - (a[i] & (2 * T - 1)), cur_b);
            }
        }
        int ans = 0;
        for (int j = 0; j < 29; ++j) {
            if (res[j] % 2) {
                ans |= (1 << j);
            }
        }
        out << ans << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc092_d solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2672
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_11_B: Depth First Search

#include <algorithm>
#include <cstdio>
#include <stack>
#include <utility>

using uint = unsigned int;

class Graph {
  const uint n_;
  uint* const g_;
  std::pair<int, int>* const visited_;
  uint time_;
  
public:
  Graph(uint n) : n_(n),
                  g_(new uint[(n_*n_)]),
                  visited_(new std::pair<int, int>[n_])
  {
    std::fill(g_, g_+(n_*n_), 0u);
  }

  ~Graph()
  {
    delete[] g_;
    delete[] visited_;
  }
  
  uint* operator [](uint i) const { return g_+(n_*i); }

  std::pair<int, int>* visited() const { return visited_; }

  void dfs()
  {
    init_visited();
    for (auto i = 0u; i < n_; ++i) {
      inner_dfs(i);
    }
  }

private:
  void init_visited()
  {
    time_ = 0u;
    for (auto i = 0u; i < n_; ++i) {
      visited_[i].first = -1;
    }
  }

  void inner_dfs(uint i)
  {
    if (visited_[i].first != -1) {
      return;
    }
    visited_[i].first = time_++;
    for (auto j = 0u; j < n_; ++j) {
      auto k = (*this)[i][j];
      if (k) {
        inner_dfs(j);
      }
    }
    visited_[i].second = time_++;
  }
};

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, v;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u", &v);
      g[u-1][v-1] = 1;
    }
  }

  g.dfs();
  auto visited = g.visited();
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %d %d\n", i+1, visited[i].first+1, visited[i].second+1);
  }
}

// eof

Measured memory_bytes: 2716
// 解説AC
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define int long long

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

    int n;
    cin >> n;
    vector<int> a(n + 1);     // a[d]: 深さdの葉の数
    vector<int> b(n + 1, 0);  // b[d]: 深さdの葉以外の頂点数
    for (int i = 0; i < n + 1; i++) cin >> a[i];

    vector<int> csa(n + 1 + 1);  // csa[i+1]-csa[j]: a[j]からa[i]までの和
    csa[0] = 0;
    for (int i = 0; i < n + 1; i++) csa[i + 1] = csa[i] + a[i];

    for (int d = 0; d <= n; d++) {
        if (d == 0) {
            b[d] = 1 - a[d];
            continue;
        }

        const int bmin = b[d - 1] - a[d];
        const int bmax = min(2 * b[d - 1] - a[d], csa[n + 1] - csa[d + 1]);

        b[d] = bmax;
    }

    int ans = 0;
    bool cant = false;  // 構築できない

    for (auto &&i : a) {
        ans += i;
    }
    for (auto &&i : b) {
        if (i < 0) cant |= true;
        ans += i;
    }

    if (cant)
        cout << -1 << endl;
    else
        cout << ans << endl;
}


Measured memory_bytes: 5536
#include<stdio.h>
int main()
{
	int a, b, c;
	int tmp;
	scanf("%d %d %d", &a, &b, &c);
	if (a > b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	if (b>c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}
	if (a > b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	if (b>c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}

Measured memory_bytes: 2700
#include<stdio.h>
int main(){
  int n, S[1000000], q, T[1000000], i, j, cnt = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);

  scanf("%d", &q);
  for(j = 0; j < q; j++)
    scanf("%d", &T[j]);
  

  
  for(i = 0; i < q; i++)
    for(j = 0; j < n; j++)
      if(T[i] == S[j])   {
	cnt++;
	break;
      }

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

Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
int n,a[155],mn,mx;
int main(){
	n = rd();
	Rep(i,1,n) a[i] = rd();
	sort(a+1,a+1+n);
	mn = a[1],mx = a[n];
	if(mn != (mx+1)/2){
		puts("Impossible");
		return 0;
	}
	int cnt = 0;
	Rep(i,1,n) cnt += a[i] == mn;
	if(cnt != (mx & 1) + 1){
		puts("Impossible");
		return 0;
	}
	Rep(i,mn+1,mx){
        cnt=0;
        for(int j=1;j<=n;j++)
            if(a[j]==i)
                cnt++;
        if(cnt==0||cnt==1){
            puts("Impossible");
            return 0;
        }
    }
    puts("Possible");
    return 0;
}


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

using namespace std;

int main(void) {
  unsigned long long ans = 1;
  int N; cin >> N;
  
  bool OF = false;
  
  for (int i = 0; i < N; i++) {
    unsigned long long A; cin >> A;
    unsigned long long tmp = ans*A;
    
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    
    if (!OF) {
      
      if (tmp/A != ans || tmp > 1000000000000000000) {
        OF = true;
      }
      
      ans = tmp;
    }
  }
  
  if (OF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
    long int a[3], i, j;

    for(i=0;i<3;i++){
        scanf("%ld", &a[i]);
    }
    long int min=a[0]*a[1]*a[2];
        
    if(a[0]%2==0 || a[1]%2==0 || a[2]%2==0) printf("%d\n", 0);
    else{
        for(i=0;i<3;i++){
            for(j=i+1;j<3;j++){
                if(a[i]*a[j]<min) min=a[i]*a[j];
            }
        }
        printf("%ld\n", min);
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n, l;
    cin >> n >> l;
    string s[n];
    for(int i = 0; i < n; i++) cin >> s[i];
    sort(s, s+n);
    for(int i = 0; i < n; i++) cout << s[i];
    cout << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n>=400&&n<=599)
    cout<<"8"<<endl;
    if(n>=600&&n<=799)
    cout<<"7"<<endl;
     if(n>=800&&n<=999)
    cout<<"6"<<endl;
     if(n>=1000&&n<=1199)
    cout<<"5"<<endl;
     if(n>=1200&&n<=1399)
    cout<<"4"<<endl;
     if(n>=1400&&n<=1599)
    cout<<"3"<<endl;
     if(n>=1600&&n<=1799)
    cout<<"2"<<endl;
     if(n>=1800&&n<=1999)
    cout<<"1"<<endl;
    return 0;
}



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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

ll N,K;
vector<ll> a;

// t番目のカードが必要なら真
bool f(ll t) {
    // dp[i][sum]: i番目のカードまでを使った時、値sumを作れるかどうか
    vector<vector<bool>> dp(N, vector<bool>(K+1, false));
    vector<ll> b;
    rep(i,0,N)
        if (i!=t)
            b.push_back(a[i]);

    dp[0][0]=true;
    rep(i,0,N-1){
        rep(s,0,K+1){
            if (!dp[i][s])
                continue;
            // b[i]を使う
            if(s+b[i]<=K)
                dp[i+1][s+b[i]] = true;
            // b[i]を使わない
            dp[i+1][s] = true;
        }
    }

    ll min_val = 1e15;
    rep(s,0,K+1){
        if (dp[N-1][s] && s+a[t]>=K){
            min_val = s+a[t];
            break;
        }
    }
    
    return min_val - a[t] < K;
}

signed main() {
    cin>>N>>K;
    a.resize(N);
    rep(i,0,N){
        cin>>a[i];
    }
    sort(begin(a),end(a));

    ll l=-1, r=N; // a_l以下は不要なカード、a_r以上は必要なカード
    while (l+1 < r){
        ll m=(l+r)/2;
        // printf("m=%d f(m)=%d\n", m, f(m));
        if (f(m))
            r=m;
        else
            l=m;
    }
    // printf("l=%d\n",l);
    cout<<l+1<<endl;
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N,x;
    vector<ll> A;
    vector<ll> addA;
    cin >> N >> x;
    for (int i = 0; i < N; i++) {
        ll a; cin >> a;
        A.pb(a);
    }
    asort(A);
    addA.pb(0);
    for (int i = 0; i < N; i++) {
        addA.pb(addA[i]+A[i]);
    }
    ll ans = -1;
    for (int i = 1; i <= N; i++) {
        if(addA[i] > x){
            ans = i-1;
            break;
        }
    }
    if(ans == -1){
        if(addA[N] == x){
            ans = N;
        } else if(addA[N] < x) {
            ans = N-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(a,b,c):
    return ((max(a,b,c,)*10)+a+b+c-max(a,b,c))

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b, str_c] = line.split(' ')
    return (int(str_a), int(str_b), int(str_c))

def main():
    a, b, c = readQuestion()
    answer = solve(a, b, c)
    print(answer)
    
if __name__ == '__main__':
    main()

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

int main(){
  int x;
  cin >> x;
  for(int i=-118;i<=119;i++){
    for(int j=-119;j<=118;j++){
      if(i*i*i*i*i-(j*j*j*j*j)==x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstA = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstA.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstA.Sort();
            int iOut = 0;
            for (int i = 1; i < lstA.Count; i++) { iOut += lstA[i] - lstA[i - 1]; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int n, m;
vector< vector<int> > edg;
vector<double> exp;
double f(int x, int y){
    if(x == n-1)return 0;
    if(exp[x] >= 0)return exp[x];
    int es = edg[x].size();
    double res = 0;
    double mx = 0;
    for(int i=0;i<es;i++){
        int z = edg[x][i];
        res += f(z, y) + 1;
        mx = max(mx, f(z, y)+1);
    }
    if(x == y && es > 1){
        res -= mx;
        es--;
    }
    return exp[x] = res / es;
}
int main(void){
    cin >> n >> m;
    edg.assign(n, vector<int>());
    exp.assign(n, -1);

    for(int i=0;i<m;i++){
        int s, t;
        cin >> s >> t;
        edg[--s].push_back(--t);
    }
    double ans = f(0, -1);
    for(int i=0;i<n;i++){
        exp.assign(n, -1);
        ans = min(ans, f(0, i));
    }


    cout << fixed << setprecision(16) << ans << endl;

}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> a(N);       //電球の状態
    int p = 0;
    int ans = 0;

    for (int i=0; i<M; i++){
        int k;
        cin >> k ;
        for (int j=0; j<k; j++){
            int s;
            cin >> s;
            s--;        //1から始まるから0スタートにする
            a[s] |= 1<<i;
        }
    }
    for (int i=0; i<M; i++){
        int x;
        cin >> x;
        p |= x << i;            //pのiビット目に保存
    }

    for (int s=0; s<(1<<N); s++){       //2^N個の状態(全て)を列挙できる
        int t=0;
        for (int i=0; i<N; i++){
            if (s>>i & 1){      //sのiビット目が1かどうかの判定
                t ^= a[i];
            }
        }
        if (t==p){
            ans++;  
        }
    }

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


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

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

		while(true){
			final int e = sc.nextInt();
			
			if(e == 0){
				break;
			}
			
			int min = Integer.MAX_VALUE;
			
			for(int z = (int)(Math.cbrt(e)); z >= 0; z--){
				for(int y = (int)(Math.sqrt(e - z*z*z)); y >= 0; y--){
					int x = e - z*z*z - y*y;
					
					min = Math.min(min, x + y + z);
				}
			}
			
			System.out.println(min);
		}
		
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
int sol;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i += 2)
    {
        int s = 0;
        for (int j = 1; j <= i; ++j)
            if (i % j == 0)
                s++;
        if (s == 8)
            sol++;
    }
    cout << sol;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List

main = do
    n <- readLn
    let (ts, ds) = partition (< n) $ scanl (+) 0 [1..n]
    let l = length ts
        m = (head ds) - n
    mapM_ print [1..m-1]
    mapM_ print [m+1..l]

Measured memory_bytes: 2044
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

int L[110] ;

int main()
{
	int n ;
	scanf ("%d", &n) ;
	
	for (int i=0; i<n; i++)
		scanf ("%d", L + i) ;
	
	int ans = 0 ;
	for (int i=0; i<n; i++)
		for (int j=i+1; j<n; j++)
			for (int k=j+1; k<n; k++)
				if (L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i] && L[i] != L[j] && L[j] != L[k] && L[i] != L[k])
					ans++ ;
					
	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 3284
#include<bits/stdc++.h>
#define rep(i,n) for(long long int i=0;i<n;i++)
#define lli long long int
#define ll long long 
#define dd double
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define limit 1000000000000000000
const double pi=3.14159265358;
const double pie=2*acos(0.0);
	
using namespace std;
lli power(lli a,lli b)
{
	lli res=1;
	while(b>0)
	{
		if(b%2!=0)
		{
			b--;
			res=(res%mod*a%mod)%mod;
		}
		else
		{
			a=(a%mod*a%mod)%mod;
			b/=2;
		}
	}
	return res%mod;
}
bool sortinrev(const pair<lli,lli> &a,  
               const pair<lli,lli> &b) 
{ 
       return (a.first > b.first); 
}

int main() {
	fast
	lli t;
	cin>>t;
	lli cnt=0;
	for(int i=1;i<=360;i++)
	{
		if((i*t)%360==0)
		{
			cnt=i;
			break;
		}
	}
		
		
	cout<<cnt<<endl;
}

Measured memory_bytes: 3532
#include <stdio.h>

int main()
{
   char o[100],e[100],s[100];
   int i;
   scanf("%s%s",o,e);
   for(i=0;i<=strlen(o);i++)
   {
   s[i*2]=o[i];
   }
   for(i=0;i<=strlen(e);i++)
   {
       s[i*2+1]=e[i];
   }
   printf("%s",s);
    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        String s = (a+b >= c) ? "Yes": "No";
        System.out.println(s);
    }

}

Measured memory_bytes: 21844
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

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

    double hx, hy, mx, my, dist;

    hx = sin(2 * M_PI * ((double)h / 12 + (double)m / 60 / 12)) * a;
    hy = cos(2 * M_PI * ((double)h / 12 + (double)m / 60 / 12)) * a;
    mx = sin(2 * M_PI * m / 60) * b;
    my = cos(2 * M_PI * m / 60) * b;

    dist = sqrt(pow(hx - mx, 2) + pow(hy - my, 2));

    cout.precision(12);
    cout << showpoint << dist;

    return 0;
}


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

typedef long long ll;
const int MAX_N = 100;

int main() {
	int W, H, N, x_min = 0, y_min = 0, x_max, y_max;
	std::cin >> W >> H >> N;
	x_max = W;
	y_max = H;
	for(int i = 0; i < N; ++i) {
		int x, y, a;
		std::cin >> x >> y >> a;
		switch(a) {
			case 1:
				x_min = std::max(x_min, x);
				break;
			case 2:
				x_max = std::min(x_max, x);
				break;
			case 3:
				y_min = std::max(y_min, y);
				break;
			case 4:
				y_max = std::min(y_max, y);
				break;
		}
	}

	std::cout << std::max(0, x_max - x_min) * std::max(0, y_max - y_min) << std::endl;
}

Measured memory_bytes: 256
use std::collections::{BTreeSet, VecDeque};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    let mut ins = vec![0; n];
    for _ in 0..(n - 1 + m) {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        ins[b] += 1;
    }

    let mut root = n;
    for i in 0..n {
        if ins[i] == 0 {
            assert_eq!(root, n);
            root = i;
        }
    }
    assert!(root != n);

    let mut parents = vec![n; n];
    let mut q = VecDeque::new();
    let mut count = vec![0; n];
    q.push_back(root);
    while let Some(v) = q.pop_front() {
        for &next in graph[v].iter() {
            count[next] += 1;
            if count[next] == ins[next] {
                parents[next] = v;
                q.push_back(next);
            }
        }
    }
    for i in 0..n {
        if i != root {
            println!("{}", parents[i] + 1);
        } else {
            println!("0");
        }
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

static int swap_count = 0;
void insert_sort(int* a, int length, int interval);
void shell_sort(int* a, int length);
void print(int* a, int length) {
    for (int i = 0; i < length; ++i) {
        cout << a[i] << endl;
    }
}


int main() {
    int length = 0;
    cin >> length;
    int* a = new int[length];
    for (int i = 0; i < length; ++i) {
        cin >> a[i];
    }

    shell_sort(a, length);
    return 0;
}

void insert_sort(int* a, int length, int interval) {
    for (int i = interval; i < length; ++i) {
        int v = a[i];
        int j = i - interval;
        while (j >= 0 && a[j] > v) {
            a[j + interval] = a[j];
            j -= interval;
            ++swap_count;
        }
        a[j + interval] = v;
    }
}
void shell_sort(int* a, int length) {
    swap_count = 0;
    int m = max(1, (int) floor(log(length) / log(2)));
    int* intervals = new int[m];
    cout << m << endl;
    int length_copy = length;
    bool is_first = true;
    for (int i = 0; i < m; ++i) {
        intervals[i] = length_copy / 2;
        if (is_first) {
            is_first = false;
        } else {
             cout << " ";
        }
        cout << intervals[i];
        length_copy /= 2;
    }
    cout << endl;
    for (int i = 0; i < m; ++i) {
        insert_sort(a, length, intervals[i]);
    }
    cout << swap_count << endl;
    print(a, length);
}

Measured memory_bytes: 7272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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(){
  int N; cin >> N;
  string S; cin >> S;
  vector<int> R;
  vector<int> G;
  vector<int> B;
  rep(i,N){
    if(S[i] == 'R') R.pb(i+1);
    if(S[i] == 'G') G.pb(i+1);
    if(S[i] == 'B') B.pb(i+1);
  }
  ll ans = 0;
  ll cnt = 0;
  rep(r,sz(R)){
    rep(g,sz(G)){
      if(R[r]>G[g]){
        int d = R[r]-G[g];
        if(binary_search(all(B), R[r]+d)) ans--;
        if(binary_search(all(B), G[g]-d)) ans--;
      }
      else{
        int d = G[g]-R[r];
        if(binary_search(all(B), R[r]-d)) ans--;
        if(binary_search(all(B), G[g]+d)) ans--;
      }
      if((R[r]+G[g])%2==0){
        int t = (R[r]+G[g])/2;;
        if(binary_search(all(B), t)) cnt++;
      }
      ans += sz(B);
    }
  }
  cout << ans-cnt << endl;
  return 0;
}


Measured memory_bytes: 3668
#include<stdio.h>
int main(){
  int X,A,B;
  int x;
  
    scanf("%d",&X);
    scanf("%d",&A);
  scanf("%d",&B);
  x=X-A;
  x=x-B*(x/B);
  printf("%d",x);
  
  return 0;
  
  
  
  
  
} 

Measured memory_bytes: 128
#include <cstdio>
#include <queue>
#include <utility>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

using P = std::pair<int, int>;
using PP = std::pair<P, int>;

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

int H, W;
char s[51][51];
int ans;
bool used[51][51];

int main()
{
  scanf( "%d%d", &H, &W );

  ans = H*W;

  rep( i, H )
  {
    scanf( "%s", s[i] );

    rep( j, W ) if( s[i][j] == '#' )
      --ans;
  }

  std::queue<PP> que;
  que.push( PP( P( 0, 0 ), 1 ) );
  used[0][0] = true;

  bool fl = false;

  while( !que.empty() )
  {
    PP pp = que.front(); que.pop();
    P pos = pp.first;
    int dist = pp.second;

    if( pos.first == H-1 && pos.second == W-1 )
    {
      ans -= dist;
      fl = true;
     
      break;
    }

    rep( i, 4 )
    {
      int nx = pos.first+dx[i], ny = pos.second+dy[i];

      if( nx >= 0 && nx < H && ny >= 0 && ny < W && !used[nx][ny] && s[nx][ny] != '#' )
      {
        que.push( PP( P( nx, ny ), dist+1 ) );
        used[nx][ny] = true;
      }
    }
  }

  if( !fl )
    puts("-1");
  else
    printf( "%d\n", ans );

  return 0;
}

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.setf(ios::fixed);
	cout.precision(4);
	
	int n, k = 1, p, flag, cont, ans = 0;

	cin >> n;

	vector <int> h(n);

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

	for (int i = 0; i < n; i++) {
		p = h[i];
		flag = i + 1;
		cont = 0;
		for (int j = 0; j < k; j++) {
			if (h[j] <= h[i]) cont++;
		}
		if (cont == flag) ans++;
		k++;
	}

	cout << ans << '\n';

	return 0;
}

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


int main() {
  int i,j;
  int N,K;
  cin>>N>>K;
  long long x[N];
  for(i=0;i<N;i++) cin>>x[i];
  sort(x,x+N);
  long long ans=-1;
  long long pre;
  for(i=0;i<=N-K;i++){
	if((x[i]<=0&&x[i+K-1]<=0)||(x[i]>=0&&x[i+K-1]>=0)){
		pre=max(abs(x[i]),abs(x[i+K-1]));
	}
	else pre=abs(x[i])+abs(x[i+K-1])+min(abs(x[i]),abs(x[i+K-1]));
	if(ans==-1) ans=pre;
	else ans=min(ans,pre);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	int n;
	cin >> n;
	for(int k = 0; k < n; k++) {
		string str1, str2;
		cin >> str1 >> str2;
		int a = str1.size(), b = str2.size();
		if(a > 80 || b > 80) {
			cout << "overflow" <<endl;
		} else if(a >= b) {
			for(int i = 0; i < b; i++) {
				str1[a - b + i] += str2[i] - '0';
				for(int i = a - 1; i >= 0; i--) {
					if(str1[i] > '9') {                 //?????????//
						if(i != 0) {
							str1[i] = str1[i] - ':' + '0';
							str1[i - 1] = str1[i - 1] + 1;
						}
					}
				}
			}
			if(a == 80 && str1[0] > '9') {
				cout << "overflow" <<endl;
			} else {
				for (int j = 0; j < a; j++) {
					if(str1[j] > '9') {
						printf("%d",str1[j] - '0');
					} else cout<< str1[j];
				}
				cout <<endl;
			}
		} else if(b > a) {
			for(int i = 0; i < a; i++) {
				str2[b - a + i] += str1[i] - '0';
				for(int i = b - 1; i >= 0; i--) {
					if(str2[i] > '9') {                    //?????????//
						if(i != 0) {
							str2[i] = str2[i] - ':' + '0';
							str2[i - 1] = str2[i - 1] + 1;
						}
					}
				}
			}
			if(b == 80 && str2[0] > '9') {
					cout << "overflow" <<endl;
			} else {
				for (int j = 0; j < b; j++) { 
					if(str2[j] > '9') {
						printf("%d",str2[j] - '0');
					} else cout << str2[j];
				}
				cout << endl;
			}
		}
	}
	return 0;
}

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

int main() {
    int a[3];
    rep(i, 3) cin >> a[i];
    int ans = 0;
    
    sort(a, a + 3);
    
    ans = (a[1] - a[0]) / 2;
    a[0] += ans * 2;
    
    ans += (a[2] - a[1]);
    a[0] += (a[2] - a[1]);
    a[1] = a[2];
    
    if (a[0] != a[1]) {
        ans += 2;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
sabc=[list(input()) for _ in range(3)]
abc=[0,0,0]
lsabc=['a','b','c']
lsABC=['A','B','C']
def func(turn):
    if abc[turn]==len(sabc[turn]):
        print(lsABC[turn])
        exit()
    next=lsabc.index(sabc[turn][abc[turn]])
    abc[turn]+=1
    func(next)
func(0)


Measured memory_bytes: 3188
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append((i, int(n / i)))
            if i != n // i:
                divisors.append((i, int(n // i)))
    return divisors

divisors = make_divisors(N)
length = 1e10
for d in divisors:
    if length > len(list(str(max(list(d))))):
        length = len(list(str(max(list(d)))))

print(length)

Measured memory_bytes: 3244
#include<cstdio>
#include<iostream>
#define int long long
using namespace std;
int n,sum,x,y,i;
signed main()
{
	scanf("%lld",&n);
	while(n--)
	{
		scanf("%lld%lld",&x,&y);
		if(y<=x)
		{
			while(x%y!=0)
			{
				int tmp = (x - x / y * y) / (x / y + 1);
				if(!tmp) x -= x / y + 1;
				else x-=tmp * (x / y + 1);
				
			}
			sum^=x/y;
		}
	}
	if(!sum)puts("Aoki");else puts("Takahashi");
}

Measured memory_bytes: 256
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        return a;
    }
    if a > b {
        return gcd(b, a % b);
    } else {
        return gcd(a, b % a);
    }
    
}

fn main() {
    let n = read1::<usize>();
    let t = (0..n).map(|_| read1::<usize>()).collect::<Vec<usize>>();
    let ans = t.iter().fold(1, |m, &a| {
        let g = gcd(a, m);
        m / g * a
    });
    println!("{}", ans);
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;



//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int i = 1; i < N; i++) cout << ", " << v[i]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()



lint ipow(lint x, lint n)
{
	lint i, ret = 1;
	for (i = 0; i < n; i++)
		ret *= x;
	return ret;
}

int problemB()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	lint odd = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) odd *= 2;
	}

	cout << ipow(3, N) - odd << endl;

	return 0;
}

int main()
{
	//clock_t start, end;
	//start = clock();

	problemB();

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> arr(n);
    for(auto &i:arr){
        cin>>i;
    }

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

    if(n==2){
        cout<<arr[0];
    }else if(n==3){
        cout<<arr[0]+arr[1];
    }else if(n==4){
        cout<<arr[0]+arr[1]+arr[1];
    }else{
        long long ans=arr[0];
        for(int i=2;i<n;i++){
            ans+=arr[i/2];
            // cout<<i<<" "<<i/2<<endl;
        }
        cout<<ans;
    }

}

Measured memory_bytes: 4032
def set(a, b):
  R[a].append(b)
  R[b].append(a)

N = int(input())
xy = [[i] + list(map(int, input().split())) for i in range(N)]
R = [[] for _ in range(N)]
xy.sort(key = lambda x: x[1])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  set(a[0], b[0])
xy.sort(key = lambda x: x[2])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  set(a[0], b[0])

xy.sort()
import heapq
q = [[0, 0]]
L = [True] * N
pop = heapq.heappop
push = heapq.heappush
ans = 0

for _ in range(N):
  k, t = pop(q)
  while not L[t]:
    k, t = pop(q)
  L[t] = False
  ans += k
  for i in R[t]:
    if L[i]:
      x = abs(xy[t][1] - xy[i][1])
      x = min(x, abs(xy[t][2] - xy[i][2]))
      push(q, [x, i])
print(ans)
# online help seeked

Measured memory_bytes: 48944
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int H, W;
/**********************************/

#define int long long
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>H>>W;

    int ans = MOD;
    UP(h, 1, H-1) {
        int s1 = W*(H-h);
        int s2 = (W/2)*h;
        int s3 = ((W+1)/2)*h;
        int big = max(s1,max(s2,s3));
        int small = min(s1,min(s2,s3));
        ans = min(ans, big-small);
    }
    UP(w, 1, W-1) {
        int s1 = H*(W-w);
        int s2 = (H/2)*w;
        int s3 = ((H+1)/2)*w;
        int big = max(s1,max(s2,s3));
        int small = min(s1,min(s2,s3));
        ans = min(ans, big-small);
    }
    int t1 = H*(W/3);
    int t2 = H*((W+2)/3);
    ans = min(ans, t2-t1);
    int v1 = W*(H/3);
    int v2 = W*((H+2)/3);
    ans = min(ans, v2-v1);
    cout << ans << endl;

}


Measured memory_bytes: 256