akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

// b以下のペアの数を返す o(n)
_LL count(vector<_LL> &a1, vector<_LL> &a2, bool issame, _LL b)
{
    _LL ret = 0;
    rep(i, a1.size())
    {
        _LL t = b / a1[i];
        auto itr = upper_bound(a2.begin(), a2.end(), t);
        _LL count = itr - a2.begin();
        if( issame && a1[i] <= t ) count--;
        ret += count;
    }
    if( issame ) return ret / 2;
    return ret;
}

_LL bsearch(vector<_LL> &am, vector<_LL> &ap, bool isplus, _LL k)
{
    _LL tmax = (1000000000LL * 1000000000LL);
    _LL tmin = -1;
    while( tmax  > tmin + 1 )
    {
        _LL t = (tmin + tmax) / 2;
        _LL ret;
        if( isplus )
        {
            ret = count(am, am, true, t) + count(ap, ap, true, t);
        }  
        else
        {
            ret = count(am, ap, false, t);
        }
        if( ret < k )
        {
            tmin = t;
        }
        else
        {
            tmax = t;
        }
    }
    return tmin + 1;
}

int main()
{
    _LL n, k;
    cin >> n >> k;
    vector<_LL> ap;
    vector<_LL> am;
    _LL zero = 0;

//    vector<_LL> _debug;
//    vector<_LL> _debugall;

    rep(i, n) 
    {
        _LL a;
        cin >> a;
//        _debug.push_back(a);
        if( a > 0 ) ap.push_back(a);
        if( a < 0 ) am.push_back(-a);
        if( a == 0 ) zero++;
    }
//    rep(i, n)
//        rep(j, n)
//            if( i < j ) _debugall.push_back(_debug[i] * _debug[j]);
//    sort( _debugall.begin(), _debugall.end() );
    sort( ap.begin(), ap.end() );
    sort( am.begin(), am.end() );

//    for(k = 1; k <= n * (n - 1) / 2; k++ )
    {
        _LL mnum = am.size() * ap.size();
        _LL zeronum = zero * (am.size() + ap.size());
        if( zero > 0 )  zeronum += zero * (zero - 1) / 2;
        if( k - 1 < mnum )
        {
            cout << -bsearch(am, ap, false, mnum - k + 1 );
        }
        else if( k - 1 < mnum + zeronum )
        {
            cout << 0;
        }
        else
        {
            cout << bsearch(am, ap, true, k - mnum - zeronum );
        }
//        cout  << "  :  " << _debugall[k - 1] << endl;
    }
    return 0;    

}

Measured memory_bytes: 5160
#include <stdio.h>
#include <algorithm>
int n, x;
long long a[200001];
long long b[200001];
long long z[200000];
long long u[200000];
long long v[200000];
int l, r, f, s, t;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		a[x]++;
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		b[x]++;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] + b[i] > n) {
			printf("No\n");
			return 0;
		}
		z[i - 1] = (a[i] + b[i]) * 1000000 + i;
	}
	printf("Yes\n");
	std::sort(z, z + n);
	r = n - 1;
	for (int i = n - 1; i >= 0; i--) {
		x = z[i] % 1000000;
		if (f) {
			for (int j = 0; j < a[x]; j++) {
				u[l] = x;
				l++;
			}
			for (int j = 0; j < b[x]; j++) {
				v[r] = x;
				r--;
			}
		}
		else {
			if (a[x] + b[x] <= r - l + 1) {
				for (int j = 0; j < a[x]; j++) {
					u[l] = x;
					l++;
				}
				for (int j = 0; j < b[x]; j++) {
					v[r] = x;
					r--;
				}
			}
			else {
				t = b[x] - l;
				s = a[x] - (n - 1 - r);
				if (s < 0)s = 0;
				if (t < 0)t = 0;
				if (s + t < r - l + 1) {
					if (a[x] >= r - l + 1 - t)s = r - l + 1 - t;
					else {
						s = a[x];
						t = r - l + 1 - s;
					}
				}
				for (int j = 0; j < s; j++) {
					u[l] = x;
					l++;
				}
				for (int j = 0; j < t; j++) {
					v[r] = x;
					r--;
				}
				for (int j = 0; j < a[x] - s; j++) {
					u[n - 1 - j] = x;
				}
				for (int j = 0; j < b[x] - t; j++) {
					v[j] = x;
				}
				f = 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		z[i] = u[i] * 1000000 + v[i];
	}
	std::sort(z, z + n);
	for (int i = 0; i < n; i++) {
		if (i < n - 1)printf("%lld ", z[i] % 1000000);
		else printf("%lld\n", z[i] % 1000000);
	}
}

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

bool isPrime(int n) {
    if(n == 1) return false;
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0) return false;
    }
    return true;
}

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

    while(!isPrime(x)) x++;

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A, B) << " " << max(A + B - N, 0) << endl;
  return 0;
}

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

typedef pair<int,int> P;

const int N=2e5+5;
const ll INF=numeric_limits<ll>::max();
int n;
P bag[N];
multiset<int> r,b;

ll cost(){
	return 1LL*(*r.rbegin()-*r.begin())*(*b.rbegin()-*b.begin());
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		int x,y;
		cin>>x>>y;
		if(x>y) swap(x,y);
		r.insert(x);
		b.insert(y);
		bag[i].first=x;
		bag[i].second=y;
	}
	sort(bag,bag+n);
	ll res=cost();
	for(int i=0;i<n;++i){
		//we will swap color of pair i, in the hope that it could minimize (Rmax-Rmin) by bringing Rmin closer to Rmax
		//the cost function will decrease, then increase back after the breakpoint
		int x=bag[i].first;
		int y=bag[i].second;
		r.erase(r.find(x));
		b.erase(b.find(y));
		r.insert(y);
		b.insert(x);
		res=min(res,cost());
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 23972
#include <bits/stdc++.h>
#define stop "=7"

using namespace std;
using LL = long long;

char n[4];
char ops[3];

int main(){
	for (int i = 0; i < 4; i++){
		cin >> n[i];
		n[i] -= '0';
	}
	for (int i = 0; i <= 8; i++){
		for (int j = 0; j < 3; j++){
			if (i & (1 << j)){
				ops[j] = '+';
			}
			else{
				ops[j] = '-';
			}
		}
		int result = n[0];
		for (int i = 1; i <= 3; i++){
			if (ops[i - 1] == '+'){
				result += n[i];
			}
			else{
				result -= n[i];
			}
		}
		if (result == 7){
			cout << (int)n[0];
			for (int i = 1; i <= 3; i++){
				cout << ops[i - 1] << (int)n[i];
			}
			cout << stop << flush;
			break;
		}
	}
}

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

#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'

typedef long long int ll ;

void solve()
{
	 int n;
	 cin >> n ;
	 int d1[n] ;
	 int d2[n] ;
	 int cnt = 0 ;
	 bool ans = 0 ;
	 for ( int i = 0 ; i < n ; i++ )
	 {
	 	 cin >> d1[i] >> d2[i] ;
	 	 if( d1[i] == d2[i] ) cnt++ ;
	 	 else cnt = 0 ;
	 	 if ( cnt == 3 ) ans = 1 ;
	 }
	 if (ans) cout << "Yes" << endl ;
	 else cout << "No" << endl ;
}

int main()
{
	 ios ;
	 solve();
}


Measured memory_bytes: 3652
n = int(input())
count = 0
judge = False
for N in range(n):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        count += 1
    else:
        count = 0
    if count == 3:
        judge = True
        break

if judge:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9176
from itertools import accumulate
from bisect import bisect_left
 
n,m,k=map(int,input().split())
a=list(accumulate([0]+list(map(int,input().split()))))
b=list(accumulate([0]+list(map(int,input().split()))))
#print(b)
mx=0
for i in range(n+1):
  if a[i]>k:continue
  #print('a[i];'+str(a[i]))
  idx=min(bisect_left(b,k-a[i]),m)
  #print(idx)
  if b[idx]>k-a[i]:idx-=1
  if a[i]+b[idx]>k:continue
  mx=max(mx,i+idx)
print(mx)
  

Measured memory_bytes: 42912
#include<stdio.h>
int main(){
  int H;
  int A;
  
  scanf("%d", &H);
  scanf("%d", &A);
  for(int i=1;i<=10001;i++){
    if(H>=1){
      H=H-A;
    }else{
      printf("%d \n", i-1);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define MAX 100005

int32_t main(){
	IOS;
	int n;
	cin >> n;
	int arr[n];
	vector<int> cnt(MAX, 0);
	int tot = 0;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		cnt[arr[i]]++;
		tot += arr[i];
	}

	int q, b, c;
	cin >> q;
	while(q--){
		cin >> b >> c;
		int cur = cnt[b];
		tot = tot - cur*b + cur*c;
		cnt[b] = 0;
		cnt[c] += cur;
		cout << tot << endl;
	}
	return 0;
}

Measured memory_bytes: 4740
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(std::vector<long long> m, std::vector<long long> d){
    if(m[0] != m[1])
        cout << 1 << endl;
    else
        cout << 0 << endl;
}


signed main(){
    std::vector<long long> M(2);
    std::vector<long long> D(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&M[i]);
        scanf("%lld",&D[i]);
    }
    solve(std::move(M), std::move(D));
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
triples = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            numbers = [a[i], a[j], a[k]]
            if len(set(numbers)) == 3:
                numbers = sorted(numbers)
                if numbers[0] + numbers[1] > numbers[2]:
                    triples += 1
print(triples)


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

char data[15][15];

void dfs(int x, int y);

int main(void)
{
	while (1){
		for (int i = 0; i < 12; i++){
			cin >> data[i];
		}
		if (cin.eof()) return 0;
		
		int res = 0;
		for (int i = 0; i < 12; i++){
			for (int j = 0; j < 12; j++){
				if (data[i][j] == '1'){
//					printf("i >> %d, j >> %d\n", i, j);
					data[i][j] = '0';
					dfs(i, j);
					res++;
				}
			}
		}
		
		printf("%d\n", res);
	}
	
	return (0);
}

void dfs(int x, int y)
{
	if (data[x + 1][y] == '1' && (x + 1) < 12){
		data[x + 1][y] = '0';
		dfs(x + 1, y);
	}
	if (data[x - 1][y] == '1' && 0 <= (x - 1)){
		data[x - 1][y] = '0';
		dfs(x - 1, y);
	}
	if (data[x][y + 1] == '1' && (y + 1) < 12){
		data[x][y + 1] = '0';
		dfs(x, y + 1);
	}
	if (data[x][y - 1] == '1' && 0 <= (y - 1)){
		data[x][y - 1] = '0';
		dfs(x, y - 1);
	}
	
	return;
}

Measured memory_bytes: 0
(defun common-divisor (a b k)
  (let ((cnt 0) (i 1) (ret nil) (end-val (gcd a b)))
    (loop 
      (when (> i end-val) (return))

      (when (and (zerop (mod a i)) (zerop (mod b i)))
        (setf cnt (1+ cnt))
        (push i ret))
      
      (setf i (1+ i)))
    (nth (1- k) ret)))


(format t "~A~%" (common-divisor(read) (read) (read)))

Measured memory_bytes: 13284
n,y = gets.chomp.split().map(&:to_i)
s,t,u = 0
ans = []
for s in 0..n
    if ans.size > 0
        break
    end
    if (y - 10000*s) <= 5000*(n-s)
        for t in 0..(n-s)
            if ans.size > 0
                break
            end 
            if 10000*s+5000*t+1000*(n-s-t) == y
                ans.push("#{s} #{t} #{n-s-t}")
                break
            end
        end
    end
end

if ans.size > 0
    print ans[0]
else
    print "-1 -1 -1"
end

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

int main() {
	string str;
	cin>>str;
	int a,b=0;
	a=str.size();
	for(int i=0;i<a;i++){
		char s;
		s=str.at(i);
		
	    for(int j=0;j<a-i-1;j++){
	    	char m;
	    	m=str.at(i+j+1);
	   	    if(s==m){
	   	    	b++;
	   	    }
	   }
	   
	}
	if(b!=0){
		cout<<"no"<<endl;
	}
	else{
		cout<<"yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int W,H,x,y,r;
  
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  
  if(x-r<0||x+r>W||y-r<0||y+r>H){
  	printf("No\n");
  }
	else{
		printf("Yes\n");
	}
	
  return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long int cost[101][101],k,n,a,b,c,d,e,which,go[101];
bool used[101];
void dij(int s){
    fill(go,go+101,10000000);
    fill(used,used+101,false);
    go[s]=0;
    while(true){
        int v=-1;
        for(int i=0;i<100;i++){
            if(!used[i]&&(v==-1||go[i]<go[v]))v=i;
        }
        if(v==-1)break;
        used[v]=true;
        for(int i=0;i<100;i++){
            go[i]=min(go[i],go[v]+cost[v][i]);
        }
    }
}
int main(){
    for(;;){
        cin>>n>>k;
        if(n==0&&k==0)break;
        fill(cost[0],cost[0]+101*101,10000000);
        for(int i=0;i<k;i++){
            cin>>which;
            if(!which){
                cin>>a>>b;
                dij(a-1);
                if(go[b-1]!=10000000)cout<<go[b-1]<<endl;
                else cout<<-1<<endl;
            }
            else {
                cin>>c>>d>>e;
                cost[c-1][d-1]=min(cost[c-1][d-1],e);
                cost[d-1][c-1]=min(cost[d-1][c-1],e);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;
const int64_t INF = (1LL << 50);
int64_t cost[MAXN][MAXN], dist[MAXN][MAXN];

void init()
{
  for (int i = 0; i < MAXN; i++)
  {
    for (int j = 0; j < MAXN; j++)
    {
      cost[i][j] = INF;
      dist[i][j] = INF;
    }
  }
  for (int i = 0; i < MAXN; i++)
  {
    cost[i][i] = 0;
  }
}

int main()
{
  int64_t N, M, L, a, b, c, Q;
  cin >> N >> M >> L;
  init();
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b >> c;
    a--, b--;
    cost[a][b] = cost[b][a] = c;
  }
  cin >> Q;
  vector<int> S(Q), T(Q);
  for (int i = 0; i < Q; i++)
  {
    cin >> S.at(i) >> T.at(i);
    S.at(i)--, T.at(i)--;
  }
  for (int k = 0; k < N; k++)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (cost[i][j] <= L)
      {
        dist[i][j] = 1;
      }
    }
  }
  for (int k = 0; k < N; k++)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  for (int i = 0; i < Q; i++)
  {
    cout << (dist[S[i]][T[i]] < INF ? dist[S[i]][T[i]] - 1 : -1) << endl;
  }
}

Measured memory_bytes: 5352
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int constexpr maxn = 100009;
int n;
int h[maxn];
int dp[maxn];
bool done[maxn];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> h[i];
}

int go(int i) {
    if(i == 1) return 0;
    if(i == 2) return abs(h[2] - h[1]);
    if(done[i]) return dp[i];

    dp[i] = min(go(i-1) + abs(h[i] - h[i-1]), go(i-2) + abs(h[i] - h[i-2]));
    done[i] = true;
    return dp[i];
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    read_input();
    cout << go(n) << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

int n,m;
map<int,int> map;

vp prime_factorize(){
    vp ret;
    for(int p=1; p*p<=m; p++){
        if(m%p!=0) continue;
        ret.PB(MP(p,1));
        ret.PB(MP(m/p,1));
    }
    ret.PB(MP(m,1));
    sort(all(ret));
    return ret;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    cin >> n >> m;
    vp a=prime_factorize();
    int res=1;
    for(auto p:a){
        if(p.F*n<=m) chmax(res,p.F);
        //cout<<p.F<<endl;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, 1, n + 1) {
        int a;
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int N = 123456;
const int LOGN = 20;

int n, l, q;
int x[N];
int rg[N][LOGN];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", x + i);
  scanf("%d %d", &l, &q);
  for (int i = 0; i < n; i++) for (int j = 0; j < LOGN; j++) rg[i][j] = n;
  int dist = 0;
  for (int i = 0, j = 0; i < n; i++) {
    while (j + 1 < n && dist <= l) {
      dist += x[j + 1] - x[j];
      j++;
    }
    if (dist > l) {
      j--;
      dist -= x[j + 1] - x[j];
    }
    rg[i][0] = j;
    dist -= x[i + 1] - x[i];
  }
  for (int j = 1; j < LOGN; j++) for (int i = 0; i < n; i++) {
    rg[i][j] = rg[rg[i][j - 1]][j - 1];
  }
  while (q--) {
    int a, b; scanf("%d %d", &a, &b); a--, b--;
    if (a > b) swap(a, b);
    int ans = 0;
    for (int i = LOGN - 1; i >= 0; i--) {
      if (rg[a][i] < b) {
        a = rg[a][i];
        ans |= 1 << i;
      }
    }
    printf("%d\n", ans + 1);
  }
  return 0;
}

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

int main() {
	string s;
  	cin >> s;
  	int counter = 0;
    if (s[0] == '1') ++counter;
    if (s[1] == '1') ++counter;
    if (s[2] == '1') ++counter;
    cout << counter << endl;
}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.Scanner;


public class Main {
    Scanner sc = new Scanner(System.in);
    int n;
    public void run(){
        n = sc.nextInt();
        solve();
    }
    public void solve(){
        int[] pat = {111, 222, 333, 444, 555, 666, 777, 888, 999};
        for(int i = 0; i < pat.length; i++){
            int ans = pat[i];
            if(n <= ans){
                System.out.println(ans);
                break;
            }
        }
    }

    public static void main(String[] args){
        new Main().run();
    }

    static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }
    static class Edge{
        int to, cost;
        public Edge(int a, int b){
            this.to = a;
            this.cost = b;
        }
    }
    class MyComparator implements Comparator {
        @Override
        public int compare (Object arg0, Object arg1) {
            int x = ((Pair)arg0).first;
            int y = ((Pair)arg1).first;

            if (x < y) {
                return 1;
            } else if (x > y) {
                return -1;
            } else{
                return 0;
            }
        }
    }
    static class UnionFind{
        int par[];
        int rank[];

        //n要素で初期化
        public UnionFind(int maxn){
            par = new int[maxn];
            rank = new int[maxn];

            for(int i = 0; i < maxn; i++){
                par[i] = i;
                rank[i] = 0;
            }
        }

        //木の根を求める
        int find(int x){
            if(par[x] == x){
                return x;
            }
            else {
                return par[x] = find(par[x]);
            }
        }

        // xとyの属する集合を併合
        void unite (int x, int y){
            x = find(x);
            y = find(y);
            if(x == y){
                return;
            }

            if(rank[x] < rank[y]){
                par[x] = y;
            }
            else{
                par[y] = x;
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        // xとyが同じ集合に属するか否か
        boolean same(int x, int y){
            return find(x) == find(y);
        }
    }

}

Measured memory_bytes: 23252
function main()
  
  (A,B) = map(x -> parse(Float64,x), split(readline()))
  
  check = false
  
  for i in 1:1000
    if floor(i * 0.08) == A && floor(i * 0.1) == B
      check = true
      println(i)
      break
    end
  end
  
  if check == false
    println(-1)
  end
  
end

main()

Measured memory_bytes: 167184
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, k; cin >> n >> k;
	int ans = 1, p = k;
	for (int i = 0; i < n; i++) {
		ans *= p--; ans %= 1000000007;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    int ans=100000;
    for (int i=0;i+t.size()-1<s.size();i++) {
        string tmp=s.substr(i,t.size());
        int count=0;
        for (int j=0;j<tmp.size();j++) {
            if (tmp[j]!=t[j]) {
                count++;
            }
        }
        ans=min(ans,count);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)

//	rep(i,10)cout << i << endl;
using namespace std;

int main(void){
	int n,k,t,a[101],num[101],flg,p;
	scanf("%d %d",&k ,&t);
	rep(i,t){
		scanf("%d" ,&a[i]);
		num[i]=i;
	}
	flg=-1;
	int ans=k;
	rep(ii,k){
		rep(i,t){
			for(int j=i;j<t;j++){
				if(a[i]<a[j]){
					swap(a[i],a[j]);
					swap(num[i],num[j]);
				}
			}
		}
		
	/*	rep(i,t){
			printf("%d =%d %d\n",i,a[i],num[i]);
		}*/
		//printf("%d\n",flg);
		p=0;
		while(!(a[p]!=0 && num[p] != flg)){
			p++;
			if(p>=t)	break;
		}
		if(p>=t){
			ans=ii;
			break;
		}
		a[p]--;
		flg=num[p];
	}
	printf("%d\n",k-ans);
	
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0)break;
			
			String[] a = new String[n];
			int[] b = new int[n];
			
			for(int i=0;i<n;i++){
				a[i] = sc.next();
				b[i] = sc.nextInt();
			}
			
			int sum = 0;
			int c = 0;
			String s = "";
			
			for(int i=0;i<m;i++){
				s = sc.next();
				for(int j=0;j<n;j++){
					c = 0;
					while(a[j].codePointAt(c)==42)c++;
					if(a[j].substring(c,8).compareTo(s.substring(c,8))==0)sum+=b[j];
				}
			}
			System.out.println(sum);
			
		}
	
	}	
}

Measured memory_bytes: 60156
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;
typedef long long ll;
int pr[101010];
ll ans[555][555];
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
ll lcm(ll a, ll b)
{
	if (a == 0 || b == 0)return max(a, b);
	return a*b / gcd(a, b);
}
int main()
{
	int num;
	scanf("%d", &num);
	deque<ll>v;
	for (int i = 2; i <= 10000; i++)
	{
		if (pr[i] == 0)
		{
			for (int j = i + i; j <= 10000; j += i)pr[j] = -1;
			if (i >= 30 && v.size() < num * 2 + 100)v.push_back(i);
		}
	}
	deque<ll>x, y;
	for (int i = 0; i < v.size(); i++)
	{
		if (i % 4 == 0)x.push_back(v[i]);
		if (i % 4 == 1)x.push_front(v[i]);
		if (i % 4 == 2)y.push_back(v[i]);
		if (i % 4 == 3)y.push_front(v[i]);
	}
	for (int i = 0; i < num + 5; i++)
	{
		for (int j = 0; j < num + 5; j++)
		{
			if ((i + j) % 2 == 0)
			{
				ans[i][j] = x[(i + j) / 2] * y[(i - j + num + 5) / 2];
			}
		}
	}
	for (int i = 1; i <= num; i++)
	{
		for (int j = 1; j <= num; j++)
		{
			if ((i + j) % 2 != 0)
			{
				ll t = x[(i + j - 1) / 2] * y[(i - j + num + 5 - 1) / 2] * x[(i + j + 1) / 2] * y[(i - j + num + 5 + 1) / 2];
				ans[i][j] = t + 1;
			}
			if (ans[i][j]>1000000000000000LL)abort();
			printf("%lld ", ans[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 5248
#include<iostream>
#include<cstdio>
using namespace std;
const int N=2002020,mod=1e9+7;
int n,m,fac[N],iv[N];
int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%mod)
		if(y&1)res=1ll*res*x%mod;
	return res;
}
int C(int x,int y){
	return 1ll*fac[x]*iv[y]%mod*iv[x-y]%mod;
}
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 main()
{
	n=read(); m=read();
	fac[0]=iv[0]=1;
	for(int i=1;i<=max(n,m);i++)
		fac[i]=1ll*fac[i-1]*i%mod,iv[i]=fpow(fac[i],mod-2);
	int opt=1,ans=0;
	for(int i=0;i<=n;i++,opt*=-1){
		int wm=1ll*fac[m-i]*iv[m-i-(n-i)]%mod,lm=1ll*fac[m]*iv[m-i]%mod;
		int tmp=1ll*wm*wm%mod*lm%mod*C(n,i)%mod; ans=(ans+opt*tmp)%mod;
	} cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 7428
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        long ans = 0;
        int K = sc.nextInt();
        int N = sc.nextInt();
        int mx = 0;
        int[] arr = new int[N];
        for(int i=0;i<N;i++){
            arr[i]=sc.nextInt();
        }
        
        mx = K-arr[N-1] + arr[0];
        for(int i=1;i<N;i++){
            int num = arr[i] - arr[i-1];
            mx = Math.max(mx,num);
        }
        ans = K - mx;
        pw.println(ans);
        pw.flush();
    }

    public static void main(String[] args) {
        new Main();
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public ArrayList<Integer> nextIntList(int n) {
        ArrayList<Integer> a = new ArrayList<Integer>(n);
        for (int i = 0; i < n; i++)
            a.add(nextInt());
        return a;
    }

    public ArrayList<Long> nextLongList(int n) {
        ArrayList<Long> a = new ArrayList<Long>(n);
        for (int i = 0; i < n; i++)
            a.add(nextLong());
        return a;
    }
    
    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

#define ll long long int

#define y first
#define x second


int sa(int, int,int);


int main()
{
	pair<int, int> pr;

	int n,m;

	int half;
	int sar;
	int color[] = {3,1,2};

	int i;

	cin >> n >> m;

	half = n / 2;

	for (i = 0; i < m; i++)
	{
		cin >> pr.y >> pr.x;

		sar=min( sa(pr.y, half, n) , sa(pr.x, half, n) );

		cout << color[sar % 3] << endl;
	}

	return 0;
}


int sa(int len, int half, int n)
{
	int saa=len;

	if (half < len)
	{
		saa = n - len + 1;
	}
	return saa;
}

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

vector<pair<long long int, long long int>> prime_factorize(long long int N) {
  vector<pair<long long int, long long int>> res;
  for (long long int a = 2; a * a <= N; a++) {
    if (N % a != 0) continue;
    long long int ex = 0;
    while (N % a == 0) {
      ex++;
      N /= a;
    }
    pair<long long int, long long int> p = make_pair(a, ex);
    res.push_back(p);
  }
  if (N != 1) {
    pair<long long int, long long int> q = make_pair(N, 1);
    res.push_back(q);
  }
  return res;
}

long long int F(long long int k) {
  int res = 0;
  for (int i = 1; i < 1000; i++) {
    if (k >= i * (i + 1) / 2 && k < (i + 1) * (i + 2) / 2) {
      res = i;
    }
  }
  return res;
}

int main() {
  long long int N;
  cin >> N;
  vector<pair<long long int, long long int>> A = prime_factorize(N);
  long long int ans = 0;
  for (auto p : A) {
    ans += F(p.second);
  }
  cout << ans << endl;
}

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; cin >> n >> k;

    long double prob=0.0;
    repe(i,1,n){
        int tmp=i;
        int cnt=0;
        while(tmp<k){
            tmp*=2;
            cnt++;
        }
        //cout << "cnt: " << cnt ENDL;
        prob+=(long double)1/n*(long double)pow(0.5,cnt);
        //cout << setprecision(20);
        //cout << prob ENDL;
    }

    cout << setprecision(20);
    cout << prob ENDL;
    
    return 0;
}

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

int main() {
    int N;
    string S, T1 = "";
    string T2 = "";
    cin >> N >> S;
    if (N % 2 == 0) {
        for (int i = 0; i < N / 2; i++) {
            T1 += S.at(i);
            T2 += S.at(N / 2 + i);
        }
        if (T1 == T2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
    
   
}


Measured memory_bytes: 256
#include<stdio.h>
void dfs(void);
void dfs_init(int);
#define N 100
#define origin 0
#define discover 1
#define death 2
int n,X[N][N];
int condition[N],a[N],b[N],c;
int main(){
  int i,j,x,y,z;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	X[i][j]=0;
      }
    }
    for(i=0;i<n;i++){
      scanf("%d %d",&x,&y);
      x--;
      for(j=0;j<y;j++){
	scanf("%d",&z);
	z--;
	X[x][z]=1;
      }
    }
    dfs();
    return 0;		  
}
void dfs(void){
  int x;
  for(x=0;x<n;x++)
    condition[x]=origin;
  c=0;
  for(x=0;x<n;x++){
    if(condition[x]==origin)
      dfs_init(x);
  }
  for(x=0;x<n;x++){
    printf("%d %d %d\n",x+1,a[x],b[x]);
  }
}
void dfs_init(int x){
  int z;
  condition[x]=discover;
  a[x]=++c;
  for(z=0;z<n;z++){
    if(X[x][z]==0)
      continue;
    if(condition[z]==origin)
      dfs_init(z);
    }
  condition[x]=death;
  b[x]=++c;
}



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll a,b,c;
  cin>>a>>b>>c;
  
  ll ans=b+min(a+b+1,c);
  cout<<ans<<endl;
  
  
}

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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )

template < typename T >
inline T read( )
{
	register T x = 0;
	register char ch = gc( );
	register bool f = 0;
	while( !std::isdigit( ch ) )
	{
		f = ( ch == '-' );
		ch = gc( );
	}
	while( std::isdigit( ch ) )
	{
		x = x * 10 + ( ch - '0' );
		ch = gc( );
	}
	return f ? -x : x;
}

template < typename T >
void print( T x )
{
	if( x < 0 )
	{
		x = -x;
		pc( '-' );
	}
	if( x < 10 )
	{
		pc( x + 48 );
		return;
	}
	print < T > ( x / 10 );
	pc( x % 10 + 48 );
	return ;
}

namespace Solution
{
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( ' ' )
#define ptl( i ) print < long long > ( i ), putchar( ' ' )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
	const int Maxn = 204001;
	int n, t;
	void fakemain( )
	{
		n = rdi( );
		pti( n % 1000 != 0  ? 1000 - n % 1000 : 0 );
		return;
	}

} // namespace Solution

int main( int argc, char* argv[] )
{
	Solution::fakemain( );
	return 0;
}

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

int main()
{
    string s;
    string t;
    string u;
    cin >> s >> t;
    u = s;
    int ans = 0;
    int k = s.size();
    for(int i = 0; i < k; i++){
        if(s == t){
            ans = 1;
        }
        u[0] = s[s.size()-1];
        for(int j = 0; j < k-1; j++){
            u[j+1] = s[j];
        }
        s = u;
    }
    if(ans == 1){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 int x,y;  
  cin>>x>>y;
  bool solution=false;
  for(int i=0;i<x+1;i++){
    if(2*(x-i)+4*i==y){
      solution=true;
    }
  }
    if(solution==true){
      cout<<"Yes"<<endl;
    }
     if(solution==false){
      cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <climits>

using namespace std;
using ll = long long int;

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

    ll ans = 1;
    ll sign = 0;
    for (size_t i = 1; i < n; i++)
    {
        ll diff = a[i] - a[i - 1];

        if ((sign == 1 && diff < 0) || (sign == -1 && diff > 0))
        {
            ans++;
            sign = 0;
        } else if (diff > 0) {
            sign = 1;
        } else if (diff < 0) {
            sign = -1;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    vector<int> a(n);
    rep(i, n) a[i] = i+1;
    
    map<vector<int>, int> mp;
    do{
        mp[a] = mp.size();
    } while(next_permutation(a.begin(), a.end()));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 8648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x, y;
ll abs2(ll f) {
	if (f < 0) return -f;
  	return f;
}
ll min2(ll a, ll b) {
	if (a < b) return a;
 	return b;
}
int main () {
	cin >> x >> y;
    if (x > y) {
        x = x - (x / y) * y;
    }
	cout << min2(abs2(x-y), abs2(x));
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  char a, b;
  cin >> a >> b;
  int ac=1;
  if(a=='H')
    ac=0;
  int tc=0;
  if(b=='H')
    tc=1;
  if(ac^tc)
    cout << 'H' << endl;
  else
    cout << 'D' << endl;
  return 0;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,k,ans=0;
	cin>>n>>k;
	vi vs(n+1);
	for(int i=0,x;i<n;++i){
		cin>>x;
		vs[i+1] = vs[i] + x;
	}
	for(int i=k;i<=n;++i){
		ans = max(ans,(vs[i]-vs[i-k]));
	}
	cout<<fixed<<setprecision(10)<<(ans+k)/2.0<<endl;
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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 (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1e9+7) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

const int INF = 1e18;

const int NN = 222222;
int L;
vector<int> A;
int dp[NN][10];

signed main() {
  cin >> L;
  A.resize(L);
  for (int i = 0; i < L; i++) {
    cin >> A[i];
  }

  rep (i, NN) rep (j, 10) dp[i][j] = INF;

  repp (i, 1, 6) {
    dp[0][i] = 0;
  }
  for (int i = 0; i < L; i++) {
    // 左の取らない区間
    int cost1 = A[i];
    chmin(dp[i+1][1], dp[i][1] + cost1);

    // 左の偶数区間
    int cost2 = A[i] == 0 ? 2 : A[i] % 2;
    chmin(dp[i+1][2], min({dp[i][1], dp[i][2]}) + cost2);

    // 奇数区間
    int cost3 = A[i] == 0 ? 1 : A[i] % 2 == 0;
    chmin(dp[i+1][3], min({dp[i][3], dp[i][2], dp[i][1]}) + cost3);

    // 右の偶数区間
    int cost4 = A[i] == 0 ? 2 : A[i] % 2;
    chmin(dp[i+1][4], min({dp[i][4], dp[i][3], dp[i][2], dp[i][1]}) + cost4);

    // 右の取らない区間
    int cost5 = A[i];
    chmin(dp[i+1][5], min({dp[i][5], dp[i][4], dp[i][3], dp[i][2], dp[i][1]}) + cost5);
  }

  int ans = 1e18;
  repp (i, 1, 6) {
    chmin(ans, dp[L][i]);
  }

  cout << ans << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const long long INF = 1LL << 61;
const int MOD = 2019;

int main() {
	string S; cin >> S;
	map<char, int> mp;
	rep(i, S.size())++mp[S[i]];
	if (mp.size() == 2) {
		for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
			if (itr->second != 2) {
				cout << "No";
				return 0;
			}
		}
	}
	else {
		cout << "No";
		return 0;
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a[300][300],h,w;
  for(int k=0; k<10000; k++) {
      cin >> h >> w;
      if(h==0&&w==0) {
          return 0;
      }
      for(int i=0; i<h; i++) {
          for(int j=0; j<w; j++) {
              cout << "#";
          }
          cout << endl;
      }
      cout << endl;
  }
}


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

int main(){
	char a;
	cin >> a;
	char s[5] = {'a', 'i', 'u', 'e', 'o'};
	char * p = find(s, s+5, a);
	if(p == s+5) cout << "consonant" << endl;
	else cout << "vowel" << endl;
	return 0;
}

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


void solve() {
    int n, y;
    cin >> n >> y;
    int a = 10000;
    int b = 5000;
    int c = 1000;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            int v = i * a;
            int w = j * b;
            int x = y - v - w;
            int res = v + w + x;
            if(x >= 0 && i + j + (x/c) == n) {
                if(res == y) {
                    cout << i << " " << j << " " << x/c << endl;
                    return;
                }
            }
        }
    }
    cout << "-1 -1 -1";

}


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


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;


int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())
MOD = 10**9+7
#print(X, Y)

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
  return pow(a, mod-2, mod)

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
  r = min(r, n-r)
  res = 1
  for i in range(r):
    res = res * (n - i) * modinv(i+1, mod) % mod
  return res

## 条件1: Y <= 2X かつ X <= 2Y
## 条件2: (X+Y) % 3== 0

if Y <= 2*X and X <= 2*Y and (X+Y) % 3 == 0:
  # 組み合わせを求める
  
  # (+2, +1) をa回、(+1, +2)をb回とすると、
  # a - b = X - Y
  #  -> a = X - Y + b
  # 2a + b = X
  # a + 2b = Y
  # -> (X - Y + b) + 2b = Y
  # -> 3b = 2Y - X
  # -> b = (2Y - X) // 3
  b = (2*Y - X) // 3
  a = X - Y + b
  # (+2, +1) をa回、(+1, +2)をb回の組み合わせ
  # a + b 個の移動の中から、(+2, +1)の移動を行う場所をa個選ぶ（順不同）
  # すなわち (a+B)_C_aを計算する
  print(combination(a+b, a, MOD))

else:
  print(0)

Measured memory_bytes: 40300
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll a,b,c;
  cin >> a >> b >> c;
  REP(i,1,111) if(a*i%b==c) {
    pr("YES");
    return;
  }
  pr("NO");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
S = list(input())

if len(S)%2 == 0:
    S1 = S[:len(S)//2]
    S2 = S[len(S)//2:]
else:
    S1 = S[:len(S)//2]
    S2 = S[(len(S)+1)//2:]    

res = 0
for i in range(len(S1)):
    if S1[i] != S2[-1*(i+1)]:
        res +=1

print(res)

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

using namespace std;

int n;

int v[3];

int main()
{
    cin >> v[0] >> v[1] >> v[2];

    sort(v + 0,v + 3);

    if((v[0] == v[1] && v[1] != v[2] ) || (v[0] != v[1] && v[1] == v[2]) )
        cout << "Yes\n";

    else
        cout << "No\n";



    return 0;
}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const long long SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑





int main() {

	int a, b, k[15][15], l[15], ans = 0,num[15];
	cin >> a >> b;

	for (int i = 0; i < b; ++i) {
		cin >> num[i];
		for (int j = 0; j < num[i]; ++j) {
			cin >> k[i][j];
			--k[i][j];
		}
	}
	for (int i = 0; i < b; ++i) {
		cin >> l[i];
	}

	for (int bit = 0; bit < (1 << a); ++bit) {
		int tuiteru = 0;
		for (int i = 0; i < b; ++i) {
			int on=0;
			for (int j = 0; j < num[i]; ++j) {
				if (bit&(1 << k[i][j])) { ++on; }
			}
			if (on % 2 == l[i]) { ++tuiteru; }
		}
		if (tuiteru == b) { ++ans; }

	}
	cout << ans << endl;

}

Measured memory_bytes: 256