akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	int d;

	cin >> d;

	if (d == 25) {
		cout << "Christmas";
	}
	if (d == 24) {
		cout << "Christmas Eve";
	}
	
	if (d == 23) {
		cout << "Christmas Eve Eve";
	}
	if (d == 22) {
		cout << "Christmas Eve Eve Eve";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;

const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int n;
    cin>>n;
    int a[n];
    int ma =0;
    rep(i,n){
        cin>>a[i];
        ma=max(ma,a[i]);
        }
    int ha =(ma+1)/2;
    int d =INF;
    int ans;
    rep(i,n){
        if(d>abs(ha-a[i])&&ma!=a[i]){
            d=abs(ha-a[i]);
            ans=a[i];
        };
    }
    cout<<ma<<' '<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

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

int main() {
  int n;
  cin >> n;
  int m[n][n];
  long long s[n + 1][n + 1];
  rep (i, n) rep (j, n) cin >> m[i][j];
  rep (i, n + 1) rep (j, n + 1) s[i][j] = 0;
  rep (i, n) rep (j, n) s[i + 1][j + 1] = m[i][j] + s[i][j + 1] + s[i + 1][j] - s[i][j];
  long long res = -1e15;
  rep (i, n) rep (j, n) rep (ii, i + 1) rep (jj, j + 1) {
    res = max(res, s[i + 1][j + 1] - s[i + 1][jj] - s[ii][j + 1] + s[ii][jj]);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>

int main(){
	int N,sum;
	scanf("%d",&N);
	int S[N+1],C[N+1],F[N+1];
	for(int i=0;i<N-1;i++){
		scanf("%d%d%d",&C[i],&S[i],&F[i]);
	}
	for(int i=0;i<N;i++){
		int sum = 0;
		for(int j=i;j<N-1;j++){
			if(sum<S[j]){
				sum=S[j];
			}else if(sum%F[j]==0){
			}else{
				sum=sum+F[j]-sum%F[j];
			}
			sum+=C[j];
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int a[5];
	for (int i = 0; i < 5; i++) {
		scanf("%d", &a[i]);
		//printf("%d\n", a[i]);
	}
	printf("%d\n", ave(5,a));
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		if (all[i] < 40)all[i] = 40;
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2704
MOD = 1000000007  # type: int
 
def solve(n: int, k: int):
    fact = [1] * (n+1)
    inv_fact = [1] * (n+1)
    for i in range(1, n+1):
        fact[i] = i*fact[i-1] % MOD
 
    inv_fact[-1] = pow(fact[-1], MOD-2, MOD)
    for i in range(n-1, 0, -1):
        inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
 
    def comb(n, r, MOD=MOD):
        return fact[n] * inv_fact[n-r] * inv_fact[r] % MOD
    
    ans = 0
    for i in range(min(k, n-1)+1):
        ans += comb(n, i) * comb(n-1, i) % MOD
        ans %= MOD
 
    return ans

n, k = list(map(int, input().split()))

print(solve(n, k))

Measured memory_bytes: 18804
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, A; cin >> N >> A;
	cout << N*N - A << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int H, W, K;
char S[10][1000];
int cnt[11][1001];

int query(int h1, int h2, int w1, int w2){
    return cnt[h2+1][w2+1]-cnt[h1][w2+1]-cnt[h2+1][w1]+cnt[h1][w1];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W >> K;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> S[i][j];
            int m = S[i][j]-'0';
            cnt[i+1][j+1] = cnt[i+1][j]+cnt[i][j+1]-cnt[i][j]+m;
        }
    }
    // for(int i = 0; i <= H; i++){
    //     for(int j = 0; j <= W; j++){
    //         cout << cnt[i][j];
    //     }
    //     cout << endl;
    // }
    int ans = 100000;
    for(int i = 0; i < (1<<(H-1)); i++){
        int prev = 0;
        int cnt = 0;
        bool ok = true;
        vector<int> v;
        v.push_back(-1);
        for(int j = 0; j < H; j++){
            int m = 1<<j;
            if(i&m || j == H-1) {
                if(j != H-1) cnt++;
                v.push_back(j);
            }
        }
        // cout << i << "->";
        // for(int j = 0; j < v.size(); j++){
        //     cout << v[j] << ' ';
        // }
        // cout << endl;
        int pre = 0;
        for(int k = 0; k < W; k++){
            for(int j = 0; j+1 < v.size(); j++){
                if(query(v[j]+1, v[j+1], pre, k) > K){
                    if(pre == k) ok = false;
                    cnt++;
                    pre = k;
                    break;
                }
            }
        }
        // cout << cnt << endl;
        if(ok) ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin >> s;
  int h,m;
  h = s/3600;
  s %= 3600;
  m = s/60;
  s %= 60;
  printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 3228
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i32 = read();
    let op: String = read();
    let b: i32 = read();

    let ans = match op.chars().next().unwrap() {
        '+' => a + b,
        '-' => a - b,
        _ => unreachable!(),
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//GCD(最大公約数)
ll gcd(ll a, ll b) {
   if(a < b) return gcd(b, a);
   if(b == 0) return a;
   return gcd(b, a % b);
}

vector<pair<ll, ll>> v;
void f(ll n) {
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) continue;
        ll ex = 0;
        while(n % i == 0) {
            ex++;
            n /= i;
        }
        v.push_back({i, ex});
    }
    if(n != 1) v.push_back({n, 1});
    return;
}

int main() {
    ll a, b;
    cin >> a >> b;

    ll g = gcd(a, b);

    f(g);

    cout << v.size() + 1 << endl;

    return 0;
}


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

#define fi first
#define se second

const int N = 200200;
const int mod = 1e9 + 7;

using namespace std;

int n;
int m;
int t[4 * N];
int lz[4 * N];
vector < int > v[N];

void build(int x, int l, int r)
{
        if(l == r){
                t[x] = l;
                return;
        }
        int m = (l + r) / 2;
        build(x * 2, l, m);
        build(x * 2 + 1, m + 1, r);
        t[x] = max(t[x * 2], t[x * 2 + 1]);
}

void upd(int x, int l, int r, int tl, int tr, int y)
{
        if(tl > tr){
                return;
        } else if(l == tl && r == tr){
                t[x] += y;
                lz[x] += y;
                return;
        }
        int m = (l + r) / 2;
        upd(x * 2, l, m, tl, min(m, tr), y);
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr, y);
        t[x] = max(t[x * 2], t[x * 2 + 1]) + lz[x];
}

int get(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return 0;
        } else if(l == tl && r == tr){
                return t[x];
        }
        int m = (l + r) / 2;
        return max(get(x * 2, l, m, tl, min(m, tr)), get(x * 2 + 1, m + 1, r, max(m + 1, tl), tr)) + lz[x];
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n >> m;
        for(int i = 1; i <= n; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
        }
        int res = max(0, n - m);
        build(1, 0, m + 1);

        for(int i = 0; i <= m; i++){
                for(int y: v[i]){
                        upd(1, 0, m + 1, 0, y, 1);
                }
                res = max(res, get(1, 0, m + 1, i + 1, m + 1) - i - m - 1);
        }

        cout << res << "\n";
}


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

void return_err()
{
    printf("%d", -1);
}

int main(int argc, char const *argv[])
{
    int N, M;
    scanf("%1d %1d", &N, &M);

    int *s = (int *) malloc(sizeof(int) * M);
    int *c = (int *) malloc(sizeof(int) * M);
    char *val = (char *) malloc(sizeof(char) * N);

    if (1 == N)
    {
        val[0] = 0;
    } else {
        for (int i = 0; i < N; i++)
        {
            val[i] = (0 == i) ? 1 : 0;
        }
    }
    
    for (int i = 0; i < M; i++)
    {
        scanf("%1d %1d", s+i, c+i);

        if (N > 1 && 1 == s[i] && 0 == c[i]){
            return_err();
            return 0;
        }

        for (int j = 0; j < i; j++)
        {
            if (s[j] == s[i])
            {
                if(c[j] != c[i])
                {
                    return_err();
                    return 0;
                } else {
                    continue;
                }
            }
        }

        val[s[i]-1] = c[i];
    }

    for (int i = 0; i < N; i++)
    {
        printf("%d", val[i]);
    }
    
    
    free(s);
    free(c);
    free(val);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  a = a+b;
  c = c+d;
  if(a > c) cout << "Left" << endl;
  else if(a < c) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <iostream>
    #include<bits/stdc++.h>
    using namespace std;
    int ans;
    void dfs(vector<vector<int>>&g, vector<int>&dp, int u){
            dp[u]=0;
            for(int i=0;i<g[u].size();i++){
                if(dp[g[u][i]]==-1)
                    dfs(g, dp, g[u][i]);
                
                dp[u]=max(dp[u], dp[g[u][i]]+1);
                ans=max(dp[u], ans);  
            }
    }
    int main() {
        int n,e;
        ans=INT_MIN;
        cin>>n>>e;
        vector<vector<int>>graph(n+1);
        vector<int>dp(n+1,-1);
        // vector<bool>vis(n+1,0);
        //vis[0]=1;
        dp[0]=0;
        for(int i=0;i<e;i++){
            int u,v;
            cin>>u>>v;
            graph[u].push_back(v);
        }
        for(int i=0;i<dp.size();i++){
            if(dp[i]==-1)
                dfs(graph, dp, i);
        }
        cout<<ans;
    }

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

int p2(int a){
	int tmp=a;
	int cnt=0;
	while(true){
	if(tmp%2!=0)break;
	tmp/=2;
	cnt++;
	}
	return cnt;
}

int main(){
	int n;cin>>n;
	int ret=0;
	for(int i=0;i<n;i++){
	int x;cin>>x;
	ret+=p2(x);
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 256
//AtCoder ABC076 B - Addition and Multiplication
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N,K;
    cin>>N>>K;
    ll ans=1;
    for(ll i=0;i<N;++i){
        ans=min(ans*2,ans+K);
    }    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
    //ながさN  文字列小文字 S Kばんめ
    string S;
    int N,K;
    cin >> N >> S >> K;

    int X = K-1;
    //B Kばんめの文字
    string B = S.substr(X,1);

    // 置換対象の文字列    // 検索文字列
    for (int i = 0; i < N; i++) {
      string Y = S.substr(i,1);;
      if (Y == B){
      }
      else{
        S.replace(i, 1, "*");
      }
    }
  cout << S << endl;
          
}

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

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

ll a[SIZE], b[SIZE];
int main() {
	start = clock();
	int n;
	ll s1 = 0, s2 = 0;
	scanf("%d", &n);
	for (int i = 0 ; i < n ; ++i) {
		scanf("%lld", &a[i]);
		s1 += a[i];
	}
	bool eq = true;
	for (int i = 0 ; i < n ; ++i) {
		scanf("%lld", &b[i]);
		s2 += b[i];
		if (b[i] != a[i]) eq = false;
	}
	if (eq) {
		printf("Yes\n");
		return 0;
	}
	if (s2 <= s1) {
		printf("No\n");
		return 0;
	}
	
	ll c1 = 0, c2 = 0, d = s2 - s1;
	for (int i = 0 ; i < n ; ++i) {
		if (a[i] > b[i]) c1 += a[i] - b[i];
		else {
			c2 += cil(b[i] - a[i], 2);
			if (a[i] != b[i]) c1 += (b[i] % 2 != a[i] % 2);
		}
	}
	if (d >=c1 && d >= c2 && d - c1 == 2 * (d - c2)) printf("Yes\n");
	else printf("No\n");

	Time(false);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
 
int main(){
  int n;
  int x;
  cin >> n;
 
  for(int i=1; i <=n; i++){
    x  = i;
    if(x%3 == 0)
      cout << " " << i;
    else{
      do{
        if(x%10 == 3){
          cout << " " << i;
          break;
        }
        x /= 10;
        }while(x>0);
      }
   } 
   cout << "\n";
}


Measured memory_bytes: 3108
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = ll(1e18) + 1;

struct eratosthenes
{
    int n;
    vector<int> f;
    vector<P> primes;

    eratosthenes(int n) : f(n + 1)
    {
        ll i, j;
        f[0] = f[1] = -1;
        for (i = 2; i <= n; i++)
        {
            if (!f[i])
            {
                f[i] = i;
                primes.push_back(P(i, 0));
                for (j = i * i; j <= n; j += i)
                {
                    if (!f[j])
                    {
                        f[j] = i;
                    }
                }
            }
        }
    }

    vector<int> genosis(int x)
    {
        vector<int> g;

        while (x != 1)
        {
            g.push_back(f[x]);
            x /= f[x];
        }

        return g;
    }

    vector<P> genosiscount(int x)
    {
        vector<P> gc;
        vector<int> g = genosis(x);

        if (g.empty() == 1)
        {
            return {};
        }

        gc.push_back(P(f[x], 0));

        for (auto &i : g)
        {
            if (gc.back().first == i)
            {
                gc.back().second++;
            }
            else
            {
                gc.push_back(P(i, 1));
            }
        }

        return gc;
    }
};

int main(void)
{
    ll x;
    eratosthenes e(200000);

    cin >> x;

    for (auto &z : e.primes)
    {
        if (z.first >= x)
        {
            cout << z.first << endl;
            break;
        }
    }
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
string s;
cin>>s;
if(s=="SAT")cout<<1;
if(s=="FRI")cout<<2;
if(s=="THU")cout<<3;
if(s=="WED")cout<<4;
if(s=="TUE")cout<<5;
if(s=="MON")cout<<6;
if(s=="SUN")cout<<7;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

const int mod = 1e9 + 7;

int power(int x, int n, int mod) {
    //(x^n)%mod
    int result = 1;
    while(n) {
        if(n % 2)
            result = (result * x) % mod;
        x = (x * x) % mod;
        n /= 2;
    }
    return result;
}


int32_t main() {

    fast
    int n;
    cin >> n;
    if(n == 1) {
        cout << 0;
        return 0;
    }
    int ans=(power(10,n,mod)-((2*power(9,n,mod))%mod-power(8,n,mod)+mod)%mod+mod)%mod;
    //int ans = ((( n * (n - 1)) % mod) * power(10, n - 2, mod)) % mod;
    cout << ans;


    return 0;
}



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

int main() {
  int N, c = 0;
  bool chk = false;
  cin >> N;
  
  vector<int> botton(N);

  for (int i = 0; i < N; i++) {
    cin >> botton.at(i);
  }
  int k = 0;

  for (int i = 0; i < N; i++) {
    c++;
    
    if (botton.at(k) == 2) {
      chk = true;
      break;
    } else {
      k = botton.at(k) - 1;
    }
  }
  
  if (chk) {
    cout << c << endl;
  } else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		long A = scan.nextLong();
		long B = scan.nextLong();
		long AB = A + B;

		long c = 0;

		if (N % AB > A) {
			c = A;
		} else {
			c = N % AB;
		}

		System.out.println(A * (N / AB) + c);

	}

}


Measured memory_bytes: 22868
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------





//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    ll x,k,d;cin>>x>>k>>d;
    ll tmpx=abs(x);
    ll divx_d=(tmpx-tmpx%d)/d;
    if(divx_d>=k){
        O(tmpx-k*d);
    }else{
        ll tmp=k-divx_d;
        if(tmp%2){
            O(abs(tmpx%d-d));
        }else{
            O(tmpx%d);
        }
    }
    
    
    
    
//------------------------------------------------------------
	return 0;
}


Measured memory_bytes: 3648
/* author: Tarek */ 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
const int N=2000005;
int n,c[10][10];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
 int a=i;
 while(a>=10)
    a/=10;
 c[a][i%10]++;
}
ll tot=0;
for(int i=1;i<=n;i++){
  int a=i;
  while(a>=10)
     a/=10;
  tot+=c[i%10][a];
}
   	cout<<tot<<endl;
return 0;
 
}



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

int main() {
    int a[3][3];

    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    int b[n];
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }

    int table[3][3] = {0};

    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < n; k++) {
                if(a[i][j] == b[k]) {
                    table[i][j] = 1;
                    break;
                }
            }
        }
    }

    int ans = 0;

    for(int i = 0; i < 3; i++) {
        if(table[i][0] == 1 && table[i][1] == 1 && table[i][2] == 1) ans = 1;
        if(table[0][i] == 1 && table[1][i] == 1 && table[2][i] == 1) ans = 1;
    }
    if(table[0][0] == 1 && table[1][1] == 1 && table[2][2] == 1) ans = 1;
    if(table[2][0] == 1 && table[1][1] == 1 && table[2][0] == 1) ans = 1;

    if(ans == 1) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<int> eratosthenes(int n) {
  vector<int> p, is_prime(n+1, 1);
  for(int i=2; i<=n; i++) {
    if(is_prime[i]) {
      for(int j=2*i; j<=n; j+=i) is_prime[j] = 0;
      p.push_back(i);
    }
  }
  return p;
}

int main() {
  IOS;
  int n,cnt=0; cin >> n;

  vector<int> p = eratosthenes(55555);
  REP(i,p.size()) {
    if (p[i] % 5 != 1) continue;

    cout << p[i] << " ";
    cnt++;
    if(cnt == n) break;
  }

  return 0;
}

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

using LL = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector<LL> P(M);
  for(auto& i: P) cin >> i;
  vector<LL> A(N + 1), B(N + 1), C(N + 1);
  for(int i = 1; i < N; ++i) cin >> A[i] >> B[i] >> C[i];

  vector<LL> s(N + 1);
  for(int i = 1; i < M; ++i) {
    if(P[i-1] < P[i]) {++s[P[i-1]]; --s[P[i]];}
    else              {++s[P[i]]; --s[P[i-1]];}
  }
  for(int i = 1; i < N; ++i) s[i] += s[i - 1];

  LL ans = 0;
  for(int i = 1; i < N; ++i) ans += min(A[i] * s[i], B[i] * s[i] + C[i]);
  cout << ans << endl;
}

Measured memory_bytes: 6776
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var strs = str.Split(' ');
            var n = int.Parse(strs[0]);
            var m = int.Parse(strs[1]);

            str = Console.ReadLine();
            strs = str.Split(' ');

            if (m <= n)
            {
                Console.WriteLine(0);
                return;
            }

            var nums = new int[m];
            for (int i = 0; i < nums.Length; i++)
            {
                nums[i] = int.Parse(strs[i]);
            }

            Array.Sort(nums);

            var numDiffs = new int[nums.Length - 1];
            for (int i = 0; i < nums.Length - 1; i++)
            {
                numDiffs[i] = nums[i + 1] - nums[i];
            }

            Array.Sort(numDiffs);
            var longLengthSum = 0;
            for (int i = 0; i < n - 1; i++)
            {
                longLengthSum += numDiffs[numDiffs.Length - 1 - i];
            }

            Console.WriteLine(nums.Max() - nums.Min() - longLengthSum);
        }
    }
}


Measured memory_bytes: 16864
fn main() {
    let mut sc = Scanner::new();
    let n = sc.read();
    let a: Vec<usize> = sc.read_vec(n);
    let mut b: Vec<usize> = sc.read_vec(n);

    let mut ans = 0;
    for bit in (1..32).rev() {
        ans <<= 1;

        let mask = (1 << bit) - 1;
        let look = 1 << (bit - 1);
        b.sort_by_key(|&b| b & mask);

        let mut bit_count = 0;
        for &a in &a {
            let a = a & mask;

            let pos1 = b.binary_search_by_key(&(1 * look * 2 - 1), |&b| (a + (b & mask)) * 2)
                .err()
                .unwrap();
            let pos2 = b.binary_search_by_key(&(2 * look * 2 - 1), |&b| (a + (b & mask)) * 2)
                .err()
                .unwrap();
            let pos3 = b.binary_search_by_key(&(3 * look * 2 - 1), |&b| (a + (b & mask)) * 2)
                .err()
                .unwrap();

            let count = n - pos3 + pos2 - pos1;
            bit_count ^= count & 1;
        }
        ans += bit_count;
    }

    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 11640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
  string a;
  int max=0,num=0;
  cin >> a;
  for(int i = 0; i < a.size(); i++){
      if(a[i]=='A'||a[i]=='C'||a[i]=='G'||a[i]=='T') num++;
      else num=0;
      max = std::max(num,max);
  }
  cout << max << endl;
  
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


class comb_calclator():
    def __init__(self, N, p):
        self.N = N
        self.p = p
        self.frac_N = [0 for i in range(N + 1)]
        self.frac_N[0] = 1L
        self.comb_N = {}
        for i in range(1, N + 1):
            self.frac_N[i] = (self.frac_N[i - 1] * i ) % p

    def comb(self, n, r):
        if n<0 or r<0 or n<r: return 0
        if n==0 or r==0: return 1
        if (n, r) in self.comb_N:
            return self.comb_N[(n, r)]
        a = self.frac_N[n]
        b = self.frac_N[r]
        c = self.frac_N[n - r]
        self.comb_N[(n, r)] = (a*power_func(b,self.p-2,self.p)*power_func(c,self.p-2, self.p))% self.p
        self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
        return self.comb_N[(n, r)]


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]

    prime_table = prime_decomposition(M)
    primes = {}
    for p in prime_table:
        if p in primes:
            primes[p] += 1
        else:
            primes[p] = 1

    max_num = 0
    for p in primes:
        max_num = max(max_num, primes[p])

    cmb = comb_calclator(max_num + N, int(1e+9) + 7)
    count = 1
    for p in primes:
        b = primes[p]
        count = (count * cmb.comb(b + N - 1, b))%(int(1e+9) + 7)


    print count



if __name__ == '__main__':
    main()


Measured memory_bytes: 10036
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <cstring>
#include <fstream>

using namespace std;
using ll = long long;

int h[100005];
int dp[100005]; // dp[i] = cheapest cost to get to i

int main()
{
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> h[i];
	memset(dp, 0x3f, sizeof dp);
	dp[1] = 0;
	for(int i = 2; i <= n; i++)
	{
		for(int j = 1; j <= k; j++)
		{
			if(i - j >= 1)
				dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]);
		}
	}
	cout << dp[n] << endl;
	return 0;
}



Measured memory_bytes: 4400
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;

typedef pair<int, int> pii;

int main() {
	int n, cMax;
	cin >> n >> cMax;

	vector<priority_queue<pii, vector<pii>, greater<pii>>> p(cMax);
	for (int i = 0; i < n;i++) {
		int s, t, c;
		cin >> s >> t >> c;
		c--;
		p[c].push(make_pair(s, t));
	}


	
	vector<int> sum(100000 * 2 + 2);
	for (int i = 0; i < cMax;i++) {
		vector<int> active(100000 * 2 + 2);


		while (!p[i].empty()) {
			int s = p[i].top().first;
			int t = p[i].top().second;
			p[i].pop();
			active[s * 2 - 1]++;
			active[t * 2]--;
		}

		for (int i = 1; i < 100001 * 2;i++) {
			active[i] += active[i - 1];
		}
		for (int i = 0; i < 100001 * 2;i++) {
			if (active[i] > 0) {
				sum[i]++;
			}
		}

	}
	int ans = 0;
	for (int i = 0; i < 200002;i++) {
		ans = max(ans, sum[i]);
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int fact(int n) {
  if (n <= 1) {
	  return 1;
	}
  else {
	  return n * fact(n - 1);
	}
}

int main() {
  int N;
  cin >> N;
  vector <int> x(N);
  vector <int> y(N);
  vector <int> v(N);
  double ans = 0.0;
  for (int i = 0; i < N; i++) {
	  cin >> x[i] >> y[i];
	  v[i] = i;
	}
  do {
	  double dist = 0.0;
	  for (int i = 0; i < N - 1; i++) {
		  dist += sqrt((x[v[i]] - x[v[i + 1]]) * (x[v[i]] - x[v[i + 1]]) + (y[v[i]] - y[v[i + 1]]) * (y[v[i]] - y[v[i + 1]]));
		}
	  ans += dist / fact(N);
	} while (next_permutation(v.begin(), v.end()));
  printf("%10f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define ll long long
using namespace std;

int main(){
	string s;
	cin>>s;
	ll res=0,ori=0;
	rep(i,s.size()){
		ll num=s[i]-'0';
		res+=num;
		ori+=num*pow(10,s.size()-1-i);
	}
	cout<<((ori%res)?"No":"Yes")<<endl;
}

Measured memory_bytes: 384
N, W = map(int, raw_input().split())
obj = []
for i in xrange(N):
    w, v = map(int, raw_input().split())
    obj.append((w, v))
dp = [[-1 for _ in xrange(W+1)] for i in xrange(N)]

dp[0][0] = 0
dp[0][obj[0][0]] = obj[0][1]

for i in xrange(1, N):
    w, v = obj[i]
    for j in xrange(W+1):
        if dp[i-1][j] != -1:
            dp[i][j] = dp[i-1][j]
    for j in xrange(W+1):
        if dp[i-1][j] != -1 and j + w <= W:
            dp[i][j+w] = max(dp[i-1][j]+v, dp[i][j+w])
res = 0
for i in xrange(W+1):
    res = max(dp[N-1][i], res)
print res


Measured memory_bytes: 110828
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <stack>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int x;
	cin >> x;
	if (x <= 599) {
		cout << 8 << endl;
	} else if (x <= 799) {
		cout << 7 << endl;
	} else if (x <= 999) {
		cout << 6 << endl;
	} else if (x <= 1199) {
		cout << 5 << endl;
	} else if (x <= 1399) {
		cout << 4 << endl;
	} else if (x <= 1599) {
		cout << 3 << endl;
	} else if (x <= 1799) {
		cout << 2 << endl;
	} else if (x <= 1999) {
		cout << 1 << endl;
	}
	return 0;
}

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

ans_max = 0
while ans_max * (ans_max + 1) / 2 < N:
    ans_max += 1

num_remove = ans_max * (ans_max + 1) // 2 - N
for i in range(1, ans_max + 1):
    if i != num_remove:
        print(i)


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

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		String s = sc.next();
		int n = s.length();
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i<n; i++) {
			sb.append('x');
		}
		
		pw.print(sb);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


Measured memory_bytes: 23124
import java.util.*;

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


    long max = 1;
    for (int i = 0; i < 18; i++) {
      max *= 10;
    }
    // 1000000000000000000
    // 9223372036854775807 System.out.println(Long.MAX_VALUE);
    int n = sc.nextInt();
    long[] list = new long[n];
    for (int i = 0; i < n; i++) {
      list[i] = sc.nextLong();
    }
    sc.close();

    // 昇順で並び替え
    Arrays.sort(list);

    // ０がいればいくらかけても０
    if (list[0] == 0) {
      System.out.println(0);
      return;
    }

    long a = 1;
    for (int i = n - 1; i >= 0; i--) {
      long temp = a * list[i];
      if ( temp > max || temp < a) {
        System.out.println(-1);
        return;
      }
      a = temp;

    }

    System.out.println(a);
  }
}


Measured memory_bytes: 62156
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int x = 0, m = n;
    while(m > 0){
        x += m % 10;
        m /= 10;
    }
    if(n%x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  2e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x ,y, k , Q , ans ; string s,t;
ll dp[MAX]; ll tree[4*MAX];
vector < pair < int , ll > > v;

void update(int node , int lo , int hi , int want, ll val){

    if(want < lo || want > hi)
        return;

    if(lo == hi){
        tree[node] = val;
        return;
    }

    int mid = (lo + hi )/2;

    update(2*node + 1,lo , mid,want,val);
    update(2*node + 2,mid + 1,hi,want,val);

    tree[node] = max(tree[2*node + 1],tree[2*node + 2]);

}


ll query(int node , int lo , int hi , int ql , int qh){

    if(qh < lo || ql > hi )
        return 0;

    if(ql <= lo && hi <= qh)
        return tree[node];


    int mid = (lo + hi)/2;

    return max(query(2*node + 1,lo,mid,ql,qh),query(2*node + 2,mid + 1,hi,ql,qh));
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//   freopen("test.in","r",stdin);


    cin>>n;

    for(int i = 0 ; i < n ; ++i)
        cin>>x,v.pb({x,0});

    for(int i = 0 ; i < n ; ++i)
        cin>>v[i].s;
    ans = 0 ;

    for(int i = 0 ; i < n ; ++i){
        ll sum = v[i].s + query(0,0,n,0,v[i].f);
        update(0,0,n,v[i].f,sum);
        ans = max(ans,sum);
    }

    cout<<ans<<'\n';



    return 0;
}


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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int a, b, k;
    cin >> a >> b >> k;
    bool odd = false;
    if (k % 2 == 1) {
        odd = true;
        k--;
    }
    k /= 2;
    rep(i, k) {
        if (a % 2 == 1) {
            a--;
        }
        a -= a / 2;
        b += a;
        if (b % 2 == 1) {
            b--;
        }
        b -= b / 2;
        a += b;
    }
    if (odd) {
        if (a % 2 == 1) {
            a--;
        }
        a -= a / 2;
        b += a;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3596
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val k = cin.nextInt()
    val max = (n-1)*(n-2)/2
    if (k > max) {
        println(-1)
    } else {
        val diff = max - k
        println(n - 1 + diff)
        for (i in 2..n) {
            println("1 ${i}")
        }
        var l = 2
        var r = 3
        for (i in 1..diff) {
            println("$l $r")
            if (r == n) {
                l += 1
                r = l + 1
            } else {
                r += 1
            }
        }
    }
}

Measured memory_bytes: 31264
<?php

$input = trim(fgets(STDIN));
$a = explode(' ',$input);

$W = $a[0];
$H = $a[1];
$x = $a[2];
$y = $a[3];
$r = $a[4];
	
if((0 <= ($x-$r) && ($x+$r) <= $W) && (0 <= ($y-$r) && 	($y+$r) <= $H)){

	echo "Yes";
	
}else{
	echo "No";
}

?>

Measured memory_bytes: 15376
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;

int main(){
   int n;
   string s;
   cin >> n >> s;
   
   int count=0;
   REP(i,n-2){
       if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
           count++;
       }
   }
   
   cout << count << endl;
   
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		for(i=1;i<=n;i++){
			if(i%3==0){
				System.out.print(" "+i);
			}
			int x = i;
			while(i%3!=0){
				if(x==0)break;
				if(i%10==3||x%10==3){
					System.out.print(" "+i);
					break;
				}else{
					x = x/10;
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 28660