akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=1e5+10;
vector<int>v[maxn];
long long int dp[2][maxn];
//dp[0] for siah
//dp[1] for sefid
int n;
void dfs(int root,int par){
	dp[0][root]=1;
		dp[1][root]=1;
	for(int i=0;i<v[root].size();i++){
		if(par!=v[root][i]){
			dfs(v[root][i],root);
			dp[0][root]*=dp[1][v[root][i]];
			dp[1][root]*=(dp[1][v[root][i]]+dp[0][v[root][i]])%mod;
			dp[0][root]%=mod;
			dp[1][root]%=mod;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=0;i<n-1;i++){
    	int x;
    	int y;
    	cin>>x>>y;
    	v[x].emplace_back(y);
    	v[y].emplace_back(x);
	}
	dfs(1,-1);
	if(n==1){
		cout<<2;
		return 0;
	}
	cout<<(dp[1][1]+dp[0][1])%mod;
}

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

using namespace std;

int main(){
	long long W = 0, H = 0, x = 0, y = 0;
	
	cin >> W >> H >> x >> y;
	
	cout << W / 2.0 * H << " ";
	
	if(x <= W / 2 && y <= H / 2){
		if(2 * x == W && 2 * y == H){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}else{
		cout << 0 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn dfs(
    cur: usize,
    edges: &Vec<Vec<usize>>,
    tree: &mut Vec<HashSet<usize>>,
    used: &mut HashSet<usize>,
) {
    used.insert(cur);
    for &to in edges[cur].iter() {
        if used.contains(&to) {
            continue;
        }
        tree[cur].insert(to);
        dfs(to, edges, tree, used);
    }
}

fn dfs2(
    cur: usize,
    tree: &Vec<HashSet<usize>>,
    count: &Vec<i32>,
    pairs: &mut Vec<(usize, usize)>,
) -> bool {
    let mut remainder = count[cur] % 2 == 1;
    for &to in tree[cur].iter() {
        let ret = dfs2(to, tree, count, pairs);
        if ret {
            pairs.push((to, cur));
        } else {
            pairs.push((cur, to));
            remainder = !remainder;
        }
        // remainder ^= ret;
    }
    remainder
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut edges = vec![vec![]; n];
    let mut pairs = vec![];
    for i in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        edges[a].push(b);
        edges[b].push(a);
        pairs.push((a, b));
    }

    if m % 2 == 1 {
        println!("-1");
        return;
    }

    let mut tree = vec![HashSet::new(); n];
    let mut used = HashSet::new();
    dfs(0, &edges, &mut tree, &mut used);

    let mut counts = vec![0; n];

    let mut answers = vec![];
    for (a, b) in pairs {
        if tree[a].contains(&b) || tree[b].contains(&a) {
            continue;
        }
        answers.push((a, b));
        counts[a] += 1;
    }
    // debug!(tree);
    // debug!(answers);
    dfs2(0, &tree, &counts, &mut answers);
    for ans in answers {
        println!("{0} {1}", ans.0 + 1, ans.1 + 1);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 80892
K=int(input())
a,b=map(int,input().split())
if b-a+1>=K:
    print("OK")
else:
    s=0
    for i in range (a,b+1):
        if i%K==0:
            s=s+1
    if s==0:
        print("NG")
    else:
        print("OK")
 

Measured memory_bytes: 9176
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	string s,t;
	cin >> s;
	cin >> t;
	int array[26];
	rep(i,26){
		array[i]=-1;
	}

	rep(i,s.size()){
		int s_int,t_int;
		s_int=int(s[i]-'a');
		t_int=int(t[i]-'a');

		if(array[s_int]==-1 | array[s_int]==t_int){
			array[s_int]=t_int;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	rep(i,26){
		array[i]=-1;
	}
	rep(i,s.size()){
		int s_int,t_int;
		s_int=int(s[i]-'a');
		t_int=int(t[i]-'a');

		if(array[t_int]==-1 | array[t_int]==s_int){
			array[t_int]=s_int;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 776
q = int(input())


def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass


prime_list = primes(100000)
familiar = [0]*100001
for p in prime_list:
    if (p+1)//2 in prime_list:
        familiar[p] = 1
s = [0]*100001
for i in range(100000):
    s[i+1] = s[i] + familiar[i+1]


for _ in range(q):
    l, r = map(int, input().split())
    print(s[r]-s[l-1])

Measured memory_bytes: 56072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<long long>
#define endl "\n"
int main()
{
	ll n;
	cin>>n;
	vi a(n),b(n),c(n);
	vi dp1(n,INT_MIN),dp2(n,INT_MAX),dp3(n,INT_MAX);
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	dp1[n-1]=a[n-1];
	dp2[n-1]=b[n-1];
	dp3[n-1]=c[n-1];
	for(int i=n-2;i>=0;i--)
	{
      dp1[i]=a[i]+max(dp2[i+1],dp3[i+1]);
      dp2[i]=b[i]+max(dp3[i+1],dp1[i+1]);
      dp3[i]=c[i]+max(dp2[i+1],dp1[i+1]);
	}
	ll m =max(dp1[0],dp2[0]);
	m=max(m,dp3[0]);
//cout<<max(dp1[0],dp2[0],dp3[0])<<endl;
	cout<<m<<endl;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    int r,g;
    int sum=1;
    cin>>r>>g;
    for(int i=1;i<=r;i++){
        if(sum*2<sum+g){
            sum=sum*2;
        }

        else
        sum+=g;
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int h, w; cin >> h >> w;
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a.at(i);
    queue<int> q;
    rep(i, n){
        rep(j, a.at(i)){
            q.push(i+1);
        }
    }

    vector<vector<int>> b(h+2, vector<int>(w+2, 0));
    for(int i=1; i<=h; i++){
        if(i%2){
            for(int j=1; j<=w; j++){
                b.at(i).at(j) = q.front();
                q.pop();
            }
        }
        else{
            for(int j=w; j>=1; j--){
                b.at(i).at(j) = q.front();
                q.pop();
            }
        }
    }

    rep(i, h) {
        rep(j, w){
            cout << b.at(i+1).at(j+1);
            if(j!=w-1) cout << " ";
            else cout << endl;
        }
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

/*
    for(int j=0;j<=K;j++)
        f[1][j]=1,s[1][j]=K-j+1;
    for(int i=2;i<=n+1;i++)
    {
        for(int j=0;j<=K;j++)
            for(int k=1;k<i;k++)
                f[i][j]=(f[i][j]+f[i-k][j]*s[k][j+1]%mod*C[i-2][k-1])%mod;  
        for(int j=K;j>=0;j--)
            s[i][j]=(f[i][j]+s[i][j+1])%mod;
    }
*/
const int N=305;
int C[N][N],f[N][N],g[N][N],n,K,mod;

int fix(int x){
	return x>=mod?x-mod:x;
}

int main(){
	read(n),read(K),read(mod);
	C[0][0]=1;
	rep(i,1,n){
		C[i][0]=1;
		rep(j,1,n)C[i][j]=fix(C[i-1][j-1]+C[i-1][j]);
	}
	rep(i,0,K)f[1][i]=1,g[1][i]=K-i+1;
	rep(i,2,n+1)per(j,K,0){
		rep(k,1,i-1)
			f[i][j]=(f[i][j]+(ll)f[i-k][j]*g[k][j+1]%mod*C[i-2][k-1])%mod;
		g[i][j]=fix(g[i][j+1]+f[i][j]);
	}
	cout<<f[n+1][0]<<endl;
	return 0;
}

Measured memory_bytes: 1280
def solve():
	t,*a=open(0)
	h,w=map(int,t.split())
	a=[[int(x)%2 for x in y.split()] for y in a]
	ret=[]
	for i in range(h):
		for j in range(w-1):
			if a[i][j]:
				a[i][j+1]^=1
				ret+=[i+1,j+1,i+1,j+2]
	for i in range(h-1):
		if a[i][-1]:
			a[i+1][-1]^=1
			ret+=[i+1,w,i+2,w]
	print(len(ret)//4)
	for a,b,c,d in zip(*[iter(ret)]*4):
		print(a,b,c,d)
	
if __name__=="__main__":
	solve()

Measured memory_bytes: 19216
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>


using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define y1 Emilia
#define forit(s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

#define N 400400
#define dracarys ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll mod = (ll)1e9 + 7;

int n;
ll c[N];
ll dp[N], x[N];

void add(ll &x, ll y){
    x = (x + y) % mod;
}
int main(){
    dracarys
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> c[i];
    dp[0] = 1;
    for(int i = 1; i <= n; ++i){
        add(dp[i], dp[i - 1]);
        if(c[i] != c[i - 1]){
            add(dp[i], x[c[i]]);
            add(x[c[i]], dp[i - 1]);
        }
    }
    cout << dp[n] << "\n";
    return 0;
}


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

using namespace std;

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

    int H, W;
    cin >> H >> W;
    char hoge[H][W];
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j) cin >> hoge[i][j];
    
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(hoge[i][j] == '#') continue;

            int count = 0;
            for(int k = 0; k < 8; ++k) {
                const int x = i + dx[k];
                const int y = j + dy[k];
                if(x < 0 || y < 0 || H <= x || W <= y) continue;
                if(hoge[x][y] == '#') count++;
            }
            hoge[i][j] = count + '0';
        }
    }

    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) cout << hoge[i][j];
        cout << endl;
    }

    return 0;
}


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

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

int main() {
    char c;
    cin >> c;

    if (c == 'A') {
        P('T');
    } else if (c == 'T') {
        P('A');
    } else if (c == 'C') {
        P('G');
    } else {
        P('C');
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s,t,x="";
  	cin>>s>>t;
  	int n=s.length(),m=t.length();
  	int dp[n+1][m+1];
  	for(int i=0;i<=n;i++) {
    	for(int j=0;j<=m;j++) {
        	if(i==0 || j==0) {dp[i][j]=0;}
          	else if(s[i-1]==t[j-1]) {dp[i][j]=dp[i-1][j-1]+1;}
          	else {dp[i][j]=max(dp[i-1][j],dp[i][j-1]);}
        }
    }
  	int i=n,j=m;
  	while(i>0 && j>0) {
    	if(s[i-1]==t[j-1]) {x.push_back(s[i-1]); i--; j--;}
      	else {
          	if(dp[i-1][j]>dp[i][j-1]) {i--;}
      		else {j--;}
        }
    }
  	reverse(x.begin(),x.end());
  	cout<<x<<endl;
}


Measured memory_bytes: 38828
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;

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

  if (s[0] == '2' && s[1] == '0' && s[2] == '1' && s[3] == '7')
  {
    s[3] = '8';
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace AtcoderExpress
{
    

    class Program
    {
        static long N;
        static long M;
        static long[][] XYZ;
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            
            N = NM[0];
            M = NM[1];

            XYZ = new long[N][];

            for (long i = 0; i < N; i++)
            {
                XYZ[i] = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            }
            var max = 0L;
            for (long i = 0; i < 2; i++)
            {
                for (long j = 0; j < 2; j++)
                {
                    for (long k = 0; k < 2; k++)
                    {
                        max = Max(max, Calculate(i, j, k));
                        
                    }
                }
            }
            Console.WriteLine(max);
        }

        static long Calculate(long i,long j,long k)
        {
            var ans = 0L;
            var one = i == 0 ? 1 : -1;
            var two = j == 0 ? 1 : -1;
            var thr = k == 0 ? 1 : -1;
            //Console.WriteLine(one + " " + j + " " + k);
            var arr = new long[N];
            for (long l = 0; l < N; l++)
            {
                arr[l] = XYZ[l][0] * one + XYZ[l][1] * two + XYZ[l][2] * thr;
            }
            Sort(arr);
            Reverse(arr);
            for (long l = 0; l < M; l++)
            {
                ans += arr[l];
            }
            return ans;
        }
    }
}


Measured memory_bytes: 13780
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n, m;
    cin >> n >> m;

    vector<li> ls(m), rs(m), cs(m);
    vector<pair<li, li>> lis;
    for (int i = 0; i < m; ++i) {
        cin >> ls[i] >> rs[i] >> cs[i];
        ls[i]--;
        rs[i]--;

        lis.emplace_back(ls[i], i);
    }

    sort(lis.begin(), lis.end());

    const li inf = 1LL << 60;

    set<pair<li, li>> cost_candidates;
    cost_candidates.emplace(inf, n - 1);
    cost_candidates.emplace(0, 0);
    for (int _i = 0; _i < m; ++_i) {
        const li i = lis[_i].second;
        const li l = ls[i];
        const li r = rs[i];
        const li c = cs[i];

        while (!cost_candidates.empty()) {
            if (cost_candidates.begin() -> second < l) {
                cost_candidates.erase(cost_candidates.begin());
            } else {
                break;
            }
        }

        auto l_elem = *cost_candidates.begin();
        const li new_cost = l_elem.first + c;

        cost_candidates.emplace(new_cost, r);
    }

    while (!cost_candidates.empty()) {
        if (cost_candidates.begin() -> second < n - 1) {
            cost_candidates.erase(cost_candidates.begin());
        } else {
            break;
        }
    }

    li ans = (*cost_candidates.begin()).first;
    if (ans == inf) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10480
a, b, k = map(int, input().split())

if b-a+1 >= 2*k:
    for i in range(k):
        print(a+i)

    for i in range(k-1, -1, -1):
        print(b-i)

else:
    for i in range(a, b+1):
        print(i)


Measured memory_bytes: 3060
#include <stdio.h>
  
int main(){
    char a[4];
    int ans=0;

    scanf("%s",a);
    for (int i=0;i<4;i++){
        if(a[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
template<class T>void sort(vector<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vector<T> &v){sort(v.rbegin(),v.rend());}

int main(){
  int n;cin>>n;
  int ans=n/2;
  if(n%2==1)ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s;

int main(){
  int w,h,n; cin >> w >> h >> n;
  int x1 = 0; int x2 = w;
  int y1 = 0; int y2 = h;
  int x,y,a;
  rep(i,n){
    cin >> x >> y >> a;
    if(a == 1) x1 = max(x1, x);
    else if(a == 2) x2 = min(x2, x);
    else if(a == 3) y1 = max(y1, y);
    else if(a == 4) y2 = min(y2, y);
  }
  cout << max(0, x2-x1)*max(0, y2-y1) << "\n";
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a;
	cin>>a;
	long double b ;
	cin>>b;
	long double ans = ((long double)a * b);
	int k  = (int) ans;
	cout<<k;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int n, w = 0, r = 0;
string str;

void reset()
{
}

void input()
{
	cin>>n>>str;
	UP(i,0,n)
	{
		w += (str[i] == 'W');
		r += (str[i] == 'R');
	}
}

void solve()
{
	int cnt = 0;
	UP(i,0,r)
	{
		cnt += (str[i] == 'W');
	}
	
	int best = r;
	
	cnt = 0;
	DN(i,n-1,n-1-w)
	{
		cnt += (str[i] == 'R');
	}
	
	cout<<min(best, cnt)<<endl;
}

void LetsRock()
{
	solve();	
}

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

	input();
	reset();
	LetsRock();
	
	return 0;
}


Measured memory_bytes: 3744
#include "stdio.h"
#include <stdlib.h>
#include <utility>
using namespace std;

#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int N, H;
int a, b;
pair<int, int> knife_pair[200000];

int compare(const void *a, const void *b)
{
	pair<int, int> c = *(pair<int, int> *)a;
	pair<int, int> d = *(pair<int, int> *)b;

	if(c.second<d.second) return 1;
	else if(c.second==d.second) return 0;
	else return -1;
}

int main(void){
	int nokori_hp;
	int ans = 0;

	scanf("%d%d", &N, &H);

	FOR(i, 0, N-1){
		scanf("%d%d", &a, &b);

		//aを登録
		FOR(j, 0, 2*N-1){
			if(knife_pair[j].second==0){
				knife_pair[j].first = -1; //無限
				knife_pair[j].second = a;
				break;
			}else if(knife_pair[j].second==a){
				knife_pair[j].first = -1;
				break;
			}
		}
		//bを登録
		FOR(j, 0, 2*N-1){
			if(knife_pair[j].second==0){
				knife_pair[j].first++;
				knife_pair[j].second = b;
				break;
			}else if(knife_pair[j].second==b){
				if(knife_pair[j].first != -1){ //無限じゃない
					knife_pair[j].first++;
				}
				break;
			}
		}
	}

	qsort(knife_pair, SIZE_OF_ARRAY(knife_pair), sizeof(knife_pair[0]), compare);

	nokori_hp = H;

	FOR(j, 0, 2*N-1){
		if((knife_pair[j].first==-1)||(knife_pair[j].first * knife_pair[j].second >= nokori_hp)) {  //次に攻撃力がでかい刀が無限回、また残りのHPはこの刀で殺せる
			ans += nokori_hp/knife_pair[j].second;
			if(nokori_hp - nokori_hp/knife_pair[j].second*knife_pair[j].second >0){
				ans +=1;
			}
			goto RETURN;
		}else{
			nokori_hp -= knife_pair[j].first * knife_pair[j].second;
			ans += knife_pair[j].first;
		}
	}

RETURN:
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	if(K>(N-1)*(N-2)/2){
	    cout << -1 << endl;
	    return 0;
	}
	cout << N*(N-1)/2-K << endl;
	for(int i=1; i<N; ++i){
	    cout << i << ' ' << N << endl;
	}
	int p=1, q=2;
	for(int i=1; i<=(N-1)*(N-2)/2-K; ++i){
	    cout << p << ' ' << q << endl;
	    if(q+1==N){
	        ++p;
	        q=p+1;
	    }
	    else ++q;
	}
	return 0;
}


Measured memory_bytes: 384
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()

def odd(A):
    oddi=np.array(A[::2],dtype=np.int64)
    eveni=np.array(A[1::2],dtype=np.int64)
    left=np.cumsum(oddi[:-1]-eveni)
    left=np.insert(left,0,0)
    left=np.append(left,0)
    right=np.cumsum(oddi[:0:-1]-eveni[::-1])[::-1]
    right=np.insert(right,0,0)
    right=np.append(right,0)
    tmp=np.max(np.maximum.accumulate(left)+right)
    return tmp+np.sum(eveni)

def even(A):
    left=np.array([0]+A[::2],dtype=np.int64)
    right=np.array(A[1::2]+[0],dtype=np.int64)[::-1]
    return np.max(left.cumsum()+right.cumsum()[::-1])

def main():
    n=int(input())
    A=list(map(int, input().split()))
    if n%2==1:
        print(odd(A))
    else:
        print(even(A))


if __name__ == '__main__':
    main()

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

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

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

template<typename T>
struct RectangleSum {
	int H, W;
	vector<vector<T>> sum;
	RectangleSum(vector<vector<T>> v)
		:H(v.size()), W(v.front().size()), sum(H + 1, vector<T>(W + 1)) {
		rep(i, 0, H + 1)rep(j, 0, W + 1) {
			sum[i][j] = (i == 0 || j == 0) ? 0 :
				sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + v[i - 1][j - 1];
		}
	}
	// [si, ti), [sj, tj)
	T get(int si, int sj, int ti, int tj) {
		return sum[ti][tj] - sum[si][tj] - sum[ti][sj] + sum[si][sj];
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> x(N), y(N); vector<char> c(N);
	int L = 2 * K;
	auto v = gen_v<int>(2, L, L);
	int W = 0;
	rep(i, 0, N) {
		cin >> x[i] >> y[i] >> c[i];
		v[c[i] == 'W'][x[i] % L][y[i] % L]++;
		W += c[i] == 'W';
	}

	vector<RectangleSum<int>> sum = { v[0],v[1] };

	int ans = 0;

	rep(i, 0, K + 1)rep(j, 0, K + 1) {
		int cnt[2] = {};
		rep(k, 0, 2) {
			cnt[k] += sum[k].get(i, j, i + K, j + K);
			cnt[k] += sum[k].get(0, 0, i, j);
			cnt[k] += sum[k].get(i + K, j + K, L, L);
			cnt[k] += sum[k].get(0, j + K, i, L);
			cnt[k] += sum[k].get(i + K, 0, L, j);
		}
		chmax(ans, cnt[0] + (W - cnt[1]));
		chmax(ans, (N - W - cnt[0]) + cnt[1]);
	}
	cout << ans << endl;

	return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int d, g;
    cin >> d >> g;
    vector<ll> p(d);
    vector<ll> c(d);
    REP(i, d) {
        cin >> p[i] >> c[i];
    }

    int min_count = 1000000000;
    REP(i, 1 << d) {
        ll sc = 0;
        int count = 0;
        int b = -1;
        for (int j = d - 1; j >= 0; j--) {
            if ((1 & i >> j) == 1) {
                sc += p[j] * (j + 1) * 100 + c[j];
                count += p[j];
            } else if (b == -1) {
                b = j;
            }
        }
        // b をチェック
        if (sc >= g) {
            chmin(min_count, count);
        } else {
            REP(j, p[b] - 1) {
                sc += (b + 1) * 100;
                count++;
                if (sc >= g) {
                    chmin(min_count, count);
                    break;
                }
            }
        }
    }
    cout << min_count << endl;
}


Measured memory_bytes: 256
// C - pushpush
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

vi solve(int N, vi &A){
	vi ans(N);
	int isodd = N & 1;
	int f = isodd? N/2: N/2-1;
	int b = f + 1;
	rp(a, 0, N){
		int ix = (a&1) != isodd? f--: b++;
		ans[ix] = A[a];
	}
	return ans;
}

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i, 0, N) cin>>A[i];
	vi ans = solve(N, A);
	rp(i, 0, N) cout<< ans[i] <<" ";
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long a,b;
  cin >> a >> b;
  if (a>0) cout << "Positive" << endl;
  else if (a*b<=0) cout << "Zero" << endl;
  else{
    if ((b-a)%2) cout << "Positive" << endl;
    else cout << "Negative" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import re

#正規表現使用. [a-z]は小文字アルファベット.$は完全一致, +は一回以上の繰り返し
print(re.match("A[a-z]+C[a-z]+$", input()) and "AC" or "WA")

# matchしてるものなければNoneなのでorで結ばれた"WA"
# その他ならばTrue扱いでandで結ばれた"AC"を出力.

Measured memory_bytes: 3188
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	x := scanInt()
	a := make([]int, N)

	for i := 0; i < N; i++ {
		a[i] = scanInt()
	}

	sort.Ints(a)

	res := 0
	for i := 0; i < N; i++ {
		x -= a[i]
		if x == 0 {
			res = i + 1
			break
		} else if x < 0 {
			res = i
			break
		}
		res = i
	}

	fmt.Println(res)
}


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

int min(int a,int b){if(a>b){return b;}return a;}

int main(void){
	int b[128],r[128],n,l,i,j;
	char s[64];
	scanf("%d",&n);
	for(i = 0;i <= 127;i++){r[i] = 128;}
	for(i = 1;i <= n;i++){
		for(j = 0;j <= 127;j++){b[j] = 0;}
		scanf("%s",s);
		l = strlen(s);
		for(j = 0;j < l;j++){b[s[j]]++;}
		for(j = 0;j <= 127;j++){r[j] = min(r[j],b[j]);}
	}
	for(i = 97;i <= 122;i++){
		for(j = 1;j <= r[i];j++){printf("%c",i);}
	}
	printf("\n");
	return 0;
}

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

int main(){
  int N,L = 0;
  scanf("%d" "%d",&N,&L);
  char S[N][L+1], tmp[L+1];
  S[0][0] = '\0';
  for(int x = 0; x<N; x++){
    scanf("%s" ,S[x]);
  }
  for(int i = 1; i<N; i++){
    for(int j = 1; j<N; j++){
      if(strcmp(S[j],S[j-1])<0){
        strcpy(tmp,S[j-1]);
        strcpy(S[j-1],S[j]);
        strcpy(S[j],tmp);
      }
    }
  }
  for(int y=0; y<N; y++){
    printf("%s",S[y]);
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define int long long
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	int W; cin >> W;
	std::vector<int> v(n);
	vector<int> w(n); for (int o = 0; o < n; o++) { cin >> w[o] >> v[o]; }
	std::vector<int> maxvalue(W + 1, 0);
	for (int i = 0; i < n; ++i)
		for (int j = W - w[i]; j >= 0; --j) 
			maxvalue[j + w[i]] = max(maxvalue[j + w[i]], maxvalue[j] + v[i]);
	int ma = 0;
	for (int i = 0; i <= W; ++i) 
		ma = max(maxvalue[i], ma);
	cout << ma;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=61;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll A[MAXN], B[MAXN], C[MAXN];
int P[MAXN], sp[MAXN][LOG];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	for (int i=1; i<n; i++) B[i]=A[i]-A[i+1], P[i]=i;
	cin>>m>>k;
	while (m--){
		cin>>x;
		swap(P[x-1], P[x]);
	}
	for (int i=1; i<n; i++) sp[i][0]=P[i];
	for (int j=1; j<LOG; j++) for (int i=1; i<n; i++) sp[i][j]=sp[sp[i][j-1]][j-1];
	
	for (int i=1; i<n; i++){
		C[i]=i;
		for (int j=0; j<LOG; j++) if ((k>>j)&1) C[i]=sp[C[i]][j];
	}
	for (int i=n-1; i; i--) A[i]=B[C[i]]+A[i+1];
	
	for (int i=1; i<=n; i++) cout<<A[i]<<'\n';
	
	return 0;
}


Measured memory_bytes: 27904
#include <stdio.h>

int main(){
  char S[3][4];
  int k;
  for(k=0;k<2;k++){
    scanf("%s",S[k]);
  }
  if(S[0][0]==S[1][2]&&S[0][1]==S[1][1]&&S[0][2]==S[1][0]) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int a,b,aa=0,bb=0;
    cin>>a>>b;
    string A,B;
    
    for(int i=0;i<b;i++){
        aa *= 10;
        aa += a;
    }
    for(int i=0;i<a;i++){
        bb *= 10;
        bb += b;
    }

    A = to_string(aa);
    B = to_string(bb);

    if(A<B){
        cout<<A<<endl;
    }else{
        cout<<B<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

S = input()

def main():
    FS  = int(S[:2])
    LS = int(S[2:])
    can_yymm = True
    can_mmyy = True
    if FS < 0:
        return "NA"
    if FS == 0:
        can_mmyy = False
    if FS > 12:
        can_mmyy =False
    if LS < 0:
        return "NA"
    if LS == 0:
        can_yymm =False
    if LS > 12:
        can_yymm =False
    if can_yymm and can_mmyy:
        return "AMBIGUOUS"
    if can_yymm:
        return "YYMM"
    if can_mmyy:
        return "MMYY"
    return "NA"
print(main())


Measured memory_bytes: 38256
n = gets.to_i
as = gets.split.map(&:to_i)
q = n.div 2

odd = n.odd? ? 1 : 0
unless as.uniq.size == q + odd
    puts 0
    exit
end

unless as.inject(&:+) == (n + odd) * q
    puts 0
    exit
end

puts (2 ** q).modulo(10 ** 9 + 7)

Measured memory_bytes: 12676
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  int L[M],R[M];
  REP(i,M){
    cin>>L[i]>>R[i];
    L[i]--;R[i]--;
  }
  int C[N+1];
  REP(i,N)C[i]=0;
  REP(i,M){
    C[L[i]]++;
    C[R[i]+1]--;
  }
  REP(i,N)C[i+1]+=C[i];
  // REP(i,N)cerr<<C[i]<<" ";
  // cerr<<endl;
  int ans=0;
  REP(i,N)if(C[i]==M)ans++;
  cout<<ans<<endl;
  return 0;
}


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

const int N = 3333, mod = 1e9 + 7;

int dp[N][N], trace[N][N];
string s, t, ans;

signed main() {
	cin >> s >> t;
	int n = s.size(), m = t.size();
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
			} else if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
				trace[i][j] = s[i - 1];
			} else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	int lcs = dp[n][m];
	for (int i = n; i >= 0; i--) {
		for (int j = m; j >= 0; j--) {
			if (dp[i][j] == lcs && trace[i][j]) {
				ans += trace[i][j];
				lcs--;
				i--;
			}
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}

Measured memory_bytes: 160000
#include <cstdio>
#include <cctype>
using namespace std;
int main(void){
    char ch;
    while(true){
        scanf("%c", &ch);
        if(islower(ch)) ch = toupper(ch);
        else if(isupper(ch)) ch = tolower(ch);
        printf("%c", ch);
        if(ch == '\n') break;
    }

    return 0;
}



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

using namespace std;

int main(){
 int count=0;
 string s;
 
 cin>>s;
 
 for(int i=0,j=s.size()-1;i<=(s.size()) , j>=0; i++,j--){
    
    if(s[i]!=s[j]){
      s[i]=s[j];
      count++;
    
    }
 
 
  }

 cout<<count;


return 0;
}

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

int n, rv = 0, last[10];
string s;

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

	for (int i = 0; i < n; i++) {
		last[s[i] - '0'] = i;
	}

	for (int k = 0, m; k < 100; k++) {
		m = k;
		for (int i = 0, d = 0; i < n; i++) {
			if (s[i] - '0' == m % 10) {
				d++;
				if (d == 2) {
					for (int j = 0; j < 10; j++) {
						if (last[j] > i)
							rv++;
					}
					break;
				}
				m /= 10;
			}
		}
	}
	cout << rv << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,i,j,count;
  cin >> N >> M;
  vector<int> vec(2*M);
  
  for(i=0;i<2*M;i++) cin >> vec.at(i);
  
  for(i=0;i<N;i++){
    count=0;
    for(j=0;j<2*M;j++){
      if(vec.at(j)==i+1) count++;
    } 
    cout << count <<endl;
  }
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int a[4010],q[4010];

int main()
{
	#ifdef waltz
		freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int n,x;scanf("%d%d",&n,&x);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) a[i+n]=a[i];
    ll ans=100000000000000000ll;
    for (int i=0;i<n;i++)
    {
        int f=1,r=0;ll tmp=ll(x)*i;
        for (int j=1;j<=2*n;j++)
        {
            while (f<=r&&a[q[r]]>a[j]) r--;
            q[++r]=j;
            while (f<=r&&q[f]+i<j) f++;
            if (j>n) tmp+=a[q[f]];
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
def prime_factor_table(n):
    table = [0] * (n + 1)

    for i in range(2, n + 1):
        if table[i] == 0:
            for j in range(i + i, n + 1, i):
                table[j] = i

    return table

l = prime_factor_table(100000)
l[0] = 1
l[1] = 1
l2 = [0]*100000

for i in range(1,100000,2):
    x = (i+1)//2
    if l[i] == 0 and l[x] == 0:
        l2[i] = 1

l3 = [0]
for i in range(100000):
    x = l3[i] + l2[i]
    l3.append(x)

Q = int(input())
for i in range(Q):
    a,b = map(int, input().split())
    print(l3[b+1]-l3[a])


Measured memory_bytes: 13624
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

const int N_MAX = 50;
const int X_MAX = 50;
int N, A;
int x_max;
VI X;

LL dp[N_MAX + 1][N_MAX + 1][N_MAX * X_MAX + 1]; // n, i, sum

void solve() {
    REP(j, N + 1) {
        REP(k, N + 1) {
            REP(s, N * x_max + 1) {
                if (j == 0 and k == 0 and s == 0) {
                    dp[j][k][s] = 1;
                } else {
                    if (j >= 1 and s < X[j]) {
                        dp[j][k][s] = dp[j-1][k][s];
                    } else if (j >= 1 and k >= 1 and s >= X[j]) {
                        dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[j]];
                    } else {
                        dp[j][k][s] = 0;
                    }
                }
            }
        }
    }
    LL ans = 0;
    FOR(k, 1, N + 1) {
        ans += dp[N][k][k * A];
    }
    cout << ans << endl;
    /*
    REP(i, N + 1) {
        REP(j, N + 1) {
            REP(x, N * x_max + 1) {
                cout << dp[i][j][x] << " ";
            }
            cout << endl;
        }
    }
    */
}


int main(int argc, char const* argv[])
{
    cin >> N >> A;
    x_max = A;
    int x;
    X.PB(-1);
    REP(i, N) {
        cin >> x;
        X.PB(x);
        x_max = max(x_max, x);
    }
    solve();
    return 0;
}


Measured memory_bytes: 51072
#include <iostream>
using namespace std;
int N;
int A[15];
int DP[15][2];
void Read()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> A[i];
}

void Solve()
{
    DP[0][1] = 1;
    for(int i = 1; i <= N; i++)
    {
        A[i] %= 2;
        DP[i][1 - A[i]] = DP[i - 1][1] * 2;
        DP[i][0] += DP[i - 1][0] * 2;
        DP[i][A[i]] += DP[i - 1][1];
        DP[i][0] += DP[i - 1][0];
    }
    cout << DP[N][0] << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
  char c;
  cin>>c;
  if(c>='a' && c<='z')
  	cout<<'a';
 else
   cout<<'A';
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// leave to tomorrow anything that can be done today
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a;
    long double b;
    cin>>a>>b;
    b = round(b*100);
    ll calc = (a*b)/100;
    cout<<calc<<"\n"; 
    return 0;   
}   

Measured memory_bytes: 3796
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
int main(void)
{
    int K;
    cin >> K;
    string s;
    cin >> s;
    if (s.length() <= K)
    {
        cout << s << endl;
    }
    else
    {
        for (int i = 0; i < K; i++)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define ll long long
#define pb push_back
#define gcd __gcd

#define For(i,j,k) for(int i=(j);i<k;i++)
#define lowbit(i) (i&(-i))
#define _(x) printf("%d\n",x)


const int maxn = 10005;
int a[maxn * maxn];
int mp[maxn][maxn];

int main(){
    int h,w,n;
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
    }
    int x = 1;
    for(int i=1;i<=h;i++){
        if(i%2==1){
            for(int j=1;j<=w;j++){
                if(a[x]){
                    mp[i][j] = x;
                    a[x]--;
                }
                else {
                    while(a[x]==0) x++;
                    mp[i][j] = x;
                    a[x]--;
                }
            }
        }
        else {
            for(int j=w;j>=1;j--){
                if(a[x]) {
                    mp[i][j] = x;
                    a[x]--;
                }
                else {
                    while(a[x]==0)x++;
                    mp[i][j] = x;
                    a[x]--;
                }
            }
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            printf("%d ",mp[i][j]);
        }
        puts("");
    }
    return 0;
}




Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int n;
    cin >> n;

    cout << (n + 1) / 2 << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a, b ,c;
    scanf("%d%d%d", &a, &b, &c);
    if((a == b && b == c && a == c) || (a != b && b != c && a != c))
        printf("No");
    else if ((a == b && a !=c) || (a == c && a != b) || (b == c && b != a))
        printf("Yes");
    printf("\n");

    return 0;
}

Measured memory_bytes: 128
def Main():
    w,h ,n = map(int,input().split())
    mnx = 0
    mny = 0
    mxx = w
    mxy = h

    for i in range(n):
        x,y ,a = map(int ,input().split())
        if a == 1:
            mnx = max(mnx, x)
        elif a == 2:
            mxx = min(mxx, x)
        elif a == 3:
            mny = max(mny, y)
        elif a == 4:
            mxy = min(mxy, y)

    if mxy <= mny or mxx <= mnx:
        print(0)
    else:
        print((mxy - mny)*(mxx - mnx))


if __name__ == '__main__':
    Main()

Measured memory_bytes: 3064