akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int dp[3030][3030];
int path[3030][3030]; // 左上1, 上2, 左3, 

int main() {
    string s, t;
    cin >> s >> t;
    rep(i,s.size()) {
        rep(j,t.size()) {
            if (s[i]==t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
                path[i+1][j+1] = 1;
            }
            else {
                if (dp[i][j+1]>dp[i+1][j]) {
                    dp[i+1][j+1] = dp[i][j+1];
                    path[i+1][j+1] = 2;
                } else {
                    dp[i+1][j+1] = dp[i+1][j];
                    path[i+1][j+1] = 3;
                }
            }
        }
    }
    string ans = "";
    int i = s.size();
    int j = t.size();
    while (i>0 && j>0) {
        switch (path[i][j]) {
            case 1: 
                --i; --j;
                ans += s[i];
                break;
            case 2:
                --i;
                break;
            case 3:
                --j;
                break;
        }
    
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}

















Measured memory_bytes: 71936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll f[3010][3010],a[3010];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		f[i][i]=a[i];
	}
	for (int l=1;l<n;l++)
	{
		for (int i=1;i+l<=n;i++)
		{
			int j=i+l;
			f[i][j]=max(a[i]-f[i+1][j],a[j]-f[i][j-1]);
		}
	}
	cout<<f[1][n]<<endl;
	return 0;
}


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

struct Star
{
    int x, y, d;
    Star () {}
    Star (int x, int y, int d) : x(x), y(y), d(d) {}
    bool operator < (const Star &p) const { return (d < p.d); }
};

int main()
{
    int N, D;
    Star data[200005];
    set < pair < int , int > > x, y;
    cin >> N >> D;
    for(int i = 0; i < N; i++) {
        int x, y, d;
        cin >> x >> y >> d;
        data[i] = Star(x, y, d);
    }
    sort(data, data + N);

    int l = 0, r = 0;
    ll maxv = 0;
    while(l < N) {
        while(r < N && data[r].d <= data[l].d + D) {
            x.insert(make_pair(data[r].x, r));
            y.insert(make_pair(data[r].y, r));
            r++;
        }
        maxv = max(maxv, (ll)((x.rbegin() -> first) - (x.begin() -> first)) * ((y.rbegin() -> first) - (y.begin() -> first)));
        x.erase(make_pair(data[l].x, l));
        y.erase(make_pair(data[l].y, l));
        l++;
    }
    cout << maxv << endl;
    return (0);
}



Measured memory_bytes: 24164
def check(x, y): 
    z = [0, 1, 2]
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
                break
            if x[j] == y[z[j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
        z = [z[2], z[0], z[1]]
        if i == 2:
            z = [z[0], z[2], z[1]]
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
for i in range(n):
    for j in range(i+1, n, 1): 
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int ans,n;
string s;

main() {
    cin >> s;
    n = pow(2,s.size()-1);
    rep(i,n) {
        int tmpn = i;
        string tmps;
        tmps.pb(s[0])
        rep1(j,s.size()-1) {
            if (tmpn%2) {
                ans += stoul(tmps);
                tmps.clear();
            }
            tmps.pb(s[j])
            tmpn /= 2;
        }
        ans += stoul(tmps);
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL "\n"
#define fillm(a,val) memset(a,val,sizeof(a))
typedef long long ll;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 1ll<<50;
const ll maxn = 100005;
ll t[maxn],x[maxn],y[maxn];
int main()
{
#ifdef LOCAL_SYS
	freopen("input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
	cin>>n;
	bool flag = 1;
	for(int i = 1;i<=n;i++)
	{
		cin>>t[i]>>x[i]>>y[i];
		ll tim = t[i]-t[i-1];
		ll dist = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
		ll rem= tim-dist;
		if(rem<0 || rem&1)
		{
			flag&=0;
		}
	}
	if(flag)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int t[100000],ma=0;
	for(int i=0;i<n;i++){
		cin>>t[i];
		ma=max(ma,t[i]);
	}
	int ans=0;
	vector<int> v;
	for(int i=1;i<=ma;i++)
		if(ma%i==0)v.push_back(i);
	for(int i=0;i<n;i++){
		for(int j=0;j<v.size();j++){
			if(v[j]>=t[i]){
				ans+=v[j]-t[i];
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



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

x = [0] * n
y = [0] * n
h = [0] * n

for i in range(n):
    x[i],y[i],h[i] = map(int,input().split())
    
ans_x = 0 
ans_y = 0  
ans_h = 0

for i in range(101):
    for j in range(101):
        H_candidate = []
        for k in range(n):
            if h[k] != 0:
                H_candidate.append(abs(x[k]-i)+abs(y[k]-j)+h[k])
        if len(set(H_candidate)) == 1:
            flag = True
            for k in range(n):
                if h[k] != max(H_candidate[0]-abs(x[k]-i)-abs(y[k]-j),0):
                    flag = False
            if flag:
                ans_x = i
                ans_y = j
                ans_h = H_candidate[0]
print(ans_x,ans_y,ans_h)

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

int main()
{
    int n;
    cin >> n;
    int Adj[n][n] = {};
    int time[n][2] = {};
    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            Adj[u - 1][v - 1] = 1;
        }
    }

    stack<int> s;
    int current_time = 1;
    for (int i = 0; i < n; i++)
    {
        if (time[i][0] == 0)
        {
            int src = i;
            s.push(src);
            while (!s.empty())
            {
                int cur = s.top();
                s.pop();
                //cout << cur << " " << current_time << endl;
                if (time[cur][0] == 0)
                {
                    time[cur][0] = current_time;
                    s.push(cur);
                    for (int dst = n - 1; dst >= 0; dst--)
                    {
                        //cout << cur << " " << dst << " " << Adj[cur][dst] << endl;
                        if (Adj[cur][dst] && time[dst][0] == 0)
                        {
                            s.push(dst);
                        }
                    }
                    current_time++;
                }
                else if (time[cur][0] != 0 && time[cur][1] == 0)
                {
                    time[cur][1] = current_time;
                    current_time++;
                }
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << i + 1 << " " << time[i][0] << " " << time[i][1] << endl;
    }

    return 0;
}



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

int solve(string S){
  vector<int> data;
  for(int i = 0; i < S.size()-1; ++i){
    if(S[i] == S[i+1]) data.push_back(i);
  }
  int ret = 0;
  while(data.size() >= 2){
    ++ret;
    int d = data.back();
    data.pop_back();
    if(d - data.back() == 1) data.pop_back();
  }
  if(data.size() == 1) ++ret;
  return ret;
}

int main(){
  string S;
  cin >> S;
  long long K;
  cin >> K;

  if(S.size() == 1){
    cout << (K>>1) << endl;
    return 0;
  }

  long long c1 = solve(S);
  long long c2 = solve(S+S);
  // long long c22 = solve(S+S+S[0]);
  // cout << c1 << " " << c2 << " " << c22 << endl;
  // cout << (K/2-1) << endl;
  // cout << c22 * (K/2-1) << endl;
  // cout << "test" << endl;
  // cout << solve(S+S[0]) << endl;
  // cout << solve(S+S+S[0]) << endl;
  // cout << solve(S+S+S+S[0]) << endl;
  // cout << solve(S+S+S+S+S[0]) << endl;
  // cout << "test" << endl;
  long long r1 = solve(S+S[0]);
  long long r3 = solve(S+S+S+S[0]);
  long long c22 = r3 - r1;

  if(K % 2 == 0){
    cout << (c22 * (K/2-1) + c2) << endl;
  }else{
    cout << (c22 * (K/2  ) + c1) << endl;
  }

  // string SS;
  // for(int i = 0; i < K; ++i) SS += S;
  // cout << solve(SS) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
int main() {
	char ch;

	while (1) {
		scanf("%c", &ch);

		if (islower(ch)) printf("%c", toupper(ch));
		else if (isupper(ch)) printf("%c", tolower(ch));
		else printf("%c", ch);

		if (ch == '\n') break;
	}

	return 0;
}



Measured memory_bytes: 3132
/*ASHWINI SHARMA*/
#include <bits/stdc++.h>

using namespace std;


#define fr(i,a,b) for (long long int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second


#define PI 3.1415926535897932385
#define INF 1000111222
#define EPS 1e-7
#define MAXN 1000001
#define MOD 1000000007
                                           /*ASHWINI SHARMA*/
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];

    // Storing the respective array
    // elements in pairs.
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    // Sorting the pair array.
    sort(pairt, pairt + n);

    // Modifying original arrays
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}

int main() {
    
    cin.sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    ll a[n];
    ll b[n];
    rep(i, n)
    cin >> a[i] >> b[i];
    pairsort(a, b, n);
    ll sum = 0;
    rep(i, n)
    {   
    	sum += min(m, b[i]) * a[i];
    	m -= min(m, b[i]);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main() {
    int h, w, n;
    int ans = 0;
    scanf("%d %d %d", &h, &w, &n);
    if(w>=h){
        ans = n/w;
        if(w*ans<n){
            ans++;
        }
    }
    if(h>w){
        ans = n/h;
        if(h*ans<n){
            ans++;
        }
    }
    printf("%d", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std ;
inline int Readin() {
	register int K = 0 , F = 1 ; register char C = getchar() ;
	while( C < '0' or C > '9' ) F = C == '-' ? -1 : 1 , C = getchar() ;
	while( C <= '9' and C >= '0' ) K = ( K << 1 ) + ( K << 3 ) + C - '0' , C = getchar() ;
	return F * K ;
}
int main() {
	int D = Readin() ;
	printf( "Christmas" ) ;
	while( D < 25 ) printf( " Eve" ) , ++D ;
	return not printf( "\n" ) ; 
}

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

bool a[11];

bool f(int n){
  int m = n;
  int ind;
  while(m > 0){
    ind = m % 10;
    m /= 10;
    if(!a[ind]) return true;
  }
  return false;
}

int main(void){
  for(int i = 0; i < 11; i++) a[i] = true;
  int n, k, temp;
  cin >> n >> k;
  for(int i = 0; i < k; i++){
    cin >> temp;
    a[temp] = false;
  }
  bool flag = true;
  temp = n - 1;
  while(flag){
    temp++;
    flag = f(temp);
  }
  cout << temp << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <utility>
#include <sstream>
#include <iterator>

using namespace std;
// #define int long long
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)


int main(int argc, const char * argv[]) {

    int N, L;

    cin >> N >> L;
    vector<int> myvec;
    rep(i, N){
      myvec.push_back( abs(L + i) );
    }
    int min_pos = distance(myvec.begin(),min_element(myvec.begin(),myvec.end()));
    
    int sum = 0;
    rep(i,N){
      sum += L + i;
    }

    // cout << sum << endl;
    sum -= L + min_pos ;
    cout << sum << endl;

    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  double x ;
  cin >> x ;
  x *=2;
  
  cout << x * 3.141592 ;
  


}


Measured memory_bytes: 3784
s = input()
t = input()
t = t[:-1]

flag = 0

if len(t) < len(s):
    flag = 1
else:
    for i in range(len(t)):
        if s[i] is not t[i]:
            flag = 1
            break
if flag is 0 :
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9116
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
    int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for (int i=0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }

    cout << "]" << endl;
}

int rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for (int i=0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

    for (int i=0; i < n; i++) {
        cin >> v >> d;
        for (int j=0; j < d; j++) {
            cin >> c;
            if (j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }

    for (int i=0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }

    rec(r, 0);

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

    return 0;
}


Measured memory_bytes: 7720
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int dp[100009],n,a[100009],b[100009];
vector<P>v1,v2;
vector<P>v[100009];

signed main(){
  r(i,100009)dp[i]=1e18;
  cin>>n;
  r(i,n)cin>>a[i];
  r(i,n)cin>>b[i];
  r(i,n){
    v1.push_back(P(b[i],i));
    v2.push_back(P(a[i],i));
  }
  sort(v1.begin(),v1.end());
  sort(v2.begin(),v2.end());
  r(i,n-1){
    for(int j=i+1,k=0;j<n&&k<20;k++,j++){
    int x=v1[i].se;
    int y=v1[j].se;
    int z=abs(v1[i].fi-v1[j].fi);
    v[x].push_back(P(y,z));
    v[y].push_back(P(x,z));}
  }
  r(i,n-1){
    for(int j=i+1,k=0;j<n&&k<20;k++,j++){
    int x=v2[i].se;
    int y=v2[j].se;
    int z=abs(v2[i].fi-v2[j].fi);
    v[x].push_back(P(y,z));
    v[y].push_back(P(x,z));}
  }
  priority_queue<P,vector<P>,greater<P> >q;
  r(i,n){
    if(!i){
      q.push(P(0,i));
      dp[i]=0;
    }
  }
  while(!q.empty()){
    P p=q.top();q.pop();
    int now=p.second;
    int cost=p.first;
    if(dp[now]<cost)continue;
    r(i,v[now].size()){
      int nex=v[now][i].fi;
      int nc=v[now][i].se+cost;
      if(dp[nex]<=nc)continue;
      dp[nex]=nc;
      q.push(P(nc,nex));
    }
  }
  r(i,n)cout<<dp[i]<<endl;
}


Measured memory_bytes: 234216
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = input()
    s_n = 0
    for char in n:
        s_n += int(char)
    print('Yes') if int(n) % s_n == 0 else print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  // read problem
  long long int N, K, tmp;
  std::vector<long long int> V;

  scanf("%lld%lld", &N, &K);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    V.push_back(tmp);
  }

  // solve problem
  long long int l, r, Kleft, anstmp;
  std::vector<long long int> take_jewels;

  long long int ans = 0;

  for(long long int l = -1; l < N; l++){
    for(long long int r = l+1; r <= N; r++){
      //std::cerr << l << " " << r << " " << N-(r-l-1) << std::endl;
      // if it is impossible to take as many jewels
      if(N - (r-l-1) > K){
        continue;
      }
      // make take_jevels
      take_jewels.clear();
      for(long long int i = 0; i <= l; i++){
        take_jewels.push_back(V[i]);
      }
      for(long long int i = r; i < N; i++){
        take_jewels.push_back(V[i]);
      }
      std::sort(take_jewels.begin(), take_jewels.end());

      

      // calculate answer
      Kleft = K - N + (r-l-1);
      for(long long int i = 0; i < N - (r-l-1) && i < Kleft; i++){
        if(take_jewels[i] < 0){
          take_jewels[i] = 0;
        }
        else{
          break;
        }
      }

      anstmp = 0;
      for(long long int i = 0; i < N - (r-l-1); i++){
        anstmp += take_jewels[i];
      }
      ans = std::max(ans, anstmp);

    }
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;



  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [[int(s) for s in input().split()], [int(s) for s in input().split()]]

cnt = [[0 for j in range(n)] for i in range(2)]

for i in range(2):
    for j in range(n):
        if j > 0:
            left = cnt[i][j-1]
        else:
            left = 0
        if i > 0:
            up = cnt[i-1][j]
        else:
            up = 0
        cnt[i][j] = a[i][j] + max(up, left)

print(cnt[1][n-1])


Measured memory_bytes: 3064
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int M = s.nextInt();
		int[][] dp = new int[M][2];
		for(int i = 0; i < M; i++) {
			dp[i][0] = s.nextInt();
			dp[i][1] = s.nextInt();
		}
		
		Arrays.sort(dp, (a, b) -> Integer.compare(a[1], b[1]));
		
		int cur = -Integer.MAX_VALUE;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			if(cur <= dp[i][0]) {
				ans++;
				cur = dp[i][1];
			}
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 92956
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;


#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

const int N = 2e5 + 5;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

	
//////////////////////////////code//////////////////////////////

int dp[100001];
vi adj[100001];
int ans = 0;

int dfs(int node){
   
   if(dp[node]!=-1)
   return dp[node];
    
    int a = 0;
    
    for(auto &c:adj[node])
    { 
        a = max(a,1 + dfs(c));
    }
    
    return dp[node]=a;
}


void solve()
{
   // cout << "-------------------" << "\n";
     
    int n,m;
    cin>>n>>m;
    
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        
        adj[u].pb(v);
    }
    
    memset(dp,-1,sizeof(dp));

    for(int i=1;i<=n;i++)
    {
        ans = max(ans,dfs(i));
    }
    
    cout<<ans<<"\n";
    
  //  cout << "-------------------" << "\n";

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

    int t = 1;
    //cin >> t;

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits


Measured memory_bytes: 11856
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

lint mod;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }

inline lint invm(lint a, lint p = mod) { a %= p; return a == 1 ? 1 : -p / a * invm(p % a) % p; }

inline lint powm(lint a, lint n, lint p = mod) { return !n ? 1 : powm(a * a % p, n >> 1, p) * (n & 1 ? a : 1) % p; }

V<lint> fact, ifact;
void init_table(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; i++) fact[i] = i * fact[i - 1] % mod;
  ifact[n] = invm(fact[n]);
  for (int i = n; i > 2; i--) ifact[i - 1] = i * ifact[i] % mod;
}

lint comb(lint n, lint r) {
  if (n < 0 or r < 0 or r > n) return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  lint n; cin >> n >> mod;
  init_table(n);
  VV<lint> s; assign(s, n + 2, n + 2);
  s[0][0] = 1;
  for (int i = 1; i < n + 2; i++) for (int j = 1; j < i + 1; j++) s[i][j] = (j * s[i - 1][j] + s[i - 1][j - 1]) % mod;
  lint res = powm(2, powm(2, n, mod - 1));
  for (int k = 1; k < n + 1; k++) {
    lint t = 0, c = 1, d = powm(2, n - k);
    for (int j = 0; j < k + 1; j++) {
      t = (t + c * s[k + 1][j + 1]) % mod;
      c = c * d % mod;
    }
    t = t * powm(2, powm(2, n - k, mod - 1)) % mod;
    res = (res - (k & 1 ? 1 : -1) * comb(n, k) * t) % mod;
  }
  cout << emod(res) << '\n';
}

Measured memory_bytes: 70784
import java.util.*;

public class Main {
    public static final long INF = Long.MAX_VALUE >> 2;
    public static final int SIZE = 110000;
    public static long[][] dp = new long[SIZE][3]; //制約に応じてテーブル規模を調節する
    //dp[DAY][DID] -> DAY日目までの幸福度の総和の最大値と、前日にした行動(DID)
    public static long[][] happiness = new long[SIZE][3];//制約に応じてテーブル規模を調節する
    //happiness[DAY][VALUE] -> DAY日目の幸福度(VALUE)
    public static void main(String[] args) throws Exception {
       for(int i=0;i<SIZE;++i){
           for(int j=0;j<3;j++){
                dp[i][j] = 0;   
           }
       }
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       for(int i=0;i<N;i++){
           for(int j=0;j<3;j++){
               happiness[i][j] = sc.nextInt();
           }
       }
       for(int i=0;i<N;i++){
               for(int j=0;j<3;j++){
                   for(int k=0;k<3;k++){
                       if(j == k) continue;
                       dp[i + 1][k] = Math.max(dp[i + 1][k],dp[i][j] + happiness[i][k]);
                   }
               }
           }
        long res = 0;
        for(int j=0;j<3;j++)res = Math.max(res,dp[N][j]);
        System.out.println(res);
       }
    }

Measured memory_bytes: 106644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int l = x - k +1; l = Math.max(l,-1000000);
		int r = k + x -1; r = Math.min(r,1000000);
		for(int i = l; i <= r; i++ ) {
			System.out.println(i);
		}
	}

}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int>a(A);
	vector<int>b(B);
	rep(i, A) {
		cin >> a[i];
	}
	rep(i, B) {
		cin >> b[i];
	}
	vector<int>X(M);
	vector<int>Y(M);
	vector<int>C(M);
	rep(i, M) {
		cin >> X[i] >> Y[i] >> C[i];
	}
	int ans = INT_MAX;
	rep(i, M) {
		ans = min(ans, a[X[i] - 1] + b[Y[i] - 1] - C[i]);
	}
	sort(a);
	sort(b);
	ans = min(ans, a[0] + b[0]);
	cout << ans << endl;
}


Measured memory_bytes: 2176
// abc150_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    string S;
    cin >> S;

    int cnt = 0;
    REP(i, N-2){
        if (S.substr(i, 3) == "ABC"){
            cnt++;
        }
    }

    print(cnt);


    return 0;
}


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

 
int main() {
    int n;
    cin >> n;
    int b[n - 1];
    for (int& x : b)
        cin >> x;
    int a[n];
    fill(a, a + n + 1, INF);
    for (int i = 0; i < n - 1; i++) {
        a[i] = min(a[i], b[i]);
        a[i + 1] = min(a[i + 1], b[i]);
    }
    int ans = 0;
    for (int z : a)
        ans += z;
    cout << ans;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
using namespace std;
int main(){
	string s;
	cin>>s;
	int n=s.size();
	string s1,s2;
	s1=s.substr(0,(n-1)/2);
	s2=s.substr((n+3)/2-1,(n-1)/2);
	//cout<<s<<" "<<s1<<" "<<s2<<endl;
	int f=1;
	for(int i=0;i<s.size();i++){
        if(s[i]!=s[n-i-1]) {
            f=0;
            break;
        }
	}
	for(int i=0;i<s1.size();i++){
        if(s1[i]!=s1[s1.size()-i-1]) {
            f=0;
            break;
        }
	}
	for(int i=0;i<s2.size();i++){
        if(s2[i]!=s2[s2.size()-i-1]) {
            f=0;
            break;
        }
	}
	if(f==0) printf("No");
	else printf("Yes");
	return 0;
}


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

int main(){
  ll x, y, z, k;
  cin >> x >> y >> z >> k;
  ll a[x], b[y], c[z];
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  ll ab[x*y];
  rep(i, x){
    rep(j, y){
      ab[i*y + j] = a[i] + b[j];
    }
  }
  sort(ab, ab+x*y, greater<ll>());
  ll K = 3000;
  ll v = min(K, x*y);
  ll abp[v], abc[v*z];
  rep(i, v) abp[i] = ab[i];
  rep(i, z){
    rep(j, v){
      abc[i*v + j] = c[i] + abp[j];
    }
  }
  sort(abc, abc+v*z, greater<ll>());
  rep(i,k) cout << abc[i] << endl;
  return 0;
}


Measured memory_bytes: 31616
N, M = map(int, input().split())
R = [i for i in range(N)]
def root(x):
  if R[x] == x:
    return x
  else:
    R[x] = root(R[x])
    return R[x]
def union(x, y):
  rx = root(x)
  ry = root(y)
  if rx < ry:
    R[ry] = rx
  else:
    R[rx] = ry
for i in range(M):
  x, y, z = map(int, input().split())
  union(x - 1, y - 1)
for i in range(N):
  root(i)
print(len(set(R)))

Measured memory_bytes: 13216
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long

using namespace std;

const int N = 2e5 + 5;

int arr[N], grid[200][200];

int main()
{
    int n, m, x, ind = 0;
    scanf("%d%d%d", &n, &m, &x);
    for(int i = 0 ; i < x ; i++) scanf("%d", arr + i);
    for(int i = 0 ; i < n ; i++)
    {
        if(i&1)
        {
            for(int j = m - 1 ; j >= 0 ; j--)
            {
                while(arr[ind] == 0 and ind < x) ind++;
                arr[ind]--;
                grid[i][j] = ind + 1;
            }
        }
        else
        {
            for(int j = 0 ; j < m ; j++)
            {
                while(arr[ind] == 0 and ind < x) ind++;
                arr[ind]--;
                grid[i][j] = ind + 1;
            }
        }
    }
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            printf("%d%c", grid[i][j], " \n"[j == m - 1]);
        }
    }
    return 0;
}


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

const unsigned long long bigp=(1ULL<<61)-1ULL;
const unsigned long long smallp=(1ULL<<31)-1ULL;
const unsigned long long smallpplus=(1ULL<<31);
const unsigned long long smallpminus=(1ULL<<30)-1ULL;

unsigned long long b=40787;

class hash_mod{
    public:
    unsigned long long val;
    unsigned long long val_u, val_d;
    unsigned long long another_u, another_d;
    unsigned long long m, m_u, m_d;

    void remainder(){
        val_u=(val>>61);
        val_d=val&bigp;
        if(val_u + val_d <bigp) val= val_u + val_d;
        else val= (val_u + val_d) -bigp;
    }

    void update(unsigned long long v){
        val=v;
        remainder();
    }

    void addition(unsigned long long another){
        val+=another;
        remainder();
    }

    void subtraction(unsigned long long another){
        val+=bigp;
        val-=another;
        remainder();
    }

    void multiple(unsigned long long another){
        val_u=(val>>31);
        val_d=val&smallp;
        another_u=(another>>31);
        another_d=another&smallp;
        m=val_u*another_d + val_d*another_u;
        m_u=(m>>30);
        m_d=m&smallpminus;
        val=0;
        val+=val_u*another_u*(2ULL);
        val+=m_u + m_d*smallpplus;
        val+=val_d*another_d;
        remainder();
    }
};

int main(){
    //input
    unsigned long long N;
    string S;
    cin >> N >> S;

    //calc
    unsigned long long i,j;
    hash_mod S_hash;
    char c='a';
    c--;
    hash_mod sub, b_pow;

    for(i=N/2; i>=1; i--){
        set<pair<unsigned long long, unsigned long long> > st;
        set<pair<unsigned long long, unsigned long long> >::iterator it, itne;
        b_pow.update(1ULL);
        for(j=0; j<i-1; j++){
            b_pow.multiple(b);
        }
        S_hash.update(0ULL);
        for(j=0; j<i; j++){
            S_hash.multiple(b);
            S_hash.addition((unsigned long long)(S[j]-c));
        }
        st.insert(make_pair(S_hash.val,0ULL));
        for(j=i; j<N; j++){
            sub.update((unsigned long long)(S[j-i]-c));
            sub.multiple(b_pow.val);
            S_hash.subtraction(sub.val);
            S_hash.multiple(b);
            S_hash.addition((unsigned long long)(S[j]-c));
            st.insert(make_pair(S_hash.val,j-(i-1)));
        }
        for(it=st.begin(); it!=st.end(); it++){
            itne=st.lower_bound(make_pair((*it).first+1ULL,0ULL));
            itne--;
            if((*it).second+i<=(*itne).second) break;
        }
        if(it!=st.end()) break;
    }

    //output
    cout << i << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3936
#include <iostream>

using namespace std;

int main(){
    int n;
    long long L[87];
    cin >> n;
    L[0] = 2;
    L[1] = 1;
    for(int i = 2; i <= n; i++){
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[n] << endl;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    input.push("EOF");
    for(var i=0;input[i]!="EOF";i++){
    	if(input[i].length>2){
    		num = input[i].split(" ");
    		console.log(Str(Int(num[0])+Int(num[1])).length);
    	}
    }
}
//??°????????????????????¢??°??¨(??????)
function ascendingOrder(val1,val2){
    return val1 - val2;
}
//??°????????????????????¢??°??¨(??????)
function descendingOrder(val1,val2){
    return val2 - val1;
}
//??°??????
function Int(str){
    return parseInt(str, 10);
}
//????????????
function Str(num){
    return num.toString(10);
}


//???????????°??¨
function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

//?????????????????\??????????????????
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 15976
k = int(input())
count = 0


def is_even(num):
    return num % 2 == 0


for i in range(1, k + 1):
    for j in range(i, k + 1):
        if (is_even(i) & (not is_even(j))) | (is_even(j) & (not is_even(i))) :
            count += 1

print(count)








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

const int MAXN = 100010;
const int mod = 1000000007;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int n, f[MAXN];
LL A[MAXN], X, Y;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> X >> Y; if (X < Y) std::swap(X, Y);
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	A[n + 1] = A[n] + X; ++n;
	f[0] = 1; A[0] = -X;
	int l = 0, r = 0;
	for (int i = 1; i <= n; ++i) {
		while (A[i] - A[r] >= X) ++r;
		if (i > 1 && A[i - 1] - A[i - 2] < Y) {
			if (A[i - 1] - A[l] < Y)
				return std::cout << 0 << std::endl, 0;
			l = i - 2;
		}
		// std::cout << "NOW " << i << ' ' << l << ' ' << r - 1;
		if (l < r) {
			reduce(f[i] += f[r - 1] - mod);
			if (l) reduce(f[i] -= f[l - 1]);
		}
		// std::cout << ' ' << f[i] << std::endl;
		if (i != n) reduce(f[i] += f[i - 1] - mod);
	}
	std::cout << f[n] << std::endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (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 FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, w;
    cin >> n >> w;
    std::vector<int> wei(n);
    std::vector<int> val(n);
    for (int i = 0; i < n; i++) {
        cin >> wei[i] >> val[i];
    }
    std::vector<int> dp(1e5 + 1, w + 1);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1e5; j >= 0; j--) {
            if (j == 0) {
                chmin(dp[val[i]], wei[i]);
            } else if (dp[j] == w + 1) {
                continue;
            } else {
                if (dp[j] + wei[i] <= w) {
                    chmin(dp[j + val[i]], dp[j] + wei[i]);
                }
            }
        }
    }
    for (int i = 1e5; i >= 0; i--) {
        if (dp[i] <= w) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
string s,t;
int main(){
  cin >> s >> t;
  if(s.length()<t.length()){
    cout << "UNRESTORABLE";
    return 0;
  }
  bool y=false;
  for (int i=s.size()-t.size(); i>=0; i--) {
    bool can=true;
    for (size_t l = 0; l < t.length(); l++) {
      if(s[i+l]!='?' && s[i+l]!=t[l]){
        can=false;
        break;
      }
    }
    if(can){
      for (size_t l = 0; l < t.length(); l++) {
        s[i+l] = t[l];
      }
      for (size_t l = 0; l < s.length(); l++) {
        if(s[l] == '?') s[l] = 'a';
      }
      y = true;
      break;
    }
  }
  if(y){
    cout << s;
  }else{
    cout << "UNRESTORABLE";
  }
}


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

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

struct ps{
    long long par, sz;
};

#define N 1e5+5
vector<ps> par(N);
long long Find(long long node){
    return par[node].par == node ? node : par[node].par = Find(par[node].par);
}
bool Union(long long u, long long v){
    long long pu = Find(u);
    long long pv = Find(v);
    if(pu != pv){
        par[pu].par = pv;
        par[pv].sz+=par[pu].sz;
        par[pu].sz = 1;
        return true;
    }
    return false;
}

vector<int> arr[100005];

int main()
{
    //textIO();
    fastIO();

    int n, m, k;
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++){
        par[i].par = i;
        par[i].sz = 1;
    }
    for(int i=0;i<m;i++){
        long long u, v;
        cin >> u >> v;
        Union(u, v);
        arr[u].push_back(v);
        arr[v].push_back(u);
    }
    for(int i=0;i<k;i++){
        long long u, v;
        cin >> u >> v;
        if(Find(u) == Find(v)){
            arr[u].push_back(v);
            arr[v].push_back(u);
        }
    }
    for(int i=1;i<=n;i++){
        cout << par[Find(i)].sz-arr[i].size()-1 << " ";
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 9464
#include <numeric>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    long long a[50]; for (int i = 0; i < n; i++) cin >> a[i];
    long long sum = accumulate(a, a+n, 0LL);
    long long k = max(0LL, sum - n * (n-1));
    while (true) {
        long long s = 0;
        for (int i=0; i<n; i++) {
            long long r = (a[i] + k + 1) / (n + 1);
            if (r == (a[i] + k) / (n + 1)) s += r;
            else { s = -1; break; }
        }
        if (s == k) { cout << s << endl; return 0; }
        k++;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
char s[10101];
int main()
{
	scanf("%d\n",&n);
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		int p=s[i]-'A'+1;
		p=(p+n-1)%26+1;
		s[i]=p+'A'-1;
		printf("%c",s[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int mn = 1000000007;

int main(void)
{
    string w;

    cin >> w;

    map<char, int> cn;
    for(int i = 0; i < w.size(); ++i)
    {
        ++cn[w[i]];
    }    

    bool b = true;

    for(auto iter = begin(cn); iter != end(cn); ++iter)
    {
        if(iter->second % 2 != 0)
        {
            b = false;
        } 
    }

    if(b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 3624
import collections

N, M = [int(i) for i in input().split()]

answers = []
for i in range(N):
    answers.extend([int(i) for i in input().split()][1:])
    
c = collections.Counter(answers)

cnt = 0
for k, v in c.items():
    if v == N:
        cnt += 1
print(cnt)


Measured memory_bytes: 3444
//
//  abc153_Raccon_Monster.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define PI 3.14159265


int main(int argc, const char* argv[]) {

  ll h, n;
  std::cin >> h >> n;

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    std::cin >> a;
    sum += a;
  }

  if (sum >= h) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            sf = (S[A-1:D+1].count('...'))
            if(sf == 0):
                print(NO)
            
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                if(tS[A-1:D+1].count('..b#') == 1):
                    print(NO)
                else:
                    print(YES)
            ######### あとはここだけ考える ####
            elif(sf >= 2):
                # print('Im here!')
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                ptS = tS.rfind('..b#')
                if(ptS == -1):
                    print(YES)
                else:
                    if(tS[ptS+3:D+1].count('...') == 0):
                        # print(tS[ptS:D])
                        print(NO)
                    else:
                        # print(tS[ptS:D])
                        print(YES)
        else: # D > Cの場合
            print(YES)  
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5364