akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <functional>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int q;
    cin >> q;

    priority_queue<int> q0;
    priority_queue<int, vector<int>, greater<>> q1;
    ll s0 = 0, s1 = 0;

    ll s = 0;
    int k = 0;

    for (int h = 0; h < q; h++) {
        int t;
        cin >> t;

        if (t == 1) {
            int a, b;
            cin >> a >> b;

            if (k % 2 == 0) {
                auto v = k == 0 ? a : q1.top();
                if (a > v) {
                    q0.push(v);
                    s0 += v;
                    q1.pop();
                    s1 -= v;
                    q1.push(a);
                    s1 += a;
                } else {
                    q0.push(a);
                    s0 += a;
                }
            } else {
                auto v = q0.top();
                if (a < v) {
                    q1.push(v);
                    s1 += v;
                    q0.pop();
                    s0 -= v;
                    q0.push(a);
                    s0 += a;
                } else {
                    q1.push(a);
                    s1 += a;
                }
            }

            s += b;
            k++;

        } else {
            auto x = q0.top();
            auto r = ((ll)q0.size() * x - s0) + (s1 - (ll)q1.size() * x) + s;
            cout << x << ' ' << r << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3452
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int count;
    int ans = 0;
    
    for(int i = 1; i <= N; i+=2){
        count = 0;
        for(int j = 1; j <= i; j++){
            // 約数の個数を計算し、カウントする
            if((i % j) == 0){      
                count++;
                if(count == 8){
                    ans++;
                }
            }
        }
    }    
        System.out.println(ans);
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  map<int,int> m;
  ll ans = 0;
  REP(i,N) {
    // 自分より左の項目と一致するのを加算
    if (i != 0 ) ans += m[i+1-A[i]];
    m[i+1+A[i]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 21088
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

    static int N;
    static int K;
    static int Q;
    static int A;
    static long B;
    static long C;
    //    static int[][] map;
    static int min = 9999999;
    static long ans = 0;


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

        long N = scanner.nextInt();

        long M = scanner.nextInt();

        long ans = 1;
        long nokori;

        for (long i = M; i >= 0; i--) {
            nokori = M - N * i;

            if (nokori >= 0 && nokori % i == 0){
                ans = i;
                break;
            }
        }

        System.out.println(ans);
    }
}



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

const int DIM = 100005;

int arr[DIM];

int getgcd(int x, int y) {
    return !y ? x : getgcd(y, x % y);
}

bool solve(int n)
{
    int nr = 0;
    for (int i = 1; i <= n; ++i)
        nr += (arr[i] & 1);

    if ((n - nr) & 1) return true;
    if (nr >= 2) return false;
    
    for (int i = 1; i <= n; ++i) if (arr[i] & 1) {
        if (arr[i] == 1)
            return false;
        --arr[i];
    }
    
    int gcd = arr[1];
    for (int i = 1; i <= n; ++i)
        gcd = getgcd(gcd, arr[i]);
    
    for (int i = 1; i <= n; ++i)
        arr[i] /= gcd;
    
    return !solve(n);
}

int main(void)
{
    int n; cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> arr[i];
    
    cout << (solve(n) ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 640
def palindrome(string): return 0 if string==string[::-1] else 1

s = input()
n = len(s)

kai1 = int((n - 1) / 2)
kai2 = int((n + 3) / 2)

first = s[0:kai1]
second = s[kai2-1:n]
if palindrome(s) == 0:
    if palindrome(first) == 0:
        if palindrome(second) == 0:
            print('Yes')
            exit()

print('No')



Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

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

	vector<int> x(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}

	sort(x.begin(), x.end());
	vector<int> dist(m);
	dist[0] = numeric_limits<int>::max();

	for (int i = 1; i < m; i++) {
		dist[i] = x[i] - x[i - 1];
	}
	
	sort(dist.begin(), dist.end());

	ll total_dist = 0;
	for(auto it = dist.begin(); it < dist.end() - n; it++) {
		total_dist += *it;
	}

	cout << total_dist;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int W,a,b,A,B;
  cin>>W>>a>>b;
  A=max(a,b);
  B=min(a,b);
  if(A-B-W<=0) cout<<"0"<<endl;
  else cout<<A-B-W<<endl;
}


Measured memory_bytes: 256
N = int(input())
heights = list(map(int, input().split()))
steps = [0] * N
for i in range(1, N):
    if heights[i-1] + steps[i-1] > heights[i]:
        steps[i] = (heights[i-1] + steps[i-1]) - heights[i]
    else:
        steps[i] = 0
        
print (sum(steps))

Measured memory_bytes: 32248
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
int N, Q;
char str[100001];
int c[100001], cur;
int main() {
	scanf("%d%d", &N, &Q);
	vector<int> l(Q), r(Q);
	scanf("%s", str);
	rep(i, 0, Q)scanf("%d%d", &l[i], &r[i]);
	rep(i, 1, N) {
		if (str[i - 1] == 'A' && str[i] == 'C')cur++;
		c[i] = cur;
	}
	rep(i, 0, Q)printf("%d\n", c[r[i] - 1] - c[l[i] - 1]);
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
using namespace std;
int main() {
    int n,q,r;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    cin >> q;vector<bool> w(q);
    for (int i = 0; i < q; i++) {
        cin >> r;
        w[i] = binary_search(v.begin(), v.end(), r);
    }
    for (int I = 0; I < q; I++) {
        if (w[I])
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long gcd(long long a,long long b){

    if(b%a==0) return a;

    else return gcd(b%a,a);

}
ll a[105],ans;
int main(void){
	ll n; cin>>n;
	cin>>a[0];
	ans=a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		ll g=gcd(ans,a[i]);
		ans=a[i]/g*ans;
	}
	cout<<ans<<endl;
	
	
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main()
{
	unordered_map<int, bool> verdict;
	unordered_map<int,int> penalties;
	int correct = 0, penalty = 0;
	int n, m;
	cin>>m>>n;
	for(int i = 0;i<n;i++)
	{
		int problem;
		string checker;
		cin>>problem>>checker;
		if(verdict[problem])
			continue;
		if(checker[0]=='A')
		{
			verdict[problem] = true;
			correct++;
			penalty += penalties[problem];
		}
		else if(checker[0]=='W')
		{
			penalties[problem]++;
		}
	}
	cout<<correct<<" "<<penalty<<endl;
	return 0;
}


Measured memory_bytes: 8520
#include <iostream>
#include <stdio.h>
#include <string.h>
#include<algorithm>


#define N 1010

using namespace std;
int main(void){
    // Your code here!
 
 int n;int sl=0;int tl=0;
 char s[N];
 char t[N];
 
 int count=0;
 int maxc=0;
 int flag=0;

scanf("%s",s);
scanf("%s",t);

sl=strlen(s);
tl=strlen(t);


//can greedy brute force?
for(int i=0; i<sl; i++){
    for(int j=0; j<tl; j++){
        
        if( s[i+j]==t[j]  ) count++;
        if( (i+j)>=sl ){
            count=0;
            break;
        }
    }
    maxc=max( maxc, count );
    count=0;
}

printf("%d\n",tl-maxc);
 
 
 return 0;   

}


Measured memory_bytes: 3780
#include "bits/stdc++.h"
using namespace std;

int main() {
    double w,h, x,y;
    cin >> w >> h >> x >> y;
    cout << h * w / 2 << " ";
    if(w/2 == x && h/2 == y) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC123_D___Cake_123別解
{
    class Program
    {
        static void Main(string[] args)
        {
            var XYZK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var K = XYZK[3];
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse).OrderByDescending(n => n).ToArray();
            var B = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse).OrderByDescending(n => n).ToArray();
            var C = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse).OrderByDescending(n => n).ToArray();

            var cakes = new List<long>();
            for (int a = 0; a < A.Length; a++)
            {
                for (int b = 0; b < B.Length; b++)
                {
                    for (int c = 0; c < C.Length; c++)
                    {
                        if (a * b * c > K) break;
                        cakes.Add(A[a] + B[b] + C[c]);
                    }
                }
            }
            cakes = cakes.OrderByDescending(c => c).Take(K).ToList();
            foreach (long c in cakes) Console.WriteLine(c);
        }
    }
}


Measured memory_bytes: 99480
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

vector<int> g[101];
bool visited[101]{};
P ans[101];

int dfs(int s, int t) {
    visited[s] = true;
    ans[s].first = t;
    REP(i, g[s].size()) {
        if (visited[g[s][i]]) continue;
        t = dfs(g[s][i], t + 1);
    }
    t++;
    ans[s].second = t;
    return t;
}

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        int u, m;
        cin >> u >> m;
        REP(j, m) {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1, T = 0; i <= n; i++) {
        if (visited[i]) continue;
        T = dfs(i, T+1);
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define MAX 10000000
using namespace std;
 
 
int main(){
	ll n,W,w,v;
	cin >> n >> W;
	vector< pair<ll,ll> > knap;
	for(int i=0;i<n;i++){
		cin >> w >> v;
		knap.push_back({w,v});
	}
	ll k[n+1][W+1];
	for(int i=0;i<=n;i++){
		for(int s=0;s<=W;s++){
			if(i==0 || s==0){
				k[i][s]=0;
			}
			else if(knap[i-1].first <=s){
				k[i][s] = max(knap[i-1].second + k[i-1][s - knap[i-1].first], k[i-1][s]);
			}
			else{
				k[i][s] = k[i-1][s];
			}
		}
	}
	cout << k[n][W] << endl;
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;

ll n, a[202020], s;

ll pw(ll a, ll b){
    ll ret = 1; a %= mod;
    while(b){
        if(b & 1) ret = ret * a % mod;
        b >>= 1; a = a * a % mod;
    }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i], s += a[i];
    s %= mod;
    ll res = s * s % mod;
    for(int i=1; i<=n; i++){
        res -= a[i] * a[i] % mod;
        res %= mod; res += mod; res %= mod;
    }
    cout << res * pw(2, mod-2) % mod;
}

Measured memory_bytes: 5216
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1
m = n-1

while len(res) >1:
    resu = min(resu,max(res[0],m-res[0]))
    x = res.pop(1)
    res[0]  = res[0]+x    
    
print(resu)

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    char c;
    for(int i=0; i<9; i++){
            cin>>c;
            if(i==0||i==4||i==8){
                    cout<<c;
            }
    }
    cout<<endl;
}


Measured memory_bytes: 3584
//1

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b)for(int i=(a); i<(b); i++)
#define REP(i,n)FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b){if (a<b){a = b; return 1;}return 0;}
template<typename A, typename B> inline bool chmin(A &a, B b){if (a>b){a = b; return 1;}return 0;}

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

const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const bool debug = 1;

int N;
int p[300][300];
int sum[300][301];
int d[300], ma[300];

int main(){
	cin >> N;
	REP(i, N) REP(j, N) scanf("%d", &p[i][j]);
	
	REP(i, N) REP(j, N) sum[i][j + 1] = sum[i][j] + p[i][j];
	
	ll ans = -INF;
	REP(i, N) REP(j, N) {
		int sum = 0;
		FOR(h, i, N) {
			sum += p[h][j];
			chmax(ans, sum);
		}
	}
	REP(i, N) REP(j, N) {
		int sum = 0;
		FOR(w, j, N) {
			sum += p[i][w];
			chmax(ans, sum);
		}
	}
	
	FOR(x, 1, N) {
		REP(w, N) {
			// [x - 1, x + w] 横棒は[x, x+w)
			if (x + w >= N) break;
			d[0] = sum[0][x+w+1]-sum[0][x];
			
			REP(i, N - 1) d[i + 1] = d[i] - (sum[i][x+w] - sum[i][x]) + (sum[i + 1][x+w+1] - sum[i + 1][x - 1]);
			
			ma[N - 2] = d[N - 1];
			for (int i = N - 3; i >= 0; i--) ma[i] = max(ma[i + 1], d[i + 1]);
			
			REP(i, N - 1) {
				chmax(ans, ma[i] - d[i] + (sum[i][x+w+1]-sum[i][x-1]) + (sum[i][x+w]-sum[i][x]));
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3852
#include<stdio.h>

void swap(int *x,int *y){
    int z;
    z=*x;
    *x=*y;
    *y=z;
}

int main(void){
    int N,K;
    int p[1024];
    int i,m,n,l;
    int sum=0;
    scanf("%d",&N);
    scanf("%d",&K);
    for(i=0;i<N;i++){
        scanf("%d",&p[i]);
    }
    
    //バブルソート
    for(m=0;m<N;m++){
        for(n=m+1;n<=N;n++){
            if(p[m]>=p[n]){
                swap(&p[m],&p[n]);
            }
        }
    }

  /*  printf("並び替えると");
    for(i=0;i<N;i++){
        printf("%d ",p[i]);
    }
    printf("\n");
    */

    for(l=0;l<=K;l++){
        sum+=p[l];
    }
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 2160
#include<stdio.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Min(a, b) ((a < b)? a : b)
#define Max(a, b) ((a > b)? a : b)
#define Abs(x) ((x>=0)? x : -x)/*Return the absolute value of x.*/
typedef long long int lli;
/*  scan  */
#define sd(a) scanf("%d",&a)
#define sc(a) scanf("%c",&a), getchar()
#define sf(a) scanf("%f",&a)
#define ss(a) scanf("%s",a)
#define sld(a) scanf("%lld",&a)
/*  print  */
#define odn(a) printf("%d\n",a)
#define oldn(a) printf("%lld\n",a)
#define ocn(a) printf("%c\n",a)
#define ofn(a) printf("%f\n",a)
#define osn(a) printf("%s\n",a)
#define od(a) printf("%d ",a)
#define old(a) printf("%lld\n",a)
#define oc(a) printf("%c ",a)
#define of(a) printf("%f ",a)
#define os(a) printf("%s ",a)
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int a, b, c, d;
	sd(a); sd(b);
	c = Max((a+b), (a-b));
	d = Max(c, a*b);
	od(d);
	return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 && i % 5) ans += i;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
int main() {
	int q;
	scanf("%d", &q);
	while (q--) {
		int a, b;
		scanf("%d %d", &a, &b);
		int r = sqrt(1LL * a * b);
		int res = 2 * r;
		if (1LL * r * r == 1LL * a * b) { // square root not counted
			res -= 2 + (a < r) + (b < r);
		} else if (r * (r + 1LL) >= 1LL * a * b) { // square root counted once
			res -= 1 + (a <= r) + (b <= r) - (a == b);
		} else if (a == r + 1 || b == r + 1) { // square root counted once
			res -= 1 + (a <= r) + (b <= r);
		} else {
			res -= (a <= r) + (b <= r);
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stack>
#include<queue>
using namespace std;
const int MAXn=100000;
const int NIL=-1;

int n,col[MAXn];
vector<int> G[MAXn];

void dfs(int r,int c)
{
	stack<int> S;
	S.push(r);
	col[r]=c;
	while(!S.empty())
	{
		int u=S.top();S.pop();
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i];
			if(col[v]==NIL)
			{
				col[v]=c;
				S.push(v);
			}
		}
	}
	return;
}

void assigncol()
{
	int id=1;
	for(int i=0;i<n;i++)col[i]=NIL;
	for(int u=0;u<n;u++)if(col[u]==NIL)dfs(u,id++);
	return;
}

int main() {
	int m,a,b,q;cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	assigncol();
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a>>b;
		if(col[a]==col[b])cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	string s;
	cin >> s;
	if(s.size()<4){
		cout << "No" << endl;
		return 0;
	}
	if(s.substr(0,4) == "YAKI") cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>

using namespace std;




int main(int argc, char *argv[])
{
	int n;
	vector<int> a;

	cin >> n;

	for (int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}


	int ans = 0;
	for (int i = 0; i < n; i++){
		ans += a[i] - 1;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long N,K;
cin>>N>>K;
long long d,a;
int mem[N]={};
for(long long i=0;i<K;++i){
    cin>>d;
    for(long long j=0;j<d;++j){
        cin>>a;
        a--;
        mem[a]=1;
    }
}
long long ans=0;
for(int i=0;i<N;++i){
if(mem[i]!=1){
    ans+=1;
}
}
cout<<ans<<"\n";

return 0;
}


Measured memory_bytes: 3596
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

void solv() {
	
	ll k;
	cin >> k;
	ll rem = k % 50;
	cout << 50 << endl;
	ll mul = k / 50;
	mul--;
	ll p[50];
	p[0] = 50 + mul + ((rem > 0) ? 1 : 0);
	int su = 0;
	for (size_t i = 1; i < 50; i++)
	{
		p[i] = 50 + mul;
		if (k < 50) {
			if(i >= k)
				p[i] = 0;
		}
		else {
			if (i >= rem) p[i] -= rem;
		}
	}

	for (size_t i = 0; i < 50; i++)
	{
		if (i > 0) cout << " ";
		cout << p[i];
	}
	cout << endl;
	//for (size_t i = 0; i < 50; i++)
	//{
	//	p[i] = 46;
	//}
	//p[0] = 51;
	//p[1] = 50;
	//p[2] = 50;
	//p[3] = 50;
	//int c = 0;
	//while (true)
	//{
	//	bool ok = true;
	//	for (size_t i = 0; i < 50; i++)
	//	{
	//		if (!ok || p[i] < 50){
	//			p[i] += 1;
	//		}
	//		else if (p[i] >= 50) {
	//			ok = false;
	//			p[i] -= 50;
	//		}

	//	}
	//	if (ok) break;
	//	c++;
	//}
	//cout << c << endl;

}

int main() {
	//COMinit();
	solv();

	return 0;
}


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

/* answer is number in bracket minus 1
44, 8 (2)

444, 48, 12, 3 (4)

4444, 448, 88, 16, 7 (5)
4444, 448, 412, 43, 7 (5)

44444, 4448, 4412, 443, 47, 11, 2 (7)

444444, 44448, 4488, 888, 168, 114, 24, 6 (8)

4444444, 444448, 44488, 4888, 4168, 4114, 424, 46, 10, 1 (10)


44444444, 4444448, 844448, 88448, 8888, 8816, 887, 167, 77, 14, 5 (11)
*/

// 108, 18, 9 (3)

// 1990, 199, 109, 19, 10, 1 (6)

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

    long long sumOfDigits = 0;
    long long numDigits = 0;
    for(int i = 0; i < N; i ++){
        int d; long long c;
        scanf("%d%lld", &d, &c);
        numDigits += c;
        sumOfDigits += c*d;
    }
    long long extraDigits = (sumOfDigits-1)/9;
    printf("%lld", numDigits+extraDigits-1);
}


Measured memory_bytes: 256
while True:
    n, r, l = map(int, input().split())
    if n == 0:
        break
    else:
        a = []
        for i in range(n):
            a.append(int(input()))
        a.append(1)
        count = 0
        for i in range(r, l + 1):
            for j in range(n + 1):
                if i % a[j] == 0:
                    if j % 2 == 0:
                        count += 1
                    break
        print(count)


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


inline int health_fun(int *h , int *a){
    int rem = (*h)%(*a);
    if(rem==0)
        return (*h)/(*a);
    else
        return 1 + (*h)/(*a);
}

int main(){
    int h,a;
    cin>>h>>a;
    int ans = health_fun(&h,&a);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
//#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const int inf2 = 1145141919;
const ld pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//??£??\???????????¨???
	ll to, cost;
};
struct S {//???????????±?????\???????????°
	int from, to, cost;
};
bool operator<(S a, S b) { return a.cost < b.cost; }
bool operator>(S a, S b) { return a.cost > b.cost; }
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad?????§?¨???????2??????????????¢
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
string a, b;
int dp[4000][4000];
signed main() {
	while (cin >> a >> b) {
		int n = a.size(), m = b.size();
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				dp[i][j] = 0;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) 
						dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
					else 
						dp[i][j] = 1;
					ans = max(ans, dp[i][j]);
				}
			}
		}
		cout << ans << endl;
	}
	getchar(); getchar();
}

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

int main(){
  string s;cin>>s;
  int c=0,ans=0;
  rep(i,s.size()){
    if(s.at(i)=='A'||s.at(i)=='T'
       ||s.at(i)=='G'||s.at(i)=='C'){c++;ans=max(ans,c);}
    else{ans=max(c,ans);c=0;}
  }
  cout<<ans;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<P>a(n);
  rep(i,0,n){
    cin>>a[i].fi;
    a[i].se=i+1;
  }
  sort(ALL(a));
  rep(i,0,n){
    if(i!=0)cout<<" ";
    cout<<a[i].se;
  }
  cout<<endl;
  return 0;
}

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

int main()
{
  int N;

  cin >> N ;

  vector<int> A(N);
  //vector<vector<int>> A(N, vector<int>(30));

  
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    /*for (int j = 0; j < K.at(i); j++)
    {
      cin >> A.at(i).at(j);
    }*/
  }

  vector<int> B(N);
  //cout << "test" << endl;

  for (int i = 0; i < N; i++)
  {
    B.at(i) = A.at(i);
  }

  //cout << "test" << endl;
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());

  //cout << "test" << endl;

  for (int i = 0; i < N;i++){
    if(A.at(i)==B.at(0)){
      if(B.at(0)==B.at(1)){
        cout << B.at(0) << endl;
      }
      else{
        cout << B.at(1) << endl;
      }
    }
    else{
      cout << B.at(0) << endl;
    }
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353

long pow_and_mod(int x, int N)
{
    if (N == 0)
    {
        return 1;
    }
    else
    {
        return (x * pow_and_mod(x, N - 1)) % MOD;
    }
}

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    int a[N];
    // S = 作る三角形の辺の合計の長さ
    int S = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        S += a[i];
    }

    // DP1[i][j] : i番目までの要素で辺Rの長さがjとなる選び方の個数
    // DP2[i][j] : i番目までの要素で辺Rの長さがj、辺Bの長さS-jがとなる選び方の個数
    int DP1[N][S + 1];
    int DP2[N][S + 1];
    // 初期化
    for (int n = 0; n < N; n++)
    {
        for (int s = 0; s < S + 1; s++)
        {
            DP1[n][s] = DP2[n][s] = 0;
        }
    }

    // 初期値代入祭
    DP1[0][0] = 2;
    DP1[0][a[0]] = 1;
    DP2[0][0] = 1;
    DP2[0][a[0]] = 1;

    for (int i = 1; i < N; i++)
    {
        for (int j = 0; j < S + 1; j++)
        {
            if (j - a[i] >= 0)
            {
                DP1[i][j] = ((DP1[i - 1][j] * 2) % MOD + DP1[i - 1][j - a[i]]) % MOD;
                DP2[i][j] = (DP2[i - 1][j] + DP2[i - 1][j - a[i]]) % MOD;
            }
            else
            {
                DP1[i][j] = (DP1[i - 1][j] * 2) % MOD;
                DP2[i][j] = DP2[i - 1][j];
            }
        }
    }
    /*
    cout << endl;

    for (int n = 0; n < N; n++)
    {
        for (int s = 0; s < S + 1; s++)
        {
            cout << to_string(DP1[n][s]) + " ";
        }
        cout << endl;
    }
    cout << endl;*/

    // R_is_bigger_than_half_of_S : 辺RがS/2より長い選び方の数
    long R_is_bigger_than_half_of_S = 0;
    if (S % 2 == 0)
    {
        for (int j = S / 2; j <= S; j++)
        {
            R_is_bigger_than_half_of_S += DP1[N - 1][j];
        }
    }
    else
    {
        for (int j = S; j > S / 2; j--)
        {
            R_is_bigger_than_half_of_S += DP1[N - 1][j];
        }
    }

    R_is_bigger_than_half_of_S %= MOD;

    // R_and_B_is_half_of_S: 辺R、Bの長さが共にS/2となる選び方の数
    long R_and_B_is_half_of_S = 0;
    if (S % 2 == 0)
    {
        R_and_B_is_half_of_S = DP2[N - 1][S / 2] % MOD;
    }

    //cout << R_is_bigger_than_half_of_S << endl;
    cout << ((pow_and_mod(3, N) - (R_is_bigger_than_half_of_S * 3) % MOD + MOD) % MOD + (R_and_B_is_half_of_S * 3)) % MOD << endl;

    return 0;
}


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

int main()
{
    int l,r,k;
    int cnt=0;
    scanf("%d %d %d",&l,&r,&k);
    for(int i=l;i<=r;i++)
    {
        if(i%k==0)
        {
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 3820
#include<iostream>
#include<string>
#include<queue>
using namespace std;

int main(){
    string s;
    cin >> s;

    queue<char> q;

    int count = 0;
    for(int i = 0; i < s.size();){
        if(i != s.size()-1){
            //cout << s[i] << " "<< s[i+1] <<" "<<i << endl;
            if((s[i]-'0') + (s[i+1]-'0') == 1){
                //cout << "i" << i << endl;
                count+=2;
                if(i+2 >= s.size()){
                    i+=2;
                }
                else {
                    i += 2;
                }
                //cout<<"c"<<count<<"i"<<i<<endl;
            }
            else {
                if(q.size() == 0){
                    q.push(s[i]); 
                }
                else{
                    if((q.front()-'0') + (s[i]-'0')==1){
                        count+=2;
                        q.pop();
                        //cout <<"cc"<<count<<endl;
                    }
                    else {
                        q.push(s[i]);
                    }
                }
                i++;
            }
        }
        else {
            if(q.size() == 0){
                    q.push(s[i]);
                    //i++;
            }
            else{
                if((q.front()-'0') + (s[i]-'0')==1){
                    count+=2;
                    q.pop();
                    //i++;
                }
            }
            i++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.lang.Integer;
import java.util.HashMap;

public class Main {
    // driver function to test the above functions
    public static void main(String args[]) throws IOException {
        Reader.init(System.in);

        String n = Reader.next();
        char[] arr = n.toCharArray();

        if (arr[2]==arr[3]&&arr[5]==arr[4]){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }

    }
}

class Node{
    char val;
    Node nxt = null;
    Node prev=null;


}



class solu{

}

/** Class for buffered reading int and double values */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

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

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

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

    static String line() throws IOException {
        return reader.readLine();
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	long long w, h, x, y;
	cin >> w >> h >> x >> y;
	printf("%.08Lf ", (long double)w*h/2.0);
	if (2*x == w && 2*y == h)
		printf("1\n");
	else
		printf("0\n");
	return 0;

}


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

int main() {
  LL n, m;
  cin >> n >> m;
  vector<LL> a(n+1);
  for (int i = 1; i <= n; i ++) cin >> a[i];

  sort(a.begin(), a.end());
  LL x = max(a[n], m);
  LL dp[51][51][2501];
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i ++) {
    for (int j = 0; j <= n; j ++) {
      for (int k = 0; k <= n*x; k ++) {
        if (k < a[i]) dp[i][j][k] = dp[i-1][j][k];
        else if (j > 0 && k >= a[i]) dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-a[i]];
        else dp[i][j][k] = 0;
      }
    }
  }

  LL ans = 0;
  for (int i = 1; i <= n; i ++) {
    ans += dp[n][i][i*m];
  }

  cout << ans << endl;
}


Measured memory_bytes: 50944
#define Bobyama
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_H = 2000, MAX_W = 2000;
int H, W;
string field[MAX_H];

int b[MAX_H][MAX_W], t[MAX_H][MAX_W], l[MAX_H][MAX_W], r[MAX_H][MAX_W];

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

  cin >> H >> W;
  rep(i, H) cin >> field[i];

  rep(i, H) {
    rep(j, W) {
      if (field[i][j] == '#') l[i][j] = j;
      else l[i][j] = (j == 0 ? -1 : l[i][j-1]);
    }
  }

  rep(i, H) {
    rrep(j, W) {
      if (field[i][j] == '#') r[i][j] = j;
      else r[i][j] = (j == W-1 ? W : r[i][j+1]);
    }
  }

  rep(i, H) {
    rep(j, W) {
      if (field[i][j] == '#') b[i][j] = i;
      else b[i][j] = (i == 0 ? -1 : b[i-1][j]);
    }
  }

  rrep(i, H) {
    rep(j, W) {
      if (field[i][j] == '#') t[i][j] = i;
      else t[i][j] = (i == H-1 ? H : t[i+1][j]);
    }
  }
    
  int ans = 0;
  rep(i, H) {
    rep(j, W) {
      if (field[i][j] == '#') continue;
      int tmp = t[i][j]-b[i][j]-1 + r[i][j]-l[i][j]-1 -1;
      ans = max(ans, tmp);
    }
  }
  
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 68864
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
// int N が既に与えられているとする.

/*
int vector_finder(std::vector<int> vec, int number)
{
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance(vec.begin(), itr);
    if (index != vec.size())
    { // 発見できたとき
        return 1;
    }
    else
    { // 発見できなかったとき
        return 0;
    }
}
*/

int main()
{
    int N, M;

    int ac_num = 0;
    int wa_num = 0;

    int p = 0;
    string s = "";

    cin >> N >> M;
    int ac_list[N + 1] = {};
    int wa_list[N + 1] = {};

    for (int i = 0; i < M; i++)
    {
        cin >> p >> s;
        if (s == "WA")
        {
            if (ac_list[p] == 0)
            {
                wa_list[p] += 1;
            }
        }
        else
        {
            if (ac_list[p] == 0)
            {
                ac_list[p] = 1;
                ac_num++;
                wa_num += wa_list[p];
            }
        }
    }

    cout << ac_num << " " << wa_num << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        long ans = Stream.of(a, b, c).distinct().count();
        System.out.println(ans);
    }
}

Measured memory_bytes: 27860
import java.math.BigInteger;
import java.util.*;

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

        int N = sc.nextInt();
        String[] A = new String[N];

        BigInteger result = BigInteger.ONE;

        for(int i=0; i<N; i++) {
            A[i] = sc.next();
            if(A[i].equals("0")) {
                result = BigInteger.ZERO;
            }
        }

        for(int i=0; i<N; i++) {
            String inputStr = A[i];
            BigInteger inputNum = new BigInteger(inputStr);

            result = result.multiply(inputNum);

            if(result.equals(BigInteger.ZERO)) {
                break;
            }

            if(result.compareTo(BigInteger.TEN.pow(18)) > 0) {
                result = new BigInteger("-1");
                break;
            }
        }

        System.out.println(result);
    }
}

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

int main() {
	int n, x, cnt;
	while (cin >> n >> x, n) {
		cnt = 0;
		for (int i = 1; i <= n - 2; i++) {
			for (int j = i + 1; j <= n - 1; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x) cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, x, A;
  A = 0;
  while(1){
    cin >> n >> x;
    if(n == 0 && x == 0)break;
    A = 0;
    for(int a=1;a<n;a++)
      for(int b=a+1;b<n;b++)
	for(int c=b+1;c<=n;c++){ if( a+b+c !=x)continue;
	  A++;
	}
  
    cout << A << endl;
  }




  return 0;
}


Measured memory_bytes: 3088
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int s[MAXN],g[MAXN],match[MAXN],f[MAXN][MAXN];
int upd(int x,int y){ return x+y>=mods?x+y-mods:x+y; }
int main()
{
	int n=read(),k=read();
	for (int i=1;i<=k;i++)
	{
		int x=read(),y=read();
		match[x]=y,match[y]=x;
	}
	for (int i=1;i<=n<<1;i++) s[i]=s[i-1]+(!match[i]);
	g[0]=1;
	for (int i=2;i<=n<<1;i+=2) g[i]=1ll*g[i-2]*(i-1)%mods;
	int ans=0;
	for (int i=1;i<=n<<1;i++)
		for (int j=i;j<=n<<1;j++)
		{
			bool flag=1;
			for (int k=i;k<=j;k++)
				if (match[k]&&(match[k]<i||match[k]>j)) { flag=0; break; }
			if (!flag) continue;
			f[i][j]=g[s[j]-s[i-1]];
			for (int k=i+1;k<j;k++) f[i][j]=upd(f[i][j],mods-1ll*f[i][k]*g[s[j]-s[k]]%mods);
			ans=upd(ans,1ll*f[i][j]*g[s[n<<1]-s[j]+s[i-1]]%mods);
		}
	printf("%d\n",ans);
	return 0;
}


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

int main(void){
    int n;cin >> n;
    int p[n],q[n];
    vector<int> v(n);
    for(int i = 0;i < n;i++)cin >> p[i];
    for(int i = 0;i < n;i++)cin >> q[i];
    for(int i = 0;i < n;i++)v[i] = i+1;
    
    int a = 0,b = 0,sum = 0;
    
    do{
        sum++;
        bool check = true;
        for(int j = 0;j < n;j++)if(v[j] != p[j])check = false;
        if(check)a = sum;
        
        check = true;
        for(int j = 0;j < n;j++)if(v[j] != q[j])check = false;
        if(check)b = sum;
        
    } while(next_permutation(v.begin(),v.end()));
    
    cout << abs(a-b) << endl;
}

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

int main(){
  long long n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  
  int count = 0;
  bool overtake = false;
  bool can1 = false;
  bool can2 = false;
  bool answer = false;
  
  long long smaller;
  if(c < d){
    smaller = c;
  }else{
    smaller = d;
  }
  
  for(long long i=b-2; i<=smaller; i++){
    if(s.at(i) == '.'){
      count++;
      if(count == 3) {
        overtake=true;
        break;
      }
    }else{
      count=0;
    }
  }
  
  int position1=a-1;
  int position2=b-1;
  
  while(1){
    if(s.at(position1+1) == '.'){
      position1++;
    }else{
      if(s.at(position1+2) =='.'){
        position1 += 2;
      }else{
        break;
      }
    }
    
    if(position1 == c-1) {
      can1 = true;
      break;
    }
  }
  
  while(1){
    if(s.at(position2+1) == '.'){
      position2++;
    }else{
      if(s.at(position2+2) =='.'){
        position2 += 2;
      }else{
        break;
      }
    }
    
    if(position2 == d-1) {
      can2 = true;
      break;
    }
  }
  
  if(can1 == true && can2 == true){
    if(c<d){
      answer = true;
    }else if(c>d){
      if(overtake == true){
        answer = true;
      }
    }
  }
  
  if(answer == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

struct BC {
    int B, C;
    BC(int b, int c) { B = b; C = c;}
    bool operator<(const BC &another) const {
        return C > another.C;
    }
};

int main() {
    int N, M;
    vector<int> A;
    vector<BC> v;

    cin >> N >> M;

    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    for (int i = 0; i < M; ++i) {
        int B, C;
        cin >> B >> C;
        v.push_back(BC(B, C));
    }

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

    long long sum = 0;
    int itr = 0;
    for (auto i : v) {
        int begin = itr;
        int end = itr + i.B;
        for (int j = begin; j < end && j < A.size(); ++j) {
            if (A[j] < i.C) {
                sum += i.C;
                itr++;
            }
            else {
                break;
            }
        }
    }

    for (int i = itr; i < A.size(); ++i) {
        sum += A[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 1784