akhauriyash/Code-Regression huggingface dataset:
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(n: usize, ta: [(usize, usize); n]);

    let mut x = 1;
    let mut y = 1;
    for i in 0..n {
        let (t, a) = ta[i];
        // 切り上げ処理
        let n = max((x + t - 1) / t, (y + a - 1) / a);
        x = t * n;
        y = a * n;
    }
    println!("{}", x + y);
}


Measured memory_bytes: 4476
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <math.h>
#include <map>
#include <set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/** In set, multiset ,map etc the concept of index
    does not exist. */

/*

Bring me back to the time
When we were free, just you and I
Now I can feel the pressure building
The battle for us to survive

[Pre-Chorus]
You're an addiction
The only drug I'll ever need
Like a prescription
I crave you to breathe

[Chorus]
You're an addiction
The only drug I'll ever need
You're an addiction
The only drug I'll ever need

[Drop]
(You're an addiction)
(The only drug I'll ever need)

[Verse 2]
Bring me back to the time
When we would make it 'cross the line
Now I can feel the end is nearing
The time for us has arrived

[Pre-Chorus]
You're an addiction
The only drug I'll ever need
Like a prescription
I crave you to breathe

*/

/*

When I saw you I would lose control
Made me feel like there was no tomorrow
Should've told you that you're beautiful
But the days pass and now it's so long ago

Did you make it?
Did you break free?
Did you manage to be who you wanna be?
Maybe somewhere you think about me too

I wonder where are you now
~

*/


using namespace std;
using namespace __gnu_pbds;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

/** find_by_order(int k) -> iterator to kth largest element
    order_of_key(int e)  -> position of element with
    value 'e' ie. number of elements strictly less than e */

int mod=1000000007;

int powmod(int64_t a,int64_t b){
int64_t ans=1;while(b>0){if(b&1){b--;ans=(ans*a)%mod;}
else{a=(a*a)%mod;b=b>>1;}}return ans;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cout<<fixed;
    ///learn from your mistakes
    ///read the question properly
    ///initialize variables s'il vous plait
    vector <vector <int> > arr(5,vector <int> (5,0));
    int a,b;
    for(int i=0;i<3;i++){
        cin>>a>>b;
        arr[a][b]=1;
        arr[b][a]=1;
    }
    vector <int> x = {1,2,3,4};
    do{
        int f=1;
        for(int i=0;i<3;i++){
            if(arr[x[i]][x[i+1]]==0){
                f=0;
                break;
            }
        }
        if(f){
            cout<<"YES";
            return 0;
        }

    }while(next_permutation(x.begin(), x.end()));
    cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main()
{
    int n,m,k;cin >> n >> m >> k;
    vector<int>a(n); rep(i, n) cin >> a[i];
    vector<int>b(m); rep(i, m) cin >> b[i];
    // vector<ll>A(n+1,0), B(n+1,0);  // 累積和
    // rep(i, n){
    //     A[i+1] = a[i] + A[i];
    //     B[i+1] = b[i] + B[i];
    // }

    ll t = 0; //totalの時間
    rep(i,m) t += b[i];

    int j=m;  // b読んだ数。まずは全部読む。
    int ans = 0;
    rep(i, n+1){
        if(i != 0) t += a[i-1];
        while(j > 0 && t > k){  // bがまだある。bの合計時間がオーバー。
            --j;  // オーバーしてる分をへらす。
            t -= b[j];
        }
        if(t > k) break; //bが0冊でもオーバーなら終わり。これ以上a増やしても無駄。
        ans = max(ans, i+j);
        // if(i == n) break; //aの配列外参照を防ぐ
        // t += a[i];
    }
    cout << ans << endl;
    return 0;
}

/*
g++ c.cpp
./a.out

oj d https://atcoder.jp/contests/abc172/tasks/abc172_c
g++ c.cpp
oj t
*/


Measured memory_bytes: 4844
fun main(args: Array<String>) {
    val (h, w, d) = readLine()!!.split(' ').map { it.toInt() }
    val xs = IntArray(h * w + 1)
    val ys = IntArray(h * w + 1)

    for (i in 0 until h) {
        val a = readLine()!!.split(' ').map { it.toInt() }
        for (j in 0 until w) {
            xs[a[j]] = j + 1
            ys[a[j]] = i + 1
        }
    }

    val cs = IntArray(h * w + 1)
    for (r in 1..h * w) {
        if (r - d < 1) {
            cs[r] = 0
            continue
        }
        val l = r - d
        cs[r] = cs[l] + Math.abs(xs[r] - xs[l]) + Math.abs(ys[r] - ys[l])
    }

    val q = readLine()!!.toInt()
    (0 until q)
            .map {
                val (l, r) = readLine()!!.split(' ').map { it.toInt() }
                cs[r] - cs[l]
            }
            .joinToString("\n")
            .let { println(it) }

}


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

int main() {
  string s;
  int q;
  cin >> s >> q;
  
  string pre;
  string suf;
  
  bool reversed = false;
  
  for (int i = 0; i < q; i++) {
    int t,f;
    string cha;
    cin >> t;
    if (t == 2) {
      cin >> f >> cha;
    }
  
    if (t == 1) {
      reversed = !reversed;
    } else {
      if (f == 1) {
        if (reversed) {
          suf = suf + cha;
        } else {
          pre = cha + pre;
        }
      } else {
        if (reversed) {
          pre = cha + pre;
        } else {
          suf = suf + cha;
        }
      }
    }
  }
    
  s = pre + s + suf;
 
if (reversed) {
  std::reverse(s.begin(), s.end());
  cout << s << endl;
} else {
  cout << s << endl;
}
 
}

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

using namespace std;

int main(){
  int n;

  cin>>n;
  
  if(n == 0) {
	cout<<"No"<<endl;
    return 0;
  }
  
  for(int i = 9 ; i >= 1 ; i--){
  	if(( n % i == 0)&&( n / i <= 9 )){
		cout<<"Yes"<<endl;
		return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
def count_divisors(num):
  factor = 2
  divisors = 1
  
  while num > 1:
    exp = 0
    while num % factor == 0:
      num //= factor
      exp += 1
    divisors *= (exp + 1)
    factor += 1
    
  return divisors

n = int(input())
res = 0

for i in range(1, n + 1, 2):
  if count_divisors(i) == 8:
    res += 1
    
print(res)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i =0;
		int[] mat = new int[n];

		for (i = 0; i < n; i++) {
			mat[i] = sc.nextInt();
		}

		for (i = n - 1; i >= 0; i--) {
			if (i > 0) {
				System.out.print(mat[i] + " ");
			} else {
				System.out.println(mat[i]);
			}
		}
	}

}


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
#endif
}

const int N = 3e5 + 1e3;

#define mid ((l + r) >> 1)
#define lson ls[o], l, mid
#define rson rs[o], mid + 1, r

template<int Maxn>
struct President_Tree {

	int sumv[Maxn], ls[Maxn], rs[Maxn], tot;

	President_Tree() { tot = 0; }

	void Update(int pre, int &o, int l, int r, int up) {
		sumv[o = ++ tot] = sumv[pre] + 1; ls[o] = ls[pre]; rs[o] = rs[pre]; 
		if (l == r) return;
		up <= mid ? Update(ls[pre], lson, up) : Update(rs[pre], rson, up);
	}

	int Ask(int o, int l, int r, int qp) {
		if (!o || l == r) return sumv[o];
		return qp <= mid ? sumv[rs[o]] + Ask(lson, qp) : Ask(rson, qp);
	}

};

President_Tree<N * 20> T;

vector<int> V[N]; int rt[N];

int main () {

	File();

	int n = read(), m = read();

	For (i, 1, n)
		V[read()].push_back(read());
	For (i, 1, m) {
		rt[i] = rt[i - 1];
		for (int v : V[i]) {
			int tmp = 0; T.Update(rt[i], tmp, 1, m, v); rt[i] = tmp;
		}
	}

	For (i, 1, m) {
		int ans = n, j;
		for (j = i; j <= m; j += i)
			ans -= T.Ask(rt[j - 1], 1, m, j - i + 1);
		if (j > m && j - i + 1 <= m)
			ans -= T.Ask(rt[m], 1, m, j - i + 1);
		printf ("%d\n", ans);
	}

	return 0;

}

Measured memory_bytes: 81152
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout  << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2000000000;
const ll INF64 =3223372036854775807ll;
//const ll INF64 = 9223372036854775807ll;
//const ll INF64 = 9223372036854775ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;
//tuple<hoge,huga,foo> tのget関数はget<i>(t)

int main(){
    int n,x;
    std::cin >> n>>x;
    VEC(int,a,n);
    ll ans=0;
    if(a[0]>x){
        ans+=a[0]-x;
        a[0]-=a[0]-x;
    }
    rrep(i,1,n){
        int d=x-a[i-1];
        if(a[i]>=d){
            ans+=a[i]-d;
            a[i]-=a[i]-d;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 640
import java.util.Scanner ;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
       // int n = sc.nextInt();
        int a[] = new int[6];
        int count = 0 ; 
        for(int i=0 ; i<6 ; i++){
            a[i]= sc.nextInt();
        }
        for(int i= 0 ; i <6-1 ; i++){
            for(int j =i+1; j<6 ; j++ ){
                
                if((a[j]-a[i])>a[6-1])
                    
                        count++;
            }
            
            
        }
        if(count>0)System.out.println(":(");
        else System.out.println("Yay!");
    }
 
}


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

int main()
{long int n,k,i;
 cin>>n;
 long int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
long int dp[n];
 dp[0]=0;
 dp[1]=abs(a[1]-a[0]);
 for(i=2;i<n;i++)
 {
   dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
 }
 cout<<dp[n-1];
   return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  double  a, b, c, d, X, Y;
  //  double  c;
  int  A[103]={};
  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
//char s[101][101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  int tmp=0;
  int min=1000;
  int len=0;
  int cnt=0;
  int num=0;
  double ans=1000;
  int max=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%lf%lf", &a, &b);
//  cnt = strlen(t);
  //printf("%d\n",cnt);


  
//  if(flag==0)   printf("TLE\n");
  printf("%lf\n", a/b);
  
return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int h, w; cin >> h >> w;
  vector<string> a(h);
  for(int i=0; i<h; i++) cin >> a[i];

  vector<bool> ww(w, false);
  vector<bool> hh(h, false);
  for(int j=0; j<w; j++){
    bool f = true;
    for(int i=0; i<h; i++){
      if( a[i][j] == '#') f = false;
    }
    ww[j] = f;
  }
  for(int i=0; i<h; i++){
    bool f = true;
    for(int j=0; j<w; j++){
      if( a[i][j] == '#' ) f = false;
    }
    hh[i] = f;
  }

  for(int i=0; i<h; i++){
    bool f = false;
    for(int j=0; j<w; j++){
      if( ww[j] || hh[i] ) continue;
      cout << a[i][j];
      f = true;
    }
    if(f) cout << endl;
  }

  return 0;
}




//


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> v(n);
  rep(i,n)
  {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  ll sum = 0;
  rep(i,n)
  {
    if (m <= v[i].second) {
      sum += v[i].first * m;
      cout << sum;
      return 0;
    } else {
      sum += v[i].first * v[i].second;
      m -= v[i].second;
    }
  }
}


Measured memory_bytes: 1792
"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf-8"));

function main(input) {
  const date = ["SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"];
  input = input.trim().split("\n")[0];
  console.log(date.findIndex(e => e === input) + 1);
}


Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;
  cin >> N;
  
  int ans = 0;
  for( int i = 1; i <= N; i+=2 ){
    int cnt = 0;
    for( int j = 1; j <= sqrt(i); j++ ){
      if( i%j == 0 ){
        if( i != j ) cnt += 2;
        else if( i == j ) cnt++;
      }
    }
    if( cnt == 8 ) ans++;
  }
  cout << ans << endl;

}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    sort(H.rbegin(), H.rend());
    ll ans = 0;
    rep(i, N) {
        if (K > 0) {
            K--;
        }else{
            ans += H[i];
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1792
//Counting Sort
#include <iostream>

using namespace std;

const int k = 10000;

void countingSort(int A[], int B[], int n, int k) {
    int C[k+1];
    for(int i=0; i<k+1; i++) C[i] = 0;
    for(int i=0; i<n; i++) C[A[i]]++;
    for(int i=1; i<k+1; i++) C[i] += C[i-1];
    for(int i=n-1; i>=0; i--) {
        B[C[A[i]]-1] = A[i];
        C[A[i]]--;
    }
}

int main() {
    int n;
    cin >> n;
    int A[n], B[n];
    for(int i=0; i<n; i++) cin >> A[i];

    countingSort(A, B, n, k);

    for(int i=0; i<n-1; i++) cout << B[i] << " ";
    cout << B[n-1] << endl;
}


Measured memory_bytes: 18740
N, D, A = map(int, input().split())
tekis = []
for i in range(N):
    x, h = map(int, input().split())
    tekis.append((x, h))

tekis.sort()

haba = 2 * D

# iryoku, zahyoumigihaji
ruisekiwa = [(0, float("-inf"))]

left = 0

ans = 0
for i in range(N):
    x, h = tekis[i]

    while left < len(ruisekiwa) and ruisekiwa[left][1] < x:
        left += 1
    left -= 1
    # print("------x=", x, "h=", h)
    # print(ruisekiwa)
    # print("left=", left)

    imamadeiryoku = 0
    if left < len(ruisekiwa):
        imamadeiryoku = ruisekiwa[-1][0] - ruisekiwa[left][0]
    # print("imamadeiryoku=", imamadeiryoku)

    h -= imamadeiryoku

    bakudankaisuu = 0
    if h > 0:
        bakudankaisuu = h // A + (1 if h % A > 0 else 0)
    ans += bakudankaisuu
    # print("bakudannkaisuu", bakudankaisuu)
    bakudaniryoku = A * bakudankaisuu
    ruisekiwa.append((bakudaniryoku + ruisekiwa[-1][0], x + haba))

print(ans)

Measured memory_bytes: 77892
def func(n, a):
	if(0 in a):
		return 0
	tmp = [0 for i in range(n)]
	tmp[0] = a[0]
	for i in range(1, n):
		tmp[i] = tmp[i-1] * a[i]
		if(tmp[i] > 10**18):
			return '-1'
	
	return str(tmp[-1])

n = int(input())
a = list(map(int, input().split()))
s = func(n, a)
print(s)

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

using namespace std;
int main(){
    //([n][n][n*x] -> n^3 * x)
    long long dp[51][51][2501];
    for (int i=0;i<51;i++) for (int j=0;j<51;j++) for (int k=0;k<2501;k++) dp [i][j][k]=0;
    dp[0][0][0]=1;
    int n,a,x;
    long long ans=0;
    scanf("%d %d",&n,&a);
    for (int i=0;i<n;i++) {
        scanf("%d",&x);
        for (int j=0;j<50;j++) {
            for (int k=0;k<2501;k++) {
                if (dp[i][j][k]){
                    dp[i+1][j][k]+=dp[i][j][k];
                    dp[i+1][j+1][k+x]+=dp[i][j][k];
                }
            }
        }
    }
    for (int i=1;i<=n;i++) ans+=dp[n][i][i*a];
    printf("%lld\n",ans);
    return 0;
}

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

// definitions
#define __Imperial_Lord__ ONLINE_JUDGE
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c <<endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<endl
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<endl
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>             
ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}


// code beigns in main
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    while(t--)
    {
    	ll n;
    	cin >> n;
    	vl p(n),q(n);
    	cin >> p >> q;
    	ll pr=1;
    	rep(i,1,n+1) pr*=i;

    	// vl sp[pr],sq[pr];
    	
    	vl pf(n),qf(n);
    	iota(all(pf),1);
    	iota(all(qf),1);

    	ll a,b;
    	rep(j,0,pr)
    	{
    		// rep(i,0,n) sp[j].pb(p1[i]);
    		// rep(i,0,n) sq[j].pb(q1[i]);
    		if(pf==p) a=j+1;
    		if(qf==q) b=j+1;

    		next_permutation(all(pf));
    		next_permutation(all(qf));
    	}

    	p1(abs(a-b));
    }		
    exec;
}


Measured memory_bytes: 3792
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>

using namespace std;

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define FORi(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FOR(i,n) FORi(i,1,n)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;
using pii=pair<int, int>;
using pdd=pair<double, double>;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
    os<<'[';
    for(auto& p: c) os << p << " ";
    return os<<']';
}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
    print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}


template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
    os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
    print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
    print_tuple<0,Args...>(os<<'(',t);
    return os<<')';
}


constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;
constexpr int maxw=31;
constexpr int maxn=1001;

int arf[26];
vs ma;
int n, m;
bool solve() {
	int ji4 = 0;
	rep(i, 26) {
		ji4+= arf[i]/4;
		arf[i] %= 4;
	}
	if(n<m) swap(n, m);
	int zon4 = (n/2)*(m/2);
	if(zon4 > ji4) return false;
	ji4 -= zon4;
	int ji2 = ji4 * 2;
	rep(i, 26) {
		ji2 += arf[i]/2;
		arf[i] %= 2;
	}
	int zon2 = 0;
	if(n&1) zon2 += m/2;
	if(m&1) zon2 += n/2;
	if(zon2 > ji2) return false;
	return true;
}


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

	while(cin>>n>>m) {
		ma.clear();
		memset(arf, 0, sizeof(arf));
		rep(i, n) {
			string tmp;
			cin>>tmp;
			for(char c: tmp) arf[c-'a']++;
		}
		cout << (solve()?"Yes":"No") << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(V) V.begin(), V.end()
#define PB push_back
using namespace std;
typedef long long ll;

int main() {
    int d,t,s;
    cin >> d >> t >> s;
    if(d <= s*t){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void)
{
	int x;
	int max = 100004;
	int p[50000];
	int index;
	int i,j;
	int f = 0;
	int ret;

	p[0] = 2;
	index = 1;

	scanf("%d", &x);
	if (x == 2){
		ret = 2;
	}
	else{


		for (i = 3; i < max; i++){
			f = 0;
			for (j = 0; j < index; j++){
				if (i % p[j] == 0){
					f = 1;
					break;
				}
			}
			if (f == 0){
				p[index] = i;
				index++;
				if (x <= i){
					ret = i;
					break;
				}
			}
		}
	}
	printf("%d\n", ret);

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>


using namespace std;




int main() {
	int N;
	int cnt = 0;
	long long sum = 0;
	long long absmin = 99999999999;

	cin >> N;
	vector<long long> A(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] < 0)
			cnt++;
		if (abs(A[i]) < absmin)
			absmin = abs(A[i]);
		sum += abs(A[i]);
	}

	if (cnt % 2)
		cout << sum - 2*absmin <<endl;
	else
		cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	int a;
	char s[10000];
	cin >> a >> s;
	if (a >= 3200) {
		cout << s;
	}
	else {
		cout << "red";
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void) {
	int n, i, j, k;
	char cp;
	scanf("%d", &n);
	char S[n][100];
	int count[26] = {};
	int ans[26] = {};
	int flag = 0;
	for (i = 0; i < n; i++) scanf("%s", S[i]);

	for (i = 0; i < n; i++) {
		for (k = 0; k < 26; k++)count[k] = 0;
		for (j = 0; j < strlen(S[i]); j++) {
			//printf("%d",strlen(S[i]));
			count[S[i][j] - 'a']++;
		}
		for (k = 0; k < 26; k++) {
			if (flag == 0) {
				ans[k] = count[k];
			}
			else if (ans[k] > count[k]) {
				ans[k] = count[k];
			}
			//printf("%c:%d\n", 'a' + k, count[k]);
		}
		flag = 1;
	}

	for (i = 0; i < 26; i++) {
		for (; ans[i] != 0; ans[i]--) printf("%c", 'a' + i);
	}
	printf("\n");



	return 0;
}

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

using namespace std;
typedef long long ll;
const int M=1000000007;
int f[maxn],nf[maxn],n,m,K;
long long ans;

int C(int x,int y){
    if (y<0||y>x) return 0;
    return 1ll*f[x]*nf[y]%M*nf[x-y]%M;
}

int main(){
    f[0]=1; for (int i=1;i<maxn;i++) f[i]=1ll*f[i-1]*i%M;
    nf[0]=nf[1]=1; for (int i=2;i<maxn;i++) nf[i]=M-1ll*(M/i)*nf[M%i]%M;
    for (int i=2;i<maxn;i++) nf[i]=1ll*nf[i-1]*nf[i]%M;
    cin >> n >> m >> K;
    for (int k=1;k<=K;k++){
        long long res=(1ll*n*m%M*C(n+m-2,k-2)+1ll*(n+m)*C(n+m-1,k-1)+C(n+m,k))%M;
        (ans+=res*f[n+m-k]%M*f[k]%M*nf[n+m-K])%=M;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef int ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mods[] = {998244353, 1000000007, 1000000009};
const ll bases[] = {997, 1009, 1013};
// const ll mod = mods[0];
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll factorial(ll n,ll mod){
  static ll dp[100000];
  if(dp[n]) return dp[n];
  if(n == 0) return dp[n] = 1;
  return dp[n] = (n*factorial(n-1,mod))%mod;
}

ll powl(ll x,ll r,ll mod){
  ll ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

ll inverse(ll x,ll mod){
  static ll dp[100000];
  if(dp[x]) return dp[x];
  return dp[x] = powl(x,mod-2,mod);
}

ll combination(ll n,ll m,ll mod){
  static ll dp[3000][3000];
  if(n < m) return 0;
  if(dp[n][m]) return dp[n][m];

  return dp[n][m] = (((factorial(n,mod)*inverse(factorial(m,mod),mod))%mod)*inverse(factorial(n-m,mod),mod))%mod;
}


// (ax+b)^n
void expansion(vl& ret, ll a, ll b, ll n, ll mod){
  for(ll i = 0;i <= n;i++){
    ll hoge = powl(a,i,mod)*powl(b,n-i,mod);
    hoge %= mod;
    hoge *= combination(n,i,mod);
    hoge %= mod;
    ret[i] = hoge;
  }

}

ll p;
vl a;
vl b;
vl q;

int main(){

  cin >> p;
  a = vl(p);
  for(ll i = 0;i < p;i++){
    cin >> a[i];
  }
  b = vl(p);
  q = vl(p);
  for(ll i = 0;i < p;i++){
    if(a[i]){
      b[0]++;
      b[0] %= p;
      expansion(q, 1, (p-i)%p, p-1, p);
      for(ll j = 0;j < p;j++){
        b[j] -= q[j];
        b[j] = (b[j]+p)%p;
      }
    }

  }
  for(ll i = 0;i < p;i++){
    cout << b[i] << " ";
  }
  cout << endl;

}


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

const int N = 101;
int n, W, arr[N], v[N];
map < long long , int > dp[N];

int call(int i, long long w)
{
    if(i == n)
        return 0;
    if(dp[i].find(w) != dp[i].end())
        return dp[i][w];
    int ret = call(i + 1, w);
    if(w + arr[i] <= W)
        ret = max(ret, v[i] + call(i + 1, w + arr[i]));
    return dp[i][w] = ret;
}

int main()
{
    cin>>n>>W;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        cin>>v[i];
        dp[i].clear();
    }
    printf("%d\n", call(0, 0));
    return 0;
}


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

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main() 
{
  ll n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int max = *std::max_element(a.begin(), a.end());
  int max2;

  std::vector<int>::iterator iter = std::max_element(a.begin(), a.end());
  size_t index = std::distance(a.begin(), iter);

  a[index] = 0;
  
  max2 = *std::max_element(a.begin(), a.end());

  rep(i,n){
    if (i == index) {
      cout << max2 << endl;
    }else{
      cout << max << endl;
    }
  }

  return 0;
}


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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

struct Dice {
  int a, b, c, d, e, f;

  Dice(int a_, int b_, int c_, int d_, int e_, int f_) {
    a = a_;
    b = b_;
    c = c_;
    d = d_;
    e = e_;
    f = f_;
  }

  void spin(char ch) {
    int aa = a;
    int bb = b;
    int cc = c;
    int dd = d;
    int ee = e;
    int ff = f;

    if (ch == 'E') {
      a = dd;
      c = aa;
      d = ff;
      f = cc;
    } else if (ch == 'N') {
      a = bb;
      b = ff;
      e = aa;
      f = ee;
    } else if (ch == 'S') {
      a = ee;
      b = aa;
      e = ff;
      f = bb;
    } else if (ch == 'W') {
      a = cc;
      c = ff;
      d = aa;
      f = dd;
    }
  }
};

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  string commands;
  cin >> commands;

  Dice dice(a, b, c, d, e, f);

  rep(i, commands.size()) { dice.spin(commands[i]); }

  printf("%d\n", dice.a);
}



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

struct Node{
	int x, id;
	Node(){}
	Node(int _x, int _id){x = _x, id = _id;}
	bool operator < (const Node &A) const{
		return id > A.id;
	}
};

vector <int> from[100010];
priority_queue <Node> q;
int id[100010];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++){
		int u, v;
		scanf("%d%d", &u, &v);
		from[u].push_back(v);
		from[v].push_back(u);
	}
	int m;
	scanf("%d", &m);
	memset(id, -1, sizeof(id));
	for (int i = 0; i < m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		id[a] = b;
		q.push(Node(a, b));
	}
	while (!q.empty()){
		Node t = q.top(); q.pop();
		int u = t.x;
		for (int i = 0; i < from[u].size(); i++){
			int v = from[u][i];
			if (id[v] == -1) id[v] = t.id + 1, q.push(Node(v, t.id + 1));
		}
	}
	bool pd = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 0; j < from[i].size(); j++){
			int v = from[i][j];
			if (abs(id[i] - id[v]) != 1){
				pd = 1;
				break;
			}
		}
		if (pd) break;
	}
	if (pd){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for (int i = 1; i <= n; i++){
		printf("%d\n", id[i]);
	}
	return 0;
}


Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N;
  cin >> N;
  vector<long long> T(N), A(N);
  for (int i = 0; i < N; i++) cin >> T.at(i) >> A.at(i);
  
  long long t = T.at(0), a = A.at(0);
  for (int i = 1; i < N; i++)
  {
    long long p = 1;
    if (T.at(i) < t) chmax(p, divCeil(t, T.at(i)));
    if (A.at(i) < a) chmax(p, divCeil(a, A.at(i)));
    
    t = T.at(i) * p;
    a = A.at(i) * p;
  }
  
  long long ans = t + a;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{
    ll n;
    cin>>n;
    ll a[n+1],b[n];
    for(int i=0;i<n+1;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        int x=min(a[i],b[i]);
        cnt+=x;
        a[i]-=x;
        b[i]-=x;
        x=min(a[i+1],b[i]);
        cnt+=x;
        a[i+1]-=x;
        b[i]-=x;
    }
    cout<<cnt;
    return 0;
}











Measured memory_bytes: 1792
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)

cnt = 0
last = 0


for i in 1..n do
    # print a[i-1]," ",b[i-1]," ",last,"\n"
    if b[i-1] + last <= a[i-1]
        cnt += b[i-1] + last
        last = 0        
    elsif last > a[i-1]
        last = b[i-1]
        cnt += a[i-1]
    else
        last = b[i-1] + last - a[i-1]
        cnt += a[i-1]
    end

end

if a[n] <= last
    cnt += a[n]
else
    cnt += last
end
p cnt
    

Measured memory_bytes: 17556
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	int ans = 1, cnt = 1;
	rep(i, n) {
		cin >> a[i];
		ans *= 3;
		if (a[i] % 2 == 0) {
			cnt *= 2;
		}
	}
	cout << ans - cnt << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
x,y=map(int,input().split())
lx=[]
ly=[]
t=0
k=0
for i in s:
    if i=="F":
        t+=1
    else:
        if k:
            ly.append(t)
            k=0
        else:
            lx.append(t)
            k=1
        t=0
if k:
    ly.append(t)
else:
    lx.append(t)
x-=lx.pop(0)
sx,sy={0},{0}
for i in lx:
    t=set()
    for j in sx:
        t.add(i+j)
        t.add(j-i)
    sx=t
for i in ly:
    t=set()
    for j in sy:
        t.add(i+j)
        t.add(j-i)
    sy=t
if x in sx and y in sy:
    print("Yes")
else:
    print("No")

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



int main() {
	int N;
	cin >> N;
	
	rep(1, 10) {
		if (N%i==0 && N / i > 0 && N / i < 10) {
			//cout << i<<":"<<N / i << endl;
			cout << "Yes" << endl;
			return 0;
		}
	}
		cout << "No" << endl;
	
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i, ai in enumerate(a):
        if (i+1) % 2 == 1 and ai % 2 == 1:
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 61964
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile("\\s");
      int[] arrayS = delim
        .splitAsStream(line)
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 180884
import Control.Monad
import Data.List
import Data.Function (on)

main = do
  li <- getLine
  let n = read li
  sps <- forM [1..n] (\_ -> do
    li <- getLine
    let [s,p] = words li
    let ip = read p
    return (s,ip)
    )
  let answer = compute sps
  mapM_ print answer

compute :: [(String,Int)] -> [Int]
compute sps = map snd $ concat $ map reverse $
              groupBy ((==) `on` (fst.fst)) $ sort $ zip sps [1..]


Measured memory_bytes: 1020
#include <stdio.h>

void dfs(void);
void visit(int);

int n;
int G[101][101];
int color[101];
int d[101];
int f[101];
int time;
int main (){
  int i,j;
  int u,v,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)G[i][j] = 0;
  }
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      G[u-1][v-1] = 1;
    }
  }
  
  dfs();
  
  
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
    
  return 0;
}
void dfs(){
  int i;
  for(i=0;i<n;i++){
    color[i] = 0;
  }
  time = 0;
  for(i=0;i<n;i++){
    if(color[i] == 0)visit(i);
  }
}


void visit(int i){
  int m;
  color[i] = 1;
  d[i] = ++time;
  for(m=0;m<n;m++){
    if(G[i][m] == 0)continue;
    if(color[m] == 0)visit(m);
  }
  color[i] = 2;
  f[i] = ++time;
}



Measured memory_bytes: 2108
S = input()
S = S[::-1]
pattern = ["dream","dreamer","erase","eraser"]
for i in range(len(pattern)):
  pattern[i] = pattern[i][::-1]
while True:
  flag = False
  for v in pattern:
    if S[:len(v)] == v:
      S = S[len(v):]
      flag = True
  if S == "":
    print("YES")
    break
  elif not flag:
    print("NO")
    break

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
    bool tf=true;
    int tedad[3]={1,1,1};
    char str[4];
    cin>>str;
    for(int i=0;i<3;i++){
        if(str[i]=='a'){
            if(tedad[0]==1){
                tedad[0]=0;
            }
            else{
                tf=false;
                break;
            }
        }
        if(str[i]=='b'){
            if(tedad[1]==1){
                tedad[1]=0;
            }
            else{
                tf=false;
                break;
            }
        }
        if(str[i]=='c'){
            if(tedad[2]==1){
                tedad[2]=0;
            }
            else{
                tf=false;
                break;
            }
        }
    }
    if(tf==false){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}


Measured memory_bytes: 3584
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,ans;
int a[10005],ap;
int b[10005],c[10005];
int in[10005][2];
vector <int> v[10005];

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n-1;i++)
    {
        scanf("%d %d", &in[i][0], &in[i][1]);
        v[in[i][0]].push_back(in[i][1]);
        v[in[i][1]].push_back(in[i][0]);
        b[in[i][0]]++;
        b[in[i][1]]++;
    }
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    for(int i = 1;i <= n;i++)
    {
        if(b[ap] < b[i])
        {
            ap = i;
        }
    }
    queue <int> q;
    q.push(ap);
    int x,aa = n;
    while(!q.empty())
    {
        x = q.front();
        //cout << x << '\n';
        q.pop();
        if(c[x]) continue;
        c[x] = a[aa];
        aa--;
        for(int i = 0;i < v[x].size();i++)
        {
            q.push(v[x][i]);
        }
    }
    for(int i = 1;i <= n-1;i++)
    {
        ans += min(c[in[i][0]],c[in[i][1]]);
    }
    printf("%d\n",ans);
    for(int i = 1;i <= n;i++)
    {
        printf("%d ",c[i]);
    }
}

#endif // 1++

Measured memory_bytes: 1152
n=int(input())
arr=[]
dic={}
for i in range(0,n):
    a = int(input())
    arr.append(a)
    dic[a]=i%2
#print(dic)
brr=sorted(arr)
diff=0
for i in range(0,n):
    if dic[brr[i]] != i%2:
        diff+=1
print(diff//2)


Measured memory_bytes: 15728
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    long long a[n+2];
    long long b[n+1];
    for(int i = 1; i <= n+1; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    long long ans = 0;
    long long amari = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] - amari >= 0){
            ans += amari;
            if(a[i] - amari - b[i] >= 0){
                ans += b[i];
                amari = 0;
            } else {
                ans += a[i] - amari;
                amari = b[i] - (a[i] - amari);
            }
        } else {
            ans += a[i];
            amari = b[i];
        }
    }
    ans += min(a[n+1], amari);
    cout << ans << endl;
    return 0;
}

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

int main(void) {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < 4; ++i) {
    if (s[i] == '+') ++ans;
    else --ans;
  }
  cout << ans << 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;

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

    int ans = 1;

    rep(i, N){
        if (i == 0)ans *= K;
        else ans *= K-1;
    }

    cout << ans << endl;
}

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

typedef long long ll;

int main()
{
    ll N, Y;
    cin >> N >> Y;
    for (ll i = 0; i <= N; ++i)
    {
        for (ll j = 0; j <= N - i; ++j)
        {
            ll k = N - i - j;
            if (k < 0)
            {
                break;
            }
            ll en = 10000 * i + 5000 * j + 1000 * k;
            if (en == Y)
            {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <tuple>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

const std::vector<std::pair<int, int>> dxys{{1, 0}, {0, 1}};

bool solve() {
    int h, w, n;
    std::cin >> h >> w >> n;
    if (h == 0) return false;

    auto way = vec(h, vec(w, 0));
    for (auto& v : way) {
        for (auto& x : v) std::cin >> x;
    }

    auto visit = vec(h, vec(w, 0));
    visit[0][0] = n - 1;

    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            int m = visit[x][y];
            for (int i = 0; i < 2; ++i) {
                int dx, dy;
                std::tie(dx, dy) = dxys[i];

                int nx = x + dx,
                    ny = y + dy;
                if (nx >= h || ny >= w) continue;

                visit[nx][ny] += m / 2 + (m % 2 == 1 && way[x][y] == i);
            }

            if (m % 2 == 1) way[x][y] = 1 - way[x][y];
        }
    }

    int x = 0, y = 0;
    while (x < h && y < w) {
        int dx, dy;
        std::tie(dx, dy) = dxys[way[x][y]];
        x += dx, y += dy;
    }

    std::cout << x + 1 << " " << y + 1 << "\n";
    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 10840