akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()

s_length = len(s)
t_length = len(t)

ans = ''
keep = ''
remind = 0
checker = False
for i in range(s_length):
    if (i + t_length) <= s_length:
        check = True
        for j in range(t_length):
            if (s[i + j] != t[j]) & (s[i + j] != '?'):
                check = False
        if check:
            checker = True
            ans = keep + t
            remind = i + t_length
    if s[i] == '?':
        keep += 'a'
    else:
        keep += s[i]
ans = ans + keep[remind:]

if checker:
    print(ans)
else:
    print('UNRESTORABLE')


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


int main()
{
    int k,n;
    cin>>k>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    ll Max = 0;
    for(int i=1;i<n;i++)
    {
        if(v[i]-v[i-1]>Max)
            Max = v[i]-v[i-1];
    }
    if(v[0]+k-v[n-1]>Max)
        Max = v[0]+k-v[n-1];
    cout<<k-Max<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int mod,l,r,vis[100050];
struct node{
	long long tot,val;
}q[100050];
int main(){
	cin>>mod;
	q[l=r=1].tot=1;q[1].val=1;
	while(l<=r){
		
		if(!q[l].tot){
			cout<<q[l].val;return 0;
		}if(vis[q[l].tot]){
			++l;
		}else{
			vis[q[l].tot]=1;
			q[l].tot=q[l].tot*10%mod;q[l].val=q[l].val;
			q[++r].tot=(q[l].tot+1)%mod;q[r].val=q[l].val+1;
		}
	}
}

Measured memory_bytes: 2176
# -*- coding: utf-8 -*-

def dfs(num, dem, k, cur_num, prd, p, q, a, n):

    #print num, dem, k, cur_num, prd
    #time.sleep(0.5)
    if num == 0:
        #print "result: " + str(result)
        return 1

    result = 0

    i = cur_num
    while prd * i <= a:
        #print i, num, dem, k, cur_num, prd
        if (n - k) * dem < num * i:
            break
        if num * i < dem:
            i += 1
            continue

        result += dfs((num * i) - dem, dem * i, k + 1, i, prd * i, p, q, a, n)
        i += 1

    return result

def func():
    while True:

        p, q, a, n = map(int, raw_input().split())

        if p == 0 and q == 0 and a == 0 and n == 0:
            break

        print dfs(p, q, 0, 1, 1, p, q, a, n)
        
    return None

if __name__ == '__main__':
    func()
    

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    vector<vector<int>> edges(n);
    --x, --y;
    edges[x].push_back(y);
    edges[y].push_back(x);
    for (int i = 0; i < n-1; ++i) {
    	edges[i].push_back(i+1);
    	edges[i+1].push_back(i);
    }
    vector<int> how_many(n+1);
    vector<vector<int>> dist(n+1, vector<int>(n+1, -1));
    for (int from = 0; from < n; ++from) {
    	dist[from][from] = 0;
    	vector<int> bfs = {from};
	    for (int i = 0; i < bfs.size(); ++i) {
	    	int v = bfs[i];
	    	for (int u : edges[v]) {
	    		if (dist[from][u] != -1) continue;
	    		dist[from][u] = dist[from][v] + 1;
	    		bfs.push_back(u);
	    	}
	    }
	}
	for (auto v : dist) {
		for (int u : v) {
			if (u != -1) how_many[u]++;
		}
	}
	for (int i = 1; i < n; ++i)
		cout << how_many[i]/2 << '\n';
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

signed main() {
    cin >> A >> B >> C >> D >> E >> F;
    ll MA = F / (100 * A);
    double noudo = 0.0;
    pair<int, int> ans;
    REP(i, MA + 1) {
        ll water = 100 * A * i;
        while (water <= F) {
            if (water != 0) {
                ll f = F - water;
                ll MC = f / C;
                REP(j, MC + 1) {
                    ll lim = min(f, water * E / 100) - j * C;
                    if (lim < 0)
                        break;
                    ll k = lim / D;
                    ll sugar = C * j + D * k;
                    double tmp = (double)sugar / (water + sugar);
                    dump(tmp, water, sugar, lim);
                    if (tmp >= noudo) {
                        noudo = tmp;
                        ans = {water + sugar, sugar};
                    }
                }
            }
            water += 100 * B;
        }
    }
    cout << ans.first << " " << ans.second << endl;
}

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

using namespace std;

signed main() {
    string n;
    cin >> n;

    auto flag = vector<bool>(3);
    for (auto c : n){
        flag.at(c - 'a') = true;
    }

    for (auto b : flag){
        if (b == false) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

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

typedef long long ll;

string s;
int N;
int S[200010];
int sum[100] = {0};
int cnt[100] = {0};
bool bef[200010] = {0};
vector<int> V[100];
vector<int> bac;
ll ans = 0;
ll bit[200010] = {0};

void add(int i)
{
    while(i <= N)
    {
        bit[i]++;
        i += i & -i;
    }
    return;
}

ll cmp(int i)
{
    ll res = 0;
    while(i > 0)
    {
        res += bit[i];
        i -= i & -i;
    }
    return res;
}

int main()
{
    cin >> s;

    N = s.size();
    for(int i = 0; i < N; i++)S[i] = s[i] - 'a';
    for(int i = 0; i < N; i++)sum[S[i]]++;
    bool flag = false;
    for(int i = 0; i < 26; i++)if(sum[i] % 2)
    {
        if(flag)
        {
            printf("-1\n");
            return 0;
        }
        flag = true;
    }

    if(N % 2)
    {
        for(int i = 0; i < 26; i++)
        {
            if(sum[i] % 2)
            {
                int now = 0;
                for(int j = 0; j < N; j++)
                {
                    if(S[j] == i)
                    {
                        if(now == sum[i] / 2)
                        {
                            S[j] = 50;
                        }
                        now++;
                    }
                }
                sum[i]--;
            }
        }
    }

    int id = 1,k = 0;
    for(int i = 0; i < N; i++)
    {
        int now = S[i];
        if(now == 50)
        {
            continue;
        }
        if(sum[now] % 2 == 0)
        {
            if(cnt[now] < sum[now] / 2)
            {
                bef[i] = true;
                V[now].push_back(id++);
                ans += i - k;
                k++;
            }
            cnt[now]++;
        }
    }

    for(int i = 0; i < 26; i++)reverse(V[i].begin(),V[i].end());

    for(int i = N - 1; i >= 0; i--)
    {
        int now = S[i];
        if(now == 50)continue;
        if(!bef[i] && sum[now] % 2 == 0)
        {
            bac.push_back(V[now].back());
            V[now].pop_back();
        }
    }

    for(int i = 0; i < bac.size(); i++)
    {
        int now = bac[i];
        ans += i - cmp(now);
        add(now);
    }

    k = 0;
    for(int i = 0; i < N; i++)
    {
        if(S[i] == 50)ans += k;
        if(!bef[i])k++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <math.h>

int main(void) {
	int x, h;
	double S;
	
	while(1) {
		S = 0;
		scanf("%d %d", &x, &h);
		if(!x && !h)
			break;

		S += x * x;
		S += x * sqrt(x * x + 4 * h * h);

		printf("%lf\n", S);
	}

	return 0;
}

Measured memory_bytes: 1060
x = input()

ans = 0

if len(x) < 3:
    ans = 0

elif len(x) < 4:
    tmp1 = int(x[-2] + x[-1])
    tmp2 = int(x[0])
    if tmp2 * 5 >= tmp1:
        ans = 1

else:
    tmp1 = int(x[-2] + x[-1])
    tmp2 = int(x[-4] + x[-3])
    if tmp2 * 5 >= tmp1:
        ans = 1

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4005;
const ll ms=998244353;
ll C[N][N],pw[N];
void pre(int n){
	for (int i=1;i<=n;i++){
		C[i][0]=1;
		for (int j=1;j<=i;j++){
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%ms;
		}
		pw[i]=pw[i-1]*2%ms;
	}
}
ll solve(int x,int y,int z){
	ll ans=0;
	for (int i=0;i<=min(x,z);i++)
	if (y+i-1>=0) ans=(ans+pw[i]*C[x][i]%ms*C[z+y-1][y+i-1]%ms)%ms;
	return ans;
}
int main(){
	int n,k;
	scanf("%d%d",&k,&n);
	pw[0]=1; C[0][0]=1; 
	pre(4000);
	ll ans=0;
	for (int i=2;i<=2*k;i++){
		int cnt=0;
		for (int j=1;j<=k;j++)
		if (i-j>=1&&i-j<=k) cnt++;
		if (i%2==0){
			ans=solve((cnt-1)/2,k-cnt,n)+solve((cnt-1)/2,k-cnt,n-1);
			if (ans>=ms) ans-=ms;
		}
		else ans=solve(cnt/2,k-cnt,n);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 123776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int i,x;
    while(cin>>s)
    {
        i = 0;

        if(s[i]=='R'&&s[i+1]=='R'&&s[i+2]=='R')x = 3;
        else if(s[i]=='S'&&s[i+1]=='S'&&s[i+2]=='S')x = 0;
        else if((s[i]=='R'&&s[i+1]=='R')||(s[i+1]=='R'&&s[i+2]=='R'))x = 2;
        else x = 1;
        printf("%d\n",x);
    }






return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>

int gcd(int a, int b) {
    int q = a / b;
    int r = a - b * q;
    if (r == 0)
        return b;
    else
        return gcd(b, r);
}

int main(void) {
    int n, x;
    int xs[100000];
    int d;

    scanf("%d%d", &n, &x);
    for (int i = 0; i < n; i++)
        scanf("%d", &xs[i]);

    for (int i = 0; i < n; i++) {
        xs[i] -= x;
        if (xs[i] < 0)
            xs[i] *= -1;
    }

    d = xs[0];
    for (int i = 1; i < n; i++)
        d = gcd(d, xs[i]);

    printf("%d\n", d);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, K; cin >> N >> K;
    vd p(N);
    REP(i, N)
    {
        double n; cin >> n;
        p[i] = n*(n+1)/2/n;
    }
    vd sum(N+1); REP(i, N) sum[i+1] = sum[i]+p[i];
    double ans = 0;
    REP(i, N-K+1)
    {
        ans = max(ans, sum[i+K]-sum[i]);
    }
    cout << ans << endl;
}

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

#define int long long

#define mk(a,b) make_pair(a,b)
#define fi first
#define se second

typedef pair<int,int> pii;

int N, M, L, Q;
vector<vector<int>> dist(310, vector<int>(310, 1001001001));

signed main() {
    cin >> N >> M >> L;
    for(int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    for(int k = 1; k <= N; k++) {
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(dist[i][j] > L) dist[i][j] = 1001001001;
            else dist[i][j] = 1;
        }
    }

    for(int k = 1; k <= N; k++) {
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    cin >> Q;
    for(int i = 0; i < Q; i++) {
        int a, b;
        cin >> a >> b;
        if(dist[a][b] >= 1001001001) cout << -1 << endl;
        else cout << dist[a][b] - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>

int a[90][30], b[90][30], ans[90][30];
int main()
{
	int len1,len2,n,i,j,k,x=0;
	a[0][0]=2;
	a[1][0]=1;
	for(i=2;i<89;i++)
	{
		x=0;
		
		for(j=0; j<20; j++)
  		  {
      	  a[i][j]=(a[i-1][j]+a[i-2][j]+x)%10;
      	  x=(a[i-1][j]+a[i-2][j]+x)/10;
   		 }
	}
	scanf("%d",&n);
	 for(i=20; !a[n][i] && i>=0; i--);
	{
		if(i==-1) printf("0");
    else
        for(; i>=0; i--)
            printf("%d", a[n][i]);
	}
	printf("\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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; }
struct Point {
  int x, y;
  Point(int x, int y) : x(x), y(y) {}
};
int main()
{
  int n; cin >> n;
  vector<int> p(n*n);
  rep(i,n*n) {
    cin >> p[i];
  }

  vector<vector<int>> c(n+1, vector<int>(n+1));
  rep1(i,n) rep1(j,n) {
    c[i][j] = min({i-1, n-i, j-1, n-j});
  }

  auto show = [&]()-> void{
		rep1(i,n) {
		  rep1(j,n) cout << c[i][j] << " ";
		  cout << "\n";
		}  
	      };
  
  vector<vector<bool>> f(n+1, vector<bool>(n+1, true));
  using pi = pair<int,int>;
  vector<int> dx = {1, 0, -1, 0};
  vector<int> dy = {0, 1, 0, -1};
  int res = 0;
  rep(i,n*n) {
    int x = (p[i] + n - 1)/n;
    int y = (p[i] % n == 0 ? n : p[i] % n);
    res += c[x][y];
    f[x][y] = false;
    queue<Point> q;
    q.emplace(x, y);
    while( !q.empty() ) {
      Point pp = q.front(); q.pop();
      int xx = pp.x, yy = pp.y;
      vector<Point> buf;
      rep(j,4) {
	int nx = xx + dx[j];
	int ny = yy + dy[j];
	if(0 < nx && nx <= n && 0 < ny && ny <= n) {
	  buf.emplace_back(nx, ny);
	}
      }
      rep(j,buf.size()) {
	int nx = buf[j].x;
	int ny = buf[j].y;	
	if(chmin(c[nx][ny], c[xx][yy] + f[xx][yy])) {
	  q.emplace(nx, ny);
	}
      }
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 5252
N, K = map(int, input().split())
x = list(map(int, input().split()))
import bisect
id = bisect.bisect_left(x,0)
ans=10**10
if id == N:
  print(abs(x[N-K]))
  exit(0)
for i in range(max(0,(K+id)-N),min(id+1,K)):
  right = x[K+id-1-i]
  left=0
  if i>0:
    left =x[id-i]
  tmp=min(abs(left)*2+right,right*2+abs(left)) 
  ans=min(tmp,ans)
print(ans)

Measured memory_bytes: 14252
from bisect import bisect_left
N = int(input())
A = sorted(list(map(int,input().split())))
A = [[A[i],0] for i in range(N)]
cnt = 0
for i in range(N-1,0,-1):
    if A[i][1]==0:
        a = A[i][0]
        A[i][1]=1
        k = 0
        while 2**k<=a:
            k += 1
        b = 2**k-a
        ind = bisect_left(A,[b,1])
        ind -= 1
        if ind<i and A[ind]==[b,0]:
            A[ind][1]=1
            cnt += 1
print(cnt)

Measured memory_bytes: 109392
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    int w, h; cin>>w>>h;
    vector<P> pq;
    for(int i=0; i<w; i++){
        int p; cin>>p;
        pq.push_back(P(p, 0));
    }
    for(int i=0; i<h; i++){
        int q; cin>>q;
        pq.push_back(P(q, 1));
    }

    sort(pq.begin(), pq.end());

    ll restw = w + 1;
    ll resth = h + 1;
    ll ans = 0;
    for(int i=0; i<pq.size(); i++){
        if(pq[i].second == 0){
            ans += pq[i].first * resth;
            restw--;
        }
        else{
            ans += pq[i].first * restw;
            resth--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6384
n = int(input())

'''
data = []
for i in range(10):
    data.append([])

for i in range(n):
    d = int(input())
    data[d%10].append(d)
for i in range(10):
    data[i].sort()

res = sum(data[0])

for i in range(1,5):
    while data[i]!=[] and data[10-i]!=[]:
        res+=data[i].pop()+data[10-i]+pop()
'''
res = 0
m = 101

for i in range(n):
    d = int(input())
    res+=d
    if d%10!=0 and d<m:
        m = d

if res%10==0:
    if m<100:
        res = res-m
    else:
        res = 0
print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <tr1/unordered_map>

#define For(i, l, r) for (int i = l; i <= r; ++ i)
#define Forr(i, r, l) for (int i = r; i >= l; -- i)
#define Travel(i, u) for (int i = beg[u], v = to[i]; i; v = to[i = nex[i]])

using namespace std;

typedef long long ll;

inline void File() {
	freopen("f.in", "r", stdin);
	freopen("f.out", "w", stdout);
}

const int N = 1e5 + 10;
int e = 1, beg[N], nex[N << 1], to[N << 1], n;
int ansu[N], ansv[N];
ll sz[N], tmp, dis[N];

struct node { ll v; int id; } P[N];
inline bool cmp(const node &a, const node &b) { return a.v > b.v; }

tr1::unordered_map<ll, int> mp;

inline void add(int x, int y) {
	to[++ e] = y, nex[e] = beg[x], beg[x] = e;
}

inline void dfs1(int u, int l, int rt) {
	dis[rt] += l;
	Travel(i, u) dfs1(v, l + 1, rt);
}

inline void dfs2(int u) {
	Travel(i, u) dis[v] = dis[u] - (sz[v] * 2 - n), dfs2(v);
}

int main() {

	scanf("%d", &n);
	For(i, 1, n) {
		scanf("%lld", &P[i].v); 
		P[i].id = i, mp[P[i].v] = i, sz[i] = 1;
	}

	sort(P + 1, P + 1 + n, cmp);

	for (int i = 1, u, v; i < n; ++ i) {
		u = P[i].id, tmp = P[i].v + 2 * sz[u] - n;
		
		if (n <= sz[u] << 1) return puts("-1"), 0;
		if (!mp.count(tmp)) return puts("-1"), 0;
		
		v = mp[tmp], ansu[i] = u, ansv[i] = v;
		add(v, u), sz[v] += sz[u];
	}	

	int rt = P[n].id; dfs1(rt, 0, rt), dfs2(rt);

//	For(i, 1, n) cout << P[i].id << ' '; cout << endl;
//	For(i, 1, n) cout << P[i].v << ' ' << dis[P[i].id] << endl;
	For(i, 1, n) if (dis[P[i].id] ^ P[i].v) return puts("-1"), 0;
	
	For(i, 1, n - 1) printf("%d %d\n", ansu[i], ansv[i]);

	return 0;
}



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

int main()
{
    int A, B;
    cin >> A >> B;
    if (B > A)
    {
        swap(A, B);
    }

    int ans = A;
    A--;
    if (B > A)
    {
        swap(A, B);
    }
    ans += A;

    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,j,N,ans;
  cin>>N;
  vec v(N);
  rep(i,N)cin>>v[i];
  vsort(v);
  i=0;j=N-1;
  ans=v[j]-v[i];
  i++;j--;
  while(i<j){
    ans+=v[j+1]-v[i];
    ans+=v[j]-v[i-1];
    i++;j--;
  }
  if(i==j)ans+=max(v[i]-v[i-1],v[i+1]-v[i]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

int main(){
	ll N, M, L; cin >> N >> M >> L;
	ll d[N][N];
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(i==j) d[i][j] = 0;
			else d[i][j] = INF;
		}
	}
	for(int i=0; i<M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = d[b][a] = c;
	}
	for(int k=0; k<N; k++){
		for(int i=0; i<N; i++){
			for(int j=0; j<N; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	ll d2[N][N];
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			d2[i][j] = INF;
		}
	}
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(i == j) d2[i][j] = 0;
			else{
				if(d[i][j] <= L) d2[i][j] = 1;
			}
		}
	}
	for(int k=0; k<N; k++){
		for(int i=0; i<N; i++){
			for(int j=0; j<N; j++){
				d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
			}
		}
	}
	int Q; cin >> Q;
	for(int i=0; i<Q; i++){
		int s, t; cin >> s >> t;
		s--; t--;
		if(d2[s][t] == INF) cout << -1 << endl;
		else cout << d2[s][t] - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  const ll num=393;
  ll n;
  cin >> n;
  vec s(n),l(n),p(n);
  for(ll i=0;i<n;i++) {
    cin >> s[i] >> l[i] >> p[i]; 
  }
  vec dp(num+1);
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<=num;j++) {
      for(ll k=s[i];k<=l[i];k++) {
        if(j-k>=0) {
          dp[j]=max(dp[j],dp[j-k]+p[i]);
        }
      }
    }
  }
  ll m;
  cin >> m;
  vec w(m);
  for(ll i=0;i<m;i++) {
    cin >> w[i];
    if(dp[w[i]]==0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for(ll i=0;i<m;i++) {
    cout << dp[w[i]] << endl;
  }
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    if((tail+1)%LEN == head) printf("error");
    tail = (tail + 1) %LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}


int min(int a, int b) { return a < b ? a: b;}

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    for( i = 1; i<=n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while(head != tail) {
        u = dequeue();
        if(u.t <= q) {
            c = min(u.t, q);
            elaps += c;
            printf("%s %d\n", u.name, elaps);
        }else {
            u.t -= q;
            elaps += q;
            enqueue(u);
        }
    }
    
    return 0;
}



Measured memory_bytes: 11860
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int N, a[100005],b[100005];
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> a[i];
		b[a[i]] = i;
	}
	for (int i = 1; i < N; i++)
		cout << b[i] << " ";
	cout << b[N] << endl;
	
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int a[100];
	int sum;
	int x;
	int k;
	int mx=0;
	sum=0;
	for(x=1;x<=3;x++)
	{
		cin>>a[x];
		sum+=a[x];
		mx=max(a[x],mx);
	}
	cin>>k;
	int save=mx;
	mx*=pow(2,k);
	sum+=mx-save;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/
// 0-indexed, 半開
template <typename T> struct BIT {
  private:
    int n;
    vector<T> dat;

  public:
    inline BIT(const vector<T> &v) : n(v.size()) {
        dat.assign(n + 1, 0);
        for(int i = 0; i < n; i++)
            dat[i + 1] = v[i];
        for(int i = 1; i < n; i++)
            if(i + (i & -i) <= n) dat[i + (i & -i)] += dat[i];
    }
    inline BIT(int n) : n(n) { dat.assign(n + 1, 0); }
    inline void add(int k, T a) {
        for(k++; k <= n; k += k & -k)
            dat[k] += a;
    }
    // [0,a)
    inline T sum(int a) {
        T ret = 0;
        for(; a > 0; a -= a & -a)
            ret += dat[a];
        return ret;
    }
    // [a,b)
    inline T sum(int a, int b) { return sum(b) - sum(a); }
    inline int lowerBound(int w) {
        if(w <= 0) return 0;
        int x = 0;
        for(int k = 1 << int(log2(n)); k; k /= 2) {
            if(x + k <= n && dat[x + k] < w) {
                x += k;
                w -= dat[x];
            }
        }
        return x + 1;
    }
};

int n, q;
int c[500009];

vector<pair<int, int>> ls[500009];
vector<int> ans;

int lst[500009];

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

    cin >> n >> q;
    rep(i, n) cin >> c[i + 1];

    ans.resize(q);
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        ls[r].emplace_back(l, i);
    }

    BIT bit(vector<int>(n + 10));

    FOR(i, 1, n + 1) {
        bit.add(lst[c[i]], -1);
        bit.add(lst[c[i]] = i, 1);
        for(auto [l, idx] : ls[i]) {
            ans[idx] = bit.sum(l, i + 1);
        }
    }

    rep(i, q) cout << ans[i] << "\n";

    return 0;
}

Measured memory_bytes: 33152
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define A a
#define B b
#define C c
#define D d
#define N n
#define M m
#define H h
#define W w
#define S s
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
int main(){
	char s[4];
	rep(i,0,4){
		cin>>s[i];
	}sort(s,s+4);
	if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    int ans = 0;
    for (int j = 0; j <= n - 3; j++) {
        int p1 = arr[j];
        int p2 = arr[j + 1];
        int p3 = arr[j + 2];
        
        if (p2 > p1 && p3 > p2) {
            ans++;
        } else if (p1 > p2 && p2 > p3) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define N 100

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int u[N],r[N];

int find(int x){
	return x == u[x] ? x : find(u[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y)return;
	if(r[x]<r[y])u[x]=y;
	else u[y]=x;
	r[x] += r[x] == r[y];
}

int main(){
	int n, m, a, b, d, c;
	for(;;){
		scanf("%d", &n);
		if(!n) break;
		scanf("%d", &m);
		vector< pair<int, pair<int, int> > > v;
		for(int i = 0; i < n; i++){
			u[i] = i;
			r[i] = 0;
		}
		
		for(int i = 0; i < m; i++){
			scanf("%d,%d,%d", &a, &b, &d);
			v.push_back( make_pair(d / 100 - 1, make_pair(min(a, b), max(a, b))));
		}
		sort(v.begin(), v.end());
		
		c = 0;
		for(int i = 0; i < m; i++){
			a = v[i].second.first;
			b = v[i].second.second;
			if(find(a) != find(b)){
				unite(a, b);
				c += v[i].first;
			}
		}
		printf("%d\n",c);
	}
	
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    char v[110][110];
    //黒：'#', 白：'.'
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            if (i < 50) v[i][j] = '#';
            else v[i][j] = '.';
        }
    }

    for (int i = 0; i < 49 && a > 1; i += 2) {
        for (int j = 0; j < 100 && a > 1; j += 2) {
            v[i][j] = '.';
            a--;
        }
    }
    for (int i = 51; i < 100 && b > 1; i += 2) {
        for (int j = 0; j < 100 && b > 1; j += 2) {
            v[i][j] = '#';
            b--;
        }
    }

    cout << 100 << " " << 100 << endl;

    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            cout << v[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

ans=1
for i in range(n):
    if a[i]%2==0 and a[i]%3!=0 and a[i]%5!=0:
        ans=0
if ans==1:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
from bisect import bisect_right
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

cA = [0]*(n+1)
cB = [0]*(m+1)

for i in range(n):
  cA[i+1] = cA[i]+A[i]
  
for i in range(m):
  cB[i+1] = cB[i]+B[i]
  
ans = bisect_right(cA,k) - 1 
ai = ans
bi = 0
while ai>=0 :
  r = k - cA[ai]
  tmp = bisect_right(cB,r) - 1 
  ans = max(ans,tmp+ai)
  ai -= 1
  
print(ans)  

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

vector<int> perse(long long n) {
  vector<int> ret;
  while (n) {
    ret.push_back(n % 10);
    n /= 10;
  }
  sort(ret.begin(), ret.end());

  return ret;
}

vector<int> available(vector<int> &v) {
  vector<int> ret;
  for (int i = 1; i < 10; ++i) {
    int cnt = 0;
    for (int j : v)
      if (i == j) cnt++;
    if (cnt < 4) ret.push_back(i);
  }

  return ret;
}

bool dfs(vector<int> cnt, int v = 0, int used = 0) {
  if (used == 4) return true;

  bool ret = false;

  if (cnt[v] >= 3) {
    cnt[v] -= 3;
    if (dfs(cnt, v, used + 1)) ret = true;
    cnt[v] += 3;
  }

  if (cnt[v]) {
    int t = 0;
    for (int i = 0; i < 3; ++i) {
      if (v + i == 10) continue;
      if (cnt[v + i]) t++;
    }

    if (t == 3) {
      for (int i = 0; i < 3; ++i) {
        cnt[v + i]--;
      }
      if (dfs(cnt, v, used + 1)) ret = true;
      for (int i = 0; i < 3; ++i) {
        cnt[v + i]++;
      }
    }
  } else {
    if (dfs(cnt, v + 1, used)) ret = true;
  }

  return ret;
}

bool solve(int n, vector<int> v) {
  vector<int> cnt(10);
  cnt[n]++;
  for (int i : v) cnt[i]++;

  for (int i = 1; i < 10; ++i) {
    if (cnt[i] >= 2) {
      cnt[i] -= 2;
      if (dfs(cnt)) return true;
      cnt[i] += 2;
    }
  }

  return false;
}

int main() {
  long long data;
  while (cin >> data) {
    vector<int> ans;

    vector<int> v = perse(data);
    vector<int> num = available(v);

    for (int i : num) {
      if (solve(i, v)) ans.push_back(i);
    }

    if (ans.size() == 0) cout << 0 << endl;
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i] << (i + 1 == ans.size() ? "\n" : " ");
    }
  }
}

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    map<string,int> mp;
    int n; cin >> n; REP(i,n){string s; cin >> s; mp[s]++;}
    int m; cin >> m; REP(i,m){string s; cin >> s; mp[s]--;}
    int ans = 0;
    for(auto x:mp){chmax(ans,x.second);}
    out(ans);

    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	string S=in<string>();
	map<int,ll> C;
	
	REP(i,N){
		C[S[i]-'a']++;
	}

	ll ans=1;
	for(auto& x:C){
		ans *= (x.second+1);
		ans %= atcoder_mod;
	}
	out((ans+atcoder_mod-1LL)%atcoder_mod);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  for(int w=0;w<n;w++){
  string s;
  cin >> s;
  char flag;
  char c,ans;
  int p =0;
  for(int i=0;i<s.size();i++){
    c = s[i]-'0';
    if(c==0&&flag!=0){
       p = 0;
       cout << ans;
     }
    if(c==1){
      if(p%5==0) ans = '.';
      if(p%5==1) ans = ',';
      if(p%5==2) ans = '!';
      if(p%5==3) ans = '?';
      if(p%5==4) ans = ' ';
      p++;
    }
    if(c==2){
      if(p%3==0) ans = 'a';
      if(p%3==1) ans = 'b';
      if(p%3==2) ans = 'c';
      p++;
    }
    if(c==3){
      if(p%3==0) ans = 'd';
      if(p%3==1) ans = 'e';
      if(p%3==2) ans = 'f';
      p++;
    }
    if(c==4){
      if(p%3==0) ans = 'g';
      if(p%3==1) ans = 'h';
      if(p%3==2) ans = 'i';
      p++;
    }
    if(c==5){
      if(p%3==0) ans = 'j';
      if(p%3==1) ans = 'k';
      if(p%3==2) ans = 'l';
      p++;
    }
    if(c==6){
      if(p%3==0) ans = 'm';
      if(p%3==1) ans = 'n';
      if(p%3==2) ans = 'o';
      p++;
    }
    if(c==7){
      if(p%4==0) ans = 'p';
      if(p%4==1) ans = 'q';
      if(p%4==2) ans = 'r';
      if(p%4==3) ans = 's';
      p++;
    }
    if(c==8){
      if(p%3==0) ans = 't';
      if(p%3==1) ans = 'u';
      if(p%3==2) ans = 'v';
      p++;
    }
    if(c==9){
      if(p%4==0) ans = 'w';
      if(p%4==1) ans = 'x';
      if(p%4==2) ans = 'y';
      if(p%4==3) ans = 'z';
      p++;
    }
    flag = c;
  }
  cout << endl;
}
}



Measured memory_bytes: 3220
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    x,n = map(int, input().split())
    p_list = list(map(int, input().split()))
    x_list = [i for i in range(0,200)]
    ans = 0
    min_abs = 10**3

    for i in p_list:
        x_list.remove(i)

    for j in x_list:
        if min_abs > abs(j-x):
            min_abs = abs(j-x)
            ans = j

    print(ans)
    
    

   
if __name__ == "__main__":
    main()

Measured memory_bytes: 9588
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 222222;
int a[N], sum[N];
int n;

int solve() {
    ina(n, a);
    rep(i, 1, n) {
        sum[i] = (sum[i - 1] + a[i]) % MOD;
    }
    int ans = 0;
    rep(i, 1, n - 1) {
        ans += a[i] * ((sum[n] - sum[i] + MOD) % MOD) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007

int main(){
 	int N,M;
  	cin >>N>>M;
  	priority_queue<int, vector<int>, greater<int>> pq;

  	rep(i,N){
    	int a; cin >>a;
      	pq.push(a);
    }
  	vector<P>memo(M);
  	rep(i,M){
   	int b,c;cin >>b>>c;
    memo[i]=P(c,b);
   }
  	sort(memo.begin(),memo.end());
  	reverse(memo.begin(),memo.end());
  	int flag=0;
  	rep(i,M){
    	auto x=memo[i];
    	int b=x.second,c=x.first;
      	rep(j,b){
          if(pq.top()>=c){flag=1;}
          else{pq.pop();pq.push(c);}
        }
      	if(flag==1){break;}
    }
  
  ll ans=0;
  while(!pq.empty()){
  	int x=pq.top();pq.pop();
    ans+=x;
  }
  cout<<ans;
}


Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int INF=100000000;

typedef pair<int,int> P;

char maze[60][60];
int h,w;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int d[60][60];
int gx=w-1,gy=h-1;

int bfs(){
    queue<P> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            d[i][j]=INF;
        }
    }
    que.push(P(0,0));
    d[0][0]=0;
    while(que.size()){
        P p=que.front();que.pop();
        if(p.first==gx&&p.second==gy)break;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i],ny=p.second+dy[i];
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&d[nx][ny]==INF&&maze[nx][ny]!='#'){
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[h-1][w-1];
}


int main(void){
    cin>>h>>w;
    int ans=h*w;;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>maze[i][j];
            if(maze[i][j]=='#')ans--;
        }
    }
    ans-=bfs();
    if(maze[0][0]=='#'||maze[h-1][w-1]=='#'||ans<0){
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<ans-1<<endl;
    return 0;
}


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

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return 0;
}

const int maxn=2000;
const int inf=0x3f3f3f3f;

int n,ans,a[maxn+10],b[maxn+10],sum[maxn+10],nxt[maxn+10],past[maxn+10],f[maxn+10];
char tmp[maxn+10];

inline int trans(int i,int x)
{
  if(i+x>n)
    {
      return i+x-n;
    }
  return i+x;
}

inline int getsum(int l,int r)
{
  if(r>=l)
    {
      return sum[r]-sum[l-1];
    }
  return sum[n]-sum[l-1]+sum[r];
}

int solve()
{
  for(int i=1; i<=n; ++i)
    {
      sum[i]=sum[i-1]+b[i];
    }
  for(int i=1; i<=n; ++i)
    {
      for(int j=0; j<n; ++j)
        {
          if(getsum(i,trans(i,j)))
            {
              nxt[i]=j;
              break;
            }
        }
      for(int j=0; j<n; ++j)
        {
          if(getsum(trans(i,n-j),i))
            {
              past[i]=j;
              break;
            }
        }
    }
  for(int i=0; i<n; ++i)
    {
      memset(f,0,sizeof f);
      int cnt=0;
      for(int j=1; j<=n; ++j)
        {
          if(a[j]!=b[trans(j,i)])
            {
              ++cnt;
              if(nxt[j]-i>0)
                {
                  f[past[j]-1]=std::max(f[past[j]-1],nxt[j]-i);
                }
            }
        }
      for(int j=n-1; j>=0; --j)
        {
          f[j]=std::max(f[j],f[j+1]);
          ans=std::min(ans,(f[j]+j)*2+i+cnt);
        }
    }
  return 0;
}

int main()
{
  scanf("%s",tmp+1);
  n=strlen(tmp+1);
  for(int i=1; i<=n; ++i)
    {
      a[i]=tmp[i]-'0';
    }
  scanf("%s",tmp+1);
  for(int i=1; i<=n; ++i)
    {
      b[i]=tmp[i]-'0';
    }
  int flag=0;
  for(int i=1; i<=n; ++i)
    {
      if(b[i])
        {
          flag=1;
          break;
        }
    }
  if(!flag)
    {
      for(int i=1; i<=n; ++i)
        {
          if(a[i])
            {
              flag=1;
              break;
            }
        }
      puts(flag?"-1":"0");
      return 0;
    }
  ans=inf;
  solve();
  std::reverse(a+1,a+n+1);
  std::reverse(b+1,b+n+1);
  solve();
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using P = pair<int, int>;

int main(){
    string s;
    cin >> s;
    int n = (int)s.size();
    bool flag = false;
    if (s[n-1]=='s') flag = true;
    cout << (flag? s+"es" : s+"s") << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)

const ll maxn=3e3+5, inf=0x3f3f3f3f3f3f3f3f;
string s,t;
ll m,n, dp[maxn][maxn];

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    cin>>s>>t;
    m=s.size(); n=t.size();
    rep(i,1,m+1) {
        rep(j,1,n+1) {
            if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i][j-1], dp[i-1][j]);
        }
    }
    string ans;
    ll a=m, b=n;
    while(a>0&&b>0) {
        if(dp[a][b]==dp[a-1][b]) a--;
        else if(dp[a][b]==dp[a][b-1]) b--;
        else ans+=s[a-1], a--, b--;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<"\n";
}

Measured memory_bytes: 70784
#include <iostream>

int main(void) {
	// in
	int r, d, x0;
	std::cin >> r >> d >> x0;
	
	int x = x0, x_buf;
	for(int i = 0; i < 10; ++i) {
		x_buf = r * x - d;
		x = x_buf;
		std::cout << x_buf << std::endl;
	}

	return 0;
}


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

int main() {
  int K, N;
  cin >> K >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  vector<int> vec1(N-1);
  for (int i = 0; i < N-1; i++) {
     vec1.at(i) = vec.at(i+1)-vec.at(i);
  }
  vec1.push_back(K-vec.at(N-1)+vec.at(0));
 for(int x:vec1){
    cerr << "debug " << x << endl;
  }
  
  // O(NlogN)
  sort(vec1.begin(), vec1.end());
  cout << K - vec1.at(N-1) << endl;
 
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n;
    cin>>n;
    ll ans = 0;
    for(int i = 1; i<= n; i++) ans += ((ll)i) * ((ll)n - i + 1);
    for(int i = 0; i< n-1; i++){
        int u, v;
        cin>>u>>v;
        if(u> v) swap(u,v);
        ans -= (ll)u * (n-v+1);
    }
    cout<<ans<<"\n";
}


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

const int MAX = 100010;
ll N, X, b[MAX], l[MAX], u[MAX], sum1[MAX], sum2[MAX];
vector<P> num;

bool chk(ll p){
	ll score = -1e18, cnt;
	if(p % X == 0){
		score = sum1[p/X] + sum2[N-(p/X)];
	}else{
		rep(i, N){
			int n = num[i].second;
			if((p/X)-1 >= i) cnt = sum1[(p/X)+1] - u[n]*(X-b[n]) + sum2[N-(p/X)-1];
			else cnt = sum1[p/X] + sum2[N-(p/X)] + l[n]*b[n];
			if((p%X) >= b[n]) cnt += u[n]*((p%X)-b[n]);
			else cnt += l[n]*((p%X)-b[n]);
			if(cnt > score) score = cnt;
		}
	}
	return (score >= 0);
}

int main(){
	cin >> N >> X;
	rep(i, N){
		cin >> b[i] >> l[i] >> u[i];
		num.push_back({u[i]*(X-b[i])+l[i]*b[i], i});
	}
	sort(num.begin(), num.end(), greater<P>());
	sum1[0] = 0, sum2[0] = 0;
	rep(i, N){
		int index = num[i].second, index2 = num[N-i-1].second;
		sum1[i+1] = sum1[i] + u[index]*(X-b[index]);
		sum2[i+1] = sum2[i] - l[index2]*b[index2];
	}
	ll ok = X*N, ng = -1;
	while(ok - ng > 1){
		ll mid = (ok + ng)/2;
		if(chk(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << "\n";
	return 0;
}


Measured memory_bytes: 5872