akhauriyash/Code-Regression huggingface dataset:
def main():
    s = input()
    n = len(s)
    a = [0] * n
    rl = 0
    l, r = 0, 0
    for i in range(n - 1):
        if s[i] == "R" and s[i + 1] == "L":
            rl = i
        if s[i] == "L" and s[i + 1] == "R":
            l = i
            w = l - r + 1
            a[rl] += w // 2 + (w % 2 and not rl % 2 ^ r % 2)
            a[rl + 1] += w // 2 + (w % 2 and rl % 2 ^ r % 2)
            r = i + 1
    l = n - 1
    w = l - r + 1
    a[rl] += w // 2 + (w % 2 and rl % 2 == r % 2)
    a[rl + 1] += w // 2 + (w % 2 and rl % 2 != r % 2)
    print(*a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int k, s;
    cin >> k >> s;
    ll cnt = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (z >= 0 && z <= k) cnt++;
        }
    }
    cout << cnt << endl;
}

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

public class Main {
	final Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().A();
	}
	
	void B(){
		while(sc.hasNext()){
			char[] R=sc.next().toCharArray();
			if(R[0]=='-')	break;
			char[] G=sc.next().toString().toCharArray(),dd=sc.next().toCharArray();
			char now=G[0];
			int gi=1,ri=0,di=0;
			StringBuilder d=new StringBuilder(),r=new StringBuilder();
			while(true){
				//System.out.println("N"+now);
				if(di<dd.length){
					if(now==dd[di]){
						d.append(now);
						di++;
						now=R[ri++];
					}else{
						r.append(now);
						if(gi+1>R.length)	break;
						now=G[gi++];
					}
				}else{
					if(G[gi-1]!=now)	r.append(now);
					break;
				}
			}
			while(gi<G.length)	r.append(G[gi++]);
			System.out.println("D:"+d);
			System.out.print("ANS=");
			System.out.println(r);
		}
	}
	void A(){
		while(true){
			int W = sc.nextInt(), Q = sc.nextInt();
			if(W == 0 && Q == 0){
				break;
			}
			int [] b = new int[W];
			Arrays.fill(b, -1);
			while(Q-- > 0){
				String  str = sc.next();
				int id = sc.nextInt();
				if(str.equals("s")){
					int x = sc.nextInt();
					boolean flg2 = true;
					for(int i=0; i <= W - x; i++){
						boolean flg = true;
						for(int j= i; j < i + x; j++){
							if(b[j] != -1){
								flg = false;
								break;
							}
						}
						if(flg){
							flg2 = false;
							System.out.println(i);
							for(int j = i; j < i + x; j++){
								b[j] = id;
							}
							break;
						}
					}
					if(flg2){
						System.out.println("impossible");
					}
				}
				else{
					for(int i=0; i < W; i++){
						if(b[i] == id){
							b[i] = -1;
						}
					}
				}
				//debug
//				System.out.print("DEB= ");
//				for(int i=0; i < b.length; i++){
//					System.out.print(b[i]);
//				}
//				System.out.println();
			}
			System.out.println("END");
		}
	}
}

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

int main(){
    int n,m; cin >> n >> m;
    vector<int> s(m),c(m);
    for (int i = 0; i < m; i++)
    {
        cin >> s.at(i) >> c.at(i);
    }
    vector<int> ans(n,-1);
    for (int i = 0; i < m; i++)
    {
        int digit = s.at(i) - 1;
        int num = c.at(i);
        if (digit == 0 && num == 0 && n != 1)
        {
            cout << -1 << endl;
            return 0;
        }
        if (ans.at(digit) == -1 || ans.at(digit) == num)
        {
            ans.at(digit) = num;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }

        
    }

    for (int i = 0; i < n; i++)
    {
        if (ans.at(i) == -1) ans.at(i) = 0;
    }
    
    if (n != 1 && ans.at(0) == 0)ans.at(0) = 1;


    for (auto &&i : ans)
    {
        cout << i;
    }
    
    cout << endl;
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int w=5e5+5;
const ll mod=1e9+7;
int main()
{
    int i,j;
    ll x,y;
    cin>>x>>y;
    if(x>=10)
        cout<<y<<endl;
    else
    {
        cout<<100*(10-x)+y<<endl;
    }
    return 0;
}


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

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;




int way[510][510];

int dcnt = 1;//dfsの階層
void fill(VI a, VI b,int dc) {//２つのベクトルを受け取ってレベルdcの道を形成
	int as = a.size();int  bs = b.size();
	rep(i, as)rep(j, bs) {
		int ta = a[i];int tb = b[j];
		if (ta > tb)swap(ta, tb);
		if (way[ta][tb])continue;
		way[ta][tb] = dc;
		//cout << ta << " " << tb << " " << dc << endl;
	}
}

void dfs(VI tn,bool rev,int dcnt) {//rev==1なら席を反転,dcnt dfsの階層
	int ts = tn.size();
	VI ma, usi;
	rep(i, (ts+1) / 2)ma.push_back(tn[i]);
	for (int i = (ts+1)/2; i < ts; i++)
	{
		usi.push_back(tn[i]);
	}
	if (rev)swap(ma, usi);
	fill(ma, usi, dcnt);
	if (tn.size() <= 2)return;
	dfs(ma, 0, dcnt + 1);dfs(usi, 1, dcnt + 1);
}
int main() {
	int n;
	cin >> n;
	VI tn(n);
	for (int i = 0; i < n; i++)
	{
		tn[i] = i;
	}
	dfs(tn,0,1);
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			cout << way[i][j] << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 1536
import java.util.Scanner;

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

        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();

        double min = 999999999;
        int point = 0;

        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            double temp = t - (h[i] * 0.006);
            double difference = Math.abs(a - temp);
            if (difference < min) {
                min = difference;
                point = i;
            }
        }
        System.out.println(point + 1);
    }
}


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

typedef long long ll;

ll n, a, b;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> a >> b;
	if (a % 2 == b % 2) {
		cout << (b - a) / 2;
		return 0;
	}
	cout << min(a + (b - a - 1) / 2, n - b + 1 + (b - a - 1) / 2);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;

const int Maxd = 10;

int H, W;
int dist[Maxd][Maxd];
int res;

int main()
{
	scanf("%d %d", &H, &W);
	for (int i = 0; i < Maxd; i++)
		for (int j = 0; j < Maxd; j++)
			scanf("%d", &dist[i][j]);
	for (int k = 0; k < Maxd; k++)
		for (int i = 0; i < Maxd; i++)
			for (int j = 0; j < Maxd; j++)
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++) {
			int a; scanf("%d", &a);
			if (a != -1) res += dist[a][1];
		}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
def f(i,n):
  ans =0
  cnt = i
  while n%cnt == 0:
    n//=cnt
    cnt*=i
    ans +=1
  while n%i ==0:
    n//=i
  return n,ans

n = int(input())
i = 2
ans = 0
while i <= int(n**0.5)+1:
  if n%i ==0:
    n,a = f(i,n)
    ans += a
  i += 1
  
if n >1:
  ans += 1
print(ans)



Measured memory_bytes: 9456
from collections import deque

K = int(input())
dque = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

ans = 0
while True:
    v = dque.popleft()
    ans += 1
    if ans == K:
        print(v)
        exit(0)

    strv = str(v)
    if strv[-1] == '0':
        dque.append(int(strv+'0'))
        dque.append(int(strv+'1'))
    elif strv[-1] == '9':
        dque.append(int(strv+'8'))
        dque.append(int(strv+'9'))
    else:
        endv = int(strv[-1])
        dque.append(int(strv+str(endv-1)))
        dque.append(int(strv+str(endv)))
        dque.append(int(strv+str(endv+1)))


Measured memory_bytes: 10904
#include<bits/stdc++.h>
#include<time.h>
#define loop(i,c,n) for(long long i=c;i<n;i++)
#define iter(v) for(auto x : v)  // to iterate over entire vector/sets/map
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
int ab(int a) {if (a < 0)return -a; return a;}
int max(int a, int b) {
	if (a > b)return a;
	return b;
}
//optimised school method
bool isPrime(ll a) {
	if (a <= 1)return false ;
	if (a <= 3)return true ;
	if (a % 2 == 0 || a % 3 == 0)return false;
	for (ll i = 5; i * i <= a; i = i + 6) { //Instead of checking till n, we can check till √n because a larger factor of n
//must be a multiple of smaller factor that has been already checked.
		if (a % i == 0 || a % (i + 2) == 0)return false;
	} return true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//  to read input from local files
#ifndef ONLINE_JUDGE
	clock_t clocktime;
	clocktime = clock();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// to read entire line with spaces
	// string s;
	// getline(cin,s);

	// when amount of data is unknown
	// while(cin>>x){}

	int n ;
	cin >> n ;
	vi v(n); 
	int max= - 1;
	loop(i,0,n){cin>>v[i];if(v[i]>max)max =v[i];}   
	//sort(v.rbegin(),v.rend());
	vector<int> b(max+1,1) ;
iter(v){
	if(b[x]==1){ b[x]++;
		for(int j=2;x* j<b.size();j++){b[x*j]=false;}
	}else if(b[x]>1)b[x]=0;} 
int ans=0;
iter(v){if(b[x])ans++;}cout<<ans;

#ifndef ONLINE_JUDGE
	clocktime = clock() - clocktime;
	double runtime  = (((double)clocktime) / CLOCKS_PER_SEC);
	cout << "\n--------\nTimeUsed -- " << runtime << "s";
#endif
	return 0;
}

Measured memory_bytes: 7848
#include<bits/stdc++.h>
#define ll                    long long int
#define ull                   unsigned long long int
#define vll                   vector<long long int>
#define loop(i,a,b) 		  for(ll i=(ll)a;i<(ll)b;++i)
#define pb                    push_back
#define ii					  pair<int, int> 
#define vii					  vector<ii>
#define vvi					  vector<vector<int>> 
#define pi                    acos(-1.0)
#define MOD                   1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void f_io(){
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int main()
{
	f_io();
	ll t,n,k,a,b,c,d,x,y;
  
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(k>0){
        if(k>=a){
        ans+=a;
        k-=a;
        }else{
            ans+=k;
            k=0;
        }
    }
     if(k>0){
        if(k>=b){
        ans+=0;
        k-=b;
        }else{
            ans+=0;
            k=0;
        }
    }
    if(k>0){
        if(k>=c){
        ans+=-c;
        k-=c;
        }else{
            ans+=-k;
            k=0;
        }
    }
    cout<<ans;
    
 
 
}

Measured memory_bytes: 3652
import java.util.*;

public class Main{
  
  public static void main (String[] args){
    
    Main main = new Main ();
    main.solve();
  }
  
  private void solve(){
    
    Scanner scanner = new Scanner (System.in);
    
    int N = scanner.nextInt();
    int T = scanner.nextInt();
    int A = scanner.nextInt();
    
    double nearOndo =0;
    int nearIndex=26;
    for (int index=0; index<N; index++){
      int temp = scanner.nextInt();
      double ondo = T-(temp*0.006);
      if (index==0){
        nearOndo=ondo;
        nearIndex=index;
   	  }else if (Math.abs(ondo-A)<Math.abs(nearOndo-A)){
        nearOndo=ondo;
        nearIndex=index;
      }
    }
    System.out.println(nearIndex+1);
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define f first
#define s second
 
#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)
 
#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)
#define fill_nd(a,p2f,val) fill(p2f,p2f+sizeof(a)/sizeof(*p2f),val)
 
#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"
 
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;
 
const int sz= 1e5+5;
const int M = 998244353;

vi prime;

void seive(int n){
	int sqn = sqrt(n), sq2n = sqrt(sqn);

	bool isprime[sqn+1];
	memset(isprime,1,sizeof(isprime));

	for(int i=2;i<=sq2n;++i){
		if(isprime[i])
			for(int j=i<<1;j<=sqn;j+=i)
				isprime[j]=0;
	}
	for(int i=2;i<=sqn;++i)
		if(isprime[i])
			prime.pb(i);

	// finding primes in [i+1,i+sqn]; i is a multiple of sqn
	for(int i=sqn;i<n;i+=sqn){
		memset(isprime,1,sizeof(isprime));
		sq2n = sqrt(i+sqn);
		for(int p: prime){
			if(p>sq2n)
				break;
			for(int j=(i/p+1)*p;j<=i+sqn;j+=p)
				isprime[j-i]=0;
		}
		for(int j=1;j<=sqn;++j)
			if(isprime[j])
				prime.pb(j+i);
	}
}

ll pow_mod(ll base, ll pow){
	ll ans = 1;
	while(pow){
		if(pow&1)
			ans = ans*base%M;
		base = base*base%M;
		pow>>=1;
	}
	return ans;
}

ll fac[200005];
ll inv_fac[200005];

void factorial(int n){
	fac[0] = fac[1] = 1;
	for(int i=2;i<=n;++i)
		fac[i] = fac[i-1]*i%M;

	inv_fac[n] = pow_mod(fac[n],M-2);
	for(int i=n-1;i>=0;--i){
		inv_fac[i] = inv_fac[i+1]*(i+1)%M;
	}
}

ll multinomial(vi& list){
	ll sum = 0, ans = 1;
	for(int i=0;i<list.size();++i){
		sum+=list[i];
		ans = ans*inv_fac[list[i]]%M;
	}
	ans = ans*fac[sum]%M;
	return ans;
}

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


int main() {
	int a,b;
	cin>>a>>b;
	cout<<a*b;










	return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
int main(void){
  int i, j, h, m, s;
  scanf("%d",&i);
  h=i/3600;
  j=i%3600;
  m=j/60;
  s=j%60;
  printf("%d:%d:%d\n",h,m,s);
 return 0;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    int ans = max(a,b);
    if(a>b) a =a-1;
    else b =b-1;
    ans+=max(a,b);
    cout<<ans<<endl;
}

Measured memory_bytes: 384
N = int(input())
A = map(int, input().split())

cnt = 0
for a in A:
    if a % 2 == 0:
        if a % 3 == 0:
            cnt += 1
        elif a % 5 == 0:
            cnt += 1
    else:
        cnt += 1
print('APPROVED' if N == cnt else 'DENIED')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main()
{
    iso;
    int n;
    cin>>n;
    int ar[n+1];
    f(i,1,n+1)cin>>ar[i];
    ll dp[n+1];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(ar[1]-ar[2]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
    }
    cout<<dp[n];
}


Measured memory_bytes: 1408
#include <stdio.h>
 
int main(){
    int a,b,c;
 
    scanf("%d %d %d",&a,&b,&c);
    if( (a==5 && b == 5 && c == 7) || (a==5 && b == 7 && c == 5) || (a==7 && b == 5 && c == 5) )
        printf("YES\n");
    else
        printf("NO\n");
 
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  
  for (int i = 0; i < N; i++)
  {
  	cin >> A[i];
  }
  
  int counter = 0;
  bool flag = true;
  
  while (flag == true)
  {
    for (int i = 0; i < N; i++)
    {
        if (A[i] == 0)
        {
          flag = false;
          break;
        }
    	else if (A[i] % 2 == 0) 
        {
          A[i] = A[i] /2;
          if (i == N - 1) counter++;
        }
      	else
        {
          flag = false;
          break;
        }
    }
  }
  
  cout << counter << endl;
  
  return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
d = []
a = []
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))

cnt = 0
for i in range(1,n+1):
    if i not in set(sum(a,[])):
        cnt += 1
print(cnt)

Measured memory_bytes: 8916
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int a, b, c, x,count=0;
	cin >> a >> b >> c >> x;

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (i * 500 + j * 100 + k * 50 == x) {
					count++;
				}
			}
		}
	}

	cout << count << endl;
	return 0;
}

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

int main()
{
    int N, K, s;
    cin >> N >> K;
    s = 1;
    for (int i = 0; i < N; i++)
    {
        if (s * 2 < s + K)
        {
            s *= 2;
        }
        else
        {
            s += K;
        }
    }

    cout << s << endl;
}

Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, m, i, j, sumt, sumh , tt, th;
    int[] st, sh;

    for(;;){
      n = sc.nextInt(); m = sc.nextInt();
      if(n == 0 && m == 0)break;
      st = new int[n]; sh = new int[m];
      sumt = 0;sumh = 0; tt = 201; th = 201;
      for(i = 0;i < n;i++){
        st[i] = sc.nextInt(); sumt += st[i];
      }
      for(i = 0;i < m;i++){
        sh[i] = sc.nextInt(); sumh += sh[i];
      }

      for(i = 0;i < n;i++)for(j = 0;j < m;j++){
        if(sumt - 2 * st[i] == sumh - 2 * sh[j] && tt + th > st[i] + sh[j]){
          tt = st[i]; th = sh[j];
        }
      }

      if(tt != 201 && th != 201)out.println(tt + " " + th);
      else out.println("-1");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 21016
#include <iostream>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

signed main() {
	int M, D; cin >> M >> D;
	int ans = 0;
	REP(m, 1, M + 1)
		REP(d, 1, D + 1) {
			int d1 = d % 10, d10 = d/10 % 10;
			if (d1 > 1 && d10 > 1 && d1 * d10 == m)
				++ans; 
		}
	cout << ans;
}

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

using namespace std;

const int MAX_N = 50 + 5;
const long long MOD = 1e9 + 7;

typedef long long ll;

int n, k;
int arr[MAX_N];
int ans = 0;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    for (int i = 1; i <= min(k, n); i++) {
        for (int j = 0; j <= i; j++) {
            vector<int> tmp;
            for (int h = 1; h <= j; h++) tmp.push_back(arr[h]);
            for (int h = n; h >= n - (i - j) + 1; h--) tmp.push_back(arr[h]);
            sort(tmp.rbegin(), tmp.rend());
            for (int h = 0; h < k - i && !tmp.empty() && tmp.back() < 0; h++)
                tmp.pop_back();
            int cur = 0;
            for (int x : tmp)
                cur += x;
            ans = max(ans, cur);
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/



int main(){
    ll n;
    cin>>n;
    vec(a,n);
    vec(b,0);
    vec(c,0);
    vec(d,0);
    a=getv<ll>(n);
    rep(i,n){
        if(i%2==0){
            b.push_back(a[i]);
        }else {
            d.push_back(a[i]);
        }
    }
    
    if(n%2==1){
        rep(i,b.size()){
            c.push_back(b[b.size()-1-i]);
        }
        c.insert(c.end(),d.begin(),d.end());
    }else{
        rep(i,d.size()){
            c.push_back(d[d.size()-1-i]);
        }
        c.insert(c.end(),b.begin(),b.end());
    }
    putv(c);
    return 0;
}

Measured memory_bytes: 9044
import collections

N = int(input())
SSS = []

for i in range(N):
  SSS.append(input())
#print(N, SSS)

#print(collections.Counter(SSS).most_common())
hindo_ck = collections.Counter(SSS).most_common()

i = 1
hindo_max = list(hindo_ck[0])

if len(hindo_ck) > 1:
  del hindo_max[-1]
  while i < N and hindo_ck[i-1][1] == hindo_ck[i][1]:
    hindo_max.append(hindo_ck[i][0])
    i += 1
  hindo_max.sort()
  
  for h in hindo_max:
    print(h)
  
else:
  hindo_max = hindo_ck[0][0]
  print(hindo_max)
#print(result)



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

cnt = [10000] * 26

for i in range(n):
    s = input()
    tmp = [0] * 26
    for c in s:
        tmp[ord(c) - ord('a')] += 1
    for j in range(26):
        cnt[j] = min(cnt[j], tmp[j])

a = ''
for i in range(26):
    if cnt[i]:
        a = a + chr(ord('a') + i) * cnt[i]
print(a)


Measured memory_bytes: 3060
a = int(input())

i = 1
b = 0

for i in range(1,10):
  if (a % i ==0):
    if(a / i < 10):
      b = b+ 1
      break
    else:
      pass
  else:
    pass
  
if (b == 1):
  print("Yes")
else:
  print("No")

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

using namespace std;
using ll = long long;

ll memo[2][200001];

int main() {
  ll N;
  string S;
  cin >> N >> S;
  int black=-1;
  int white=-1;
  for (int i = 0; i < N; ++i) {
    if(black==-1 && i!=0 && S[i]=='.' && S[i-1]=='#')
      black=i-1;
    if(i!=0 && S[i]=='.' && S[i-1]=='#')
      white=i;
    memo[0][i]=-1;
    memo[1][i]=-1;
  }
  if(white==-1){
    cout << 0 << endl;
    return 0;
  }
  ll ret1 = 0, ret2=0;
  for (int j = 0; j < N; ++j) {
    if(j<white && S[j]=='#') {
      ret1++;
    }
    memo[0][j]=ret1;
  }
  for (int j = N-1; j >=0; --j) {
    if(j>black && S[j]=='.') {
      ret2++;
    }
    memo[1][j]=ret2;
  }
  ll m = min(ret1,ret2);
  for (int k = 0; k < N; ++k) {
    if(S[k]=='.') {
      if (memo[0][k] != -1 && memo[1][k+1] != -1) {
        m = min(m, memo[0][k] + memo[1][k + 1]);
      }
    }else{
      if (k!=0 && memo[0][k-1] != -1 && memo[1][k] != -1) {
        m = min(m, memo[0][k-1] + memo[1][k]);
      }
    }
  }
  cout << m << endl;
}


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

int main() {

    ld r;
    cin >> r;
    std::cout << std::fixed;
    std::cout << std::setprecision(8) << (2 * M_PI * r) << endl;

    return 0;

}


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

using namespace std;

typedef long long ll;

ll expfactor (ll prim, ll fact) {
    ll res = 0, i = prim;
    while (fact/i) {
        res += fact/i;
        i *= prim;
    }
    return res;
}

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, fact_two, fact_five;
    cin >> n;
    if (n%2) {
        fact_two = expfactor(2,n) - ((n-1)/2 + expfactor(2,(n-1)/2));
        fact_five = expfactor(5,n) - expfactor(5,(n-1)/2);
    } else {
        fact_two = expfactor(2,n/2) + (n/2);
        fact_five = expfactor(5,n/2);
    }
    cout << min(fact_two,fact_five);
    
    return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_o
//O - Matching
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
constexpr ll MOD=1e9+7;
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif   
    ll N; cin>>N;
    vector<vector<ll>> ann(N, vector<ll>(N));
    for(auto&& an:ann){
        for(auto&& a:an){
            cin>>a;
        }
    }

    ll mask_max=1<<N;
    vector<ll> dp(mask_max,0);
    dp[0]=1;
    FOR(i,1,mask_max){
        ll man_no = __builtin_popcountll(i)-1;
        FOR(w,0,N){
            ll w_mask = 1<<w;
            if (w_mask & i){
                ll m_mask = (~w_mask) & i;
                dp.at(i) += dp.at(m_mask) * ann[man_no][w];
                dp[i] %= MOD;
            }
        }
    }
    cout<<dp[mask_max-1]<<endl;
    return 0;
}

Measured memory_bytes: 16640
<?php
  fscanf(STDIN, "%s", $s);
  $chars = str_split($s);
  sort($chars);
  if ($chars[0] == $chars[1] && $chars[1] != $chars[2] && $chars[2] == $chars[3]) {
    echo "Yes\n";
  } else {
    echo "No\n";
  }
?>

Measured memory_bytes: 4604
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std ;
int a[100001];

int main() {
	int n ; cin >> n ;
	int s[10001];
	for(int i = 1 ; i <= n ;i++ ) {
		cin >> s[i];
	}
//	sort(s+1,s+n+1);

	int min1 = 9999999;
	//cout << [1] <<" " << a[n] << endl;
	for(int i = -100; i <= 100 ; i++) {
		int sum = 0 ;
		for(int j = 1 ; j <= n ; j++) {
			sum+=(i-s[j])*(i-s[j]) ;
		}
		if(min1 > sum){
			min1 = sum ;
		}
	}
	cout << min1 ;
}

Measured memory_bytes: 256
#include<iostream>
int main(){
    int a,b;
    std::cin>>a>>b;
    if(a>b){
        std::cout<<"a > b"<<std::endl;
    }
    if(a<b){
        std::cout<<"a < b"<<std::endl;
    }
    if(a==b){
        std::cout<<"a == b"<<std::endl;
    }
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
using namespace std;

const int maxn = 1e5 + 5;
int n, a[maxn];
int cnt2, cnt4;

int main(){
  scanf("%d", &n);
  rep(i, 1, n){
	scanf("%d", &a[i]);
	if(a[i] % 4 == 0) cnt4 ++;
	else if(a[i] % 2 == 0) cnt2 ++;
  }
  if(cnt2 == 0){
	if(cnt4 * 2 + 1 >= n) puts("Yes");
	else puts("No");
  }
  else{
	if(cnt4 * 2 + cnt2 >= n) puts("Yes");
	else puts("No");
  }
  return 0;
}


Measured memory_bytes: 640
n=int(input())
s=list(input())
ans = 'Yes'
if(n % 2 == 0):
    N = int(n / 2)
    for i in range(N):
        if(s[i] != s[i + N]):
            ans = 'No'
else:
    ans = 'No'

print(ans)

Measured memory_bytes: 3060
n,m,x = map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int,input().split())))

ans = []
s = [0 for i in range(2 ** n)]
for i in range(2 ** n):
    tmp_0 = [0]
    tmp_1 = [0 for i in range(m)]
    for j in range(n):
        if ((i >> j) & 1):
            tmp_0[0] += a[j][0]
            for k in range(1,m+1):
                tmp_1[k-1] += a[j][k]
    #print(tmp_1)
    if min(tmp_1) >= x:
        ans.append(tmp_0[0])

if not ans:
    print(-1)
else:
    print(min(ans))
#print(ans)
#print(min(ans))


Measured memory_bytes: 74476
//専用ライブラリ
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e9
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define PI acos(-1.0)
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/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int cmp(P a,P b){
        if(a.fi!=b.fi)
        return a.fi>b.fi;
        else
        return a.se<b.se;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<P> a[100001];
    int color[100001];
    memset(color,0,sizeof(color));
    int cnt[100001];
   memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=n;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        a[u].push_back(make_pair(v,w));
        a[v].push_back(make_pair(u,w));
        //cnt[v]++;
    }
  /*  int startp;
    for(int i=1;i<=n;i++)
    {
        if(cnt[i]==0)
        {
            startp=i;
            break;
        }
    }*/
    int dp[100001];
    memset(dp,0,sizeof(dp));
    queue<int> point;
    point.push(1);
    cnt[1]=1;
    color[1]=0;
    while(point.size())
    {
        int now=point.front();
        point.pop();
        if(a[now].size())
        {
            for(auto it=a[now].begin();it!=a[now].end();it++)
            {
                if(cnt[it->fi]==1)
                    continue;
                else
                    cnt[it->fi]=1;
                dp[it->fi]=dp[now]+it->se;
                if(dp[it->fi]%2==0)
                    color[it->fi]=0;
                else
                    color[it->fi]=1;
                point.push(it->fi);
            }
        }
    }
    for(int i=1;i<=n;i++)
        cout<<color[i]<<endl;
    return 0;
}


Measured memory_bytes: 9088
A, B, C, D, E, F = map(int, raw_input().split())

mx = 0
mx_x = 100*A
mx_y = 0
for i in xrange(31):
    for j in xrange(16):
        for k in xrange(101):
            for l in xrange(51):
                if 100*A*i + 100*B*j + C*k + D*l > F: continue
                if (A*i + B*j)*E < C*k + D*l: continue
                a = 100*A*i + 100*B*j
                b = C*k + D*l
                if a > 0 and 100.0*b/(a + b) > mx:
                    mx_x = a + b
                    mx_y = b
                    mx = 100.0*b/(a + b)
print mx_x, mx_y


Measured memory_bytes: 2692
#include <string>
#include <vector>
#include <map>
#include <iostream>
#define MAXN 111111
#define ll long long
using namespace std;

ll A[MAXN+1];
ll dp[MAXN+1][2];

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) {
        cin>>A[i];
    }
    
    for(int pos=N;pos>=1;pos--) {
        for(int is_swap=0;is_swap<=1;is_swap++) {
            if (pos >= N) {
                dp[pos][is_swap]=(is_swap ? -A[pos] : A[pos]);
            } else {
                dp[pos][is_swap] = max(dp[pos+1][0]+(is_swap ? -A[pos] : A[pos]),
                             dp[pos+1][1]+(is_swap ? A[pos] : -A[pos]));
            }
        }
    }
    
    cout << dp[1][0] << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
using namespace std;

class dice {
public:
	int a[6];
	int b;
	void moveN() {
		b = a[0];
		a[0] = a[1];
		a[1] = a[5];
		a[5] = a[4];
		a[4] = b;
	}

	void moveS() {
		b = a[0];
		a[0] = a[4];
		a[4] = a[5];
		a[5] = a[1];
		a[1] = b;
	}

	void moveE() {
		b = a[0];
		a[0] = a[3];
		a[3] = a[5];
		a[5] = a[2];
		a[2] = b;
	}

	void moveW() {
		b = a[0];
		a[0] = a[2];
		a[2] = a[5];
		a[5] = a[3];
		a[3] = b;
	}

	void moveR() {
		b = a[1];
		a[1] = a[2];
		a[2] = a[4];
		a[4] = a[3];
		a[3] = b;
	}

	void moveL() {
		b = a[1];
		a[1] = a[3];
		a[3] = a[4];
		a[4] = a[2];
		a[2] = b;
	}
};

int main() {
	dice dice1, dice2;
	int cnt = 0;

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

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

	for (int i = 0; i < 6; i++){
		if (dice1.a[i] == dice2.a[i]){
			cnt++;
		}
	}
	if (cnt == 6){
		cout << "Yes" << endl;
		return 0;
	}
	cnt = 0;

	for (int i = 0; i < 4; i++) {
		dice2.moveR();
		for (int j = 0; j < 4; j++) {
			dice2.moveN();
			for (int i = 0; i < 6; i++){
				if (dice1.a[i] == dice2.a[i]){
					cnt++;
				}
			}
			if (cnt == 6){
				cout << "Yes" << endl;
				return 0;
			}
			cnt = 0;
		}
	}

	for (int i = 0; i < 4; i++) {
		dice2.moveE();
		for (int j = 0; j < 4; j++) {
			dice2.moveN();
			for (int i = 0; i < 6; i++){
				if (dice1.a[i] == dice2.a[i]){
					cnt++;
				}
			}
			if (cnt == 6){
				cout << "Yes" << endl;
				return 0;
			}
			cnt = 0;
		}
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
bool is_prime(lli x) {
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main() {
  lli A,B,C=1,D=0,E=0,F=0,G=0,H=0,N,M;
  cin >> N;
  vector<lli>P(N);
  rep(i,0,N)cin >> P[i];
  for(lli i=N-1;i>0;i--)if(P[i]<P[i-1])P[i-1]--;
  rep(i,1,N)if(P[i]<P[i-1]){
    Out("No");
    C=0;
    break;
  }
  if(C)Out("Yes");
}


Measured memory_bytes: 1024
N = int(input())
F = []
for i in range(N):
  F.append(list(map(int, input().split())))
  
P = []
for i in range(N):
  P.append(list(map(int, input().split())))
  
ma = -10e10

for i in range(1, 1024):
  t = i
  x = []
  for j in range(10):
    x.append(t % 2)
    t //= 2
  wa = 0
  for j in range(N):
    cnt = 0
    for k in range(10):
      if x[k] == 1 and F[j][k] == 1:
        cnt += 1
    wa += P[j][cnt]
    
  if ma < wa:
    ma = wa
print(ma)
        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int q;
  cin >> q;
  set<int> num;
  for(int i = 2; i <= 100100; i++) {
    bool ok = true;
    for(int j = 2; j*j <=i; j++) {
      if(i%j==0) {
        ok = false;
        break;
      }
    }
    if(ok) num.insert(i);
  }
  int a[100100];
  a[0] = 0;
  a[1] = 0;
  for(int i = 2; i <= 100100; i++) {
    a[i] = a[i-1];
    if(num.count(i)&&num.count((i+1)/2)) a[i]++;
  }
  vector<int> l(q), r(q);
  rep(i,q) cin >> l[i] >> r[i];
  rep(i,q) cout << a[r[i]] - a[l[i]-1] << endl;
  return 0;
}

Measured memory_bytes: 4756
module IntSet = Set.Make (struct type t = int let compare = compare end)

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.fold_left (fun (s, n) a ->
    if a < 3200 then (IntSet.add (a / 400) s, n)
    else (s, n + 1)) (IntSet.empty, 0) as_
  |> (fun (s, n) -> (max 1 (IntSet.cardinal s), IntSet.cardinal s + n))
  |> (fun (max, min) -> Printf.printf "%d %d\n" max min)

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <stdio.h>
using namespace std;

int main() {
	char C;
	scanf("%c", &C);
	(int)C++;
	printf("%c", C);
	
	return 0;
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int X,A; cin >> X >> A;
    if(X < A) cout << 0 << endl;
    else cout << 10 << endl;
}

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

#define int ll

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int MOD = 998244353;

int add(int x, int y) {
	x += y;
	if(x >= MOD)
		x -= MOD;
	return x;
}

int mult(int x, int y) {
	return (x * y) % MOD;
}


ll binpow(ll base, ll e, ll mod = MOD) {
	ll ret = 1;
	while(e) {
		if(e & 1)
			ret  = ret * base % mod;
		base = base * base % mod;
		e >>= 1;
	}		
	return ret;
}

int32_t main() {
	int n;
	cin >> n;
	vi h(n), d(n);
	string s[n];
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		int sum = 0;
		for(char c : s[i]) {
			if(c == '(')
				sum++;
			else
				sum--;
			d[i] = min(d[i], sum);
		}
		//debug(sum);
		d[i] = -d[i];
		h[i] = sum + d[i];
		//debug(h[i], d[i]);
	}
	vi v(n);
	iota(all(v), 0);
	sort(all(v), [&](int i, int j) {
		if(h[i] - d[i] >= 0 && h[j] - d[j] < 0)
			return true;
		if(h[i] - d[i] < 0 && h[j] - d[j] >= 0)
			return false;
		if(h[i] - d[i] >= 0 && h[j] - d[j] >= 0)
			return d[i] < d[j];
		if(h[i] - d[i] < 0 && h[j] - d[j] < 0)
			return h[i] > h[j];
	});
	int cur = 0;
	for(int pos : v) {
		cur -= d[pos];
		if(cur < 0) {
			cout << "No\n";
			return 0;
		}
		cur += h[pos];
	}
	if(cur == 0) {
		cout << "Yes\n";
	}
	else
		cout << "No\n";
}


Measured memory_bytes: 57820
var ans,s,ss,t:string;
    lent,lens:longint;
    i,j:longint;
    x:boolean;
    max:longint;
begin
  readln(s);
  readln(t);
  lens:=length(s);
  lent:=length(t);
  for i:=1 to lens do
  ans:=ans+'z';
  for i:=1 to lens-lent+1 do
  begin
    x:=true;
    for j:=1 to lent do
    if (s[i+j-1]<>t[j])and(s[i+j-1]<>'?') then
    begin
      x:=false;
      break;
    end;
    if x then
    begin
      ss:='';
      for j:=1 to i-1 do
      if s[j]='?' then ss:=ss+'a' else ss:=ss+s[j];
      ss:=ss+t;
      for j:=i+lent to lens do
      if s[j]='?' then ss:=ss+'a' else ss:=ss+s[j];
      if ss<ans then ans:=ss;
      max:=1;
    end;
  end;
  if max=0 then
  begin
    writeln('UNRESTORABLE');
    exit;
  end;
  writeln(ans);
end.

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N, M;
  cin >> N >> M;
  vi32 imos(N + 1);
  rep(i, M) {
    int l, r;
    cin >> l >> r;
    l--;
    imos[l]++;
    imos[r]--;
  }
  rep(i, N) imos[i + 1] += imos[i];
  int ans = 0;
  rep(i, N) if (imos[i] == M) ans++;
  cout << ans << '\n';
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long K = sc.nextLong();

		int Onecnt = 0;
		int Slen = S.length();
		for(int i = 0; i < Slen; i++) {
		String Onehantei = S.substring(i, i+1);
		if(Onehantei.equals("1")) {
			Onecnt ++;
		}else {
			break;
		}
		}
		String ans = "1";
		if(Onecnt < K) {
			ans = S.substring(Onecnt,Onecnt+1);
		}

		System.out.println(ans);
		sc.close();

	}

}


Measured memory_bytes: 21844
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main(){
    long long N;
    cin >> N;
    long long num=0;
    long long num_max=0;
    long long tmp=N;
    long long num_nine=0,num_six=0;
    long long cost=0;
    for(int i=0;i<=N;++i){
        int res=i;
        num=0;
        while(res>0) num+=res%6,res=res/6;
        res=N-i;
        while(res>0) num+=res%9,res=res/9;
        if(tmp>num) tmp=num;
    }
    cout << tmp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;


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


  int a, b;
  cin >> a >> b;

  pr((a <= 8 && b <= 8 ? "Yay!" : ":("));

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define M 1000000007
 
#define mp make_pair
#define pb push_back
#define tri pair<int, pair<int, int> >
#define TRI(a,b,c) (make_pair(a,make_pair(b,c)))
 
typedef long long ll;
typedef long double ld;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a, b, c, x, y; cin>>a>>b>>c>>x>>y;
    ll tot=0;
    ll mn = min(x, y);
    tot+=min(2*c, a+b)*mn;
    x-=mn, y-=mn;
    tot+=x*min(2*c, a)+y*min(2*c, b);
    cout<<tot<<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;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int N, K; cin >> N >> K;
    vector<int> h(N);
    rep(i, N){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    
    int ans = 1001001001;
    for (int i = 0; K-1+i < N; i++){
        int x = h[K-1+i] - h[i];
        ans = min(ans, x);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3780
#include <stdio.h>

int main(void)
{
	int a[10];
	int sum;
	int v[2];
	int i, j;
	float time;
	
	while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", a, a+1, a+2, a+3, a+4, a+5, a+6, a+7, a+8, a+9, v, v+1) != EOF){
		sum = 0;
		for (i = 0; i < 10; i++){
			sum += a[i];
		}
		
		time = 0;
		for (i = 0; i < 10; i++){
			sum -= a[i];
			time += (float)a[i] / v[0];
			if (v[1] * time >= sum){
				printf("%d\n", i + 1);
				break;
			}
		}
	}
	
	return (0);
}

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

int main() {
  set<string> S;
  int N;
  int i;
  string s;
  
  cin >> N;
  for(i = 0; i < N; ++i){
    cin >> s;
    S.insert(s);
  }
  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 19228
import sys
import math
a,b,x = list(map(int, input().split()))

if a*a*b/2 < x:
    print(180*math.atan(2*b/a-2*x/a/a/a)/math.pi)
else:
    print(math.atan(a*b*b/2/x)*180/math.pi)

Measured memory_bytes: 38256
# coding: utf-8
# Your code here!

N = int(input())
lst = list(map(int,input().split()))
lst.sort(reverse = True)
count = 0
longest = 0
for n,i in enumerate(lst):
    if n == 0:
        longest = i
    else:
        count += i

if longest < count:
    print("Yes")
else:
    print("No")
#print(longest,count)

Measured memory_bytes: 3060