akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

A, V = input().split(' ')
A, V = int(A), int(V)
B, W = input().split(' ')
B, W = int(B), int(W)
T = int(input())

if (V - W)*T >= abs(A - B):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 61596
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
using namespace std;

int main(){ 
  int n,x=0,y=0,ans=100000,c=0;
  cin>>n>>x;
  rep(i,0,n){
    c+=i+x;
  }
  rep(i,0,n){
    y=i+x;
    if(abs(ans)>abs(y)) ans=y;
  }
  co(c-ans);
  
  return 0;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	string S; cin >> S;
	ll Q; cin >> Q;
	
	int t; ll f; string c;
	int flag = false;
	rep(i, Q) {
		cin >> t;
		if (t == 1) {
			if (flag) flag = false;
			else flag = true;
		}
		else if (t == 2) {
			cin >> f; cin >> c;
			if (flag) {//反転あり
				if (f == 1) S += c;
				else {
					S.insert(0, c);
				}
			}
			else {
				if (f == 1) {
					S.insert(0, c);
				}
				else S += c;
			}
		}
	}

	if (flag) {
		reverse(ALL(S));
		cout << S << endl;
	}
	else cout << S << endl;
}

Measured memory_bytes: 900
def count_happiness(S):
    happiness = 0
    for n in range(N):
        if(S[n] == "L" and n > 0 and S[n] == S[n-1]):
            happiness += 1
        elif(S[n] == "R" and n < N -1 and S[n] == S[n+1]):
            happiness += 1
    return happiness

N, K = map(int, input().split())
S = list(input())

LR_RL_unhappy_pair = 0
LR_unhappy = 0
RL_unhappy = 0
for n in range(N-1):
    if(S[n] == "R" and S[n+1] == "L"):
        RL_unhappy += 1
    if(S[n] == "L" and S[n+1] == "R"):
        LR_unhappy += 1

change_pair_count  = min(K, min(RL_unhappy, LR_unhappy))
change_single_count = 0
if(K > change_pair_count):
    remain = K - change_pair_count
    changable = abs(RL_unhappy  - LR_unhappy)
    change_single_count = min(remain, changable) 
print(count_happiness(S) + 2 * change_pair_count + change_single_count)

Measured memory_bytes: 4084
#include<iostream>
using namespace std;
int main(){
  long long n,m;cin>>n>>m;
  long long n1=max(n,m),m1=min(n,m);
  if(m1==1){
    if(n1==1)cout<<1<<endl;
    else cout<<n1-2<<endl;
  }else{
    cout<<(n-2)*(m-2)<<endl;
  }
  return 0;
}


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

int main(void) {
  string ss;
  int N, cnt=0;

  cin >> ss;
  N = ss.length();

  for(int i=0;i<N;i++) {
    if(ss.at(i)!=ss.at(N-i-1)) cnt++;
  }

  cnt /= 2;

  cout << cnt << endl;

  return (0);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        List<String> list = Arrays.asList(sc.next().split(""));
        boolean flag = true;
        for(int i=0; i<list.size(); i++){
            String back = list.get(list.size()-1-i);
            if(!back.equals(list.get(i))){
                flag = false;
                break;
            }
        }
        if(flag){
            System.out.println("Yes");
        } else{
            System.out.println("No");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    auto check = [&](int id){
        ll sz = a[id];
        rep(i,n){
            if(i == id)continue;
            if(a[i] <= 2*sz)sz += a[i];
            else return false;
        }
        return true;
    };

    int ok = n-1;
    int ng = -1;
    while(abs(ok - ng) > 1){
        int x = (ok + ng)/2;

        if(check(x))ok = x;
        else ng = x;
    }
    cout << n - ok << endl;
}

Measured memory_bytes: 1024
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e18;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  bool f=0;
  if(a<=0 && b>=0)
    f=1;
  if(c<=0 && d>=0)
    f=1;
  ll ans=max({a*c,a*d,b*c,b*d});
  if(f)
    ans=max(ans,0LL);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    T = input()
    Scnt = [0] * (len(S) + 1)
    for i in range(len(S)):
        if S[i] == 'A':
            Scnt[i + 1] = Scnt[i] + 1
        else:
            Scnt[i + 1] = Scnt[i] + 2
    
    Tcnt = [0] * (len(T) + 1)
    for i in range(len(T)):
        if T[i] == 'A':
            Tcnt[i + 1] = Tcnt[i] + 1
        else:
            Tcnt[i + 1] = Tcnt[i] + 2
    
    Q = int(input())
    for _ in range(Q):
        a,b,c,d = map(int,input().split())
        a -= 1
        c -= 1
        if (Scnt[b] - Scnt[a] - Tcnt[d] + Tcnt[c])%3 == 0:
            print('YES')
        else:
            print('NO')
if __name__ == '__main__':
    main()

Measured memory_bytes: 17252
import numpy as np
import math

a, b, h, m = list(map(int, input().split(" ")))

h_a = (h + m/60) * 30
m_a = m * 6
angle = abs(h_a - m_a)
if angle > 180:
    angle = 360 - angle

if angle == 0:
    ans = abs(a-b)
else:
    angle = angle * np.pi / 180
    ans = np.sqrt(a**2 + b**2 - 2 * a * b * np.cos(angle))

print(ans)

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

/*
  ll n , m ;
  cin >> n >> m ;
  ll a , b , c ;
  cin >> a >> b >> c ;
  vector<ll> A(n) ;
  cout << "Yes" << endl ;
  cout << "No"  << endl ;
*/

int main(){
    ll n ;
    cin >> n ;
    vector<ll> A(n) ;
    rep(i,n) cin >> A.at(i) ;
    ll count = 0 ;
    rep(i,n){
      for(ll j = i+1 ; j < n ;j++ ){
        for(ll k = j+1 ; k < n ;k++ ){
            //cout << i+1 << ' ' << j+1 << ' ' << k+1 <<endl; 
            if( A[i] < A[j] && A[j] < A[k] && A[i] + A[j] > A[k] ) count++ ;
            else if( A[k] < A[j] && A[j] < A[i] && A[k] + A[j] > A[i] ) count++ ;
            else if( A[j] < A[i] && A[i] < A[k] && A[i] + A[j] > A[k] ) count++ ;
            else if( A[k] < A[i] && A[i] < A[j] && A[k] + A[i] > A[j] ) count++ ;
            else if( A[j] < A[k] && A[k] < A[i] && A[k] + A[j] > A[i] ) count++ ;
            else if( A[i] < A[k] && A[k] < A[j] && A[k] + A[i] > A[j] ) count++ ;
            //cout << count << endl ;
          }
        }
      }
      cout << count << endl ;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++)
    cin >> p.at(i);
  
  int k=0;
  
  for(int i=0;i<n;i++){
    if(p.at(i)!=i+1)
    k++;
  }
  if(k==2||k==0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<cctype>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll prime[100001];
    ll pre[100001];
    ll i,j;
    prime[0]=0;
    prime[1]=0;
    for(i=2;i<100001;i++){
        prime[i]=1;
    }
    for(i=2;i<100001;i++){
        if(prime[i]==1){
            j=2*i;
            while(j<100001){
                prime[j]=0;
                j+=i;
            }
        }
    }
    pre[0]=0;
    for(i=1;i<100001;i++){
        pre[i]=pre[i-1]+(prime[i]==1&&prime[(i+1)/2]==1);
    }
    ll Q;
    ll l,m;
    cin >> Q;
    for(i=0;i<Q;i++){
        cin >> l >> m;
        cout << pre[m]-pre[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 998244353; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


class binomial_coefficients {
	long long MAX_VAL;
	vector<long long> fac, mmi;

public:

	binomial_coefficients(){
	}
	
	binomial_coefficients(long long num){
		init(num);
	}
	
	~binomial_coefficients(){
		
	}
	
	void init(long long num){
		MAX_VAL = num+1; 
		fac.resize(MAX_VAL);
		mmi.resize(MAX_VAL);
		
		factorial_mod();
		modular_multiplicatibe_inverse();
	}
	
	void factorial_mod(){
		 fac[0] = 1;
		for(long long i = 1; i < MAX_VAL; fac[i] %= MOD, i++)
			fac[i] = fac[i - 1] * (i % MOD);
	}
	
	long long power(long long x, long long n){
		long long ans = 1;
		for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
			if(n&1)ans*=x;
		return ans % MOD;
	}
	
	void exgcd(long long a, long long b, long long &x, long long &y){
		if(b == 0){
			x = 1;
			y = 0;
			return ;
		}
		exgcd(b, a % b, y, x);
		y -= a / b * x;
	}
	
	void modular_multiplicatibe_inverse(){
		long long x, y;  
		exgcd(fac[MAX_VAL - 1], MOD, x, y);
		mmi[MAX_VAL-1] = x;
		// mmi[MAX_VAL-1] = power(fac[MAX_VAL-1], MOD-2);
		for(long long i = MAX_VAL - 2; i >= 0; mmi[i]%=MOD, i--)
			mmi[i] = mmi[i + 1] * ((i + 1) % MOD);
	}
	
	long long combination(long long n, long long r){
		return n < r ? 0 :fac[n] * (mmi[r] * mmi[n-r] % MOD) % MOD;
	}
};

signed main(){
	cout<<fixed<<setprecision(10);
	
	binomial_coefficients BC;
	int N, M, K;
	int ans = 0;
	
	
	cin>>N>>M>>K;
	
	BC.init(N*2);
	
	for(int i = 0; i <= K; i++){
		ans += BC.combination(N-1, i) * BC.power(M-1,N-(i+1)) % MOD * M % MOD;
		ans %= MOD;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

int main(){
  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  a--; b--; c--; d--;
  string str;
  cin >> str;
  int cnt=0;
  for(int i=a; i<=c; i++){
    if(str[i]=='#'){
      cnt++;
      if(cnt==2){
        cout << "No" << endl;
        return 0;
      }
    }else{
      cnt = 0;
    }
  }
  cnt=0;
  for(int i=b; i<=d; i++){
    if(str[i]=='#'){
      cnt++;
      if(cnt==2){
        cout << "No" << endl;
        return 0;
      }
    }else{
      cnt = 0;
    }
  }
  if(c<d){
    cout << "Yes" << endl;
    return 0;
  }
  cnt =0;
  for(int i=b-1; i<=d+1; i++){
    if(str[i]=='.'){
      cnt++;
      if(cnt==3){
        cout << "Yes" << endl;
        return 0;
      }
    }else{
      cnt = 0;
    }
  }
  cout << "No" << endl;
  return 0;
}





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

int main(int argc, char *argv[]){
    int n,m;
    cin >> n >> m;
    int h[n];
    int g[n];
    int c=0;
    int a,b;
    for(int i=0;i<n;i++){
        cin >> h[i];
        g[i]=1;
    }
    for(int i=0;i<m;i++){
        cin >> a >> b;
        if(h[a-1]>h[b-1]){
            g[b-1]=0;
        }else if(h[a-1]<h[b-1]){
            g[a-1]=0;
        }else{
            g[a-1]=0;
            g[b-1]=0;
        }
    }
    for(int i=0;i<n;i++){
        if(g[i]==1) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 4416
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,m,ea=0,eb=0,ff[SZ]; Edg
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
int col[SZ],su[SZ],sz[SZ],dep[SZ],hb[SZ];
void dfs(int x,int f=0)
{
	col[x]=col[f]^1; su[x]=col[x]; sz[x]=1;
	dep[x]=dep[f]+1; hb[x]=(x==eb);
	for esb(x,e,b)
		if(b!=f) dfs(b,x),su[x]+=su[b],
		sz[x]+=sz[b],hb[x]|=hb[b];
}
int main()
{
	scanf("%d%d",&n,&m); ea=1;
	for(int i=1;i<=m;++i)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		int ga=gf(a),gb=gf(b);
		if(ga^gb) adde(a,b),ff[ga]=gb;
		else ea=a,eb=b;
	}
	dfs(ea);
	if(m==n-1)
	{
		if(su[ea]!=n-su[ea])
		{
			puts("-1");
			return 0;
		}
		ll ans=0;
		for(int i=1;i<=n;++i) if(i!=ea)
			ans+=abs(sz[i]-su[i]-su[i]);
		printf("%lld\n",ans);
		return 0;
	}
	int cl=dep[eb];
	if(cl%2==0)
	{
		if(su[ea]!=n-su[ea])
		{
			puts("-1");
			return 0;
		}
		vector<int> v; ll ans=0;
		for(int i=1;i<=n;++i) if(i!=ea)
		{
			int g=sz[i]-su[i]-su[i];
			if(hb[i]) v.pb(g);
			else ans+=abs(g);
		}
		v.pb(0);
		sort(v.begin(),v.end());
		int s=v[v.size()/2];
		for(int i=0;i<v.size();++i)
			ans+=abs(v[i]-s);
		printf("%lld\n",ans);
	}
	else
	{
		int c=su[ea]-n+su[ea];
		if(c&1)
		{
			puts("-1");
			return 0;
		}
		c/=2; ll ans=abs(c);
		for(int i=1;i<=n;++i) if(i!=ea)
			ans+=abs(sz[i]-su[i]-su[i]+(hb[i]?c:0));
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 26492
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll n,t;
    cin >> n >> t;
    ll ans=INF;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(y<=t){
            ans=min(ans,x);
        }
    }
    if(ans==INF) cout << "TLE" << endl;
    else cout << ans << endl;
    return 0;
} 

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

typedef long long ll;
typedef long double ld; //
typedef double db; //
typedef string str; //
//
typedef pair<int, int> pi;
typedef pair<ll,ll> pl; //
typedef pair<ld,ld> pd; //
#define mp make_pair
#define f first
#define s second

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll; //
typedef vector<ld> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi; //
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //
typedef vector<vi> vvi;
typedef vector<vll> vvll;

//
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back() //
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = 4*atan((ld)1); 
const int xd[4] = {0,1,0,-1}, yd[4] = {1,0,-1,0}; //

template<class T> bool ckmin(T& a, const T& b) { 
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { 
    return a < b ? a = b, 1 : 0; }
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

    int H, W, h, w;
    cin >> H >> W >> h >> w;

    if (H % h == 0 && W % w == 0) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    vll grow (W, 0);
    vvll grid (H, grow);

    if (W % w != 0) {
        int r = W/w;

        int k = W - r;
        int good = 2*r;
        int bad = -2*k + 1;

        for (int y=0;y<H;y++) {
            for (int x = 0; x<W;x++) {
                if (x % w == w-1) grid[y][x] = bad;
                else grid[y][x] = good;
            }
        }
    } else {
        int r = H/h;
        int k = H - r;
        int good = 2*r;
        int bad = -2*k + 1;

        for (int y=0;y<H;y++) {
            for (int x = 0; x<W;x++) {
                if (y % h == h-1) grid[y][x] = bad;
                else grid[y][x] = good;
            }
        }
    }

    for (int y=0;y<H;y++) {
        for (int x=0;x<W;x++) cout << grid[y][x] << " \n"[x+1==W];
    }
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli h,w;
mat s;
mat b;
mat mem;
stack<vll> stck;
lli ans = 0;

int main(){
  cin >> h >> w;
  s = b = mem = mat(h+1,vll(w+1));
  for(lli i = 1;i <= h;i++){
    string $;
    cin >> $;
    for(lli j = 1;j <= w;j++){
      if($[j-1] == '#') s[i][j] = 1;
      else if($[j-1] == '.') s[i][j] = 0;
    }
  }
  for(lli i = 1;i < h;i++){
    for(lli j = 1;j < w;j++){
      b[i][j] = (s[i][j]+s[i+1][j]+s[i][j+1]+s[i+1][j+1])%2;
    }
  }
  for(lli i = 0;i <= h;i++) b[i][0] = b[i][w] = 1;
  for(lli j = 0;j <= w;j++) b[0][j] = b[h][j] = 1;
  for(lli i = 1;i <= h;i++){
    for(lli j = 1;j <= w;j++){
      mem[i][j] = b[i-1][j-1] ? 1 : mem[i-1][j]+1;
    }
  }
  ans = h;
  for(lli i = 1;i <= h;i++){
    stck = stack<vll>();
    for(lli j = 2;j <= w;j++){
      lli from = j;
      while(!stck.empty() && stck.top()[0] >= mem[i][j]){
        ans = max(ans,(j-stck.top()[1]+1)*stck.top()[0]);
        from = stck.top()[1];
        stck.pop();
      }
      stck.push(vll({mem[i][j],from}));
    }
    while(!stck.empty()){
      ans = max(ans,(w+1-stck.top()[1]+1)*stck.top()[0]);
      stck.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 94336
l,r=map(int,input().split())

mod=2019
r=min(r,l+mod+1)
res=float('inf')

for i in range(l,r):
    for j in range(i+1,r+1):
        res=min(res,(i*j)%mod)
        if res==0:
            print(res)
            exit()
print(res)

Measured memory_bytes: 3060
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    const p = arg[1].split(" ").map(n=>parseInt(n));
    
    // 期待値はpが大きいほど大きくなる
    // 最後に計算すれば良い
    
    const map = {};
    
    let totalSum = new Array(N).fill(0);
    
    // 累積和
    for(let i=0; i<N; i++) {
        totalSum[parseInt(i) + 1] = totalSum[i] + p[i];
    }

    let answer = 0;
    let index  = 0;
    
    // console.log(totalSum)
    
    // Kの範囲で大きくなってるとこ探す
    for(let i=K; i<=N; i++) {
        const temp = totalSum[i] - totalSum[i - K];
        
        // console.log("i" + totalSum[i]);
        // console.log("i - K" + totalSum[i - K]);
        // console.log(temp)
        
        if(answer < temp) {
            answer = temp;
            index  = i - K;
        } 
    }
    
    let expectation = 0;
    
    // 期待値を計算
    for(let i=index; i<index + K; i++) {
        expectation += ((0.5 * p[i]) * (p[i] + 1)) / p[i];
    }
    
    console.log(expectation);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
    int A, B, C, D, E, F, G, H, I; 
    cin >> A >> B >> C >> D >> E >> F >> G >> H >> I; 
  if(D-A == E-B && E-B == F-C && G-A == H-B && H-B == I-C)
    cout << "Yes" << endl;
  else cout << "No" << endl;  
}

Measured memory_bytes: 256
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = {};
  for(var i = 1; i*i <= m; i++){
    if(m % i === 0){
      a[i] = m / i;
    }
  }
  var ans = 1;
  for(i in a){
    if(a[i] >= n)if(ans < +i)ans = +i;
    if(+i >= n)if(ans < a[i])ans = a[i];
  }
  return ans;
}

Measured memory_bytes: 11724
#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る
    //Ans+= ceil(X[i]/len)-1;//多少遅くなるがこっちが正解
  }
  return Ans;
}

int main()
	{
	  long long K;
	  cin>>N>>K;
	  for(int i=0;i<N;i++)
	{
		cin>>X[i];
		//X[i]-=0.1;
	}

  long double l=1,r=1e9;
  //while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
	//for(int i=0;i<35;i++)//OK log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  //while(!((ceil(r)-ceil(l)) == 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
	while(!((floor(r)-floor(l)) == 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid=(l+r)/2;
    if(Count(mid)<=K) r=mid;
    else	l=mid;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}

Measured memory_bytes: 6828
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll H,W,N;
set<P> st;
set<P> checked;
int main(){
    cin>>H>>W>>N;
    for(ll i=0;i<N;i++){
        ll a,b;
        cin>>a>>b;
        st.insert(P(a,b));
    }
    ll ans[10]={};
    for(auto p:st){
        ll cnt=0;
        for(ll h=max(1ll,p.first-2);h<=p.first;h++){
            if(h+2>H)break;
        for(ll w=max(1ll,p.second-2);w<=p.second;w++){
            if(w+2>W)break;
            if(checked.find(P(h,w))!=checked.end()){
                        continue;
            }
            checked.insert(P(h,w));
            for(ll i=h;i<h+3;i++){
                for(ll j=w;j<w+3;j++){
                    
                    if(st.find(P(i,j))!=st.end() ){
                        cnt++;
                    }
                }
            }
            ans[cnt]++;
            cnt=0;
        }
        }
    }
    ll sum=0;
    for(ll i=1;i<=9;i++){
        sum+=ans[i];
    }
    cout<<(H-2)*(W-2)-sum<<endl;
    for(ll i=1;i<=9;i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 62720
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(S);Cins(T);
    cout << T << S << nn;
    return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

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

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int sentouCnt = 0;
	int cnt = 0;
	FOR(i,0,n){
		if(s[i] == '('){
			cnt++;
		}else{
			if(cnt > 0){
				cnt--;
			}else{
				sentouCnt++;
			}
		}
	}
	FOR(i,0,sentouCnt)cout << '(';
	cout << s;
	FOR(i,0,cnt)cout << ')';
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(long long int i = 0; i < (n); i++)


int Len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}


int Sint(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int Svec(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}


int GCD(int a,int b){
  int r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


int LCM(int a,int b){
  int c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  int n;
  bool flag=false;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  int cnt=0;
  int k,a=0;
   while(a<n){
     k=a;
      while(v[k]>0 && k<n){
        v[k]--;
        k++;
        flag=true;
        
      }
      if(flag){
        cnt++;
        flag=false;
      }
      if(v[a]==0){
        a++;
      }
   }
   cout<<cnt<<endl; 
  
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define display(v) f(v.size())cout << v[i] << " "
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
int check(ll n,ll i)
{
   ll tmp = n;
   while(tmp%i == 0)tmp/=i;
   if(tmp%i==1)return 1;
   return 0;
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ll n;  cin>>n;
   if(n==2)
   {
      cout << 1 << "\n"; return 0;
   }
   // n%i == 1 or (n-1)%i == 0 1st codition
   ll c = n-1;
   ll ans = 2;  // n and n-1
   for(ll i = 2;i*i <= c;i++)
   {
      if(c%i)continue;
      ans += 2;  // i and c/i .  2 answers
      if(i*i == c)ans--;
   } 
   // for n keep dividing it. 
   for(ll i = 2;i*i<=n;i++)
   {
      if(n%i)continue;
      ans += check(n,i);
      if(i*i != n)ans += check(n,n/i);
   }cout << ans;
   return 0;
}     

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int H, W;
    string A[100];
    cin >> H >> W;
    REP(i, H) cin >> A[i];

    vector<int> hv, wv;
    REP(i, H) REP(j, W) if (A[i][j] == '#') {
        hv.push_back(i);
        break;
    }
    REP(j, W) REP(i, H) if (A[i][j] == '#') {
        wv.push_back(j);
        break;
    }
    for (int i : hv) { for (int j : wv) cout << A[i][j]; cout << endl; }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <functional>
using namespace std;
double absdouble(double a)
{
	return a>0?a:-a;
}
int asc( const void *p, const void *q ) {
    if( *(double*)p > *(double*)q ) return -1;
    if( *(double*)p < *(double*)q ) return 1;
    return 0;
}
int main()
{
	int n,m,i,j=0,sum=0,ans=0;
	vector<int> x(100000+10);
	vector<int> sa(100000+10);
	//vector<double> dif(100000+10);
	double dif[100000+10];
	cin>>n>>m;
	for (i=0;i<m;i++)
	{
		cin>>x[i];
	}
	sort(x.begin(),x.begin()+m,greater<int>());
	for (i=0;i<m-1;i++)
	{
		sa[i]=x[i]-x[i+1];
	}
	sort(sa.begin(),sa.begin()+m-1,greater<int>());
	for (i=min(n-1,m-1);i<m-1;i++)
	{
		//cout<<sa[i]<<endl;
		ans+=sa[i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
N = int(input())
count = [0, 0]
for _ in input().split():
    count[int(_) % 2] += 1
if count[1]:
    count[0] += 1
    count[1] %= 2
if bool(count[0]) ^ bool(count[1]):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 11104
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	
	int answer = 0;
	for (int i = 0; i < N; i++)
	{
		// 3倍操作は何回でもできるので、A[i]に対して2で割る操作を1回行った回数を計算する
		while(A[i] % 2 == 0)
		{
			A[i] /= 2;
			answer++;
		}
	}
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Fennec vs Monster
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int hs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 0; i < n; i++) scanf("%d", hs + i);
  sort(hs, hs + n);

  int m = n - k;
  ll sum = 0;
  for (int i = 0; i < m; i++) sum += hs[i];

  printf("%lld\n", sum);
  return 0;
}


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

using namespace std;

struct BooKIndex{
  vector<int> page;
  string word;
  BooKIndex(const int &p,const string &w){
    word=w;
    page.push_back(p);
  }
  bool operator==(const BooKIndex &b)const{
    return word==b.word;
  }
  bool operator<(const BooKIndex &b)const{
    return word<b.word;
  }
};

int main(){
  vector<BooKIndex> indexlist;
  string word;
  int page;
  while(cin>>word>>page){
    auto idx=find(indexlist.begin(),indexlist.end(),BooKIndex(page,word));
    if(idx!=indexlist.cend())
      idx->page.push_back(page);
    else
      indexlist.push_back(BooKIndex(page,word));
  }
  for(auto &l:indexlist){
    sort(l.page.begin(),l.page.end());
  }
  sort(indexlist.begin(),indexlist.end());
  for(auto l:indexlist){
    cout<<l.word<<endl;
    for(int i=0;i<l.page.size();i++)
      cout<<l.page[i]<<((i!=l.page.size()-1)?' ':'\n');
  }

}

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

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

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    vector<int> x(3, 0), y(3, 0);
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    x[0] = 0;
    rep(i, 3) y[i] = a[i][0] - x[0];
    rep(i, 3) x[i] = a[0][i] - y[0];
    bool flag = true;
    rep(i, 3) rep(j, 3) if(a[i][j] != y[i] + x[j]) flag = false;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main()
{
  int a,b;
  cin>>a>>b;
  if(a>12){
    cout<<b;
  }
  if(a<=12 && a>5){
    b=b/2;
    cout<<b;
  }
  else if(a<=5){
    cout<<0;
  }
}

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

int main()
{
  int N, K;
  int A[201010];
  cin >> N >> K;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++)
  {
    mp[A[i]]++;
  }
  
  vector<int> v;
  for (auto x:mp)
  {
    v.push_back(x.second); //新たな要素を末尾に追加する
  }
  sort(v.begin(), v.end());
  
  int n = v.size();
  
  if (n <= K)
  {
    cout << 0 << endl;
  }
  else
  {
    int ans = 0;
    for (int i = 0; i < n - K; i++)
    {
      ans += v[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 11516
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(a*c, max(a*d, max(b*c, b*d)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int f(int a, int b) {
  int d = abs(a-b);
  return min(d,24-d);
}

int main() {
  int n;
  scanf("%d",&n);
  vi d(n);
  cin>>d;
  ++n; d.pb(0);
  sort(rng(d));
  rep(i,n) if (i&1) d[i] = 24-d[i];
  sort(rng(d));
  int ans = f(d[0],d.back());
  rep(i,n-1) mins(ans,f(d[i],d[i+1]));
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

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

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;



int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}

int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}

int digitsum(int x)
{
  while(x>9)
    {  int ans=0;
       while(x!=0)
       {
        ans+=x%10;
        x/=10;
       }
       x=ans;
    }
    return x;
}

int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;}
  return a;
}



int solve( ){

int n;
cin>>n;
vi a(n);
rep(i,0,n)cin>>a[i];
int dp[n+1];

dp[0]=0;
dp[1]=abs(a[1]-a[0]);
int ans=0;
rep(i,2,n)
{   

   dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  
}
cout<<dp[n-1];

return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);



  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
    //cout <<endl<< "Processor time taken is "
      //<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 1792
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R: std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read {
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0;
        self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {
                break;
            }
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn read_a<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {
            self.read_line();
        }
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
}

fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}
#[allow(unused_imports)]
use std::cmp;

fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let n: i32 = r.read_a();
    let mut max = 0;
    let mut ans: i32 = 0;
    for i in 0..n+1 {
        let mut cnt = 0;
        let mut j = i;
        while j > 0 {
            j /= 2;
            cnt += 1;
        }
        ans = if max < cnt {
            max = cnt;
            i
        } else {
            ans
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

arr = inputs[0]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

a = (arr[1] - arr[0]).abs + (arr[2] - arr[1]).abs # 0, 1, 2
c = (arr[2] - arr[0]).abs + (arr[1] - arr[2]).abs # 0, 2, 1
b = (arr[0] - arr[1]).abs + (arr[2] - arr[0]).abs # 1, 0, 2
d = (arr[2] - arr[1]).abs + (arr[0] - arr[2]).abs # 1, 2, 0
e = (arr[0] - arr[2]).abs + (arr[1] - arr[0]).abs # 2, 0, 1
f = (arr[1] - arr[2]).abs + (arr[0] - arr[1]).abs # 2, 1, 0
puts [a,b,c,d,e,f].min


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  int m = *max_element(v.begin(), v.end());
  int s = accumulate(v.begin(), v.end(), 0);
  cout << (m < (s - m) ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(b - a == c - b) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

using namespace std;

int main(){
  int n,i,j;
  cin >> n;
  long long a[n][3];
  for(i=0;i<n;i++){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  long long dp[n][3];
  for(i=0;i<n;i++)for(j=0;j<3;j++)dp[i][j]=0;
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  for(i=1;i<n;i++){
    for(j=0;j<3;j++)dp[i][j]=max(dp[i-1][(j+1)%3]+a[i][j],dp[i-1][(j+2)%3]+a[i][j]);
  }
  cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << endl;
  return 0;
}


Measured memory_bytes: 4992
n,k  = map(int, input().split())
d=[]
a=[]
for i in range(0,k):
    do=int(input())
    d.append(do)
    a.extend(list(map(int, input().split())))
    a=list(set(a))
#print(n,k,d,a)
#print(a)

a_list=[]
for i in range(1,n+1):
    a_list.append(i)
#print(a_list)
a=a+a_list
a = [x for x in set(a) if a.count(x) == 1]
print(len(a))

Measured memory_bytes: 9208
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        PriorityQueue<Integer> pq = new PriorityQueue<Integer>((a,b)->{return b-a;});
        for(int i=0;i<N;i++) pq.offer(sc.nextInt());
        for(int i=0;i<M;i++){
            int b = pq.poll();
            pq.offer(b/2);
        }
        long ans = 0l;
        while(!pq.isEmpty()){
            ans += pq.poll();
        }
        System.out.println(ans);
    }
}


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

bool is_even_str(string str) 
{
    if (str.length()%2 != 0) return false;
    int half_len = str.length() / 2;
    for (int i = 0; i < half_len; i++) {
        if (str[i] != str[i + half_len]) return false;
    }
    return true;

}

int solve(string str)
{
    int ans = 0;
    for (int i = 1; i < str.length(); i++)
    {
        string sub = str.substr(0, str.length() - i);
        if (is_even_str(sub))
        {
            ans = sub.length();
            break;
        }
    }
    return ans;
}

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

    string s;
    cin >> s;
    cout << solve(s) << endl;
    
    return 0;
}

Measured memory_bytes: 256