akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef  long double ll;
#define fr(i,a,b) for(long long i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
int main()
{
    fast;
   ll t;
   t=1;
   while(t--)
   {
       long long n,x=0,k;
       std::cin >> n>>k;
       ll a[n],maxi=0,sum;
       fr(i,0,n)
       std::cin >> a[i];
       fr(i,0,k)
       maxi+=((a[i]+1)/2);
       sum=maxi;
       fr(i,k,n)
       {
           sum=sum-((a[i-k]+1)/2)+(a[i]+1)/2;
           maxi=max(maxi,sum);
       }
       cout<<fixed;
       cout<<setprecision(12);
       cout<<maxi<<"\n";
       
   }
}

Measured memory_bytes: 6900
#include <cstdio>
#include <cstring>
typedef long long ll;
#define ri register int
const int N=3e5+5,mod=1e9+7;
char s[N];
int f[N][6],power[N],cnt[N];
inline int _add(ri x,ri y){
	return (x+=y)>=mod?x-mod:x;
}
int main(){
	ri n,i,ans;
	scanf("%s",s+1);
	n=strlen(s+1);
	power[0]=1;
	for(i=1;i<=n;++i) power[i]=power[i-1]*2ll%mod;
	for(i=n;i;--i) cnt[i]=cnt[i+1]+(s[i]=='?');
	/*
	0 empty
	1 0
	2 1
	3 00
	4 10
	5 100
	
	000 -> 0
	11 -> win
	10/01 -> empty
	*/
	ans=0;
	f[0][0]=1;
	for(i=1;i<=n;++i){
		if(s[i]=='0')
			// empty + 0 -> 0
			// 0 + 0 -> 00
			// 1 + 0 -> 10
			// 00 + 0 -> 0
			// 10 + 0 -> 100
			// 100 + 0 -> 10
			f[i][1]=_add(f[i-1][0],f[i-1][3]),
			f[i][3]=f[i-1][1],
			f[i][4]=_add(f[i-1][2],f[i-1][5]),
			f[i][5]=f[i-1][4];
		else if(s[i]=='1')
			// empty + 1 -> 1
			// 0 + 1 -> empty
			// 1 + 1 -> win
			// 00 + 1 -> 0
			// 10 + 1 -> 1
			// 100 + 1 -> 10
			f[i][0]=f[i-1][1],
			f[i][1]=f[i-1][3],
			f[i][2]=_add(f[i-1][0],f[i-1][4]),
			f[i][4]=f[i-1][5],
			ans=(ans+(ll)f[i-1][2]*power[cnt[i+1]])%mod;
		else
			f[i][0]=f[i-1][1],
			f[i][1]=_add(f[i-1][0],_add(f[i-1][3],f[i-1][3])),
			f[i][2]=_add(f[i-1][0],f[i-1][4]),
			f[i][3]=f[i-1][1],
			f[i][4]=_add(f[i-1][2],_add(f[i-1][5],f[i-1][5])),
			f[i][5]=f[i-1][4],
			ans=(ans+(ll)f[i-1][2]*power[cnt[i+1]])%mod;
	}
	ans=(ans+f[n][2])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
# define M_PI          3.141592653589793238
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,b,c,d=0;
    cin>>a>>b;
    for(int i=0; i<b; i++)
    {
        cin>>c;
        d+=c;
    }
    if(d>a)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<abs(a-d)<<endl;
    }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	vector<int> V;
	rep1(i, N) {
		int b;
		cin >> b;
		V.pb(b);
	}
	int kotae[101];
	for (int i = N; i > 0; i--) {
		int OK = 0;
		for (int j = i; j > 0; j--) {
			if (V[j - 1] == j) {
				kotae[i] = j;
				OK = 1;
				V.erase(V.begin() + j - 1);
				break;
			}
			else if(V[j - 1] > j){
				break;
			}
		}
		if (OK == 0) {
			co(-1);
			return 0;
		}
	}
	rep1(i, N) co(kotae[i]);

	Would you please return 0;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto k = lread();
    auto q = new DList!long(iota(1, 10).array());
    foreach (_; iota(k - 1))
    {
        auto t = q.front();
        q.removeFront();
        auto res = t % 10;
        if (res)
            q.insertBack(10 * t + res - 1);

        q.insertBack(10 * t + res);

        if (res < 9)
            q.insertBack(10 * t + res + 1);
    }
    q.front.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 11132
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long A,B,C,num=0;
  cin >> A >> B >> C;
  while((A%2==0) && (B%2==0) && (C%2==0)){
    num++;
    long long x,y,z;
    x=A;
    y=B;
    z=C;
    A = (y+z)/2;
    B = (x+z)/2;
    C = (x+y)/2;
    if(A==B && B==C){
      num = -1;
      break;
    }
  }
  cout << num << endl;
  return 0;
}
  

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        sc.close();
        if (a>=b && a>=c) {
            System.out.println((int)(a*Math.pow(2,k)+b+c));
        }else if (b>=a && b>=c) {
            System.out.println((int)(b*Math.pow(2,k)+a+c));
        }else {
            System.out.println((int)(c*Math.pow(2,k)+a+b));
        }
    }
}

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

int main() {

  int a;
  int b;
  int c;

  std::cin >> a >> b >> c;
  std::vector<int> bell{a, b, c};

  std::sort(bell.begin(), bell.end());
  std::cout << bell[0] + bell[1] << std::endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
dic = [0]*N
dist = [[0]*N for i in range(N)]
for i in range(N):
  dic[i] = [int(c) for c in input().split()]
  for j in range(N):
    dist[i][j] = dic[i][j]
  dic[i][i] = float('inf')

ans = 0
for i in range(N):
  for j in range(i):
    d = min(a+b for a, b in zip(dic[i],dic[j]))
    if d<dic[i][j]:
      print(-1)
      exit()
    elif d>dic[i][j]:
      ans += dic[i][j]
print(ans)

Measured memory_bytes: 7412
s = list(input())
n = len(s)
tempa = []
tempb = []
for i in range(n):
    if i%2 == 0:
        tempa.append("0")
        tempb.append("1")
    else:
        tempa.append("1")
        tempb.append("0")
    
countera = 0
counterb = 0
for i in range(n):
    if s[i] != tempa[i]:
        countera += 1
    if s[i] != tempb[i]:
        counterb += 1
print(min(countera,counterb))

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

using namespace std;

int main()
{
    int res = 0, a;
    for (int i = 0; i < 2; i++) {
        int sum = 0;
        for (int j = 0; j < 4; j++) {
            cin >> a;
            sum += a;
        }
        res = max(res, sum);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    int x, y;
    cin >> x >> y;
    rep(i, x+1){
        if(y == 2*i+4*(x-i)){
            out("Yes");
            return;
        }
    }
    out("No");
}
int main() {
    INCANT;
    solve();
    return 0;
}




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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double
#define DUMP(v) "," #v ":" << v


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

  ll ans = 0;
  rep(i,s.size()){
    ans += s[i] - '0';
  }
  cout << ((ans % 9 == 0) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3752
#include <iostream>
using namespace std;
int s[6];
int c[6];
int z[4]={0,0,0,0};
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;++i){
    cin>>s[i]>>c[i];
  }
  int ans=0;
  for(int i=0;i<m;++i){
    if(n!=1&&s[i]==1&&c[i]==0){
      ans+=1;
      cout<<-1;
    }
    for(int j=0;j<m;++j){
      if(s[i]==s[j]&&ans==0){
        if(c[i]!=c[j]&&ans==0){
          cout<<-1;
          ans+=1;
        }
      }
    }
  }
  if(ans==0){
    for(int i=0;i<m;++i){
      z[s[i]-1]=c[i];
    }
    if(z[0]==0&&n!=1) z[0]=1;
    for(int i=0;i<n;++i){
      cout<<z[i];
    }
  }
}
    


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

using namespace std;
typedef long long ll;

ll n,q;
ll a[100005];
ll x[100005];
ll sum[100005];
ll ta[100005];
map<ll,ll> ans;

int main() {
  cin >> n >> q;
  int j = 0;
  if(n & 1) {
    j++;
    n++;
  }
  
  for(; j < n; j++) cin >> a[j];
  for(int i = 0; i < q; i++) cin >> x[i];

  if(n == 2) {
    for(int i = 0; i < q; i++) {
      cout << a[1] << endl;
    }
    return 0;
  }
  
  sum[0] = a[0];
  for(int i = 1; i < n; i++) sum[i] = sum[i-1] + a[i];
  ta[1] = a[1];
  for(int i = 3; i < n; i+=2) ta[i] = ta[i-2] + a[i];

  //for(int i = 0; i < n; i++) cout << sum[i]<<"  ";
  //cout << endl;
  // for(int i = 0; i < n; i++) cout << ta[i] <<"   ";
  //cout << endl;
			      

  for(int i = n - 2; i >= n/2; i--) {
    int tmp = (a[i] + a[2*i-n+1]) / 2;
    tmp++;
    ll T = sum[n-1] - sum[i] + ta[2*i-n+1];
    ans[tmp] = T;
  }
  ans[0] = sum[n-1] - sum[(n-1)/2];

  /* for(auto itr = ans.begin(); itr != ans.end(); ++itr) {
    cout << itr->first <<"   "<<itr->second << endl;
    }*/

  for(int i = 0; i < q; i++) {
    auto itr = ans.upper_bound(x[i]);
    itr--;
    cout << itr->second << endl;
  }
}


Measured memory_bytes: 8064
S = input()

if S == 'RRR':
    print(3)
elif S == 'SRR' or S =='RRS':
    print(2)
elif S =='SRS' or S == 'RSR' or S == 'SSR' or S == 'RSS':
    print(1)
elif S == 'SSS':
    print(0)

Measured memory_bytes: 61800
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1; i<=n; i++)
int main(){
    rep(i,9){
        rep(j,9){
            cout << i << 'x' << j << '=' << i*j << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3068
import java.util.*;

class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        String N = scanner.next();
        int K = scanner.nextInt();
        int L = N.length();

        long[] D = new long[L];
        for(int i=0;i<L;i++) D[i] = (long)Character.getNumericValue(N.charAt(i));

        long R = 0;
        int i=0;
        while(K>0 && L>i){
            if(K > L-i) break;

            if(K == 1){
                if(D[i] != 0){
                    R += D[i];
                    R += 9L * (L-(long)i-1L);
                    K--;
                }
            } else if(K == 2){
                if(D[i] != 0){
                    R += (D[i]-1L) * 9L * (L-(long)i-1L);
                    R += 81L * (L-(long)i-1L) * (L-(long)i-2L) /2L;
                    K--;
                }
            } else {
                R += (D[0]-1L) * 81L * (L-1L) * (L-2L) / 2L;
                R += 729L * (L-1L) * (L-2L) * (L-3L) / 6L;
                K--;
            }

            i++;
        }

        System.out.println(R);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>
using namespace std;
int main(void){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  cout<<(H-h)*(W-w);
  return 0;
}


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

template <typename T>
class LazySegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id1, id2;
	func_t merge;
	func_t change;
	vector<T> data, lazy;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	void propa(int node) {
		if (lazy[node] == id2) return;
		if (node < n) {
			lazy[node * 2] = change(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = change(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = change(data[node], lazy[node]);
		lazy[node] = id2;
	}
	void suc(int l, int r, int node, int lb, int ub, T val) {
		if (ub <= l || r <= lb) return;
		propa(node);
		if (l <= lb && ub <= r) {
			lazy[node] = val;
			return;
		}
		int c = (lb + ub) / 2;
		suc(l, r, node * 2, lb, c, val);
		suc(l, r, node * 2 + 1, c, ub, val);
		data[node] = merge(change(data[node * 2], lazy[node * 2]), change(data[node * 2 + 1], lazy[node * 2 + 1]));
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id1;
		propa(node);
		if (l <= lb && ub <= r) {
			return data[node];
		}
		int c = (lb + ub) / 2;
		return merge(sub(l, r, node * 2, lb, c), sub(l, r, node * 2 + 1, c, ub));
	}
public:
	LazySegmentTree(int n_, T id1_, T id2_, func_t merge_, func_t change_)
		: n(size(n_)), id1(id1_), id2(id2_), merge(merge_), change(change_), data(n * 2, id1), lazy(n * 2, id2) {}
	void update(int l, int r, T val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int n, q, com, s, t, x;
	cin >> n >> q;
	LazySegmentTree<int> lst(n, INT_MAX, -1, [](int l, int r) { return min(l, r); }, [](int l, int r) { return r != -1 ? r : l; });
	while (q--) {
		cin >> com;
		if (com) {
			cin >> s >> t;
			printf("%d\n", lst.find(s, t));
		}
		else {
			cin >> s >> t >> x;
			lst.update(s, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 4964
import heapq
def dijkstra_heap():
    used = [-1] * (2451*n)
    edgelist=[]
    heapq.heappush(edgelist,[0,ss])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if used[minedge[1]]!=-1:
            continue
        v = minedge[1]
        kai=minedge[0]
        mai=v%2451
        used[v] = kai
        for e in edge[v//2451]:
            if mai-e[1]>=0:
                sss=mai-e[1]
                if used[e[2]*2451+sss]==-1:
                    heapq.heappush(edgelist,[e[0]+kai,e[2]*2451+sss])
        if mai+cd[v//2451][0]<=2450:
            if used[v+cd[v//2451][0]]==-1:
                heapq.heappush(edgelist,[kai+cd[v//2451][1],v+cd[v//2451][0]])
    return used

################################
n,m,ss = map(int,input().split())
ss=min(2450,ss)
edge = [[] for i in range(n)]

for i in range(m):
    x,y,a,b = map(int,input().split())
    edge[x-1].append([b,a,y-1])
    edge[y-1].append([b,a,x-1])
cd=[]
for i in range(n):
    cd.append(list(map(int,input().split())))
pp=dijkstra_heap()
for i in range(1,n):
    ans=10**20
    for j in range(2451):
        if pp[i*2451+j]!=-1:
            ans=min(ans,pp[i*2451+j])
    print(ans)

Measured memory_bytes: 37892
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

int x[(int)1e5];
int main() {
	int N,K;
	cin >> N >> K;
	for(int i=0;i<N;i++){
		cin >> x[i];
	}
	int ret=1e9;
	for(int i=0;i+K<=N;i++){
		int j=i+K-1;
		if(x[i]<0&&x[j]>0){
			ret=min(ret,2*abs(x[j])+abs(x[i]));
			ret=min(ret,2*abs(x[i])+abs(x[j]));
		}
		else{
			ret=min(ret,max(abs(x[i]),abs(x[j])));
		}
	}
	cout << ret << endl;

	return 0;
}



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



int main() {
    int i, N, judge=0, count=0;
    ll A[200];
    
    cin >> N;
    for(i=0; i<N;i++) cin >> A[i];
    
    for(;judge==0;count++){
        for (i = 0; i < N; i++) {
            if(A[i]%2==0) A[i]/=2;
            else {
                judge =1;
                break;
            }
        }
    }
    cout << count-1 << endl;
}

Measured memory_bytes: 3632
import bisect,collections,copy,heapq,itertools,math,string
import sys
import random
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
d = I()
c_l = LI()
s_l = [LI() for _ in range(d)]
for i in range(d):
    print(random.randint(1, 26))

Measured memory_bytes: 77808
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

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(nullptr);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    auto mp = make_v(H + 2, W + 2, '#');
    REP(i, 1, H + 1) {
        REP(j, 1, W + 1) {
            cin >> mp[i][j];
        }
    }
    auto mp1 = make_v(H + 2, W + 2, 0);
    REP(i, 0, H + 2) {
        int s = 0;
        REP(j, 0, W + 2) {
            mp1[i][j] = s;
            if (mp[i][j] == '.')
                s++;
            else
                s = 0;
        }
    }

    auto mp2 = make_v(H + 2, W + 2, 0);
    REP(i, 0, H + 2) {
        int s = 0;
        for (int j = W + 1; j >= 0; j--) {
            mp2[i][j] = s;
            if (mp[i][j] == '.')
                s++;
            else
                s = 0;
        }
    }

    auto mp3 = make_v(H + 2, W + 2, 0);
    REP(j, 0, W + 2) {
        int s = 0;
        REP(i, 0, H + 2) {
            mp3[i][j] = s;
            if (mp[i][j] == '.')
                s++;
            else
                s = 0;
        }
    }
    auto mp4 = make_v(H + 2, W + 2, 0);
    REP(j, 0, W + 2) {
        int s = 0;
        for (int i = H + 1; i >= 0; i--) {
            mp4[i][j] = s;
            if (mp[i][j] == '.')
                s++;
            else
                s = 0;
        }
    }
    int ans = 0;
    REP(i, 0, H + 2) {
        REP(j, 0, W + 2) {
            if (mp[i][j] == '#') continue;
            int tmp = (mp[i][j] == '.') + mp1[i][j] + mp2[i][j] + mp3[i][j] + mp4[i][j];
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 67200
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 5005
#define ll long long
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
struct Zab{
	int h,p,s;
	inline bool operator<(const Zab&a)const{return s<a.s;}
}a[N];
int n,ans;
ll f[N][N];
int main(void){
	register int i,j;
	n=read();
	for(i=1;i<=n;++i)
		a[i].h=read(),a[i].p=read(),a[i].s=a[i].h+a[i].p;
	sort(a+1,a+n+1);
	for(i=1;i<=n;++i)
		for(j=n;j;--j){
			if((f[i-1][j-1]^(j==1))&&f[i-1][j-1]<=a[i].h)
				f[i][j]=(f[i][j]==0?f[i-1][j-1]+a[i].p:min(f[i][j],f[i-1][j-1]+a[i].p)),ans=max(ans,(bool)f[i][j]*j);
			if(f[i-1][j])f[i][j]=min(f[i][j],f[i-1][j]);
			if(!f[i][j])f[i][j]=f[i-1][j];
		}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 195712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

public class Main {

	static BufferedReader reader;
	final static boolean MODE_DEBUG = false;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		int X = readLineInt()[0];
		if(X==1) {print("1 0");return;}
		Integer[] yaku = getYaku(X);
		for(long p : yaku) {
			long val1 = X/p-p*p*p*p;
			if(val1%5!=0) {
				continue;
			}
			val1/=5;
			Integer[] yaku2 = getYaku((int)(Math.abs(val1)));
			for(long a : yaku2) {
				if(a*(a*a*a-2*p*a*a+2*p*p*a-p*p*p)==val1) {
					print(a+" "+(a-p));
					return;
				}
			}
		}
	}
	
	//functions here
	//note that all methods should be STATIC
	private static Integer[] getYaku(int x) {
		int max = (int)Math.ceil(Math.sqrt(x));
		HashSet<Integer> yakus = new HashSet<Integer>();
		for(int i=1;i<=max;i++) {
			if(x%i==0) {
				yakus.add(i);
				yakus.add(x/i);
			}
		}
		return yakus.toArray(new Integer[yakus.size()]);
	}

	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static int[] sort(int[] base) {
		int[] copy = array_copy(base);
		Arrays.sort(copy);
		return copy;
	}
	private static int[] array_copy(int[] base) {
		int[] copy = new int[base.length];
		for(int i=0;i<base.length;i++) {
			copy[i] = base[i];
		}
		return copy;
	}
	private static int[] asArray(ArrayList<Integer> ints) {
		int[] intlist = new int[ints.size()];
		for(int i=0;i<intlist.length;i++) {
			intlist[i] = ints.get(i);
		}
		return intlist;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}


Measured memory_bytes: 36704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  
  for(int i=0; i<N; i++){
    cin >>d.at(i);
  }
  
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  
  int count =1;
  int presentD = d.at(0); 
  for(int i=1;i<N;i++){
    if(d.at(i) < presentD) {
      presentD = d.at(i);
      count++;
    }
    
  }
  cout << count << endl;
  
}

Measured memory_bytes: 256
var
 i,n,len:longint;
 s:string;
 heap:array[0..202] of string;
procedure put(x:string);
var son:longint;
   t:string;
begin
    len:=len+1;
    heap[len]:=x;
    son:=len;
    while(son<>1)and(heap[son div 2]>heap[son])do
        begin
            t:=heap[son div 2];
            heap[son div 2]:=heap[son];
            heap[son]:=t;
            son:=son div 2;
        end;
end;
function get:string;
var fa,son:longint;
    s:boolean;
    t:string;
begin
    get:=heap[1];
    heap[1]:=heap[len];
    len:=len-1;
    fa:=1;
    s:=false;
    while((fa*2<=len)or(fa*2+1<=len))and(not s)do
        begin
            if(fa*2+1>len)or(heap[fa*2]<heap[fa*2+1])
                then son:=fa*2 else son:=fa*2+1;
            if heap[fa]>heap[son]then
                begin
                    t:=heap[fa];
                    heap[fa]:=heap[son];
                    heap[son]:=t;
                    fa:=son;
                end
            else s:=true;
        end;
end;
begin
 readln(n);
  for i:=1 to n do
    begin
     readln(s);
     put(s);
    end;
  for i:=1 to n do write(get);
end.


Measured memory_bytes: 128
// This code Write By chtholly_micromaker(MicroMaker)
#include <cstdio>
#include <cctype>
#define int long long
#define reg register
using namespace std;
const int MaxN=100051;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
int a[MaxN];
signed main(void)
{
	int n;rd(n);
	reg bool flg=false;
	for(int i=1;i<=n;++i)
		rd(a[i]);
	for(int i=1;i<n;++i)
	{
		if(a[i]>a[i+1])
		{
			if(flg)
				return puts("No"),0;
			--a[i];
			flg=true;
			if(a[i]>a[i+1])
				return puts("No"),0;
		}
		else if(a[i]<a[i+1])
			flg=false;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 896
N, M = map(int, input().split())
A = [0]*N
for i in range(N):
  A[i] = [0,0]
  A[i][0],A[i][1] = map(int, input().split())
A.sort()
sum = 0
for a in A:
  if a[1]<M:
    sum += a[0]*a[1]
    M -= a[1]
  else:
    sum += a[0]*M
    print(sum)
    exit()



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

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

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

ll t, a, b, n;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> t;
	a = t * 4;
	b = t * 8;
	cin >> t;
	a = min(t * 2, a);
	b = min(t * 4, b);
	cin >> t;
	a = min(t, a);
	b = min(t * 2, b);
	cin >> t;
	b = min(b, t);
	cin >> n;
	if (a * 2 <= b)
		cout << a * n << endl;
	else
		cout << a * (n % 2) + b * (n / 2) << endl;
	return 0;
}


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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
template<class T> struct Fenwick {
    int n;
    T* d;
    Fenwick() : n(0), d(NULL) {}
    Fenwick(int n_) : n(n_) {
	d = new T[n_]();
    }
    Fenwick(const Fenwick &y) : n(y.n) {
	d = new T[n];
	memcpy(d, y.d, sizeof (T) * n);
    }
    ~Fenwick() {
	delete[] d; d = NULL;
	n = 0;
    }
    friend void swap(Fenwick &x, Fenwick &y) {
	swap(x.n, y.n); swap(x.d, y.d);
    }
    Fenwick& operator=(Fenwick y) {
	swap(*this, y);
	return *this;
    }
    inline void add(int i, const T &x) {
	for (; i<n; i|=i+1) d[i] += x;
    }
    inline T sum(int r) {
	T s = T();
	for (; r; r&=r-1) s += d[r-1];
	return s;
    }
    T sum(int l, int r) {
	return sum(r) - sum(l);
    }
};

int N;
char S[200011];
VI G[26], R[26];
int C[26];

void MAIN() {
    scanf("%s", S);
    N = strlen(S);
    REP (i, N) C[S[i]-'a']++;
    int cnt = 0;
    REP (t, 26) if (C[t] % 2) cnt++;
    if (cnt > 1) {
	puts("-1");
	return;
    }

    REP (i, N) {
	int c = S[i]-'a';
	G[c].push_back(i);
    }
    REP (c, 26) reverse(G[c].begin(), G[c].end());

    Fenwick<int> F(N);
    LL ans = 0;
    for (int i=N; i--; ) {
	int c = S[i]-'a';
	int a = G[c].back(); G[c].pop_back();
	ans += F.sum(a, N);
	F.add(a, 1);
    }
    
    printf("%lld\n", ans/2);
    eprintf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 2296
let s' = read_line ()
let t = read_line ()
let n, m, u, f = String.(length s', length t, ref "", map (function '?' -> 'a' | c -> c))
let _ = String.(for i = n - m downto 0 do let b = ref true in u := init m (fun j -> match s'.[i + j] with '?' -> t.[j] | c -> if c <> t.[j] then b := false; c);
  if !b then (print_endline @@ (f @@ sub s' 0 i) ^ !u ^ (f @@ sub s' (i + m) @@ n - i - m); exit 0) done); print_endline "UNRESTORABLE"

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

int main (){
    
    int N,M;
    cin >> N >> M;
    vector<vector<int>> S(M,vector<int>(N+1,0));
    
    for(int i=0;i<M;i++){
        int j;
        cin >> j;
        for(int k=0;k<j;k++)cin >> S[i][k];
    }
    vector<int> P(M,0);
    
    for(int i=0;i<M;i++)cin >> P[i];
    
    int count0=0;
    
    for(int i=0;i<1<<N;i++){
        
        int count1=0;
        for(int l=0;l<M;l++){
            int count2=0;
            for(int j=0;S[l][j]!=0;j++){
                count2+=((1<<(S[l][j]-1)&i)!=0);
            }
            if(count2%2!=P[l])break;
            count1+=(count2%2==P[l]);
        }
        count0+=(count1==M);
    }
    cout << count0 << endl;
    
}


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

int main(){

    int s,i;
    int a[1000]={};
    i = 0;
    cin >> s;
    
    while(1){
        if(s%2 == 0){
            a[i] = s;
            s = s/2;
        }else if(s%2 == 1){
            a[i] = s; 
            s = 3*s + 1;
        }
        for(int j = 0;j<i;j++){
            if(a[j] == s){
                cout << i+2 << endl;
                return 0;
            }
        }
        i++;

    }

    


}




Measured memory_bytes: 384
n = int(input())
P = list(map(int, input().split()))
P = [p-1 for p in P]

A=  list(range(1, n+1))
B = list(reversed(range(1, n+1)))

C = [0]*(n+1)
D = [0]*(n+1)
for i in range(n):
    p = P[i]
    C[p] += i+1
    C[n] -= i+1
    D[0] += i+1
    D[p+1] -= i+1
from itertools import accumulate
C = list(accumulate(C))
D = list(accumulate(D))

A_ = [0]*n
B_ = [0]*n
for i in range(n):
    A_[i] = A[i] + C[i]
    B_[i] = B[i] + D[i]

print(*A_)
print(*B_)

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

int main() {
    long long a,b,c,d,n;
    cin >> n;
    a = n*(n+1);
    b = n/15;
    c = n/3;
    d = n/5;
    a = a - c*(3+c*3) - d*(5+5*d) + b*(15+b*15);
    a = a/2;
    cout << a << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = NextInt();
        int K = NextInt();
        if (N % 2 == 1) N++;
        Console.WriteLine((N < K*2?"NO":"YES"));
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

double f(double K, double i, double n) {
    if(K <= i) {
        return n;
    }
    n++;
    f(K, i * 2, n);
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    double N;
    double K;
    cin >> N >> K;
    double ans;
    for(double i = N; i >= 1; i--) {
        double tmp;
        double cl = f(K, i, 0);
        tmp = (1.0 / N) * pow(1.0 / 2.0, cl);
        ans += tmp;
    }

    printf("%.12f\n", ans);
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    vector<LL> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];

    }
    sort(all(v), greater<LL>());
    LL h, w;
    h = w = -1;
    int c = 0;
    for(int i = 0; i < n - 1; ++i) {
        if(v[i] == v[i + 1]) {
            if(c == 0) {
                h = v[i];

            } else {
                w = v[i];

            }
            ++i;
            ++c;
        }
        if(c == 2) {
            cout << h * w << endl;
            return 0;

        }
    }

    cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int N, W;
    cin >> N >> W;
    vl w(N), v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }
    vvl dp(N + 1, vl(W + 1, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j + w[i] <= W) {
                chmax(dp[i + 1][j], dp[i][j]);
                chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
            } else {
                chmax(dp[i + 1][j], dp[i][j]);
            }
        }
    }
    cout << dp[N][W] << "\n";
    return 0;
}

Measured memory_bytes: 80256
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <vector>
#include <string>

using namespace std;

int a[100050];
int INF = 1e9 + 3;
int n, m;

int gcd(int a, int b) {
    return a ? gcd(b % a, a) : b;
}

int lca(int a, int b) {
    if (a > INF || b > INF) {
        return INF;
    }
    int x = gcd(a, b);
    long long P = a * 1ll * b / x;
    if (P > INF) {
        return INF;
    }
    return (int)P;
}

void solution() {
    cin >> n >> m >> a[0];
    int st = a[0] / 2;
    int mp = a[0];
    for (int i = 1; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i < n; i++) {
        int k2 = a[i] / 2;
        int p2 = a[i];
        if (st > k2) {
            swap(st, k2);
            swap(mp, p2);
        }
        if (st == k2) {
            continue;
        }
        int s1 = st, s2 = k2;
        int gg = 10 + 2 * min(mp, k2);
        while (s1 != s2 && s1 < INF && s2 < INF && --gg) {
            int dif = abs(s2 - s1) - 1;
            if (s1 < s2) {
                s1 += dif / mp * mp + mp;
            } else {
                s2 += dif / k2 * k2 + k2;
            }
        }
        if (s1 != s2) {
            cout << "0" << endl;
            return;
        }
        st = s1;
        mp = lca(mp, p2);
    }
    int ans = (m - st) / mp;
    if (m >= st) {
        ans++;
    }
    cout << ans << endl;
}

void solution2() {
    cout << "RIGHT ANSWER:" << endl;
    int ans = 0;
    for (int k = 1; k <= m; k++) {
        bool f = true;
        for (int i = 0; i < n; i++) {
            int j = k - a[i] / 2;
            if (j % a[i]) {
                f = false;
            }
        }
        if (f) {
            ans++;
        }
    }
    cout << ans << endl;
}

/*-------------------*/

int main()
{
#ifdef Files
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    /*Test*/
    //freopen("input.txt", "w", stdout);

    double OcZ2X = clock();
#else
    //freopen("joke.in", "r", stdin);
    //freopen("joke.out", "w", stdout);
#endif

    solution();
    //solution2();

#ifdef Time
    double P2HxQ = clock();
    printf("\n*** Total time = %.3f sec ***\n", (P2HxQ - OcZ2X) / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 640
using System;
using System.Numerics;

namespace ABC054B
{
    static class Program
    {
        static void Main()
        {
            BigInteger n = BigInteger.Parse(Console.ReadLine());
            BigInteger power = 1;
            BigInteger mod = BigInteger.Pow(10, 9) + 7;
            
            for(int i = 1; i < n + 1; i++)
                power = (power * i) % mod;

            Console.WriteLine(power);
        }
    }
}

Measured memory_bytes: 15572
#include<bits/stdc++.h>
#define ll long long 
#define inf 1000000007
using namespace std;
void make_fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int main(){
    make_fast();
	vector<ll>fact(10000005,0);
	for(ll i=1;i<=10000005;i++){
	    for(ll j=i;j<=10000005;j+=i){
	        fact[j]++;
	    }
	}
	for(ll i=2;i<=10000005;i++){
	    fact[i]=fact[i-1]+(i*fact[i]);
	}
	int n;
	cin>>n;cout<<fact[n]<<endl;
}
	   


Measured memory_bytes: 81220
n=int(input())

A = list(map(int, input().split()))
l = [0] * len(A)

ans=0

for i in range(n-1):
  if A[i]>=A[i+1]:
    l[i+1]=A[i]-A[i+1]
    A[i+1]=A[i]
  else:
    l[i+1]=0
  ans=ans+l[i+1]  
print(ans)  


Measured memory_bytes: 32124
from collections import deque
S = deque(input())
Q = int(input())
query = [input().split() for _ in range(Q)]
reverse = False
for q in query:
    if q[0] == '1':
        reverse = not reverse
    else:
        if q[1] == '1':
            S.append(q[2]) if reverse else S.appendleft(q[2])
        else:
            S.appendleft(q[2]) if reverse else S.append(q[2])
if reverse:
    S.reverse()
print(''.join(S))

Measured memory_bytes: 44660
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        final int MAX = 100001;
        boolean[] prime = new boolean[MAX];
        Arrays.fill(prime, true);
        prime[0] = false;
        prime[1] = false;
        
        for(int i=2; i<MAX; i++){
            for(int j=2; j*j<=i; j++){
                if(i%j==0){
                    prime[i] = false;
                    break;
                }
            }
        }
        
        boolean[] likeNum = new boolean[MAX];
        Arrays.fill(likeNum, false);
        
        for(int i=1; i<MAX; i+=2){
            if(prime[i] && prime[(i+1)/2]){
                likeNum[i] = true;
            }
        }
        
        int[] likeNumRui = new int[MAX];
        int sum = 0;
        for(int i=0; i<MAX; i++){
            if(likeNum[i]){
                sum++;
            }
            likeNumRui[i] = sum;
        }
        
        int q = sc.nextInt();
        for(int i=0; i<q; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int ans = likeNumRui[r] - likeNumRui[l-1];
            
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 74456
function main(arg) {
    var size = arg.split("\n")[0].split(" ")
    var sel = arg.split("\n")[1].split(" ")
    console.log(size[0]*size[1]-size[1]*sel[0]-(size[0]-sel[0])*sel[1])
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <cassert>
// #include <algorithm>
#include <iostream>
#include <vector>
#include <climits>

struct TSize
{
    int r;
    int c;
    TSize() : r(0), c(0) {}
    TSize(int Ar, int Ac)
     : r(Ar), c(Ac)
    {}
};

class TMcmSolver
{
    typedef std::vector<std::vector<int> > TMatrix;
    TMatrix FMemo;
    const std::vector<TSize>& FChain;

    static int Count(const TSize& Left, const TSize& Right)
    {
        return Left.r * Right.c * Left.c;
    }
    int Solve(int s, int l)
    {
        assert(s <= l);
        if(s == l) return 0;
        if(FMemo[s][l] != 0) return FMemo[s][l];
        if(s + 1 == l){
            FMemo[s][l] = Count(FChain[s], FChain[l]);
        }else{
            int min = INT_MAX;
            for(int i = s+1; i < l; ++i){
                int c = Solve(s, i) + Count(TSize(FChain[s].r, FChain[i].c), TSize(FChain[i+1].r, FChain[l].c)) + Solve(i+1, l);
                min = std::min(min, c);
            }
            FMemo[s][l] = min;
        }
        return FMemo[s][l];
    }
public:
    TMcmSolver(const std::vector<TSize>& Chain)
     : FChain(Chain)
    {
        FMemo.resize(Chain.size());
        for(std::size_t i = 0; i < FMemo.size(); ++i){
            FMemo[i].resize(Chain.size(), 0);
        }
    }
    int Answer()
    {
        return Solve(0, FMemo.size()-1);
    }
    void Print()const
    {
        for(std::size_t s = 0; s < FMemo.size(); ++s){
            for(std::size_t l = 0; l < FMemo[0].size(); ++l){
                std::cout << FMemo[s][l] << '\t';
            }
            std::cout << '\n';
        }
    }
};

int main()
{
    int n;
    std::cin >> n;
    if(n == 1){
        std::cout << 0 << std::endl;
        return 0;
    }
    std::vector<TSize> Chain(n);
    for(int i = 0; i < n; ++i){
        std::cin >> Chain[i].r >> Chain[i].c;
    }
    TMcmSolver Solver(Chain);
    
    std::cout << Solver.Answer() << std::endl;
    // Solver.Print();
    return 0;
}

Measured memory_bytes: 3120
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct t_cell {
	int x;
	int y;
	char color;
	int num;
} a_cell;

int min(int x, int y)
{
	if (x > y)
		return (y);
	else 
		return (x);
}
int	main(void)
{
	int H,W;

	scanf("%d %d", &H, &W);
	
	struct t_cell cells[H][W];
	char str[H][W];
	int i =0;
	int j =0;
	while (i < H)
	{
		j =0;
		scanf("%s", str[i]);
		while (j<W)
		{
			cells[i][j].color = str[i][j];
			cells[i][j].x = i;
			cells[i][j].y = j;
			cells[i][j].num = (cells[i][j].color == '.')?(0):(1);
			//# is black . is white
			j++;
		}
		i++;
	}
	i =0;
	j =0;
	while (i <H)
	{
		j =0;
		while (j <W)
		{
			if (i ==0 && j ==0)
			{
				j++;
				continue;
			}
			else if (i ==0 && cells[i][j].color == '.')
				cells[i][j].num = cells[i][j-1].num;
			else if (i ==0 && cells[i][j-1].color == '#')
				cells[i][j].num = cells[i][j-1].num;
			else if (i ==0 && cells[i][j-1].color == '.')
				cells[i][j].num = cells[i][j-1].num + 1;
			else if (j ==0 && cells[i][j].color == '.')
				cells[i][j].num = cells[i-1][j].num;
			else if (j ==0 && cells[i-1][j].color == '#')
				cells[i][j].num = cells[i-1][j].num;
			else if (j ==0 && cells[i-1][j].color == '.')
				cells[i][j].num = cells[i-1][j].num + 1;
			else if (cells[i][j].color == '.')
				cells[i][j].num = min(cells[i-1][j].num,cells[i][j-1].num);
			else if (cells[i][j].color == '#' && cells[i-1][j].color =='#' && cells[i][j-1].color =='#')
				cells[i][j].num = min(cells[i-1][j].num,cells[i][j-1].num);
			else if (cells[i][j].color == '#' && cells[i-1][j].color =='#' && cells[i][j-1].color == '.')
				cells[i][j].num = min(cells[i-1][j].num,cells[i][j-1].num+1);
			else if (cells[i][j].color =='#' && cells[i-1][j].color == '.' && cells[i][j-1].color == '#')
				cells[i][j].num = min(cells[i-1][j].num+1,cells[i][j-1].num);
			else if (cells[i][j].color =='#' && cells[i-1][j].color == '.' && cells[i][j-1].color == '.')
				cells[i][j].num = min(cells[i-1][j].num,cells[i][j-1].num)+1;
			j++;
		}
		i++;
	}
	int r_num = cells[H-1][W-1].num;
	printf("%d\n",r_num);
	return(0);
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

typedef __uint128_t u128;

const u128 mod = 1e9 + 7;

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

    long long n;
    cin >> n;

    long long res = 0;
    for (int i = 1; i < n;++i){
        res += ((n-1) / i);
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
     
using namespace std;
typedef long long ll;
ll a[1000010];
ll b[1000010];
ll c[1000010];
int main()
{
   int a, b;
   while(~scanf("%d %d", &a, &b))
   {
   	   double d;
   	   int c = (a + b) / 2;
   	   d = (a + b) / 2.0;
   	   if((d - c) >= 0.5)
   	   	   printf("%d\n", c + 1);
   	   	else
   	   		printf("%d\n", c);
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <functional>

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> V;
  int v;
  int ans = 0;

  for(int i=0; i<N; i++){
    cin >> v;
    V.push_back(v);
  }
  int vsize = V.size();

  for(int a=0; a<=min(N,K); a++){
    for(int b=0; b<=min(N,K)-a; b++){
      int preans = 0;
      vector<int> minus;
      for(int i=0; i<a; i++){
        preans += V[i];
        if(V[i] < 0){
          minus.push_back(V[i]);
        }
      }
      for(int i=0; i<b; i++){
        preans += V[vsize-1-i];
        if(V[vsize-1-i] < 0){
          minus.push_back(V[vsize-1-i]);
        }
      }
      sort(minus.begin(), minus.end());
      for(int i=0; i<min(K-a-b, (int)minus.size()); i++){
        preans -= minus[i];
      }
      ans = max(ans,preans);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256