akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int c[26],s[400][30],last[400][30],d,now = -1000000000;
vector<int> ans,w;
int score(int l, int r, vector<int> &v){//[l,r)
    int i,j,res = 0;
    for(i=l;i<r;i++){
        for(j=0;j<26;j++){
            last[i][j] = 0;
        }
    }
    for(i=l;i<r;i++){
        int x = v[i]; x--;
        if(x<0 || x>25){
            //cout << x << endl;
            exit(1);
        }
        res += s[i][x];
        last[i][x] = i + 1;
        for(j=0;j<26;j++){
            res -= c[j]*(i + 1 - last[i][j]);
        }
    }
    return res;
}

void score2(int x){
    vector<int> vv; vv.resize(d);
    vector<int> st;
    int i,j;
    for(i=0;i<d;i++){
        int k = -1,mx = -1000000000;
        for(j=0;j<26;j++){
            if(mx<s[i][j]){
                mx = s[i][j]; k = j + 1;
            }
        }
        if(mx>x) vv[i] = k;
        else st.push_back(i);
    }
    for(i=0;i<d;i++){
        if(vv[i]==0){
            bool flag = true;
            for(int x:st){
                if(x==i) flag = false;
            }
            if(flag){
                cout << -1 << endl;
                exit(1);
            }
        }
    }
    for(j=1;j<=26;j++){
        int y = j;
        for(int x:st){
            vv[x] = y; y++;
            if(y==27) y = 1;
        }
        int sc = score(0,d,vv);
        if(sc>now){
            swap(ans,vv); now = sc; 
        }
    }
}

/*vector<int> score3(){
    vector<int> vv; vv.resize(d);
    int i,j,l = 0;
    for(i=0;i<d;i++){
        if(i%26!=25 && i!=d - 1) continue;
        for(j=l;j<=i;j++){
            
        }
        l = i + 1;
    }
}*/

int main(){
    int i,j; cin >> d;
    for(i=0;i<26;i++) cin >> c[i];
    for(i=0;i<d;i++){
        for(j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    for(i=0;i<d;i++) ans.push_back(i%26 + 1);
    now = score(0,d,ans);
    for(j=1;j<26;j++){
        w.clear();
        for(i=0;i<d;i++) w.push_back((i + j)%26 + 1);
        int sc = score(0,d,w);
        if(sc>now){
            swap(ans,w); now = sc;
        }
    }
    for(i=0;i<=20000;i+=10) score2(i);
    for(i=0;i<d;i++) cout << ans[i] << "\n";
}

Measured memory_bytes: 3728
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
bool used[210];
vector<int>G[210];
int match[210];
bool dfs(int v) {
	used[v] = true;
	for (int i = 0; i < G[v].size(); ++i) {
		int u = G[v][i];
		int w = match[u];
		if (w < 0 || !used[w] && dfs(w)) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}
int main() {
	int N; cin >> N;
	int a[110], b[110], c[110], d[110];
	REP(i, N)cin >> a[i] >> b[i];
	REP(i, N)cin >> c[i] >> d[i];
	REP(i, N) {
		REP(j, N) {
			if (a[i] < c[j] && b[i] < d[j]) {
				G[i].push_back(j + N);
				G[j + N].push_back(i);
			}
		}
	}
	int res = 0;
	memset(match, -1, sizeof(match));
	REP(i, N) {
		memset(used, false, sizeof(used));
		if (dfs(i)) {
			res++;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n,bit=0,i;
  cin>>n;
  int arr[n];
  for(i=0;i<n;i++)
  cin>>arr[i];
  sort(arr,arr+n);
   for(i=0;i<n-1;i++)
   if(arr[i] == arr[i+1]){
       cout<<"NO";
       bit++;
   break;
   }
  if(bit==0) cout<<"YES";
  
  
  
  
  
 return 0; 
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>

	using namespace std;
	int N ,ptr ,res;
	int A[100000];

int main()
{
	scanf ("%d", &N);
	for(int i=0; i<N; i++) {
		scanf ("%d", &A[i]);
	}

	sort (A, A+N);

	while(ptr<N){
		int cc=A[ptr], f=0;
		while(ptr<N && A[ptr]==cc){
			f++, ptr++;
		} 
		res += f%2;
	}
	printf ( "%d\n" , res );

}

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

int main() {
  int n;
  cin >> n;
  vector<int>ki(100001);
  vector<int>gu(100001);
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    if(i%2 == 0) ki[a]++;
    else gu[a]++;
  }
  int kimax = 0,kinem = 0,kmp = 0;
  int gumax = 0,gunem = 0,gmp = 0;
  for(int i = 0;i < 100001;i++){
    if(ki[i] > kimax){
      kinem = kimax;
      kimax = ki[i];
      kmp = i;
    }
    else if(ki[i] > kinem){
      kinem = ki[i];
    }
    if(gu[i] > gumax){
      gunem = gumax;
      gumax = gu[i];
      gmp = i;
    }
    else if(gu[i] > gunem){
      gunem = gu[i];
    }
  }
  int ans;
  if(kmp == gmp){
    if(kinem > gunem){
      ans = n-gumax-kinem;
    }
    else{
      ans = n-kimax-gunem;
    }
  }
  else{
    ans = n-kimax-gumax;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A.sort()
mod = 10**9 + 7

f = [1] * (N + 1)
for i in range(2, N + 1):
    f[i] = f[i - 1] * i % mod
fi = [pow(f[-1], mod - 2, mod)]
for i in range(N, 0, -1):
    fi += [fi[-1] * i % mod]
fi = fi[::-1]


def comb(n, r):
    return f[n] * fi[r] * fi[n - r]


ans = 0
for k in range(K - 1, N):
    ans += A[k] * comb(k, K - 1)
    ans %= mod
for k in range(N - K, -1, -1):
    ans -= A[k] * comb(N - k - 1, K - 1)
    ans %= mod
print(ans)

Measured memory_bytes: 65700
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int x;
  cin >> x;
  unordered_map<long long int,int> a;
  for(int i=-300;i<300;i++){
    a[x+pow(i,5)]=i;
  }
  for(int i=-300;i<300;i++){
    if(a.find(pow(i,5))!=a.end()){
      cout << i << " " << a[pow(i,5)] << endl;
      break;
    }
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b;
  cin >> a >> b;
  
  if(a > b){
    for(int i = 0; i < a; i++){
      cout << b;
    }
  }
  else{
    for(int i = 0; i < b; i++){
      cout << a;
    }
  }
  cout << '\n';
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  unordered_map<char, int64_t> RGB;
  for (char c : S) RGB[c]++;
  int64_t total = RGB['R'] * RGB['G'] * RGB['B'];

  int64_t remove = 0;
  for (int d = 1; d <= N; d++) {
    for (int i = 0; i + 2 * d < N; i++) {
      int j = i + d;
      int k = i + d * 2;
      if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
        remove++;
      }
    }
  }

  cout << total - remove << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define ALL(x) x.begin(), x.end()
using namespace std;
using ll=long long;
signed main()
{
	ll N; cin >> N; vector<vector<ll> > children(N+1);
	FOR(_i,N) {		auto i=_i+1;
		ll a; cin >> a;
		children[i].push_back( a);
		// children[a].push_back( i);
	}
	ll ans = 0;
	FOR(_i, N) { auto i=_i+1;
		for(auto c_i : children[i] ) { 
		
			if ( find(ALL(children[c_i]), ( i )) != children[c_i].end() )  {
				ans += 1;
			}
		}
	}
	cout << ans/2 << endl;
	return 0;
}

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  int ans=0;
  for(int i=0;i<K;i++){
    ans+=A.at(i);
  }
  cout<<ans;
}


Measured memory_bytes: 3624
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(input.readLine());
	for(int i=0;i<n;i++)
	    {
		char a[]=input.readLine().toCharArray();
	    
		for(int j=0;j<a.length-6;j++)
		    {
			if(a[j]=='H' && a[j+1]=='o' && a[j+2]=='s' && a[j+3]=='h' && a[j+4]=='i' && a[j+5]=='n' && a[j+6]=='o')
			    {
				a[j]='H';
				a[j+1]='o';
				a[j+2]='s';
				a[j+3]='h';
				a[j+4]='i';
				a[j+5]='n';
				a[j+6]='a';
			    }
		    }
		System.out.println(String.valueOf(a));
	    }
    }
}

Measured memory_bytes: 15044
import math
N = int(input())
for h in range(1,3501):
    for n in range(1,h):
        d = 4*h*n-N*n-N*h
        if d>0:
            w = N*h*n/d
            if w.is_integer():ans = [h,n,int(w)]
print(ans[0],ans[1],ans[2])

Measured memory_bytes: 43868
program main
  integer :: N, M
  integer :: X
  integer,allocatable :: C(:), A(:, :)
  integer :: i,j
  integer :: out,tmp
  logical,allocatable :: switch(:)
  integer,allocatable :: test(:)
  
  read(*,*) N, M, X
  allocate(C(N))
  allocate(A(N, M))
  allocate(switch(N))
  allocate(test(M))
  do i = 1, N
     read(*,*) C(i), A(i, :)
  end do
  if (all(sum(A(:,:), dim = 1) >= X)) then
     out = sum(C)
     do i=0,2**n-1
        do j=1,n
           switch(j) = btest(i,j-1)
        end do
        do j = 1,M
           test(j) = sum(A(:,j), mask=switch)
        end do
        if ( all(test >= X) ) then
           tmp = sum(C(:), mask=switch)
           if (tmp < out) then
              out = tmp
           end if
        end if
     end do
      write(*,'(i0)') out
  else
     write(*,'(i0)') -1
  end if
contains

  
end program main


Measured memory_bytes: 2864
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <climits>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<int,int> p;

int main()
{
  // input & declare
  ll s,c;
  ll result;
  cin >> s >> c;
  if (s >= c/2) {
    result = c / 2;
  }
  else
  {
    result = s;
    c -= s * 2;
    result += c / 4;
  }
  std::cout << result << '\n';
}


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

s1 = input()
s2 = input()
dirct = []
i = 0
while i<n:
    if s1[i] ==s2[i]:
        dirct.append(True)
        i+=1
        continue
    else:
        i+=2
        dirct.append(False)
        continue
dp = [0]*52
MAX = 1000000007
for i in range(len(dirct)):
    if i == 0:
        if dirct[0]:
            dp[0]=3
        else:
            dp[0]=6
        continue
    #| |
    if dirct[i] and dirct[i-1]:
        dp[i] = (dp[i-1]*2)%MAX
        continue
    #= |
    if dirct[i] and (not dirct[i-1]):   
        dp[i] = dp[i-1]
        continue
    #| =
    if (not dirct[i]) and dirct[i-1]:
        dp[i] = (dp[i-1]*2)%MAX
        continue
    #= =
    if (not dirct[i]) and (not dirct[i-1]):
        dp[i] = (dp[i-1]*3)%MAX

print(dp[len(dirct)-1]%MAX)



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

#define int long long




signed main()
{
    string S;
    int w;

    cin >> S;
    cin >> w;

    for(int i = 0; i < S.length(); i += w) {
        cout << S[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;

  int not_one_ind = 0;
  int not_one = 0;

  rep(i, S.size()) {
    if (S[i] - '0' != 1) {
      not_one_ind = i;
      not_one = S[i] - '0';
      break;
    }
  }
  if (not_one == 0) {
    cout << 1 << endl;
    return 0;
  }
  if (K - 1 < not_one_ind) {
    cout << 1 << endl;
  } else {
    cout << not_one << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;

const int N = 200010, P = 1000000007, A = 2010;

int n;
int a[N], b[N], fac[N * 4], ifac[N * 4];
int f[A * 2][A * 2];

void add(int& x, int y) {
  if ((x += y) >= P)
    x -= P;
}

void sub(int& x, int y) {
  if ((x -= y) < 0)
    x += P;
}

int main() {
//  freopen("test.in", "r", stdin);
//  freopen("test.out", "w", stdout);
  
  scanf("%d", &n);
  int ma = 0, mb = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    ma = max(ma, a[i]);
    mb = max(mb, b[i]);
  }
  for (int i = 0; i < n; ++i)
    ++f[ma - a[i]][mb - b[i]];
  for (int i = 0; i <= ma * 2; ++i)
    for (int j = 0; j <= mb * 2; ++j) {
      if (i) add(f[i][j], f[i - 1][j]);
      if (j) add(f[i][j], f[i][j - 1]);
    }
  int ans = 0;
  for (int i = 0; i < n; ++i)
    add(ans, f[ma + a[i]][mb + b[i]]);
  fac[0] = 1;
  int K = (ma + mb) * 2;
  for (int i = 1; i <= K; ++i)
    fac[i] = fac[i - 1] * (ll)i % P;
  ifac[1] = 1;
  for (int i = 2; i <= K; ++i)
    ifac[i] = -(P / i) * (ll)ifac[P % i] % P + P;
  ifac[0] = 1;
  for (int i = 1; i <= K; ++i)
    ifac[i] = ifac[i - 1] * (ll)ifac[i] % P;
  for (int i = 0; i < n; ++i)
    ans = (ans + (P - fac[(a[i] + b[i]) * 2]) * (ll)ifac[a[i] * 2] % P * ifac[b[i] * 2]) % P;
  if (ans & 1) ans += P;
  ans >>= 1;
  printf("%d\n", ans);

  return 0;
}



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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	int ans =0;
	rep(i,n){
		if(h[i] >= k) ans++;
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int n,k;
long long int w[100000];
int search(long long int mid){
  int i,j;
  int x=0;
  int count=0;
  for(i=0;i<n;i++){
    if(x+w[i]<=mid)x=x+w[i];
    else {x=w[i];count++;}
    
    if(count==k) return 0;
  } 
  return 1;
}
int main(){
  int i;
  long long int min=1,max=1000000000;
  long long int mid;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&w[i]);
    if(min<w[i])min=w[i];
  }
  while(min<max){
    mid=(min+max)/2;
    if(search(mid))max=mid;
    else min=mid+1;
  }
  printf("%lld\n",min);
  return 0;
}

Measured memory_bytes: 1376
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<double> V(N);
  for (auto& v : V)cin >> v;
  sort(begin(V), end(V));
  while (V.size() >= 2) {
    double val = (V[0] + V[1]) / 2;
    V.erase(V.begin(), V.begin() + 2);
    V.insert(lower_bound(begin(V), end(V), val), val);
  }
  cout << V[0] << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var s string
  fmt.Scan(&s)
  var a []int

  list := map[rune]int{
    '1': 1,
    '0': 0,
  }
  for _, v := range s {
    a = append(a, list[v])
  }
  invert := map[int]int{
    1: 0,
    0: 1,
  }
  var count int
  for i := 1; i < len(a); i++ {
    if a[i] == a[i-1] {
      a[i] = invert[a[i]]
      count++
    }
  }
  fmt.Println(count)
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

const int MAX_N=100010;
int dp[MAX_N];
int main(){
  int n;
  cin >> n;
  dp[0]=0;
  rep(i,MAX_N+1)dp[i]=n;
  dp[0]=0;
  rep(i,n){
    for(int pow6=1;pow6+i<=n;pow6*=6){
      dp[i+pow6]=min(dp[i]+1,dp[i+pow6]);
    }
    for(int pow9=1;pow9+i<=n;pow9*=9){
      dp[i+pow9]=min(dp[i]+1,dp[i+pow9]);
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <ctime>
#include <set>
#include <sstream>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n,i;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	i=sqrt(n);
    for(;i>=1;i--)
	{
		if(n%i!=0)continue;
		break;
	}
	int h=n/i,k=1;
	while(h>=10)
	{
		k++;
		h/=10;
	}
	cout<<k<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;, i < n; i++)
#define rep_2(i,n) for(int i=n, i > 0; i--)
using namespace std;
using ln = long long;

int main()
{
    int N,R;
    cin >> N >> R;
    if(N>=10)
        cout << R << endl;
    else
        cout << R + 100 * (10 - N) << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    char c;cin>>c;
    switch (c)
    {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
        cout<<"vowel"<<endl;
        break;
    default:
        cout<<"consonant"<<endl;
    }
}

Measured memory_bytes: 256
k,x = map(lambda x:int(x),input().split())

if x + k - 1 > 1000000:
	dst = list(range(x-k+1,1000001))
elif x - k + 1 < -1000000:
	dst = list(range(-1000000,x+k))
else:
	dst = list(range(x-k+1,x+k))

print(' '.join(list(map(str,dst))))

Measured memory_bytes: 3060
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2]<<endl;

}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int x,y,z; 
	cin>>x>>y>>z;
	cout<<z<< " "<<x<<" "<<y<<endl;
	return 0;
}


Measured memory_bytes: 256
var
  i,j,n:longint;
  ans:qword;
  s:string;
begin
  read(s);
  n:=length(s);
  for i:=1 to n do
    begin
      if s[i]='W' then
        begin
          inc(j);
          ans:=ans+(i-j);
        end;
    end;
  write(ans);
end.

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

int main(){
  int M1, D1;
  int M2, D2;
  cin >> M1 >> D1;
  cin >> M2 >> D2;
  
  int c = 0;
  if(M1==1 and D1==31){
    c=1;
  }else if(M1==2 and D1==28){
    c=1;
  }else if(M1==3 and D1==31){
    c=1;
  }else if(M1==4 and D1==30){
    c=1;
  }else if(M1==5 and D1==31){
    c=1;
  }else if(M1==6 and D1==30){
    c=1;
  }else if((M1==7 or M1==8 or M1==10 or M1==12) and D1==31){
    c=1;
  }else if((M1==9 or M1==11) and D1==30){
    c=1;
  }else{
    c=0;
  }

  cout << c;
  return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::cmp;

#[fastout]
fn main() {
    input! {
        r#as: [u64],
    }

    let mut ans = 0;
    let mut max = r#as[0];
    for &a in &r#as[1..] {
        max = cmp::max(max, a);
        ans += max - a;
    }
    println!("{}", ans);
}


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

int n, a[30][30], d;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "r", stdin);
#endif  // ONLINE_JUDGE
  cin >> n >> d;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < d; ++j) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int dist = 0;
      for (int k = 0; k < d; ++k) {
        dist += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
      }
      int x = sqrt(dist);
      if (x * x == dist) ++ans;
      // cout << dist << ' ' << x * x << '\n';
    }
  }
  cout << ans << '\n';
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, x, ans = 0;
  int a[100001];
  cin >> n >> x;

  rep(i, 0, n) cin >> a[i], ans += a[i];

  rep(i, 1, n) {
    multiset<int> ms;
    queue<int> q;
    int kans = x * i;
    rep(j, 0, i) ms.insert(a[j]), q.push(a[j]);
    rep(j, i, n + i) {
      ms.insert(a[j % n]);
      q.push(a[j % n]);
      kans += *ms.begin();
      ms.erase(q.front());
      q.pop();
    }
    ans = min(ans, kans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
int fun(){
   int A,B,C,K;
  cin >> A >> B >> C >> K;
  if (A > K) return K;
  else if (A+B > K) return A;
  else if (A+B+C > K) return A - (K - A - B);
  else return A - C;
}

int main(){
  cout << fun() << endl;
  return 0;
}

Measured memory_bytes: 3640
N, M, X = map(int, input().split(' '))
A = [int(a) for a in input().split(' ')]

count_0 = 0
for i in range(0, X):
    if i in A: count_0 += 1

count_N = 0
for i in range(X+1, N):
    if i in A: count_N += 1
print(min(count_0, count_N))

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

using namespace std;

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

  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n);
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      int dist = j - i;
      dist = min(dist, abs(x - i) + abs(y - j) + 1);
      ++ans[dist];
    }
  }
  for (int i = 1; i < n; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
import Control.Monad

main = do
  [d, g] <- map read . words <$> getLine
  pcs <- replicateM d $ map (read :: String -> Int) . words <$> getLine
  print $ solve g d $ reverse pcs

solve :: Int -> Int -> [[Int]] -> Int
solve _ _ [] = 1001
solve g i ([p,c]:pcs)
  | g <= 0         = 0
  | g <= p*i*100   = min ((g + (i*100) - 1) `div` (i*100)) (solve g (i-1) pcs)
  | g <= p*i*100+c = min p (solve g (i-1) pcs)
  | otherwise      = min (p + (solve (g-p*i*100-c) (i-1) pcs)) (solve g (i-1) pcs)


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

int main() {
  int a, b;
  cin>>a>>b;
  if (a <= b) {
    for (int i=0; i<b; i++) {
      cout<<a;
    }
  } else {
    for (int i=0; i<a; i++) {
      cout<<b;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    int left = 0;
    int ans = 0;
    for(int i = N - 2; i >= 0; i--)
    {
        if(H[i] >= H[i + 1]) left++;
        else left = 0;
        ans = max(left, ans);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  char s;
  cin >> s;
  switch (s) {
    case 'A':
      /* code */
      cout << "T" << endl;
      break;
    case 'C':
      cout << "G" << endl;
      break;
    case 'G':
      cout << "C" << endl;
      break;
    case 'T':
      cout << "A" << endl;
      break;
    default:
      break;
  }
  return 0;
}

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;
using P = pair<int,int>;

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; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    ll A, B;
    double Bin;
    cin >> A >> Bin;
    B = int(Bin*100+0.5);

    ll ans = A*B/100;

    cout << ans <<  endl;

    return 0;
}

Measured memory_bytes: 3704
#include<iostream>
using namespace std;
int main(){
	int a;
	int i;
	int s=0;
	
	while(cin>>a){
		if(a==0)break;
		s=0;
		a=1000-a;
		if(a>499){
			a=a-500;
			s=s+1;
		}
		for(i=0;i<4;i++){
			if(a>99){
				a=a-100;
				s=s+1;
			}
		}
		if(a>49){
			a=a-50;
			s=s+1;
		}
		for(i=0;i<4;i++){
			if(a>9){
				a=a-10;
				s=s+1;
			}
		}
		if(a>4){
			a=a-5;
			s++;
		}
		s=s+a;
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 2972
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a, b;
int x;

int main()
{
	scanf("%d%d", &a, &b);
	if((a+b)%2 == 0) x = (a + b)/2;
	else x = (a + b)/2 + 1;
	printf("%d\n", x);
	return 0;
}

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

a = [0]*n

for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        a[i] = 1
ans = 'No'        
for i in range(n-2):
    if a[i]*a[i+1]*a[i+2] ==1:
        ans = 'Yes'
        
print(ans)

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

using namespace std;

int main() {
	int n;
	ignore = scanf("%d", &n);
	
	long long ans = 1, bad = 1;
	for (int i = 0; i < n; i++) ans *= 3;
	
	while (n--) {
		int x;
		ignore = scanf("%d", &x);
		if (x % 2 == 0) bad *= 2;
	}
	
	printf("%lld\n", ans - bad);
	
	return 0;
}


Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const [N, M] = nextIntArray()
    o.list.shift()
    let a = new Set(o.list.map(el => parseInt(el)))
    let dp = {}
    dp[0] = 1n
    if(a.has(1)) dp[1] = 0n
    else dp[1] = 1n
    for(let i = 2;i<=N; i++){
        if(a.has(i)) dp[i] = 0n
        else {
            dp[i] = dp[i-1] + dp[i-2]
        }        
    }
    console.log(Number(dp[N] % 1000000007n))
}
Main()


Measured memory_bytes: 499240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication30 {
    class Program {
        static void Main(string[] args) {

            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            var result = Method(a, b, c);
            Console.WriteLine(result);
        }

        private static int Method(int a, int b,int c) {

            //（上底＋下底）×高さ÷２
            return (a + b) * (c/2);
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <cmath>
#define SIZE 105
#define INF 1000000000000000000LL

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

vector <int> vec[SIZE];
int mx[SIZE];
int A[SIZE],B[SIZE];

int dfs(int v,int p,int d=0)
{
	int df=vec[v].size();
	if(p>=0) df--;
	mx[d]=max(mx[d],df);
	int ret=d;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) ret=max(ret,dfs(to,v,d+1));
	}
	return ret;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
		A[i]=a,B[i]=b;
	}
	int col=n;
	ll mn=n;
	for(int i=0;i<n;i++)
	{
		memset(mx,0,sizeof(mx));
		int dep=dfs(i,-1);
		//dep+1 色
		ll way=1;
		for(int i=0;i<dep;i++)
		{
			if(way>INF/mx[i]+1)
			{
				way=-1;
				break;
			}
			way=way*(ll) mx[i];
		}
		if(way!=-1)
		{
			if(col>dep+1)
			{
				col=dep+1;
				mn=way;
			}
			if(col==dep+1) mn=min(mn,way);
		}
	}
	for(int i=0;i<n-1;i++)
	{
		memset(mx,0,sizeof(mx));
		int dep=max(dfs(A[i],B[i]),dfs(B[i],A[i]));
		ll way=2;
		for(int i=0;i<dep;i++)
		{
			if(way>INF/mx[i]+1)
			{
				way=-1;
				break;
			}
			way=way*(ll) mx[i];
		}
		if(way!=-1)
		{
			if(col>dep+1)
			{
				col=dep+1;
				mn=way;
			}
			if(col==dep+1) mn=min(mn,way);
		}
	}
	printf("%d %lld\n",col,mn);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>

#define MAX_WH 20

typedef std::pair<int, int> P;

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

int W, H, sx, sy;
char field[MAX_WH][MAX_WH];
int solve();

int bfs();

int main(){
	while(true){
		std::cin >> W >> H;
		if(W == 0 && H == 0)
			break;

		for(int i = 0; i < H; ++i){
			for(int j = 0; j < W; ++j){
				char in;
				std::cin >> in;

				if(in == '@')
					sx = j, sy = i;

				field[j][i] = in;
			}
		}

		std::cout << solve() << std::endl;
	}
	return 0;
}

int solve(){
	return bfs();
}

int bfs(){
	std::queue<P> que;
	int ans = 0;
	bool flag[MAX_WH][MAX_WH];

	for(int i = 0; i < MAX_WH; ++i){
		for(int j = 0; j < MAX_WH; ++j)
			flag[i][j] = true;
	}

	que.push(P(sx, sy));
	flag[sx][sy] = false;

	while(!que.empty()){
		++ans;
		P p = que.front(); que.pop();

		for(int i = 0; i < 4; ++i){
			int nx = p.first + dx[i], ny = p.second + dy[i];

			if(nx >= 0 && ny >= 0 && nx < W && ny < H && field[nx][ny] != '#' && flag[nx][ny]){
				flag[nx][ny] = false;
				que.push(P(nx, ny));
			}
		}
	}

	return ans;
}

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

#define int            long long int
#define float          long double
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define inf            1e18
#define set_pre(x,y)   fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
using namespace std;
int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    int n;
    cin>>n;
    int w;
    cin>>w;
    vector<int>wt(n,0);
    vector<int>v(n,0);
    for(int i=0;i<n;i++){
        cin>>wt[i]>>v[i];
    }
    vector<vector<int>>dp(n+1,vector<int>(w+1,0));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            if(j>=wt[i-1])
                dp[i][j]=max(dp[i][j],dp[i-1][j-wt[i-1]]+v[i-1]);
        }
    }
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 80256
#include <iostream>
#include<vector>
#include<deque>
#include<algorithm>
//Compiler version g++ 6.3.0
#define int long long int
using namespace std;

deque<int> d;
int32_t main()
{
  int n,t;cin>>n;
  for(int i=1;i<=n;i++){
    cin>>t;
    if(i&1){
      d.push_back(t);
    }
    else {
      d.push_front(t);
    }
  }
  vector<int> v;
  for(auto x: d){
    v.push_back(x);
  }
  if((n&1)){
    reverse(v.begin(),v.end());
  }
  for(auto x:v){
    cout<<x<<" ";
  }
}



Measured memory_bytes: 5488
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

struct edge {
	int s, t, cost;
	edge(int s, int t, int cost) : s(s), t(t), cost(cost) {}
};

int main() {
	int N; cin >> N;
	vector<edge> e;
	vector<vector<int>> goal(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			int a; cin >> a;
			goal[i][j] = a;
			if (i < j)
				e.push_back(edge(i, j, a));
		}
	}
	sort(e.begin(), e.end(), [&](edge e1, edge e2) { return e1.cost < e2.cost; });

	vector<vector<ll>> mn_cost(N, vector<ll>(N, (1LL << 60)));
	for (int i = 0; i < N; ++i)
		mn_cost[i][i] = 0;
	ll res = 0;
	for (auto ei : e) {
		int s = ei.s, t = ei.t;
		int cost = ei.cost;
		if (mn_cost[s][t] < cost) {
			cout << -1 << endl;
			return 0;
		}
		else if (mn_cost[s][t] > cost) {
			res += cost;
			for (int i = 0; i < N; ++i) {
				for (int j = i + 1; j < N; ++j) {
					ll new_path1 = mn_cost[i][s] + mn_cost[t][j] + cost;
					ll new_path2 = mn_cost[i][t] + mn_cost[s][j] + cost;
					ll new_path = min(new_path1, new_path2);
					if (new_path < goal[i][j]) {
						cout << -1 << endl;
						return 0;
					}
					mn_cost[i][j] = mn_cost[j][i] = min(mn_cost[i][j], new_path);
				}
			}
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1912
#include <stdio.h>

int main()
{
    int m,d,i,j,count = 0,d1,d10;

    scanf("%d %d",&m,&d);

    for (i = 1; i <= d; i++)
    {
        d10 = i / 10;
        d1 = i % 10;
        if((d10 >= 2) && (d1 >= 2))
        {
            if(d10 * d1 <= m)
            {
                //printf("%d %d %d",d1,d10,d1 * d1);
                count++;
            }
        }
    }
    
    
    printf("%d",count);
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int M = nextInt();

  pair<int,int> p[N];
  REP(i, N) {
    p[i].first = nextInt();
    p[i].second = nextInt();
  }
  sort(p, p+N);

  ll ans = 0;
  REP(i, N) {
    int buy = min(M, p[i].second);
    ans += (ll)buy * p[i].first;
    M -= buy;
  }

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

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main(){
    string ta,ha;
    int tap = 0 ,hap = 0,n;
    
    cin >> n;
    while(n--){
        cin >> ta >> ha;
        
        if(ta > ha) tap += 3;
        else if(ta < ha) hap += 3;
        else{
            tap++;
            hap++;
        }
    }
    cout << tap << ' ' << hap << endl;

    return 0;
}

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

using namespace std; 

const int maxn = 2e6; 
const int mod = 1e9 + 7; 

int ans, x[7], y[7]; 
int fac[maxn + 5], ivf[maxn + 5]; 

int add(int x, int y, int p = mod) {
    return (x += y) >= mod ? x - mod : x; 
}

int fpw(int x, int k, int p = mod) {
    int ret = 1; 
    while (k) {
        if (k & 1) ret = 1ll * ret * x % p; 
        x = 1ll * x * x % p; k >>= 1; 
    }
    return ret; 
}

int C(int n, int m) {
    return 1ll * fac[n + m] * ivf[n] % mod * ivf[m] % mod; 
}

int solve(int x1, int y1, int x2, int y2) {
    int ret = 0; 
    for (int X = x[3]; X <= x[4]; X++) {
        ret = add(ret, 1ll * (X + y[4] + 1) * C(X - x1, y[4] - y1) % mod * C(x2 - X, y2 - y[4] - 1) % mod); 
        ret = add(ret, mod - 1ll * (X + y[3]) * C(X - x1, y[3] - y1 - 1) % mod * C(x2 - X, y2 - y[3]) % mod); 
    }
    for (int Y = y[3]; Y <= y[4]; Y++) {
        ret = add(ret, 1ll * (Y + x[4] + 1) * C(Y - y1, x[4] - x1) % mod * C(y2 - Y, x2 - x[4] - 1) % mod); 
        ret = add(ret, mod - 1ll * (Y + x[3]) * C(Y - y1, x[3] - x1 - 1) % mod * C(y2 - Y, x2 - x[3]) % mod); 
    }
    return ret; 
}   

int main() {
    fac[0] = 1; 
    for (int i = 1; i <= maxn; i++) fac[i] = 1ll * fac[i - 1] * i % mod; 
    ivf[maxn] = fpw(fac[maxn], mod - 2); 
    for (int i = maxn - 1; i >= 0; i--) ivf[i] = 1ll * ivf[i + 1] * (i + 1) % mod; 
    for (int i = 1; i <= 6; i++) {
        scanf("%d", &x[i]); 
    }
    for (int i = 1; i <= 6; i++) {
        scanf("%d", &y[i]); 
    }
    x[1]--; 
    y[1]--; 
    x[6]++; 
    y[6]++; 
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= 2; j++) {
            for (int k = 5; k <= 6; k++) {
                for (int l = 5; l <= 6; l++) {
                    if ((i + j + k + l) & 1) ans = add(ans, mod - solve(x[i], y[j], x[k], y[l])); 
                    else ans = add(ans, solve(x[i], y[j], x[k], y[l])); 
                }
            }
        }
    }
    cout << ans << '\n'; 
    return 0; 
}

Measured memory_bytes: 15872
while True:
    n, x = map(int, input().split())
    if (n, x) == (0, 0): break
    ans = []
    for i in range(n, 1, -1):
        for j in range(1, n):
            tmp = x-(i+j)
            if tmp > n: continue
            if tmp > 0 and i > 0 and j > 0:
                if tmp != j and tmp != i and i != j:
                    pmt = sorted([i, j, tmp])
                    if not pmt in ans: ans.append(pmt)
    print(len(ans))

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

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

    int n, m;
    cin >> n >> m;

    int large, small;
    if(n > m) large = n, small = m;
    else large = m, small = n;
    ll ans = 1;
    int MOD = 1e9+7;

    if(abs(n-m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    else {
        ll tmp = 1;
        ll val = 1;
        int interval = large - 1;
        if(abs(n-m) % 2 == 0) {
            for(ll i = 1; i <= large; ++i) {
                tmp *= i;
                tmp %= MOD;
            }
            for(ll i = 1; i <= small; ++i) {
                val *= i;
                val %= MOD;
            }
            ans = ((tmp*val) % MOD) * 2 % MOD;
        }
        else {
            for(ll i = 1; i <= large; ++i) {
                tmp *= i;
                tmp %= MOD;
            }
            for(ll i = 1; i <= interval; ++i) {
                val *= i;
                val %= MOD;
            }
            ans = (tmp*val) % MOD;
        }
    }

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

Measured memory_bytes: 3600
#include <iostream>

#ifdef LOCAL
  #define debugEcho(expr) cout << expr << "\n";
#else
  #define debugEcho(expr)
#endif

using namespace std;

#define at ,<=,
#define to ,<,
#define in ,
#define forrange(...)  forrange1(forrange2, (__VA_ARGS__))
#define forrange1(X, A) X A
#define forrange2(i, s, op, e) for (int i = (s); i op (e); i++)

int main() {
  int A;
  int B;
  cin >> A;
  cin >> B;
  if (A + B >= 10) {
    cout << "error\n";
  } else {
    cout << (A + B) << "\n";
  }
}


Measured memory_bytes: 256
N, D = map(int, input().split())
X = [[0] * D for _ in range(N)]
for i in range(N):
  X[i] = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    dist = 0.0
    for k in range(D):
      dist += (X[i][k] - X[j][k]) ** 2
    dist = dist ** 0.5
    if dist.is_integer():
      ans += 1
print(ans)


Measured memory_bytes: 3064
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(void){
  string str;
  int n;
  cin >> n;
  cin >> str;
  for (auto ite=str.begin();ite!=str.end();++ite){
      *ite = (*ite-'A'+n)%26+'A';
  }
  cout << str << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
A = list()

for i in range(n):
    A.append(list(map(int, input().split())))

B = list()
for i in range(m):
    B.append(int(input()))
res = []
for i in range(n):
  value = 0
  for j in range(m):
    value += A[i][j] * B[j]
  print(value)


Measured memory_bytes: 6012
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{ int p, l, r, depth;};
struct Node T[MAX];

int flag,k,left;

void maketree(int id, int c){
  T[c].p = id;
  if(flag == 0){ 
    T[id].l = c;
    left = c;
  }
  else{
    T[left].r = c;
    left = c;
  }
}

void print(int u){
  if(T[u].p == -1){
    if(T[u].l == -1) printf("node %d: parent = %d, depth = %d, root, []", u, T[u].p, T[u].depth);
    else{
      left = T[u].l;
      printf("node %d: parent = %d, depth = %d, root, [", u, T[u].p, T[u].depth);
      printf("%d", left);
      while(1){
	if(T[left].r == -1) break;
	printf(", ");
	printf("%d", T[left].r);
	left = T[left].r;
      }
      printf("]");
    }
  }
  else{
    if(T[u].l == -1) printf("node %d: parent = %d, depth = %d, leaf, []", u, T[u].p, T[u].depth);
    else{
      left = T[u].l;
      printf("node %d: parent = %d, depth = %d, internal node, [", u, T[u].p, T[u].depth);
      printf("%d", left);
      while(1){
	if(T[left].r == -1) break;
	printf(", ");
	printf("%d", T[left].r);
	left = T[left].r;
      }
      printf("]");
    }
  }
}

int main(){
  int i, j, id, c, l, n, parent;
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r =NIL;
  }
  T[0].depth = 0;
  for ( i = 0; i < n; i++ ){
    scanf("%d%d", &id, &k);
    flag = 0;
    if(k != 0){
      for ( j = 0; j < k; j++ ){
	scanf("%d", &c);
	maketree(id, c);
	flag++;
      }
    }
  }
  for ( i = 0; i < n; i++ ){
    parent = T[i].p;
    while(1){
      if(parent == -1) break;
      parent = T[parent].p;
      T[i].depth++;
    }
    print(i);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2164
from collections import *
H,W=map(int,input().split())
S=[input() for i in range(H)]
INF=10**9
D=[[INF]*W for i in range(H)]
if S[0][0]=='.':
  D[0][0]=0
else:
  D[0][0]=1
Q=deque([(0,0)])
v=0
while len(Q):
  v=Q.popleft()
  if v[0]!=H-1:
    if S[v[0]][v[1]]=='.' and S[v[0]+1][v[1]]=='#':
      if D[v[0]][v[1]]+1<D[v[0]+1][v[1]]:
        D[v[0]+1][v[1]]=D[v[0]][v[1]]+1
        Q.append((v[0]+1,v[1]))
    else:
      if D[v[0]][v[1]]<D[v[0]+1][v[1]]:
        D[v[0]+1][v[1]]=D[v[0]][v[1]]
        Q.append((v[0]+1,v[1]))
  if v[1]!=W-1:
    if S[v[0]][v[1]]=='.' and S[v[0]][v[1]+1]=='#':
      if D[v[0]][v[1]]+1<D[v[0]][v[1]+1]:
        D[v[0]][v[1]+1]=D[v[0]][v[1]]+1
        Q.append((v[0],v[1]+1))
    else:
      if D[v[0]][v[1]]<D[v[0]][v[1]+1]:
        D[v[0]][v[1]+1]=D[v[0]][v[1]]
        Q.append((v[0],v[1]+1))
print(D[-1][-1])

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    int N, K;
    cin >> N >> K;
    vector<LL> cum;
    string S;
    cin >> S;

    if (S[0] == '0')
    {
        cum.push_back(0);
    }

    char curr_c = S[0];
    int curr_n  = 1;

    REP1 (i, N - 1)
    {
        if (S[i] == curr_c)
            curr_n++;
        else
        {
            if (cum.size())
                cum.push_back(cum.back() + curr_n);
            else
                cum.push_back(curr_n);
            curr_c = S[i];
            curr_n = 1;
        }
    }

    if (cum.size())
        cum.push_back(cum.back() + curr_n);
    else
        cum.push_back(curr_n);

    LL ans = curr_n;
    int L  = cum.size();

    for (int i = 0; i < L; i += 2)
    {
        
        LL tmp = cum[min(L - 1, i + 2 * K)];
        if (i != 0)
            tmp -= cum[i - 1];
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 1528
#include <stdio.h>
#include <math.h>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
inline double sq(double a) { return a*a; }
#define INF (1e100)
#define EPS (1e-9)

int n;
double hx, hy, mx, my, xs[32], ys[32], ds[32], ws[32][32];
pair<double, int> ns[32];
map<pair<int, int>, double> mem;

bool rec(int b, int at, double t) {
    if (b == (1<<n)-1) return true;
    if (mem.count(mp(b, at)) && mem[mp(b, at)] < t) return false;
    mem[mp(b, at)] = t;
    rep (i, n) {
        const int ix = ns[i].second;
        if (b&(1<<ix)) continue;
        double nt = t + ws[at][ix];
        if (nt > ds[ix]-EPS) return false;
        if (rec(b|(1<<ix), ix, nt)) return true;
    }
    return false;
}

int main() {
    for (;;) {
        scanf("%d%lf%lf%lf%lf", &n, &hx, &hy, &mx, &my);
        if (n == 0) return 0;
        rep (i, n) scanf("%lf%lf", xs+i, ys+i);
        rep (i, n) ds[i] = sqrt(sq(xs[i]-mx) + sq(ys[i]-my));
        rep (i, n) ns[i] = mp(ds[i], i);
        sort(ns, ns+n);
        rep (i, n) rep (j, n) {
            ws[i][j] = sqrt(sq(xs[i]-xs[j]) + sq(ys[i]-ys[j]));
        }
        mem.clear();
        bool ans = false;
        rep (i, n) {
            double t = sqrt(sq(xs[i]-hx) + sq(ys[i]-hy));
            if (t < ds[i]-EPS && rec(1<<i, i, t)) { ans = true; break; }
        }
        puts(ans ? "YES" : "NO");
    }
}

Measured memory_bytes: 53480
class RMQ:
    def __init__(self, length, ini_num = float("inf")):
        self.length = 1
        while self.length < length:
            self.length <<= 1
        self.segtree = [ini_num] * (2 * self.length - 1)

    def update(self, index, n):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] = n
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = min(self.segtree[leaf_index * 2 + 1], self.segtree[leaf_index * 2 + 2])

    def find(self, a, b, index, l, r):
        if a == b:
            return self.segtree[self.length - 1 + a]
        elif a <= l <= r <= b:
            return self.segtree[index]
        elif b < l or r < a:
            return float("inf")
        else:
            return min(self.find(a, b, index * 2 + 1, l, (l + r) // 2), self.find(a, b, index * 2 + 2, (l + r) // 2 + 1, r))

v_num, query = (int(n) for n in input().split(" "))
rmq = RMQ(v_num, 2147483647)
for _ in range(query):
    com, i, n = (int(n) for n in input().split(" ") )
    if com == 0:
        rmq.update(i, n)
    else:
        print(rmq.find(i, n, 0, 0, rmq.length - 1))

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

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

    ll ans = 0;

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

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


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

using namespace std;

int main(int argc, char *argv[]) {
  vector<int> a, b;
  string s;
  cin >> s;
  s += 'T';
  int now = 0, dir = 0;
  for (auto c : s) {
    if (c == 'F') {
      now++;
    } else {
      dir ? b.push_back(now) : a.push_back(now);
      dir ^= 1;
      now = 0;
    }
  }
  auto check = [](int val, vector<int> a) {
    for (auto x : a) {
      val += x;
    }
    vector<int> f(val + 1);
    f[0] = 1;
    for (auto x : a) {
      for (int j = val; j - 2 * x >= 0; j--) {
        f[j] |= f[j - 2 * x];
      }
    }
    return f[val];
  };
  int x, y;
  cin >> x >> y;
  cout << (check(abs(x - a[0]), {a.begin() + 1, a.end()}) && check(abs(y), b) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 384