akhauriyash/Code-Regression huggingface dataset:
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         String input = st.nextToken();
         int Q = Integer.parseInt(infile.readLine());
         ArrayList<Character> front = new ArrayList<Character>();
         ArrayList<Character> back = new ArrayList<Character>();
         boolean flip = false;
         while(Q-->0)
         {
            st = new StringTokenizer(infile.readLine());
            if(Integer.parseInt(st.nextToken()) == 1)
               flip = !flip;
            else
            {
               char a = st.nextToken().charAt(0);
               char b = st.nextToken().charAt(0);
               if(a == '1' && flip || a == '2' && !flip)
               {
                  back.add(b);
               }
               else
               {
                  front.add(b);
               }
            }
         }
         Collections.reverse(front);
         StringBuilder sb = new StringBuilder();
         StringBuilder lol = new StringBuilder(input);
         for(char c: front)
            sb.append(c);
         sb.append(input);
         for(char c: back)
            sb.append(c);
         if(flip)
            sb.reverse();
         System.out.println(sb);
      }
   }

Measured memory_bytes: 47568
N, M = [int(i) for i in input().split()]
di = {}
flag = True
for _ in range(M):
    s, c = [int(i) for i in input().split()]
    if(s in di):
        if(di[s] != c):
            print(-1)
            flag = False
            break
    else:
        di[s] = c

if(1 in di):
    if(di[1]==0):
        if(N==1):
            print(0)
        else:
            print(-1)
        flag = False

if(N==1 and M==0):
    print(0)
    flag=False

if(flag):
    for i in range(10**(N-1), 10**N):
        x = str(i)
        ok = True
        for ind, s in enumerate(x):
            if(ind+1 in di):
                if(di[ind+1] != int(s)):
                    ok = False
                    continue
        if(ok):
            print(i)
            break
    else:
        print(-1)


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Arrays.sort(ary);
        double d = 0.0;
        for (int i = 0; i < n - 1; i++) {
            if (d == 0) {
                d = (ary[i] + ary[i + 1]) / 2.0;
            } else {
                d = (d + ary[i + 1]) / 2.0;
            }
        }
        System.out.println(d);
    }
}

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


void solve (){
	int k; cin>>k;
	int total=0;
	for(int i=1; i<(1e7); i++){
		total=(total*10+7)%k;
		if(total==0) {
			cout<<i;
			return;
		}
	}
	cout<<"-1";
}
int main(){
	int t=1;
	for(int i=1; i<=t; i++) solve();
	
	return 0;
	
}

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n;
	cin >> n;
	vector<int> dp(n + 1, INT_MAX);
	dp[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		dp[i] = dp[i - 1] + 1;

		int tmp = 6;
		while (0 <= i - tmp)
		{
			dp[i] = min(dp[i], dp[i - tmp] + 1);
			tmp *= 6;
		}

		tmp = 9;
		while (0 <= i - tmp)
		{
			dp[i] = min(dp[i], dp[i - tmp] + 1);
			tmp *= 9;
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 640
N = int(input())

res = {}
res_res = []
biggest = 0

for i in range(N):
    x = input()
    if x not in res:
        res[x] = 1
    else:
        res[x] = res[x] + 1

for i in res:
    if res[i] > biggest:
        biggest = res[i]

for i in res:
    if res[i] == biggest:
        res_res.append(i)

res_res = sorted(res_res)

for i in res_res:
    print(i)

Measured memory_bytes: 32984
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int N;
ll bit[200005];

void add(ll x) {
  while(x<=N) {
    bit[x]++;
    x += x & -x;
  }
}

ll sum(ll x) {
  ll ans = 0;
  while(x>0) {
    ans += bit[x];
    x -= x & -x;
  }
  return ans;
}

int main() {
  cin>>N;
  ll A[N];
  vector<ll> arr(N);
  map<ll, int> amap;
  for(int i=0;i<N;++i) {
    cin>>A[i];
    arr[i] = A[i];
  }
  sort(arr.begin(), arr.end());
  for(int i=0;i<N;++i) {
    amap[arr[i]] = i+1;
  }
  for(int i=0;i<N;++i) {
    A[i] = amap[A[i]];
  }
  ll ans = 0;
  for(int i=0;i<N;++i) {
    ans += i - sum(A[i]);
    add(A[i]);
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 20124
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

void solve(int E) {
    int ans = INF;
    for (int i = 0; i*i*i <= E; i ++) {
        for (int j = 0; i*i*i + j*j <= E; j++) {
            int x = E - i*i*i - j*j;
            if (x >= 0) ans = min(ans,x + i + j);
            else break;
        }
    }
    cout << ans << endl;
}

int main() {
    while (1) {
        int E; cin >> E;
        if (E == 0) return 0;
        solve(E);
    }
}


Measured memory_bytes: 3016
program main
  implicit none
  integer :: N
  integer, allocatable :: P(:)
  integer :: i
  integer :: out
  integer :: imin
  read(*,*) N
  allocate( P(N) )
  read(*,*) P(:)
  out = 1
  imin = P(1)
  do i = 2, N
     !imin = minval(P(1:i-1))
     if (imin > P(i)) then
        imin = P(i)
     end if
     if ( imin < P(i)) then
     else 
        out = out + 1
     end if
  end do
  write(*,'(i0)') out
  deallocate( P )
  stop
end program main


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) {//切り上げ
	return (xxx + yyy - 1) / yyy;
}

//メモリ置き場
int n;

//inputします
void input() {
	cin >> n;
}

//ライブラリ置き場

//main
int main() {
	input();
	int ans = cup(n, 2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()

#define MAX_N 100000
#define swap(x, y) { card_t t = x; x = y; y = t; }

typedef struct card_tbl
{
	char mark;
	int val;
	int seq;
} card_t;

card_t l[MAX_N / 2 + 2], r[MAX_N / 2 + 2];

int
partition(card_t a[], int p, int r)
{
	int j;

	int x = a[r].val;
	int i = p - 1;
	for (j = p; j < r; ++j)
	{
		if (a[j].val <= x)
		{
			i++;
			swap(a[i], a[j]);
		}
	}

	swap(a[i + 1], a[r]);
	return i + 1;
}

void
quicksort(card_t a[], int p, int r)
{
	if (p < r)
	{
		int q = partition(a, p, r);
		quicksort(a, p, q - 1);
		quicksort(a, q + 1, r);
	}
}

int
main(int argc, char** argv)
{
	card_t a[MAX_N];
	int n, i;

	scanf("%d\n", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%c %d\n", &a[i].mark, &a[i].val);
		a[i].seq = i;
	}

	quicksort(a, 0, n - 1);

	for (i = 0; i < n - 1; ++i)
	{
		if (a[i].val == a[i + 1].val && a[i].seq > a[i + 1].seq)
			break;
	}

	if (i >= n - 1)
		printf("Stable\n");
	else
		printf("Not stable\n");

	for (i = 0; i < n; ++i)
		printf("%c %d\n", a[i].mark, a[i].val);

	return 0;
}

Measured memory_bytes: 1784
import copy

n = int(input())
a = input().split()

bubble = copy.copy(a)
for i in range(n):
    for j in reversed(range(i+1,n)):
        if bubble[j][1] < bubble[j-1][1]:
            bubble[j],bubble[j-1] = bubble[j-1],bubble[j]

insertion = copy.copy(a)
for i in range(n):
    minj = i
    for j in range(i,n):
        if insertion[j][1] < insertion[minj][1]:
            minj = j
    insertion[i],insertion[minj] = insertion[minj],insertion[i]

print(' '.join(bubble))
print('Stable')
print(' '.join(insertion))
if tuple(bubble) != tuple(insertion):
    print('Not stable')
else:
    print('Stable')


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int n;
vector<int> p, a, b, r;
/**********************************************/

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

    cin >> n;
    p.resize(n);
    a.resize(n);
    b.resize(n);
    r.resize(n+1);
    REP(i, n) {cin >> p[i]; p[i]--; r[p[i]] = i+1; }

    REP(i, n){
        cout << 30000 * (i+1);
        if(i != n-1) cout << " ";
    }
    cout << endl;
    REP(i, n){
        cout << 30000 * (n - i) + r[i];
        if(i != n-1) cout << " ";
    }
    cout << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;cin>>n>>m;
    vector<int> v[m];
    int a[m];
    rep(i,0,m){
        cin>>a[i];
        int b;cin>>b;
        rep(j,0,b){
            int c;cin>>c;
            c--;
            v[i].push_back(c);
        }
    }
    int dp[m+1][1<<n];
    rep(i,0,m+1){
        rep(j,0,1<<n)dp[i][j]=1000000000;
    }
    dp[0][0]=0;
    rep(i,0,m){
        int r=0;
        rep(j,0,v[i].size()){
            int num=v[i][j];
            r+=1<<num;
        }
        rep(j,0,1<<n){
            if(dp[i][j]==1000000000)continue;
            Min(dp[i+1][j],dp[i][j]);
            Min(dp[i+1][j|r],dp[i][j]+a[i]);
        }
    }
    if(dp[m][(1<<n)-1]==1000000000)dp[m][(1<<n)-1]=-1;
    cout<<dp[m][(1<<n)-1]<<endl;
}





Measured memory_bytes: 16384
#include<stdio.h>
#define N 10000
#define Q 500

int  linearSearch(int);
  int n,s[N];  
int main(){
  int i,q,l,cnt = 0;
  int t[Q];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
      scanf("%d",&s[i]);
  }
  scanf("%d",&q);

  for(i=0;i<q;i++){
      scanf("%d",&t[i]);
  }
  for(i=0;i<q;i++){
  l = linearSearch(t[i]);
  if(l > 0) cnt++;
  }
  printf("%d\n",cnt);

  return 0;
}
  
int  linearSearch(int key){
  int i = 0;

  s[n] = key;
  while(s[i] != key){
    i++;
    if(i == n) return 0;
  }
  return 1;
}
  
  
  

Measured memory_bytes: 636
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn square(v: f64) -> f64 {
    v * v
}
fn calc(prev: usize, used: usize, sum: f64, ps: &Vec<(f64, f64)>) -> f64 {
    let n = ps.len();
    let rest = n - used.count_ones() as usize;
    if rest == 0 {
        return sum;
    }
    let mut ret = 0.0;
    for i in 0..n {
        let nused = used | (1 << i);
        if used == nused {
            continue;
        }
        let d = (square(ps[prev].0 - ps[i].0) + square(ps[prev].1 - ps[i].1)).sqrt();
        ret += calc(i, nused, sum + d, ps);
    }
    return ret;
}

fn main() {
    let n = read::<usize>();
    let mut ps = vec![(0.0, 0.0); n];
    for i in 0..n {
        ps[i].0 = read::<f64>();
        ps[i].1 = read::<f64>();
    }
    let mut ans = 0.0;
    for i in 0..n {
        ans += calc(i, 1 << i, 0.0, &ps);
    }
    for i in 0..n {
        ans /= (1 + i) as f64;
    }
    println!("{:.8}", ans);
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back
// #define endl "\n"
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll p=1000000007;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p; 
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a); 
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b; 
}

int powerCount(int num, int x){
    int count = 0;
    while(!(num%x)){
        count++;
        num/=x;
    }
    return count;
}

vector <int> SieveOfEratosthenes(int n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
    vector<int> vec;
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) {
        vec.push_back(p);
          // cout << p << " ";
        } 
    return vec;
} 

int main(){

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t = 1;
    while(t--){
        int k;
        string s;
        cin>>k;cin>>s;
        int n = s.size();
        if(n <= k)
            cout<<s;
        else{
            for(int i = 0 ; i < k ; i++)
                cout<<s[i];
            cout<<"...";
        }
    }
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int N;
int A[20];
int B[20];
int C[20];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> B[i];
    for(int i=0;i<N-1;i++) cin >> C[i];
    int s = 0;
    s += B[A[0]-1];
    for(int i=1;i<N;i++){
        s += B[A[i]-1];
        if(A[i-1] + 1==A[i]) s += C[A[i-1]-1];
    }
    cout << s << endl;
    return 0;
}

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

int main() {
    int h, w; cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int b;
            cin >> b;
            a[i][j] = abs(a[i][j] - b);
        }
    }
    const int m = 160 * 80;
    // dp[i][j][k] : iからjまででkになるか
    vector<vector<bitset<m*2>>> dp(h + 1, vector<bitset<m*2>>(w + 1));
    dp[1][1][m - a[0][0]] = 1;
    dp[1][1][m + a[0][0]] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int k = a[i][j];
            dp[i + 1][j + 1] |= (dp[i + 1][j] << k) | (dp[i + 1][j] >> k) | (dp[i][j + 1] << k) | (dp[i][j + 1] >> k);
        }
    }
    for (int i = 0; i <= m; i++) {
        if (dp[h][w][m+i]) {
            cout << i << endl;
            break;
        }
        if (dp[h][w][m-i]) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 21248
n, h = map(int,input().split())
a = []
b = []
ans = 0

for i in range(n):
    x, y = map(int,input().split())
    a.append(x)
    b.append(y)

b.sort(reverse=True)
c = max(a)

#刀を投げる
for i in b:
    if i > c:
        h -= i
        ans += 1
        if h <= 0:
            print(ans)
            exit()

#刀を振る
ans += (h+c-1)//c
print(ans)

Measured memory_bytes: 61528
S = input()

count = 0
letter = "R"

end = [0] * len(S)

for i, s in enumerate(S + "E"):
    if s == letter:
        count += 1
    else:
        odds = (count + 1) // 2
        evens = count // 2
        if s == "L":
            end[i] += evens
            end[i - 1] += odds
        else:
            end[i - count] += odds
            end[i - count - 1] += evens
        count = 1
        letter = s

end = [str(item) for item in end]
end = " ".join(end)
print(end)


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

int main() {
ll n;cin>>n;
  ll a,b; cin>>a>>b;
  
  ll mina=a*(n-1)+b;
  ll maxa=a+b*(n-1);
  
  if(mina>maxa)cout<<0<<endl;
  else cout<<maxa-mina+1<<endl;
  
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC142A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            bool ans = true;
            for (int i = 0; i < 4; i++)
            {
                int count = 0;
                for (int j = 0; j < 4; j++)
                {
                    if (i == j) continue;
                    if (S[i] == S[j]) count++;
                }
                if (count != 1) ans = false;
            }

            if (ans) Console.WriteLine("Yes");
            else Console.WriteLine("No");


            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 11092
l=list(input())
n=len(l)
mod=10**9+7
c1=0
ans=0
for i in range(n):
    if l[i]=='1':
        ans=(ans+pow(3,n-i-1,mod)*pow(2,c1,mod))%mod
        c1+=1
print((ans+pow(2,c1,mod))%mod)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(n);
    repin(L, n);
    sort(all(L));
    ll ans = 0;

    //a<b<cとしてaとbを固定
    rep(a, n) {
        rep2(b, a + 1, n) {
            //b<c && c <a+bより
            //cの取り得る範囲は
            ll k = lower_bound(L.begin(), L.end(), L[a] + L[b]) - L.begin();
            ans += k - (b + 1);
        }
    }
    out(ans);
}

Measured memory_bytes: 256
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
INF = float("inf")

H,W = map(int,input().split())
grid = [list(input()) for i in range(H)]

dist = [[INF]*W for i in range(H)]
dist[0][0] = 0

dxy = [(0,1),(1,0),(0,-1),(-1,0)]

q = deque([(0,0)])

while q:
    x,y = q.popleft()
    for dx,dy in dxy:
        nx,ny = x+dx ,y+dy
        if nx < 0 or ny <0 or nx >=W or ny >= H:
            continue
        if grid[ny][nx] == "#":
            continue
        if dist[ny][nx] < INF:
            continue
        q.append((nx,ny))
        dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
    ans += grid[i].count(".")
if dist[H-1][W-1] == INF:
    print(-1)
else:
    print(ans-dist[H-1][W-1]-1)

Measured memory_bytes: 3316
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl


int main(){
	string s;
	
		cin.clear();
	
		
	while(getline(cin,s)>0){
		if(sz(s)==0)break;
		rep(i,26){
			if(s.find("the", 0)!=string::npos || s.find("this", 0)!=string::npos || s.find("that", 0)!=string::npos){
				cout<<s<<endl;
				break;
			}
			rep(i,sz(s)){
				if(s[i]=='z')s[i]='a';
				else if(s[i]!=' ' && s[i]!='.')s[i]++;
			}
		}
		cin.clear();
	}
	
	return 0;
}

Measured memory_bytes: 1176
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const int MX = 407;
const ll INF = 1e18;

ll f[MX][MX];
int a[MX];
ll s[MX];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }

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

    for (int len = 2; len <= n; len++) {
        for (int l = 1; l + len - 1 <= n; l++) {
            int r = l + len - 1;
            f[l][r] = INF;
            for (int k = l; k < r; k++) {
                f[l][r] = min(f[l][r], f[l][k] + f[k + 1][r] + s[r] - s[l - 1]);
            }
        }
    }

    cout << f[1][n] << "\n";
    return 0;
}



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

int main(){
  const string keyword= "keyence";
  string S;
  cin >> S;

  bool is_satisfied= false;
  for(size_t len_head=0; len_head<= keyword.size(); len_head++){
    size_t len_tail= keyword.size()- len_head;
    if(S.substr(0, len_head)==keyword.substr(0, len_head) && S.substr(S.size()-len_tail)==keyword.substr(keyword.size()-len_tail)){
      is_satisfied= true;
      break;
    }
  }
  string ans= is_satisfied ? "YES"
                           : "NO";
  cout << ans << endl;
}

Measured memory_bytes: 256
implicit none
integer:: n, i, j, a, b, count_1, count_2, count_3
integer,allocatable,dimension(:):: p

read(5,*) a, b
!allocate(p(n))
!read(5,*) (p(i),i=1,n)

!write(6, *) sum(p) - maxval(p)/2
write(6, *) a+b/2

end

Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int a, b, c, d;
 
int main(){
  cin >> a >> b >> c;
  d = a;
  a = b;
  b = d;
  d = a;
  a = c;
  c = d;
  cout << a << " " << b << " " << c;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
void kaitou1(){
    int n;
    string s;
    cin>>n>>s;
    int rsum[1000000];
    rsum[0]=(s[0]=='E'?1:0);
    for(int i=1;i<n;i++){
        rsum[i]=(s[i]=='E'?1:0)+rsum[i-1];
    }
    int ans=1000000;
    for(int i=0;i<n;i++){
        int mi=i-(i==0?0:rsum[i-1])+rsum[n-1]-rsum[i];
        ans=min(ans,mi);
        
    }
    cout<<ans<<endl;
    

}
void kaitou2(){
    int n;
    string s;
    cin>>n>>s;
    int esum[1000000],wsum[1000000];
    
    for(int i=0;i<n;i++){wsum[i]=(i==0?0:wsum[i-1])+(s[i]=='W'?1:0);}
    for(int i=n-1;i>=0;i--){esum[i]=(i==n-1?0:esum[i+1])+(s[i]=='E'?1:0);}
    int ans=10000000;
    for(int i=0;i<n;i++){
        int mi=(i==0?0:wsum[i-1])+(i==n-1?0:esum[i+1]);
        ans=min(ans,mi);
    }
    cout<<ans<<endl;
}
int main(){
    //kaitou1();
    kaitou2();

return 0;
}


Measured memory_bytes: 7684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 200010;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = INF;
  rep(i, MAX) {
    int sum = c*i;
    sum += max(x-i/2, 0)*a;
    sum += max(y-i/2, 0)*b;
    chmin(ans, sum);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
import sys
import itertools

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
MOD = 10 ** 9 + 7
AGCT3 = ["".join(x) for x in itertools.product("AGCT", repeat=3)]
A, G, C, T = 0, 1, 2, 3
M = 64

blacklist3 = {"AGC", "ACG", "GAC"}


def solve():
    dp = [[0] * M for _ in range(N + 1)]
    for i in range(M):
        if AGCT3[i] not in blacklist3:
            dp[3][i] = 1
    for i in range(4, N + 1):
        for j in range(M):
            p3 = AGCT3[j]
            if p3 in blacklist3:
                dp[i][j] = 0
                continue

            if p3[1] == "G" and p3[2] == "C":
                for k in range(M):
                    q3 = AGCT3[k]
                    q2 = q3[1:]
                    if p3.startswith(q2) and q3[0] != "A":
                        dp[i][j] += dp[i - 1][k]
                        dp[i][j] %= MOD
                continue

            if p3[0] == "G" and p3[2] == "C":
                for k in range(M):
                    q3 = AGCT3[k]
                    q2 = q3[1:]
                    if p3.startswith(q2) and q3[0] != "A":
                        dp[i][j] += dp[i - 1][k]
                        dp[i][j] %= MOD
                continue

            for k in range(M):
                q3 = AGCT3[k]
                q2 = q3[1:]
                if p3.startswith(q2):
                    dp[i][j] += dp[i - 1][k]
                    dp[i][j] %= MOD
    ans = 0
    for x in dp[N]:
        ans = (ans + x) % MOD
    return ans


print(solve())


Measured memory_bytes: 42480
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};

ll f(ll a){
    ll rep = 0;
    for(ll i = 1;i <= a/2;++i){
        if(a%i == 0){
            rep++;
        }
    }
    return rep+1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int> (26,0));
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    vector<int> last(26,0);
    int ans = 0;
    rep(i,D){
        int t;
        cin >> t;
        last[t-1] = i+1;
        ans += s[i][t-1];
        int tmp =  0;
        rep(j,26){
            tmp += c[j] * (i+1-last[j]);
        }
        ans -= tmp;
        cout << ans << endl;   
    }
    

    
    
    cout << endl;
    return 0;
}


Measured memory_bytes: 3704
n=int(input())
l=list(map(int,input().split()))
import collections
c = collections.Counter(l)
ans=0
for v in c.values():
  ans+=v*(v-1)//2
for x in l:
  print(ans-c[x]*(c[x]-1)//2+(c[x]-1)*(c[x]-2)//2)

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

signed main(){
	int n; cin>>n;
	int m=0,ans=0;
	rep(i,0,n){
		int a; cin>>a;
		if(a>=m){
			ans++;
			m=a;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
int main(void){
    int n,m,i,j,a[100][100],b[100],c[100];
    for(i=0,scanf("%d%d",&n,&m);i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0;j<m;j++){
        scanf("%d",&b[j]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
        }
    }
    for(i=0;i<n;i++){
        printf("%d\n",c[i]);
    }
}

Measured memory_bytes: 1800
#include<stdio.h>
    
int main(){
    int i,j,n,Max,key,key2,count=0;
    int A[200001];
        
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&A[i]);
    }
   
   Max=A[2]-A[1];
 key2=A[n];
for(i=n;i>=2;i--){
     
        if(key2<=A[i]){
    for(j=i;j>1;j--){
 
    	
    	if(Max<A[i]-A[j-1]){
           Max=A[i]-A[j-1];
            key=A[j-1];}
          
              
    if(count==1){
    if(key>A[j-1]){
    if(Max<A[i]-A[j-1]){
    Max=A[i]-A[j-1];
    key=A[j-1];}}
 
        key2=A[i];
    }
          count=1; 
              
}
        }}
          
            printf("%d\n",Max);
            return 0;
        }
    

Measured memory_bytes: 1376
#include<iostream>
#include<cstdio>
#define MN 2000
#define MX 4000000
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int f[MN+5][MN+5],n,k,p[MX+5],inv[MX+5];
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;}
inline int C(int n,int m){return 1LL*p[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	n=read();k=read();if(k==1) return 0*puts("1");
	p[0]=inv[0]=p[1]=inv[1]=f[0][0]=1;
	for(int i=2;i<=n*k;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=n*k;++i) inv[i]=1LL*inv[i]*inv[i-1]%mod;
	for(int i=0;i<=n;++i)
		for(int j=0;j<=i;++j)
		{
			if(i<n) R(f[i+1][j],f[i][j]);
			if(j<i) R(f[i][j+1],1LL*f[i][j]*C((n-j-1)*(k-1)+n-i+k-1-1,k-2)%mod*(n-j)%mod);	
		}
	printf("%d\n",f[n][n]);
	return 0;
}



Measured memory_bytes: 47104
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  static long n;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    out.println(n >= 30 ? "Yes" : "No");

    out.flush();
  }
}


Measured memory_bytes: 32772
while line = gets
  xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 = line.split.map(&:to_f)

  if (xa1 > xb2) || (xa2 < xb1) || (ya1 > yb2) || (ya2 < yb1)
    puts 'NO'
  else
    puts 'YES'
  end
end

Measured memory_bytes: 8616
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]

if S=='keyence':
    print('YES')
    exit()

for i in range(len(S)):
    for j in range(i, len(S)):
        T = S[:i]+S[j+1:]
        
        if T=='keyence':
            print('YES')
            exit()

print('NO')

Measured memory_bytes: 39024
#!/usr/bin/env ruby

def main(argv)
  (a, b) = gets.chomp.split(' ').map(&:to_i)
  if (a - b).abs >= 2 then
    puts ([a, b].max * 2 - 1).to_s
  else
    puts (a + b).to_s
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int pos = -1;
    rep(i, n - 1) if (a[i] + a[i + 1] >= l) pos = i;
    if (pos == -1)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    rep(i, pos) cout << i + 1 << endl;
    for (int i = n - 1; i > pos + 1; i--)
        cout << i << endl;
    cout << pos + 1 << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int A, B, X;
  cin >> A >> B >> X;
  string s[2] = {"NO", "YES"};
  print(s[A <= X && X <= A + B]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

int64_t a004()
{
    vector<int64_t> a(3);
    cin >> a;

    sort(begin(a), end(a));
    int64_t out = numeric_limits<int64_t>::max();
    do {
        out = min(out, a[0] & 1 ? a[1] * a[2]: 0);
    } while(next_permutation(begin(a), end(a)));

    return out;
}

int main(const int argc, char * argv [])
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << a004();

    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ankit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            for (int i = 0; i < k + 2; i++) {
                out.print("#");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print("#");
                out.print(in.next());
                out.println("#");
            }
            for (int i = 0; i < k + 2; i++) {
                out.print("#");
            }
        }

    }
}



Measured memory_bytes: 21844
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    
    let N = Number(input[0]);
    
    let pow_10 = myPow(10n,BigInt(N),10n ** 9n + 7n);
    let pow_9 = myPow(9n,BigInt(N),10n ** 9n + 7n);
    let pow_8 = myPow(8n,BigInt(N),10n ** 9n + 7n);
    
    let ans = pow_10 - 2n * pow_9 + pow_8;
    while(ans < 0n) ans += (10n ** 9n + 7n);
    
    console.log(ans.toString());
    
}

function myPow(x, n, m){
  if(n == 0)
    return 1n;
  if(n % 2n == 0)
    return myPow(x * x % m, n / 2n, m);
  else
    return x * myPow(x, n - 1n, m) % m;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int ans = 0;
    rep(i, N){
        int a; cin >> a;
        while(a%2 == 0){
            a/=2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

void solve(){
    int h,w;cin>>h>>w;
    int dx[8]={0,0,1,1,1,-1,-1,-1},dy[8]={1,-1,0,1,-1,0,1,-1};
    int sx,sy,cnt;
    char arr[h][w];
    fol(i,h){
        cin >> arr[i];
    }
    fol(i,h){
        fol(j,w){
            cnt = 0;
            if (arr[i][j]!='#'){
                fol(k,8){
                    sx = j + dx[k];
                    sy = i + dy[k];
                    if (sx<w&&sx>=0&&sy>=0&&sy<h){
                        if (arr[sy][sx]=='#') cnt++;
                    }
                }
                arr[i][j]='0'+cnt;
            }
        }
    }
    fol(i,h){
        fol(j,w){
            cout << arr[i][j];
        }
        cout << endl;
    }
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

public static void main (String[] args) {
  Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int M = sc.nextInt();
  int[][] student = new int[N][2];
  int[][] check = new int[M][2];
 
  for(int i=0; i<N; i++) {
    student[i][0] = sc.nextInt();
    student[i][1] = sc.nextInt();
  }
 
  for(int i=0; i<M; i++) {
    check[i][0] = sc.nextInt();
    check[i][1] = sc.nextInt();
  }
 
  for(int i=0; i<N; i++) {
    int min = Integer.MAX_VALUE;
    int minj=0;
    for(int j=0; j<M; j++) {
      int d =  Math.abs(student[i][0]-check[j][0])+Math.abs(student[i][1]-check[j][1]);
      if(d<min) {
        min=d;
        minj = j;
      }
    }
    System.out.println(minj+1);
  }
 
}
 
}

Measured memory_bytes: 35980
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	cin >> n>>k;
	int p[100005],a[100005];
	for(int i=0;i<n;i++){
		cin >> p[i];
	}
	sort(p,p+n);
	for(int i=0;i<=n-k;i++){
		a[i]=p[k-1+i]-p[i];
	}
	sort(a,a+n-k+1);	
	cout << a[0];	
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void){
	int n,i,j,k,l,len,ll,flg,flg2,cnt,h;
	char a[26],s[101];
	cin>>n;
	cin>>a;
	len=strlen(a); 
	cnt=0;
	for(i=0;i<n;i++){
		cin>>s;
		ll=strlen(s);
		flg=0;
		if(ll>=len){
			for(j=0;j<ll;j++){
				if(s[j]==a[0]){
					for(k=1;k<ll;k++){
						flg2=1; h=j;
						for(l=0;l<len;l++){
							if(h>=ll){
								flg2=0;
								break;
							}
//							cout<<i<<' '<<s[h]<<' '<<a[l]<<endl;
							if(s[h]!=a[l]){
								flg2=0;
								break;
							}
							h+=k;
						}
						if(flg2==1) flg=1;
					}
				}
			}
		}
		if(flg==1) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{   int n,d,x,sum;
    scanf("%d%d%d",&n,&d,&x);
    int a[200];
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sum=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<100;j++){
            if(j*a[i]+1>d)
                break;
            else
                sum+=1;
        }
    }
    printf("%d",sum+n+x);
    return 0;
}


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

#define abs(a) (((a)>0)?(a):(-1*(a)))
int main(void)
{
	int n;
	scanf("%d",&n);
	int *w;
	w = (int *)malloc(sizeof(int)*(n));
	int i = 0;
	int right = 0;
	while (i < n)
	{
		scanf("%d", &(w[i]));
		right += w[i];
		i++;
	}
	int min = 10000;
	int left = 0;
	i = 0;
	while (i < n)
	{
		left += w[i];
		right -= w[i];
		//printf("left:%d, right:%d, min:%d\n",left,right,min);
		if(min > abs(left - right))
			min = abs(left - right);
		//printf("left:%d, right:%d, min:%d\n",left,right,min);
		i++;
	}
	printf("%d\n",min);
	return(0);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    int S;
    int h;
    int m;
    int s;

    scanf("%d", &S);

    h = S / 3600;

    m = (S - (h * 3600)) / 60;

    s = S - (h * 3600) - (m * 60);

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}


Measured memory_bytes: 2120
n, m, l = gets.split.map(&:to_i)
  mtx_a,mtx_b = [],[]
  mtx_c = Array.new(n){ Array.new(l){0} }

  n.times do
    mtx_a << gets.split.map(&:to_i)
  end
  
  m.times do
    mtx_b << gets.split.map(&:to_i)
  end

  n.times do | i_idx |
    m.times do | j_idx |
      l.times do | k_idx |
        mtx_c[i_idx][k_idx] += mtx_a[i_idx][j_idx] * mtx_b[j_idx][k_idx]
      end
    end
  end

  mtx_c.each{|out| puts(out.join(" "))}



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

int main(){
  int n;
  cin >> n;
  vector<long> a(n);
  
  int i;
  for(i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  long ans1=0,ans2=0;
  if(n%2==0){
    for(i=0; i<n/2; i++){
      ans1=ans1+2*a[n-1-i]-2*a[i];
    }
    ans1=ans1-a[n/2]+a[n/2-1];
    cout << ans1; return 0;



  }else{
    for(i=n/2+1; i<n; i++){
      ans1=ans1+2*a[i];
    }
    for(i=0; i<n/2-1; i++){
      ans1=ans1-2*a[i];
    }
    ans1=ans1-a[n/2]-a[n/2-1];

    for(i=n/2+2; i<n; i++){
      ans2=ans2+2*a[i];
    }
    for(i=0; i<n/2; i++){
      ans2=ans2-2*a[i];
    }
    ans2=ans2+a[n/2]+a[n/2+1];
    cout << max(ans1,ans2); return 0;
  }
}

Measured memory_bytes: 1024