akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
typedef long long int ll;
int main()
{
    int n;
    cin >>n;
    int count=0;
    rep(x,n+1)
    {
        if(x==0)continue;
        int cnt=0;
        if(x%2==0)continue;
        rep(i,x+1)
        {   
            if(i==0)continue;
            if(x%i==0)
            {
                cnt++;
               
            }
               
        }
        if(cnt==8)count++;
    }
    printf("%d",count);
}


Measured memory_bytes: 3700
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HossamDoma
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n = in.nextInt();
            int odds = 0, evens = 0, fours = 0;

            for (int i = 0; i < n; ++i) {

                int x = in.nextInt();

                if (x % 4 == 0)
                    fours++;
                else if (x % 2 == 0)
                    evens++;
                else
                    odds++;
            }

            if (fours >= odds || (fours + 1 == odds && n - odds * 2 + 1 == 0))
                out.println("Yes");
            else
                out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



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

int rotN(int a, int N){
  return (a + N)%26;
}

int char2num(char c, vector<char> &alp){
  for (int i = 0; i<26; i++){
    if (c == alp.at(i)){
      return i;
    }
  }
}

int main() {
  int N;
  string S;
  cin >> N >> S;
 
  vector<char> alp = {'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'};
  
  for (int i=0; i<S.size(); i++){
    cout << alp.at(rotN( char2num(S.at(i), alp), N));
  }
  cout << endl; 

 
}


Measured memory_bytes: 256
main=do
    line<-getLine
    let n=head [read x::Int|x<-words line]
    let m=last [read x::Int|x<-words line]
    ctx<-getContents
    let r=[(read (head $words x)::Int,read (last $words x)::Int)|x<- lines ctx]
    let ha=hana r
    let ta=tana r
    if ha<=ta then print (ta-ha+1) else print 0
    
hana :: [(Int,Int)]->Int
hana [x] = fst x
hana (x:xs) = max (fst x) (hana xs)

tana :: [(Int,Int)]->Int
tana [x] = snd x
tana (x:xs) = min (snd x) (tana xs)


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

int main() {
	int n,k;
  cin >> k >> n;
  vector<int> v1(n),v2(n,0);
  r(i,n)cin >> v1[i];
  v2[0]=v1[0]+k-v1[n-1];
  r(i,n-1)v2[i+1]=v1[i+1]-v1[i];
  sort(v2.begin(),v2.end());
  cout<<k-v2[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAX_N 100005
using namespace std;
/*
 * min(r, n-r)の最大値を求めればいい
 * このとき, nはaの最大値
*/
int n;
int a[MAX_N];
int main() {
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> a[i];
	
	sort(a, a+n);
	int left = a[n-1], right = min(a[0], left - a[0]);
	for(int i=0;i<n-1;i++) {
		int tmp = min(a[i], left - a[i]);
		if(tmp > right)
			right = a[i];
	}
	cout << left << " " << right << endl;
}

Measured memory_bytes: 640
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,d=INTM()
    ct=0
    for i in range(n):
        x,y=INTM()
        if x**2.0+y**2.0<=d**2.0:
            ct+=1
    print(ct)
    
if __name__=='__main__':
    do()

Measured memory_bytes: 9268
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
const int N = 10;
ll n,a,b,c;
ll ans=1e9;
ll len[N];

ll rec(ll ind, ll i, ll j, ll k)   // brute force, checking all combos
{
       if(ind==n+1)
       {
              if(i==0 || j==0 || k==0) return 1e9;
              return abs(i-a)+abs(j-b)+abs(k-c); // shortening magic + stretching magic
       }
       ll ans=1e9;
       ans=min(ans, rec(ind+1, i, j, k)); // this stick not used
       if(i==0) ans=min(ans, rec(ind+1, i+len[ind], j, k)); // used in i, if nothing intitally there no need to mix, so no cost incurred
       if(j==0) ans=min(ans, rec(ind+1, i, j+len[ind], k));
       if(k==0) ans=min(ans, rec(ind+1, i, j, len[ind]+k));
       if(i>0)  ans=min(ans, 10 + rec(ind+1, i+len[ind], j, k));// if some stick already present cost = 10 is incurred
       if(j>0)  ans=min(ans, 10 + rec(ind+1, i, j+len[ind], k));
       if(k>0)  ans=min(ans, 10 + rec(ind+1, i, j, k+len[ind]));
       return ans;
}

void solve()
{
       cin>>n>>a>>b>>c;
       rep(i, 1, n+1) cin>>len[i];
       ll ans = rec(1, 0, 0, 0);
       cout<<ans;
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
int main(){
    int w,h;
    while(scanf("%d%d",&w,&h),w|h){
        int stage[32][32]={{0}};
        int    dp[32][32]={{0}};
        rep(i,h)rep(j,w)scanf("%d",&stage[i+1][j+1]);

        reps(i,1,w+1)if(stage[1][i] == 0)dp[1][i] = 1;

        reps(i,2,h+1){
            reps(j,1,w+1){
                if(stage[i][j] == 2){
                    dp[i+2][j] += dp[i-1][j] + dp[i][j];
                    dp[i][j] = 0;
                }
                else if(stage[i][j] == 1){
                    dp[i][j] = 0;
                }
                else if(stage[i][j] == 0){
                    dp[i][j] += dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1];
                }
            }
        }

        int ans = 0;
        rep(i,w+1){
            ans += dp[h][i] + dp[h+1][i] + dp[h+2][i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;


void slove() {
	string s; cin >> s;
	ll l = s.size();
	rep(i,0,l) {
		if (s[i]=='?') {
			if (s[i+1]=='P') {s[i]='D'; continue;}
			if (i==0) {s[i]='D'; continue;}
			if (s[i-1]=='P') {s[i]='D'; continue;}
			if (s[i+1]=='D') {s[i]='P'; continue;}
			if (s[i+1]=='?') {s[i]='P'; continue;}
			s[i]='D';
		}
	}
	cout << s << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	//int t; cin >> t; while(t--)
	slove();

	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int h , w;
string s[10];
void solve(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	
	int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
	queue<P> q;
	q.push(P(0,0));
	bool used[20][20] = {0};
	while(!q.empty()){
		P p = q.front(); q.pop();
		int x = p.first, y = p.second;
		int cnt = 0;
		used[x][y] = 1;
		for(int i = 0; i < 2; i++){
			int nx = x+dx[i], ny = y+dy[i];
			if(nx >= h || ny >= w) continue;
			if(s[nx][ny] == '#'){
				cnt++;
				q.push(P(nx,ny));
			}
			if(cnt > 1){
				cout << "Impossible" << endl;
				return;
			}
		}
	}
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '.') continue;
			if(used[i][j]) continue;
			cout << "Impossible" << endl;
			return;
		}
	}
	
	cout << "Possible" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

bcount = 0
wcount = 0
mins = []

for i in range(N):
    if S[i] == ".":
        wcount += 1

mins.append(wcount)
        
for i in range(N):
    if S[i] == '#':
        bcount += 1
    else:
        wcount -= 1
    mins.append(bcount + wcount)

print(min(mins))


Measured memory_bytes: 12836
import math

def gcd(k):
  ans = 0
  for a in range(1, k+1):
    for b in range(1, k+1):
      for c in range(1, k+1):
        ans += math.gcd(math.gcd(a, b), c)
  print(ans)  
  
if __name__ == "__main__":
  k = int(input())
  gcd(k)

Measured memory_bytes: 9184
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=100 +117;
const int MM=100 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
LL a[NN]={};
LL dp[NN][NN]={};
bool conti[NN]={};
int li[NN]={};
const int mod=1e9+7;
LL ksm(LL a,LL b){
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ret=ret*a%mod;
	return ret;
}
int main(){
	//open();
	n=read();
	LL ans=1;
	for(int i=1;i<=n;++i){
		a[i]=read();
		if(a[i]==1){
			ans=ans*2%mod;
			a[i]=0;
		}
	}
	int lcnt=0;
	for(int i=1;i<=n;++i){
		int nb=max(a[i-1],a[i+1]);
		if(a[i]>nb){
			ans=ans*ksm(2,a[i]-nb)%mod;
			a[i]=nb;
		}
		if(a[i])li[++lcnt]=a[i];
	}
	sort(li+1,li+1+lcnt);
	lcnt=unique(li+1,li+1+lcnt)-li-1;
	for(int i=1;i<=n+1;++i){
		if(!a[i]){
			conti[i]=0;
			if(conti[i-1]==1){
				ans=ans*dp[i-1][0]%mod;
			}
		}
		else{
			int h=lower_bound(li+1,li+1+lcnt,a[i])-li;
			if(conti[i-1]){
				int pre=lower_bound(li+1,li+1+lcnt,a[i-1])-li;
				if(pre<=h){
					for(int j=0;j<=pre;++j){
						dp[i][j]=(dp[i-1][j]+dp[i-1][pre])*ksm(2,a[i]-a[i-1])%mod;
					}
					for(int j=pre+1;j<=h;++j){
						dp[i][j]=(dp[i-1][pre]+dp[i-1][pre])*ksm(2,a[i]-li[j])%mod;
					}
				}
				else{
					for(int j=0;j<=h;++j){
						dp[i][j]=(dp[i-1][j]+dp[i-1][h])%mod;
					}
				}
			}
			else{
				dp[i][0]=ksm(2,a[i]);
				for(int j=1;j<=h;++j){
					dp[i][j]=2*ksm(2,a[i]-li[j]);
				}
			}
			conti[i]=1;
		}
	}
	printf("%lld\n",ans);
	close();
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int A, B;

int main(){
    cin >> A >> B;

    vector<string> ans;
    string buf(100, '#');
    for(int i=0; i<A-1; i++){
        buf[2*(i%50)] = '.';
        if(i%50==49){
            ans.push_back(buf);
            ans.push_back(string(100, '#'));
            buf = string(100, '#');
        }
    }
    ans.push_back(buf);
    ans.push_back(string(100, '#'));

    buf = string(100, '.');
    for(int i=0; i<B-1; i++){
        buf[2*(i%50)] = '#';
        if(i%50==49){
            ans.push_back(string(100, '.'));
            ans.push_back(buf);
            buf = string(100, '.');
        }
    }
    ans.push_back(string(100, '.'));
    ans.push_back(buf);

    printf("%d 100\n", ans.size());
    for(string s: ans){
        printf("%s\n", s.c_str());
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define MAX_N 200050

using namespace std;

int dp[MAX_N];

int main(){
  int n,k;
  cin >> n >> k;
  int h[MAX_N];
  for(int i=0;i < n;i++) cin >> h[i];
  for(int i=0;i < MAX_N;i++) dp[i] = 1000000000;
  dp[0] = 0;
  
  for(int i=1;i < n;i++){  
    for(int j=max(i-k,0);j < i;j++){
        dp[i] = min(dp[i],dp[j]+abs(h[i] - h[j]));
     }
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void ii(ll &x){ cin >> x; }
void is(string &x){ cin >> x; }
void oi(ll x){ cout << x << " "; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

bool ab[10000],ac[10000],bc[10000];

bool match(char c1, char c2){
    return (c1=='?'||c2=='?'||c1==c2);
}

int main(){
    ll i,j;
    ll M=2000;
    string a,b,c;
    is(a);
    is(b);
    is(c);

    ll A = a.length();
    ll B = b.length();
    ll C = c.length();

    REP(i,0,A) REP(j,0,B) if(!match(a[i],b[j])) ab[i-j+5000] = true;
    REP(i,0,A) REP(j,0,C) if(!match(a[i],c[j])) ac[i-j+5000] = true;
    REP(i,0,B) REP(j,0,C) if(!match(b[i],c[j])) bc[i-j+5000] = true;

    ll ans=3*M;
    for(i=-2*M;i<=2*M;i++){
        for(j=-2*M;j<=2*M;j++){
            if(!ab[i+5000] && !ac[j+5000] && !bc[j-i+5000]){
                ll L = min((ll)0, min(i,j));
                ll R = max(A, max(B+i,C+j));
                ans=min(ans,R-L);
            }
        }
    }
    oie(ans);
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[] b = new int[a];
        int[] c = new int[a];
        int max = 0;
        for(int i=0; i<a; i++) {
            b[i] = sc.nextInt();
        }
        for(int i=0; i<a; i++) {
            c[i] = sc.nextInt();
        }
        for(int i=0; i<a; i++) {
            int total = 0;
            for(int j=0; j<=i; j++) {
                total += b[j];
            }
            for(int k=i;k<a;k++) {
                total += c[k];
            }
            if(total > max) {
                max = total;
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 21844
n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
def euclid(a,b):
    if a % b == 0:
        return b
    else:
        return euclid(b, a%b)

now = abs(x[0] -x[1])
for i in range(1, len(x)-2):
    r = euclid(now, abs(x[i] - x[i+1]))
    if r < now:
        now = r
r = euclid(now, abs(x[0] - x[-1]))
if r < now:
    now = r
print(now)

Measured memory_bytes: 20380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vector<ll> a(n + 1);
	for (ll i = 0; i < n + 1; i++) cin >> a[i];

	if (n == 0) {
		if (a[0] == 1) cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}
	else if (a[0] > 0) {
		cout << -1 << endl;
		return 0;
	}

	vector<ll> sum(n + 1, a.back());
	for (ll i = n - 1; i >= 0; i--) {
		sum[i] = sum[i + 1] + a[i];
	}

	ll ans = 1, m = 1;
	for (ll i = 1; i < n; i++) {
		ll x = min(sum[i], 2 * m);
		if (x <= a[i]) {
			cout << -1 << endl;
			return 0;
		}
		ans += x;
		m = x - a[i];
	}
	if (a.back() > 2 * m) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans + a.back() << endl;
}


Measured memory_bytes: 4748
N = int(input())
s = [input().split(" ") for i in range(N)]

count = 0
yes = False
for i in s:
    if i[0] == i[1]:
        count += 1
    else:
        count = 0
    if count >= 3:
        print("Yes")
        yes = True
        break

if not yes:
    print("No")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}
string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m,ans=0,total=0;
    double mini;
    cin>>n>>m;
    double a[n];
    mini=1;
    mini/=(4*m);
    //cout<<mini<<"\n";
    for (int i=0;i<n;++i)
    {
        cin>>a[i];
        total+=a[i];
    }
    for (int i=0;i<n;++i)
    {
        a[i]/=total;
        if (a[i]>=mini)
        {
            ++ans;
        }
    }
    if (ans>=m)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#define ll long long

using namespace std;

const ll NMAX = 105, WMAX = 1e5 + 15;
struct OBJECT {
    ll v, w;
} v[NMAX];
ll matrix[NMAX][WMAX];

ll n, w;

ll solve(ll pos, ll weight) {
    if(weight > w)
        return INT_MIN;
    if(pos > n)
        return 0;
    if(matrix[pos][weight] != 0)
        return matrix[pos][weight];
    ll val;
    val = max(solve(pos + 1, weight + v[pos].w) + v[pos].v, solve(pos + 1, weight));
    matrix[pos][weight] = val;
    return val;
}

int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++) {
        cin >> v[i].w >> v[i].v;
    }
    cout << solve(1, 0);
    return 0;
}


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

using namespace std;

int main()
{
  string s; cin >> s;
  string ans;
  for (int i = 0, len = s.size(); i < len; ++i) {
    if (s[i] == '0' or s[i] == '1') {
      ans.push_back(s[i]);
    } else if (ans.size() > 0) {
      ans.pop_back();
    }
  }

  cout << ans;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn rec(n : usize,s : String, c : char){
    if s.len() == n {
        println!("{}",s);
        return;
    }
    let x = c as u8;
    let a = 'a' as u8;
    for t in a..(x+1) {
        rec(n, format!("{}{}",s,t as char), if t == x {(x + 1) as char} else {c} );
    }
}

fn main() {
    input!{
        n:usize
    }
    rec(n, String::new(), 'a');
    return;
}



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

int main(){
    int N; cin >> N;
    int A[N+2];
    A[0] = 0; A[N+1] = 0;
    for(int i = 1; i <= N; i++) cin >> A[i];

    int D = 0;
    for(int i = 1; i <= N; i++){
        D += abs(A[i] - A[i-1]);
    }
    D += abs(A[N+1] - A[N]);
    // cout << D << endl;
    for(int i = 1; i <= N; i++){
        int tmp = abs(A[i+1]-A[i-1]) - (abs(A[i+1]-A[i])+abs(A[i]-A[i-1]));
        cout << D + tmp << endl;
    }


    
    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	ll N, K;
	cin >> N >> K;

	if(K == 0){
		cout << N * N << endl;
		return 0;
	}

	ll ans = 0;
	for(ll b = 1; b <= N; b++){
		ll a = N / b;
		ans += a * max(0LL, b - K);
		ll rem = N % b;
		if(rem){
			ans += max(0LL, rem + 1 - K);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;

int main() {
	int n,s;
	while(1){
		cin >> n >> s ; if(!n && !s) break;
		long long dp[10][1001][101]; memset(dp,0,sizeof(dp));
		for(int i=0;i<=min(s,100);i++) dp[0][i][i]=1;
		for(int i=0;i<n;i++){
			for(int k=0;k<=min(s,100*(i+1));k++){
				for(int l=0;l<=100;l++){
					for(int j=l+1;j<=100;j++){
						if(k+j>s) break;
						dp[i+1][k+j][j]+=dp[i][k][l];
					}
				}
			}
		}
		long long sum=0;
		for(int i=0;i<=100;i++) sum+=dp[n-1][s][i];
		cout << sum << '\n' ;
	}
}

Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}


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

	queue<ll> q;
	for(int i=1; i<10; i++) q.push(i);

	ll now;
	for(int i=0; i<K; i++) {
		now=q.front(); q.pop();
		if(now%10==0) {
			q.push(now*10);
			q.push(now*10+1);
		}
		else if(now%10==9) {
			q.push(now*10+8);
			q.push(now*10+9);
		}
		else {
			int foo=now%10;
			q.push(now*10+foo-1);
			q.push(now*10+foo);
			q.push(now*10+foo+1);
		}
	}
	cout<<now<<endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
    int N,K,i;
    int h[100000];
    int safe = 0;
    scanf("%d %d",&N,&K);
    for(i = 0 ; i < N ; i++){
        scanf("%d",&h[i]);
    }
    for(i = 0 ; i < N ; i++){
        if(h[i] >= K){
            safe++;
        }
    }
    printf("%d\n",safe);
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 1e5+10;

int N, M;
vii edge[MAX];

vii cnstrs[MAX];
int parent[MAX];

ll solve() {
    queue<int> idxs;
    idxs.push(0);

    while (!idxs.empty()) {
        int n = idxs.front();
        idxs.pop();

        cnstrs[0].push_back(ii(1, 0));
        FORE (e, edge[n]) if (parent[n] != e.first) {
            ll l = e.first, s = e.second;
            if (cnstrs[l].size() == 0) idxs.push(l);
            cnstrs[l].push_back(ii(cnstrs[n][0].first * -1, s - cnstrs[n][0].second));
        }
    }

    ll must_be = -1;
    REP (i, N) {
        sort(ALL(cnstrs[i]));
        REP (j, cnstrs[i].size()) {
            // 制約の偶奇は一致
            if ((cnstrs[i][j].second & 1) != (cnstrs[i][0].second & 1)) return 0;
            if (cnstrs[i][j].first != cnstrs[i][0].first) {
                ll t = (cnstrs[i][0].second - cnstrs[i][j].second) / 2;
                if (must_be != -1 && must_be != t) return 0;
                must_be = t;
            }
        }
    }

    if (must_be != -1) {
        REP (i, N) FORE (c, cnstrs[i]) {
            if (c.first * must_be + c.second <= 0) return 0;
        }
        return 1;
    }

    ll pos = -1e18, neg = 1e18;
    REP (i, N) FORE (c, cnstrs[i]) {
        if (c.first == 1) {
            CHMAX(pos, -c.second);
        } else {
            CHMIN(neg, c.second);
        }
    }
    pos++;
    return max(neg - pos, 0ll);
}

int main() {
    cin >> N >> M;
    REP (i, M) {
        int u, v, s;
        cin >> u >> v >> s;
        u--; v--;
        edge[u].push_back(ii(v, s));
        edge[v].push_back(ii(u, s));
    }
    cout << solve() << endl;
}

Measured memory_bytes: 18160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
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;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int h,w;
    cin>h>w;
    vector<string> s(h);
    cin>s;
    REP(y,h){
        REP(x,w){
            if(s[y][x]=='#')continue;
            int cnt=0;
            if(x>0 && y>0 && s[y-1][x-1]=='#')cnt++;
            if(x>0 && y<h-1 && s[y+1][x-1]=='#')cnt++;
            if(x<w-1 && y>0 && s[y-1][x+1]=='#')cnt++;
            if(x<w-1 && y<h-1 && s[y+1][x+1]=='#')cnt++;

            if(x>0 && s[y][x-1]=='#')cnt++;
            if(x<w-1 && s[y][x+1]=='#')cnt++;
            if(y>0 && s[y-1][x]=='#')cnt++;
            if(y<h-1 && s[y+1][x]=='#')cnt++;
            s[y][x]=cnt+'0';
        }
    }
    REP(i,h){
        cout<s[i]<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}
#

int main() {
	int n,m; cin >> n >> m;
	vector<int> cnt(m);
	int k,l;
	for (int i = 0; i < n; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> l;
			cnt[l - 1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (cnt[i] == n) ans++;
	}
	cout << ans;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let nk = read_vec::<u64>();
    let mut n = nk[0];
    let k = nk[1];

    let mut cnt = 0;
    while n >= k {
        n /= k;
        cnt += 1;
    }

    println!("{}", cnt + 1);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
//	int dp[n]={INT_MAX};
vector<int> dp(n,1e9);
	dp[0]=0;
for(int i=0;i<n;i++){
	for(int j=i+1;j<=i+2;j++){
		dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
	}
}
	cout<<dp[n-1]<<" ";
	
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 114：A - 753


def main():
    X = int(raw_input().strip())

    if X == 7 or X == 5 or X == 3:
        print 'YES'
    else:
        print 'NO'


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0;i < n;++i)
    {
        cin >> v.at(i);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    long long sum1 = 0;
    long long sum2 = 0;
    for(int i = 0;i < n;++i)
    {
        if(i % 2 == 0)
            sum1 += v[i];
        else
            sum2 += v[i];
    }
    cout << sum1 - sum2 << '\n';
}



Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

class DICE {
  public:
    int T, S, E, W, N, B;

    DICE(vector<int> tmp) {
        if(tmp.size() != 6)
            exit(1);
        T = tmp[0];
        S = tmp[1];
        E = tmp[2];
        W = tmp[3];
        N = tmp[4];
        B = tmp[5];
    }
    DICE(int T0, int S0, int E0, int W0, int N0, int B0) {
        tie(T, S, E, W, N, B) = make_tuple(T0, S0, E0, W0, N0, B0);
    }

    void turn(char dir) {
        if(dir == 'S')
            tie(T, B, S, N) = make_tuple(N, S, T, B);
        else if(dir == 'N')
            tie(T, B, N, S) = make_tuple(S, N, T, B);
        else if(dir == 'E')
            tie(T, B, E, W) = make_tuple(W, E, T, B);
        else if(dir == 'W')
            tie(T, B, W, E) = make_tuple(E, W, T, B);
        else if(dir == 'B')
            tie(T, B, W, E) = make_tuple(B, T, E, W);
        else if(dir == 'R')
            tie(N, E, S, W) = make_tuple(W, N, E, S);
    }

    bool match(int to, int fr) {
        if(T != to) {
            if(to == B) {
                turn('B');
            } else if(to == E) {
                turn('W');
            } else if(to == W) {
                turn('E');
            } else if(to == S) {
                turn('N');
            } else if(to == N) {
                turn('S');
            }
        }
        while(fr != S) {
            turn('R');
        }
        return true;
    }
};

bool isSameDice(DICE a, DICE b) {
    return (a.B == b.B && a.W == b.W && a.E == b.E && a.N == b.N &&
            a.T == b.T && a.S == b.S);
}

int main() {
    vector<int> dia(6), dib(6);
    rep(i, 6) cin >> dia[i];
    rep(i, 6) cin >> dib[i];
    DICE a = dia, b = dib;
    string rotate = "XNNNNWNNNNWNNNNWNNNNNWNNNNWNNNNWNNNNWNNNN";
    rep(i, rotate.length()) {
        b.turn(rotate[i]);
        if(isSameDice(a, b)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3204
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int n, q, m;
vi A;

bool solve(int i, int sum) {
  if (sum == m) return true;
  if (i >= n || sum > m) return false;
  return solve(i+1, sum+A[i]) || solve(i+1, sum);
}

int main(int argc, char **argv)
{
  scanf("%d", &n);
  A = vi(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &m);
    printf("%s\n", solve(0, 0) ? "yes" : "no");
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
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;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  int N; cin >> N;
  if(N>=30){ cout <<Liny;}
  else{ cout <<Linn;}
  

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
/*
Mau chot là, neu ban ue oai, luoi nhác hôm nay, ban se không bat chat tro nên tràn day nang luong vào tuân sau,
tháng sau, nam sau hay sau nua, tru phi ban bat tay làm gì dó
*/
using namespace std;

typedef long long ll ;

const ll ts = 100005;

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

int n;

string s; 

void init() {
     cin >> s; 
     if(s.length() % 2 == 1) {
     	cout << "No";
     	return ; 
	 }
     for(int i = 0 ; i < s.length() ; i++) {
     	if(i % 2 == 0 && s[i] != 'h') {
     		cout << "No";
     		return ; 
		 } 
		if(i % 2 == 1 && s[i] != 'i') {
			cout << "No";
			return ; 
		}
	 }
	 cout << "Yes";
}
signed main() {
	IOS;
	init();


}










Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l;cin>>n>>l;
    int x=abs(l);
    int k,i,s=0;
    for(i=1;i<=n;i++)
    {
        k = l+i-1;
        s=s+k;

        if(abs(k) < x) x=abs(k);

    }

    if(s<0) printf("%d\n",s+x);
    else printf("%d\n",s-x);
    return 0;

}


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

int main() {
    int N;
    cin >> N;
    unordered_map<string, int> S;
    string str;
    int mx = 0;
    for (int i = 0; i < N; i++) {
        cin >> str;
        if (S.find(str) == S.end()) {
            S[str] = 0;
        } else {
            S[str]++;
            mx = max(mx, S[str]);
        }
    }
    vector<string> res;
    for (auto v : S) {
        if (v.second == mx) {
            res.push_back(v.first);
        }
    }
    sort(res.begin(), res.end());

    for (auto v : res) {
        cout << v << "\n";
    }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector <int> a(M),b(M),r(N);
  

 for(int i=0 ; i < M ; i++){
	cin >> a.at(i) >> b.at(i);

 }
 
for(int i=0 ; i < N ; i++){
  
   for(int j=0 ; j < M ; j++){
	if(a.at(j)==i+1) r.at(i)++;     
    if(b.at(j)==i+1) r.at(i)++;    
     
     
   }
  
}
  
   for(int i=0 ; i < N ; i++){

   cout <<  r.at(i)  <<endl;
 }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;
    N++;

    vector<int> time(N);
    vector<int> x(N);
    vector<int> y(N);

    time[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for (int i = 1; i < N; i++)
    {
        cin >> time[i] >> x[i] >> y[i];
    }

    int turn;
    int diff_x;
    int diff_y;
    int dis;
    for (int i = 0; i < N - 1; i++)
    {
        turn = time[i + 1] - time[i];
        diff_x = abs(x[i + 1] - x[i]);
        diff_y = abs(y[i + 1] - y[i]);
        dis = diff_x + diff_y;
        // printf("turn = %d, dis = %d\n", turn, dis);

        if (turn < dis)
        {
            cout << "No" << endl;
            return (0);
        }
        else
        {
            int diff = turn - dis;
            if (diff % 2 == 0)
            {
                continue;
            }
            else
            {
                cout << "No" << endl;
                return (0);
            }

            // if (turn % 2 == 0)
            // {
            //     if (dis % 2 == 0)
            //     {
            //         // even & even
            //         // possbile
            //         continue;
            //     }
            //     else
            //     {
            //         // even & odd
            //         cout << "No" << endl;
            //         return (0);
            //     }
            // }
            // else
            // {
            //     if (dis % 2 == 0)
            //     {
            //         // odd & even
            //         cout << "No" << endl;
            //         return (0);
            //     }
            //     else
            //     {
            //         // odd & odd
            //         // possible
            //         continue;
            //     }
            // }
        }
    }
    cout << "Yes" << endl;
    return (0);
}

Measured memory_bytes: 1408
s = input()
n = len(s)
rl = []
for i in range(n-1):
    if s[i] == "R" and s[i+1] == "L":
        rl.append(i)
rl.append(-1)
left = right = rl[0]
k = 0
ans = [0]*n
for i in range(n):
    if i == right:
        ans[i] += 1
        continue
    if i == right + 1:
        ans[i] += 1
        left = right
        right = rl[k+1]
        k += 1
        continue
    if s[i] == "R":
        ans[right + (right-i)%2] += 1
    else:
        ans[left + (i-left)%2] += 1
print(*ans)

Measured memory_bytes: 48188
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int a,b;
	cin >> a >> b;
	if(a+b > a*b && a+b > a-b)cout << a+b << endl;
	else if(a*b > a+b && a*b > a-b)cout << a*b << endl;
	else cout << a-b << endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List

main :: IO ()
main = do
  ls <- replicateM 5 readLn
  let ans' = sum $ map ((*10).(`div` 10)) ls
      ls' = (filter (/= 0) $ map (`mod` 10) ls)
      ans'' = if ls' == [] then 0 else (minimum ls') + (max 0 ((length ls') - 1))*10
  print $ ans' + ans''


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
string s;
int use=0;
int ans=0;
signed main(){
    cin>>s;
    int l=s.size();
    rep(i,l){
        if(s[i]=='g'){
            if(use>0){
                use--;
                ans++;
            }
            else use=true;
        }
        else{
            if(use<=0){
                ans--;
                use++;
            }
            else use--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	long long ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
		if(i%3&&i%5)
			ans+=i;
	cout<<ans<<endl;
	return 0;
}


 

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d,x,a[101];
  cin>>n>>d>>x;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int sum=n;
  for(int i=0;i<n;i++){
    for(int j=1;j<d+1;j++){
      if(a[i]*j+1>d){break;}
      sum++;
    }
  }
  cout<<sum+x<<endl;
  return 0;
}
     

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int T;
ll a, b, c, d;
ll n, ans;
map<ll, ll> mp;
ll solve(ll x)
{
    if (x == 0) return 0;
    if (x == 1) return d;
    if (mp.find(x) != mp.end()) return mp[x];
    ll res = INF;
    if (INF / x > d) res = d * x;
    res = min(res, solve(x / 2) + d * (x % 2) + a);
    res = min(res, solve((x + 1) / 2) + d * (2 - x % 2) + a);
    res = min(res, solve(x / 3) + d * (x % 3) + b);
    res = min(res, solve((x + 2) / 3) + d * (3 - x % 3) + b);
    res = min(res, solve(x / 5) + d * (x % 5) + c);
    res = min(res, solve((x + 4) / 5) + d * (5 - x % 5) + c);
    return mp[x] = res;
}
int main()
{
    scanf("%d", &T);
    while (T--)
    {
        mp.clear();
        scanf("%lld", &n);
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        printf("%lld\n", solve(n));
    }
    return 0;
}

Measured memory_bytes: 4480