akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a[5][5];
bool flag[5][5];
pair<int,int> cor[105];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
		{
			cin>>a[i][j];
			cor[a[i][j]]=make_pair(i,j);
		}
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int b;
		cin>>b;
		flag[cor[b].first][cor[b].second]=1;
	}
	for(int i=1;i<=3;i++)
		if(flag[i][1]&&flag[i][2]&&flag[i][3])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	for(int i=1;i<=3;i++)
		if(flag[1][i]&&flag[2][i]&&flag[3][i])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	if(flag[1][1]&&flag[2][2]&&flag[3][3])
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(flag[1][3]&&flag[2][2]&&flag[3][1])
	{
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;
    dsu d(n+5);

    rep(i, q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t==0) d.merge(u, v);
        else {
            int ans = 0;
            if (d.same(u, v)) ans = 1;
            pr(ans);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3924
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int matiCount = int.Parse(Reader.ReadLine());
        long[,] Road = new long[matiCount, matiCount];
        for (int i = 0; i < matiCount; i++) {
            long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
            for (int j = 0; j < matiCount; j++) {
                Road[i, j] = inpt[j];
            }
        }
        bool[,] isFuyo = new bool[matiCount, matiCount];
        for (int i = 0; i < matiCount; i++) {
            for (int j = 0; j < matiCount; j++) {
                if(i==j) {
                    continue;
                }
                for (int k = 0; k < matiCount; k++) {
                    if(i==k) {
                        continue;
                    }
                    if(j==k) {
                        continue;
                    }
                    if(Road[j,k]>Road[j,i]+Road[i,k]) {
                        Console.WriteLine(-1);
                        return;
                    }
                    if(Road[j,k]==Road[j,i]+Road[i,k]) {
                        isFuyo[j, k] = true;
                    }
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < matiCount; i++) {
            for (int j = 0; j < matiCount; j++) {
                if(!isFuyo[i,j]) {
                    ans += Road[i, j];
                }
            }
        }
        Console.WriteLine(ans/2);
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



3
0 1 3
1 0 2
3 2 0


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 21592
#include <iostream>

using namespace std;

int main()
{
    int red_box, green_box, blue_box, balls;
    cin >> red_box >> green_box >> blue_box >> balls;

    int no_of_ways = 0;
    for(int r = 0; r*red_box <= balls; r++)
    {
        for(int g = 0; r*red_box + g*green_box <= balls; g++)
        {
            int balls_taken = r*red_box + g*green_box;
            int balls_remaining = balls - balls_taken;

            if(balls_remaining%blue_box == 0)
                no_of_ways++;
        }
    }

    cout << no_of_ways;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

bool search(ll N, vll& b, vll& ans){
  if(N==0) return true;
  ll tmp=-1;
  REP(i, N){
    if(i+1 == b[i]) tmp = i;
  }
  if(tmp==-1) return false;

  vll b_copy;
  REP(i, N){
    if(i==tmp) continue;
    b_copy.push_back(b[i]);
  }

  ans.push_back(b[tmp]);

  return search(N-1, b_copy, ans);
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vll b(N);
  REP(i, N) cin >> b[i];

  REP(i, N){
    if(i+1 < b[i]){
      cout << "-1\n";
      return 0;
    }
  }

  vll ans;
  bool flag = search(N, b, ans);

  if(!flag){
    cout << "-1\n";
    return 0;
  }else{
    REP(i, ans.size()){
      cout << ans[N-i-1] << "\n";
    }
    return 0;
  }

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <numeric>
#define ll long long
using namespace std;
int main() {
  int N;
  cin>>N;
  ll a[3*N],ans=0;
  for(int i=0;i<3*N;i++) cin>>a[i];
  sort(a,a+3*N);
  for(int i=3*N-2,cnt=0;cnt<N;i-=2,cnt++) ans+=a[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}
void solve()
{
//Read Comments below main

ll n,m;
cin>>n>>m;
ll ans=(m*(m-1))/2+(n*(n-1))/2;
cout<<ans<<endl;	
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constraint is of the order of 15-20, think of bitmask DP.
// 2)When some constraint is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int H, W, i, j;
  
  while(1){
    scanf("%d %d", &H, &W);
    if (H == 0 && W ==0) break;
    for (i = 0; i < H; i++){
      for (j = 0; j < W; j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

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

using namespace std;

/**/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/**/

#define LL long long
const int MAXN = 100000;
const int INF  = 0x3f3f3f3f;


int main () {

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

	std::vector<int> a(n), b(n);

	for (int i = 0; i < n; ++i) {
		scanf("%d %d", &a[i], &b[i]); //w v
	}

	std::vector<LL> dp(MAXN + 1, INF);

	dp[0] = 0;

	for (int i = 0; i < n; ++i) {
		for (int j = MAXN; j >= b[i]; --j) {
			dp[j] = min (dp[j], a[i] + dp[j-b[i]]);
		}
	}

	LL ans = 0;

	for (int j = MAXN; j >= 0; --j) {
		if (dp[j] <= w) {
			ans = max (ans, (LL)j);
		}
	}

	printf("%lld\n", ans);
	

	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,K;
    cin >> N >> K;
    vector<ll> cnt(N + 1);
    cnt.at(0) = 0;
    for(int i = 1;i < N + 1;i++) {
        cin >> cnt.at(i);
    }
    for(int i = 0;i < N;i++) {
        cnt.at(i + 1) += cnt.at(i);
    }
    vector<ll> cnt2;
    for(int i = 0;i < N;i++) {
        for(int j = i + 1;j < N + 1;j++) {
            ll C = cnt.at(j) - cnt.at(i);
            cnt2.push_back(C);
        }
    }
    int A = cnt2.size();
    vector<vector<int>> cnt3(A,vector<int>(41));
    for(int i = 0;i < A;i++) {
        for(int j = 0;j < 41;j++) {
            cnt3.at(i).at(j) = cnt2.at(i) % 2;
            cnt2.at(i) /= 2;
        }
    }
    ll ret = 0;
    vector<bool> flag(A,true);
    for(int i = 40;i >= 0;i--) {
        int count = 0;
        for(int j = 0;j < A;j++) {
            if(flag.at(j) == true && cnt3.at(j).at(i) == 1) {
                count++;
            }
        }
        if(count >= K) {
            ret += pow(2,i);
            for(int j = 0;j < A;j++) {
                if(cnt3.at(j).at(i) == 0) {
                    flag.at(j) = false;
                }
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 102128
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using ll = long long;
using namespace std;

ll calc_atack_num(ll hp){
  if(hp == 1) return 1;

  return 2*calc_atack_num(hp/2) + 1;
}

int main(){
  ll H;

  cin >> H;

  cout << calc_atack_num(H) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int digit_sum(int n){
	int sum;
	sum = 0;
	if (n < 10){
		return (n);
	}
	sum = sum + digit_sum(n / 10) + n % 10;
	return (sum);
}
int main(void){
	int N, A, B;
	int sum;
	int sumsum;
	int i;

	scanf("%d%d%d", &N, &A, &B);
	sumsum = 0;
	i = 0;
	while (i <= N){
		sum = digit_sum(i);
		//printf("sum: %d, i: %d\n", sum, i);
		if ((sum >= A) && (sum <= B)){
			sumsum += i;
			//printf("sumsum: %d\n", sumsum);
		}
		i++;
	}
	printf("%d\n", sumsum);
	return (0);
}


Measured memory_bytes: 1712
unittest
{
	assert( [ "3 3 2", "1 4 3", "2 5 7", "8 9 6", "1", "4 8" ].parse.expand.solve == "5" );
	assert( [ "4 2 3", "3 7", "1 4", "5 2", "6 8", "2", "2 2", "2 2" ].parse.expand.solve == "0\n0" );
	assert( [ "5 5 4", "13 25 7 15 17", "16 22 20 2 9", "14 11 12 1 19", "10 6 23 8 18", "3 21 5 24 4", "3", "13 13", "2 10", "13 13" ].parse.expand.solve == "0\n5\n0" );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hwd = input.front.split.to!( long[] );
	auto ass = new long[][]( hwd[ 0 ], hwd[ 1 ] );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
	}
	input.popFront;
	auto q = input.front.to!( long );
	auto lrs = new long[ 2 ][ q ];
	foreach( ref lr; lrs )
	{
		input.popFront;
		lr = input.front.split.to!( long[] );
	}
	return tuple( hwd[ 2 ], ass, lrs );
}

auto solve( long d, long[][] ass, long[ 2 ][] lrs )
{
	// マス目を番号基準の座標配列に変換
	auto ids = new Tuple!( long, long )[ 1 + ass.length * ass[ 0 ].length ];
	foreach( y, as; ass )
	{
		foreach( x, a; as )
		{
			ids[ a ] = tuple( y, x );
		}
	}
	
	// 消費魔力の累積和を計算
	auto cs = new long[ ids.length ];
	for( auto i = 1L; i + d < cs.length; i++ )
	{
		cs[ i + d ] = cs[ i ] + abs( ids[ i + d ][ 0 ] - ids[ i ][ 0 ] ) + abs( ids[ i + d ][ 1 ] - ids[ i ][ 1 ] );
	}
	
	// 試験ごとの消費魔力を計算
	return lrs.map!( ( lr ) => ( cs[ lr[ 1 ] ] - cs[ lr[ 0 ] ] ).to!string ).join( "\n" );
}


Measured memory_bytes: 13692
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define endl "\n"
#define print(X) cout << (X) << "\n"
// // #define input(X) getline(cin,X)
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
ll n,m,l;
string s,t;
ll d[200010],e[200010],dp[1001][1001];
char field[200][200];

int p[3] = {-1,0,1};

void check(int x, int  y){
  int ans = 0;
  rep(i,0,3){
    rep(j,0,3){
      if(field[x+p[i]][y+p[j]] == '#')ans++;
    }
  }
  dp[x][y] = ans;
}

int main(){
  cin >> n >> m;
  lep(i,1,n){
    lep(j,1,m){
      cin >> field[i][j];
    }
  }

  lep(i,1,n){
    lep(j,0,m){
      check(i,j);
    }
  }

  lep(i,1,n){
    lep(j,1,m){
      if(field[i][j] == '#')cout << field[i][j];
      else cout << dp[i][j];
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;


int main()
{

    ll n,k;
    cin>>n>>k;
    ll R,S,P;
    cin>>R>>S>>P;
    string s;
    cin>>s;
    ll ans=0;
    ll temp[n+10]= {0};
    for(ll i=0; i<zz(s); i++)
    {
        if(s[i]=='r')
        {
            ll rev=i-k;
            if(rev>=0)
            {
                if( temp[rev]==3)
                    continue;
            }
            ans+=P;
            temp[i]=3;
        }
        else if (s[i]=='s')
        {
            ll rev=i-k;
            if(rev>=0)
            {
                if( temp[rev]==1)
                    continue;
            }
            ans+=R;
            temp[i]=1;
        }
        else
        {

            ll rev=i-k;
            if(rev>=0)
            {
                if( temp[rev]==2)
                    continue;
            }
            ans+=S;
            temp[i]=2;

        }


    }

    cout<<ans<<nn;




}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 4532
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby
A = gets
N = gets.chomp.split.map(&:to_i)

if N.sort[0] == 0
  puts 0
  return
end

result = 1
N.each do |n|
  result *= n
  if 1e18 < result
    puts -1
    return
  end
end

puts result


Measured memory_bytes: 24976
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;


int main()
{
    int n; cin >> n;
    string s;
    map <string, int> m;
    int arr[4]={0, 0, 0, 0};
    for(int i = 0; i < n; i++)
    {
       cin >> s;
       m[s]++;
    }

    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}


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


int main(){
    int K;
    cin >> K;

    int sum = 0;

    for(int a=1; a<=K; a++){
        for(int b=1; b<=K; b++){
            for(int c=1; c<=K; c++){
                int A = a;
                int B = b;
                int C = c;

                //cout << A << B << C << endl;

                if(A<B){
                    int tmp = A;
                    A = B;
                    B = tmp;
                }

                int r = A % B;
                while(r!=0){
                A = B;
                B = r;
                r = A % B;
                }

                //cout << B << endl;
                
                if(C<B){
                    int btmp = C;
                    C = B;
                    B = btmp;
                }

                int s = C % B;
                while(s!=0){
                C = B;
                B = s;
                s = C % B;
                }

                //cout << B << endl;
                

                sum += B;
                
            }
        }

    }


    cout << sum;

    return 0;
}

Measured memory_bytes: 3676
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

int main(int argc, const char * argv[]) {
    int N;
    int last = 9999999, sum = 0, x;
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        cin >> x;
        sum += min(last, x);
        last = x;
    }
    sum += last;

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        int[] dp = new int[n];
        Arrays.fill(dp,Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i < n-1; i++){
            dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(a[i+1]-a[i]));
            if(i != n-2) dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(a[i+2]-a[i]));
        }
        pw.println(dp[n-1]);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 36928
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    int[] C = new int[K];
    int[] D = new int[K];
    for (int i = 0; i < K; i++) {
      C[i] = sc.nextInt();
      D[i] = sc.nextInt();
    }
    sc.close();
    /*
    */

    @SuppressWarnings("unchecked")
    Set<Integer>[] g = new Set[N + 1];
    int[] fc = new int[N + 1];
    for (int i = 0; i < M; i++) {
      int a = A[i];
      int b = B[i];
      if (g[a] == null && g[b] == null) {
        Set<Integer> set = new HashSet<>();
        set.add(a);
        set.add(b);
        g[a] = set;
        g[b] = set;
      } else if (g[a] == null) {
        Set<Integer> set = g[b];
        set.add(a);
        g[a] = set;
      } else if (g[b] == null) {
        Set<Integer> set = g[a];
        set.add(b);
        g[b] = set;
      } else if (g[a] != g[b]) {
        Set<Integer> setL = g[a];
        Set<Integer> setS = g[b];
        if (setL.size() < setS.size()) {
          Set<Integer> temp = setL;
          setL = setS;
          setS = temp;
        }
        setL.addAll(setS);
        for (int c : setS) g[c] = setL;
      }
      fc[a]++;
      fc[b]++;
    }

    int[] bc = new int[N + 1];
    for (int i = 0; i < K; i++) {
      int c = C[i];
      int d = D[i];
      if (g[c] == g[d]) {
        bc[c]++;
        bc[d]++;
      }
    }
    /*
    sc.close();
    */

    int[] ans = new int[N + 1];
    for (int i = 1; i < N + 1; i++)
      if (g[i] != null)
        ans[i] = g[i].size() - 1 - fc[i] - bc[i];

    StringBuilder buf = new StringBuilder();
    for (int i = 1; i < N + 1; i++)
      buf.append(ans[i]).append(' ');
    System.out.println(buf);
  }
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;

namespace math { namespace integer {

template<class T> T mod_mul(T x, T k, T m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x + x) % m, k / 2, m); } else { return (x + mod_mul(x, k - 1, m)) % m; } }
template<class T> T mod_pow(T x, T n, T mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
template<class T> T extgcd(T a, T b, T& x, T& y) { T d = a; if(b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class T> T mod_inverse(T x, T mod) { return mod_pow(x, T(mod - 2), mod); /* use fermat */ }
template<class T> T mod_inverse_composite_num_mod(T a, ll mod) { T x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}
using namespace math::integer;

ll const MOD = 1e9+7;

ll C(ll n, ll a) {
  ll x = 1;
  ll y = 1;
  rep(i, a) {
    x *= n - i;
    x %= MOD;
    y *= i + 1;
    y %= MOD;
  }
  return (x * mod_inverse(y, MOD)) % MOD;
}

int main() {
  ll n, a, b; cin >> n >> a >> b;
  ll all = (mod_pow(2LL, n, MOD) + (MOD - 1)) % MOD;
  cout << ((all + (MOD - C(n, a)) + (MOD - C(n, b))) % MOD) << endl;
}


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

int main(){
	int x;
	cin >> x;
	int ans = 1;
	for(int i = 1; i < x; i++){
		int beki = 1;
		for(int j = 2; j < x; j++){
			beki = pow(i,j);
			if(beki > x) continue;
			ans = max(ans,beki);
		}
		if(beki > x) continue;
		ans = max(ans,beki);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define INF 1000000000000000000LL
typedef pair<int,int>Q;
typedef pair<long long,int>T;
typedef pair<Q,Q>P;
long long min_cost[5][100009];
vector<P>node[100009];

int main(){
  int n,m,s,t;
  cin>>n>>m>>s>>t;
  for(int j=0;j<2;j++){
    for(int i=0;i<=n;i++){
      min_cost[j][i]=INF;
    }
  }
  for(int i=0;i<m;i++){
    int u,v,a,b;
    cin>>u>>v>>a>>b;
    node[u].push_back(P(Q(v,a),Q(b,0)));
    node[v].push_back(P(Q(u,a),Q(b,0)));
  }
  for(int j=0;j<2;j++){
    priority_queue<T,vector<T>,greater<T> >pq;
    if(j==0){
      pq.push(T(0,s));
      min_cost[0][s]=0;
    }
    else{
      pq.push(T(0,t));
      min_cost[1][t]=0;
    }
    while(!pq.empty()){
      T now=pq.top();pq.pop();
      long long cost=now.fi;
      int pos=now.se;
      for(int i=0;i<node[pos].size();i++){
        int next=node[pos][i].fi.fi;
        long long ncost;
        if(j==0)ncost=(long long)node[pos][i].fi.se;
        else ncost=(long long)node[pos][i].se.fi;
        if(cost+ncost<min_cost[j][next]){
          min_cost[j][next]=cost+ncost;
          pq.push(T(cost+ncost,next));
        }
      }
    }
  }
  priority_queue<T,vector<T>,greater<T> >p;
  for(int i=1;i<=n;i++){
    p.push(T(min_cost[0][i]+min_cost[1][i],i));
  }
  for(int i=0;i<n;i++){
    T now;
    while(1){
      now=p.top();
      if(now.se<=i)p.pop();
      else break;
    }
    cout<<1000000000000000LL-now.fi<<endl;
  }
  return(0);
}

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

int main() {
    ll n, a, count = 0;
    cin >> n >> a;
    vector<ll> A(n);
    
    for(int i = 0; i < n; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    for(int i = a; i < n; i++) {
        count += A[i];
    }
    
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1792
N = int(input())
H = list(map(int,input().split()))
ans = []
count = 0
if len(H) == 1:
  print(0)
  exit()
for i in range(1,N):
  if H[i-1] < H[i]:
    ans.append(count)
    count = 0
  elif H[i-1] >= H[i]:
    count += 1
  if i == N-1:
    ans.append(count)

print(max(ans))

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

using namespace std;

/*helpfull*/
using vl  = vector<long long>;
using vpl = vector<pair<long long, long long>>;
using vs = vector<string>;
using pl  = pair<long long, long long>;
using ll  = long long int;
using vb  = vector<bool>;


struct hash_pair {
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const
	{
		auto hash1 = hash<T1> {}(p.first);
		auto hash2 = hash<T2> {}(p.second);
		return hash1 ^ hash2;
	}
};
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

// shortcut macros
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp              make_pair
#define fi              first
#define se              second
// #define mt              make_tuple
#define pb              push_back
#define all(x)          (x).begin(), (x).end()
#define ini(a, v)       memset(a, v, sizeof(a))
#define rep(i, a, n)    for(ll i=a ; i<n ; ++i)
#define For(i, n)       rep(i, 0, n)
#define sz(x)           (int((x).size()))
#define ump(x,y)        unordered_map<x,y>
#define umpr(x,y,z)     unordered_map<x,y,z>
void printcase(ll &x) {
	cout << "Case #" << x << ": ";
}
void read(vector<ll>&v, ll &n) {
	For(i, n)
	cin >> v[i];
}
void read(ll &x) {
	cin >> x;
}
void read(string &s) {
	cin >> s;
}
void read(int &x) {
	cin >> x;
}
void read(ll a[], ll &n) {
	For(i, n)
	cin >> a[i];
}
void print() {
	cout << endl;
}
void write(vector<ll>&v, ll &n) {
	For(i, n)
	cout << v[i] << " ";
	cout << endl;
}
void write(vector<ll>&v) {
	ll n = v.size();
	For(i, n)
	cout << v[i] << " ";
	cout << endl;
}
void write(ll x) {
	cout << x << endl;
}
void write(string &s) {
	cout << s << endl;
}
void write(int &x) {
	cout << x << endl;
}
void write(ll a[], ll &n) {
	For(i, n)
	cout << a[i] << " ";
	cout << endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS;
	ll n;
	ll d;
	cin >> n >> d;
	ll c = 0;
	ll x, y;
	while (n--) {
		cin >> x >> y;
		if (x * x + y * y <= d * d)
			++c;
	}
	cout << c << endl;
	return 0;
}




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

int main(){
  string S;
  cin >> S;
  if(S[0]==S[1]||S[1]==S[2]||S[2]==S[0]){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

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

int main()
{
    int n,m,ans;

    cin >> n >> m;
    vector<int> h(n),ng(n);
    rep(i, n) {
        cin >> h[i];
        ng[i] = 0;  //NGデータクリア
    }
    rep(i, m) {
        int x1,x2;
        cin >> x1 >> x2;
        --x1;
        --x2;
        if (h[x1] <= h[x2])
            ++ng[x1];
        if (h[x2] <= h[x1])
            ++ng[x2];
    }

    ans = 0;
    rep(i, n)
        if (ng[i] == 0)
            ++ans;

    cout << ans << endl;

    return(0);
}


Measured memory_bytes: 4032
n = gets.to_i
a = gets.split.map(&:to_i)
gets; m = gets.split.map(&:to_i)

list = []
1.upto(n) do |i|
  list += a.combination(i).map {|e| e.inject(:+)}
end
m.each do |e|
  puts list.include?(e) ? 'yes' : 'no'
end

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

bool is_integer(double x) { return std::floor(x) == x; }

int main() {
    int x,tmp;
    map<int,int> v;
    cin >> x;

    v[1];

    for(int i = 2; i <= 40; i++){
        for(int j = i; j <= 1000; j*=i){
            if(j * i <= 1000){
                v[j*i];
            }else{
                break;
            }
        }
    }

    //for(auto a:v){ cout << a.first << " ";}


    for(auto a:v) {
        if(a.first > x){
            cout << tmp << endl;
            return 0; 
        }
        tmp = a.first;
    }
    cout << x << endl;
}

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

int main(){
    int H,W;cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin>>S[i];
    }
    vector<vector<int> > L(H,vector<int>(W,0));
    vector<vector<int> > R(H,vector<int>(W,0));
    vector<vector<int> > U(H,vector<int>(W,0));
    vector<vector<int> > D(H,vector<int>(W,0));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#') L[i][j]=-1;
          else if(j==0) L[i][j]=0;
            else L[i][j]=L[i][j-1]+1;
        }
    }
    for(int i=0;i<H;i++){
        for(int j=W-1;j>=0;j--){
          if(S[i][j]=='#') R[i][j]=-1;
          else if(j==W-1) R[i][j]=0;
            else R[i][j]=R[i][j+1]+1;
        }
    }
    for(int j=0;j<W;j++){
        for(int i=0;i<H;i++){
          if(S[i][j]=='#') U[i][j]=-1;
          else if(i==0) U[i][j]=0;
            else U[i][j]=U[i-1][j]+1;
        }
    }
    for(int j=0;j<W;j++){
        for(int i=H-1;i>=0;i--){
          if(S[i][j]=='#') D[i][j]=-1;
          else if(i==H-1) D[i][j]=0;
            else D[i][j]=D[i+1][j]+1;
        }
    }
    int m=-1;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++)if(S[i][j]!='#'){
            m=max(m,L[i][j]+R[i][j]+U[i][j]+D[i][j]+1);
        }
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 69120
#include <cstring>
#include <cstdio>
using namespace std;

int main() {
    char s[4];
    scanf("%s", s);
    if (strlen(s) == 2)
        printf("%s\n", s);
    else
        printf("%c%c%c\n", s[2], s[1], s[0]);
    return 0;
}


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

using namespace std;

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

  int n, m, a, b;
  cin >> n >> m;
  vector<set<int>> adj(n);
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    a--; b--;
    adj[a].insert(b);
    adj[b].insert(a);
  }
  vector<int> vert(n-1);
  iota(vert.begin(), vert.end(), 1);

  int res = 0;
  do {
    if (adj[0].find(vert[0]) == adj[0].end()) continue;
    bool ok = true;
    for (int i = 1; i < n-1; ++i) {
      if (adj[vert[i-1]].find(vert[i]) == adj[vert[i-1]].end()) {
        ok = false;
        break;
      }
    }
    if (ok) ++res;
  } while (next_permutation(vert.begin(), vert.end()));

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int x=0;
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		x^=--t%(k+1);
	}
	puts(x?"First":"Second");
}


Measured memory_bytes: 2132
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(n);
	REP(i, n) {
		cin >> v[i];
		v[i]--;
	}
	int cnt = 0;
	REP(i, n) {
		if (v[i] == i) {
			cnt++;
			++i;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

#define MAX 100000007

static unsigned char is_not_prime[((MAX + 1) + 7) / 8];

static inline int get_bit(int i) {
	return (is_not_prime[i >> 3] >> (i & 7)) & 1;
}

static inline void set_bit(int i) {
	is_not_prime[i >> 3] |= (1 << (i & 7));
}

void init(void) {
	int i, j;
	set_bit(0);
	set_bit(1);
	for (j = 4; j <= MAX; j += 2) set_bit(j);
	for (i = 3; i * i <= MAX; i += 2) {
		if (!get_bit(i)) {
			for (j = i * i; j <= MAX; j += i) set_bit(j);
		}
	}
}

int main(void) {
	int N, i;
	int count = 0;
	init();
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int q;
		if (scanf("%d", &q) != 1) return 1;
		if (!get_bit(q)) count++;
	}
	printf("%d\n", count);
	return 0;
}



Measured memory_bytes: 13996
class Bit:
    """1-indexed"""

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

    def max(self, i):
        m = 0
        while i > 0:
            m = max(m, self.tree[i])
            i -= i & -i
        return m

    def update(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i


N = int(input())
H = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))

S = sorted([(h, i) for i, h in enumerate(H)])

dp = Bit(N)
for h, i in S:
    dp.update(i + 1, dp.max(i) + A[i])
print(dp.max(N))


Measured memory_bytes: 134316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
   vector<int> A(N); 
 
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
 
  for (int i = 0; i < N; i++) {
    if(A[i]%2==0 && A[i]%3 != 0 && A[i]%5 !=0){
      cout << "DENIED" << endl;
      return 0;
  }
  }
    cout << "APPROVED" <<endl;
 
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    ll ans = 1e18;
    rep(mask, 1<<n) {
        ll tmp = 1LL;
        rep(i, n) {
            if(mask & (1<<i)) tmp *= 2;
            else tmp += k;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    int N;
    string S;
    

    cin >> N;
    cin >> S;

    int count = 0;
    bool finished = false;
    int tmp;
    vector<int> digit(3);

    for(int num = 0; num < 1000; num++) {
        tmp = num;
        for(int d = 2; d >= 0; d--) {
            digit[d] = tmp % 10;
            tmp /= 10;
        }

        finished = false;

        for(int i = 0; i < N-2; i++) {
            if(S[i] - '0' == digit[0]) {
                for(int j = i+1; j < N-1; j++) {
                    if(S[j] - '0' == digit[1]) {
                        for(int k = j+1; k < N; k++) {
                            if(S[k] - '0' == digit[2]) {
                                count++;
                                finished = true;
                                break;
                            }
                        }
                        finished = true;
                        break;
                    }
                    if(finished == true) {
                        break;
                    }
                }
                finished = true;
                break;
            }
            if(finished == true) {
                break;
            }
        }
    }

    cout << count << endl;
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[n];
  int dp[n];
  for(int i = 0 ; i <n ; i++){
    cin >> h[i] ;
    dp[i] = INT_MAX ;
  }
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2 ; i <n ; i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl ;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int arr [5];
    for(int i = 0; i < 5; i++) {
        cin >> arr[i];
        if(arr[i] == 0) {
            cout << (i+1) << '\n';
            break;
        }
    }
   
    return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rp(i,n) for (int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool { return abs(i) < abs(j); });
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;
double pi=3.14159265359;

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

//出力するよ
void output_tate(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        //if (i != 0)
        //    cout << " ";
        cout << s[i]<<endl;
    }
    //cout << endl;
}

void output_yoko(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        if (i != 0)
            cout << " ";
        cout << s[i];//<<endl;
    }
    cout << endl;
}

int dp[3010][3010][4];
int v[3010][3010]={};

signed main() {
    int r,c,K; cin>>r>>c>>K;
    rp(i,K){
        int ri,ci,vi;
        cin>>ri>>ci>>vi;
        v[ri-1][ci-1]=vi;
    }

    rp(i,3010) rp(j,3010) rp(l,4) dp[i][j][l]=-1;
    dp[0][0][0]=0;

    rp(i,r){
        rp(j,c){
            //dp[i][j][k]が非負のときは、一つ選んだ場合を考える。
            for(int k=2;k>=0;k--){
                if(dp[i][j][k]>=0){
                    dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+v[i][j]);
                }
            }
            rp(k,4){
                if(dp[i][j][k]>=0){
                    if(i+1<r) chmax(dp[i+1][j][0],dp[i][j][k]);
                    if(j+1<c) chmax(dp[i][j+1][k],dp[i][j][k]);
                }
            }
        }
    }

    int ans=-1;
    rp(k,4) chmax(ans,dp[r-1][c-1][k]);
    cout<<ans<<endl;
}


Measured memory_bytes: 357172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=405;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
/*
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		else a=a*a%MOD;
		b>>=1;
	}
	return res;
}
*/
ll dp[maxn][maxn];
int a[maxn],b[maxn];

ll ex[maxn][maxn];
ll pre[maxn][maxn];

int main()
{
	IOS;
	int n,c;
	cin>>n>>c;
	REP(i,n) cin>>a[i+1];
	REP(i,n) cin>>b[i+1];

	REP(i,maxn) REP(j,maxn){ //j^i
		if(i) ex[i][j]=ex[i-1][j]*j%MOD;
		else ex[i][j]=1;
	}
	REP(i,maxn) REP(j,maxn){
		if(j) pre[i][j]=(pre[i][j-1]+ex[i][j])%MOD;
		else pre[i][j]=0;
	}
	//REP(i,5) REP(j,5) cout<<ex[i][j]<<" \n"[j==4];
	//REP(i,5) REP(j,5) cout<<pre[i][j]<<" \n"[j==4];
	for(int i=1;i<=n;i++) REP(j,c+1){
		if(i==1){
			dp[i][j]=(pre[j][b[i]]-pre[j][a[i]-1]+MOD)%MOD;
		}
		else{
			dp[i][j]=0;
			for(int k=0;k<=j;k++){
				dp[i][j]+=dp[i-1][j-k]*(pre[k][b[i]]-pre[k][a[i]-1]+MOD)%MOD;
				//cout<<i<<' '<<j<<' '<<k<<' '<<dp[i-1][j-k]<<' '<<pre[k][b[i]]<<' '<<pre[k][a[i]-1]<<' '<<b[i]<<' '<<a[i]<<'\n';
				if(dp[i][j]>=MOD) dp[i][j]-=MOD;
			}
		}
		//cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
	}
	cout<<dp[n][c];
	return 0;
}


Measured memory_bytes: 4096