akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {
  int n;
  scanf("%i", &n);
  
  char s[n+1];
  scanf("%s", s);
  
  int neg = 0, open = 0;
  for (int i = 0; i < n; i++) {
    open += (s[i] == ')') ? -1 : 1;
    if (open < 0) {
      neg++;
      open = 0;
    } 
  }
  
  char sol[5*n];
  int m = 0;

  while (neg--) {
    sol[m++] = '(';
  }
  for (int i = 0; i < n; i++) {
    sol[m++] = s[i];
  }
  while (open--) {
    sol[m++] = ')';
  }
  sol[m++] = '\0';
  
  puts(sol);
  
  return 0;
}

Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
greatest = 0
m = 0
g = N

while g > 0:
  for i in range(N):
    if a[i]>greatest:
      greatest = a[i]
      m = i
  Alice += greatest
  a[m] = 0
  greatest = 0

  for i in range(N):
    if a[i]>greatest:
      greatest = a[i]
      m = i
  Bob += greatest
  a[m] = 0
  greatest = 0
  g = g - 2

print(Alice - Bob)


Measured memory_bytes: 3064
///****In the name of ALLAH, most Gracious, most Compassionate****//

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

template < class T1,class T2>
ostream &operator <<(ostream &os,const pair < T1,T2 > &p)
{
    os<<"{"<<p.first<<","<<p.second<<"}";
    return os;
}

const int N=3e5+5;
const int oo=1e9+7;

int32_t main()
{
    FastIO;
    int n,x,nn;
    cin>>n>>x;
    nn=n*2-1;
    if(x==1 or x==nn)
    {
        cout<<"No\n";
    }
    else
    {
        cout<<"Yes\n";
        list<int > lst;
        list<int > ans;
        ans.push_back(x);
        ans.push_back(x+1);
        ans.push_front(x-1);
        for(int i=1;i<=nn;i++)
        {
            if(abs(x-i)<=1) continue;
            lst.push_back(i);
        }
        while(!lst.empty())
        {
            ans.push_back(lst.front());
            ans.push_front(lst.back());
            lst.pop_back();
            lst.pop_front();
        }
        for(int i: ans)
            cout<<i<<"\n";
    }
}


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

using pp=pair<int,int>;

int main() {
  string S, T;
  cin >> S >> T;
  S+=S;
  string ans = "No";
  int C=0;
  for (int i=0; i<T.size(); i++) {
    C=0;
    for (int j=0; j<T.size(); j++) {
      if (S[i+j]!=T[j]) {
        C=1;
        break;
      }
    }
    if (C==0) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 5e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

struct BITree {
	int t[N];
	int Lowbit(int x) {
		return x & -x;
	}
	void Add(int x, int det) {
		if (x < 0)
			while (1)
				;
		for (; x < N; x += Lowbit(x))
			t[x] += det;
	}
	int Query(int x) {
		if (x < 0)
			while (1)
				;
		int ret = 0;
		for (; x; x -= Lowbit(x))
			ret += t[x];
		return ret;
	}
};
BITree bt;

struct Query {
	int l, r, id, ans;
};
Query qry[N];
vector<int> pos[N];

int main() {
	ios::sync_with_stdio(0);

	int n, q;
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		int c;
		cin >> c;
		pos[c].push_back(i);
	}
	for (int i = 1; i <= q; i++) {
		int l, r;
		cin >> l >> r;
		qry[i] = (Query){l, r, i, 0};
	}
	sort(qry + 1, qry + q + 1, [](Query a, Query b) {
		return a.r < b.r;
	});

	static vector<tint> pts;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < pos[i].size(); j++) {
			pts.push_back(make_tuple(pos[i][j], pos[i][j], 1));
			if (j > 0)
				pts.push_back(make_tuple(pos[i][j - 1], pos[i][j], -1));
		}
	}
	sort(all(pts), [](tint a, tint b) {
		return get<1>(a) < get<1>(b);
	});

	auto p = pts.begin();
	for (int i = 1; i <= q; i++) {
		int l = qry[i].l, r = qry[i].r;
		while (p != pts.end() && get<1>(*p) <= r) {
			bt.Add(get<0>(*p), get<2>(*p));
			p++;
		}
		qry[i].ans = bt.Query(n) - bt.Query(l - 1);
	}
	sort(qry + 1, qry + q + 1, [](Query a, Query b) {
		return a.id < b.id;
	});

	for (int i = 1; i <= q; i++)
		cout << qry[i].ans << endl;

	return 0;
}


Measured memory_bytes: 46936
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i = 0;i < N;i++) cin >> L.at(i);
  
  sort(L.begin(), L.end());
  
  int sum = 0;
  for(int i = 0;i < N - 1;i++) sum += L.at(i);
  
  if(L.at(N-1) < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main(void) {
	int k;
	cin >> k;
	if (k / 100 == 0 || k / 100 > 12) {
		if (k % 100 == 0 || k % 100 > 12)
			printf("NA\n");
		else
			printf("YYMM\n");
	}
	else {
		if (k % 100 == 0 || k % 100 > 12)
			printf("MMYY\n");
		else
			printf("AMBIGUOUS\n");
	}
	return 0;
}

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

int main() {
  int A,B,C,X,Y,Z;
  int ans=1e9;
  cin >> A >> B >> C >> X >> Y;
  rep(i, 100001) {
    int sum = 0;
    sum += i*2*C;
    sum += max(0, X-i) * A;
    sum += max(0, Y-i) * B;
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  string s,t;
  cin >> s >> t;
  string ans="No";
  rep(i,s.size()){
    string u=s.substr(0,s.size()-1);
    char c=s.at(s.size()-1);
    s=c+u;
    if(s==t){
      ans="Yes";
    }
  }
  cout << ans;
}

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

typedef unsigned long  long ull;
typedef unsigned int ui;

int main() {
  ull N, M, K;
  cin >> N >> M >> K;
  vector<ull> a(N);
  vector<ull> b(M);
  vector<ull> A(N+1);
  vector<ull> B(M+1);
  A[0] = 0;
  B[0] = 0;
  for(ull i = 0; i < N; i++) {
    cin >> a[i];
    A[i+1] = a[i] + A[i];
  }
  for(ull i = 0; i < M; i++) {
    cin >> b[i];
    B[i+1] = b[i] + B[i];
  }

  ull ans = 0;
  ull j = M;
  for(ull i = 0; i <= N; i++) {
    if(A[i] > K) break;
    while(B[j] > K - A[i]) {
      j--;
    }
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9584
#include <iostream>

using namespace std;

int main() {
  int N, c[200000] = {}, count = 0, rcount = 0;
  char s;
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> s;
    if (s == 'R'){
      c[i] = 1;
      count++;
    }
  }
  for (int i = 0; i < count; i++){
    rcount += c[i];
  }
  cout << count - rcount << endl;
  return 0;
}

Measured memory_bytes: 4372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a - b < c)
	{
		cout << c - (a - b) << endl;
	}
	else
	{
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    long long a,b,x; cin>>a>>b>>x;
    long long ans=0;
    long long ai;
    long long bi;
    if(a-1==-1){ ai=0; }else{ ai=(a-1)/x+1; }
    if(b==-1){ bi=0; }else{ bi=(b/x+1); }
    ans=bi-ai;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    multimap< double,set<string> > list;
    for(int i=0; i<n; i++){
      string name;
      int p,a,b,c,d,e,f,s,m;
      cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int num = f + f * (m-1);
      int time = a + b + c + (d + e) * m;
      double value = (num * s - p) / (double)time;
      multimap< double,set<string> >::iterator it = list.find(value);
      if(it != list.end()){
        (*it).second.insert(name);
      }else{
        set<string> s;
        s.insert(name);
        list.insert(make_pair< double,set<string> >(value,s));
      }
    }
    multimap< double,set<string> >::reverse_iterator rit = list.rbegin();
    while(rit != list.rend()){
      for(set<string>::iterator it = (*rit).second.begin(); it != (*rit).second.end(); it++){
        cout << (*it) << endl;
      }
      rit++;
    }
    cout << "#" << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
/*
  AOJ 1082
  Title:11224111122411
  @kankichi573
  2014/2/18 TLE
*/
#include <stdio.h>
#include <string.h>
#define min(x,y) (((x)<(y))?(x):(y))
#define LIMIT 100000

char input[100001];
long long memo[2][LIMIT];


int calc_max(int n)
{
  if(n==8 || n==0)
    return(3);
  else
    return(5);
}
unsigned long long bunkatu(int n,int max_val)
{
  unsigned long long ret;
  int i;
  
  if(n<LIMIT)
    if(max_val==5)
      {
      if(ret=memo[0][n])
	return(ret);
      }
    else
      {
        if(ret=memo[1][n])
	  return(ret);
      }
  
  if(n==1)
    ret=1;
  else if(n==2)
    ret=2;
  else
    {
      ret=1; //no divide
      for(i=1;i<=min(max_val,n-1);i++)
	{
	  ret += bunkatu(n-i,max_val);
	  ret %= 100000007;
	}
    }
  
  if(max_val==5)
    memo[0][n]=ret;
  else
    memo[1][n]=ret;
  
  return(ret);
}

int main()
{
  int i;
  unsigned long long res;
  char prev;
  int  cnt;
  int  len;

    
  (void)bunkatu(100000,5);
  (void)bunkatu(100000,3);

  while(scanf("%s",input) && input[0]!='#')
    {
      res=1;
      cnt=1;
      prev='\0';
      len=strlen(input);
      for(i=0;i<=len;i++)
	{
	  if(prev == input[i])
	    {
	      cnt++;
	    }
	  else
	    {
	      res *= bunkatu(cnt,calc_max(input[i-1]-'0'));
	      res %= 100000007;
	      cnt = 1;
	    }
	  prev=input[i];
	}
      printf("%llu\n",res);
    }
  
  return(0);
}

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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MAX_N = 700;
int n,m;
bool g[MAX_N][MAX_N];
int col[MAX_N] = {};
int comp_col[MAX_N][2];
bool dp[2][MAX_N+1];

namespace union_find {
  int parent[MAX_N];
  int rank[MAX_N];
  void init()
  {
    for (int i = 0; i < n; i++) {
      parent[i] = i;
      rank[i] = 0;
    }
  }

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

  void merge(int a, int b)
  {
    a = find(a);
    b = find(b);

    if (a == b) return;
    if (rank[a] < rank[b]) {
      parent[a] = b;
    } else {
      parent[b] = a;
      if (rank[a] == rank[b])
        rank[a]++;
    }
  }
}

bool dfs(int v, int p, int c)
{
  if (col[v] == c) return true;
  col[v] = c;

  for (int i = 0; i < n; i++) {
    if (i == v || i == p || !g[v][i]) continue;
    if (col[i] == c || !dfs(i, v, 3-c)) return false;
  }

  return true;
}

int main()
{
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    g[u-1][v-1] = true;
    g[v-1][u-1] = true;
  }

  // 補グラフの構築と連結成分分解
  union_find::init();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      g[i][j] = !g[i][j];
      if (g[i][j]) union_find::merge(i,j);
    }
  }

  // 二部グラフかチェック
  for (int i = 0; i < n; i++) {
    if (col[i] == 0) {
      if (!dfs(i, -1, 1)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    comp_col[i][0] = comp_col[i][1] = 0;
  }

  for (int i = 0; i < n; i++) {
    comp_col[union_find::find(i)][col[i]-1]++;
  }

  // 圧縮
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (comp_col[i][0] + comp_col[i][1] > 0) {
      comp_col[k][0] = comp_col[i][0];
      comp_col[k][1] = comp_col[i][1];
      k++;
    }
  }

  fill_n(dp[0], n+1, false);
  dp[0][0] = true;
  for (int i = 0; i < k; i++) {
    fill_n(dp[1], n+1, false);
    for (int j = 0; j <= n; j++) {
      if (dp[0][j]) {
        if (j+comp_col[i][0] <= n)
          dp[1][j+comp_col[i][0]] = true;
        if (j+comp_col[i][1] <= n)
          dp[1][j+comp_col[i][1]] = true;
      }
    }
    copy_n(dp[1], n+1, dp[0]);
  }

  int m = INT_MAX;
  for (int i = 0; i <= n; i++) {
    if (dp[0][i]) {
      m = min(m, i*(i-1)/2 + (n-i)*(n-i-1)/2);
    }
  }

  cout << m << endl;

  return 0;
}


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

int main() {
  int a, b, c, ans = 1;
  cin >> a >> b >> c;
  if (a == b) {
    if (b != c) ans = 2;
  } else {
    ans = 2;
    if (a != c && b != c) ans = 3;
  }
    
  cout << ans << endl;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    int a[n];rep(i,0,n)cin>>a[i];
    int c=0;
    rep(i,0,n-1){
        if(a[i]>=a[i+1]){
            c=1;
            break;
        }
    }
    if(c==0){
        cout<<1<<endl;
        return 0;
    }
    int u=n,d=1;
    while(u-d>1){
        int mid=(u+d)/2;
        unordered_map<int,int> mp;
        deque<int> dq;
        int cc=0;
        rep(i,1,n){
            if(a[i]>a[i-1]){
                continue;
            }
            else{
                for(;;){
                    if(dq.size()==0)break;
                    if(dq.back()>a[i]){
                        mp[dq.back()]=0;
                        dq.pop_back();
                    }
                    else break;
                }
                dq.push_back(a[i]);
                ll now=a[i];
                mp[now]++;
                while(now>0&&mp[now]==mid){
                    mp[now]=0;
                    now--;
                    mp[now]++;
                }
                if(now==0){
                    cc=1;
                    break;
                }
            }
        }
        if(cc==1)d=mid;
        else u=mid;
    }
    cout<<u<<endl;
}


Measured memory_bytes: 8948
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

ll dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll h,w,k;
  std::cin>>h>>w>>k;

  std::vector<std::string> a(h);
  rep(i,0,h)std::cin>>a[i];

  P s;
  rep(i,0,h){
    rep(j,0,w){
      if(a[i][j]=='S'){
        s={i,j};
      }
    }
  }

  ll ans=MOD;

  std::queue<P> que;

  std::vector<std::vector<ll>> d(h,std::vector<ll>(w,-1));

  que.push(s);
  d[s.first][s.second]=0;

  while(!que.empty()){
    P e=que.front();que.pop();
    if(d[e.first][e.second]>k)break;

    chmin(ans,(std::min(std::min(e.first,h-1-e.first),std::min(e.second,w-1-e.second))+k-1)/k+1);

    rep(i,0,4){
      P next={e.first+dx[i],e.second+dy[i]};
      if(0<=next.first&&next.first<=h-1&&0<=next.second&&next.second<=w-1&&a[next.first][next.second]=='.'&&d[next.first][next.second]==-1){
        que.push(next);
        d[next.first][next.second]=d[e.first][e.second]+1;
      }
    }
  }

  std::cout<<ans;

  return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int gcd(int a, int b)
{
	if (b == 0)	return a;
	return gcd(b, a % b);
}
int main()
{
	string n;
	cin >> n;
	if (n[0] == '7' || n[1] == '7' || n[2] == '7')
		cout << "Yes" << endl;
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int N,M,K,L,A[200005],B[200005];
string str,str2;
//素数判定　素数ならそのまま返す　合成数なら０を返す。
int sosu(long long int n) {
	for (long long int i = 2; i <= n-1; i++) {
		if (n%i == 0) { return 0; }
	}
	return n;
}

int main() {
	
	cout << fixed << setprecision(18);
	cin>>N;
	for(long long int i=N;i==i;i++){
		if(sosu(i)==i){cout<<i<<endl;return 0;}
	}
} 


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<pair<int64_t, int>> DT(N);
  rep(i, N) { cin >> DT[i].second >> DT[i].first; }
  sort(DT.begin(), DT.end(), [](const auto& lhs, const auto& rhs) {
    if (lhs.first == rhs.first)
      return lhs.second < rhs.second;
    else
      return lhs.first > rhs.first;
  });

  int64_t tmp_ans0 = 0;
  unordered_map<int, int> hist;
  for (int i = K - 1; i >= 0; --i) {
    tmp_ans0 += DT[i].first;
    hist[DT[i].second]++;
  }
  int64_t neta = hist.size();
  tmp_ans0 += neta * neta;

  vector<int64_t> sub_taste;
  for (int i = K - 1; i >= 0; --i) {
    if (hist[DT[i].second] >= 2) {
      sub_taste.emplace_back(DT[i].first);
    }
    hist[DT[i].second]--;
  }

  vector<int64_t> add_taste;
  for (int i = K; i < N; ++i) {
    if (hist.count(DT[i].second)) continue;
    add_taste.emplace_back(DT[i].first);
    hist[DT[i].second]++;
  }

  int64_t answer = tmp_ans0;
  int loop = min(sub_taste.size(), add_taste.size());
  rep(i, loop) {
    // add
    int j = i + neta;
    int64_t add = (int64_t)((j + 1) * (j + 1)) - (int64_t)(j * j);
    // sub
    int64_t sub = sub_taste[i] - add_taste[i];
    tmp_ans0 += add - sub;
    answer = max(answer, tmp_ans0);
  }
  cout << answer << endl;
  return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int H,W,K;
    Scd3(H,W,K);

    W--;
    K--;
    ll dp[900][9];
    dp[0][0] = 1;
    ll MOD = 1000000007;

    Rep(hi,H*W){
        Rep(wi,W+1){
            int from = hi%W;
            int to = wi;
            int jump = from+1 == W ? 1 : 2;
            if( from == to ){
                to++;
            }else
            if( from+1 == to){
                to--;
            }
            dp[hi+1][wi] += dp[hi][wi];
            dp[hi+1][wi] %= MOD;
            dp[hi+jump][wi] += dp[hi][to];
            dp[hi+jump][to] %= MOD;
        }
    }

    printf ("%llu\n", (dp[H*W][K] + dp[H*W+1][K]) % MOD );

    return 0;
}



Measured memory_bytes: 384
import sys
input = sys.stdin.readline

# C - Skill Up
n, m, x = map(int, input().split())
books = []

for i in range(n):
	ca = list(map(int, input().split()))
	books.append(ca)

ans = sys.maxsize

for i in range(1, pow(2, n)):
	s = format(i, 'b')
	bin_str = s.zfill(n)
	
	skills = [0] * m
	price = 0
	
	for j in range(n):
		if bin_str[j] == '1':
			price += books[j][0]
			
			for k in range(1, m + 1):
				skills[k-1] += books[j][k]			
				
	if min(skills) >= x:
		ans = min(ans, price)

if ans == sys.maxsize:
	print(-1)
else:
	print(ans)

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

int main() {
  int N, j, A;
  cin >> N >> A;
  j = 0;
  
  while (A % 2 == 0) {
    A = A / 2;
    j++;
  }
  
  for (int i = 0; i < N-1; i++) {
    int A, k;
    cin >> A;
    k = 0;
    
    while (A % 2 == 0) {
      A = A / 2;
      k++;
    }
    
    if (j > k) {
      j = k;
    }
  }
  cout << j << endl;
}


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

int main()
{
  int n;
  cin>>n;
  int cnt=0,f=0;
  for(int i=0;i<n;i++){
	  
	  int x,y;
	  cin>>x>>y;
	  if(x==y){
		  cnt++;
	  }
	  else{
		  cnt=0;
	  }
	  if(cnt>=3){
		  f=1;
	  }
  }
  if(f){
	  cout<<"Yes\n";
  }
  else{
	  cout<<"No\n";
  }
}
		



Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#define nMAX 50000
#define mMAX 20
using namespace std;

int n, m, dp[nMAX+1][mMAX+1], c[mMAX+1];

void solve(){
  // コインをsort
  sort(c, c + m);
  // init
  for ( int i = 1; i <= m; i++){ dp[0][i] = 0; }
  for ( int k = 0; k <= n; k++){ dp[k][1] = k; }

  for ( int i = 2; i <= m; i++){
    for ( int k = 1; k <= n; k++){
      if ( k >= c[i]){
        dp[k][i] = min ( dp[k - c[i]][i] + 1, dp[k][i-1]);
      } else { dp[k][i] = dp[k][i-1];}
    }
  }

}

int main(){
  cin >> n >> m;
  for ( int i = 1; i <= m; i++){
    cin >> c[i];
  }

  solve();

  cout << dp[n][m] << endl;

  return 0;
}


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

int main() {
  int n;
  int a, b, c, d;
  int sum=0;
  int max=9;
  int count;
  while (1) {
    cin >> n;
    if (cin.eof()) break;
    count = 0;
    for (a=0; a<10; a++) {
      if (a > n) break;
      for (b=0; b<10; b++) {
        sum=a+b;
        if (sum > n) break;
        if (n-sum > 2*max) continue;
        for (c=0; c<10; c++) {
          sum = a+b+c;
          if (sum > n) break;
          if (n-sum > max) continue;
          count++;
        }
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
#define inI(x) scanf("%d",&x)
#define inI2(x,y) scanf("%d %d",&x,&y)
#define inI3(x,y,z) scanf("%d %d %d",&x,&y,&z)
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
int h,n,a,b;
LL dp[20005],ans=imx;
int main()
{
    for(int i=0;i<20005;i++)dp[i]=imx;
    dp[0]=0;
    scanf("%d %d",&h,&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d %d",&a,&b);
        for(int j=0;j<20005;j++)
        {
            if(j+a<20005)
            {
                if(dp[j+a]>dp[j]+b)
                {
                    dp[j+a]=dp[j]+b;
                    if(j+a>=h)ans=min(ans,dp[j+a]);
                }
            }
        }
    }
    printf("%lld",ans);
}


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

int main() {
  int H, W;
  cin >> H >> W ;
  vector<string> picture(H);
  for(int i=0; i<H; i++){
    cin >> picture.at(i);
  }
  for(int i=0; i<W+2; i++){
    cout<<"#";
  }
  cout<<endl;
  
  for(int i=0; i<H; i++){
    cout<<"#"<<picture.at(i)<<"#"<<endl;
  }
  
  for(int i=0; i<W+2; i++){
    cout<<"#";
  }
  cout<<endl;
  
}

Measured memory_bytes: 3616
N = int(input())

ans = 100000
for i in range(0,N+1,1):#i円6で払うj円9で払う
    j = N - i

    icount = 0
    while i!=0:
        icount += (i%6)
        i=i//6

    jcount = 0
    while j!=0:
        jcount += (j%9)
        j=j//9

    ans = min(icount+jcount,ans)

print(ans)

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n+1);
  REP(i,n){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  
  long double ans = 1;
  REP(i,n){
    ans *= a[i];
    if(ans>1000000000000000000){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (ll)ans << endl;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;

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

    vector<long long>a(s+1,0);
    a.at(0) = 1;
    for(int i=3; i<s+1; i++){
        a.at(i) = (a.at(i-1) + a.at(i-3))%mod;
    }
    cout << a.at(s)<<endl;
}

Measured memory_bytes: 3544
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
int k[102];
string s;
char prev(char c, int m) {
    rep(i, m) {
        if (c == 'a')
            c = 'Z';
        else if (c == 'A')
            c = 'z';
        else
            c--;
    }
    return c;
}
void solve() {
    int idx = 0;
    string ans;
    rep(i, s.size()) {
        char c = prev(s[i], k[idx]);
        ans += c;
        idx++;
        idx %= n;
    }
    cout << ans << endl;
}
int main() {
    while (cin >> n, n) {
        rep(i, n) cin >> k[i];
        cin >> s;
        solve();
    }
    return 0;
}

Measured memory_bytes: 3180
from bisect import bisect_right
from collections import defaultdict
import sys
read = sys.stdin.readline

s = read()[:-1]
t = read()[:-1]
# 即時終了
if set(t) - set(s):
    print(-1)
    exit()

# 前処理
# 0based indexにおいてi文字目以降に文字cが出てくるidxを取得する

# 前処理の前処理、0文字目から見たときにその文字が何文字目にあるかを記録しておく
mojiidx = defaultdict(lambda: [])
for i, ss in enumerate(s + s):
    mojiidx[ss].append(i)

# i文字目において、次に文字cが出てくるのは何文字あと？
skiptable = []
for i in range(0, len(s)):
    tmp = {}
    for c, ls in mojiidx.items():
        tmp[c] = ls[bisect_right(ls, i)] - i
    skiptable.append(tmp)

# print(skiptable)

# 本処理
# 最初にうまく飛べる点を探索
for i, ss in enumerate(s):
    if ss == t[0]:
        now = i
        break

for tt in t[1:]:
    idx = now % len(s)
    now += skiptable[idx][tt]
print(now + 1)

Measured memory_bytes: 377504
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define newl "\n"
#define out(x) cout << (x) << newl
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << newl
template <class T>
using VV = vector<vector<T>>;
#define Uni(v) (v).erase(unique((v).begin(), (v).end()), (v).end());

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}

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

#pragma endregion

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  vector<vector<vector<ll>>> X(N);
  rep(i, N) {
    ll A;
    cin >> A;
    rep(j, A) {
      ll x, y;
      cin >> x >> y;
      --x;
      vector<ll> tmp = {x, y};
      X[i].pb(tmp);
    }
  }

  ll ans = 0;
  for (ll i = 0; i < (ll)pow(2, N); ++i) {
    vector<ll> p(N);
    rep(j, N) p[j] = i >> j & 1;
    ll num = 0;
    rep(j, N) if (p[j] == 1)++ num;

    bool pos = true;
    rep(j, N) {
      if (p[j] == 0) {
        continue;
      } else {
        rep(k, X[j].size()) {
          if (p[X[j][k][0]] != X[j][k][1]) {
            pos = false;
            break;
          }
        }
      }
    }
    if (pos == true) ans = max(ans, num);
  }
  out(ans);
  return 0;
}

Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n = in();
    int s = in();
    if (n == 0 && s == 0) break;
    auto dp = vectors(n + 1, s + 1, 0LL);
    dp[0][0] = 1;
    for (int k = 0; k <= 100; k++) {
      for (int i = n; i > 0; i--) {
        for (int j = 0; j <= s; j++) {
          if (j - k >= 0) dp[i][j] += dp[i - 1][j - k];
        }
      }
    }
    cout << dp[n][s] << endl;
  }
}



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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int a,b;
  cin>>a>>b;
  cout<<a*b<<endl;

}

Measured memory_bytes: 3600
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();
            final String sl[] = s.split(" ");

            int a = Integer.parseInt(sl[0]);
            int b = Integer.parseInt(sl[1]);

            System.out.println(a * b % 2 == 0 ? "Even" : "Odd");
        }
    }
}


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

using namespace std;

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

    for (int i = A; i <= B; ++i) {
        if (i < A + K || B - K < i) {
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<map>
using namespace std;

int N, M;
int L,R;
int ans;

int main() {
	int LMAX = 0, RMIN = 100010;

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		LMAX = max(L, LMAX);
		RMIN = min(R, RMIN);
	}
	if (RMIN == LMAX) {
		ans = 1;
	}
	else {
		ans = RMIN - LMAX + 1;
	}
	if (ans < 0) {
		ans = 0;
	}
	cout << ans << endl;

	return 0;
}

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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n,m;
V<V<int>> v;

int main(){
    INIT;
    cin >> n >> m;
    v.resize(m);
    REP(i,m) {
        int p,y; cin >> p >> y;
        v[i] = (initializer_list<int>{p,y,i,0});
    }

    std::sort(ALL(v), [](V<int>& a, V<int>& b){
        return a[0] < b[0] || (a[0] == b[0] && a[1] < b[1]);
    });

    REP(i,m) {
        v[i][3] = 1;
        int j = i+1;
        for(;j < m && v[i][0] == v[j][0]; j++) {
            v[j][3] = v[j-1][3] + 1;
        }
        i = j-1;
    }

    std::sort(ALL(v), [](V<int>& a, V<int>& b) {
        return a[2] < b[2];
    });

    REP(i,m) {
        printf("%06d%06d\n", v[i][0], v[i][3]);
    }
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  ll N;
  int K;
  std::cin >> N >> K;

  int d = 0;
  while(N > 0) {
    N /= K;
    ++d;
  }

  std::cout << d << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string A = "Three";
  
  for(int i=0; i<N; i++){

  string  x;
    
  cin >> x;

if (x == "Y"){
 A ="Four";
 break;
 }

  }
  cout << A << endl;
 return 0;

}

Measured memory_bytes: 3560
N, M = map(int, input().split())
b_cnt = 2 ** N #箱の数は最大12個
INF = 10 ** 9
dp = [INF] * b_cnt
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    c = sum([2 ** (int(x)-1) for x in list(input().split())])
    for j in range(b_cnt):
        if dp[j|c] > dp[j] + a:
            dp[j|c] = dp[j] + a

if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])


Measured memory_bytes: 3188
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			System.out.println(Integer.toOctalString(n).replace('7','9').replace('6','8').replace('5','7').replace('4','5'));
		}
	}
}

Measured memory_bytes: 51640
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [None]*n
    dp[0], dp[1] = 0, abs(h[0]-h[1])
    for i, hi in enumerate(h[2:], 2):
        di = 10**9
        m = max(0, i-k)
        for dj, hj in zip(dp[m:i], h[m:i]):
            d = dj + abs(hj-hi)
            if di > d:
                di = d
        dp[i] = di
    print(dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 54112
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);

int main() {
	string s;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++) {
		if ('a' <= s[i] && s[i] <= 'z')cout << char(s[i] - 32);
		else cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<long long int>());
#define INF 999999999
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A,B;
vector<pll> Plan;

void input(){
  fast_io();
  #ifdef __LOCAL
    fs::path p = __FILE__;
    fs::path input,output;
    input = output = p.parent_path();
    input += string("/input/") + string(p.stem()) + string(".txt");
    output += string("/output/") + string(p.stem()) + string(".txt");
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N;
  // A.assign(N,0);
  // B.assign(N,0);
  for (int i = 0; i < N; i++)
  {
    ll a,b;
    cin >> a >> b;
    Plan.push_back({b,a});
  }
  VSORT(Plan)
  reverse(ALL(Plan));
}


int solve(){
  ll ter = LL_INF;
  for (int i = 0; i < N; i++)
  {
    ter = min(ter,Plan[i].first);
    ter -= Plan[i].second;
  }
  string ans = ter>=0 ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

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


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define int long long int
// #include "Template.cpp"
#define endl "\n"

void solve()
{
    string s; cin >> s;
    int n = s.size();
    int i = 0;
    int ans = 0;
    while(i < n) {
        if(s[i] == 'S') {
            i ++;
            continue;
        }
        int c = 0;
        while(i < n && s[i] == 'R') {
            i ++;
            c ++;
        }
        ans = max(ans, c);
    }
    cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3612
from collections import deque 
k=int(input())
dq=deque()
for i in range(1,10):
    dq.append(i)

cnt=1
while cnt<k:
    now=dq.popleft()
    if now%10>=1:
        dq.append(now*10+now%10-1)
    dq.append(now*10+now%10)
    if now%10<=8:
        dq.append(now*10+now%10+1)
    cnt+=1
print(dq.popleft())


Measured memory_bytes: 11908
import sys


def solve(inp):
    (N, L) = map(int, inp.readline().split(' '))
    S = sorted([inp.readline() for i in range(N)])

    r = ""
    for s in S:
        r += s.strip()

    return r


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


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

void lcs(string x,string y);

int main(){
	int n; cin>>n;
	string x,y;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		lcs(x,y);
	}
	cin.get();cin.get();
}

void lcs(string x,string y){
	int m = x.size() , n = y.size();
	x = ' '+x; y = ' '+y;
	int **c;
	c = new int*[m+1]; for(int i=0;i<=m;i++) c[i] = new int[n+1];
	for(int i=0;i<=m;i++) c[i][0] = 0; for(int j=0;j<=n;j++) c[0][j] = 0;
	int maxl = 0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(x[i]==y[j]){
				c[i][j] = c[i-1][j-1]+1;
				if(i==m&&j==n) cout<<c[i][j]<<endl;
			}else{
				c[i][j] = max(c[i-1][j],c[i][j-1]);
				if(i==m&&j==n) cout<<c[i][j]<<endl;
			}
		}
	}
	for(int i=0;i<=m;i++) delete [] c[i]; delete [] c;
}

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

using namespace std;
#define endl "\n"
#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    set<char> str;
    for (int i = 0; i < 4; ++i) {
        char temp;
        cin >> temp;
        str.insert(temp);
    }
    if (str.size() == 2)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256