akhauriyash/Code-Regression huggingface dataset:
x,n =map(int,input().split())
p =list(map(int,input().split()))

for i in range(0,1000000000000):
  a = x-i
  b=x+i
  if(a not in set(p)):
    print(a)
    break
    
  elif(b not in set(p)):
    print(b)
    break
	

Measured memory_bytes: 9020
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i]; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int n;
	cin>>n;
	string s;
	cin>>s;
	if((int)s.length()<=n)
		cout<<s<<endl;
	else{
		for(int i=0;i<n;i++)
			cout<<s[i];
		cout<<"...\n";
	}
}



Measured memory_bytes: 3624
#include <iostream>
#include <set>
#define PI pair<int,int>
using namespace std;
char m[101][101];
int main()
{
  int h,w,i,j;
  for(;;){
    cin >> h >> w;
    if(h==0 && w==0) break;
    for(i=0;i<h;i++){
      cin >> m[i];
    }
    i = j = 0;
    set< PI > s;
    s.insert(PI(i,j));
    for(;;){
      if(m[i][j] == '.') {
	cout << j << " " << i << endl;
	break;
      }
      switch(m[i][j]){
      case '>': j++; break;
      case '<': j--; break;
      case '^': i--; break;
      case 'v': i++; break;
      }
      if(s.find(PI(i,j)) != s.end()){
	cout << "LOOP" << endl;
	break;
      }
      s.insert(PI(i,j));
    }
  }
  return 0;
}

Measured memory_bytes: 0
class DisjoinSet:
    def __init__(self, size):
        self.rank = [0 for _ in range(size)]
        self.p = [0 for _ in range(size)]
        for i in range(n):
            self.makeSet(i)

    def makeSet(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def same(self, x, y):
        print(int(self.findSet(x) == self.findSet(y)))

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    # ???????±???????
    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]


if __name__ == '__main__':
    n, q = map(int, input().split())
    D = DisjoinSet(n)
    cmd = {0: lambda x, y: D.unite(x, y), 1: lambda x, y: D.same(x, y)}
    for _ in range(q):
        c, x, y = map(int, input().split())
        cmd[c](x, y)

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

int main(){

  int sum;
  int cash;

  while(cin >> cash , cash){
    cash = 1000-cash;
    sum = 0;
    sum += cash/500; cash%=500;
    sum += cash/100; cash%=100;
    sum += cash/50; cash%=50;
    sum += cash/10; cash%=10;
    sum += cash/5; cash%=5;
    sum += cash/1;
    
    cout<< sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

class Problem {
    private int N;
    private int K;
    private int[] hs;

    Problem() {
        Scanner sc = new Scanner(System.in);

        N = sc.nextInt();
        K = sc.nextInt();
        hs = new int[N];
        for (int i = 0; i < N; i++) {
            hs[i] = sc.nextInt();
        }
    }

    int solve() {
        int[] costs = new int[N];
        for(int i = 1; i < N; i++) {
            costs[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= K; j++) {
                if (i - j < 0) break;

                int cost = Math.abs(hs[i] - hs[i-j]) + costs[i-j];
                costs[i] = Math.min(costs[i], cost);
            }
        }
        return costs[N-1];
    }
}

public class Main {
    public static void main(String[] args) {
        int ans = new Problem().solve();
        System.out.println(ans);
    }
}


Measured memory_bytes: 51244
#include <cstdio>

int main() {
    int num;
    scanf("%d", &num);

    int* prices = new int[num];
    for (int i = 0; i < num; i++) {
        int input;
        scanf("%d", &input);
        prices[i] = input;
    }

    int maxProfit = prices[1] - prices[0];
    if (num == 2) {
        printf("%d\n", maxProfit);
        return 0;
    }

    int minPrice = (prices[1] > prices[0])? prices[0] : prices[1];
    for (int i = 2; i < num; i++) {
        int profit = prices[i] - minPrice;
        if (profit > maxProfit) {
            maxProfit = profit;
        }
        if (prices[i] < minPrice) {
            minPrice = prices[i];
        }
    }
    printf("%d\n", maxProfit);

    delete[] prices;
    return 0;
}

Measured memory_bytes: 1796
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

bool chk(ll N, ll A, ll B, std::vector<ll> h, ll T) {
  ll check = 0;
  REP(i, N) {
    if (h[i] - B * T <= 0)
      continue;
    check += (h[i] - B * T) / (A - B) + ((h[i] - B * T) % (A - B) == 0 ? 0 : 1);
  }
  // cout << T << " " << check << endl;
  return check <= T;
}

void solve(long long N, long long A, long long B, vector<long long> h) {
  ll left = 0;
  ll right = 1000000000;
  ll ans = right;

  //二分探索
  // binarySearch + iwashi!
  while (left < right) {
    ll mid = (left + right) / 2;
    if (chk(N, A, B, h, mid)) {
      ans = min(ans, mid);
      right = mid;
    } else {
      left = mid + 1;
    }

    if (right - left < 100)
      break;
  }

  for (ll i = left; i <= right; ++i)
    if (chk(N, A, B, h, i)) {
      ans = min(ans, i);
    }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long A;
  long long N;
  long long B;
  cin >> N;
  vector<long long> h(N - 1 + 1);
  cin >> A;
  cin >> B;
  for (int i = 0; i <= N - 1; i++) {
    cin >> h[i];
  }
  solve(N, A, B, h);
  return 0;
}


Measured memory_bytes: 2672
#include<cstdio>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

int main(){
	for(int n,c[100],T=1;scanf("%d",&n),n;T++){
		rep(i,n)	scanf("%d",c+i);

		if(c[0]!=1){
			printf("Case #%d: Cannot pay some amount\n",T);
			continue;
		}

		const int L=2*c[n-1];
		int dp1[2000];	dp1[0]=0;
		fill(dp1+1,dp1+L,INF);
		rep(k,n)for(int p=c[k];p<L;p++)	dp1[p]=min(dp1[p],dp1[p-c[k]]+1);

		int dp2[2000];	dp2[0]=0;
		rep(p,L)for(int k=n-1;k>=0;k--){
			if(p-c[k]>=0){
				dp2[p]=dp2[p-c[k]]+1;
				break;
			}
		}

		bool ok=true;
		rep(i,L)if(dp1[i]<dp2[i]){ ok=false; break; }
		printf("Case #%d: %s\n",T,ok?"OK":"Cannot use greedy algorithm");
	}

	return 0;
}

Measured memory_bytes: 780
#include <stdio.h>
int main()
{
	int A,B,C,D;
	2 < A < 100;
	2 < B < 100;
	scanf ("%d", &A);
	scanf ("%d", &B);
	C = A - 1;
	D = B - 1;
	printf ("%d", C * D);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const int rows = 2;
int dx[2] = {0, 1};
int dy[2] = {1, 0};

int main() {
    int N; cin >> N;
    vector<vector<int>> A(rows, vector<int>(N));
    REP(i, 0, rows) REP(j, 0, N) cin >> A[i][j];

    vector<vector<int>> dp(rows, vector<int> (N, 0));
    dp[0][0] = A[0][0];
    REP(i, 0, rows) {
        REP(j, 0, N) {
            REP(k, 0, 2) {
                int nx = i + dx[k];
                int ny = j + dy[k];
                if (nx >= 2 || ny >= N) continue;
                dp[nx][ny] = max(dp[nx][ny], dp[i][j] + A[nx][ny]);
            }
        }
    }
    cout << dp[rows - 1][N - 1] << endl;
    return 0;
}

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

void Swap(int *a,int *b) {
  int t=*a;
  *a=*b;
  *b=t;
}
int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin>>n;
  int A[n],r=n-1;
  for (int i=0; i<n; i++) {
    cin>>A[i];
  }
  int x=A[n-1],i=(-1);
  for (int j=0; j<r; j++) {
    if (A[j]<=x) {
      i++;
      Swap(&A[i],&A[j]);
    }
  }
  Swap(&A[i+1],&A[r]);
  int p=i+1;
  for (int k=0; k<n; k++) {
    if (k) {
      cout<<" "<<flush;
    }
    if (k==p) {
      cout<<"["<<flush;
    }
    cout<<A[k]<<flush;
    if (k==p) {
      cout<<"]"<<flush;
    }
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3464
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int                 long long   
#define double              long double
#define endl                "\n"
#define pb                  push_back
#define PI                  3.1415926535897932384626433832795l
#define F                   first
#define S                   second
#define mp                  make_pair
#define f(i,n)              for(int i=0;i<n;++i)
#define loop(i,a,b)         for (int i=a ; i<b ;++i)
#define fastio              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define gcd(a,b)            __gcd((a),(b))
#define fill(a,value)       memset(a,value,sizeof(a));
#define minn(v)             *min_element(v.begin(), v.end());
#define maxx(v)             *max_element(v.begin(), v.end());
#define print(x)            cout<<(x)<<endl;
#define sum(v)+x            accumulate(v.begin(), v.end(),x);
typedef pair<int,int> pii;  
typedef vector<int> vi;

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n,d;
    cin>>n>>d;
    int x=ceil((n)/(1.0*(2*d+1)));
    print(x)
    
    
    
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

vector<int> parent(100005,0);
vector<int> size(100005,0);

void make_set(int a)
{
    parent[a] = a;
    size[a] = 1;
}

int find_set(int a)
{
    if(a == parent[a])
        return a;
    return parent[a] = find_set(parent[a]);
}

void union_set(int a, int b)
{
    a = find_set(a);
    b = find_set(b);
    if(a!=b)
    {
        if(size[a] < size[b])
            swap(a,b);
        parent[b] = a;
        size[a]+=size[b];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int answer = (a-c)*(b-d);
    cout<<answer;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")    
    #include <bits/stdc++.h>
    #define int long long
    #include<math.h>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    const int mod =1e9+7;
   


void  solve()
{
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }

  vector<int>dp(n,INT_MAX); //dp[i] represents the cost to reach i.
  dp[0]=0;
 
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<=i+k;j++)
    {
      if(j<n){
        dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
      }
    }
  }




  //arrive either from stone i-1 or stone i-2


  cout<<dp[n-1]<<endl;
 

 

 return;
  
}
 



int32_t main()
{
  int tc;
  tc=1;
  while(tc--){
    solve();
  }
  
  




  return 0;
}













 
 

 


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int a,b;
    cin >> a >> b;
    if(a+b==15) cout << "+" << endl;
    else if(a*b==15) cout << "*" << endl;
    else cout << "x" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<ctype.h>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int main(){
    int a=read(),b=read(),c=read(); 
    printf("%d\n",(a-c)/(b+c));
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

typedef long long ll;

void parse(char *s1,char *s2){
	char s[64]; gets(s);
	int i;
	for(i=0;s[i]!='-';i++);
	s[i]='\0';
	strcpy(s1,s);
	strcpy(s2,s+i+1);
}

ll hash(const char *s){
	const ll P=1000000007;
	ll h=0;
	for(int i=0;s[i];i++) h=h*P+s[i];
	return h;
}

int main(){
	for(int m;scanf("%d ",&m),m;){
		ll h1[1000],h2[1000],H[2000];
		rep(i,m){
			char s1[17],s2[17];
			parse(s1,s2);
			H[2*i+0]=h1[i]=hash(s1);
			H[2*i+1]=h2[i]=hash(s2);
		}
		sort(H,H+2*m);
		int n=unique(H,H+2*m)-H;

		int u1[1000],u2[1000];
		bool G[200][200]={};
		rep(i,m){
			u1[i]=lower_bound(H,H+n,h1[i])-H;
			u2[i]=lower_bound(H,H+n,h2[i])-H;
			G[u1[i]][u2[i]]=true;
		}

		int d[200][200]; // 距離行列
		rep(u,n) rep(v,n) {
			bool ok=false;
			rep(w,n){
				if(G[u][w] && G[v][w]) ok=true;
				if(G[w][u] && G[w][v]) ok=true;
				if(G[u][w] && G[w][v]){ ok=false; break; }
				if(G[v][w] && G[w][u]){ ok=false; break; }
			}
			d[u][v]=(ok?0:INF);
		}
		rep(i,m) d[u1[i]][u2[i]]=1;

		rep(w,n) rep(u,n) rep(v,n) d[u][v]=min(d[u][v],d[u][w]+d[w][v]);

		int q; scanf("%d ",&q);
		printf("%d\n",n);
		while(q--){
			char s1[17],s2[17];
			parse(s1,s2);
			ll h1=hash(s1),h2=hash(s2);
			if(binary_search(H,H+n,h1) && binary_search(H,H+n,h2)){
				int u=lower_bound(H,H+n,h1)-H;
				int v=lower_bound(H,H+n,h2)-H;
				puts(d[u][v]<INF&&d[u][v]%2==1?"YES":"NO");
			}
			else puts("NO");
		}
	}

	return 0;
}

Measured memory_bytes: 1308
s = input()
res, ans = 0, 0

for i in s:
    if i in ['A', 'C', 'G', 'T']:
        res += 1   # 指定した文字列がどれだけ連続しているか
    else:
        ans = max(res, ans)
        res = 0    # 文字列の連続が途切れた場合、0にリセット

ans = max(res, ans)
print(ans)

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Collections;
import java.util.ArrayList;

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

    static class ID {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            long[] years = new long[m];
            HashMap<Long, Integer> map = new HashMap<>();
            int[] pre = new int[n + 1];
            HashMap<Integer, Long> imap = new HashMap<>();


            for (int i = 0; i < m; i++) {
                int p = Integer.parseInt(in.next());
                long year = Long.parseLong(in.next());
                years[i] = year;
                map.put(year, p);
                imap.put(i, year);
            }

            Arrays.sort(years);

            HashMap<Long, String> result = new HashMap<>();
            for (int i = 0; i < m; i++) {
                long year = years[i];
                int p = map.get(year);
                int num = pre[p] + 1;
                pre[p] = num;

                result.put(year, String.format("%06d%06d", p, num));
            }

            ArrayList<Integer> keys = new ArrayList<>(imap.keySet());
            Collections.sort(keys);

            for (Integer i : keys) {
                Long y = imap.get(i);
                out.println(result.get(y));
            }
        }

    }
}



Measured memory_bytes: 148844
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100;

int n,a[2*N+5];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
		scanf("%d",&a[i]);
	
	sort(a+1,a+2*n+1);
	int s=0;
	for(int i=1;i<=2*n;i+=2)
		s+=a[i];
	printf("%d\n",s);
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    int x;
    cin >> x;
    int max = a > b ? a : b;
    max = c > max ? c : max;
    int ans = 0;
    if (max == a) {
        ans += b + c;
    } else if (max == b) {
        ans += a + c;
    } else {
        ans += a + b;
    }
    for (int n = 0; n < x; n++) max *= 2;
    ans += max;

    cout << ans << endl;
}


Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

def solve():
    MOD = 998244353
    INF = float('inf')

    N = int(input())
    XDs = [tuple(map(int, input().split())) for _ in range(N)] + [(10**12, 0)]

    XDs.sort()
    Xs = [X for X, D in XDs]

    def max2(x, y): return x if x >= y else y
    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [-INF] * (numPow2+1)
        return data, numPow2
    def setInit(As):
        for iB, A in enumerate(As, 1):
            data[iB] = A
        for iB in range(1, numPow2):
            i = iB + (iB & -iB)
            data[i] = max2(data[i], data[iB])
    def setValue(iA, A):
        iB = iA + 1
        while iB <= numPow2:
            data[iB] = max2(data[iB], A)
            iB += iB & -iB
    def getMax(iA):
        iB = iA + 1
        ans = -INF
        while iB > 0:
            ans = max2(ans, data[iB])
            iB -= iB & -iB
        return ans

    data, numPow2 = makeBIT(N+1)
    setInit(list(range(N)))

    dp = [0] * (N+1)
    dp[-1] = 1
    for i in reversed(range(N)):
        X, D = XDs[i]
        j = bisect_left(Xs, X+D) - 1
        pos = getMax(j)
        setValue(i, pos)
        dp[i] = dp[pos+1] + dp[i+1]
        dp[i] %= MOD

    print(dp[0])


solve()


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

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    int sr, sc;
    cin >> sr >> sc;
    sr--;
    sc--;
    string s, t;
    cin >> s >> t;
    int r = sc;
    int u = sr;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') r++;
        if(s[i] == 'U') u--;
        if(r >= w){
            cout << "NO" << endl;
            return 0;
        }
        if(u < 0){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'L' && r > 0) r--;
        if(t[i] == 'D' && u < h - 1) u++;
    }
    r = sc;
    u = sr;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') r++;
        if(s[i] == 'D') u++;
        if(r >= w){
            cout << "NO" << endl;
            return 0;
        }
        if(u >= h){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'L' && r > 0) r--;
        if(t[i] == 'U' && u > 0) u--;
    }
    r = sc;
    u = sr;
    for(int i = 0; i < n; i++){
        if(s[i] == 'L') r--;
        if(s[i] == 'U') u--;
        if(r < 0){
            cout << "NO" << endl;
            return 0;
        }
        if(u < 0){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'R' && r < w - 1) r++;
        if(t[i] == 'D' && u < h - 1) u++;
    }
    r = sc;
    u = sr;
    for(int i = 0; i < n; i++){
        if(s[i] == 'L') r--;
        if(s[i] == 'D') u++;
        if(r < 0){
            cout << "NO" << endl;
            return 0;
        }
        if(u >= h){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'R' && r < w - 1) r++;
        if(t[i] == 'U' && u > 0) u--;
    }
    cout << "YES" << endl;
}

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	string s;
	cin>>s;
	char x=s[s.size()-1];
	if (x=='s') cout<<s+"es"<<endl;
	else cout<<s+"s"<<endl;
	return 0;
}

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

int main() {
    int n, k; cin >> n >> k;

    int h;
    int out = 0;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) out++;
    }
    
    cout << out << 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 repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;

 
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if(a >= k){
    ans = k;
  }
  else if(a + b >= k){
    ans = a;
  }
  else{
    ans = a - (k - (a + b));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

map<string,long long int> p;

int q[11]={1,2,4,8,16,32,64,128,256,512,1024};

long long  f(string s, int d){
	if(p[s]){return p[s];}
	
	long long res=stoll(s);

	if(d == 1){
		p[s] = stoll(s);
		return p[s];
	}

	for(int i=1; i<d; i++){
		res += (stoll(s.substr(0,i))*q[d-i-1]);
		res += f(s.substr(i),d-i);
	}

	p[s] = res;
	
	return res;
}

int main(){
	string s;
	cin >> s;

	cout << f(s,s.length()) << endl;
	return 0;
}

Measured memory_bytes: 256
def solve(x,a,ind):
#    print(x,a,ind)
    if "0" <= a[0][ind] <="9":
        return int(a[0][ind])

    if a[0][ind] =="+":
        i = j= 1
        su = 0
        while(i < x):
            if a[i][ind+1] == "+" or a[i][ind+1]=="*":
                j+=1
                while j < x and a[j][ind +1]==".":
                    j += 1
                su += solve(j-i,a[i:j],ind+1)
                i = j
                j = j
            else:
                su += int(a[j][ind+1])
                i += 1
                j += 1

#        print(x,a,ind,su)
        return su


    if a[0][ind] =="*":
        i = j= 1
        su = 1
        while(i < x):
            if a[i][ind+1] == "+" or a[i][ind+1]=="*":
                j+=1
                while j<x and a[j][ind +1]==".":
                    j += 1
                su *= solve(j-i,a[i:j],ind+1)
                i = j
                j = j
            else:
                su *= int(a[j][ind+1])
                i += 1
                j += 1
 #       print(x,a,ind,su)
        return su


while(1):
    n  = int(input())
    if n >0:
        a = [input() for i in range(n)]
        print(solve(n,a,0))
    else:
        break


Measured memory_bytes: 5616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}

int main()
{
   int n;
    while(cin>>n)
    {
        if(n < 1200)
            cout<<"ABC"<<endl;
        else if(n < 2800)
            cout<<"ARC"<<endl;
        else
            cout<<"AGC"<<endl;
    }
}
















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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int odd_count = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 2 == 1)
			odd_count++;
	}
	printf("%.10f\n", (double)odd_count / n);
	return 0;
}

Measured memory_bytes: 256
mod=1000000007
# from https://ikatakos.com/pot/programming_algorithm/contest_history/atcoder/2019/0106_educational_dp
from itertools import accumulate, starmap
from operator import sub

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[0]*(k+1)
dp[0]=1
for i in a:
    dp=list(accumulate(dp))
    dp[i+1:]=starmap(sub,zip(dp[i+1:],dp[:-i-1]))
    dp=[x%mod for x in dp]
print(dp[k])


Measured memory_bytes: 126864
n = int(input())
a = list(map(int, input().split()))
x = []

for i in range(n):
    if a[i] % 2 == 0:
        x.append(a[i])

for j in range(len(x)):
    if x[j] % 3 != 0 and x[j] % 5 != 0:
        print('DENIED')
        exit()

print('APPROVED')


Measured memory_bytes: 38384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
size = len(s)
cnt = size
flag = False
for i in range(size):
    if s[cnt - 1] == 'r':
        if cnt >= 7:
            if s[cnt - 7:cnt] == 'dreamer':
                cnt -= 7
            elif s[cnt - 6:cnt] == 'eraser':
                cnt -= 6
            else:
                flag = True
                break
        elif cnt >= 6:
            if s[cnt - 6:cnt] == 'eraser':
                cnt -= 6
            else:
                flag = True
                break
        else:
            flag = True
            break
    elif s[cnt - 1] == 'e' and cnt >= 5:
        if s[cnt - 5:cnt] == 'erase':
            cnt -= 5
        else:
            flag = True
            break
    elif s[cnt - 1] == 'm' and cnt >= 5:
        if s[cnt - 5:cnt] == 'dream':
            cnt -= 5
        else:
            flag = True
            break
    else:
        flag = True
        break
    if cnt == 0:
        break
    elif cnt < 0:
        flag = True
        break
if flag:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n){
		if(n==-1)break;
		string s;
		string temp;
		for(int i=0;n>>i;i+=2){
			temp+=(char)((n>>i)%4)+'0';
		}
		if(temp.empty())temp="0";
		for(int i=temp.size()-1;i>=0;--i)s+=temp[i];
		cout << s << "\n";
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main()
{
	unsigned short int n,i,min=0,max=0; 
	long int sum=0;
	cin>>n;
	int A[n];
	for(i=0;i<n;i++)
	cin>>A[i];
	for(i=0;i<n;i++)
	{
	if(A[i]>A[max]){max=i;}
	else if(A[i]<A[min]){min=i;}
	sum+=A[i];
	}
	cout<<A[min]<<" "<<A[max]<<" "<<sum<<endl;
}



Measured memory_bytes: 3108
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer>
inline _typer read() {
	_typer init = 0;
	char ch = getchar(), k = 0;
	for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
	for ( ; isdigit(ch); ch = getchar()) init = (init << 3) + (init << 1) + (ch ^ 48);
	return k ? -init : init;
}
const ll N = 100005, INF = 1e9;

int n;
int X[N], Y[N];
int fa[N << 1], totx[N << 1], toty[N << 1];

int mark[N << 1];
int Find(int x) {
	return x == fa[x] ? x : fa[x] = Find(fa[x]);
}
void Uni(int x, int y) {
	x = Find(x), y = Find(y);
	if (x == y) return ;
	fa[x] = y;
	totx[y] += totx[x], toty[y] += toty[x];
}

int main() {
	n = read<int>();
	int deita = 100000;
	rep (i, 1, deita << 1)
		fa[i] = i, totx[i] = (i <= deita), toty[i] = (i > deita);
	rep (i, 1, n) {
		X[i] = read<int>(), Y[i] = read<int>();
		Uni(X[i], Y[i] + deita);
		// cout << X[i] << " " << Y[i] + deita << endl;
	}
	ll Ans = 0;
	rep (i, 1, n) if (!mark[Find(X[i])])
		Ans += 1ll * totx[fa[X[i]]] * toty[fa[X[i]]], mark[fa[X[i]]] = true;
	cout << Ans - n << endl;
	return 0;
}



Measured memory_bytes: 3584
//abc121_c.cpp
//Mon Mar 18 19:29:01 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll n,m;
	cin >> n >> m;

	ll a[n],b[n];
	unordered_map<ll, ll> mp;
	for (int i=0;i<n;i++){
		cin >> a[i] >> b[i];
		auto itr = mp.find(a[i]);
		if (itr != mp.end()){
			mp[a[i]] = mp[a[i]]+b[i];
		}else {
			mp[a[i]] = b[i];
		}
	}

	sort(a,a+n);
	ll prev = -1;
	ll ans = 0;
	ll bought = 0;
	for (int i=0;i<n;i++){
		if (prev == a[i]){
			continue;
		}else {
			if (bought + mp[a[i]] >= m){
				ans = ans + (m-bought)*a[i];
				cout << ans << endl;
				return 0;
			}
			ans = ans + a[i]*mp[a[i]];
			bought = bought + mp[a[i]];
			prev = a[i];
		}
	}
}

Measured memory_bytes: 5924
N, X = map(int, input().split())
L = list(map(int, input().split()))

lenL = 0

for i in range(len(L)):
    lenL += L[i]
    i += 1

if lenL <= X:
    print(N+1)
else:
    j = 1
    sumL = L[0]

    while sumL <= X:
        sumL += L[j]
        j += 1
    print(j)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

lld norm(lld x, lld y, lld z)
{
    return sqrtl(x * x + y * y + z * z);
}

void solve()
{
    int n, q;
    cin >> n >> q;
    vector<vector<lld>> p(n, vector<lld>(3));
    vector<lld> r(n);
    vector<ll> cost(n);
    rep(i, n) cin >> p[i][0] >> p[i][1] >> p[i][2] >> r[i] >> cost[i];
    rep(i, q)
    {

        vector<lld> s(3), e(3);
        cin >> s[0] >> s[1] >> s[2] >> e[0] >> e[1] >> e[2];
        ll ans = 0;
        rep(j, n)
        {
            lld high = 1.0;
            lld low = 0.0;
            lld dist = IINF;
            lld dl, dh;
            while (high - low > 1e-10)
            {
                lld cl = (low * 2 + high) / 3.0;
                lld ch = (low + high * 2) / 3.0;
                lld x = s[0] * cl + e[0] * (1 - cl);
                lld y = s[1] * cl + e[1] * (1 - cl);
                lld z = s[2] * cl + e[2] * (1 - cl);
                dl = norm(p[j][0] - x, p[j][1] - y, p[j][2] - z);

                x = s[0] * ch + e[0] * (1 - ch);
                y = s[1] * ch + e[1] * (1 - ch);
                z = s[2] * ch + e[2] * (1 - ch);
                dh = norm(p[j][0] - x, p[j][1] - y, p[j][2] - z);
                if (dl < dh)
                {
                    high = ch;
                }
                else
                {
                    low = cl;
                }
            }
            if (dl < r[j] + 1e-9)
            {
                ans += cost[j];
            }
        }
        cout << ans << endl;
    }
}

int main()
{
    solve();
    return 0;
}


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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    // ll t;cin>>t;while(t--)
    {
        ll n;cin>>n;
        string  s;cin>>s;
        
        string temp1="",temp2="";
        
        if(n&1){
            cout<<"No\n";
            return 0;
        }
        
        for(ll i=0;i<n/2;i++)
        {
            temp1+=s[i];
        }
        for(ll i=n/2;i<n;i++)
        {
            temp2+=s[i];
        }
        
        if(temp1==temp2)
        {
            cout<<"Yes\n";
        }
        else
        {
            cout<<"No\n";
        }
        
    }
    
    
       
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
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; }
///////////////////////////////////////////////////////////////////////////////////
vi used(1000050,0);
void solve(){
    ll m,k;
    cin >> m >> k;
    vi bits;
    int dig=0;
    rp(i,31){
        if(k&(1<<i)) {
            bits.pb(1);
            dig=i+1;
        }
        else bits.pb(0);
    }
    if(m<dig){
        print(-1);
        return;
    }
    if(m==1&&k==0){
        print("0 0 1 1");
        return;
    }
    deque<ll> ans;
    ans.pb(k);
    if(__builtin_popcount(k)==1){
        if(k==1){
            if(m<=1){
                print(-1);
                return;
            }else{
                ans.pb(2);
                ans.pb(3);
                ans.push_front(2);
                ans.push_front(3);
                used[2]=used[3]=1;
            }
        }else{
            ans.pb(k+1);
            ans.pb(1);
            ans.push_front(k+1);
            ans.push_front(1);
            used[1]=used[k+1]=1;
        }
    }else{
        rp(i,31){
            if(bits[i]==1){
                ans.push_front(1ll<<i);
                ans.push_back(1ll<<i);
                used[1<<i]=1;
            }
        }
    }
    used[k]=1;
    rp(i,1ll<<m){
        if(used[i]==0){
            ans.push_front(i);
            ans.pb(i);
        }
    }
    ans.pb(k);
    for(auto an:ans){
        princ(an);
    }
    cout << endl;
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 9284
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll dist[103][103] , ans[103][103];
ll n , m ;
const ll inf = 3e18 ;
void flloyd()
{
    for(ll k=1;k<=n;++k){
        for(ll i = 1;i<=n;++i){
            for(ll j=1;j<=n;++j){
                ans[i][j] = min(ans[i][j] , ans[i][k] + ans[k][j]);
            }
        }
    }
}
int main()
{
   ios;
   cin >> n >> m;
   for(ll i =1 ;i<=100;++i){
    for(ll j =1;j<=100;++j){
        if(i==j) {
                dist[i][j] = 0 ;
                dist[j][i] =0 ;
                ans[i][j] = 0 ;
                ans[j][i] =  0 ;
        }
        else dist[i][j] = 3e18;
        dist[j][i] = dist[i][j];
        ans[i][j] = dist[i][j];
        ans[j][i] = ans[i][j];
    }
   }
   bool shortt[105][105] ;
   forn(i , 0 , 104 ) forn(j , 0 , 104) shortt[i][j] = false ;
   vll edges;
   forn(i , 1 , m ){
       ll x , y , d;
       cin >> x >> y >> d;
       dist[x][y] = d;
       dist[y][x] = d;
       ans[x][y] = d;
       ans[y][x] = d;
       edges.pb({x , y}) ;
   }
   flloyd();
   ll cnt = 0 ;
   forn(i , 1 , n){
     forn(j , i+1 , n ){
       if(dist[i][j] == inf ) con;
       else if(dist[i][j] != ans[i][j]) ++cnt;
     }
   }
   cout << cnt << el ;
   ro;
}


Measured memory_bytes: 512
from itertools import permutations, product
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, R = map(int, input().split())
r = [int(x) for x in input().split()]
abc = [[int(x) for x in input().split()] for _ in range(M)]

dist = [[float('inf') for _ in range(N)] for _ in range(N)]
A, B, C = [0] * M, [0] * M, [0] * M
for i in range(M):
    a, b, c = abc[i]
    A[i] = a - 1
    B[i] = b - 1
    C[i] = c

g = csr_matrix((C, (A, B)), shape=(N, N), dtype=int)
dist = floyd_warshall(g, directed=False)

ans = float('inf')
for route in permutations(r):
    d = 0
    for i in range(R - 1):
        s = route[i] - 1
        g = route[i + 1] - 1
        d += int(dist[s][g])
    ans = min(ans, d)
print(ans)

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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

int a[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k, i;
	cin>>n>>k;
	char ch;
	for(i=1; i<=n; i++){
		cin>>ch;
		a[i] = (ch == 'R');
	}
	a[0] = -1; a[n+1] = -1;
	int init = 0, ans;
	for(i=1; i<=n; i++){
		if(a[i] == 0 && a[i-1] == 0) init++;
		if(a[i] == 1 && a[i+1] == 1) init++;
	}
	ans = min(n-1, init + 2*k);
	cout<<ans;
	return 0;
}

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

int main() {
    int x,y,fl=0;
    cin>>x>>y;
    rep(i,x+1)rep(j,x+1){
        if(i+j==x and 2*i+4*j == y)fl = 1;
    }
    cout << (fl? "Yes":"No") << endl;
}

Measured memory_bytes: 3632
K, N = map(int,input().split())
An = list(map(int, input().split()))
maxi = 0
for i in range(N):
    if i == N-1:
        i = -1
        if K + (An[i + 1] - An[i]) > maxi:
            maxi = K + (An[i + 1] - An[i])
            break
    if An[i+1] - An[i] > maxi:
        maxi = An[i+1] - An[i]
print(K - maxi)

Measured memory_bytes: 25836
N, K, C = gets.split.map(&:to_i)
S = gets.strip.chars.map { |char| char == 'o' ? 0 : nil }

# Justify the numbers to the right
dates_from_left = S
# Justify the numbers to the left
dates_from_right = S.reverse
ans = []

i = 0
plan = 1
while i < N
  break if plan > K
  if dates_from_left[i] == 0
    dates_from_left[i] = plan
    plan += 1
    i += C + 1
  else
    i += 1
  end
end

i = 0
plan = K
while  i < N
  break if plan < 1
  if dates_from_right[i] == 0
    dates_from_right[i] = plan
    plan -= 1
    i += C + 1
  else
    i += 1
  end
end

dates_from_left.each_with_index do |date, i|
  unless date.nil? || date == 0
    ans << i + 1 if date == dates_from_right[- (i + 1)] 
  end
end
if ans.nil?
  puts "\n"
else
  ans.each do |a|
    puts a
  end
end

Measured memory_bytes: 24828
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int N = 1e6 + 10;

char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  std::reverse(s, s + n);
  std::vector<int> f(n), g(n);
  for (int i = 0; i < n; ++i) {
    int o = s[i] - '0';
    if (i == 0) f[i] = o, g[i] = 11 - o;
    else {
      f[i] = std::min(f[i - 1], g[i - 1]) + o;
      g[i] = std::min(f[i - 1] + 11 - o, g[i - 1] + 9 - o);
    }
  }
  printf("%d\n", std::min(f.back(), g.back()));
  return 0;
}


Measured memory_bytes: 9088
A, B = map(int, input().split(' '))

# 1. YONTEM:
import math
asil1_1 = (100*(A))/8
asil1_2 = (100*(A+1))/8
asil2_1 = 10*(B)
asil2_2 = 10*(B+1)
sonuc_1 = max(asil1_1, asil2_1)
sonuc_2 = min(asil2_2, asil1_2)
if math.ceil(sonuc_1)>=sonuc_2:
    print(-1)
else:
    print(math.ceil(sonuc_1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	string a, b;
	cin >> a >> b;
	cout << (a[0] == b[2] && a[1] == b[1] && a[2] == b[0] ? "YES" : "NO") << endl;
	return 0;
}
 

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    string s;
    cin >> s;

    int win = 0;
    rep(i, s.size()){
        if(s[i] == 'o'){
            ++win;
        }
    }

    if(win + 15 - (int)s.size() >= 8){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
#define int long long
map<char, int>m;
signed main() {
	string s; cin >> s;
	for (char c = 'a'; c <= 'z'; c++)m[c] = 0;
	for (int i = 0; i < s.size(); i++)m[s[i]]++;
	int ans = 1, n = s.size();
	for (char c = 'a'; c <= 'z'; c++) {
		n -= m[c];
		ans += n * m[c];
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30;

ll cnt[N];
int main () {
    ios::sync_with_stdio(0), cin.tie(0);
	ll n;
	cin >> n;
	for (int i = 2; i <= n; i ++) {
		ll x;
		cin >> x;
		cnt[x] ++;
	}
	for (int i = 1; i <= n;i  ++)
		cout << cnt[i] << '\n';
    return (0);
}

Measured memory_bytes: 5180
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

template<typename T>
T max(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())maxi(ret, v[i]);
	return ret;
}

template<typename T>
T min(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())mini(ret, v[i]);
	return ret;
}

signed main() {
	makei(n);
	makev(a, n);
	Rep(1, n + 1) {
		sort(a.begin(), a.begin() + i);
		say(a);
	}
}


Measured memory_bytes: 3048
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int a, b, c, k;
		cin >> a >> b >> c >> k;
		if(cin.fail()) break;

		int need=0;
		for(;b<=a;need++) b*=2;
		for(;c<=b;need++) c*=2;

		bool ans=(need<=k);
		cout << (ans?"Yes":"No") << "\n";
	}
	return 0;
}


Measured memory_bytes: 3644