akhauriyash/Code-Regression huggingface dataset:
integer N,x
integer(16),allocatable,dimension(:)::A
integer(16) ans
read*,N,x
allocate(A(n))
read*,A
ans=0
if(A(1)>=x)then
  ans=A(1)-x
  A(1)=x
end if
do i=2,N
  if(A(i)+A(i-1)<=x)cycle
  ans=ans + (A(i)+A(i-1)-x)
  A(i)=x-A(i-1)
end do
print"(i0)",ans
end

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

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

int main(){
	string s;
	cin >> s;
	vector<int> t(s.size());
	rep(i, s.size()){
		t[i] = (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') ? 1 : 0;
	}
	int n = s.size();
	for(int i = 1; i < n; ++i){
		if(t[i] != 0) t[i] += t[i-1];
	}
	int mx = 0;
	for(int i = 0; i < n; ++i){
		mx = max(mx, t[i]);
	}
	cout << mx << endl;
	return 0;
}



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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N;
    cin >> A >> B;
    cout << min(A, B) << ' ' << max(A + B - N, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main(){
   int n;
   cin >> n;
   int h[n], s[n];
   for(int i = 0; i < n; i++) {cin >> h[i]; s[i] = MOD;}
   s[0] = 0;
   for(int i = 0; i < n; i++){
       for(int j = 1; j <= 2 && i + j < n; j++){
           s[i + j] = min(s[i + j], s[i] + abs(h[i + j] - h[i]));
       }
   }
   cout << s[n - 1] << endl;
}


Measured memory_bytes: 1024
/*
problem's name:
statue:
writer:Patrick_y
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <cctype>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050208;
/*------------main part------------*/



int p[100005];
vector<int> edg[100005];
bool vis[100005];
int num[100005];
int cnt;
int ans;
void dfs(int x)
{
	if(vis[x])
		return;
	vis[x]=true;
	num[x]=cnt;
	for(int i=0;i<edg[x].size();i++)
	{
		dfs(edg[x][i]);
	}
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
		p[i]--;
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--,y--;
		edg[x].push_back(y);
		edg[y].push_back(x);
	}
	for(int i=0;i<n;i++)
	{
		if(!vis[i])
		{
			dfs(i);
			cnt++;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(num[i]==num[p[i]])
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

bool isPrime(int a) {
    if (a < 2) return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}

void solve(int k) {
    if (k == 1 || isPrime(k)) {
        cout << 0 << endl;
        return;
    }
    int ans = 0;
    for (int i = k - 1; !isPrime(i); i--) {
        ans++;
    }
    for (int i = k; !isPrime(i); i++) {
        ans++;
    }
    cout << ans + 1 << endl;
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        //return 0;
    }
}

Measured memory_bytes: 3084
s = input()

ans = 0
ind = 0
while ind < len(s)-1:
    if s[ind:ind+2] in ("01", "10"):
        s = s[:ind]+s[ind+2:]
        ans += 1
        ind = max(0, ind-1)

    else:
        ind += 1
print(ans*2)


Measured memory_bytes: 9280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  double n;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
  double sum=accumulate(a.begin(),a.end(),0);
double p=sum/n;
  double r=p-floor(p);
  int ans=0;
  if(0.5>r){
    rep(j,n){
        ans+=(a[j]-floor(sum/n))*(a[j]-floor(sum/n));
    }
  }
     if(r>=0.5){
    rep(j,n){
     ans+=(a[j]-ceil(sum/n))*(a[j]-ceil(sum/n));
    }
     }
        cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main() {
  int N;
  cin >> N;
  int com = 0;
  int sum = 0;
  vector<int> yam(N);
  for (int i = 0; i < N; i++) {
    cin >> yam.at(i);
  }
  
  for (int j = 0; j < N; j++) {
    for (int k = 0; k < N; k++) {
      if (j == k) {
        continue;
      }
      else { 
        sum += yam.at(j) * yam.at(k);
      }
    }
  }
  
  cout << sum /2 << endl;

  return 0;
}

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

const int N = 110000;

int a[N], b[N], nxt[N], chk[N];
pair<int, int> A[N], B[N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n; i++) B[i] = make_pair(b[i], i);
	for (int i = 0; i < n; i++) A[i] = make_pair(a[i], i);
	sort(A, A + n); sort(B, B + n);
	bool flg = 1;
	for (int i = 0; i < n; i++) if (A[i].first > B[i].first) flg = 0;
	if (!flg) {
		cout << "No\n";
		return 0;
	}
	flg = 0;
	for (int i = 1; i < n; i++) if (A[i].first <= B[i - 1].first && A[i - 1].first <= B[i].first) flg = 1;
	if (flg) {
		cout << "Yes\n";
		return 0;
	}
	for (int i = 0; i < n; i++) nxt[A[i].second] = B[i].second;
	int u = 1, tot = 1;
	chk[u] = 1;
	while (1) {
		u = nxt[u];
		if (chk[u]) break;
		chk[u] = 1;
		tot++;
	}
	if (tot == n) cout << "No\n";
	else cout << "Yes\n";
	return 0;
}



Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(m);
    vvi vec(n);
    REP(i,n){
        int k;
        cin>>k;
        vec[i].resize(k);
        REP(j,k){
            cin>>vec[i][j];
            vec[i][j]--;
        }
        FOR(j,1,k){
            uf.unite(vec[i][0],vec[i][j]);
        }
    }
    REP(i,n){
        if(!uf.find(vec[0][0],vec[i][0])){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <cmath>
#include <cstdio>
using  namespace std;

int main(){
  int N;
  int x[10];
  int y[10];
  int i, j;
  double sum = 0;
  int product = 1;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (j != i)
        sum += sqrt((double)((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])));
    }
  }
  printf("%lf\n", sum/N);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int n;
int mn=INF;
int ans;
int main(){
	cin>>n;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		if(x<mn)ans++,mn=x;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
def verify(A, B, C, M):
    n = 0
    for i in range(M):
        n += A[i]*B[i]
    if n + C > 0:
        return True
    return False


in1 = list(map(int, input().split()))
N = in1[0]
M = in1[1]
C = in1[2]

B = list(map(int, input().split()))

v = 0
for _ in range(N):
    A = list(map(int, input().split()))
    if verify(A, B, C, M): v += 1;

print(v)


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

using namespace std;

int main()
{
 	int n;
  cin>>n;
  string s;
  cin>>s;
  int k;
  cin>>k;
  k--;
  char ofc=s[k];
 
  for(int i=0; i<n; i++)
  {
   	if(i==k) continue;
    else
    {
     	if(s[i]!=ofc)
        {
         	s[i]='*';
        }
    }
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
"""

https://atcoder.jp/contests/agc018/tasks/agc018_c

絶対最大なのは、全員から一番たくさん持ってるコインを貰う事
とりあえずそうして、後から人数を調整することを考える

金と銀を貰いすぎたとする
金をN個減らす、銀をM個減らす、銅をN+M個増やす…？
→必ずしもこうではなさそう…
金を貰いすぎたとする。
貰いすぎたコインを減らし、別のコインを増やす
削った時の減少量が銀にするとA-B , 銅だとA-C
減少量最小化問題になる
→あれなんかやったことがある気が…？

方針違う？
適当にX,Y,Z人で振り分ける
swapすると増える限りswapし続ける？

金銀でswapする場合(1が金→銀)
(B1-A1) + (A2-B2)増える
どちらもheapqに突っ込んで、正な限りswapし続ける？
金銀・金銅・銀銅でやれば最適解になるか？
→そんなことはない(改善できない局所解がある…)

なんもわからん…


=====ちょっと答えを見た=====

まず銅を無視する(金銀だけに分ける)
A-Bで降順ソート(B-A)で昇順ソート
ここで金銀グループはどこかで切って左右にすっぱり分けられる
その中で金銅・銀銅を同様に求めればよい？
→ヒープを使って切り方を全探索

まずX個金・Y+Z個銀グループにしたとする
→銀グループは B-Cで昇順ソート小さいほうからZ個の和*-1 + 大きいほうからY個の和が現在の解

左からX個金・右からZ個銅にして、ずらしていって解を求める
X側では、a-c をヒープに入れ、最小のやつを取り除いて-1をかけて寄与に足せばいい
Z側では逆

1WA　→　はい？？？
b-aでソートしたとき同じものをどうするか

1 1 1
1 2 1
99 100 1
1 1 10000
→102

だめなケース見つけたわ
最後のとこだった
"""

import heapq
X,Y,Z = map(int,input().split())
ABC = []
for i in range(X+Y+Z):
    a,b,c = map(int,input().split())
    ABC.append( (b-a , a,b,c) )

ABC.sort()

#金側

q = []
ansX = []
now = 0
for i in range(X):
    tmp,a,b,c = ABC[i]
    heapq.heappush( q , a-c )
    now += a
ansX.append(now)

for i in range(X,X+Z):
    tmp,a,b,c = ABC[i]
    heapq.heappush( q , a-c )
    now += a
    pp = heapq.heappop( q )
    now -= pp
    ansX.append(now)

#銀側
ABC.reverse()

q = []
ansY = []
now = 0
for i in range(Y):
    tmp,a,b,c = ABC[i]
    heapq.heappush( q , b-c )
    now += b
ansY.append(now)

for i in range(Y,Y+Z):
    tmp,a,b,c = ABC[i]
    heapq.heappush( q , b-c )
    now += b
    pp = heapq.heappop( q )
    now -= pp
    ansY.append(now)

ansY.reverse()

#print (ABC)
#print (ansX,ansY)

ans = 0
for i in range(len(ansX)):
    ans = max(ans , ansX[i] + ansY[i])
print (ans)
    

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

using namespace std;

int main()
{
	int value,num;
	int total,ave;
	int kai;
	total=ave=0;
	kai=0;
	while(scanf("%d,%d",&value,&num) != EOF){
		total+=value*num;
		ave+=num;
		kai++;
	}
	ave=(double)ave/(double)kai+0.5;
	cout<<total<<endl;
	cout<<ave<<endl;
	return 0;
}

Measured memory_bytes: 1204
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)

for i in range(n):
    if i > 0:
        if (a[i] - a[i-1]) == 1:
            ans += c[a[i]-2]

print(ans)

Measured memory_bytes: 3064
def insertionSort(a,n,g):
    for i in range(g,n):
        v=a[i]
        j=i-g
        while j>=0 and a[j]>v:
            a[j+g]=a[j]
            j=j-g
            global cnt
            cnt+=1
        a[j+g]=v

def shellsort(a,n):
    global cnt
    cnt=0
    g=[i for i in [262913, 65921, 16577, 4193, 1073, 281, 77, 23, 8, 1] if i <= n]
    m=len(g)
    #print(g,m)
    for i in range(m):
        insertionSort(a,n,g[i])
    return a,m,g

n=int(input())
a=[int(input()) for i in range(n)]

a,m,g=shellsort(a,n)

print(m)
print(*g)
print(cnt)
for i in a:
    print(i)

Measured memory_bytes: 47416
const main = (input) => {
  input = input.trim();
  input = input.split(' ');
  const n = parseInt(input[0], 10);
  
  if (n<1000) {
    console.log("ABC");
  }else{
    console.log("ABD");
  }
 
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <sstream>
#include <cstdlib>

using namespace std;

void insertionSort(int A[], int N) {
  for(int i = 0; i < N; i++) {
    cout << A[i];
    if(i != N - 1)
      cout << ' ';
  }
  cout << endl;
  for (int i = 1; i <= N - 1; i++) {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    for (int k = 0; k < N; k++) {
      cout << A[k];
      if (k != N - 1) cout << ' ';
    }
    cout << endl;
  }
}

int main(void) {
  int N, i = 0;
  cin >> N;
  cin.ignore();
  int A[N];
  string str;
  getline(cin, str);
  istringstream s(str);
  while (getline(s, str, ' ')) {
    A[i++] = atoi(str.c_str());
  }
  insertionSort(A, N);
  return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define in inline
#define reg register
#define int long long
#define MAX 20030813
#define f(i,l,r) for(reg int i=l;i<=r;++i)
#define F(i,l,r) for(reg int i=l;i>=r;--i)
using namespace std;
namespace qwq{
	in void read(int &o)
	{
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9')
		{
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9')
		{
			o=(o<<3)+(o<<1)+(c^48);
			c=getchar();
		}
		o*=w;
	}
	in void write(int x)
	{
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
    	putchar(x%10+48);
	}
	in int max(int x,int y)
	{
		return x>y?x:y;
	}
	in int min(int x,int y)
	{
		return x<y?x:y;
	}
}
using namespace qwq;
int N,K,Q,ans,a[MAX],p;
signed main()
{
	read(N);read(K);read(Q);
	for(reg int i=1;i<=N;++i)a[i]=K;
	for(reg int i=1;i<=Q;++i){read(p);a[p]++;}
	for(reg int i=1;i<=N;++i)
	{
		if(a[i]<=Q)puts("No");
		else puts("Yes");
	}
}




Measured memory_bytes: 1408
N = int(input())
S = input()
alphabet = 'ZABCDEFGHIJKLMNOPQRSTUVWXY'
alphabet_num = {st: num for num, st in enumerate(alphabet)}
alphabet_list = [st for st in alphabet]

output = ''
for s in S:
  num = (alphabet_num[s] + N) % 26
  output += alphabet_list[num]
print(output)

Measured memory_bytes: 40540
h,w = map(int,input().split())
S = [list(input()) for i in range(h)]

dx = [-1,0,1]
dy = [-1,0,1]

for i in range(h):
    for j in range(w):
        if S[i][j] == '#':
            continue

        count = 0
        for x in dx:
            for y in dy:
                if 0<=i+y<h and 0<=j+x<w and S[i+y][j+x]=='#':
                    count += 1
        S[i][j] = str(count)

for s in S:
    print("".join(s))

Measured memory_bytes: 3188
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    for (ll i = 0; i < b; i++) cout << a;
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , m;
deque < int > dq;
bool mark[maxn];
vector < int > adj[maxn];

bool addb(){
    int v = dq.back();
    for(auto u : adj[v])
        if(!mark[u]){
            mark[u] = 1,
            dq.pb(u);
            return(1);
        }
    return(0);
}
bool addf(){
    int v = dq.front();
    for(auto u : adj[v])
        if(!mark[u]){
            mark[u] = 1,
            dq.push_front(u);
            return(1);
        }
    return(0);
}
bool done(){
    if(addb())
        return(0);
    if(addf())
        return(0);
    return(1);
}

void make(){
    dq.pb(1), mark[1] = 1;
    while(!done())
        continue;
}

int32_t main(){
    migmig
    cin >> n >> m;
    for(int i = 0; i < m ; i ++){
        int u , v;
        cin >> u >> v,
        adj[u].pb(v),
        adj[v].pb(u);
    }
    make();
    cout << dq.size() << endl;
    for(int i : dq)
        cout << i << ' ';
    return(0);
}

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


int main(){
    string strings_2, strings_1;
    cin >> strings_1;
    cin >> strings_2;


    if( strings_1.length() + 1 != strings_2.length() ){
        cout << "No"<< endl;
        return 0;
    }

    unsigned int i;
    unsigned char flag = 0;
    for( i=0; i < strings_1.length(); i++){
        if( strings_1[i] != strings_2[i] ){
            flag = 1;
            break;
        }
    }

    if( flag == 0 ){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3596
# 明日の入学試験に合格するために、太郎くんはあと T 時間の勉強をする必要があります。
# 幸いにも、彼は今いる世界(世界A)の X 倍の速度で時間が進む世界Bへ世界跳躍(ワールドリープ)することができます。
# 世界Bで (X×t) 時間進むと、世界Aでは t 時間進みます。
# 世界Bで T 時間勉強したとき、世界Aでは何時間進んでいるでしょうか。

input = gets.chomp.split
t = input[0].to_f
x = input[1].to_f

puts t / x

Measured memory_bytes: 1788
A = [chr(i) for i in range(65, 65 + 26)]
# アルファベット大文字一覧表

D = [chr(i) for i in range(68, 68 + 23)]
D.append("A")
D.append("B")
D.append("C")
# シーザー暗号変換後アルファベット大文字一覧表

n = input()
ANS = []

for i in range(len(n)) :
    ANS.append(A[D.index(n[i])])
    
for i in range(len(ANS)) :
    if i == len(ANS) - 1 :
        print(ANS[i])
    else :
        print(ANS[i], end = "")


Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long a[n+1]={},b[n]={};
  for(int i=0;i<n+1;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  long long ans=0;
  for(int i=0;i<n;i++){
    if(a[i]>=b[i]){
      ans+=b[i];
      a[i]-=b[i];
    }
    else if(a[i]<=0){
       if(a[i+1]>=b[i]){
         ans+=b[i];
         a[i+1]-=b[i];
       }
      else{
        ans+=a[i+1];
        a[i+1]-=b[i];
    }
    }
    else{
      ans+=a[i];
      b[i]-=a[i];
      if(a[i+1]>=b[i]){
        ans+=b[i];
        a[i+1]-=b[i];
      }
      else{
        ans+=a[i+1];
        a[i+1]-=b[i];
      }
    }

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

Measured memory_bytes: 5152
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;

// ユークリッドの互除法
LL extgcd(LL a, LL b, LL& x, LL& y)
{
	LL g = a; x = 1; y = 0;
	if (b != 0)
	{
		g = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	return g;
}

// 逆元
LL mod_inverse(LL a, LL m)
{
	LL x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

// 階乗
std::vector<LL>fact;
void mod_fact(LL n, LL m)
{
	fact.resize(n + 1);
	fact[0] = 1;
	for (LL i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i % m;
}

// nCk mod p
LL mod_comb(LL n, LL k, LL m)
{
	if (n < k) return 0;
	return fact[n] * mod_inverse(fact[k] * fact[n - k] % m, m) % m;
}

int main()
{
	LL K, N;
	in >> N >> K;

	mod_fact(N + 1, mod);
	for (LL i = 1; i <= K; ++i)
	{
		LL res1 = mod_comb(N - K + 1, i, mod);
		LL res2 = mod_comb(K - i + (i - 1), i - 1, mod);
		out << (res1 * res2) % mod << std::endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N, M;
constexpr int Nmax = 200000;
int A[Nmax];
int count_[Nmax + 1];
int dup[Nmax + 1];

int ans[Nmax];

int main()
{
    scanf("%d%d", &N, &M);
    memset(count_, 0, sizeof(count_));
    memset(dup, 0, sizeof(dup));
    REP(i, N)
    {
        scanf("%d", &A[i]);
        if (A[i] - count_[A[i]] > 0) dup[A[i] - count_[A[i]]]++;
        count_[A[i]]++;
    }

    int invans = 0;
    REP(i, N) if (dup[i + 1]) invans++;

    REP(i, M)
    {
        int X, Y;
        scanf("%d%d", &X, &Y);

        int del = A[X - 1];
        count_[del]--;
        if (del - count_[del] > 0)
        {
            dup[del - count_[del]]--;
            if (dup[del - count_[del]] == 0) invans--;
        }
 
        A[X - 1] = Y;
        if (Y - count_[Y] > 0)
        {
            dup[Y - count_[Y]]++;
            if (dup[Y - count_[Y]] == 1) invans++;
        }
        count_[Y]++;
        ans[i] = N - invans;
    }

    REP(i, M) printf("%d\n", ans[i]);
}


Measured memory_bytes: 4608
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
	int a[100005];
	int b[100005];
	int i, n, m;
	int x, y;
	for(i = 0 ; i < 100005 ; i++)
	{
		a[i] = 1;
		b[i] = 0;
	}
	b[1] = 1;
	int vis = 0;
	scanf("%d %d", &n, &m);
	for(i = 1 ; i <= m ; i++)
	{
		scanf("%d %d", &x, &y);
		if(b[x] == 0)
		{
			vis = 1;
		}
		else
		{
			if(a[x] == 1)
			{
				vis = 2;
			}
			else
			{
				vis = 3;
			}
		}
		if(vis == 1)
		{
			a[x]--;
			a[y]++;
		}
		if(vis == 2)
		{
			a[x]--;
			a[y]++;
			b[x] = 0;
			b[y] = 1;

		}
		if(vis == 3)
		{
			a[x]--;
			a[y]++;
			b[y] = 1;
		}
	}
	int ans = 0;
	for(i = 1 ; i <= n ; i++)
	{
		
		if(b[i] == 1)
		{
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>

using namespace std;

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

  int sum = 0;
  for (int i = 1; i < N; i++) {
    int tmp = (N - 1) / i;
    sum += tmp;
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <sstream>
#include <cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;
#define INF 1e9

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

int64 gcd(int64 a, int64 b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

int64 modinv(int64 a, int64 m) {
    int64 b = m, u = 1, v = 0;
    while (b) {
        int64 t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// https://en.wikipedia.org/wiki/Trial_division
#define M map<int64, int64>
M f(int64 n) {
    M m;

    while (n % 2 == 0) {
        m[2]++;
        n = n / 2;
    }

    int64 c = 3;
    while (c * c <= n) {
        if (n % c == 0) {
            n = n / c;
            m[c]++;
        } else {
            c += 2;
        }
    }
    if (n != 1) m[n]++;
    return m;
}

// https://ei1333.github.io/luzhiled/snippets/math/divisor.html
vector< int64 > divisor(int64 n) {
  vector< int64 > ret;
  for(int64 i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    int64 N;
    cin >> N;

    vector<int64> items = divisor(N);

    int64 ans = 0;
    rep(i, items.size()) {
        items[i]--;
        if (items[i] == 0) continue;
        if (N % items[i] == N / items[i]) ans += items[i];
    }

    cout << ans << endl;
}


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



int main(){

   string s;
   cin>>s;
   int n=s.length();
   vector<char> st;
   int ans=0;
   for(int i=0;i<n;i++){
        if(st.size()==0){
            st.push_back(s[i]);
        }
        else{
            if(s[i]==st[st.size()-1]){
                st.push_back(s[i]);
            }
            else{
                ans+=2;
                st.pop_back();
            }
        }
   }
   cout<<ans;


return 0;
}


Measured memory_bytes: 3748
def linked_merge_sort(l): #マージソート
    if len(l) == 1:
        return
    q, r = divmod(len(l), 2)
    left = [l.pop() for _ in range(q)]
    right = [l.pop() for _ in range(q + r)]
    
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    left.reverse()
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            l.append(left.pop())
        else:
            l.append(right.pop())
    while left:
        l.append(left.pop())
    while right:
        l.append(right.pop())
    return

x,n=map(int,input().split())
p=list(map(int,input().split()))
if x>50:
    ans = 101
else:
    ans = 0
for i in range(n):
    p[i]=p[i]-x
if n>1:
    linked_merge_sort(p)
    j=n-1
    for i in range(n):
        if p[i]>=0:
            j=i
            break
    for i in range(n):
        if j-i>=0:
            if p[j-i]!=-i:
                ans = x-i
                break
        elif j-i<0:
            ans=x+p[0]-1
            break
        if j+i<n:
            if p[j+i]!=i:
                ans = x+i
                break
        else:
            ans=x+p[n-1]+1
            break
elif n==1:
    if p[0]==0:
        ans=x-1
    else:
        ans=x
elif n==0:
    ans=x
print(ans)


Measured memory_bytes: 62932
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

s = int(input())
mod = 10**9+7

ans = 0
for keta in range(1,700):
    sum = s-keta*3
    if sum<0:
        break
    ans += combinations_count(sum+keta-1,keta-1)%mod

print(ans%mod)

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

int main()
{  
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;++i){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  cout << d.at(n/2)-d.at(n/2-1);
  return 0;
}

Measured memory_bytes: 640
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, S);
    ll ans;
    if (S == "RRR")
    {
        ans = 3;
    }
    else if (S == "RRS" or S == "SRR")
    {
        ans = 2;
    }
    else if (S == "SSS")
    {
        ans = 0;
    }
    else
    {
        ans = 1;
    }
    OUT(ans);
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define rsort_v(v) std::sort(v.rbegin(), v.rend())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))
 
 // ^^^ Template ^^^ //

int main() {
	in(ll, N);
	in_v(ll, A_, N);
	multiset<ll> A;
	for(ll a : A_) A.insert(a);
	ll ans = 0;
	while(!A.empty()){
		auto AmaxI = A.end();
		--AmaxI;
		ll t = 1, Amax = *AmaxI;
		//A.erase((++Arb).base());
		A.erase(AmaxI);
		while(t <= Amax) t<<=1;
		auto Alb = A.lower_bound(t - Amax);
		if(Alb != A.end() && *Alb == t - Amax){
			A.erase(Alb);
			++ans;
		}
	}
	out(ans);
}



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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

    int n;
    cin >> n;
    vector<int> dp(3);
    for (int day = 0; day < n; day++) {
        vector<int> c(3);
        vector<int> new_dp(3, 0);
        for (int i = 0; i < 3; i++) {
            cin >> c[i];
        }
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i != j) {
                    new_dp[j] = max(new_dp[j], dp[i] + c[j]);
                }
            }
        }
        dp = new_dp;
    }

    cout << max({dp[0], dp[1], dp[2]}) << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=5e5+7;
char s[N];
int a[N],n,now;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n)a[i+1]=s[i]-'0';
	
	int c=0;
	rep2(i,n+1,1){
		int res=a[i]*9 + c;
		a[i]=res%10;
		c=res/10;
		now+=a[i];
	}
	rep(k,1,1000000){
		c=9;
		rep2(i,n+1,0){
			if(a[i]+c < 10){
				now+=c;
				a[i]+=c;
				break;
			}else{
				now-=a[i];
				int res=a[i]+c;
				c=res/10;
				a[i]=res%10;
				now+=a[i];
			}
		}
		if(now<=9*k){
			printf("%d\n",k);
			return 0;
		}
	}
}

Measured memory_bytes: 2688
K = int(input())
A,B = map(int,input().split())
flag = False

# if A==B:
#     if A % K ==0:
#         flag = True
for i in range(A,B+1,1):
    #print(i)
    if i % K == 0:
        flag = True

if flag:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9112
S = input()

chars = "abcdefghijklmnopqrstuvwxyz"
char_set = set(chars)

if len(S) == 26:
    for i in range(len(S)-1, -1, -1):
        x = chars.index(S[i])
        y = sorted(set(chars[x+1:])-set(S[:i]))
        # print(i, y)
        if len(y):
            print(S[:i]+y[0])
            exit()
else:
    t = sorted(set(chars)-set(S))[0]
    print(S+t)
    exit()
print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int digit(int num){
	if((num / 10) > 0 ) return (digit(num/10))+1;
	else return 1;
}

int main(){
	int num1,num2,result=0;
	char buf[32];
	while(fscanf(stdin,"%d %d",&num1,&num2) != EOF){
		result = digit(num1+num2);
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7+1;
int prime[maxn];
bool is_prime[maxn];

int sieve(int n) {
    int p = 0;
    for(int i = 1; i <= n; i ++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i ++) {
        if(is_prime[i]) {
            prime[p++] = i;
            for(int j = i+i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return p;
}

int main() {
    int n;
    while(scanf("%d", &n) != EOF) {
        printf("%d\n", sieve(n));
    }
    return 0;
}

Measured memory_bytes: 4416
N = gets.chomp
L = gets.chomp

r = 0;
b = 0;
L.each_char do |c|
    if c == 'B'
        b += 1
    elsif c == 'R'
        r += 1
    end
end

if r > b
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 1788
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int main(){
    int N,ans;
    ll L,a[110000];
    cin>>N>>L;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    bool flag=false;
    for(int i=0;i<N-1;i++){
        if(a[i]+a[i+1]>=L){
            flag=true;
            ans=i+1;
        } 
    }
    if(flag){
        cout<<"Possible"<<endl;
        for(int i=1;i<N;i++){
            if(ans==i) break;
            cout<<i<<endl;
        }
        for(int i=N-1;i>=0;i--){
            if(ans==i) break;
            cout<<i<<endl;
        }
        cout<<ans<<endl;
    }else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 1664
N, K = map(int,input().split())
z_list = list(map(int,input().split()))
T = str(input())
sum = 0
aiko_flag=[0] * K

for i in range(N):
    if i > K-1:
        if T[i] == 'r' and (T[i-K] != 'r' or aiko_flag[(i-K) % K]) == 1:
            sum = sum + z_list[2]
            aiko_flag[i % K] = 0
        elif T[i] == 's'and (T[i-K] != 's' or aiko_flag[(i-K) % K]) == 1:
            sum = sum + z_list[0]
            aiko_flag[i % K] = 0
        elif T[i] == 'p' and (T[i-K] != 'p' or aiko_flag[(i-K) % K]) == 1:
            sum = sum + z_list[1]
            aiko_flag[i % K] = 0
        else:
            aiko_flag[i % K] = 1
    elif i < K:
        if T[i] == 'r':
            sum = sum + z_list[2]
        elif T[i] == 's':
            sum = sum + z_list[0]
        elif T[i] == 'p':
            sum = sum + z_list[1]

print(sum)

Measured memory_bytes: 3956
n, k = map(int, input().split())
l = []

for i in range(n):
    a, b = map(int, input().split())
    l.append([a, b])

l.sort(key=lambda x: x[0])

count = 0
for j in l:
    count += j[1]
    if k <= count:
        print(j[0])
        break


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

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

    int answer = 0;
    
    for(int x = 0; x <= k; x++ ){
        for (int y = 0; y <=k; y++)
        {
            int z= s -x -y;
            if (z>=0 && z<=k)
            {
                answer++;
            }
            
        }
        
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())
ans_list = []
for i in range(len(S)):
  flag = True
  if S[i] == "?" or S[i] == T[0]:
    tmp = S[i:i+len(T)]
    if len(tmp) != len(T):
      continue
    for j in range(len(T)):
      if tmp[j] != '?' and T[j] != tmp[j]:
        flag = False
        break
    if flag:
      ans = S[:i] + T + S[i+len(T):]
      for i in range(len(ans)):
        if ans[i] == '?':
          ans[i] = 'a'
      ans_list += [ans]

if len(ans_list) != 0:
  ans_list = sorted(ans_list)
  print(''.join(ans_list[0]))
else:
  print('UNRESTORABLE')



Measured memory_bytes: 63496
(defmacro diff (a b)
  `(abs (- ,a ,b)))

(defun calc (X Y a b)
  (min (diff a b)
       (+ (diff a X) 1 (diff Y b))
       (+ (diff a Y) 1 (diff X b)) ))

(defvar N (read))
(defvar X (read))
(defvar Y (read))

(defvar arr (make-array N))

(loop for a from 1 to (1- N) do
      (loop for b from (1+ a) to N do
            (incf (aref arr (calc X Y a b))) ))

(map nil (lambda (x) 
                 (princ x)
                 (princ #\newline) )
     (subseq arr 1))

Measured memory_bytes: 6500
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
#define ull unsigned long long int
#define ld long double
//Make sure no overflow problems
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define endl '\n'
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define mod 1000000007
#define MEM(a, b) memset(a, (b), sizeof(a))
#define addmod(a,b,mod) (a%mod + b%mod)%mod
#define submod(a,b,mod) (a%mod - b%mod + mod)%mod
#define N 1000000
const ld EPS = 10e-9;
const int MAX = 1e6;

int main(){
    #ifdef mt19937 rnd(228);
        freopen("a.in", "r", stdin);
    #endif
    ios_base:: sync_with_stdio(false); 
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;
    cout << t << s;
    return 0;
}

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

struct Bar
{
  int height;
  int p;
  int q;

  bool operator<( const Bar& right ) const
  {
    return height > right.height;
  }
};

class Amida
{
  public:
    Amida(int line_num, int bar_num, int start_line);

  public:
    int Go();

  private:
    int m_line_num;
    int m_bar_num;
    int m_start_line;
    vector<Bar> m_bars;
};

Amida::Amida(int line_num, int bar_num, int start_line)
{
  m_line_num = line_num;
  m_bar_num = bar_num;
  m_start_line = start_line;

  for (int i = 0; i < m_bar_num; ++i)
  {
    Bar buf_bar;
    cin >> buf_bar.height >> buf_bar.p >> buf_bar.q;
    m_bars.push_back(buf_bar);
  }
  sort(m_bars.begin(), m_bars.end() );
}

int Amida::Go()
{
  int now = m_start_line;

  for (Bar bar : m_bars)
  {
    if (bar.p == now)
    {
      now = bar.q;
    }
    else if (bar.q == now)
    {
      now = bar.p;
    }
  }

  return now;
}

int main(void)
{
  while (true)
  {
    int n, m, a;
    cin >> n >> m >> a;
    if (n == 0 and m == 0 and a == 0) break;
    Amida amida(n, m, a);
    cout << amida.Go() << endl;
  }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
    #define pi acos(-1)
    #define ll long long
    #define pii pair<ll,ll>
    #define debug(a) cout<<a<<'\n'
    #define maxn 200009 /// I wanna be the wind
    #define MOD 1000000007
    #define F first
    #define S second
    #define rep(i, a, b) for(ll i = a; i < (b); ++i)
    #define per(i, b, a) for(ll i = b-1; i>=a ; i--)
    #define trav(a, x) for(auto& a : x)
    #define allin(a , x) for(auto a : x)
    #define all(x) begin(x), end(x)
    #define sz(x) (ll)(x).size()
    using namespace std;
    const ll INF = 1e17 + 9;
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll cont=0;
        rep(i,0,n)if(s[i]=='W')cont++;
        ll cont2=cont;
        per(i,n,n-cont2){
            // cout<<i<<"\n";
            if(s[i]=='W')cont--;
        }
        cout<<cont<<"\n";
        return 0;  
    }   

Measured memory_bytes: 3772
# frozen_string_literal: true

require 'prime'

n = gets.to_i
an = gets.split(' ').map(&:to_i)

def coprime?(bn)
  g = bn[0]
  bn[1..-1].each do |bi|
    g = g.gcd(bi)
    return true if g == 1
  end
  false
end

def setwise?(bn)
  buckets = Array.new(1_000_001, 0)
  bn.each do |bi|
    buckets[bi] += 1
  end
  Prime.each(1_000_000) do |pi|
    count = 0
    (1..(1_000_000 / pi)).each do |qi|
      count += buckets[pi * qi]
      return true if count > 1
    end
  end
  false
end

if !coprime?(an)
  puts 'not coprime'
elsif setwise?(an)
  puts 'setwise coprime'
else
  puts 'pairwise coprime'
end


Measured memory_bytes: 94644
N,K,L = map(int, input().split())

#print(N,K,L,D,T)

class UnionFind:
    def __init__(self, n: int) -> None:
        self.par = [i for i in range(n)]
        self.rank = [0] * n

    def find(self, x: int) -> int:
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        
    # 同じ集合に属するか判定
    #def same_check(self, x, y):
    #    return self.find(x) == self.find(y)

def uniteOne(num, uf):
    for _ in range(num):
        d0, d1 = map(int, input().split())
        uf.unite(d0-1, d1-1)
        
uf_D = UnionFind(N)
uf_T = UnionFind(N)

uniteOne(K, uf_D)
uniteOne(L, uf_T)

pairs = []
for i in range(N):
    pairs.append((uf_D.find(i), uf_T.find(i)))

pairs_count = {}
for p in pairs:
    if not p in pairs_count:
        pairs_count[p] = 1
    else:
        pairs_count[p] += 1

res = [0] * N
for i in range(N):
    res[i] = pairs_count[pairs[i]]
#print(*(res[i] for i in range(N)))
print(" ".join([str(i) for i in res]))

Measured memory_bytes: 66708