akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input()
s += s[0]+s[1]
case = ["SS","SW","WS","WW"]
for x in case:
    animal = x
    for i in range(1,n+1):
        if (s[i] == "o" and animal[i] == "S") or (s[i] == "x" and animal[i] == "W"):
            if animal[i-1] == "S": 
                animal += "S"
            else: 
                animal += "W"
        elif animal[i-1] == "S": 
                animal += "W"
        else: 
            animal += "S"
    if animal[-2:] == x:
        print(animal[:n])
        exit()
print(-1)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(11);
    string S;
    cin >> S;
    vector<char> s(S.size());
    for(int i = 0; i < S.size(); i++){
        s[i] = S[i];
    }

    ll ans = 0;
    int flag = 1;
    while(flag){ 
        flag = 0;
        if(s.size() <= 2){
            if(s.size() == 2 && s[0] != s[1]) ans += 2;
            break;
        } 
        for(int i = 0; i < s.size()-1; i++){
            if(s[i] != s[i+1]){
                ans += 2;
                flag = 1;
                if(i < s.size()-2) s.erase(s.begin()+i, s.begin()+i+2);
                else s.erase(s.end()-2, s.end());
                break;
            }
        }
        
    }

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


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
  int N;
  long int C, K;
  long int T[100000];

  int i;
  int bus=0;
  int fp=0, lp=0;
    
  cin >> N >> C >> K;
  
  for(i=0; i<N; i++){
    cin >> T[i];
  }

  sort(T,T+N);

  while(fp<N){
    for(i=0;i<C&& fp+i<N;i++){
      if(T[fp]+K < T[fp+i])	
	break;
    }
    //    printf("[%d,%d]=%d\n",fp,fp+i-1,i);
    lp = fp+i-1; fp = lp+1; bus++;
  }
  
  cout << bus;
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

int main(){
    fastio;
    int n;
    cin >> n;
    while(n > 0){
        if(n % 10 == 7){
            cout << "Yes\n";
            return 0;
        }
        n /= 10;
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N;
	cin >> N;
	vector<lint>L(N);
	rep(i, N) {
		cin >> L[i];
	}
	sort(L);
	lint cnt = 0;
	rep(i, N) {
		rep(j, N) {
			rep(k, N) {
				if (i < j && j < k) {
					if (L[i] != L[j] && L[j] != L[k]) {
						if (L[i] + L[j] > L[k]) {
							cnt++;
						}
					}
				}
			}
		}
	}
	cout << cnt << endl;
}

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

#define int long long
#define mp make_pair
#define fi first
#define se second

typedef pair<int,int> ii;
typedef pair<int,ii> edge;
typedef pair<ii,int> data;
const int N = 1e5 + 5;
int n;
data a[N];
priority_queue<edge, vector<edge>, greater<edge> > pq;
int par[N];
int anc(int u) { return u == par[u] ? u : par[u] = anc(par[u]); }
void join(int u,int v) { par[anc(v)] = anc(u); }
signed main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1;i <= n;++i) {
		cin >> a[i].fi.fi >> a[i].fi.se;
		a[i].se = i;
		par[i] = i;
	}
	sort(a + 1, a + 1 + n);
	for (int i = 2;i <= n;++i) pq.push(edge(min(abs(a[i].fi.fi - a[i - 1].fi.fi), abs(a[i].fi.se - a[i - 1].fi.se)), ii(a[i].se, a[i - 1].se)));
	for (int i = 1;i <= n;++i) swap(a[i].fi.se, a[i].fi.fi);
	sort(a + 1, a + 1 + n);
	for (int i = 2;i <= n;++i) pq.push(edge(min(abs(a[i].fi.fi - a[i - 1].fi.fi), abs(a[i].fi.se - a[i - 1].fi.se)), ii(a[i].se, a[i - 1].se)));
	int need = n - 1;
	int res = 0;
	while (need) {
		edge cur = pq.top(); pq.pop();
		if (anc(cur.se.fi) == anc(cur.se.se)) continue;
		join(cur.se.fi, cur.se.se) ; res += cur.fi;need--;
	}
	cout << res;
}

Measured memory_bytes: 11504
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a>b)
  {
    cout<<a+(a-1)<<endl;
  }
  else
    if(a==b)
    {
      cout<<2*a<<endl;
    }
  else
    cout<<2*b-1<<endl;
}

Measured memory_bytes: 256
import sys

a, b, n = map(int, input().split())

def f(x):
	return a*x // b - a*(x // b)

#for x in range(1, 100):
	#print(x, f(x))

if b - 1 <= n: 
	print(f(b - 1))
else:
	print(f(n))

Measured memory_bytes: 61856
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    string S,T;cin>>S>>T;
    vector<set<int>> pls;
    pls.assign(26,set<int>({INF}));
    REP(i,S.size()){
        pls[S[i]-'a'].insert(i);
    }
    bool ok=true;
    REP(i,T.size()){
        if(*pls[T[i]-'a'].lower_bound(0)==INF){
            ok=false;
            break;
        }
    }
    int before=-1;
  	int count=0;
    if(ok){
        REP(i,T.size()){
            int d=*pls[T[i]-'a'].upper_bound(before);
      	    if(d!=INF)before=d;
      	    else{
                count++;
                before=-1;
                i--;
            }
        }
    }
  	if(ok)cout<<1+before+count*S.size()<<endl;
  	else cout<<-1<<endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")
 
bool isprime(int p) {
  if (p==1) return false;
    FOR(i,2,p) {
      if (p%i==0) return false;
    }
  return true;
}
 
int main(){
  int n,c;
  cin >> n;
  REP(i,10000){
    if (isprime(i*5+1)) {
      cout << i*5+1 << ' ';
      c++;
    }
    if (c==n) return 0;
  }
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}
	ys := make([]int, n)
	copy(ys, xs)
	sort.Ints(ys)
	ml, mr := ys[n/2-1], ys[n/2]
	for _, x := range xs {
		if x <= ml {
			fmt.Println(mr)
		} else {
			fmt.Println(ml)
		}
	}
}


Measured memory_bytes: 8896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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; }


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

    ll ans=0ll;
    for (ll i = 0; i < 61; ++i) {
        ll zero=0,one=0;
        for (ll j = 0; j < N; ++j) {
            if((A[j]>>i)&1) one++;
            else ++zero;
        }

        ll base=(1ll<<i)%MOD;
        //cout<<i<<" "<<base<<endl;

        ll patern=(zero*one)%MOD;

        ans+=((base*patern)%MOD);
        ans%=MOD;

        //cout<<i<<" "<<zero<<" "<<one<<" : "<<ans<<endl;

    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n,m; cin>>n>>m;
  int t=100*(n-m)+1900*m;
  rep(i,m) t*=2;
  cout<<t<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,m;
    while(1){
        cin>>n>>m;
        if(n+m==0)break;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int ans=-1;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(m>=a[i]+a[j])ans=max(ans,a[i]+a[j]);
            }
        }
        if(ans==-1)cout<<"NONE"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;






int main(){
    int n,m;cin >> n >> m;
    priority_queue<LL> pq;
    for (int i = 0; i < n; i++) {
        LL a;cin >> a;
        pq.push(a);
    }
    for (int i = 0; i < m; i++) {
        LL k = pq.top();pq.pop();
        pq.push(k/2);
    }
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


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

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

	int a, n;
	cin >> a >> n;
	
	vector<int> v(101);
	for(int i =1 ; i <= n ; i++){
		int t; cin >> t;
		v[t] = 1;
	}    	
	
	int l = a;
	int r = a;
	while(true){
		if(!v[l]) {
			cout<<l;return 0;
		}
		if(!v[r]) {
			cout << r; return 0;
		}
		l--;
		r++;
			
	}

  return 0;
}


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

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

using namespace std;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int ans = 0;
    REP(i, A + 1) REP(j, B + 1) REP(k, C + 1)
        if (500 * i + 100 * j + 50 * k == X)
            ans++;
    cout << ans << endl;

    return 0;
}

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

int main(){
    int n,m;
    while(cin>>n>>m,n|m){
        using P = pair<ll,ll>;
        vector<P> ps(n);
        rep(i,n){
            ll d,p;
            cin>>d>>p;
            ps[i] = {p,d};
        }
        sort(all(ps), greater<P>());
        ll res = 0;
        rep(i,n){
            ll d = ps[i].second;
            ll p = ps[i].first;
            if(m>=d){
                m-=d;
            }else{
                res += (d-m)*p;
                m = 0;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
// #define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
const int mod = 1'000'000'007;
const int N = 3e5, M = N;

void solve()
{
    ll i, j, n, m;
    cin >> n;
    ll dp[n];
    ll a[n];
    ll cost1 = 0, cost2 = 0;
    fo(i, n)
    {
        cin >> a[i];
    }

    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);

    for (i = 2; i < n; i++)
    {
        cost1 = dp[i - 1] + abs(a[i] - a[i - 1]);
        cost2 = dp[i - 2] + abs(a[i] - a[i - 2]);
        dp[i] = min(cost1, cost2);
    }

    cout << dp[n - 1];
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 5208
#include <stdio.h>

int main(){
    char number[1001];
    int i, sum;
    while(1){
        scanf("%s", number);
        if(number[0]=='0')break;
        sum=0;
        for(i=0;number[i]!='\0';i++){
            sum+=number[i]-'0';
        }
        printf("%d\n", sum);
    }

    return 0;
}


Measured memory_bytes: 2048
n = int(input())
if n == 0:
    print('0')
    exit()

def base_minus_two(n):
    if n == 0:
        return ''
    d = n % 2
    return base_minus_two((n-d)//2 * -1) + str(d)
print(base_minus_two(n))
# 1,
# -2, -1
# 4, 5, 2, 3
# -8, -7, -10, -9, -4, -3, -6, -5,
# 16, 17, 14, 15, 20, 21, 18, 19, 8, 9, 6, 7, 12, 13, 10, 11


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	char c;
	cin >> c;
	cout << char(c + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main (){
    int a,b;
    cin >> a >> b;
    if (a > 9 || b > 9){
        cout << "-1" << endl;
    }else cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int a,b;
    cin >> a >> b;
    //処理
    //出力
    cout << a-b+1 << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  int i;
  int numbers[n+1] = {};
  for(i=0;i<n;i++){
    cin >> a[i];
    numbers[a[i]]++;
  }
  int ans = 0;
  sort(numbers,numbers+n+1);
  int cnt = 0;
  for(i=0;i<=n;i++){
    if(numbers[i]>0)cnt++;
  }
  
  for(i=0;i<=n;i++){
    if(cnt<=k)break;
    if(numbers[i]>0){
      ans += numbers[i];
      cnt-=1;
    }
    
  }
  cout << ans;
}

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

step = 0
for i in range(1, len(A)):
    if A[i-1] <= A[i]:
        continue
    else:
        step += (A[i-1] - A[i])
        A[i] += (A[i-1] - A[i])

print(step)

Measured memory_bytes: 32244
#include <stdio.h>

int main(void)
{
	int r,b,w,g,a;
	scanf("%d %d %d %d",&r,&b,&w,&g);
	if((1<=r && r<=100) || (1<=b && b<=100) || (1<=w && w<=100) || (1<=g && g<=100)){
		a=r+b+w+g;
		printf("%d\n",a);
	}
	else{
		printf("error\n");
	}
	return 0;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var K = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());
            var Y = int.Parse(Console.ReadLine());

            var price = Math.Min(N, K) * X;

            if (N > K)
                price += (N - K) * Y;

            Console.WriteLine(price);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int n, C;
long long w[101];
int v[101];

long long dp[101][1000001];

long long solve(int i, int value){
	if(value <= 0) return 0;
	if(i == n) return 1000000000;
	if(dp[i][value] != -1) return dp[i][value];
	
	dp[i][value] = solve(i+1, value);
	dp[i][value] = min(dp[i][value], solve(i+1, value-v[i]) + w[i]);	
	return dp[i][value];
}

int main(){
	cin>>n>>C;
	long long v_sum = 0;
	for (int i = 0; i < n; ++i){
		cin>>w[i]>>v[i];
		v_sum += v[i];
	}

	memset(dp, -1, sizeof dp);
	for(int i = v_sum; i>=0; i--){
		if(solve(0, i) <= C){
			cout<<i<<endl;
			return 0;	
		}
	}
}

Measured memory_bytes: 789376
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n;
		double dis = 0.0;
		double total = 0.0;
		double vector_total = 0.0;
		double max = 0.0;
		
		n = scan.nextInt();
		int vectorX[] = new int[n];
		int vectorY[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			vectorX[i] = scan.nextInt();
		}
		
		for (int i = 0; i < n; i++) {
			vectorY[i] = scan.nextInt();
		}
		
		for (int p = 1; p <= 4; p++) {
			total = 0.0;
			
			switch (p) {
			case 1:
				for (int i = 0; i < n; i++) {
					vector_total = (vectorX[i] - vectorY[i]);
					if (vector_total < 0) {
						vector_total *= -1;
					}
					total += vector_total;
				}
				dis = total;
				break;
			case 2:
				for (int i = 0; i < n; i++) {
					total += Math.pow((vectorX[i] - vectorY[i]), p);
				}
				dis = Math.sqrt(total);
				break;
			case 3:
				for (int i = 0; i < n; i++) {
					vector_total = Math.pow((vectorX[i] - vectorY[i]), p);
					if (vector_total < 0) {
						vector_total *= -1;
					}
					total += vector_total;
				}
				dis = Math.cbrt(total);
				break;
			case 4:
				for (int i = 0; i < n; i++) {
					vector_total = (vectorX[i] - vectorY[i]);
					if (vector_total < 0) {
						vector_total *= -1;
					}
					if ( i == 0) {
						max = vector_total;
					} else {
						max = Math.max(max, vector_total);
					}
				}
				dis = max;
				
				break;
			default:
				break;
			}
			
			System.out.println(dis);
			
		}
		
		
		
		scan.close();
	}
}



Measured memory_bytes: 26568
def ok(S, K):
    s = ''
    for i in range(len(S)):
        if i < K and i >= len(S) - K:
            s += S[i]

    if s == '':
        return True
    return all([c == s[0] for c in s])


S = input()
lb = 1
ub = len(S) + 1
while ub - lb > 1:
    mid = (ub + lb) // 2
    if ok(S, mid):
        lb = mid
    else:
        ub = mid

print(lb)


Measured memory_bytes: 4364
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n,a,b,x,e=0,m=0,h=0;cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x<=a)e++;
        else if(x<=b)m++;
        else h++;
    }
    int ans;
    ans=min(e,m);
    ans=min(ans,h);
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
s = [[] for _ in range(3)]
s[0]=list(input())
s[1]=list(input())
s[2]=list(input())
name = 'ABC'
i = 0
while True:
  if len(s[i]) == 0:
    print(name[i])
    break
  c = s[i].pop(0)  
  if c == 'a':
    i = 0
  elif c == 'b':
    i = 1
  else:
    i = 2

  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N, X;
    cin >> N >> X;
    int L[N];
    cins(L, L + N);
    int D = 0, ans = 1;
    for(int i = 0; i < N; i++){
        D += L[i];
        ans += (D <= X);
    }
    cout << ans << endl;
}


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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

vector<char> boin = {'a','i','u','e','o'};
vector<char> alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

ll T1,T2,A1,A2,B1,B2;

int main(){
    cin >> T1 >> T2;
    cin >> A1 >> A2;
    cin >> B1 >> B2;
    if(A1 < B1){
        ll temp = B1;
        B1 = A1;
        A1 = temp;
        temp = B2;
        B2 = A2;
        A2 = temp;
    }
    ll SA = T1*A1+T2*A2;
    ll SB = T1*B1+T2*B2;
    ll MA = T1*A1;
    ll MB = T1*B1;
    if(SA == SB){
        cout << "infinity" << endl;
    }else if(SA > SB){
        cout << 0 << endl;
    }else{
        ll ans = 0;
        if((MA-MB) % (SB-SA) == 0)ans++;
        ans += (((MA-MB)+(SB-SA)-1)/(SB-SA))*2-1;
        cout << ans << endl;
    }
    //cin >> T1;
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

namespace roll {
	using H = unsigned long long;
	//0123456789
	constexpr H p[] = { 1000000009,
		1000000007,
		90001 };
	constexpr int MX = 1123456;
	H hs[3][MX];
	H rh[3][MX];
	template<int m = 1>
	void build(const char* s,const int n) {
		for (int i = 0; i < m; i++) {
			hs[i][0] = 0;
			rh[i][0] = 1;
		}
		for (int i = 0; i < m; i++)for (int j = 0; j < n; j++) {
			hs[i][j + 1] = hs[i][j] * p[i] + s[j];
			rh[i][j + 1] = rh[i][j] * p[i];
		}
	}
	template<int m = 1>
	H get(const int l, const int r) {
		H ret = 0;
		for (int i = 0; i < m; i++) {
			ret ^= hs[i][r] - hs[i][l] * rh[i][r - l];
		}
		return ret;
	}
}
int N;
inline roll::H yoko(int r,int c) {
	int base = r * 2 * N + c;
	return roll::get(base, base + N);
}
inline roll::H tate(int r, int c) {
	int base = 2 * N*N + c * 2 * N + r;
	return roll::get(base, base + N);
}

char t[612 * 612 * 2];

int main() {
	cin >> N;
	vector<string> s(N);
	cin >> s;
	int n = 0;
	for (int i : range(N)) {
		for (int j : range(N)) {
			t[n++] = s[i][j];
		}
		for (int j : range(N)) {
			t[n++] = s[i][j];
		}
	}
	for (int j : range(N)) {
		for (int i : range(N)) {
			t[n++] = s[i][j];
		}
		for (int i : range(N)) {
			t[n++] = s[i][j];
		}
	}
	int ret = 0;
	roll::build(t, n);
	for (int A : range(N)) {
		for (int B : range(N)) {
			ret += [&]() {
				for (int i : range(N)) {
					if (yoko((i + A) % N, B) != tate(A, (i + B) % N))
						return 0;
				}
				return 1;
			}();
		}
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(ll i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC";
    else cout << "ABC";
}

Measured memory_bytes: 3628
x, y, a, b, c = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

pqr = []
for i in p:
  pqr.append([i, 1])
for i in q:
  pqr.append([i, 2])
for i in r:
  pqr.append([i, 3])

pqr.sort(reverse=True)

red = x
green = y
total = x+y
ans = 0

for i_pqr in pqr:
  if i_pqr[1] == 1 and red > 0 and total > 0:
    red -= 1
    total -= 1
    ans += i_pqr[0]
  elif i_pqr[1] == 2 and green > 0 and total > 0:
    green -= 1
    total -= 1
    ans += i_pqr[0]
  elif i_pqr[1] == 3 and total > 0:
    total -= 1
    ans += i_pqr[0]
  
  if total == 0:
    break

print(ans)

Measured memory_bytes: 128720
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 1000006;
//////////////////////////////

struct Block {
	Int w, s, v;
	bool operator < (const Block &a)const {
		return w + s < a.w + a.s;
	}
} Blocks[1003];

int n;
Int dp[1003][22000];

int main() { 
	ios_base::sync_with_stdio(0); cin.tie(0);//fflush(stdout);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> Blocks[i].w >> Blocks[i].s >> Blocks[i].v;
	}

	sort(Blocks, Blocks + n + 1);
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 22000; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - Blocks[i].w >= 0 && j - Blocks[i].w <= Blocks[i].s) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - Blocks[i].w] + Blocks[i].v);
			}
		}
	}
	
	Int ans = 0;
	for (int j = 0; j < 22000; j++) {
		ans = max(ans, dp[n][j]);
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 172160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll h,w;cin>>h>>w;
    ll sy,sx;cin>>sy>>sx;sy--;sx--;
    ll gy,gx;cin>>gy>>gx;gy--;gx--;
    char s[h][w];
    rep(i,h)rep(j,w)cin>>s[i][j];
    vector<vector<ll>> t(h,vector<ll>(w,-1)),d(2000000);
    
    ll tmp=0;
    int rotx[4]={0,1,0,-1},roty[4]={1,0,-1,0};
    rep(i,h)rep(j,w){
        if(t[i][j]!=-1)continue;
        if(s[i][j]=='#')continue;
        t[i][j]=tmp;tmp++;
        queue<pair<ll,ll>> que;
        que.push({i,j});
        map<ll,ll> mp;mp[tmp-1]++;
        while(que.size()){
            auto p=que.front();que.pop();
            ll y=p.first,x=p.second;
            for(int l=-2;l<=2;l++){
                for(int r=-2;r<=2;r++){
                    ll ny=y+l,nx=x+r;
                    if(ny<0||ny>=h||nx<0||nx>=w)continue;
                    if(t[ny][nx]!=-1){
                        if(mp[t[ny][nx]]==0){
                            mp[t[ny][nx]]++;
                            d[t[i][j]].push_back(t[ny][nx]);
                            d[t[ny][nx]].push_back(t[i][j]);
                        }
                    }
                }
            }
            rep(k,4){
                ll ny=y+roty[k],nx=x+rotx[k];
                if(0>ny||ny>=h||0>nx||nx>=w)continue;
                if(s[ny][nx]=='#')continue;
                if(t[ny][nx]!=-1)continue;
                t[ny][nx]=tmp-1;
                que.push({ny,nx});
            }
        }
    }
    ll f=t[sy][sx];
    ll g=t[gy][gx];
    vector<ll> q(tmp,1e9);
    q[f]=0;
    queue<ll> que;
    que.push(f);
    while(que.size()){
        ll from=que.front();que.pop();
        rep(i,d[from].size()){
            ll to=d[from][i];
            if(chmin(q[to],q[from]+1)){
                q[to]=q[from]+1;
                que.push(to);
            }
        }
    }
    if(q[g]==1e9){
        cout<<-1<<endl;
        return 0;
    }
    cout<<q[g]<<endl;
}

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

int main(){
  int R,G,B,N; 
  cin >> R >> G >> B >> N;
  int ans = 0;
  for(int r = 0; r <= N; r++){
    for(int g = 0; g <= N-r*R; g++){
      int b = r*R + g*G;
      if( b <= N && (N-b)%B == 0) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll N,K; cin >> N >> K;

    ll ans = 0;
    for(ll a=1;a<=N;a++){
        ll ma = a % K;
        ll mb = K - ma;
        ll mc = K - ma;

        if((mb + mc) % K) continue;

        ll m = mb;
        ll x = (N - m) / K + 1;

        //cout << "------" << endl;
        //cout << a << " " << x << endl;
        //cout << mb << " " <<mc << endl;
        assert(x >= 0);
        ans += x * x;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ans = 0;
    rep(i, 3) ans += S[i] - '0';
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
	int main()
{
	int i, j, H, W;
	scanf("%d %d", &H, &W);
	while(H != 0 && W != 0){
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &H, &W);
	}
	return 0;
}

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

using namespace std;
//fold
#define ll long long
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define Loop(i, a, b) for(int i = a ; i < b ; ++i)
#define loop(i, n) Loop(i, 0, n)
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define vvll vector<vll>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c-'0')
#define ltr(c) (int)(c-'a')
#define INF 1e18+5
#define inf 1e9+5
#define M 1000000007 //check
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

template <typename T> T max(T a, T b, T c){ return max(a, max(b, c));}
template <typename T> T min(T a, T b, T c){ return min(a, min(b, c));}
//endfold
const int maxn = 1e3+5;
int n, m, a[maxn];
ll dp[maxn][1<<15];
vvi b(maxn);

ll solve(int index, int mask)
{
	if(mask == (1 << n)-1) return 0;
	if(index == m) return inf;
	ll &ans = dp[index][mask];
	if(ans != -1) return ans;
	int new_mask = mask;
	for(auto it : b[index]) new_mask |= (1 << it);
	ans = min(solve(index+1, mask), 1LL*a[index] + solve(index+1, new_mask));
	return ans;
}
int main() {
	_69e27;
	memset(dp, -1, sizeof(dp));
	scanf("%d %d", &n, &m);
	loop(i, m)
	{
		int temp;
		scanf("%d %d", &a[i], &temp);
		loop(j, temp)
		{
			int in;
			scanf("%d", &in);
			in--;
			b[i].pb(in);
		}
	}
	ll ans = solve(0, 0);
	if(ans < inf) printf("%lld\n", ans);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 257664
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,m,c,cc=0,i;
    cin>>n>>m>>c;
    ll ara[m];
    for(i=0;i<m;i++)cin>>ara[i];
    while(n--){
        ll sum=0;
        for(i=0;i<m;i++){
            ll x;cin>>x;
            sum+=x*ara[i];
        }
    sum+=c;
    if(sum>0)cc++;
    }
    cout<<cc<<endl;
return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <bitset>
#include <set>

using namespace std;

typedef string::const_iterator state;

int term(state &begin,int a,int b,int c,int d);
int expr(state &begin,int a,int b,int c,int d);
int numb(state &begin,int a,int b,int c,int d);
int factor(state &begin,int a,int b,int c,int d);

int numb(state &begin,int a,int b,int c,int d){
	int ans;
	if(*begin=='0'){
		ans = 0;
	}
	if(*begin=='1'){
		ans = 1;
	}
	if(*begin=='a'){
		ans = a;
	}
	if(*begin=='b'){
		ans = b;
	}
	if(*begin=='c'){
		ans = c;
	}
	if(*begin=='d'){
		ans = d;
	}
	begin++;
	return ans;
}

int expr(state &begin,int a,int b,int c,int d){
	int ans = term(begin,a,b,c,d);
	while(1){
		if(*begin == '*'){
			begin++;
			ans *= term(begin,a,b,c,d);
		}else if(*begin == '^'){
			begin++;
			ans ^= term(begin,a,b,c,d);
		}else{
			break;
		}
	}
	return ans;
}

int term(state &begin,int a,int b,int c,int d){
	int ans;
	if(*begin== '-'){
		begin++;
		ans = term(begin,a,b,c,d);
		if(ans==0)return 1;
		else return 0;
	}else{
		return factor(begin,a,b,c,d);
	}
}

int factor(state &begin,int a,int b,int c,int d){
	if(*begin == '('){
		begin++;
		int ans = expr(begin,a,b,c,d);
		begin++;
		return ans;
	}else{
		return numb(begin,a,b,c,d);
	}
}


long long calc(string s){
	long long  x = 0;
	long long  ans=0;
	for(int a=0;a<=1;a++){
		for(int b=0;b<=1;b++){
			for(int c=0;c<=1;c++){
				for(int d=0;d<=1;d++){
					state k = s.begin();
					ans += ((long long)1<<x)*expr(k,a,b,c,d);
					x++;
				}
			}
		}
	}
	return ans;
}

int length[1<<17];


int main(){
	for(int i=0;i<(1<<17);i++){
		length[i]= 30;
	}
	set<string> d[17];
	length[calc("0")]=1;
	length[calc("1")]=1;
	length[calc("a")]=1;
	length[calc("b")]=1;
	length[calc("c")]=1;
	length[calc("d")]=1;
	d[1].insert("0");
	d[1].insert("1");
	d[1].insert("a");
	d[1].insert("b");
	d[1].insert("c");
	d[1].insert("d");
	for(int l=2;l<=16;l++){
		for(set<string>::const_iterator itr =d[l-1].begin(); itr!=d[l-1].end();++itr){
			string s1 = "-"+*itr;
			long long x = calc(s1);
			if(length[x]>l){
				d[l].insert(s1);
				length[x] = l;
			}
		}
		for(int i = 1;i<l-3;i++){
			for(set<string>::const_iterator itr1 =d[i].begin(); itr1!=d[i].end();++itr1){
				for(set<string>::const_iterator itr2 =d[l-3-i].begin(); itr2!=d[l-3-i].end();++itr2){
					string s1 = "("+*itr1+"*"+*itr2+")";
					string s2 = "("+*itr1+"^"+*itr2+")";
					long long x = calc(s1);
					long long y = calc(s2);
					if(length[x]>l){
						d[l].insert(s1);
						length[x]=l;
					}
					if(length[y]>l){
						d[l].insert(s2);
						length[y]=l;
					}
				}
			}
		}
	}
	string s;
	while(cin >> s&&s!="."){
		long long x = calc(s);
		cout << length[x] << endl;
	}
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
int main() {//BFSなんもわからん
  ll h,w;
  cin >> h >> w;
  vector<vector<char>> a(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin >> a[i][j];
    }
  }
  vvl dp(h,vl(w,INF));
  rep(i,h){
    rep(j,w){
      if(a[i][j]=='#'){
        dp[i][j]=0;
      }
    }
  }
  rep(i,h){
    FOR(j,1,w){
      dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
    }
  }
  rep(i,h){
    for(ll j=w-2;j>=0;j--){
      dp[i][j]=min(dp[i][j],dp[i][j+1]+1);
    }
  }
  FOR(i,1,h){
    rep(j,w){
      dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
    }
  }
  for(ll i=h-2;i>=0;i--){
    rep(j,w){
      dp[i][j]=min(dp[i][j],dp[i+1][j]+1);
    }
  }
  ll ans=-1;
  rep(i,h){
    rep(j,w){
      ans=max(ans,dp[i][j]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

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

int main(){
    string s; cin >> s;
    ll ss = s.size();
    vector<ll> cnt(2019,0);
    cnt.at(0)++;
    ll mem = 0;
    for(int i=ss-1;i>=0;i--){
        ll x = s.at(i) - '0';
        x = x * modpow(10,ss-1-i,2019);
        x %= 2019;
        mem = (mem + x)%2019;
        cnt.at(mem)++;
        //rep(j,2019){
        //    if(cnt.at(j)>0) cout << j << " " << cnt.at(j) << endl;
        //}        
    }
    ll ans = 0;
    rep(i,2019){
        ans += cnt.at(i) * (cnt.at(i)-1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int city[50]={};
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		city[a]++;
		city[b]++;
	}
	for(int i=1;i<=n;i++){
		cout << city[i] << endl;
	}
}


Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>                                    
#include <deque>                                    
#include <queue>
#include <iomanip>
#include <ctime>
#include <random>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;

 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int d, t, s;
 
inline void boost () {
   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
}

inline void Solve () {
   cin >> d >> t >> s;
   if ((d + s - 1) / s <= t) cout << "Yes";
   else cout << "No";
}               
 
signed main () {                                       
  // #ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                 


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    if(N>M)swap(N,M);
    if(N==1){
        if(M>=2){
            cout<<M-2<<endl;
        }
        else{
            cout<<1<<endl;
        }
    }
    else{
        cout<<(M-2)*(N-2)<<endl;
    }
    return 0;
}


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

#define Nmax int(1e5 + 1)
using namespace std;

int Max,N,s,Hans;
int a[Nmax],L[Nmax],R[Nmax];

int main() {
    ios_base::sync_with_stdio(0);
    cin >> N;
    for(int i = 1; i <= N; ++i)
        cin >> a[i];
    for(int i = 1; i <= N; ++i)
        L[i] = __gcd(L[i - 1],a[i]);
    for(int i = N; i >= 1; --i)
        R[i] = __gcd(R[i + 1],a[i]);
    for(int i = 1; i <= N; ++i)
        Hans = max(Hans,__gcd(L[i - 1],R[i + 1]));
    cout << Hans;
    return 0;
}


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

int main()
{
    long long L,R;
    long long ans=2020;

    cin >> L>>R;

    for (long long i = L; i < R; i++)
    {
        for (long long j = i+1; j <= R; j++)
        {
            long long x=(i*j)%2019;
            if(x<ans)ans=x;
            if(ans==0){
                cout << ans;
                return 0;
            }
        }
    }

    cout << ans;

    return 0;
}

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

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;




int main()
{

//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   ll n;
    cin>>n;
    string s;
    while(n>0)
    {
        int d = n%26;
        if(d==0)
            d =26;
        s+= (char)(d+'a'-1);
        n=n-d;
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3640
from itertools import combinations as c

n, m, x = map(int, input().split())
arr = []
for i in range(n):
	l = list(map(int, input().split()))
	arr.append(l)

g = list(range(1, n + 1))

h = -1
for i in range(1, n + 1):
	for p in c(g, i):
		s = 0
		r = [0] * m
		for v in p:
			s += arr[v-1][0]
			for k in range(m):
				r[k] += arr[v-1][k+1]
		u = 1
		for v in r:
			if v < x:
				u = 0
		if u:
			if h == -1:
				h = s
			else:
				h = min(h, s)
print(h)



Measured memory_bytes: 9232