akhauriyash/Code-Regression huggingface dataset:
#include <bitset>
#include <iostream>
#include <iterator>
#include <vector>

int h, w, k;

int solve(std::vector<std::string> c, int bh, int bw) {
  for (int i = 0; i < h; ++i)
    if (bh & (1 << i))
      for (int j = 0; j < w; ++j) {
        c.at(i).at(j) = '-';
      }

  for (int i = 0; i < w; ++i)
    if (bw & (1 << i))
      for (int j = 0; j < h; ++j) {
        c.at(j).at(i) = '-';
      }

  int cnt = 0;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      if (c.at(i).at(j) == '#')
        cnt++;
  return cnt;
}

int main(int argc, char *argv[]) {
  std::cin >> h >> w >> k;
  std::vector<std::string> c(h);
  for (int i = 0; i < h; ++i) {
    std::cin >> c.at(i);
  }

  int ans = 0;
  for (int i = 0; i <= ((1 << h) - 1); ++i)
    for (int j = 0; j <= ((1 << w) - 1); ++j) {
      ans += (solve(c, i, j) == k);
    }

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


Measured memory_bytes: 3164
import java.util.*;

public class Main {

	public static void main(String[] args){
	    Scanner s = new Scanner(System.in);
	    while(true){
		int in = s.nextInt(); // num of input
		if(in==0)break;
		int data[][] = new int[in][3];
		long out[] = new long[4001];
		LinkedList <Integer> o = new LinkedList <Integer> ();

		for(int i=0 ; i<in ; i++) { // input
		    for(int j=0 ; j<3 ; j++)
			data[i][j] = s.nextInt();
		}

		for(int i=0 ; i<in ; i++) {
		    out[data[i][0]] += (long) data[i][1]*data[i][2];
		    if(o.indexOf(data[i][0]) == -1)
			o.addLast(data[i][0]);
		}
		boolean flag = true; // none found

		while(o.size()!=0) {
		    int tmp = o.remove(0);
		    if(out[tmp]>=(long)1000000) {
			System.out.println(tmp);
			flag = false;
		    }
		}

		if(flag)
		    System.out.println("NA");
	    }
      	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool sortbysec(const pair<int,int> &a,
               const pair<int,int> &b)
{
    return (a.second < b.second);
}


int main()
{
    ll t=1,i,j,k=0,n,z,a,b,d,x,y,m;
     //cin>>t;
    while(t--)
    {
       cin>>n;
       if(n>=30)
        cout<<"Yes"<<endl;
       else
        cout<<"No"<<endl;


    }
    return 0;
}


Measured memory_bytes: 3448
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  2 17:11:49 2019

@author: Yamazaki Kenichi
"""

m = int(input())
A = input().split()
A = [''] + A

class CompleteBinaryTree(object):
    def __init__(self,size):
        self.table = [-1 for i in range(size)]
        
    def p(self,u):
        return u//2
    def left(self,u):
        return u*2
    def right(self,u):
        return u*2+1
cb = CompleteBinaryTree(m)

for i in range(1,m+1):
    res = ''
    res += 'node ' + str(i)
    res += ': key = ' + A[i] + ', '
    res += 'parent key = ' + A[cb.p(i)] + ', ' if i != 1 else ''
    res += 'left key = ' + A[cb.left(i)] + ', ' if cb.left(i) <= m else ''
    res += 'right key = ' + A[cb.right(i)] + ', ' if cb.right(i) <= m else ''
    print(res)
    


Measured memory_bytes: 5640
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
#endif
}
int n;
int a[N];
ll sum;
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>(),sum+=a[i];
}
ll s,x,tot,res;
void work()
{
	tot=1ll*n*(n+1)/2;
	if(sum%tot)puts("NO");
	else
	{
		a[n+1]=a[1];
		s=sum/tot;
		For(i,1,n)
		{
			//cerr<<s+a[i]-a[i+1]<<endl;
			if((s+a[i]-a[i+1])%n){puts("NO");return;}
			if(s+a[i]-a[i+1]<0){puts("NO");return;}
			res+=(s+a[i]-a[i+1])/n;
		}
		if(s==res)puts("YES");
		else puts("NO");
	}
}
int main()
{
//	file();
	input();
	work();
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> v(n, vector<ll>(n, INF));
  REP(i, n) v[i][i] = 0;
  vector<tuple<ll, ll, ll>> p;

  REP(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    v[a][b] = v[b][a] = c;
    p.emplace_back(a, b, c);
  }

  REP(k, n) REP(i, n) REP(j, n) { v[i][j] = min(v[i][j], v[i][k] + v[k][j]); }

  ll ans = 0;
  REP(i, m) {
    ll a, b, c;
    tie(a, b, c) = p[i];

    if (v[a][b] != c) ++ans;
  }

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

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {
	static final int M = 1000000007;
	static int[] xy = new int[2];
	static int gcd(int a, int b) {
		if (b == 0) {
			xy[0] = 1;
			xy[1] = 0;
			return a;
		} else {
			int d = gcd(b, a % b);
			int t = xy[0] - a / b * xy[1]; xy[0] = xy[1]; xy[1] = t;
			return d;
		}
	}
	static int inv(int a) {
		gcd(a, M);
		return (xy[0] % M + M) % M;
	}
	static int[] ff, gg;
	static void init(int n) {
		ff = new int[n + 1];
		gg = new int[n + 1];
		ff[0] = gg[0] = 1;
		for (int i = 1; i <= n; i++) {
			ff[i] = (int) ((long) ff[i - 1] * i % M);
			gg[i] = (int) ((long) gg[i - 1] * inv(i) % M);
		}
	}
	static int choose(int n, int k) {
		return (int) ((long) ff[n] * gg[n - k] % M * gg[k] % M);
	}
	static int solve(int h, int w) {
		return choose(h - 1 + w - 1, h - 1);
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int h = Integer.parseInt(st.nextToken());
		int w = Integer.parseInt(st.nextToken());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		init(h + w);
		int sum = 0;
		for (int i = 1; a + i <= h && b + i <= w; i++) {
			int w1 = solve(a + i, w + 1 - (b + i));
			int w2 = solve(h + 1 - (a + i), b + i);
			sum = (int) ((sum + (long) w1 * w2) % M);
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 24276
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <sstream>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int min = n / k;
	int max = min + (n % k);
  	cout << max - min << endl;
	return(0);
}





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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    cin>>N;
    vector<ll> P(N);
    vector<pair<ll,ll>> P_sorted(N);
    REP(i,N){
        cin>>P[i];
        P_sorted[i]=make_pair(P[i],i);
    }

    sort(P_sorted.begin(),P_sorted.end());
    ll ans=0;

    multiset<ll> st;
    st.insert(-1);
    st.insert(-1);
    st.insert(N);
    st.insert(N);

    REPD2(i,N-1,-1){
        ll num=P_sorted[i].first;
        ll idx=P_sorted[i].second;
        st.insert(idx);

        auto itr_r=st.find(idx);
        auto itr_l=st.find(idx);
        itr_r++;
        ll r2=*itr_r;
        itr_r++;
        ll r1=*itr_r;

        itr_l--;
        ll l2=*itr_l;
        itr_l--;
        ll l1=*itr_l;

        ans+=((l2-l1)*(r2-idx)+(r1-r2)*(idx-l2))*num;
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10224
#include<bits/stdc++.h>
#define ll long long
#define rint register int
using namespace std;
const int N=1e5+7;
int tot,n,m,q,v[N],d[N],c[N],first[N];
int f[N][11];
struct fuk
{
	int x,next;
}a[N<<2];
inline void add(int x,int to)
{
	tot++;
	a[tot].next=first[x]; a[tot].x=to; first[x]=tot;
}
void dfs(int x,int d,int col)
{
	if(d==-1) return;
	if(f[x][d]) return;
	f[x][d]=col; 
	for(int i=first[x];i;i=a[i].next)
	{
		int y=a[i].x;
		dfs(y,d-1,col);
	}
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;i++)
  {
  	int x,y; scanf("%d%d",&x,&y);
  	add(x,y); add(y,x);
  } 
  for(int i=1;i<=n;i++) add(i,i);
  scanf("%d",&q);
  for(int i=1;i<=q;i++) scanf("%d%d%d",&v[i],&d[i],&c[i]);
  for(int i=q;i>=1;i--)
	dfs(v[i],d[i],c[i]); 
  for(int i=1;i<=n;i++)
    printf("%d\n",f[i][0]);
  return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<unordered_map>
#include<math.h>
#include<stack>
#include<deque>
using namespace std;

signed main() {
	string a; cin >> a;
	if (a[0] == '9' || a[1] == '9')puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = LI()
    cnt = defaultdict(lambda : 0)
    for i in a:
        cnt[i] += 1
    for i in b:
        if not cnt[i]:
            continue
        cnt[i] += 1
    for i in cnt.values():
        if i > n:
            print("No")
            return
    r = n-1
    while 1:
        update = False
        for l in range(n):
            while r >= 0 and a[r] != b[r]:
                r -= 1
            if a[l] == b[l]:
                update = True
                b[l],b[r] = b[r],b[l]
                r -= 1
        if not update:
            break
    print("Yes")
    print(*b)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 131692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  int count=0;
  cin>>N>>M;
  vector<int>nichi(M);
  for(int i=0;i<M;i++){
    cin>>nichi.at(i);
    count+=nichi.at(i);
  }
  if(N>=count)
    cout<<N-count<<endl;
  else
    cout<<-1<<endl;
}

Measured memory_bytes: 3668
/*
srt: 2017年05月04日 09時46分22秒
《闲居初夏午睡起》杨万里（１１２７－１２０６）
梅子留酸软齿牙，芭蕉分绿与窗纱。
日长睡起无情思，闲看儿童捉柳花。
end: 2017年05月04日 10時26分20秒
*/

#include<cstdio>
#include<cstring>
inline void read(int&r)
{
	register char c;r=0;
	do c=getchar();while(c<'0'||c>'9');
	do r=r*10+c-'0',c=getchar();while(c>='0'&&c<='9');
}

typedef long long ll;
const ll inf=0x3f3f3f3f3f3f3f3fll;
#define umin(m,u) u<m&&(m=u)

ll a[200001],b[200001],dp[200001];int n;

void seta(int p,ll c){ a[p]=c;while(p<=n)umin(a[p],c),p+=p&-p; }
ll qrya(int p){ ll r=inf;while(p)umin(r,a[p]),p-=p&-p;return r; }

void setb(int p,ll c){ b[p]=c;while(p)umin(b[p],c),p-=p&-p; }
ll qryb(int p){ ll r=inf;while(p<=n)umin(r,b[p]),p+=p&-p;return r; }

#define set(p,c) dp[p]=c,seta(p,c-p),setb(p,c+p)
int main()
{
	int m,l,x;read(n),read(m),read(l),read(x);
	memset(a+1,0x3f,n*sizeof(ll));
	memset(b+1,0x3f,n*sizeof(ll));
	memset(dp+1,0x3f,n*sizeof(ll));

	set(l,0);ll c=0,$,_;

	while(m--)
	{
		l=x,read(x);
		c+=x>l?x-l:l-x;

		$=qrya(x)+x,_=qryb(x)-x;
		$=($<_?$:_)-(x>l?x-l:l-x);
		if($<dp[l])	set(l,$);
	}

	$=inf;
	for(int i=1;i<=n;i++)
		if(dp[i]<$)$=dp[i];
	printf("%lld\n",$+c);
}


Measured memory_bytes: 4864
c=[list(map(int,input().split())) for i in range(3)]

bl=c[0]
a2=c[1][0]-bl[0]
a3=c[2][0]-bl[0]
al=[0,a2,a3]
flag='Yes'
for i in range(3):
    for j in range(3):
        if c[i][j]!=al[i]+bl[j]:
            flag='No'
            break
print(flag)




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

int main(){
    string s; cin >> s;
    if (s.find("RRR") != string::npos) puts("3");
    else if (s.find("RR") != string::npos) puts("2");
    else if (s.find("R") != string::npos) puts("1");
    else puts("0");

    return 0;
}


Measured memory_bytes: 3620
#include<iostream>

using namespace std;

int main(){
    int  ame[3], total = 0, total2 = 0, i;
    bool flag = 0;
    for(i = 0; i < 3; i++){
        cin >> ame[i];
    }
    total = ame[0];
    total2 = ame[1] + ame[2];
    if(total == total2){
        cout << "Yes" << endl;
        flag = 1;
    }
    total = ame[1];
    total2 = ame[0] + ame[2];
    if(total == total2){
        cout << "Yes" << endl;
        flag = 1;
    }
    total = ame[2];
    total2 = ame[1] + ame[0];
    if(total == total2){
        cout << "Yes" << endl;
        flag = 1;
    }
    if(flag == 0) cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1)%1000000007;
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    string s;
    ll q,count=0;
    cin>>s>>q;
    vector<ll>t(q,0);
    for(ll i=0;i<q;i++){
        cin>>t[i];
        if(t[i]==2){
            string t;
            ll a;
            cin>>a>>t;
            if(a==1){
                if(count%2==0){
                    s.insert(0,t);
                }
                else{
                    s.insert(s.size(),t);
                }
            }
            else{
                if(count%2==0){
                    s.insert(s.size(),t);
                }
                else{
                    s.insert(0,t);
                }

            }
        }
        else{
            count++;

        }
        
    }
    if(count%2==1){
        reverse(s.begin(),s.end());
    }
    cout<<s<<endl;

    
        
}


Measured memory_bytes: 2564
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
 
using namespace std;
int N, M;
string S;

bool isKaibun(string, int, int);

int main()
{
  int n;
  int ret=0;

  cin >> S;

  n = S.size();
  if (isKaibun(S, 1, n) && isKaibun(S, 1, (n-1)/2) && isKaibun(S, (n+3)/2, n))
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}
bool isKaibun(string S, int b, int e) {
  int i;
//printf("isKaibun(%s, %d, %d)\n", S.c_str(), b, e);
  b--; e--;
  for (i=0; i<=(e-b)/2; i++) {
//printf("S[%d](%c) : S[%d](%c)\n", b+i, S[b+i], e-i, S[e-i]);
    if (S[b+i] != S[e-i]) return false;
  }
  return true;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }



int main()
{
    int N;
    string S;
    cin >> N >> S;
    int left,right;
    left = 0,right = 0;
    for(int i = 1; i < N; i++)
    {
        if(S[i] == 'E') right++;
    }
    int ans = right;
    for(int i = 1; i < N; i++)
    {
        if(S[i - 1] == 'W') left++;
        if(S[i] == 'E') right--;
        ans = min(ans,right+left);
    }
    cout << ans << endl;



}

Measured memory_bytes: 900
import collections

n = int(input())

dict = {}
for i in range(26):
    dict[chr(ord('a') + i)] = 50

for _ in range(n):
    S = input()
    for char in dict.keys():
        dict[char] = min(dict[char], S.count(char))
    
ans = ''
for char, num in sorted(dict.items()):
    ans += (char * num)

print(ans)
    

Measured memory_bytes: 3316
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const n: number = parseInt(tmp.shift().split(" ")[0]);
    const [s, t]: string = tmp.shift().split(" ");
    let result = "";
    for (let i = 0; i < n; i++) {
      result += s.charAt(i) + t.charAt(i);
    }
    return result;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 11468
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}


int main(){
    string s,t;
    cin >> s >> t;
    vector<int> cnts(26,0);
    vector<int> cntt(26,0);
    REP(i,s.size()){
        int c = s[i]-'a';
        cnts[c]++;
    }
    REP(i,t.size()){
        int c = t[i]-'a';
        cntt[c]++;
    }
    /*REP(i,26){
        int m = min(cnts[i],cntt[i]);
        cnts[i] -= m;
        cntt[i] -= m;
    }*/
    while(1){
        int mins = 26;
        int maxt = -1;
        REP(i,26){
            if(cnts[i]>0){
                chmin(mins,i);
            }
            if(cntt[i]>0){
                chmax(maxt,i);
            }
        }
        if(mins<maxt||(mins==26&&maxt!=-1)){
            put("Yes");
            return 0;
        }else if(mins>maxt){
            put("No");
            return 0;
        }else{
            cnts[mins]--;
            cntt[maxt]--;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int m; cin >> m;
    vector<int> x(m), y(m);
    for (int i = 0; i < m; i++) cin >> x[i] >> y[i];
    map<pair<int, int>, vector<int>> angles;
    for (int i = 0; i < m; i++) for (int j = 0; j < i; j++) {
        int dy = y[j] - y[i], dx = x[j] - x[i];
        int g = gcd(abs(dy), abs(dx));
        dy /= g, dx /= g;
        if (dy < 0) { dy = -dy, dx = -dx; }
        if (dy == 0) dx = 1;
        if (dx == 0) dy = 1;
        angles[{dy, dx}].emplace_back(1 << i | 1 << j);
    }
    vector<int> dp(1 << m, -1);
    dp[0] = 0;
    for (int s = 0; s < 1 << m; s++) if (~dp[s]) {
        for (auto &angle: angles) {
            vector<int> ts;
            ts.emplace_back(0);
            for (int p: angle.second) if (!(s & p)) {
                for (int i = ts.size() - 1; i >= 0; i--) {
                    int t = ts[i] | p;
                    int k = __builtin_popcount(t) / 2;
                    chmax(dp[s | t], dp[s] + k * (k - 1) / 2);
                    ts.emplace_back(t);
                }
            }
        }
    }
    cout << dp.back() << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstddef>
#include <vector>

enum {BUF_SIZE=(1<<17)};
char buf[BUF_SIZE|1], *pos, *endbuf;

inline int buffer() {
    size_t len=fread(buf, 1, BUF_SIZE, stdin);
    buf[len] = 0;
    endbuf = buf + len;
    pos = buf;
    return len;
}

inline int rebuffer() {
    ptrdiff_t left=endbuf-pos;
    if (buf+left >= pos)
        return *pos;

    memcpy(buf, pos, left);
    size_t len=fread(buf+left, 1, BUF_SIZE-left, stdin);
    endbuf = buf + (left+=len);
    *endbuf = 0;
    pos = buf;
    return len;
}

inline unsigned scan() {
    unsigned u=0;
    if (pos + 10 >= endbuf)
        rebuffer();

    do {
        u = u*10 + *pos-'0';
    } while (*++pos >= '0');

    ++pos;
    return u;
}

int main() {
    buffer();
    size_t N=scan();
    int M=scan();

    std::vector<int> B(N+1), R(N+1);
    R[1] = 1;

    for (int i=0; i<M; ++i) {
        size_t x=scan(), y=scan();

        ++B[y];
        if (R[x])
            R[y] = 1;

        if (--B[x] == -1)
            R[x] = 0;
    }

    int res=0;
    for (size_t i=1; i<=N; ++i)
        if (R[i])
            ++res;

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


Measured memory_bytes: 1152
import sys

input = sys.stdin.readline


def main():
    X = int(input())

    if X < 100:
        ans = 0
    else:
        q, r, = divmod(X, 100)
        if r <= 5 * q:
            ans = 1
        else:
            ans = 0

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C,D=0;
  str N;
  cin>>A>>B;
  if(A%500<=B)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int n;
    cin>>n;
    int p[n];
    rep(i,n)cin>>p[i];
    int a[n],b[n];
    a[0]=1;
    rep(i,n-1)a[i+1]=a[i]+45000;
    b[n-1]=1;
    rep(i,n-1)b[n-2-i]=b[n-1-i]+45000;
    rep(i,n){
        b[p[i]-1]+=i;
    }
    rep(i,n){
        if(i)cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    rep(i,n){
        if(i)cout<<" ";
        cout<<b[i];
    }
    cout<<endl;
}

Measured memory_bytes: 896
#include <cstdio>
const int MAXN = 2e5+5;
int seen[MAXN]{ };
int M, N;

int main() {
  scanf(" %d%d", &N, &M);
  int lhs = 1;
  int rhs = N;
  for (int i = 0; i < M; ++i) {
    printf("%d %d\n", lhs, rhs);
    ++lhs;
    --rhs;
    while (seen[rhs - lhs] ||
           seen[N - rhs + lhs] ||
           (2*rhs == N + 2*lhs)) --rhs;
    seen[rhs - lhs] = true;
    seen[N - rhs + lhs] = true;
  }
  return 0;
}

Measured memory_bytes: 3896
import math
import sys
def sieve(n):
    if n < 2:
        is_prime = [False for _ in range(n+1)]
        return is_prime
 
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
 
    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
 
    return is_prime

input = sys.stdin.readline
N=10**5
prime=sieve(N)
a=[0 for i in range(N+1)]
for i in range(3,N+1):
	if prime[i] and prime[(i+1)//2]: a[i]=a[i-1]+1
	else: a[i]=a[i-1]

for i in range(int(input())):
	l,r=map(int,input().split())
	print(a[r]-a[l-1])

Measured memory_bytes: 5468
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=0;i<=1000000;i++) {
	if(a%2||b%2||c%2) return cout<<i,0;
	int A=(b+c)/2,B=(a+c)/2,C=(a+b)/2;
	a=A,b=B,c=C;
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

#ifndef INF
#define INF 1000000ULL
#endif

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int sum_digits(unsigned long long n){
	int ret = 0;
	int digit = log10(n) + 1;
	for(int i = 0; i < digit; i++){
		ret += ctoi(to_string(n).at(i));
	}
	return ret;
}

int main(){
	int n, ret;
	cin >> n;
	if(n%2 == 0){
		ret = n;
	}else{
		ret = n*2;
	}
	cout << ret << endl;
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> v(N);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }

  sort(v.begin(), v.end());

  ll ans = 0;
  int cnt = 0;
  rep(i, N) {
    if (cnt == M)
      continue;
    int a = v[i].first, b = v[i].second;
    int c = min(b, M - cnt);
    cnt += c;
    ans += (ll)c * a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
    int x;
    char a;
    cin>>x;
    int ans=x;
    
    while(1){
        cin>>a;
        if(a=='=')break;
        
        cin>>x;
        if(a=='+'){
            ans+=x;
        }
        if(a=='-'){
            ans-=x;
        }
        if(a=='*'){
            ans*=x;
        }
        if(a=='/'){
            ans/=x;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3088
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll qpow(ll a,ll k){ll s=1;while(k){if(k&1)s=s*a%mod;a=a*a%mod;k>>=1;}return s;}

ll cnt[maxn];

int main() {
    int n=read(), k=read();
    ll res=0;
    /*for(int i=1; i<=n; ++i) {
        int x=i;
        for(int j=2; j*j<=x; ++j) if(x%j==0) {
            while(x%j==0) cnt[i]++, x/=j;
        }
        if(x>1) cnt[i]++;
    }*/
    for(int i=1; i<=k; ++i) {
        ll tmp=qpow(i,n);
        for(int l=2, r; l<=i; l=r+1) {
            r=i/(i/l);
            tmp=(tmp-(r-l+1)*cnt[i/l]%mod+mod)%mod;
        }
        cnt[i]=tmp;
    }
    for(int i=1; i<=k; ++i) {
        res=(res+i*cnt[k/i])%mod;
    }
    cout<<res<<endl;
}

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

int main() {
  string s;
  int q;
  int comm=0;
  int rule;
  char chara;
  int placeholder;
  cin >> s >> q;
  for(int i=0;i<q;i++){
    cin >> placeholder;
    if(placeholder==1){
      comm++;
    } else{
      cin >> rule >> chara;
      if(comm%2==0){
        if(rule==1){
          s.insert(s.begin(),chara);
        } else{
          s.insert(s.end(),chara);
        }
      } else{
        if(rule==2){
          s.insert(s.begin(),chara);
        } else{
          s.insert(s.end(),chara);
        }
      }
    }
  }
  if(comm%2) reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    char b,ans;
    cin >> b;
    if (b == 'A')
    ans = 'T';
    if (b == 'T')
    ans = 'A';
    if (b == 'G')
    ans = 'C';
    if (b == 'C')
    ans = 'G';
        cout << ans << endl; 
}

Measured memory_bytes: 256
#include <cstdio> 
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm>
#include <cstdlib> 
#include <cstring>
#include <map>

using namespace std;

#define REP(i,j,k) for(int i=j;i<(int)(k);++i)
#define rep(i,j) REP(i,0,j)
#define F first
#define S second

typedef pair<int,int> P;

const int mid = 510;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int field[1020][1020];
P dp[1020][1020];
bool is_prime[1000010];
int n, st;
map<int,P> mp;

void init(){
    memset(field,-1,sizeof(field));
    int i=0;
    int x=mid,y=mid;
    REP(N,1,1000010){
        field[y][x] = N;
        mp[N] = P(y,x);
        if(field[y+dy[i]][x+dx[i]]==-1) {
            y += dy[i]; x += dx[i];
            i = (i+1)%4;
        }else{
            y += dy[(i+4-1)%4]; x += dx[(i+4-1)%4];
        }
    }

    rep(i,1000010) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i*i<1000010;++i)if(is_prime[i]){
        for(int j=i*i;j<1000010;j+=i) is_prime[j]=false;
    }
}

P solve(const int& y, const int& x){
    P ans(0,0);
    dp[y][x] = is_prime[field[y][x]]?P(1,field[y][x]):P(0,0);
    
    rep(i,1020)rep(j,1020){
        if(dp[i][j]==P(-1,-1)) continue;
        ans = max(ans,dp[i][j]);
        REP(k,-1,2){
            if(field[i+1][j+k]>n||field[i+1][j+k]==-1) continue;
            dp[i+1][j+k] = max(dp[i+1][j+k],is_prime[field[i+1][j+k]]?
                               P(dp[i][j].F+1,field[i+1][j+k]):dp[i][j]);
        }
    }
    return ans;
}

int main(){
    init();
    while(cin >> n >> st,n||st){
        rep(i,1020)rep(j,1020) dp[i][j] = P(-1,-1);
        P ans = solve(mp[st].F,mp[st].S);
        cout << ans.F << " " << ans.S << endl;
    }
    return 0;
}

Measured memory_bytes: 76872
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	boolean[] primeList;
	
	boolean isPrime(int n) {
		if (n < 0) return false;
		return primeList[n];
	}
	
	boolean[] getPrimeList(int n) {
		boolean[] res = new boolean[n+1];
		
		Arrays.fill(res, true);
		
		res[0] = res[1] = false;
		for (int i = 2; i < res.length; i++) {
			if (!res[i]) continue;
			for (int j = 2 * i; j < res.length; j += i) {
				res[j] = false;
			}
		}
		
		return res;
	}
	
	public void run() {
		primeList = getPrimeList(200000);
		while (true) {
			int n = in.nextInt(), m = in.nextInt();
			if (n == -1) break;
			int[] p = new int[m];
			for (int i = 0, x = n + 1; i < m; x++) {
				if (isPrime(x)) {
					p[i++] = x;
				}
			}
			
			int[] sum = new int[m*m];
			Arrays.fill(sum, Integer.MAX_VALUE);
			for (int i = 0, idx = 0; i < m; i++) {
				for (int j = i; j < m; j++) {
					int temp = p[i] + p[j];
					sum[idx++] = temp;
				}
			}
			
			Arrays.sort(sum);
			
			System.out.println(sum[m-1]);
		}
		
		out.close();
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

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

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

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Measured memory_bytes: 43192
#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;

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

	int ans = 1;
	char preCh = S[0];
	rep(i, N) {
		if (preCh != S[i]) {
			ans++;
			preCh = S[i];
		}
	}
	cout << ans;
}



Measured memory_bytes: 512
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    double L;
	std::cin >> L;

	double ans = pow(L / 3.0, 3);
	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 4248
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
using namespace std;

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

int gcd_of_vector(vector<int> A, int begin, int end){
  int result = A[begin];
  for(int i=begin;i<end;i++){
    result = gcd(A[i],result);
  }
  return result;
}

int gcd_of_vector_with_skip(vector<int> A, int skip){
  int result = A[0];
  if(skip==0)result=A[1];
  for(int i=1;i<A.size();i++){
    if(i==skip)continue;
    result = gcd(A[i],result);
  }
  return result;
}

int main()
{
  int N,ans,gcd1,gcd2;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }

  if(N>=10){
    ans=1000000010;
    random_device seed_gen;
    mt19937 engine(seed_gen());
    for(int i=0;i<5;i++){
      shuffle(A.begin(),A.end(),engine);
      gcd1 = gcd_of_vector(A,1,N/2);
      gcd2 = gcd_of_vector(A,N/2,N);
      ans = min(ans,max(gcd1,gcd2));
    }
  }else{
    ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,gcd_of_vector_with_skip(A,i));
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    ll i,j,k,n,m;
    cin >> k;
    ll t = 7%k;
    m = 1;
    if(k==1 || k==7) {
        cout <<"1\n";
        return 0;
    }
    ll flag = 0;
    for(m = 2 ; m <= 1e7 ; m++){
        t = ( ((t%k)*(10%k))%k + (7%k) )%k;
        if(t==0){
            flag= 1;
            break;
        }
    }
    if(flag) cout <<m <<"\n";
    else cout <<"-1\n";
} 

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef signed long long int ll;
#define INF (1<<29)
int l;
ll a[200005];
//ll a;
ll dp[200005][5]={0};
int main(){
    cin>>l;
    //for(int i=0;i<l;i++) cin>>a[i];
    
    /*for(int i=0;i<5;i++){
        for(int j=0;j<l+2;j++){
            dp[j][i]=INF;
        }
    }*/
    
    //for(int i=0;i<5;i++) dp[0][i]=0;
    
    for(int i=1;i<=l;i++){
        cin>>a[i-1];
        int b=(a[i-1]==0?2:(a[i-1]%2));
        
        int c=!(a[i-1]%2);
        
        dp[i][0]=dp[i-1][0]+a[i-1];
        
        dp[i][1]=min(dp[i][0],dp[i-1][1]+b);
        
        dp[i][2]=min(dp[i][1],dp[i-1][2]+c);
        
        dp[i][3]=min(dp[i][2],dp[i-1][3]+b);
        
        dp[i][4]=min(dp[i][3],dp[i-1][4]+a[i-1]);
        
    }
    cout<<dp[l][4]<<endl;
    return 0;
    
}


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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int n, l;
    cin >> n >> l;

    string s[n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    
    sort(s, s + n);
    for (int i = 0; i < n; i++)
        cout << s[i];
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
def solve():
    N, *abc = map(int, open(0).read().split())
    a = abc[::3]
    b = abc[1::3]
    c = abc[2::3]
    
    dp = [[10 ** 10] * 3 for _ in range(N)]
    dp[0][0], dp[0][1], dp[0][2] = a[0], b[0], c[0]
    for i in range(1, N):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]
    print(max(dp[N - 1]))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 100780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    vector<int> x(n), y;
    for(int i=0; i<n; i++){
        cin >> x[i];
        y.push_back(x[i]);
    }
    sort(x.begin(), x.end());
    for(int i=0; i<n; i++){
        if(y[i] < x[n/2]) cout << x[n/2] << endl;
        else cout << x[(n/2)-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 5016
#include <bits/stdc++.h>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main()
{
	int K = 38;
	int N = 1 + K * (K - 1);

	printf("%d %d\n", N, K);
	vector<vector<int> > sol(N, vector<int>());

	int ni = 0;

	for (int i = 0; i < K; ++i) {
		for (int j = 0; j < K - 1; ++j) {
			sol[i * (K - 1) + j].push_back(ni);
		}
		sol[N - 1].push_back(ni);
		++ni;
	}
	for (int i = 0; i < K - 1; ++i) {
		for (int j = 0; j < K - 1; ++j) {
			sol[i].push_back(ni);
			for (int k = 0; k < K - 1; ++k) {
				int row = k + 1;
				int col = (j + i * k) % (K - 1);
				sol[row * (K - 1) + col].push_back(ni);
			}
			++ni;
		}
	}
	for (int i = 0; i < sol.size(); ++i) {
		for (int j = 0; j < K; ++j) printf("%d%c", sol[i][j] + 1, j == K - 1 ? '\n' : ' ');
	}
	return 0;
}

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

signed main() {
	int n; cin >> n;
	ll sum = 1;
	for (int i = 1; i <= n; i++)(sum *= i) %= MOD;
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 2e5+5;
int pre[M],suf[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	s = "$"+s;
	int c = 0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='#')
			c++;
		pre[i] = c;
	}
	c = 0;
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='.')
			c++;
		suf[i] = c;
	}
	int ans = n;
	for(int i=0;i<=n;i++)
	{
		ans = min(ans, pre[i]+suf[i+1]);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5308
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++)cin >> v[i];
  sort(v.begin(), v.end());
  cout << v.back() - v.front() << endl;
  return 0;
}

Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll N=1e5+5;

int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n;i++)
	{
	    cin>>a[i];
	    if(a[i]==0)
	    {
	        cout<<0;
	        return 0;
	    }
	}
	ld ans1=0;
	for(ll i=0; i<n; i++)
	ans1+=log10(a[i]);
	if(ans1>18.1)
	{
	    cout<<-1;
	    return 0;
	}
	ll ans=1;
	for(ll i=0;i<n; i++)
	ans*=a[i];
	if(ans>1000000000000000000)
	{
	    cout<<-1;
	    return 0;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4664
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back


int main()
{
   ll n,m,k,i,j,x,l;
  
   cin>>n>>l;
   ll sum=0;   
   for(i=1;i<=n;i++)
   {
      sum+=(l+i-1);
   }

   ll tmp=sum;
   ll diff=1e8;
   for(i=1;i<=n;i++)
   {
      if(abs(l+i-1)<diff)
      {
         diff=abs(l+i-1);
         tmp=sum-(l+i-1);
      }
   }

   cout<<tmp;
}  


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int D[N];
  for (int i = 0; i < N; i++)
    cin >> D[i];
  int M;
  cin >> M;
  int T[M];
  for (int i = 0; i < M; i++)
    cin >> T[i];
  map<int, int> md;
  for (int i = 0; i < N; i++)
  {
    if (md.find(D[i]) == md.end())
      md[D[i]] = 1;
    else
      md[D[i]] = md[D[i]] + 1;
  }
  map<int, int> mt;
  for (int i = 0; i < M; i++)
  {
    if (mt.find(T[i]) == mt.end())
      mt[T[i]] = 1;
    else
      mt[T[i]] = mt[T[i]] + 1;
  }
  string ans = "YES";
  for (auto t : mt)
  {
    int key = t.first;
    if (md.find(key) == md.end())
      ans = "NO";
    if (md[key] < mt[key])
      ans = "NO";
  }
  cout << ans << endl;
  return 0;
}

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

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

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m);
 cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, count=0;
  string s;
 
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  double ans = w*h/2;

  cout << fixed << setprecision(10) << ans << " ";
  if(x==w/2&&y==h/2) cout << 1 << endl;
  else cout << 0 << endl;
  
  
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];

	vi dp;
	dp.push_back(a[0]);
	for(int i = 1; i < n; i++) {
		int j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
		if(j < dp.size()) dp[j] = a[i];
		else dp.push_back(a[i]);
	}
	cout << dp.size() << endl;
}



Measured memory_bytes: 3716
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]


def search(arr, x):
    l, r = 0, len(arr)
    while abs(r - l) > 1:
        mid = (l + r) // 2
        if arr[mid] <= x:
            l = mid
        else:
            r = mid
    return l


ans = 0
for i in range(len(a)):
    rest = k - a[i]
    if rest < 0:
        break
    bidx = search(b, rest)
    if bidx == -1 or bidx == len(b):
        continue
    ans = max(ans, i + bidx)
print(ans)

Measured memory_bytes: 42188