akhauriyash/Code-Regression huggingface dataset:
# 適当な道に沿って並べていくだけ
# 自然なindexで作ったあと偶数行を反転すればよい

H,W = map(int,input().split())
N = int(input())
A = [int(x) for x in input().split()]

import numpy as np
c = np.zeros(H*W,dtype=np.int32)

first = 0
for i,a in enumerate(A,1):
  c[first:first+a] = i
  first += a
  
c2d = c.reshape((H,W))

c2d[1::2,:] = c2d[1::2,::-1]

for i in range(H):
  print(' '.join(c2d[i].astype(str)))


Measured memory_bytes: 12564
#include <bits/stdc++.h>
using namespace std;
int main(){
    double A,B,H,M,H_kakudo,M_kakudo,sita;
    cin >> A >> B >> H >> M;
    H_kakudo = H*30+M*0.5;
    M_kakudo = M*6;
    sita=max(H_kakudo,M_kakudo)-min(H_kakudo,M_kakudo);
    if(sita>180){
        sita=360-sita;
    }
    sita=sita*M_PI/180.00000000;
    printf("%.10f",sqrt(A*A+B*B-2*A*B*cos(sita)));
}

Measured memory_bytes: 4208
#include <stdio.h>

int main(){
  int D;
  int c[30];
  int s[370][30];
  int t[400];
  int last[30]={};
  int ans=0;
  
  scanf("%d",&D);
  for(int i=1;i<=26;i++)
    last[i]=0;
  for(int i=1;i<=26;i++)
    scanf("%d",c+i);
  for(int i=1;i<=D;i++)
   for(int j=1;j<=26;j++)
     scanf("%d",&s[i][j]);
  for(int i=1;i<=D;i++)
    scanf("%d",t+i);
  for(int d=1;d<=D;d++){
    ans+=s[d][t[d]];
    last[t[d]]=d;
    for(int j=1;j<=26;j++){
      ans-=c[j]*(d-last[j]);
    }
    printf("%d\n",ans);
  }
  
  return 0;
}

Measured memory_bytes: 1772
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1000000007;
const llint big=(llint)(2.19e18)+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
using pli=pair<llint,int>;
using daic=priority_queue<pli,vector<pli>,greater<pli>>;
int main(void){
	int n,K,i,j;cin>>n>>K;
	vector<llint>dp={1};
	//それぞれのパターン
	llint ans=0;
	llint rui[101]={1,0};
	for(i=0;i<100;i++){rui[i+1]=rui[i]*(K+1);rui[i+1]%=mod;}
	for(int nu=n;nu>0;nu--){
		vector<llint>ddp(dp.size()+1+ (dp.size()/nu));
		//i=0だけ増やす
		for(i=0;i<=min(K,nu);i++){
			for(j=0;j<dp.size();j++){
				int tg=j + (i+j)/nu;
				ddp[tg]+=dp[j];
				ans+=(((i+j)%nu)*dp[j])%mod * rui[nu-1];
				ans%=mod;
			}
		}
		for(i=nu+1;i<=K;i++){ans+=rui[n-1]*i;ans%=mod;}
		//ダメパターンの可能性
		for(j=0;j<dp.size();j++){
			ddp[j]+=dp[j]*max(0,K-nu);ddp[j]%=mod;
			ans+=(j*dp[j]*max(0,K-nu))%mod * rui[nu-1];
			ans%=mod;
		}
		for(j=dp.size();j<ddp.size();j++){ddp[j]%=mod;}
		swap(ddp,dp);
	}
	cout<<ans<<endl;
	RE;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b;
    scanf("%d%d", &a, &b);
    char s[13];
    scanf("%s", s);

    char number[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    int flag = 1;
    for (int i = 0; i < a; i++){
        if (s[i] == '-') flag = 0;
    }
    if (s[a] != '-') flag = 0;
    for (int i = a + 1; i < a + b + 1; i++){
        if (s[i] == '-') flag = 0;
    }

    if (flag) printf("%s\n", "Yes");
    else printf("%s\n", "No");

    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> a( N );
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}

	vector<int> color( 9 );
	for( int i = 0; i < N; i++ ) {
		int aa = a[i];
		if( aa < 400 ) color[0]++;
		else if( aa < 800 ) color[1]++;
		else if( aa < 1200 ) color[2]++;
		else if( aa < 1600 ) color[3]++;
		else if( aa < 2000 ) color[4]++;
		else if( aa < 2400 ) color[5]++;
		else if( aa < 2800 ) color[6]++;
		else if( aa < 3200 ) color[7]++;
		else color[8]++;
	}
	int mi = 0;
	for( int i = 0; i < 8; i++ ) {
		if( color[i] ) mi++;
	}
	int ma = mi + color[8];
	if( mi == 0 ) mi = 1;

	cout << mi << " " << ma << endl;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>

using namespace std;

int main(void){

  string s;

  char h[6][5] = {'a','b','c','d','e','f',
		  'g','h','i','j','k','l',
		  'm','n','o','p','q','r',
		  's','t','u','v','w','x',
		  'y','z','.','?','!',' ' };
 back:
  while( cin >> s ){
    
    int l = s.size();
    if( l % 2 == 1 ){
      cout << "NA" << endl;
      continue;
    }
    
    int x[200] = {0},y[200] = {0},I = 0;
    for( int i = 0 ; i < l ; i += 2 ){
      x[I] = s[i] - '0';
      y[I] = s[i + 1] - '0';
      if( x[I] > 6 || y[I] > 5 || x[I] <= 0 || y[I] <= 0 ){
	cout << "NA" << endl;;
	goto back;
      }
      else{
	x[I]--;
	y[I]--;
      }
      I++;
    }
    for( int i = 0 ; i < I ; i++ ){
      cout << h[x[i]][y[i]];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1176
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val k = in.readLine().toInt

    val memo = mutable.HashMap.empty[(Int, Int), Int]

    def gcd(a: Int, b: Int): Int = {
      if (b == 0) {
        a
      } else if (a < b) {
        gcd(b, a)
      } else {
        memo.getOrElseUpdate((a, b), gcd(b, a % b))
      }
    }

    def gcd3(a: Int, b: Int, c: Int): Int = {
      gcd(a, gcd(b, c))
    }

    var sum = 0L

    for (a <- 1 to k) {
      for (b <- 1 to k) {
        for (c <- 1 to k) {
          sum += gcd3(a, b, c)
        }
      }
    }
    out.println(sum)

    out.flush()
  }

}


Measured memory_bytes: 59888
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}
$temp = getq(1);
$H = $temp[0];
$W = $temp[1];
$MAP = array();
for($i=0;$i<$H;$i++){
    $temp = getq();
    if(strpos($temp,'#') === false){}else{
        array_push($MAP,$temp);
    }
}
for($i=0;$i<strlen($MAP[0]);$i++){
    $check = true;
    for($j=0;$j<count($MAP);$j++){
        if($MAP[$j][$i]=='#')$check=false;
    }
    if($check){
        for($j=0;$j<count($MAP);$j++){
            $MAP[$j][$i]="0";
        }
    }
}

//print_r($MAP);

for($i=0;$i<count($MAP);$i++){
    if($MAP[$i]!=="")
        echo str_replace('0',"","$MAP[$i]\n");
}
?>

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


int main()
{
	// freopen("input.txt", "r", stdin);

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	string a,b;
	cin >> a >> b;

	string tempA = a, tempB = b;
	reverse(tempA.begin(), tempA.end());
	reverse(tempB.begin(), tempB.end());
	if (a == tempB && b == tempA) cout << "YES\n";
	else cout << "NO\n";



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char abc[4];
    scanf("%s", abc);
    if (abc[0] < abc[1] || abc[0] < abc[2])
    {
        abc[0] += 1;
        abc[1] = abc[0];
        abc[2] = abc[0];
    }
    if (abc[0] >= abc[1] || abc[0] >= abc[2])
    {
        abc[1] = abc[0];
        abc[2] = abc[0];
    }
    printf ("%s", abc);
    return (0);
}


Measured memory_bytes: 128
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int k,a,b;

  cin >> k >> a >> b;
  bool flg;
  flg = false;
  for(ii=a;ii<=b;ii++){
    if(ii % k == 0){
      flg = true;
    }
  }

  if(flg){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
  return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
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...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string T;
    cin >> T;
    ll ans = 0;

    auto score = [&](int len, char c) {
        len = (len + 1) / 2;
        if (c == 'r') {
            return p * len;
        } else if (c == 's') {
            return r * len;
        } else if (c == 'p') {
            return s * len;
        } else {
            return 0LL;
        }
    };

    REP(i, 0, k) {
        char prev = T[i];
        int len = 0;
        for (int j = i; j < n; j += k) {
            if (T[j] == prev) {
                len++;
            } else {
                ans += score(len, prev);
                len = 1;
            }
            prev = T[j];
        }
        ans += score(len, prev);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(","); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    map<string, int> m;
    vector<string> names = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    int index = find(all(names), s) - names.begin();
    int ans = 7 - index;
    cout << ans << "\n";
    return 0; 
}




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

int memo[300];
int dp(int num);

int main(void){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;

		memset(memo, -1, sizeof(memo));

		cout << (int)ceil(dp(n) / 3650.0) << endl;
		//cout << dp(n) << endl;
		
	}

	return 0;
}

int dp(int num){
	if(num < 0) return 0;
	if(memo[num] != -1) return memo[num];
	if(num <= 1) return memo[num] = 1;

	return memo[num] = dp(num-1) + dp(num-2) + dp(num-3);
}

Measured memory_bytes: 1164
A,B,M = (int(x) for x in input().split())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
min_yen = min(a_list)+min(b_list)
m_list = []
for i in range((M)):
    m = [int(x) for x in input().split()]
    a = a_list[m[0]-1]
    b = b_list[m[1]-1]
    m = m[2]
    coupon_used = (a+b)-m
    min_yen = min(min_yen,coupon_used)    

print(min_yen)

Measured memory_bytes: 18488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    ll ans = n%k;
    cout<<min(ans,k-ans)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
std::string S;
int ans = 1 << 30;
int main() {
	std::cin >> S;
	for (int i = 0; i < 26; i++) {
		char ser = 'a' + i;
		int sum = 0;
		int max = 0;
		for (auto u : S) {
			if (u == ser)max = std::max(sum, max), sum = -1;
			sum++;
		}
		max = std::max(sum, max);
		ans = std::min(ans, max);
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

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

int main() {
    int n, k;
    cin >> n >> k;
    map<int, int> map;
    REP(i, n) {
        int a;
        cin >> a;
        map[a]++;
    }

    if (map.size() <= k) cout << 0 << endl;
    else {
        vector<int> v(map.size());
        int j = 0;
        FOR(i, map) {
            v[j] = i->second;
            j++;
        }
        sort(ALL(v));
        cout << accumulate(v.begin(), v.begin()+v.size()-k, 0) << endl;
    }
}


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

int main()
{
int n;
cin>>n;
map<long,long> mp;
for(int i=0;i<n;i++)
{
    int x;
    cin>>x;
    mp[x]++;
}
long ans=0;
for(auto i:mp)
{
    if(i.first<=i.second)
ans+=i.second-i.first;
else ans+=i.second;
}
cout<<ans<<endl;
return 0;
}
 


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

using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> X(M);
    for(int i=0;i<M;i++){
        cin >> X.at(i);
    }

    sort(X.begin(),X.end());
    int ans = 0;
    if(N<M){

    vector<int> L(M);
    for(int i=0;i<M-1;i++){
        L.at(i) = X.at(i+1) - X.at(i);
    }

    sort(L.begin(),L.end(),greater<int>());
    int sum = 0;
    for(int i=0;i<N-1;i++){
        sum += L.at(i);
    }
    ans = X.at(M-1) - X.at(0) - sum;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int X;
    cin >> X;
string A;
cin >> A;
int B=0;
if(A.size()<=X){cout << A << endl;}else{
    B=X-A.size();
    for(int i=0;i<X;i++){
        cout <<A.at(i);
    }
    cout <<"..." << endl;
}
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 100000000

int main() {
	int n, k;
	long long ans;
	cin >> n >> k;

	ans = k * pow(k-1, n-1);
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 3856
A, B = map(int, input().split())

L1, R1 = -(-(100*A) // 8), -(-(100*(A+1)) // 8) - 1
L2, R2 = -(-(100*B) // 10), -(-(100*(B+1)) // 10) - 1
L = max(L1, L2)
R = min(R1, R2)

if L <= R:
    print(L)
else:
    print(-1)


Measured memory_bytes: 3060
MAX = 1000000
prime = [1] * MAX
prime[0], prime[1] = 0, 0
i = 2
while i * i < MAX:
    j = 2
    while i * j < MAX:
        prime[i * j] = 0
        j += 1
    i += 1
for k in range(1, len(prime)):
    prime[k] += prime[k-1]

while True:
    try:
        n = int(raw_input())
        print prime[n]
    except EOFError:
        break

Measured memory_bytes: 67676
# -*- coding: utf-8 -*-


def BubbleSort(C, N):
    flag = 1
    while flag == 1:
        flag = 0
        for i in range(N - 1, 0, -1):
            if int(C[i][1]) < int(C[i - 1][1]):
                C[i], C[i - 1] = C[i - 1], C[i]
                flag = 1
    return C


def SelectionSort(C, N):
    flag = 0

    for i in range(N):

        if N == 1:
            break

        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
                flag = 1

        if flag == 1:
            C[i], C[minj] = C[minj], C[i]

        flag = 0

    return C


def print_line(A):
    for i in range(len(A)):
        if i == len(A) - 1:
            print('{0}{1}'.format(A[i][0], A[i][1]))
        else:
            print('{0}{1} '.format(A[i][0], A[i][1]), end='')


def check_stable(Bubble_A, Select_A):
    for i in range(len(Select_A)):
        if Bubble_A[i][0] != Select_A[i][0]:
            print('Not stable')
            break
        elif i == len(Select_A) - 1:
            print('Stable')


N = int(input())
A = list(input())

A = [A[i:i+2] for i in range(0, len(A), 3)]

Bubble_A = BubbleSort(A[:], N)
Select_A = SelectionSort(A[:], N)

print_line(Bubble_A)
print('Stable')
print_line(Select_A)
check_stable(Bubble_A, Select_A)



Measured memory_bytes: 5620
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long n=sc.nextLong(),m=n;
    StringBuffer sb=new StringBuffer();
    
    
    while(n>0){
      long f=n%26;
      
      if(f==0){
        sb.append('z');
        n=n/26-1;
      }else{
        long i=1;
        for(char al='a';al<='z';al++){
          if(f==i){
            sb.append(al);
          }
          i++;
        }
        n=n/26;
      }
      
    }
    sb.reverse();
    System.out.println(sb);
  }
}


Measured memory_bytes: 35640
s = input()
s = s[::-1]
s = s.replace('resare','/')
s = s.replace('esare', '/')
s = s.replace('remaerd','/')
s = s.replace('maerd','/')

s = s.replace('/', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a,b,c,d;
map <ll,ll> mp;
ll solve(ll n){
    if(n==0)return 0;
    if(n==1)return d;
    if(mp.count(n))return mp[n];
    //cout<<n<<endl;
    ll l2=(n/2)*2;
    ll r2=((n+1)/2)*2;
    
    ll l3=(n/3)*3;
    ll r3=((n+2)/3)*3;
    
    ll l5=(n/5)*5;
    ll r5=((n+4)/5)*5;
    ll ans=1e18;
    //ll ans=min(n*d,(ll)1e18);
    if (n < ans/d) ans = n*d;
    ans=min(ans, llabs(l2-n)*d + a + solve(l2/2));
    ans=min(ans, llabs(r2-n)*d + a + solve(r2/2));
    
    ans=min(ans, llabs(l3-n)*d + b + solve(l3/3));
    ans=min(ans, llabs(r3-n)*d + b + solve(r3/3));
    
    ans=min(ans, llabs(l5-n)*d + c + solve(l5/5));
    ans=min(ans, llabs(r5-n)*d + c + solve(r5/5));
    
    mp[n]=ans;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin>>tt;
    while(tt--){
        ll n;
        cin>>n;
        cin>>a>>b>>c>>d;
        mp.clear();
        ll ans=solve(n);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 4500
def main():
  s = input()
  k = int(input())
  lrs = []
  uds = []
  for c in s:
    if c == "R":
      lrs.append(1)
    if c == "L":
      lrs.append(-1)
    if c == "U":
      uds.append(-1)
    if c == "D":
      uds.append(1)
  lr_length = len(lrs)
  ud_length = len(uds)
  
  lr_dp1 = [0] * (lr_length + 1)
  lr_dp2 = [0] * (lr_length + 1)
  for i in lrs:
    for j in range(lr_length, 0, -1):
      lr_dp1[j] = max(lr_dp1[j], lr_dp1[j - 1]) + i * (-1) ** j
      lr_dp2[j] = min(lr_dp2[j], lr_dp2[j - 1]) + i * (-1) ** j
    lr_dp1[0] += i
    lr_dp2[0] += i
  
  ud_dp1 = [0] * (ud_length + 1)
  ud_dp2 = [0] * (ud_length + 1)
  for i in uds:
    for j in range(ud_length, 0, -1):
      ud_dp1[j] = max(ud_dp1[j], ud_dp1[j - 1]) + i * (-1) ** j
      ud_dp2[j] = min(ud_dp2[j], ud_dp2[j - 1]) + i * (-1) ** j
    ud_dp1[0] += i
    ud_dp2[0] += i
  
  lr_acc = [abs(lr_dp1[0])]
  for i in range(1, lr_length + 1):
    lr_acc.append(max(lr_acc[-1], abs(lr_dp1[i]), abs(lr_dp2[i])))
  
  ud_acc = [abs(ud_dp1[0])]
  for i in range(1, ud_length + 1):
    ud_acc.append(max(ud_acc[-1], abs(ud_dp1[i]), abs(ud_dp2[i])))
  
  ans = 0
  for i in range(min(k + 1, lr_length + 1)):
    ans = max(ans, lr_acc[i] + ud_acc[min(k - i, ud_length)])
  print(ans)

main()


Measured memory_bytes: 5788
n = int(input())
ans = 0
if n < 3:
    ans = 0
else:
    for i in range(1, int(n**0.5) + 1):
        if n % i == n // i:
            ans += i
        i = (n // i) - 1
        if n % i == n // i:
            ans += i

print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;


int main(void){
 char s[50];
 int ans=1000000;
 int k=0;

 cin>>s;
 for(int i=0; i<(strlen(s)-2); i++){
  k=abs(753-(((s[i]-'0')*100)+((s[i+1]-'0')*10)+(s[i+2]-'0')));
  ans=min(ans,k);
 }

 std::cout<<ans<<std::endl;
 
}

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

using namespace std;

int main() {
	while(true) {
		string red, green, bottom;
		cin >> red >> green >> bottom;
		if(red == "-") break;

		int rpos = 0, gpos = 0;
		for(int i = 0; i < bottom.size(); ++i) {
			while(gpos < green.size() && green[gpos] != bottom[i]) {
				cout << green[gpos++];
			}
			if(gpos >= green.size()) break;
			green[gpos] = red[rpos++];
		}
		if(gpos < green.size()) cout << green.substr(gpos);
		//else cout << red[rpos];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        long N = sc.nextLong();
        long[] n = new long[5];
        n[0] = sc.nextLong();
        long min = n[0];
        for(int i=1; i<5; i++){
            n[i] = sc.nextLong();
            min = Math.min(min, n[i]);
        }
        if(N%min==0){
            System.out.println(N / min + 4);
        }
        else{
            System.out.println(N / min + 5);
        }
    }
}

Measured memory_bytes: 22740
import sys
import math
h = int(input())

if h == 1:
    print(1)
    sys.exit()

flag = True
n = 1
depth_num = 2

while flag:
    if 2 ** n - 1  < h:
        n += 1
    else:
        flag = False
        depth_num = n

result_num = 2 ** depth_num - 1
print(result_num)

Measured memory_bytes: 3060
use proconio::input;
 
fn main() {
  input! {
    s: String,
    t: String,
  }
  
  let s = s.chars().collect::<Vec<char>>();
  let t = t.chars().collect::<Vec<char>>();
  
  let mut dp:Vec<Vec<usize>> = vec![vec![0;s.len()+1];t.len()+1];
  
  for i in 1..=t.len() {
    for ii in 1..=s.len() {
      let tv = t[i-1];
      let sv = s[ii-1];
      if tv == sv {
        dp[i][ii] = dp[i-1][ii-1] + 1;
      } else {
        dp[i][ii] = std::cmp::max(dp[i-1][ii], dp[i][ii-1]);
      }
    }
  }
    
  let mut r = t.len();
  let mut c = s.len();
  if dp[r][c] == 0 {
    println!("");
    return
  }
  
  let mut len = dp[r][c];
  let mut result:Vec<char> = vec!['a';len];
  while 0 < len {
    if t[r-1] == s[c-1] {
      result[len-1] = s[c-1];
      r -= 1;
      c -= 1;
      len -= 1;
    } else if dp[r][c] == dp[r-1][c] {
      r -= 1;
    } else {
      c -= 1;
    }
  }
 
  println!("{}", result.iter().collect::<String>());
}

Measured memory_bytes: 72556
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        string s;
        cin >> s;
        int n = s.length();
        int l = -1, r = -1;
        for(int i = 0; i < n - 1; i++){
            if(s[i] == s[i + 1]){
                l = i + 1, r = i + 2;
            }
        }
        for(int i = 0; i < n - 2; i++){
            if(s[i] == s[i + 2]){
                l = i + 1, r = i + 3;
            }
        }
        cout << l << ' ' << r << '\n';
    }
}

Measured memory_bytes: 31744
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <ctime>
#include <queue>
#include <sstream>
#include <utility>
#include <bitset>

using namespace std;

#define MP make_pair 
#define PB push_back 
#define INF (1000000007) 
#define eps 1e-8

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

int n,le,ri;
ll s,r,a,b;
int arr[100005];
ll y[100005];

ll Pow(ll x,int p)
{
	if(p==1) return x;
	if(p==0) return 1;
	ll ret=Pow(x,p/2)%INF;
	ret*=ret;
	ret%=INF;
	if(p&1) return (x*ret)%INF;
	return ret;
}

int main()
{
//	freopen("1.txt","r",stdin);
//	freopen("2.txt","w",stdout);
	cin>>n;
	n++;
	for(int i=1;i<=n;i++) 
	{
		cin>>arr[i];
		s+=arr[i];
	}
	r=s-(ll)n*((ll)n-1)/2;
	for(int i=1;i<=n;i++) 
	{
		if(arr[i]==r && le!=0) ri=i;
		else if(arr[i]==r) le=i;
	}
	int t=n-(ri-le+1);
	for(int i=1;i<=100001;i++) y[i]=Pow(i,1000000005)%INF;
	cout<<n-1<<endl;
	a=(ll)n,b=1ll;
	for(int i=2;i<=n;i++)
	{
		a*=(n-i+1);
		a%=INF;
		a*=y[i];
		a%=INF;
		b*=(t-i+2);
		b%=INF;
		b*=y[i-1];
		b%=INF;
		ll tmp=(a-b)%INF;
		if(tmp<0) tmp+=INF;
		cout<<tmp<<endl;
	}
	return 0;
}

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

int N, K, R, S, P;
int sc(char c){
    if(c == 'r') return P;
    if(c == 's') return R;
    if(c == 'p') return S;
    return 0;
}

int main() {
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    ll ans = 0;
    for (int i = 0; i < K; ++i) {
        int cur = i;
        ans += sc(T[i]);
        cur += K;
        while (cur < N) {
            if(T[cur] == T[cur-K]){
                T[cur] = 'a';
            } else {
                ans += sc(T[cur]);
            }
            cur += K;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
using ll = long long;
using ull = unsigned long long;
using namespace std;
using Int = int32_t;
ll mod = 1e9 + 7;

int main(){

  array<array<Int, 15>, 15> state;
  rep(i, 15)rep(j, 15)state[i][j] = -1;
  Int N; cin >> N;
  rep(i, N){
    Int A; cin >> A;
    rep(j, A){
      Int x, y; cin >> x >> y;
      x--;
      state[i][x] = y;
    }
  }

  Int ans = 0;

  rep(bit, (1 << N)){

    vector<Int> message(N, 0);
    rep(i, N){
      if(bit & (1 << i))message[i] = 1;
    }

    bool flag = true;
    rep(i, N){
      if(message[i] == 1){
        rep(j, N){
          if(state[i][j] == -1)continue;
          if(state[i][j] != message[j])flag = false;
        }
      }
    }

    if(flag)ans = max(ans, __builtin_popcount(bit));

  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int ans = 0;
    if (2 <= n) {
        ans += n * (n - 1) / 2;
    }
    if (2 <= m) {
        ans += m * (m - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int tmp[25];

void init(){
  tmp[0] = 1;
  rep(i,1,22){
    tmp[i] = tmp[i-1]*2;
  }
}

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

  init();

  vector<int> U;
  while(L>0){
    U.push_back(L%2);
    L /= 2;
  }

  int N = U.size();
  int M = (N-1)*2-1;
  rep(i,0,N) if(U[i]==1) M++;
  cout << N << " " << M << endl;
  reverse(U.begin(),U.end());

  int a = 0;
  rep(i,0,N){
    if(U[i] == 1 && i != 0){
      cout << 1 << " " << i+1 << " " << a << endl;
    }
    if(U[i] == 1) a += tmp[N-i-1];
  }

  rep(i,1,N){
    cout << i << " " << i+1 << " " << 0 << endl;
    cout << i << " " << i+1 << " " << tmp[N-i-1] << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void read(int &x)
{
	x=0;
	static int p;p=1;
	static char c;c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
	x*=p;
}
int n,a,b;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);read(a);read(b);
	if((b-a)%2==0)return cout<<"Alice"<<endl,0;
	else return cout<<"Borys"<<endl,0;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))


def get_cost(now, target):
    return (now - target) * (now - target)


ans = 10000000
for i in range(min(a), max(a) + 1):
    cost_sum = 0
    for j in a:
        cost_sum += get_cost(j, i)
    if cost_sum < ans:
        ans = cost_sum
print(ans)


Measured memory_bytes: 2940
#include<cstdio>

int a,b,t;

int main() {
	scanf("%d %d",&a,&b);
	if(a>b) t=a,a=b,b=t;
	if(a>0)
		printf("Positive\n");
	else if(b<0) {
		if((b-a+1)%2==0)
			printf("Positive\n");
		else printf("Negative\n");
	}
	else printf("Zero\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int amount , dig ;
bool arr[12];
bool isokay(int amount){
  int rem ;
  while(amount!=0){
    rem=amount%10 ;
    if(arr[rem]==true){
      return false ;
    }
    amount = amount /10;
  }
  return true ;
}
int main(){
 cin >> amount >> dig ;
 for(int i=1;i<=dig;i++){
    int x;
    cin >> x ;
    arr[x]=true ;
 }
 for(int i=amount;;i++){
    if(isokay(i)){
      cout << i <<endl;
      return 0;
    }
 }
 return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	while (1) {
		int H, W;
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		vector<vector<vector<int>>> dp(4, vector<vector<int> >(H + 1, vector<int>(W + 1, 0)));// 0右直進 1上直進 2右(曲がった)　3上(曲がった)
		dp[1][1][0] = 1; dp[0][0][1] = 1;
		for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)for (int k = 0; k < 4; k++) {
			dp[k][i][j] %= 100000;
			if (k == 0) {
				dp[3][i + 1][j] += dp[k][i][j];
				dp[0][i][j + 1] += dp[k][i][j];
			}
			else if (k == 1) {
				dp[2][i][j + 1] += dp[k][i][j];
				dp[1][i + 1][j] += dp[k][i][j];
			}
			else if (k == 2) {
				dp[0][i][j + 1] += dp[k][i][j];
			}
			else if (k == 3) {
				dp[1][i + 1][j] += dp[k][i][j];
			}
		}

		cout << (dp[0][H - 1][W - 1] + dp[1][H - 1][W - 1] + dp[2][H - 1][W - 1] + dp[3][H - 1][W - 1]) % 100000 << endl;
	}
	return 0;
}


Measured memory_bytes: 3244
#include <stdio.h>

int main(void)
{
	int s, sum_a = 0, sum_b = 0, i;
	
	for (i = 0; i < 4; i++){
		scanf("%d", &s);
		sum_a += s;
	}
	for (i = 0; i < 4; i++){
		scanf("%d", &s);
		sum_b += s;
	}
	
	if (sum_a > sum_b){
		printf("%d\n", sum_a);
	}
	else {
		printf("%d\n", sum_b);
	}
	
	return (0);
}

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i < r + 1; i++) {
        if (i % d == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
	long long N, M;
	double sum = 0;
	double a[105];
	cin >> N >> M;
	for(long long i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}


	long long num = 0;
	for(long long i = 0; i < N; i++) {
		if(a[i]/sum >= 1.0/(4.0 * M)) {
			num++;
		}
	}
	if(num >= M) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3672
//(UNCOMMENT WHEN SUBMITTING)
//#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
// #pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

// clang-format off
#define range(i) for (int _ = 0; _ < i; _++)
#define vprnt(v) for (auto vi : v) cout << vi << " "; cout << endl;
#define fastio() ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace ::std;
int nxt() {int x;cin >> x;return x;}
ll nxtll() {ll x;cin >> x;return x;}
// clang-format on

int main() {
    fastio();
    ll H = nxtll(), W = nxtll(), M = nxtll();

    ll rowsums[H] = {0};
    ll colsums[W] = {0};

    set<ll> bombs;

    for (ll i = 0; i < M; i++) {
        ll hi, wi;
        cin >> hi >> wi;
        hi--;
        wi--;
        bombs.emplace(hi + wi * H);
        rowsums[hi]++;
        colsums[wi]++;
    }

    vector<pair<ll, ll>> rowv;
    vector<pair<ll, ll>> colv;

    for (ll i = 0; i < H; i++) {
        rowv.push_back(make_pair(rowsums[i], i));
    }
    for (ll i = 0; i < W; i++) {
        colv.push_back(make_pair(colsums[i], i));
    }

    sort(all(rowv));
    sort(all(colv));

    reverse(all(rowv));
    reverse(all(colv));

    vector<ll> maxrows, maxcols;

    for (ll i = 0; i < rowv.size(); i++) {
        if (rowv[i].first == rowv[0].first) {
            maxrows.push_back(rowv[i].second);
        } else {
            break;
        }
    }

    for (ll i = 0; i < colv.size(); i++) {
        if (colv[i].first == colv[0].first) {
            maxcols.push_back(colv[i].second);
        } else {
            break;
        }
    }

    for (ll row : maxrows) {
        for (ll col : maxcols) {
            if (bombs.find(row + col * H) == bombs.end()) {
                cout << colsums[col] + rowsums[row] << endl;
                return 0;
            }
        }
    }

    cout << colv[0].first + rowv[0].first - 1LL << endl;
    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long

void sbs()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
    #endif
}

void add(int &a,int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

int32_t main()
{
    //sbs();
    // int t;cin>>t;
    // while(t--){
        
    // }
    int a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }else cout<<"win"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  
  int i,j,n[N],mini,length,tmp,count=0,flag;

  
  scanf("%d",&length);
  for(i = 0;i < length;i++){
    
    scanf("%d",&n[i]);
  }
  
  for(i = 0;i <  length;i++){
    flag = 0;
    mini = i;
    for(j = i;j < length;j++){
      
      if(n[j] < n[mini]){
	mini = j;
	flag = 1;	
      }
    }
    if(flag == 1){
  	tmp = n[i];
	n[i] = n[mini];
	n[mini] = tmp;
	count++;  
    }
  }
  
  trace(n,length);

  printf("%d\n",count);
 
  
  return 0;
  
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> data(5);
  vector<int> datax(5);
  for(int i=0;i<5;i++){
  cin >>data.at(i);
  }
  datax=data;
  
    for(int i=0;i<5;i++){
       while(datax.at(i)%10!=0){datax.at(i)+=1;}
      
    }
  
  int min=1000;
  int check=0;
  
  for(int i=0;i<5;i++){
    check=0;
     for(int j=0;j<5;j++){
       if(j!=i){check+=datax.at(j); }
     }
    check+=data.at(i);
       if(check<min){min=check;}
  
  }
  
        cout <<min<<endl;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 10*1e5;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
   ll x,y;
   cin >> x >> y;
   if((x+y)%3!=0||max(x,y)>min(x,y)*2)
   {
      cout<<0<<endl;
      return 0;
   }

   ll k = (x+y)/3;
   x-=k;
   y-=k;
   cout<<COM(x+y,x)<<endl;


   return 0;
}

Measured memory_bytes: 23808
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = int(1e9);
const int MAX = 100002;

int N,M,K;
char a[MAX],b[MAX];

int main()
{
    cin>>N>>M>>K;
    if(N*M<K)
        cout<<N*M<<endl;
    else
        cout<<K<<endl;

    return 0;
}


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

int main() {

	int n;
	bool odd = false;

	cin >> n;
	int a[250];

	int count = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	while (true) {
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 != 0) {
				odd = true;
			}
		}

		if (odd) break;
		else {
			for (int i = 0; i < n; i++) {
				a[i] /= 2;
			}
			count += 1;
		}
	}

	cout << count << endl;

	return 0;
}


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

int main()
{
	int a[100],n,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]!=(i+1))
			cnt++;
	}
	if(cnt>2)
		cout<<"NO";
	else
		cout<<"YES";
}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
			var a = firstLine[0];
			var b = firstLine[1];
			var c = firstLine[2];
			var k = firstLine[3];

			if(a >= k)
			{
				WriteLine(k);
			}
			else if(a + b >= k)
			{
				WriteLine(a);
			}
			else
			{
				WriteLine(a - (k - (a + b)));
			}
		}
	}
}


Measured memory_bytes: 19052
N=int(input())
A=list(map(int,input().split()))
B=[0]*(10**5+1)
for i in range(N):
  B[A[i]]+=1
M=B[0]+B[1]+B[2]
for i in range(10**5-1):
  M=max(M,B[i]+B[i+1]+B[i+2])
print(M)

Measured memory_bytes: 13964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string s;
    cin>>s;


    ll l=0,mx=0;
    for(ll i=0; i<3; i++){
        if(s[i]=='R'){
            l++;
        }
        else{
           mx=max(l,mx);
           l=0;
        }
    }
    if(l!=0)
        mx=l;
    cout<<mx<<endl;
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(c >= a && c <= b)cout << "Yes" << endl; //両方満たすときなので&&
	else cout << "No" << endl;
	return 0;
}

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

def y(n):
    yaku = set()
    for i in range(1, 10 ** 6 + 1):
        if n % i == 0:
            yaku.add(i)
            yaku.add( n // i)
    yaku.remove(1)
    return yaku

ans = len(y(n - 1))

for i in y(n):
    nn = n
    while nn % i == 0:
        nn //= i
    if nn % i == 1:
        ans += 1
print(ans)
        


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

int dp[505][505];

int check(const string &s, int l, int r){
    // cerr << l << " " << r << endl;
    int f;
    if(l == r)f = 1;
    else if(dp[l][r] != -1)f = dp[l][r];
    else if(s[l] != 'm' || s[r-1] != 'w')f = 0;
    else{
        f = 0;
        for(int i=l;i<r;i++){
            if(s[i] == 'e' && check(s, l+1, i) && check(s, i+1, r-1))f = 1;
        }
    }
    return dp[l][r] = f;
}

int main(void){
    string s;
    cin >> s;
    for(int i=0;i<505;i++)for(int j=0;j<505;j++)dp[i][j] = -1;
    bool f = check(s, 0, s.length());
    // for(int i=0;i<=s.length();i++){
    //     for(int j=0;j<=s.length();j++)cerr << dp[i][j] << " ";
    //     cerr << endl;
    // }
    if(f)cout << "Cat" << endl;
    else cout << "Rabbit" << endl;
}


Measured memory_bytes: 4200
import java.util.Scanner;


public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d[] = new int[n];

		int ans = 0;
		
		for(int i = 0; i < n; i++) {
			d[i] = scan.nextInt();;
		}
		for(int i = 0; i < n -1; i++) {
			for(int j = i + 1; j < n; j++) {
				ans +=  d[i] * d[j];
			}
		}
		System.out.println(ans);
	}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  int K, A, B;
  cin >> K >> A >> B;

  bool ok = false;
  for (int i = A; i <= B; ++i) {
    ok |= i % K == 0;
  }  

  cout << (ok ? "OK": "NG") << endl;

  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

int main(void) {
	int N;
	int d[128];
	int i;
	int count;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &d[i]) != 1) return 1;
	}
	qsort(d, N, sizeof(*d), cmp);
	count = 1;
	for (i = 1; i < N; i++) {
		if (d[i - 1] != d[i]) count++;
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const double eps = 1e-11;
const double PI = 2 * acos(0.0);
typedef long long int ll;
typedef unsigned long long ull;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<string,string> mss;
typedef pair<int,int> pii;
typedef pair<string,string> pss;
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sortVA(v) sort(v.begin(),v.end())
#define sortVD(v) sort(v.begin(),v.end(),greater<int>())
#define ASC(a,n) sort(a,a+n);
#define DESC(a,n) sort(a,a+n,greater<int>());
#define out(x) cout <<x<<endl
#define outt(x,y) cout <<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))
#define gcd(a,b) __gcd(a,b);
#define lcm(a, b) ((a)*((b)/gcd(a,b)))

int main()
{
    fast_io
    int a,b;
    cin >>a>>b;
    if((a+b)%3==0){
        out("Possible");
    }
    else if(a%3==0){
        out("Possible");
    }
    else if(b%3==0){
        out("Possible");
    }
    else{
        out("Impossible");
    }
    return 0;
}








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

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}

Measured memory_bytes: 23252