akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    for (int i = 0; i < 5; i++) {
      int n = sc.nextInt();
      if (n == 0) {
        System.out.println(i + 1);
        return;
      }
    }

  }

}

Measured memory_bytes: 35704
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
typedef long long LL;
const int MaxN = 2e5;
using namespace std;
priority_queue<int , vector<int> , greater<int> >que;
priority_queue<int , vector<int> , greater<int> >q;
struct NODE{
	LL a , b , c;
}seq[MaxN + 5];
int X , Y , Z ;
bool cmp(NODE x , NODE y){
	return x.a - x.b < y.a - y.b;
}
LL pre[MaxN + 5] , succ[MaxN + 5];
void Init(){
	while(que.size()) que.pop();
	while(q.size()) q.pop();
	memset(pre , 0 , sizeof(pre));
	memset(succ , 0 , sizeof(succ));
	int n = X + Y + Z;
	for(int i = 1;i <= n;i++){
		scanf("%lld%lld%lld" , &seq[i].a , &seq[i].b , &seq[i].c);
	}
	sort(seq + 1 , seq + n + 1 , cmp);
}
void Solve(){
	LL sum = 0 , cnt = 0;
	int n = X + Y + Z;
	for(int i = 1;i <= Y;i++) { 
		que.push(seq[i].b - seq[i].c);
		cnt += seq[i].b - seq[i].c;
		sum = sum + seq[i].c;
	}
	pre[Y] = cnt + sum;
	for(int i = Y + 1;i <= n;i++){
		sum += seq[i].c;
		LL tmp = que.top() , t = seq[i].b - seq[i].c;
		if(tmp < t){
			cnt = cnt - tmp + t;
			que.pop();
			que.push(t);
		}
		pre[i] = cnt + sum;
	}
	sum = cnt = 0;
	for(int i = n;i >= n - X + 1;i--) {
		sum += seq[i].c;
		cnt += seq[i].a - seq[i].c;
		q.push(seq[i].a - seq[i].c);
	}
	succ[n - X + 1] = cnt + sum;
	for(int i = n - X;i >= 1;i--){
		sum += seq[i].c;
		LL tmp = q.top() , t = seq[i].a - seq[i].c;
		if(tmp < t){
			cnt = cnt - tmp + t;
			q.pop();
			q.push(t);
		}
		succ[i] = sum + cnt;
	}
	LL res = 0;
	for(int i = Y;i <= n - X + 1;i++){
		res = max(pre[i] + succ[i + 1] , res);
	}
	printf("%lld\n" , res);
}
int main()
{
	while(~scanf("%d%d%d" , &X , &Y , &Z)){
		Init();
		Solve();
	}
}

Measured memory_bytes: 7104
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;


ll FACT[MAX];
ll IFACT[MAX];

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰的に解く
    y -= a / b * x;
    return d;
}

// 負の数にも対応した mod (a = -11 とかでも OK)
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}

ll nCr(ll n, ll r)
{
    if(n < 0 || r < 0 || r > n)return 0;
    if(r > n / 2)r = n - r;
    return FACT[n]*IFACT[n-r]%MOD*IFACT[r]%MOD;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//
    
    int N = MAX;
    FACT[0] = 1;
    IFACT[0] = 1;
    for(int i = 1;i <= N;i++){
        FACT[i] = FACT[i-1] * i % MOD;
        IFACT[i] = modinv(FACT[i], MOD);
    }
    
    ll n;
    ll k;
    cin >> n >> k;

    rep2(i, 1, k+1){
        ll a = nCr(n-k+1, i);
        ll b = nCr(k-1, i-1);
        cout << a * b % MOD << endl;
    }  
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main() {
    char a[1000];
    int i;
    
    fgets(a, 1000, stdin);
    
    for (i = 0; i < strlen(a); i++) {
        if ('a' <= a[i] && a[i] <= 'z') {
            a[i] += 'A' - 'a';
        }
    }
    
    printf("%s", a);
    
    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
#define PI 3.14159265359
typedef long long ll;
const ll MOD = 1e9+7;

/*ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}*/
/*ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}*/

/*ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  b /= g;
  a *= b;
  return a;
}*/
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

int main(){
  string sa, sb, sc; cin >> sa >> sb >> sc; int sza = sa.size(), szb = sb.size(), szc = sc.size(), a=0, b=0, c=0;
  char t='a';
  rep(p, 300){
    
    
    if(t=='a'){
      if(a<=sza-1){t=sa.at(a);}
      a++;
    }
    else if(t=='b'){
      if(b<=szb-1){t=sb.at(b);}
      b++;
    }
    else if(t=='c'){
      if(c<=szc-1)t=sc.at(c);
      c++;
    }

    if(a==sza+1){
      cout << "A" << endl;
      break;
    }
    else if(b==szb+1){
      cout << "B" << endl;
      break;
    }
    else if(c==szc+1){
      cout << "C" << endl;
      break;
    }
    //cout << t << endl;
  }
  
}

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

int main(void){
    ll n, k;
    cin >> n >> k;
    vector<int> a(n+1);
    rep1(i,n) cin >> a[i];
    int cur = 1;
    vector<ll> step(n+1);
    vector<bool> visited(n+1);
    ll cycle = 0;
    while (k > 0) {
        visited[cur] = true;
        int to = a[cur];
        if (visited[to]) {
            k--;
            cycle = step[cur] - step[to] + 1;
            k %= cycle;
            cur = to;
            break;
        }
        step[to] = step[cur] + 1;
        cur = to;
        k--;
    }
    while (k > 0) {
        cur = a[cur];
        k--;
    }
    cout << cur << endl;

    return 0;
}


Measured memory_bytes: 5636
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let m: i32 = read();
    println!("{}", 48-m);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n;
    cin >> n;
    string t = "MARCH";
    ll cnt[5] = {};

    for (int i = 0; i < n; i++){
        string s;
        cin >> s;
        for (int j = 0; j < 5; j++){
            if (s[0] == t[j]){
                cnt[j]++;
            }
        }
    }

    ll ans = 0LL;
    for (int i = 0; i < 5; i++){
        for (int j = i + 1; j < 5; j++){
            for (int k = j + 1; k < 5; k++){
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  std::string S, T;
  std::cin >> S >> T;

  int ans = 1000000009;

  for (int head = 0; head < (int)(S.length() - T.length()) + 1; head++) {
    int cnt = 0;
    for (int i = 0; i < (int)T.length(); i++) {
      cnt += (T[i] != S[head + i]);
    }
    ans = std::min(ans, cnt);
  }

  std::cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  ll n,k; cin >> n >> k;
  vector<ll> M, P;
  ll zero = 0;
  loop(i,0,n) {
    ll a; cin >> a;
    if (a == 0) zero++;
    else if (a < 0) M.push_back(a);
    else P.push_back(a);
  }
  sort(M.begin(), M.end());
  sort(P.begin(), P.end());
  ll m = M.size(), p = P.size();

  if (k <= m*p) {
    auto f = [&](ll x) {
      ll num = 0;
      // ある正整数P[i]に対して、積がx以下となるような相方の数を見つける
      // Mは昇順なので、左の方が積が大きい.
      // 満たさない箇所が一度出ればそれ以降はすべて満たさない
      // i.e. 2で満たさないとする
      // 1  1  2  2  3
      //   ok ng
      // 2個
      loop(i,0,p) {
        ll ok = -1, ng = m;
        while (ok + 1 < ng) {
          ll mid = (ok+ng)>>1;
          if (P[i]*M[mid]<=x) ok = mid;
          else ng = mid;
        }
        num += ng;
      }
      return num;
    };

    ll ng = -1000000000000000001, ok = 1000000000000000001;
    while (ng+1<ok) {
      ll mid = (ng+ok)>>1;
      if (f(mid) < k) ng = mid;
      else ok = mid;
    }
    cout << ok << endl;
    return 0;
  }

  k -= m*p;

  ll numZero = zero ? zero*(zero-1)/2 : 0;
  numZero += zero * (m+p);
  if (k <= numZero) {
    cout << 0 << endl;
    return 0;
  }

  k -= numZero;

  // 初めて満たさないインデックス = 満たす個数 としたい
  // これがないと個数=M.size()-i-1みたいになる
  reverse(M.begin(), M.end());

  auto f = [&](ll x) {
    ll num = 0;
    // 各正整数に対して、ペアに出来る正整数の数を求める.
    // ただし、自分自身とは組めないので範囲に自身も含まれる場合は-1
    // (i,j) (j,i)の両方をカウントしているので最後に2で割る.
    loop(i,0,p) {
      ll ok = -1, ng = p;
      while (ok + 1 < ng) {
        ll mid = (ok+ng)>>1;
        if (P[i]*P[mid]<=x) ok = mid;
        else ng = mid;
      }
      if (i < ng) ng--;
      num += ng;
    }
    loop(i,0,m) {
      ll ok = -1, ng = m;
      while (ok + 1 < ng) {
        ll mid = (ok+ng)>>1;
        if (M[i]*M[mid]<=x) ok = mid;
        else ng = mid;
      }
      if (i < ng) ng--;
      num += ng;
    }
    return num>>1;
  };

  ll ng = -1000000000000000001, ok = 1000000000000000001;
  while (ng+1<ok) {
    ll mid = (ng+ok)>>1;
    if (f(mid) < k) ng = mid;
    else ok = mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 5140
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef unsigned long long ll;

int gcd(int a, int b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

int main(void){
    int n,x,a1,a2;
    cin>>n>>x;
    int g;
    if(n==1){
        cin>>a1;
        cout<<abs(a1-x);
        return 0;
    }
    cin>>a1>>a2;
    a1-=x;
    a2-=x;
    g=abs(gcd(a1,a2));
    rep(i,n-2){
        cin>>a1;
        g=abs(gcd(g,a1-x));
    }
    cout<<g;
}
/*

*/

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

typedef long long int ll;

ll n,k;
ll arr[51][51];
ll mod = 1e9+7;
ll power(ll b)
{
    ll r[n][n];
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(i==j)
            r[i][j] = 1;
            else
                r[i][j] = 0;
        }
    }
    while(b>0){

        if(b%2==1){

            // r = r*a;
            ll rock[51][51];
            for(ll i=0;i<n;i++){
                for(ll j=0;j<n;j++){
                    ll su = 0;
                    for(ll k=0;k<n;k++){
                        su = (mod+su+(mod+r[i][k]*arr[k][j])%mod)%mod;
                    }
                    rock[i][j] = su;
                }
            }
            for(ll i=0;i<n;i++){
                for(ll j=0;j<n;j++){
                    r[i][j] = rock[i][j];
                }
            }


        }
        // a = a*a;
        ll rock[51][51];
        for(ll i=0;i<n;i++){
                for(ll j=0;j<n;j++){
                    ll su = 0;
                    for(ll k=0;k<n;k++){
                        su = (su+mod+(mod+arr[i][k]*arr[k][j])%mod)%mod;
                    }
                    rock[i][j] = su;
                }
        }
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                arr[i][j] = rock[i][j];
            }
        }
        b = b/2;
    }
    ll s = 0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++){
            s = (mod+s+r[i][j])%mod;
        }
    }
    return s;
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;

    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            cin>>arr[i][j];
        }
    }

    cout<<power(k)<<endl;;

}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int height = sc.nextInt();
		int width = sc.nextInt();
		String c[] = new String[height];
		for(int i = 0; i < height;i++){
			c[i] = sc.next();
		}
		int crowd[][] = new int[width][height];
		for(int i = 0;i <height;i++){
			for(int j = 0;j < width;j++){
				if(c[i].charAt(j) == 'c'){
					crowd[j][i] = 0;
				}else{
					crowd[j][i] = -1;	
				}
			}
		}
		for(int i = 0;i <height;i++){
			for(int j = 0;j < width;j++){
				for(int k = width-1;k >= 0;k--){
					if(crowd[k][i] == 0 && crowd[j][i] == -1 && k < j){
						crowd[j][i] = j-k;
					}
				}
			}
		}
		for(int i = 0;i <height;i++){
			for(int j = 0;j < width;j++){
				if(j < width-1){
					System.out.print(crowd[j][i]+" ");					
				}else{
					System.out.print(crowd[j][i]);						
				}
			}
			System.out.println();
		}
		
	}

}

Measured memory_bytes: 36228
n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
judge = sum(a) / (4.0 * m)
for i in range(n):
  if a[i] >= judge:
    count += 1
if count >= m:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
def combs(n, x):
    c = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            for k in range(j+1, n+1):
                if i+j+k == x:
                    c+=1
                elif i+j+k > x:
                    break
    return c

while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    print(combs(n, x))






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

using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	sort(A.begin(), A.end());
	vector<pair<int, int>> ans;
	for (int i = 1; i < N - 1; ++i) {
		if (A[i] > 0) {
			ans.emplace_back(A[0], A[i]);
			A[0] -= A[i];
		} else {
			ans.emplace_back(A[N-1], A[i]);
			A[N-1] -= A[i];
		}
	}
	ans.emplace_back(A[N-1], A[0]);
	cout<< A[N-1] - A[0] <<endl;
	for (auto p : ans) cout << p.first << " " << p.second << endl;
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;} 
int main(){
  fio; cout<<fixed<<setprecision(25);	
  int n; cin >> n;
  ll ans = 0;
  ll x; cin >> x;
  ll y;
  for(int i =1 ;i < n ; ++i){
    cin >> y;
    ans += max(0ll , x-y);
    x = max(x , y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
//debug
#define vecprint(v) cout << "  vector: ";rep(i,v.size())cout << v[i] << " ";cout << endl;
#define setprint(s) cout << "  set: ";for(auto i=s.begin();i!=s.end();i++)cout << *i << " ";cout << endl;
#define mappairprint(s) cout << "  map: ";for(auto i=s.begin();i!=s.end();i++)cout << i->first << " " << i->second << endl;cout << endl;
//reader
#define r1(a) cin>>(a)
#define r2(a,b) cin>>(a)>>(b)
#define r3(a,b,c) cin>>(a)>>(b)>>(c)
//writer
#define w1(a) cout<<(a)<<" "
#define w2(a,b) cout<<(a)<<" "<<(b)<<" "
#define w3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "
#define wl1(a) cout<<(a)<<endl
#define wl2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wl3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
//variable definition
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
//roop
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define all(c) c.begin(),c.end()
//term
#define elif else if
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
using namespace std;
using ll = long long;
//const


int main() {
  //input
  int n;
  cin >> n;
  
  ll ans = 1;
  ll a[n];
  rep(i,n) {
    cin >> a[i];
    if(a[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  
  rep(i,n) {
    
    //overflow check
    if(!(a[i] < LONG_MAX / ans)) {
      //cout << "-1" << " " << LONG_MAX << " " <<a << " " << ans<< endl;
      cout << "-1" << endl;
      return 0;
    }
    ans *= a[i];
    //ll tmp = ans * a[i];
    //if(tmp/a[i] == ans) {
    //  ans = tmp;
    //} else {
    //  cout << "-1" << endl;
    //  return 0;
    //}
    //cout << i << " " << ans << endl;
  }
  if(ans > 1000000000000000000) cout << "-1" << endl;
  else cout << ans << endl;  
}

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

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> S(n);
    for(int i = 0; i < n; i++) cin >> S[i];
    sort(S.begin(), S.end());
    for(int i = 0; i < n; i++) cout <<S[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int N,P[45],I[45],i,j,G[45][3],p,f[45]={0},c=0,nd;

void dfs(int p)
{
	if(G[p][0]!=-1)
		dfs(G[p][0]);
	if(G[p][1]!=-1)
		dfs(G[p][1]);
	printf("%s%d",c++==0?"":" ",p);

}

int main()
{
	scanf("%d",&N);
	memset(G,-1,sizeof(G));
	for(i=0;i<N;i++)scanf("%d",&P[i]);
	for(i=0;i<N;i++)scanf("%d",&I[i]);
	p=P[0];
	for(int np=0,ip=0;np<N;)
	{
		for(;;)
		{
			f[P[np]]=1;
			if(P[np]==I[ip])break;
			if(np<N-1)
			{
				G[P[np]][0]=P[np+1];
				f[P[np+1]]=1;
			}
			np++;
		}
		while(f[I[ip]])
		{
			ip++;
		}
		if(np<N-1)
			G[I[ip-1]][1]=P[np+1];
		np++;
	}
	dfs(P[0]);
	puts("");
}

Measured memory_bytes: 1040
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
struct edge { int to, dist, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int N, M, L, a1, a2, a3, a4;
int main() {
	while (cin >> N >> M >> L, N | M | L) {
		vector<vector<edge> > G(N);
		for (int i = 0; i < M; i++) {
			cin >> a1 >> a2 >> a3 >> a4; a1--, a2--;
			G[a1].push_back(edge{ a2, a3, a4 });
			G[a2].push_back(edge{ a1, a3, a4 });
		}
		vector<vector<int> > d(N, vector<int>(L + 1, 999999999)); d[0][L] = 0;
		priority_queue<edge> que; que.push(edge{ 0, L, 0 });
		while (!que.empty()) {
			edge u = que.top(); que.pop();
			for (edge e : G[u.to]) {
				if (u.dist >= e.dist) {
					int dist1 = u.dist - e.dist;
					int cost1 = -u.cost;
					if (d[e.to][dist1] > cost1) {
						d[e.to][dist1] = cost1;
						que.push(edge{ e.to, dist1, -cost1 });
					}
				}
				int dist2 = u.dist;
				int cost2 = -u.cost + e.cost;
				if (d[e.to][dist2] > cost2) {
					d[e.to][dist2] = cost2;
					que.push(edge{ e.to, dist2, -cost2 });
				}
			}
		}
		cout << *min_element(d[N - 1].begin(), d[N - 1].end()) << endl;
	}
	return 0;
}

Measured memory_bytes: 3440
//IOI 2021

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 2 * 1000 + 17;

ll n, x, b[MAXN], a[MAXN], ans = 1e18;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i], b[i] = a[i];
	for (int k = 0; k <= n; k++) {
		ll res = x * k;
		for (int i = 0; i < n; i++)
			b[i] = min(b[i], a[(i - k + n) % n]), res += b[i];
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] sSplit = s.split("");

		String alphabet = "abcdefghijklmnopqrstuvwxyz";
		String[] alphabetSplit = alphabet.split("");

		int[][] distance = new int[alphabetSplit.length][sSplit.length+1];
		int[] distanceCnt = new int[alphabetSplit.length];
		int currentAlphabet;
		int prev;
		for(int i=0; i<alphabetSplit.length; i++){
			distanceCnt[i] = 0;
			prev = -1;
			for(int j=0; j<sSplit.length; j++){
				if(sSplit[j].equals(alphabetSplit[i])){
					distance[i][distanceCnt[i]++] = j - prev - 1;
					prev = j;
				}
			}
			distance[i][distanceCnt[i]] = sSplit.length - prev - 1;
		}

		int[] count = new int[alphabetSplit.length];
		int max;
		int last;
		int maxIndex = -1;
		boolean flg;
		for(int i=0; i<alphabetSplit.length; i++){
			if(distance[i][0]== sSplit.length){
				count[i] = Integer.MAX_VALUE;
			}else{
				max = 0;
				for(int j=0; j<distanceCnt[i]; j++){
					if(distance[i][j]>max){
						max = distance[i][j];
						maxIndex = j;
					}
				}
				last = distance[i][distanceCnt[i]];
				if(last>=max){
					count[i] = last;
				}else{
					count[i] = max;
					/*
					for(int k=0; k<distanceCnt[i]; k++){
						distance[i][k] -= last;
					}
					count[i] = last;
					while(true){
						for(int k=0; k<distanceCnt[i]; k++){
							distance[i][k] -= 1;
							if(distance[i][k]>distance[i][maxIndex]){
								maxIndex = k;
							}
						}
						distance[i][maxIndex] -=1;
						count[i]++;
						flg = true;
						for(int k=0; k<distanceCnt[i]; k++){
							if(distance[i][k]>0){
								flg = false;
								break;
							}
						}
						if(flg == true){
							break;
						}
					}
					*/
				}
			}
		}

		int min = Integer.MAX_VALUE;
		for(int i=0; i<alphabetSplit.length; i++){
			if(count[i]<min){
				min = count[i];
			}
		}

		System.out.print(min);

	}

}


Measured memory_bytes: 21844
import sys
n = int(sys.stdin.readline())
a  = [int(n) for n in input().split()]
y = 0
summ = sum(a)
c = int(len(a) / 2)
t = False
while 1:
    lsum = sum(a[:c])
    rsum = sum(a[c:])
    if not t:
        if lsum > rsum:
            t = True
            c -= 1
        else:
            c += 1
    else:
        if lsum > rsum:
            c -= 1
        else:            
            h = sum(a[c:]) - sum(a[:c]) 
            hh = sum(a[:c + 1]) - sum(a[c + 1:])
            if h < hh:
                y += h
            else:
                y += hh
            break

print(y)


Measured memory_bytes: 135872
#include <stdio.h>
int main()
{int n,A,B,C,count=0;
int i,j,k,temp;
scanf ("%d",&n);
int a[n];
for (i=0;i<n;i++)
{
    scanf ("%d",&a[i]);
}
//sorting

for (i=0;i<n-1;i++)
{
    for(j=i+1;j<n;j++)
    {
        if (a[i]>a[j])
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for (i=0;i<n;i++)
{ 
    A=a[i];
    for (j=i+1;j<n;j++)
    {
        B=a[j];
        for (k=j+1;k<n;k++)
        {   C=a[k];
            if (C>=A+B)
            {
                break;
            }
            count++;
        }
    }

}
printf ("%d",count);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S;
cin >> S;
bool co = 0;
if(S[2] == S[3] && S[4] == S[5]) co = 1;
if(co == 1) cout << "Yes" << endl;
else cout << "No" << endl;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 2000000000
#define MOD 1000000007
#define SIZE 200005
#define FOR(i,a,n) for(i=(a);i<(n);i++)

int *par;
int *rank;
int *v;
void init_union(int size){
	int i;
	par = (int*)calloc(size,sizeof(int));
	rank = (int*)calloc(size,sizeof(int));
	v = (int*)calloc(size,sizeof(int));
	FOR(i,0,size) par[i]=i,v[i]=1;
	return;
}

int root(int a){
 	if(par[a]==a) return a;
 	else{
 		return (par[a]=root(par[a]));
 	}
}
 
int is_same(int a,int b){
 	return root(a)==root(b);
}
 
void unite(int a,int b){
	a=root(a);
	b=root(b);
	if(a==b){
		return;
	}
	if(rank[a]>rank[b]){
		par[b]=a;
		v[a]+=v[b];
		v[b]=0;
	}
	else{
		par[a]=b;
		v[b]+=v[a];
		v[a]=0;
		if(rank[a]==rank[b]) rank[b]++;
	}
	return;
}

ll inv[SIZE],f[SIZE],finv[SIZE];
void make_table(){
	int i;
	f[0]=f[1]=1; finv[0]=finv[1]=1;
	inv[1]=1;
	FOR(i,2,SIZE+1){
		inv[i]=MOD-(MOD/i)*inv[MOD%i]%MOD;
		f[i]=(f[i-1]*(ll)i)%MOD;
		finv[i]=(finv[i-1]*inv[i])%MOD;
	}
	return;
}
ll comb(int n,int k){
	if(n<0||k<0||n<k) return 0;
	return (((f[n]*finv[k])%MOD)*finv[n-k])%MOD;
}

typedef struct{
	int c,w;
}Ball;
int comp1(const void* a,const void* b){
	return ((Ball*)a)->w - ((Ball*)b)->w;
}
int comp2(const void* a,const void* b){
	return *(int*)a - *(int*)b;
}
Ball ball[SIZE];
int min[SIZE];
int *ary[SIZE],mem[SIZE];
int size[SIZE];
int main(void)
{
	int n,x,y,id,color,total,cnt,i,j,k;
	ll res;
	scanf("%d%d%d",&n,&x,&y);
	FOR(i,0,n){
		scanf("%d%d",&ball[i].c,&ball[i].w);
		ball[i].c--;
		min[i]=INF;
	}
	
	FOR(i,0,n) min[ball[i].c]=MIN(min[ball[i].c],ball[i].w);
	FOR(i,0,n){
		if(ball[i].w+min[ball[i].c]<=x){
			ball[i].w=min[ball[i].c];
		}
	}
	qsort(ball,n,sizeof(Ball),comp1);
	//FOR(i,0,n) printf("%d %d\n",ball[i].c,ball[i].w);
	
	color=ball[0].c;
	FOR(i,1,n){
		if(color!=ball[i].c){
			id=i;
			color=ball[i].c;
			break;
		}
	}
	if(color==ball[0].c){
		puts("1");
		return 0;
	}
	
	init_union(n);
	FOR(i,0,n){
		if(ball[i].c==ball[0].c&&ball[i].w+ball[id].w<=y){
			unite(id,i);
		}
		if(ball[i].c!=ball[0].c&&ball[i].w+ball[0].w<=y){
			unite(0,i);
		}
	}
	
	ary[0]=mem;
	FOR(i,0,n-1) ary[i+1]=ary[i]+v[i];
	FOR(i,0,n){
		id=root(i);
		ary[id][size[id]++]=ball[i].c;
	}
	
	make_table();
	res=1;
	
	FOR(i,0,n){
		if(size[i]==0) continue;
		qsort(ary[i],size[i],sizeof(int),comp2);
		total=size[i]; cnt=j=k=0;
		while(j<size[i]){
			while(k<size[i]&&ary[i][j]==ary[i][k]) k++;
			res*=comb(total,k-j);
			res%=MOD;
			total-=(k-j);
			j=k;
		}
	}
	printf("%lld\n",res);
	return 0;
}
    

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

#define pb push_back

//var 
int n,m,t1,t2,h[100001],ans = 0;
vector<int> e[100001];
bool g;

int main(){
	cin >> n >> m;
	for(int i = 1; i<=n; i++)cin >> h[i];
	for(int i = 1; i<=m; i++){
		cin >> t1 >> t2;
		e[t1].pb(t2);
		e[t2].pb(t1);
	}
	for(int i = 1; i<=n; i++){
		g = 1;
		for(int u : e[i]){
			g &= (h[u]<h[i]);
		}if(g)ans++;
	}cout << ans << endl;
}

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

const int INF = 1e8 ;
//vector<ll> G[2005]   ;//グラフの関係を入れるための配列
//vector<ll> P(2005,INF) ;//1からの距離
//vector<ll> Q(2005,0) ;//すでに訪れた場所かを確認するための配列

//void dfs(ll i , ll j ){
//    if(Q[i]==1) return ;
//    else
//    {
//        P[i] = j ;
//        Q[i] = 1 ;
//    }
//    for(auto p :G[i]){
//        dfs(p,j+1) ;
//    }
//}

int main(){
    ll n ,m ; 
    cin >> n >> m ;
    vector<ll> G[n]   ;
    vector<ll> dist(n,INF) ; 
    rep(i,m){
        ll x , y ;
        cin >> x >> y ;
        x-- ;y-- ;
        G[x].push_back(y) ;
        G[y].push_back(x) ;
    }
    ll ans = 0 ;
    queue<ll> q ;
    auto update = [&] (ll i , ll j ){
      if(dist[i] != INF ) return ;
	  dist[i] = j ;
      q.push(i) ;
    };
    update(0,0) ;
    rep(i,n){
        update(i,i) ;
        while (!q.empty()){
            ll now = q.front() ; 
            q.pop() ;
            for (auto p : G[now]) update(p,dist[now]) ;
        }
    }
    map<ll,ll> mp ;
    rep(i,n){
        mp[dist[i]]++ ;
        ans = max(mp[dist[i]],ans) ;
    }
    cout << ans <<endl ;

}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> sol(n+1);
    for(int i =1; i<=n; ++i)
    {
        int x;cin>> x;
        sol[x] = i;
    }
    for(int i = 1; i<=n; ++i)
        cout << sol[i] << " ";
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>

using namespace std;

int j, y;

void check(int xt, int yt, string p){
	if(xt == j && yt == y){
		cout << p << endl;
		return;
	}
	if(xt == 5 && yt <= 3 || yt == 5 && xt <= 3) return;
	if(xt > j || yt > y) return;
	check(xt + 1, yt, p + "A");
	check(xt, yt + 1, p + "B");
}

int main(){
	cin >> j >> y;
	check(0, 0, "");
	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>

int main(void){
    // Your code here!
    char s[101];
    scanf("%s\n",s);
    int N, noflag = 0;
    N = strlen(s);
    
    for(int i = 0; i < N && noflag == 0; i++)
    {
        if((i%2 == 0 && s[i] == 'L') || (i%2 == 1 && s[i] == 'R')) noflag = 1;
    }
    
    printf("%s\n",(noflag == 1)? "No":"Yes");
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int n,a[Nmax]={},b[Nmax]={};
	cin >> n;
	REP(i,n){
		cin >> a[i];
		//reverse(b, b+i+1);
	}
  	int j=n-1,k=0;
	for(int i=0;i < n;i++){
		if(i%2==0) b[k++]=a[n-i-1];
		else b[j--]=a[n-i-1];
	}
	REP(i,n) cout << b[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 3712
D = int(input())
C = list(map(int, input().split()))
S = [tuple(map(int, input().split())) for _ in range(D)]
Z = 26

last = [-1] * Z
ans = 0
T = []
for d in range(D):
    maxScore = -float('inf')
    cand = 0
    for i in range(26):
        tmp = last[i]
        last[i] = d
        up = S[d][i]
        down = sum(C[j] * (d - last[j]) for j in range(Z))
        score = up - down
        if maxScore < score:
            cand = i
            maxScore = score
        last[i] = tmp
    last[cand] = d
    T.append(cand + 1)
print(*T, sep='\n')


Measured memory_bytes: 69312
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

def b_serf(l_ok,r_ng,x,s)
  m = (l_ok+r_ng)/2
  if(m == l_ok)
    return ((s**5-m**5)==x)? m : false
  end
  if((s**5-m**5)==x)
    return m
  else
    if(((s**5-m**5)<x))
      return b_serf(m,r_ng,x,s)
    else
      return b_serf(l_ok,m,x,s)
    end
  end
end
def b_sers(l_ok,r_ng,x,s)
  m = (l_ok+r_ng)/2
  if(m == l_ok)
    return ((s**5-m**5)==x)? m : false
  end
  if((s**5-m**5)==x)
    return m
  else
    if(((s**5-m**5)>x))
      return b_sers(m,r_ng,x,s)
    else
      return b_sers(l_ok,m,x,s)
    end
  end
end
x = inp[0]
(-10000..10000).each do |i|
  if(j = b_serf(0,100000,x,i))
    puts "#{i} #{j}"
    exit
  end
  if(j = b_sers(-1000000,0,x,i))
    puts "#{i} #{j}"
    exit
  end
end



Measured memory_bytes: 14436
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int c=cin.nextInt();
			int n=cin.nextInt();
			int m=cin.nextInt();
			int start=cin.nextInt();
			int goal=cin.nextInt();
			if(c+n+m+start+goal==0){
				break;
			}
			int[][] cost=new int[n+1][n+1];
			for(int i=0;i<m;i++){
				int a=cin.nextInt();
				int b=cin.nextInt();
				cost[a][b]=cost[b][a]=cin.nextInt();
			}
			PriorityQueue<int[]> q=				new PriorityQueue<int[]>(10000,new Comparator<int[]>(){

				public int compare(int[]a,int[]b){
					return a[1]-b[1];
				}
			});
			boolean[][] already=new boolean[n+1][c+1];
			q.add(new int[]{start,0,0});
			int ans=1<<30;
			while(!q.isEmpty()){
				int a=q.peek()[0];
				int cc=q.peek()[1];
				int num=q.poll()[2];
//				System.out.println(a+" "+cc+" "+num);
				if(already[a][num])continue;
				already[a][num]=true;
				if(a==goal){
					ans=Math.min(ans, cc);
					continue;
				}
				for(int i=0;i<=n;i++){
					if(cost[a][i]>0&&!already[i][num]){
						q.add(new int[]{i,cc+cost[a][i],num});
						if(num<c){
							q.add(new int[]{i,cc+(cost[a][i])/2,num+1});
						}
					}
				}
			}
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 61604
// ARC093B.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 110;

int A, B;
bool flag;
char mp[MAX_N][MAX_N];

int main()
{
    // freopen("Table.out", "w", stdout);
    scanf("%d%d", &A, &B), printf("100 100\n");
    for (int i = 1; i <= 50; i++)
        for (int j = 1; j <= 100; j++)
            mp[i][j] = '#';
    for (int i = 51; i <= 100; i++)
        for (int j = 1; j <= 100; j++)
            mp[i][j] = '.';
    A--, B--;
    for (int i = 1; i <= 49 && A; i += 2)
        for (int j = (((i - 1) >> 1) & 1) ? 2 : 1; j <= 100 && A; j += 2)
            mp[i][j] = '.', A--;
    for (int i = 100; i >= 52 && B; i -= 2)
        for (int j = (((100 - i) >> 1) & 1) ? 2 : 1; j <= 100 && B; j += 2)
            mp[i][j] = '#', B--;
    for (int i = 1; i <= 100; i++)
        printf("%s\n", mp[i] + 1);
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,b,a) for(i=b-1;i>=(ll)a;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
// const ll mod=1000000007;
const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,a,N,S,ans=0;
  cin>>N>>S;
  vec v(S+1,0);
  while(N--){
    cin>>a;
    v[0]=(v[0]+1)%mod;
    bFor(i,S+1,a)(v[i]+=v[i-a])%=mod;
    ans+=v[S];
  }
  print(ans%mod);
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int A[3]; REP(i,3) cin>>A[i];
    sort(A,A+3);
    cout<<A[2]*10+A[1]+A[0]<<endl;
}


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

std::map<int, int> mp;

int main(void) {
  int x;
  int n;
  int p[110];
  

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

  //for(int i = 1; i <= 100; i++){
  //  mp[i] = 0;
  //}

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

  for(int i= 0;; i++){
    if (mp[x-i] == 0) {
      printf("%d", x - i);
      return 0;
    }
    if(mp[x+i] == 0){
      printf("%d", x + i);
      return 0;
    }
  }
  
  
}

Measured memory_bytes: 3832
s = input()
if s[0] == "R":
    if s[1] == "R":
        if s[2] == "R":
            print(3)
        else:
            print(2)
    else:
        print(1)
else:
    if s[1] == "R":
        if s[2] == "R":
            print(2)
        else:
            print(1)
    else:
        if s[2] == "R":
            print(1)
        else:
            print(0)

Measured memory_bytes: 9012
//半公倍数：１．５倍、２．５倍。。。
//3以上の奇数倍、割る２
//互いに素であった場合は存在しないのでは？→存在する。
//最小半公倍数が存在する場合は、それの奇数倍で求まる気がする。
//最小半公倍数が存在しない場合は、存在しない。
//どのような時に存在しないのか？
//素因数分解したときの因数２の数が異なる場合は、存在しない。
//最小半公倍数の求め方
//２で割った値が互いに素であれば、２で割った値を全てかければよい。
//互いに素でない場合は少ない方の値で大きい方の値を割る。
#include <bits/stdc++.h>
using namespace std;
vector <long long> primeNumbers;
bool isPrime(long long n){
    //cout << n << endl;
    if(n==0)return false;
    if(n==1)return false;
    if(n==2)return true;
    double sq = sqrt(n);
    for(long long i = 2; i <= sq; i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
void getPrimeNumbers(long long n){
    //cout << "getPrimeNumbers" << endl;
    //cout << n << endl;
    if(isPrime(n)){
        primeNumbers.push_back(n);
        return;
    }
    double sq = sqrt(n);
    if(n==1){
        return;
    }
    for(long long i = 2; i<=sq; i++ ){
        if(n%i==0){
            //cout << n << endl;
            if(isPrime(i))primeNumbers.push_back(i);
            getPrimeNumbers(n/i);
            break;
        }
    }
}
bool isSemiCommonMulti(long long value, vector <long> &v){
    //cout << value << endl;
    int cnt = 0;
    for(int i = 0; i < v.size(); i++){
        if(value%(v[i]/2)==0){
            cout << "test" << endl;
            long long div = value/(v[i]/2);
            if(div%2==1){
                cout << "semi common multi" << endl;
                cnt++;
            }
        }
    }
    if(cnt==v.size()){
        return true;
    }else{
        return false;
    }
}
bool checkSemiMulti(long long num, vector <long> &v){
    bool isAvailable = true;
    for(long j = 0; j < v.size(); j++){
        if(num%(v[j]/2)==0){
            long div = num/(v[j]/2);
            if(div%2==1){
                continue;
            }else{
                isAvailable=false;
            }
        }else{
            isAvailable=false;
        }
    }
    return isAvailable;
}
int main(){
    long n,m;
    cin >> n >> m;
    vector <long> p(n);
    vector <long> harfP(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    

    vector <long long> candidate;
    long long tmp = p.back()/2;
    long long value = 1;
    long long cnt = 0;
    value=tmp*(2*cnt+1);
    long long smallestOne = -1;
    while(value<=m){
        //cout << value << endl;
        if(checkSemiMulti(value,p)){
            smallestOne = value;
            break;
        }else{
            cnt++;
            value=tmp*(2*cnt+1);
        }
    }
    if(smallestOne<0){
        cout << 0 << endl;
    }else{
        if((m/smallestOne)%2==0){
            cout << m/smallestOne/2 << endl;        
        }else{
            cout << m/smallestOne/2+1 << endl;        
        }
    }
    return 0;
}

Measured memory_bytes: 4808
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
}
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL||k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}




Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
 
 if(y->left!=NIL)x=y->left;
  else x=y->right;
 if(x!=NIL) x->parent=y->parent;
  
  if(y->parent == NIL) root=z;
  else if( y == y->parent->left)    y->parent->left=x;
  else y->parent->right=x;
 
  if(y!=z) z->key=y->key;


}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y=x;
    if(z->key < x->key) x =x->left;
    else x = x->right;
  }
  z->parent=y;
  if(y==NIL) root =z; 
  else if(z->key < y->key){
    y->left=z;
  }
  else y->right=z;
  
}   

void inorder(Node u){
  if(u != NIL){
     inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){

  if(u != NIL ){
    printf(" %d",u->key);
    preorder(u->left); 
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

Measured memory_bytes: 19364
n = int(input())
sp = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    sp.append([s, p, i + 1])

cities = list(set([sp[i][0] for i in range(n)]))
cities.sort()

for city in cities:
    c = []
    for i in sp:
        if city == i[0]:
            c.append(i[1:])
    c.sort()
    c.reverse()
    for i in c:
        print(i[1])


Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
int main(void)
{
    int n;
    char str[10];

    cin >> n;
    if (n > 100000000) {
        return 0;
    }

    sprintf(str, "%d", n);

    int sum = 0;
    int i=0;
    while (str[i] != '\0') {
        sum += str[i] - '0';
        i++;
    }

    if (n % sum == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

bool is_uruu (int y) {
    if (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)) return true;
    return false;
}

int main ()
{
    int a, b;
    bool f = false;
    while (cin >> a >> b, (a or b)) {
        if (f) cout << endl;
        f = true;
        bool flag = true;
        while (a <= b) {
            if (is_uruu(a)) {
                cout << a << endl;
                flag = false;
            }
            a++;
        }

        if (flag) cout << "NA" <<endl;
    }

    return 0;
}

Measured memory_bytes: 1160
MOD = 998244353
n, m, k = map(int, input().split())

fact = [0]*(n+1)
fact[0] = 1
for i in range(1, n+1):
    fact[i] = fact[i-1]*i % MOD

invfact = [0]*(n+1)
for i in range(n+1):
    invfact[i] = pow(fact[i], MOD-2, MOD)


def nCk(n, k):
    return fact[n]*invfact[k]*invfact[n-k]


ans = 0
for i in range(k+1):
    ans += m*pow(m-1, n-1-i, MOD)*nCk(n-1, i)
    ans %= MOD
print(ans)


Measured memory_bytes: 24656