akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int t[303][303];
int c[303][303];

int main() {
  for( int N, M; cin >> M >> N, (N || M); ) {
    
    for(int i = 0; i < N; i++)
      for(int j = 0; j < N; j++) {
        t[i][j] = 987654321;
        c[i][j] = 987654321;
      }

    for(int i = 0; i < N; i++) t[i][i] = c[i][i] = 0;
    
    for(int n = 0; n < M; n++) {
      int a, b, time, cost;
      cin >> a >> b >> time >> cost;
      a--, b--;
      t[a][b] = t[b][a] = time;
      c[a][b] = c[b][a] = cost;
    }
    
    for(int k = 0; k < N; k++)
      for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++) {
          t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
          c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
        }
    
    
    cin >> M;
    for(int m = 0; m < M; m++) {
      int a, b, r;
      cin >> a >> b >> r;
      a--, b--;
      if( r == 1 ) 
        cout << c[a][b] << endl;
      else 
        cout << t[a][b] << endl;
    }
    
  }
}

Measured memory_bytes: 1104
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
long long x;
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>x;
	//Keep following 6 - 5 - 6 - 5 - ...
	int temp=x%11;
	if (temp==0) cout<<2*(x/11);
	else {
		if (temp<=6) cout<<2*(x/11)+1;
		else cout<<2*(x/11)+2;
	}
	return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int y, n;
  cin >> y >> n;
  bool a[105] = {false};

  rep(i, 0, n) {
    int x;
    cin >> x;
    a[x] = true;
  }

  int ans = 0;

  rep(i, 1, 102) {
    if (a[i] == false) {
      if (abs(ans-y) > abs(i-y)) ans = i;
    }
  }

  cout << ans << '\n';
  return 0;
}


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

#define forn(i,m,n) for(int i=m;i<n;i++)
#define vv vector
#define vi vv<int>
#define ii pair<int,int>
#define vii vv<ii>
#define mp make_pair
#define pb push_back
#define PI 3.141592653589
#define ll long long
#define pll pair<ll,ll>
#define vl vv<ll>
#define ff first
#define ss second
#define MOD 1000000007

bool is_prime[1000001];
vi prime;
void sieve(int n)
{
    memset(is_prime,true,sizeof(is_prime));
    for(int i=2;i*i<=n;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {
                is_prime[j]=false;
            }
        }
    }
    forn(i,2,n+1)
    {
        if(is_prime[i])
            prime.pb(i);
    }
}


ll ex(ll a,ll b)
{
    ll res=1;
    a=a%MOD;
    while(b)
    {
        if(b%2){res=(res*a)%MOD;b--;}
        b/=2;
        a=(a*a)%MOD;
    }
    return res;
}

ll fermat_inv(ll a){ return ex(a,MOD-2); }
ll max(ll a,ll b){ return a>b?a:b; }
ll min(ll a,ll b){ return a<b?a:b; }


int main()
{
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
    //sieve(1000000);
    int te=1;
    //cin>>te;
    while(te--)
    {
        int n,k;
        cin>>n>>k;
        int a[n];
        bool dp[k+1];
        memset(dp,false,sizeof(dp));
        forn(i,0,n)
            cin>>a[i];
        forn(i,1,k+1)
        {
            forn(j,0,n)
            {
                if(a[j]>i || dp[i])
                    break;
                dp[i]=dp[i]||!dp[i-a[j]];
            }
        }
        if(dp[k])
            cout<<"First";
        else
            cout<<"Second";
    }
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  int a,b;
  cin >> N >> M;
  vector<int> road(N);
  for(int i = 0;i<M;i++){
	cin >> a >> b;
    road.at(a-1)++;
    road.at(b-1)++;
  }
  for(int i = 0;i<N;i++){
  	cout << road.at(i) <<endl;  
  }
return 0; 
}

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

ll abs(ll a){
    if(a<0) return -a;
    else return a;
}

int main() {
    int n,t,a;
    cin >> n >> t >> a;
    pair<int,ll> ans;
    ans = make_pair(-1,30000000);
    for(int i=0; i<n; i++){
        int h;
        cin >> h;
        if(abs((t-h*0.006)*1000-a*1000) < ans.second){
            ans = make_pair(i+1,abs((t-h*0.006)*1000-a*1000));
        }
    }
    cout << ans.first << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input!{
        n: usize,
        x: i64,
        a: [i64; n],
    }
    let mut a = a;
    a.sort();
    let a = a;
    let sum: i64 = a.iter().sum();
    if x >= sum {
        puts!("{}\n", if x == sum { n } else { n - 1 });
        return;
    }
    let mut rem = x;
    let mut cnt = 0;
    for i in 0 .. n {
        if rem >= a[i] {
            cnt += 1;
            rem -= a[i];
        }
    }
    puts!("{}\n", cnt);
}

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


Measured memory_bytes: 8572
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
long long ans = 0;
long long n;
cin >> n;
if(n==1){
    cout << 0 << endl;
    return 0;
}
long long fav;
long long k;
k = sqrt(n);
for(long long i=1;i<=k;i++){
    if((n-i) % i == 0){
        fav = (n-i) / i;
        if (n / fav == n % fav){
        ans += fav;
        //cout << ans << " " << fav << " " << i <<  endl;
        //cout << n / fav << " " << n % fav << endl;
        }
    }
}
cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

// 1

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

    int m, f, b;
    cin >> m >> f >> b;
    int k = b - m;
    if(k < 0) cout << 0 << endl;
    else if(k >= 0) {
        if(k > f) {
            cout << "NA" << endl;
        } else {
            cout << k << endl;
        }
    }
}


Measured memory_bytes: 3168
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	string S;
	cin>>S;
	int w;
	cin>>w;
	for(int i=0;i<S.length();i+=w)
		cout<<S[i];
	cout<<endl;
	return 0;
}

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

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

int main()
{
  int i;
  string str;
  cin >> str;
  REP(i, str.size()){
    if (str[i] < 'D') str[i] = 'Z' + 3 + (str[i] - 'C');
    printf("%c", str[i] - 3);
  }
  cout << endl;
}

Measured memory_bytes: 1172
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (1e6)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = (1e18)+7;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

int tab[maxn];

int main()
{
	_upgrade
	int n;
	cin>>n;
	int ile = 0;
	int res = 0;
	int poprz = -1;
	for(int i = 0 ;i < n;i++)
	{
		cin>>tab[i];
		if(tab[i] != poprz)
		{
			res += ile / 2;
			ile = 1;
		}
		else
			ile++;
		poprz = tab[i];
	}
	res += ile / 2;
	cout<<res;
			
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
//int mod = 1e9 + 7;
int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

int32_t main()
{
	AB_BHI_NI_DEGI
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int cost = 0;
	for (int i = 0; i < k; i++)
		cost += a[i];
	cout << cost << "\n";
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    ll k;
    cin >> n >> k;
    vector<P> input(n);
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        input[i] = P(a, b);
    }
    sort(input.begin(), input.end());
    vector<ll> sum(n+1, 0);
    for(int i = 0; i < n; ++i)  sum[i+1] = sum[i] + input[i].second;
    for(int i = 1; i <= n; ++i){
        if(sum[i] >= k){
            cout << input[i-1].first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int a=gi();
	    int b=gi();


	   // System.out.print(Math.max(0, a-2*b));

        if (a<10 && b<10) {
        	System.out.print(a*b);
        } else {
        	System.out.print(-1);
        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main() {
  int N, M; cin >> N >> M;
  vector<pair<int, int> > c[N];
  pair<int, int> ans[M];
  for (int i = 0; i < M; i++) {
    int p, y; cin >> p >> y;
    c[p-1].push_back({y, i});
  }
  for (int i = 0; i < N; i++) {
    sort(c[i].begin(), c[i].end());
    for (int j = 0; j < (int) c[i].size(); j++) {
      ans[c[i][j].second] = {i+1, j+1};
    }
  }
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", ans[i].first, ans[i].second);
  }
  return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
using std::cin;
using std::cout;
using std::endl;
using std::ios;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

int N;
int L[52];
int dp[52][52000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if(N >= 1000) cout << "ABD" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
ll ans,tmp,t;
int n;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",&tmp);
		if(i==1){
			ans=tmp;
			continue;
		}
		t=gcd(ans,tmp);
		ans*=tmp/t;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    
    void calc()
    {
        if (check()) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

    bool check()
    {

        cin = new Scanner();
        int A = cin.nextInt();
        int B = cin.nextInt();
        string S = cin.next();
        if (S[A] != '-') return false;
        for (int i = 0; i < S.Length; i++)
        {
            if (i == A) continue;
            if (!char.IsDigit(S[i])) return false;
        }
        return true;
    }

    

}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
n = int(input())
A = list(map(int, input().split()))
from collections import deque

B = deque()

if len(A) %2 ==0:
    for idx, a in enumerate(A):

        if idx % 2 == 0:
            B.append(a)
        else:
            B.appendleft(a)

else:
    for idx, a in enumerate(A):

        if idx % 2 == 0:
            B.appendleft(a)
        else:
            B.append(a)
print(*B)

Measured memory_bytes: 98872
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break

    if 0 in a:
        ans = 0

    print (ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 21644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] a = new long[n];
		long[] abs = new long[n];
		long absmin = Long.MAX_VALUE;
		long sum = 0;
		int count = 0;
		for(int i=0;i<n;i++) {
			a[i] = in.nextInt();
			if(a[i]<0) count++;
			abs[i] = Math.abs(a[i]);
			if(abs[i]<absmin) absmin = abs[i];
			sum += abs[i];
		}
		System.out.println(count%2==0?sum:sum - absmin*2);
		in.close();
	}

}


Measured memory_bytes: 58516
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int prime[100100];

void pgen()
{

    prime[0]=1;
    prime[1]=1;
    for(int i=2; i*i<=100000; i++)
    {
        for(int j=i+i; j<=100000; j+=i)
        {
            prime[j] = 1;
        }
    }


}

int main()
{
    pgen();
    int n;
    cin >> n;
   for(int cnt=1,i=3; cnt<=n; i++)
   {
       if(!prime[i] && i%10==1)
       {
         cout << i << " " ;cnt++;
       }
   }

}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#include <queue>
#define REP(i, n) for (ll i = 1; i <= n; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ld long double
using namespace std;

int main()
{
    string T;
    cin >> T;
    ll ans = 0;
    string ansString = "";
    vector<ll> index;
    rep(i, T.size())
    {
        if (T.at(i) == '?')
        {
            index.push_back(i); //何番目が？か
        }
    }

    string keep = "";
    keep = T;

    rep(i, index.size())
    {
        keep.at(index[i]) = 'D';
    }
    ansString = keep;
    cout << ansString << endl;
}

Measured memory_bytes: 5508
A, B, K = map(int, input().split())

for i in range(K):
    if i % 2 == 0:
        A = A if A % 2 == 0 else A - 1
        A //= 2
        B += A
    else:
        B = B if B % 2 == 0 else B - 1
        B //= 2
        A += B
print(A, B)


Measured memory_bytes: 38256
#include<stdio.h>
int main () {
   int n, i, a[10000];
   int min, max;
   long int sum;

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

   min = a[0];
   max = a[0];
   sum = 0;

   for (i =  0; i < n; i++) {
     if (a[i] > max) {
       max = a[i];
     }
     if (a[i] < min) {
       min  = a[i];
     }
     sum = sum + a[i];
   }
   
   printf("%d %d %ld\n",min,max,sum);

   return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int h, a; cin >> h >> a;
    int cnt=0;
    while(h > 0){
        h -= a;
        cnt++;
    }
    cout << cnt << endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n-1);
    int i;
    for(i = 0; i < n-1; i++){
        cin >> b.at(i);
    }
    for(i = 0; i < n; i++){
        if(i == 0){
            a.at(i) = b.at(i);
        }
        else if(i == n-1){
            a.at(i) = b.at(i-1);
        }
        else if(b.at(i-1) < b.at(i)){
            a.at(i) = b.at(i-1);
        }
        else if(b.at(i-1) > b.at(i)){
            a.at(i) = b.at(i);
        }
        else if(b.at(i-1) == b.at(i)){
            a.at(i) = b.at(i);
        }
    }
    int ans = 0;
    for(int x : a){
        ans += x;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  ll d;
  cin>>d;
  ll c[26];
  for (ll i = 0; i < 26; ++i)
  {
    cin>>c[i];
  }
  vector<vector<ll>> s(d,vector<ll>(26));
  for (ll i = 0; i < d; ++i)
  {
    for (ll j = 0; j < 26; ++j)
    {
      cin>>s[i][j];
    }
  }
  ll t;
  ll ans=0;
  vector<ll> last(26,-1);
  for (ll i = 0; i < d; ++i)
  {
    vector<ll> value(26,ans);
    for (int t = 0; t < 26; ++t)
    {
      vector<ll> last2=last;
      value[t]+=s[i][t];
      last2[t]=i;
      for (ll j = 0; j < 26; ++j)
      {
        value[t]-=c[j]*(i-last[j]);
      }
    }
    ans=*max_element(value.begin(), value.end());
    last[max_element(value.begin(), value.end())-value.begin()]=i;
    cout<<1+max_element(value.begin(), value.end())-value.begin()<<endl;
  }
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
    using namespace std;
    long long n,kir,kan,mid,y,ans,ac,cc;
    long long a[100002];
    long long b[100002];
    long long c[100002];
    long long binsera(long long y){
    	kir = -1;
    	kan = n;
    	while(kan -kir > 1){
    		mid = (kir+kan)/2;
    		if(a[mid] >= y){
    			kan=mid;
    		}
    		else kir = mid;
    	}
    	return kir+1;
   }
  long long binserc(long long y){
    	kir = -1;
    	kan = n; 
    	while(kan -kir > 1){
    		mid = (kir+kan)/2;
    		if(c[mid] >= y){
    			kan=mid;
    		}
    		else kir = mid;
    	}
    	return n-kan;
    }
     
    int main(){
    	cin >> n;
    	for(int i=0;i<n;i++){
    		cin >> a[i];
    	}
    	for(int i=0;i<n;i++){
    		cin >> b[i];
    	}
    	for(int i=0;i<n;i++){
    		cin >> c[i];
    	}
    	sort(a,a+n);
    	sort(b,b+n);
    	sort(c,c+n);
    	ans = 0;
    	for(int i=0;i<n;i++){
    		y= b[i];
    	    ac = binsera(y);
    		cc = binserc(y+1);
    		ans = ans+ (ac*cc);
    		
    	}
    	cout << ans<< endl;
    }

Measured memory_bytes: 5912
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;
 
/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 * 0.5 == 1.0/2
 * Integer.valueOf(char)はダメ、(String)
 */
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println((a < b && b < c)?"Yes":"No");
		
	}
}


Measured memory_bytes: 26324
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<queue>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>

#define LL long long

using namespace std;

int n;

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

	return 0;
}



Measured memory_bytes: 256
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	fastio;
	int k;
	cin>>k;
	cout<<a[k-1];
	return 0;
}


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

using namespace std;

using ll=long long ;
const int MAXN=107 , maxw=1e5+5;

ll N, W , w[MAXN] , v[MAXN];
ll mem[MAXN][maxw];

ll dp(int i , int totalWeight)
{
    if(i==N){
            return 0;
    }

    if(mem[i][totalWeight]!=-1)return mem[i][totalWeight];

    ll path1=dp(i+1 , totalWeight);
    ll path2=0;

    if(totalWeight+w[i]<=W){
        path2=v[i]+dp(i+1 , totalWeight+w[i]);
    }

    mem[i][totalWeight]=max(path1 , path2);

    return mem[i][totalWeight];
}


int main()
{
    scanf("%lld %lld" ,&N , &W);

    memset(mem , -1 , sizeof mem);

    for(int i=0 ; i<N ; i++){
        scanf("%lld %lld" , &w[i] , &v[i]);
    }
    printf("%lld\n" , dp( 0, 0));



    return 0;
}


Measured memory_bytes: 83840
#include<cstdio>
#include<algorithm>
int divisor(long long n,long long d[]){
	int i=0;
    long long m;
	for(m=1;m*m<=n;m++){
		if(n%m==0){
			d[i]=m;
            i++;
		}
	}
    return i;
}
int digit(long long n,int k=10){
	int ans=0;
	while(n>0){
		ans++;
		n/=k;
	}
	return ans;
}
long long d[2000];
int main(){
    long long n,k,f=1e9;
    scanf("%lld",&n);
    k=divisor(n,d);
    for(int i=0;i<k;i++){
        f=std::min(f,(long long)std::max(digit(d[i]),digit(n/d[i])));
    }
    printf("%lld",f);
    return 0;
}

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

signed main(){
	int N,M; cin>>N>>M;
	vector<pair<int,int>> AB(N);
	for(int i=0;i<N;i++){
		cin>>AB[i].first>>AB[i].second;
	}
	sort(AB.begin(),AB.end());
	int p=0,ans=0;
	priority_queue<pair<int,int>> que;
	for(int i=1;i<=M;i++){
		while(AB[p].first<=i and p<N){
			pair<int,int> tmp=make_pair(AB[p].second,AB[p].first);
			que.push(tmp);
			p++;
		}
		if(not que.empty()){
			pair<int,int> tmp=que.top();
			que.pop();
			ans+=tmp.first;
		}
	}
	cout<<ans<<endl;
	return 0;

}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

i64 N, K;

int main() {
    cin >> N >> K;
    f64 p = 0;
    REPS(i, N) {
        i64 x = i;
        i64 cnt = 0;
        while (x < K) {
            x *= 2;
            cnt++;
        }
        p += pow(0.5, cnt) * (1.0 / (f64)N);
    }
    cout << p << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string Aw, Bw, Uw;
  int A, B;
  cin >> Aw  >> Bw  >> A >> B >> Uw;
  
  if (Aw==Uw) {
    cout << A-1 << " " << B << endl;
  }
  
  else if (Bw==Uw) {
    cout << A << " " << B-1 << endl;
  }
  
  else {
    cout << A << " " << B << endl;
  }
}
  
  

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] A = new int[3];
		for (int i = 0; i < 3; i++) {
			A[i] = sc.nextInt();
		}

		Arrays.sort(A);

		int sum = 0;
		for (int i = 1; i < A.length; i++) {
			sum += A[i] - A[i - 1];
		}

		System.out.println(sum);
	}
}

Measured memory_bytes: 23124
#include<iostream>
using namespace std;
typedef long long int ll;
int main(){
ll A, V;
cin >> A >> V;
ll B,W;
cin >> B >> W;
ll T;
cin >> T;
ll D=abs(A-B);
ll D2=(V-W)*T;
puts(D<=D2?"YES":"NO");
}

Measured memory_bytes: 3632
def c_traveling_plan():
    N = int(input())
    # 原点から出発して最後に原点に帰るためこうする (forループも楽)
    A = [0] + [int(i) for i in input().split()] + [0]

    total_tour_cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
    ans = []
    for i in range(1, N + 1):
        # a_{i-1} -> a_i -> a_{i+1} の長さ(delta1)を引き，
        # a_{i-1} -> a_{i+1} の長さ(delta2)を足す
        delta1 = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])
        delta2 = abs(A[i - 1] - A[i + 1])
        ans.append(total_tour_cost - delta1 + delta2)
    return '\n'.join(map(str, ans))

print(c_traveling_plan())

Measured memory_bytes: 20112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author CodeMonk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt(), e = in.nextInt(), f = in.nextInt();
            int[] ok = new int[50];
            ok[0] = 1;
            for (int i = 1; i < 50; i++) {
                if (i - a >= 0) ok[i] |= ok[i - a];
                if (i - b >= 0) ok[i] |= ok[i - b];
            }
            int[] ok2 = new int[4000];
            ok2[0] = 1;
            for (int i = 1; i < 4000; i++) {
                if (i - c >= 0) ok2[i] |= ok2[i - c];
                if (i - d >= 0) ok2[i] |= ok2[i - d];
            }
            long mw = 1, ms = -1;
            for (int i = 1; 100 * i <= f && i < 50; i++) {
                for (int j = 0; 100 * i + j <= f && j < 4000; j++) {
                    if (j > i * e) continue;
                    if (ok[i] == 0) continue;
                    if (ok2[j] == 0) continue;                  
                    if (ms * (100 * i + j) < (100 * mw + ms) * j) {
                        mw = i;
                        ms = j;
                    }
                }
            }
            out.println(mw * 100 + ms + " " + ms);
        }

    }
}



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

int main(){
	int M, K, i, A, B;
	scanf("%d%d", &M, &K);
	if(K == 0){
		for(i = 0; i < (1 << M); i++){
			printf("%d %d ", i, i);
		}
		printf("\n");
		return 0;
	}
	if(K >= (1 << M)){
		printf("-1\n");
		return 0;
	}
	if(M == 1 && K == 1){
		printf("-1\n");
		return 0;
	}
	vector<int> a(1 << M, 1);
	a[K] = 0;
	for(i = 0; i < M; i++){
		A = (1 << i);
		B = (K ^ A);
		if(A != K && B != K){
			break;
		}
	}
	a[A] = 0;
	a[B] = 0;
	printf("%d %d %d %d ", K, A, B, K);
	for(i = 0; i < (1 << M); i++){
		if(a[i] == 1){
			printf("%d ", i);
		}
	}
	printf("%d %d ", B, A);
	for(i = (1 << M) - 1; i >= 0; i--){
		if(a[i] == 1){
			printf("%d ", i);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,M;
  cin >> N >> M;
  int n = M/N;
  for(int i=n;i>0;i--)
  {
    if((M-(N-1)*i)%i==0)
    {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
ll a,b;
int main(){ //srand((unsigned)time(NULL));
  cin >> a >> b;
  cout << a*b << " " << 2*a+2*b << endl;
}



Measured memory_bytes: 3108
#include<stdio.h>
int main(){
  int i;
  char s[1010]={0};
  fgets(s,1001,stdin);
  for(i=0;s[i];i++){
    if     (s[i]=='a'&&s[i+1]=='p'&&s[i+2]=='p'&&s[i+3]=='l'&&s[i+4]=='e'){
      printf("peach");
      i+=4;
    }
    else if(s[i]=='p'&&s[i+1]=='e'&&s[i+2]=='a'&&s[i+3]=='c'&&s[i+4]=='h'){
      printf("apple");
      i+=4;
    }
    else printf("%c",s[i]);
  }
  return 0;
}
  

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

#define max(a,b) (((a) < (b)) ? (b) : (a))
#define min(a,b) (((a) > (b)) ? (b) : (a))
int main(void) {
    int A,B,C,D;
    int temp;
    cin >> A >> B >> C >> D;
    temp = min(B,D) - max(A,C);
    if (temp < 0) temp = 0;
    cout << temp << "\n";


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)    for (int i = (int)b; i < (int)e; i++)
#define forr(i, b, e)    for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);
#define tam 3341
int N,S;
int dp[tam][tam];
int v[tam];
const int MOD=998244353;
int f(int pos,int s)
{
    if (s==0)
        return (N-pos+1);
    if (s<0)
        return 0;
    if (pos==N)
        return 0;
    if (dp[pos][s]!=-1)
        return dp[pos][s];

    ll tot=0;
    tot+=f(pos+1,s-v[pos]);
    tot%=MOD;
    tot+=f(pos+1,s);tot%=MOD;
    return dp[pos][s]=tot;
}
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    cin>>N>>S;
    forr(i,0,N)
        cin>>v[i];
    memset(dp,-1,sizeof dp);
    ll tot=0;
    forr(i,0,N)
    {
        tot+=f(i+1,S-v[i])*(ll)(i+1);
        tot%=MOD;
    }
    cout<<tot<<endl;
}
// PLUS ULTRA!


Measured memory_bytes: 44032
import numpy as np

n, a, b = map(int, raw_input().split())
l = []

for i in range(n):
	l.append(input())
ll = np.array(l)
ll.sort()
ll = ll[::-1]

def solve(hp, count):
	q = hp - b * count
	t = q > 0

	if a > b:
		p = (q - 1) / (a - b) + 1
	else:
		p = q
	p = p[p > 0]
	if p.sum() <= count:
		return True
	else:
		return False

l = 1
r = ll[0] / b + 1
while r - l > 1:
	m = (l + r) / 2
	if solve(ll, m):
		r = m
	else:
		l = m

if r == 2:
	if solve(ll, 1):
		r = 1

print r

Measured memory_bytes: 18580
import java.io.*;
import java.util.*;

public class Main{
    static public void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        int N =sc.nextInt(), K = sc.nextInt();
        long R = sc.nextLong(), S = sc.nextLong(), P = sc.nextLong();
        char[] T = sc.next().toCharArray();
        // dp[i][j]: at the i-th round Taka uses j (0,1,2) and the max score
        // j: 0-rock, 1-scissor, 2:paper
        long[][] dp = new long[N][3];
        int[] charMap = new int[256], loseTo = new int[256];
        charMap['r'] = 0; charMap['s'] = 1; charMap['p'] = 2;
        loseTo['r'] = 2; loseTo['s'] = 0; loseTo['p'] = 1;
        HashMap<Integer,Long> map = new HashMap<>(3);
        map.put(0,R); map.put(1,S); map.put(2,P);
        // should have discuss base on result of i%N
        // then turns to problem of K = 1
        for(int remainder = 0; remainder < K; remainder ++){
            int winner = loseTo[T[remainder]];
            dp[remainder][winner] = map.get(winner);
            for(int i=remainder+K; i<N; i+= K){
                winner = loseTo[T[i]];
                for(int j=0;j<3;j++){
                    // and i'th round use j
                    long base = j==winner?map.get(winner):0;
                    long maxVal = 0;
                    for(int k=0;k<3;k++){
                        if(k==j) continue; // can't have two consecutive
                        maxVal = Math.max(maxVal, dp[i-K][k]);
                    }
                    dp[i][j] = base + maxVal;
                }
            }
        }
        long ans = 0;
        for(int i=N-1;i>=N-K;i--){
            long maxVal = 0;
            for(int j=0;j<3;j++) maxVal = Math.max(maxVal, dp[i][j]);
            ans += maxVal;
        }
        System.out.println(ans);
    }
}



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


int main(){
    int n;
    cin >> n;
    vector<int> x(n), s(n);
    rep(i,n){
        int z;
        cin >> z;
        x[i] = z;
        s[i] = z;
    }
    sort(s.begin(), s.end());
    int a = s[n / 2 - 1], b = s[n / 2];
    if (a == b){
        rep(i, n) cout << a << endl;
    }
    else {
        rep(i,n){
            if(x[i] <= a) cout << b << endl;
            else cout << a << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vb vector<bool>
#define PB push_back
#define MP make_pair
#define ln "\n"
#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,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=s; i>=e; i--)
#define vasort(v) sort(v.begin(), v.end())
#define vdsort(v) sort(v.begin(), v.end(),greater<ll>())
#define arrasort(arr,n) sort(arr,arr+n)
#define arrdsort(arr,n) sort(arr,arr+n,greater<ll>())

#define F first
#define S second

#define out1(x1) cout << x1 << ln
#define out2(x1,x2) cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define mz(a,val)   memset(a,val,sizeof(a))
#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007

void file()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

// code starts here


int main()
{
    //file();

    ll t;
    t = 1;

    //cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;

        ll arr[n];
        arrin(arr, n);
        sort(arr, arr + n, greater<ll>());
        ll ans = 0;
        ll pos = 1;
        ll cnt = 0;
        for (ll i = 1; i < n; i++)
        {
            if (i == 1)
                ans += arr[0];
            else
            {
                if (cnt >= 2)
                {
                    pos++;
                    cnt = 1;
                    ans += arr[pos];
                }
                else
                {
                    cnt++;
                    ans += arr[pos];
                }


            }
        }
        cout << ans;

    }
    return 0;
}

Measured memory_bytes: 5208
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  ll D,X,Y,count=0;
  int N;
  cin>>N>>D;
  D=D*D;
  for(int i=0;i<N;i++){
    cin>>X>>Y;
    if(D>=X*X+Y*Y) count++;
  }
  cout<<count<<endl;
return 0;}


Measured memory_bytes: 3640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
       
        if((a*b)%2==0) {
        	System.out.print("Even");
        }	
        else {
        	System.out.print("Odd");
        }
    }
}

Measured memory_bytes: 21844