akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
void init(){
cin.tie(0);
cin.sync_with_stdio(0);}

int main(){
init();

int r; cin>>r;
double pi=3.141592654,res;
res=2*pi*r;
cout<<fixed<<setprecision(2)<<res;
}









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

int main()
{
int h, w;
int dx[8] = {-1,0,1,-1,1,-1,0,1};
int dy[8] = {1,1,1,0,0,-1,-1,-1};
string str[50];
cin >> h >> w;
for(int i = 0; i < h; i++) cin >> str[i];

for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(str[i][j] == '#') continue;

int cnt = 0;
for(int k = 0; k < 8; k++){
int x = j + dx[k];
int y = i + dy[k];

if(x < 0 || w <= x) continue;
if(y < 0 || h <= y) continue;
if(str[y][x] == '#') cnt++;
}
str[i][j] = char(cnt + '0');
}
}

for(int i = 0; i < h; i++) cout << str[i] << endl;

return 0 ;
}

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

typedef long long int ll;

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

const ll MOD = 1000000007;

using namespace std;
vector<int> e[8];
int n = 0;
int N, M;

void search(int v, vector<int> r)
{
	r.push_back(v);
	if (r.size() == N)
	{
		n++;
		return;
	}
	REP(i, e[v].size())
	{
		bool contain = false;
		REP(j, r.size())
		{
			if (e[v][i] == r[j])
			{
				contain = true;
				break;
			}
		}

		if (contain) continue;
		search(e[v][i], r);
	}
	return;
}

int main()
{
	cin >> N >> M;
	REP(i, M)
	{
		int a, b;
		cin >> a >> b;
		e[a - 1].push_back(b - 1);
		e[b - 1].push_back(a - 1);
	}

	vector<int> r;
	search(0, r);

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

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
    long long int N,i,a,b,c;
    long long int min;
    scanf("%lld",&N);
    min=N;
    for(i=2;i<=sqrt(N);i++)
        if(N%i==0){
            a=i;
            b=N/i;
            if(min>a+b-2)
                min=a+b-2;
        }
    if(min!=N)
        printf("%lld\n",min);
    else
        printf("%lld\n",N-1);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

int main()
{
  int i;
  std::cin >> i;

  int h, m, s;

  h = i / (60 * 60);
  m = (i - h * 60 * 60) / 60;
  s = i - (h * 60 * 60 + m * 60);

  std::cout << h << ":" << m << ":" << s << std::endl;
  return 0;
}



Measured memory_bytes: 3100
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    total_T_in_A = [0] * (N+1)
    total_T_in_A[1] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

    for i in range(2, N+1):
        total_T_in_A[i] = total_T_in_A[i-1] + A[i-1]

    for i in range(1, M):
        total_T_in_B[i] = total_T_in_B[i-1] + B[i]

    result = 0
    for i in range(N+1):
        # A から i 冊読むときにかかる時間
        i_A_T = total_T_in_A[i]
        
        if K < i_A_T:
            continue

        if K == i_A_T:
            result = max(result, i)
            continue

        rem_T = K - i_A_T

        # total_T_in_B は累積和を格納した、ソート済の配列
        # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
        first = total_T_in_B[0]
        last = total_T_in_B[M-1]
        if rem_T < first:
            result = max(result, i)
            continue
        if last <= rem_T:
            result = max(result, i + M)
            continue

        # assume that first <= rem_T <= last
        first_i = 0
        last_i = M - 1
        while first_i < last_i:
            if abs(last_i - first_i) == 1:
                break
            mid_i = (first_i + last_i) // 2
            if rem_T < total_T_in_B[mid_i]:
                last_i = mid_i
            else:
                first_i = mid_i
        result = max(result, i + first_i + 1)

    print(result)

main()


Measured memory_bytes: 110956
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    S = input()
    if S[-1] == 's':
        print(S + 'es')
    else:
        print(S + 's')
    # N = int(input())
    # print(2*N)

    # N, K = [int(a) for a in input().split()]
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]


if __name__ == "__main__":
    main()


Measured memory_bytes: 68448
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin >> str;
  int q,i;
  cin >> q;
  string s1,s2;
  int a,b;
  for(i=0;i<q;i++){
    //cout << str << endl;
    cin >> s1 >> a >> b;
    if(s1=="print"){
      cout << str.substr(a,b-a+1) << endl;
    }else if(s1=="reverse"){
      string s3=str.substr(a,b-a+1);
      reverse(s3.begin(),s3.end());
      str=str.substr(0,a)+s3+str.substr(b+1,str.size()-a-1);
    }else{
      cin >> s2;
      str=str.substr(0,a)+s2+str.substr(b+1,str.size()-a-1);
    }
  }
}



Measured memory_bytes: 3204
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート 1,2,....9
}

int main(void){
    ll N, l[205], ans=0;
    in(N);
    rep(i, 2*N) in(l[i]);
    qsort(l, 2*N, sizeof(ll), cmp);
    rep(i, N) ans += l[i*2];
    put(ans);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a, b, c, d;
		
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		System.out.println(Math.max(a * b, c * d));
		
		sc.close();
	}

}


Measured memory_bytes: 22484
//逆再生(元に戻す操作)を考えると[l,l+1,…,r]が部分列だなあ～みたいな気持ちになって解ける。
#include <iostream>
#include <algorithm>
using namespace std;

int n;
int p[200000];
int pos[200000];

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) { cin >> p[i]; pos[p[i] - 1] = i; }
	
	int len = 1, mLen = 0;
	for (i = 1; i < n; i++) {
		if (pos[i - 1] < pos[i]) {
			len++;
		}
		else {
			mLen = max(mLen, len);
			len = 1;
		}
	}
	mLen = max(mLen, len);
	cout << n - mLen << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)
#define mov(a) (1<<(a))
#define lowbit(a) (a&(-a))
#define rk(i) (mov(n)-i+1)

const int N=16,M=17,S=1<<N,MOD=1e9+7;
int n,m,a[M];
int fac[S],inv[S],dp[M][S],g[S],siz[S],f;

inline bool cmp(const int &a,const int &b) {return a>b;}
inline int qsm(int a,int b) {int ans=1; while(b) {if(b&1) ans=1ll*ans*a%MOD; a=1ll*a*a%MOD; b>>=1;} return ans;}
inline int C(int a,int b) {return b<0||a<b?0:1ll*fac[a]*inv[b]%MOD*inv[a-b]%MOD;}
inline void inc(int &a,int b) {(a+=b)>=MOD?a-=MOD:a;}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("test.in","r",stdin);
	#endif
	
	scanf("%d%d",&n,&m); lor(i,1,m) scanf("%d",&a[i]); sort(a+1,a+1+m,cmp);
	fac[0]=1; lor(i,1,mov(n)-1) fac[i]=1ll*fac[i-1]*i%MOD;
	inv[mov(n)-1]=qsm(fac[mov(n)-1],MOD-2); ror(i,0,mov(n)-2) inv[i]=1ll*inv[i+1]*(i+1)%MOD;
	dp[0][0]=1;
	lor(i,1,m) lor(j,0,mov(n)-1){
		dp[i][j]=dp[i-1][j];
		lor(k,0,n-1) if(j&mov(k)){
			inc(dp[i][j],1ll*dp[i-1][j^mov(k)]*C(rk(a[i])-1-(j^mov(k)),mov(k)-1)%MOD*fac[mov(k)]%MOD);
		}
	}
	lor(j,0,mov(n)-1) g[j]=1ll*dp[m][j]*fac[mov(n)-1-j]%MOD;
	lor(j,1,mov(n)-1) siz[j]=siz[j-lowbit(j)]+1;
	lor(j,0,mov(n)-1) inc(f,siz[j]&1?MOD-g[j]:g[j]);
	f=1ll*f*mov(n)%MOD;
	printf("%d\n",f);

	return 0;
}

Measured memory_bytes: 8908
#include<iostream>
#include<cctype>
#include<string>

std::string shuffle(std::string c, int t){
	std::string s = c;
	s = s.substr(t, s.size()-t) + s.substr(0, t);
	return s;
}

/*int main(){
	std::string t = "aabc";
	t = shuffle(t, 2);
	std::cout << t << std::endl;
	return 0;
}*/

int main(){
	std::string card;
	int num;
	
	while(1){
		std::cin >> card;
		if (card == "-") break;
		std::cin >> num;
		for(int i = 1; i <= num; i++){
			int a;
			std::cin >> a;
			card = shuffle(card , a);
		}
		
		std::cout << card << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  string s;
  cin >> s;
  int cnt =0;
  for (int i=1; i<s.size(); i++){
      if (s[i] != s[i-1]){
          cnt++;
      }
  }
  cout << cnt;
  return 0; 
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <cstdlib>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); };

bool chmin(double&a,int b){return a>b?(a=b,true):false;}
bool chmax(double&a,double b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 7;

string s[55];
bool visited[55][55];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,-1,0,1};

signed main()
{
	int h, w; cin >> h >> w;
	rep(i, h) cin >> s[i];

	bool ok = true;

	rep(i, h) rep(j, w) {
		if (s[i][j] == '#') {
			bool f = false;
			rep(k, 4) {
				int ny = i + dy[k], nx = j + dx[k];
				if (0 <= nx and nx < w and 0 <= ny and ny < h) {
					if (s[ny][nx] == '#') f = true;
				}
			}
			if (not f) {
				ok = false;
			}
		}
	}

	puts(ok?"Yes":"No");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int main(int argc, char const *argv[]) {
  int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  int min=INT_MAX;
  for(int i=0;i+k-1<n;i++){
    int tmp=v[i+k-1]-v[i];
    if(tmp<min) min=tmp;
  }
  cout<<min<<endl;
  return 0;
}


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

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  auto a=vec(n,n,0LL);
  rep(i,0,n)rep(j,0,n)cin>>a[i][j];
  vector<ll>v(1<<n);
  rep(i,0,1<<n){
    bitset<16>x=i;
    rep(j,0,n){
      if(x[j]){
        v[i]=v[i&~(1<<j)];
        rep(o,0,n){
          if(j!=o&&x[o])v[i]+=a[j][o];
        }
        break;
      }
    }
  }
  //debug(v,1<<n);
  vector<ll>dp(1<<n,0);
  rep(i,0,1<<n){
    chmax(dp[i],v[i]);
    for(ll j=i;j>0;j=(j-1)&i){
      chmax(dp[i],dp[j]+dp[i&~j]);
    }
  }
  //debug(dp,1<<n);
  cout<<dp[(1<<n)-1]<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    ll n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    ll mn = INF;
    int cur = 0, idx = -1;

    cin>>a>>b;

    if(b-a+1>=2019){
        cout<<"0\n";
    }
    else {
        for(ll i=a;i<=b;i++)
            for(ll j=a;j<=b;j++){
                if(i!=j)mn = min(mn,(i*j)%2019);
            }

        cout<<mn<<"\n";
    }

    return 0;
}


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

class mint {
  int value;
  static vector<int> _fact;

public:
  static const int MOD = 1e9 + 7;
  mint(long long x)
      : value((x % MOD + MOD) % MOD) {}
  mint operator+(mint y) const {
    return mint(value + y.value);
  }
  mint &operator+=(mint a) {
    return *this = *this + a;
  }
  mint operator*(mint y) const {
    return mint(long(value) * y.value);
  }
  mint &operator*=(mint a) {
    return *this = *this * a;
  }
  mint operator-() const {
    return *this * mint(-1);
  }
  mint operator-(mint y) const {
    return *this + (-y);
  }
  mint &operator-=(mint a) {
    return *this = *this - a;
  }
  operator int() const {
    return value;
  }
  static mint pow(mint a, int n) {
    if (n <= 0) {
      return 1;
    }
    mint half = mint::pow(a, n / 2);
    return n % 2 ? half * half * a : half * half;
  }
  static mint fact(int n) {
    if (size_t(n) < _fact.size()) {
      return _fact[n];
    }
    mint ans = fact(n - 1) * mint(n);
    _fact.push_back(ans);
    return ans;
  }
  mint inv() {
    return pow(value, MOD - 2);
  }
  static mint comb(int n, int k) {
    return fact(n) * fact(k).inv() * fact(n - k).inv();
  }
};
vector<int> mint::_fact = {1};

int main() {
  int K;
  cin >> K;

  string S;
  cin >> S;

  int W = S.size();
  int L = W + K;
  mint ans = 0;
  for (int i = W - 1; i < L; i++) {
    ans += mint::pow(25, i - (W - 1)) * mint::pow(26, L - 1 - i) * mint::comb(i, W - 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 44708
S = input()
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
rslt = 'Yes'
for idx, s in enumerate(S):
    if idx%2==1 and s in even:
        continue
    elif idx%2==0 and s in odd:
        continue
    else:
        rslt = 'No'
        break
print(rslt)

Measured memory_bytes: 3060
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
int p=1e9+7;
LL qmi(LL a, int k, int p)
{
    LL ans = 1;
    while(k)
    {
        if(k&1)
            ans = ans * a % p;
        k >>= 1;
        a = a * a % p;
    }
    return ans;
}
LL C(LL a, LL b)
{
    LL ans = 1;
    for(int i = 1, j = a; i <= b; i++, j--)
    {
        ans = ans * j % p;
        ans = ans * qmi(i, p-2, p) % p;
    }
    return ans;
}

LL lucas(LL a, LL b)
{
    if(a<p&&b<p)
        return C(a, b);
    return ((LL)C(a%p, b%p)*lucas(a/p, b/p))%p;
}
LL sum=0;
int main()
{
    int n,x,y;
    scanf("%d%d%d",&n,&y,&x);
    sum=(qmi(2,n,p)%p+p-lucas(n,x)%p+p-lucas(n,y)%p-1ll)%p;
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	//int N, M;
	vector<string> wl;
	int n;
	cin >> n;
	
	string w;
	cin >> w;
	wl.push_back(w);

	for(int i=1; i<n; i++) {
		cin >> w;
		if(wl.at(i-1)[wl.at(i-1).size()-1] != w[0]) {
			cout << "No";
			return 0;
		}
		for(int j=0; j<wl.size(); j++) {
			if(wl.at(j) == w) {
				cout << "No";
				return 0;
			}
		}
		wl.push_back(w);
	}

	
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var K,A,B int

	fmt.Scan(&K,&A,&B)


	for i:=A;i<=B;i++{

		if i%K==0{

			fmt.Println("OK")

			return
		}

	}

	fmt.Println("NG")

}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

bool match(string s, int i, string t) { // sのi文字目以降の部分文字列がtと一致するか
    if (i + (int)t.size() > (int)s.size()) return false;
    rep(j, (int)t.size()) {
        if (s[i+j] != t[j]) return false;
    }
    return true;
}

int main() {
    // input
    string s;
    cin >> s;
    // solve
    reverse(ALL(s));
    int n = s.size();
    vector<string> t = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 4) {
        reverse(ALL(t[i]));
    }
    bool flag = true;
    int i = 0;
    // while (i < n and flag) {
    //     if (s[i] == 'm') {
    //         rep(j, 5) {
    //             if (i+j >= n or s[i+j] != t[0][j]) {
    //                 flag = false;
    //                 break;
    //             }
    //         }
    //         i += 5;
    //     } else if (s[i] == 'e') {
    //         rep(j, 5) {
    //             if (i+j >= n or s[i+j] != t[2][j]) {
    //                 flag = false;
    //                 break;
    //             }
    //         }
    //         i += 5;
    //     } else if (i+2 < n and s[i] == 'r' and s[i+1] == 'e') {
    //         if (s[i+2] == 's') {
    //             rep(j, 6) {
    //                 if (i+j >= n or s[i+j] != t[3][j]) {
    //                     flag = false;
    //                     break;
    //                 }
    //             }
    //             i += 6;
    //         } else if (s[i+2] == 'm') {
    //             rep(j, 7) {
    //                 if (i+j >= n or s[i+j] != t[1][j]) {
    //                     flag = false;
    //                     break;
    //                 }
    //             }
    //             i += 7;
    //         } else {
    //             flag = false;
    //             break;
    //         }
    //     } else {
    //         flag = false;
    //         break;
    //     }
    // }
    while (i < n and flag) {
        flag = false;
        rep(j, 4) {
            if (match(s, i, t[j])) {
                flag = true;
                i += (int)t[j].size();
                break;
            }
        }
    }
    // output
    if (flag) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int n,m,x;
	cin >> n >> m >> x;
	int a[m];
	REP(i,m) cin >> a[i];
	int cntl=0;
	int cntr=0;
	REP(i,m){
		if(a[i]<x) cntl++;
		else cntr++;
	}
	cout << min(cntl,cntr) << endl;
/////////////////////////////////////////////
}


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

int main(){
	int field[100][55],dp[100][55] = {};
	int cnt = 0,num = 0,tmp = 0;
	char c;
	for(int i = 0;i < 100;i++) for(int j = 0;j < 55;j++) field[i][j] = -1;
	while(c = getchar()){
		if(c == EOF) break;
		if(c == '\n') {
			field[cnt++][num] = tmp;
			tmp = 0;
			num = 0;
		}
		else if(c == ','){
			field[cnt][num++] = tmp;
			tmp = 0;
		}else{
			tmp = tmp * 10 + (c - '0');
		}
	}
	dp[0][0] = field[0][0];
	for(int i = 1;i < 100;i++){
		for(int j = 0;j < 50;j++){
			if(field[i][j] == -1) continue;
			if(i < cnt / 2){
				if(j >= 1) dp[i][j] = max(dp[i - 1][j],dp[i - 1][j - 1]) + field[i][j];
				else dp[i][j] = dp[i - 1][j] + field[i][j];
			}else{
				dp[i][j] = max(dp[i - 1][j],dp[i - 1][j + 1]) + field[i][j];
			}
		}
	}
	cout << dp[cnt - 1][0] << endl;
	return 0;
}

Measured memory_bytes: 3120
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s = iterator.next().unwrap();

    return if s == "ABC" {
        "ARC".to_string()
    } else {
        "ABC".to_string()
    }
}


Measured memory_bytes: 2128
N = int(input())
a = []
ans = []
for i in range(N):
    A = int(input())
    a.append(A)

b = sorted(a)

m = max(a)
for i in a:
    if i == m:
        ans.append(b[-2])
    else:
        ans.append(m)

for i in ans:
    print(i)


    

Measured memory_bytes: 20628
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<numeric>
#include<deque>

using namespace std;

#define ll long long

int main(void){
	ll n; cin >> n;
	deque<ll>a;
	int cnt=0;
	if(n%2!=0)cnt++;
	for(int i=0+cnt;i<n+cnt;i++){
		ll tmp; cin >> tmp;
		if(i%2==0) a.push_back(tmp);
		else a.push_front(tmp);
	}
	for(int i=0;i<n;i++){
		cout << a[i];
		if(i != n)cout << ' ';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3840
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String[] temp = scanner.nextLine().split(" ");
		int A = Integer.parseInt(temp[0]);
		int B = Integer.parseInt(temp[1]);
		int K = Integer.parseInt(temp[2]);
		Map<Integer,Integer> ans = new HashMap<Integer,Integer>();


		int defa = 1;
		for(int i = 1; i <= 100; i++) {
			if(A % i == 0 && B % i == 0) {
				if(ans.size() == 0) {
					ans.put(defa, i);
				}else {
					ans.put(defa + 1, i);
					defa++;
				}
			}
		}

		System.out.println(ans.get(ans.size() - K + 1));


	}

}


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

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var inputs = Console.ReadLine().Split(' ').Select(int.Parse).Reverse().ToList();
            Console.WriteLine(string.Join(" ", inputs));
        }
    }
}



Measured memory_bytes: 18348
y1,m1,d1 = map(int, input().split())
y2,m2,d2 = map(int, input().split())

if y1 > y2 or (y1 == y2 and (m1 > m2 or ( m1 == m2 and d1 > d2 ))):
    y1, y2 = y2, y1
    m1, m2 = m2, m1
    d1, d2 = d2, d1

if m1 < m2 or (m1 == m2 and d1 < d2): print(y2 - y1 + 1)
else: print(y2 - y1)




Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> T(n);
  ll ans = 1;
  REP(i,n){
    cin >> T[i];
    ans = ans  / __gcd(ans,T[i]) * T[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,i,b,f,r,v;
	int count[4][3][10]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		count[b-1][f-1][r-1]+=v;
	}
	for(b=0;b<4;b++){
		for(f=0;f<3;f++){
			for(r=0;r<10;r++){
				printf(" %d",count[b][f][r]);
			}
			printf("\n");
		}
		if(b<4-1){
			printf("####################\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
n,m = map(int,input().split())
if abs(n-m) >= 2:
  print(0)
  exit()
mod = 10**9+7
def factorial(n):
  ans = 1
  for i in range(2,n+1):
    ans = (ans*i)%mod
  return ans
if abs(n-m) == 1:
  print((factorial(m)*factorial(n))%mod)
  exit()
x = factorial(n)
print((2*x*x)%mod)
  

Measured memory_bytes: 62900
#include <iostream>
#include <cstring>

using namespace std;

int c[16];
int dp[1000002][15];

int main(){
  c[1] = 1;
  int x = 6;
  for(int i = 2; i < 9; i++){
    c[i] = x;
    x *= 6;
  }
  x = 9;
  for(int i = 9; i < 15; i++){
    c[i] = x;
    x *= 9;
  }
  int n; cin >> n;
  memset(dp, 127, sizeof dp);
  for(int j = 0; j < 14; j++) dp[0][j] = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= 14; j++){
      if(c[j] <= i){
        dp[i][j] = min(dp[i - c[j]][j] + 1, dp[i][j-1]);
      }
      else dp[i][j] = dp[i][j-1];
    }
  }
  cout << dp[n][14] << "\n";
  return 0;
}

Measured memory_bytes: 58880
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        d: [usize; n]
    }
    let mut d: Vec<usize> = d;
    d.sort_by(|x, y| y.partial_cmp(x).unwrap());
    let mut last = d[0];
    let mut count = 1;
    for i in d {
        if last == i {
        } else {
            count += 1;
        }
        last = i;
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
	int D;

	scanf("%d",&D);

	if (D==25){
		printf("Christmas\n");
	}else if(D==24){
		printf("Christmas Eve\n");
	}else if(D==23){
		printf("Christmas Eve Eve\n");
	}else{
		printf("Christmas Eve Eve Eve\n");
	}
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main() {
	int n;
	double x1, y1, x2, y2, x3, y3;
	double det, a, b, c, L, M, N;
	double xp, yp, r;
	scanf("%d", &n);
	while (n--) {
		scanf(" %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
		det = x1*y2 + x2*y3 + x3*y1 - x1*y3 - x2*y1 - x3*y2;
		a = x1*x1 + y1*y1;
		b = x2*x2 + y2*y2;
		c = x3*x3 + y3*y3;
		L = (a*y2 + b*y3 + c*y1 - a*y3 - b*y1 - c*y2) / det;
		M = (x1*b + x2*c + x3*a - x1*c - x2*a - x3*b) / det;
		N = (x1*y2*c + x2*y3*a + x3*y1*b - x1*y3*b - x2*y1*c - x3*y2*a)
			/ det;
		xp = L / 2.0;
		yp = M / 2.0;
		r = sqrt(fabs(N + xp*xp + yp*yp));
		printf("%0.3lf %0.3lf %0.3lf\n", xp, yp, r);
	}
	return 0;
}

Measured memory_bytes: 656
// Shinchan Loves Coding :)))
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<stack>
using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define double long double
#define en "\n"
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;
bool secdes(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi>b.fi;}else{return a.se>b.se;}}//second descending !
bool sir(const pair<int,int>&a , const pair<int,int>&b){if(a.fi==b.fi){return a.se>b.se;}else{return a.first>b.first;}}//first descending !
bool bysec(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi<b.fi;} else{return a.se<b.se;}}//second ascending !

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

const int no=3e6+5;
const int modulo=1e9+7;
const int inf=1e18+9;
const int N=1001;
int a[no]={},H[no]={},c[no]={},d[no]={},mat[N][N]={{0}};
stack<int> S;
stack<int> ma;

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

int poww(int x, int y, int modulo) {x %= modulo;int res=1;while (y > 0) {if (y & 1){res = res * x % modulo;}x = x * x % modulo;y >>= 1;}return res;}

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/
vector<int> adj[no];
int used[no],ans;

void dfs(int node , int& ans) {
    used[node]=1;
    ans++;
    for(int child : adj[node]) {
        if(!used[child]) dfs(child,ans);
    }
}

void solve(){
    int n,p,q,m;
    cin>>n>>m;
    for(int i=0 ; i<m ; i++) {
        int x,y;
        cin>>x>>y;
        adj[x].PB(y);
        adj[y].PB(x);
    }
    p=0;
    for(int i=1 ; i<=n ; i++) {
        if(!used[i]) {
            ans=0;
            dfs(i,ans);
            p=max(p,ans);
        }
    }
    cout<<p;
}

void runn(){
        #ifndef ONLINE JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
    }

signed main()
{
    night_rider
    //runn();
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 91132
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

signed main(){
	ll n; cin>>n;
	if(n%2==1){
		cout<<0<<endl;
		return 0;
	}
	ll cnt=10;
	ll ans=0;
	while(cnt<=n){
		ans+=n/cnt;
		cnt*=5;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3532
using System;

class Program{
	static void Main(){
		int i = int.Parse(Console.ReadLine());
		while(0<i--){
			double[] n = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
			double a, b, c, d;
			double x, y, r;
			a = n[0] * n[0] + n[1] * n[1];
			b = n[2] * n[2] + n[3] * n[3];
			c = n[4] * n[4] + n[5] * n[5];
			d = 2*( n[0] * (n[3] - n[5])
				  + n[2] * (n[5] - n[1])
				  + n[4] * (n[1] - n[3]));

			x = (a * (n[3] - n[5])
			   + b * (n[5] - n[1])
			   + c * (n[1] - n[3]))/d;

			y = (a * (n[4] - n[2])
			   + b * (n[0] - n[4])
			   + c * (n[2] - n[0]))/d;
		
			r = Math.Sqrt((n[0] - x) * (n[0] - x) + (n[1] - y) * (n[1] - y));
			
			Console.WriteLine("{0:f3} {1:f3} {2:f3}", x, y, r);
		}
	}
}

Measured memory_bytes: 9152
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
bool ma[110][110];
int n, m, d,rent=0,reny=0,ans=0;

int main() {
	cin >> n >> m >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			ma[i][j] = false;
				char s;
				cin >> s;
//				cout << s;
				if (s == '.')ma[i][j] = true;
		}
//		cout << endl;
	}
				
//横向き
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (ma[i][j] == false) reny = 0;
			else{
				reny++;
				if (reny >= d) ans ++;
			}
		}
		reny = 0;
	}
//縦向き
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (ma[j][i] == false) rent = 0;
			else {
				rent++;
				if (rent >= d) ans++;
			}
		}
		rent = 0;
	}

	cout << ans << endl;

	return 0;
}



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

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


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = 0
tmp = 0
prev = 0
h.append(10e9+1)
for x in h:
  if x > prev:
    ans = max(ans, tmp)
    tmp = 0
  else:
    tmp += 1
  prev = x
print(ans)

Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> p(n),q(n);
  vector<int> r(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  rep(i,n) r[i]=i+1;
  int a=0,b=0,cnt=1;
  do{
    if(p==r) a=cnt;
    if(q==r) b=cnt;
    cnt++;
  }while(next_permutation(all(r)));
  cout << abs(a-b) << endl;

  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right
import heapq
n,m=map(int,input().split())
lists=list(map(int,input().split()))
uselists=[]
for _ in lists:
    uselists.append(-_)

heapq.heapify(uselists)

cnt=0
while cnt<m:
    y=heapq.heappop(uselists)

    z=(-y)//2
    heapq.heappush(uselists,-z)
    

    cnt+=1
anslist=[]
for j in uselists:
    anslist.append(-j)
print(sum(anslist))

Measured memory_bytes: 15172
#include<stdio.h>
int main(void){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(C>A+B){
    printf("%d",B*2+A+1);
  }
  else if(C==A+B){
    printf("%d",B*2+A);
  }
  else{
    printf("%d",B+C);
  }
  return 0;
}

Measured memory_bytes: 128
a,b,c,d = map(int,input().split())
a -= 1
def gcd(A, B):
    while B:
        A, B = B, A % B
    return A
def lcm(A, B):
    return A * B // gcd (A, B)

ans = 0
tmp0 = b // c
tmp1 = b // d
tmp2 = b // lcm(c,d)
Tmp0 = tmp1 +tmp0 -tmp2

tmp3 = a // c
tmp4 = a // d
tmp5 = a // lcm(c,d)
Tmp1 = tmp3 + tmp4 - tmp5

ans = b-a - (Tmp0 - Tmp1)

print(ans)

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

int main(void) {
    int n, x, sum=0, bound=1;
    cin >> n >> x;
    vector<int> l(n);
    for(int m: l) {
        cin >> m;
        sum+=m;
        if(sum>x)
            break;
        bound++;
    }
    cout << bound << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
int main()
{
    string O, E;
    cin >> O >> E;
    int maxv = max((int)O.size(), (int)E.size());

    rep(i, maxv){
        // cout << O[i] << E[i];
        if(O.size()!=0){
            cout << O[0];
            O.erase(0, 1);
            // cout << O << endl;
        }
        if(E.size()!=0){
            cout << E[0];
            E.erase(0, 1);
            // cout << E << endl;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  if(s[5]=='0' && (s[6]-'0')<=4) cout<<"Heisei"<<endl;
  else cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll n,k,a; cin >> n >> k;
    ll ans = 1;
    if (n==k){
        REP(i,n){
            cin >> a;
            ans=(ans*(MOD+a))%MOD;
        }
        cout << ans << endl;
        return 0;
    }
    vector<ll> ap;
    vector<ll> an;
    REP(i,n){
        cin >> a;
        if (a<0) an.pb(-a);
        else ap.pb(a);
    }
    sort(ap.rbegin(),ap.rend());
    sort(an.rbegin(),an.rend());
    ll aplen = ap.size();
    ll anlen = an.size();
    if (ap.size()==0&&k%2){
        ll cnt = 0;
        while(cnt<k){
            ans=(ans*an[an.size()-1-cnt])%MOD;
            //cout << ans << " " << cnt << endl;
            cnt++;
        }
        cout << MOD-ans << endl;
        return 0;
    }
    ll apind = 0; ll anind = 0;
    if (k%2){
        ans*=ap[0];
        k--;
        apind++;
    }
    while(k){
        ll apcan = -INF;
        ll ancan = -INF;
        if (apind+1<=aplen-1) apcan = ap[apind]*ap[apind+1];
        if (anind+1<=anlen-1) ancan = an[anind]*an[anind+1];
        if (apcan>ancan){
            ans = (ans*(apcan%MOD))%MOD;
            apind+=2;
            k-=2;
        }
        else{
            ans = (ans*(ancan%MOD))%MOD;
            anind+=2;
            k-=2;
        }
        //cout << k << " " << apcan << " " << ancan << " " << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5620
#include <stdio.h>
#define range(X) (-100 <= X && X <= 100)
#define range2(R) (0 < R && R <= 100)

int main(void){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if (range(x) && range(y) && range2(W) && range2(H) && range2(r)){
        if (0 <= x - r && x + r <= W){
            if (0 <= y - r && y + r <= H)   printf("Yes\n");
            else                            printf("No\n");
        }
        else                                printf("No\n");
    }
    return 0;
}

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

int main(){
  ll n;cin>>n;
  ll ans=0;
  for(ll i=1;i<=n;i++){
    if(i%3 && i%5) ans+=i;
  }

  cout<<ans;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


char m[21][21];
int dist[21][21];
int H,W;




int solve(int sy,int sx){
  if(m[sy][sx] == '#') return 0;
  rep(i,H)rep(j,W) dist[i][j] = -1;
  dist[sy][sx] = 0;
  int M = 0;
  queue<P> q;
  q.push(make_pair(sx,sy));
  while(!q.empty()){
    P p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;
    rep(i,4){
      int X = x + dx[i];
      int Y = y + dy[i];
      if(X>=0 && Y>=0 && X<W && Y<H && dist[Y][X] == -1 && m[Y][X] == '.'){
	dist[Y][X] = dist[y][x] + 1;
	if(dist[Y][X] > M) M = dist[Y][X];
	q.push(make_pair(X,Y));
      }
    }   
  }
 return M;
}

int main(){
  cin >> H >> W;
  rep(i,H){
    rep(j,W){
      cin >> m[i][j];
    }
  }

  int ans = 0;
  rep(i,H){
    rep(j,W){
      if(m[i][j] == '#') continue;
      ans = max(ans,solve(i,j));
    }
  }

  

  // rep(i,H){
  //   rep(j,W){
  //     cout << dist[i][j] << "  ";
  //   }
  //   cout << endl;
  // }

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




Measured memory_bytes: 256
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(H: Int, W: Int, S: Array<String>){
    val ans = Array(H){ CharArray(W) }
    for(h in 0 until H){
        for(w in 0 until W){
            if (S[h][w] == '#') ans[h][w] = '#'
            else ans[h][w] = S.getAround(h, w).count{ it == '#' }.toC()
        }
    }
    ans.forEach{
        pw.println(it.joinToString(separator=""))
    }
    pw.flush()
    return
}

fun Int.toC(): Char = when(this){
    0 -> '0'
    1 -> '1'
    2 -> '2'
    3 -> '3'
    4 -> '4'
    5 -> '5'
    6 -> '6'
    7 -> '7'
    8 -> '8'
    9 -> '9'
    else -> '#'
}

fun Array<String>.safeGet(i: Int, j: Int): Char? = when{
    i < 0 || i >= size -> null
    else -> this[i].getOrNull(j)
}


fun Array<String>.getAround(i: Int, j: Int): List<Char> =
    (i-1..i+1)
        .flatMap{ y -> (j-1..j+1).map{ x -> y to x } }
        .map{ this.safeGet(it.first, it.second) }
        .filterNotNull()


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val H = sc.next().toInt()
    val W = sc.next().toInt()
    val S = StringArray(H)
    for (i in 0 until H) {
        S[i] = sc.next()
    }
    solve(H, W, S)
}



Measured memory_bytes: 41860
import sys
readline = sys.stdin.buffer.readline
kijun = ord("a")
n = int(readline())
s = readline().rstrip().decode('utf-8')
q = int(readline())
lst1 = [0]*n

def pow(n,p): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2
            p //= 2
        else:
            res = res * n
            p -= 1
    return res

for i in range(n):
    lst1[i] = pow(2,(ord(s[i])-kijun))
#####segfunc######
def segfunc(x,y):
    return x|y

def init(init_val): #渡されたリストでsegを初期化
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x): #segの要素kをxに変更(セグ木全体の更新)
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q): #区間[p,q)での、segfuncに準じた値を返す
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
"""
最小値のセグ木 → 10**9　(最小値の更新に影響しないため)
　　和のセグ木 → 0　(上の単位元の説明を参照)
　　積のセグ木 → 1　(上の単位元の説明を参照)
　　gcdのセグ木 → 0　(gcdを更新しない値は0)
"""
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num #単位元の配列(計算結果に影響を及ぼさない配列)を作成

init(lst1)

def judge(u):
    res = 0
    for i in range(27):
        if u>>i & 1:
            res += 1
    return res

for i in range(q):
    t,x,y = readline().rstrip().decode('utf-8').split()
    if t == "1":
        update(int(x)-1,pow(2,ord(y)-kijun))
    else:
        print(judge(query(int(x)-1,int(y))))


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

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

    vector<int> f(60000);
    for(int x=1; x<100; x++){
        for(int y=1; y<100; y++){
            for(int z=1; z<100; z++){
                f[x*x + y*y + z*z + x*y + y*z + z*x] += 1;
            }
        }
    }

    for(int i=1; i<=n; i++){
        cout << f[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    int N;cin>>N;
    if(N==25)cout<<"Christmas"<<endl;
    if(N==24)cout<<"Christmas Eve"<<endl;
    if(N==23)cout<<"Christmas Eve Eve"<<endl;
    if(N==22)cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;cin >> a >> b;
    cout << max(a - 2 * b, 0) << endl;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
 
import math
import re
import sys
 
args = input().split()

X = args[0]
Y = args[1]
Z = args[2]
 
# 人数
a = (int(X)-int(Z))/(int(Y)+int(Z))
 
print(int(a))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin >> a >> b >> c;
    if (a<c && b>c) cout << "Yes" << endl;
    else if (a>c && b<c) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  int ans;
  ans=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  vector<int>B(N);
  for(int i=0;i<N;i++){
    cin>>B.at(i);
  }
  vector<int>C(N-1);
  for(int i=0;i<N-1;i++){
    cin>>C.at(i);
  }
  for(int i=0;i<N-1;i++){
    if(A.at(i)+1==A.at(i+1)){
      ans+=C.at(A.at(i)-1);
    }
  }
  for(int i=0;i<N;i++){
    ans+=B.at(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256