akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r,w;
ll l,ans,sum;
ll num;
ll x[500005],y[500005],z[500005];
char s[600][600];
ll dp[600][600];
ll check[600][600];
bool dame,flag,ok;
ll num0[800005],num1[800005];

void dfs(ll i,ll j,ll color){
	check[i][j] = num;
	if((i+j)%2 == 0)num0[num]++;
	if((i+j)%2 == 1)num1[num]++;
	for(ll k=0;k<4;k++){
		ll ni,nj;
		ni = i + dx[k];
		nj = j + dy[k];
		if(check[ni][nj] == 0 && dp[ni][nj] == color){
			dfs(ni,nj,color);
		}
	}

}
int main(){
	cin >> h >> w;
	for(i=0;i<h;i++){
		cin >> s[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j] == '#' && (i+j)%2 == 0){
				dp[i][j] = 1;
			}else if(s[i][j] == '#' && (i+j)%2 == 1){
				dp[i][j] = 2;
			}else if(s[i][j] != '#' && (i+j)%2 == 0){
				dp[i][j] = 2;
			}else{
				dp[i][j] = 1;
			}
		}
	}
	num = 1;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j] != '#')continue;
			if(check[i][j] == 0){
				dfs(i,j,dp[i][j]);
				if((i+j) % 2 == 0){
					ans += num1[num];
				}else{
					ans += num0[num];
				}
				num++;
			}else{
				if((i+j) % 2 == 0){
					ans += num1[check[i][j]];
				}else{
					ans += num0[check[i][j]];
				}
			}
			//pe(i);pe(j);p(ans);
		}
	}
	for(i=1;i<=num;i++){
		//pe(num0[i]);
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			//pe(check[i][j]);
		}
		//el;
	}
	p(ans);

			

	return 0;
}


Measured memory_bytes: 40960
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	coins := []int{25,10,5,1}
	num := 0
	for i := 0; i < len(coins); i++ {
		cn := n / coins[i]
		n -= cn * coins[i]
		num += cn
	}
	fmt.Println(num)
}


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

string str;
long long ans;
long long strToInt(int L,int R) {

    long long sum=0;

    for(int i=L; i<=R; i++) {
        sum*=10;
        sum+=(str[i]-'0');
    }

//    cout<<L<<" "<<R<<" "<<sum<<endl;

    return sum;
}

void recursion(int parent,int level,int mxlevel,vector<int>& positions) {

    if(level==mxlevel+1){

        for(int k=1;k<positions.size();k++)
           ans+=strToInt(positions[k-1],positions[k]-1);

        ans+=strToInt(0,positions[0]-1)+strToInt(positions[positions.size()-1],str.size()-1);

        return;
    }

    for(int i=parent+1; i<=(int)str.size()-mxlevel+(level-1); i++) {

        positions.push_back(i);
        recursion(i,level+1,mxlevel,positions);
        positions.pop_back();
    }


}

int main() {


    while(cin>>str) {

//        strToInt(0,1);

        ans=strToInt(0,str.size()-1);

        for(int cnt=1; cnt<str.size(); cnt++) {

           vector<int> pos;
           recursion(0,1,cnt,pos);

        }

        cout<<ans<<endl;


    }

    return 0;
}



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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

int main() {
  int n;
  cin >> n;
  REP(_, n){
    string order, message;
    cin >> order >> message;
    int l = ceil(message.length() / 2.);

    RREP(io, order.length()){
      auto o = order[io];
      switch (o) {
      case 'J':
        rotate(message.begin(), message.end() - 1, message.end());
        break;
      case 'C':
        rotate(message.begin(), message.begin() + 1, message.end());
        break;
      case 'E':
        REP(i, message.length() / 2){
          swap(message[i], message[i + l]);
        }
        break;
      case 'A':
        reverse(ALL(message));
        break;
      case 'P':
        REP(i, message.length()){
          if (!isdigit(message[i])) continue;
          message[i] = (message[i] - '0' + 9) % 10 + '0';
        }
        break;
      case 'M':
        REP(i, message.length()){
          if (!isdigit(message[i])) continue;
          message[i] = (message[i] - '0' + 1) % 10 + '0';
        }
        break;
      }
    }
    cout << message << endl;
  }
}

Measured memory_bytes: 3168
import itertools
r = 110000
s = int(r*0.5)
p = [1] * r
p[0] = 0
for i in range(1,s):
	if p[i]:
		p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
		
while 1:
	N,P = map(int,raw_input().split())
	if N == -1: break
	i = N + 1
	prime = []
	while len(prime) < 30:
		if p[i-1] == 1:
			prime.append(i)
		i += 1
	wa = sorted([sum(comb) for comb in itertools.combinations(prime,2)] + [2*a for a in prime])
	print wa[P-1]

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    string A, B, C; cin >> A >> B >> C;
    if(A[A.length()-1] == B[0] && B[B.length()-1] == C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3628
N=int(input())
if N==2:
    print(1)
    exit()
DN={N}
k=2
while(k*k<=N):
    if N%k==0:
        DN.add(k)
        DN.add(N//k)
    k+=1
DN1={N-1}
k=2
while(k*k<=(N-1)):
    if (N-1)%k==0:
        DN1.add(k)
        DN1.add((N-1)//k)
    k+=1
DN1=len(DN1)
#print(DN)
#print(DN1)
ans=0
for K in DN:
    tmp=N
    while(tmp>=K):
        if tmp%K==0:
            tmp//=K
        else:
            tmp%=K
    if tmp==1:
        ans+=1

#print(ans)
print(DN1+ans)


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

int main(){
    string s,t;
    cin>>s>>t;
    vector<int> ls(123,-1),lt(123,-1);
    for (int i=0;i<s.size();i++){
        if (ls[s[i]]==-1 && lt[t[i]]==-1){
            ls[s[i]]=t[i];
            lt[t[i]]=s[i];
        }
        else if (ls[s[i]]>=0 && lt[t[i]]>=0 && ls[s[i]]==t[i] && lt[t[i]]==s[i]){
        }
        else {
            cout<<"No"<<endl;
            exit(0);
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a <= c && c <= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 21972
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, m, ans;
int arr[105];

int main(){
    ios::sync_with_stdio(0);
    cin >> n >> m;
    forn(i,n){
        cin >> arr[i];
    }
    sort(arr,arr+n);
    ans = 0;
    forn(i,n){
        if(arr[i] <= m){
            ans++;
            m -= arr[i];
        }
    }

    ans += (m/arr[0]);

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

static const int N = 1000;

int lcs(string X, string Y) {
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int j = 1; j <= n; j++) {
        c[0][j] = 0;
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    string s1, s2;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}


Measured memory_bytes: 7076
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main(){
    string s;
    cin >> s;
    int slen = s.size();
    rep(i, slen-8){
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
(X, ) = [int(n) for n in input().split()]

L = 200
#while (L + 1) ** 5 -  L ** 5 <= X * 2:
#    L += 1   
#print(L)

for i in range(L+1):
    for j in range(L+1):
        if i ** 5 - j ** 5 == X:
            print('{} {}'.format(i, j))
            exit()
        elif i ** 5 + j ** 5 == X:
            print('{} {}'.format(i, -j))
            exit()


Measured memory_bytes: 9172
#include <stdio.h>
int main(void) {
	int W, H, x, y, r;

	scanf("%d %d %d %d %d\n", &W, &H, &x, &y, &r);

	if (-100<=x && x<=100 && -100<=y && y <= 100) {
		if (0 < W && W <= 100 && 0 < H && H <= 100 && 0 < r && r <= 100) {
			//?????????????????????????????????????????????????????¨???????????§??§?????????????????????
			//????????¢???????????¨?????§???????????????

			if (0 > (x - r) || W<(x + r) || 0>(y - r) || H < (y + r)) {
				printf("No\n");
			}

			else printf("Yes\n");

		}
		
	}

	return 0;
}

Measured memory_bytes: 584
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N, M;
	cin >> N >> M;
	int Sum = M * 1900 + (N - M) * 100;
	float p = pow(0.5f, M);
	cout << Sum / p << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> vi(n, 0);
	map<int, vector<int>> mp;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		mp[x].push_back(y);
		mp[y].push_back(x);		
	}
 
	int cnt1 = 1;
	for (int i = 0; i < n; i++) {
		if (vi[i] != 0) continue;
		cnt1++;
		queue<int> q;
		q.push(i + 1);
 
		while (!q.empty()) {
			int size = q.size();
			for (int j = 0; j < size; j++) {
				int el = q.front(); q.pop();
				vi[el - 1] = cnt1;
				for (int ii = 0; ii < mp[el].size(); ii++) {
					if (vi[mp[el][ii] - 1] == 0)
						q.push(mp[el][ii]);
				}
			}
		}

	}
	set<int> st;
	for (auto el : vi) st.insert(el);
	cout << st.size() - 1 << "\n";
	return 0;
}

Measured memory_bytes: 15144
#include<cstdio>

char a[1000005],q[1000005],s[1000005];
const long long mod=1000000007ll;
struct node{
    long long y,n;
    node(long long y=0,long long n=0):y(y%mod),n(n%mod){}
}z[1000005];
int qn,sn;

node cala(node a)
{
    return node(a.n,a.y);
}

node calb(node a,node b)
{
    return node(a.y*b.y,a.y*b.n+a.n*b.y+a.n*b.n);
}

node calc(node a,node b)
{
    return node(a.y*b.y+a.y*b.n+a.n*b.y,a.n*b.n);
}

void add(char a)
{
    if(a=='x')
        s[sn++]=a;
    else if(a=='|')
    {
        for(qn--;q[qn]=='|'||q[qn]=='&'||q[qn]=='~';s[sn++]=q[qn--]);
        qn++;
        q[qn++]=a;
    }
    else if(a=='&')
    {
        for(qn--;q[qn]=='&'||q[qn]=='~';s[sn++]=q[qn--]);
        qn++;
        q[qn++]=a;
    }
    else if(a=='~')
        q[qn++]=a;
    else if(a=='(')
        q[qn++]=a;
    else if(a==')')
        for(qn--;q[qn]!='(';s[sn++]=q[qn--]);
}

int main()
{
    int zn=-1;
    scanf("%s",a);
    add('(');
    for(int i=0;a[i];i++)
    {
        add(a[i]);
        if(a[i]=='x')
        {
            for(i++;a[i]>='0'&&a[i]<='9';i++);
            i--;
        }
    }
    add(')');
    for(int i=0;s[i];i++)
    {
        switch(s[i])
        {
        case 'x':
            z[++zn]=node(1,1);
            break;
        case '~':
            z[zn]=cala(z[zn]);
            break;
        case '&':
            zn--;
            z[zn]=calb(z[zn],z[zn+1]);
            break;
        case '|':
            zn--;
            z[zn]=calc(z[zn],z[zn+1]);
            break;
        }
    }
    printf("%lld\n",z[0].y);
    return 0;
}

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

int main(void){
    int num[3],K,max;
    for(int i=0;i<3;i++)
        cin>>num[i];
    cin>>K;
    sort(num,num+3);
    for(int i=0;i<K;i++){
        num[2]*=2;
    }
    max=num[0]+num[1]+num[2];
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<cstdlib>
using namespace std;

int main(){
  int n,l;
  cin>>n>>l;
  int a;
  for(int i=1;i<=n;i++){
    if(i==1)a=l;
    else{
    int x=abs(a),y=(l+i-1);
    if(y<x){
      a=l+i-1;
    }
  }
  }
int sum=0;
  for(int i=1;i<=n;i++){
    sum+=l+i-1;
  }
  cout<<sum-a;
}


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

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

	rep(i,T.size())
		if(T.at(i) == '?')
			T.at(i) = 'D';
	cout << T << endl;
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 1000010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 30);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

char s[N];

string str;

vector < int > v;

int Palin(){
    if(str.size() == 0) return 1;
    int lo = 0, hi = str.size() - 1;
    while(lo < hi){
        if(str[lo] != str[hi]){
            return 0;
        }
        lo++; hi--;
    }
    return 1;
}

int main(){
    scanf("%s", s);
    int len = strlen(s);
    str = "";
    for(int i = 0; i < len; i++){
        if(s[i] != 'x'){
            str += s[i];
            v.pb(i);
        }
    }
    if(Palin()){
        if(str.size() == 0) puts("0");
        else {
            int sz = v.size();
            int lo, hi;
            if(sz & 1){
                lo = v[sz / 2];
                hi = v[sz / 2];
            }else {
                lo = v[(sz / 2) - 1];
                hi = v[(sz / 2)];
            }
            int ans = 0;
            while(lo >= 0 || hi < len){
                if(s[lo] == s[hi] && lo >= 0 && hi < len){
                    lo--; hi++;
                }else {
                    if(s[lo] == 'x') lo--;
                    if(s[hi] == 'x') hi++;
                    ans++;
                }
            }
            printf("%d\n", ans);
        }
    }else {
        puts("-1");
    }
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,ans=0;
	cin>>n;
	int a[n],b[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
		cin>>b[i];
	for(i=0;i<n;i++)
		ans+=max(0,a[i]-b[i]);
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int N, Y;
    int a = 10000;
    int b = 5000;
    int c = 1000;
    int I = -1;
    int J = -1;
    int K = -1;

    cin >> N >> Y;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; i + j <= N; j++) {
            int k = N - i - j;
            if ((i + j + k == N) && (a * i + b * j + c * k == Y)) {
                I = i;
                J = j;
                K = k;
                break;
            }
        }
    }
    cout << I << " " << J << " " << K << endl;

    return 0;
}

Measured memory_bytes: 256
n,c = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ab = list(zip(a,b))
table = [[0 for i in range(c+1)] for j in range(401)]
mod = 10**9+7
for j in range(c+1):
  if j == 0:
    for i in range(401):
      table[i][j] = 1
  else:
    for i in range(401):
      table[i][j] = table[i][j-1]*i%mod
dp = [[0 for i in range(c+1)] for j in range(n+1)]
for i in range(c+1):
  dp[0][i] = 1
for i in range(1,n+1):
  a,b = ab[i-1]
  for j in range(a,b+1):
    for k in range(c+1):
      dp[i][k] = (dp[i][k]+table[j][k])%mod
ans = [[0 for i in range(c+1)] for j in range(n+1)]
ans[0][0] = 1
for i in range(1,n+1):
  for j in range(c+1):
    for k in range(j+1):
      ans[i][j] = (ans[i][j]+dp[i][k]*ans[i-1][j-k])%mod
print(ans[n][c])

Measured memory_bytes: 46684
using System;

namespace aoj
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = { 111, 222, 333, 444, 555, 666, 777, 888, 999 };
            for (int i = 0; i < A.Length; i++) {
                if (n <= A[i]) {
                    Console.WriteLine(A[i]);
                    break;
                }
            }
        }
    }
}


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

int main(){
	char ch, result;
	cin >> ch;
	switch(ch){
		case 'A':
			result = 'T';
			break;
		case 'T':
			result = 'A';
			break;
		case 'C':
			result = 'G';
			break;
		case 'G':
			result = 'C';
			break;
		default:
			break;
	}
	cout << result << endl;
	return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const int MOD = 1e9 + 7;
int sum(int a, int b) { return (a + b) % MOD; }
void add(int &a, int b) { a = sum(a, b); }
int prod(int a, int b) { return a * 1ll * b % MOD; }

void go(vvi &tree, int loc, int par, vi &order) {
    for (int nbr : tree[loc]) {
        if (nbr != par) {
            go(tree, nbr, loc, order);
        }
    }
    order.push_back(loc);
}

void combine(vi &f, vi &g, int fn, int gn, vi &dp1) {
    vi r(f.size());
    for (int i = 0; i <= fn; i++) {
        for (int p1 = 0; p1 < 2; p1++) {
            for (int j = 0; j <= gn; j++) {
                for (int p2 = 0; p2 < 2; p2++) {
                    int w = prod(f[i*2+p1], g[j*2+p2]);
                    if (i + j < f.size())
                        add(r[(i+j) * 2 + p1^p2], w);
                    add(r[i*2 + (p1^p2^1)], prod(w, dp1[j]));
                }
            }
        }
    }
    swap(f, r);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vvi tree(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        tree[u-1].push_back(v-1);
        tree[v-1].push_back(u-1);
    }

    vi order;
    go(tree, 0, 0, order);

    vi dp1(5000);
    dp1[0] = 1;
    for (int i = 2; i <= 5000; i++) {
        dp1[i] = prod(i - 1, dp1[i-2]);
    }

    vb done(N);
    vi size(N);
    vvi dp(N, vi(2*(N+1)));
    for (int v : order) {
        dp[v][1*2+0] = 1;
        size[v] = 1;
        for (int nbr : tree[v])
            if (done[nbr]) {
                combine(dp[v], dp[nbr], size[v], size[nbr], dp1);
                size[v] += size[nbr];
            }
        done[v] = true;
    }

    int ans = 0;
    for (int rc = 1; rc <= N; rc++) {
        for (int p = 0; p < 2; p++) {
            int t = prod(dp[0][rc*2+p], dp1[rc]);
            if (p&1) add(ans, MOD - t);
            else add(ans, t);
        }
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 196352
#include <iostream>
#include <set>

using namespace std;
using ll = long long;
using ld = long double;

const string YES = "YES";
const string NO = "NO";

int main() {
  int N;
  cin >> N;
  set<int> s;
  int a;
  for (int i = 0; i != N; ++i) {
    cin >> a;
    if (!s.insert(a).second) {
      cout << NO << endl;
      return 0;
    }
  }

  cout << YES << endl;
  return 0;
}


Measured memory_bytes: 9600
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

template<class T>bool chmax(T &a, const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}

template<class T>bool chmin(T &a, const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	int n,k;
	cin>>n>>k;
	int ans=0;
	rep(i,n){
		int h;cin>>h;
		if(h>=k)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  A
//
//  Created by Yoshinao Itakura on 2020/07/25.
//  Copyright © 2020 Yoshinao Itakura. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int X;
    cin >> X;
    if (400<=X && X<=599){
        cout << 8<<endl;
    }
    if (600<=X && X<=799){
        cout << 7<<endl;
    }
    if (800<=X && X<=999){
        cout << 6<<endl;
    }
    if (1000<=X && X<=1199){
        cout << 5<<endl;
    }
    if (1200<=X && X<=1399){
        cout << 4<<endl;
    }
    if (1400<=X && X<=1599){
        cout << 3<<endl;
    }
    if (1600<=X && X<=1799){
        cout << 2<<endl;
    }
    if (1800<=X && X<=1999){
        cout << 1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import bisect
 
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

ans = 0
for i in b:
  ai = bisect.bisect_left(a, i)
  # print(ai)
  ci = n - bisect.bisect_right(c, i)
  # print(ci)
  ans += ai*ci
print(ans)

Measured memory_bytes: 23208
// Includes

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cstdlib>

// Defines

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define mem(name, value) memset(name, value, sizeof(name))
#define f(i,a) for(int i=0;i<a;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int arr[100005],dp[100005];
int n,k;

int calc(int i) {
    if(i == n - 1)
        return 0;
    if(dp[i] != -1)
        return dp[i];
    int ans = 1e9;
    for(int j = 1;j <= k;++j) {
        if(j + i >= n)
            break;
        int temp = std::abs(arr[i + j] - arr[i]) + calc(i + j);
        ans = min(ans,temp);
    }
    return dp[i] = ans;
}

int main(){

/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    
    cin >> n >> k;
    f(i,n) {
        cin >> arr[i];
    }
    mem(dp,-1);

    cout << calc(0) << "\n";

    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
}


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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    string s;
    int n;
    cin>>s>>n;
    REP(i,0,RUP(s.length(),n)) cout<<s[0+n*i];
    cout<<ENT;
    return 0;
}


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


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

int n, a[200005], ord[200005], ct;
ll k;
bool seen[200005];

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

    cin >> n >> k;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    int st = 0;
    int len1=-1, len2=-1;
    while(ct < k)
    {
        if(seen[st])
        {
            len1 = ord[st];
            len2 = ct - ord[st];
            break;
        }
        ord[st] = ct++;
        seen[st] = true;

        st = a[st];
    }
    if(len1 == -1)
    {
        cout << st+1;
        return 0;
    }
    //what_is(len1);
    //what_is(len2);
    k = (k-len1)%len2;
    for(int i=0; i<k; i++)
    {
        st = a[st];
    }
    cout << st+1;
    return 0;
}


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

int solve(int N, int K, vector<int> targets)
{
    auto children = vector<vector<int>>(N);
    for (auto v = 1; v < N; v++)
        children[targets[v]].push_back(v);

    auto result = 0;
    if (targets[0] != 0) result++;
    function<int(int)> dfs = [&](int v)
    {
        auto depth = 0;
        for (auto c : children[v])
        {
            auto subtree_depth = dfs(c);
            if (subtree_depth != -1) depth = max(depth, subtree_depth+1);
        }
        if (depth == K-1 && targets[v] != 0)
        {
            result++;
            return -1;
        }
        else return depth;
    };
    for (auto c : children[0]) dfs(c);
    return result;
}

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

    auto targets = vector<int>(N);
    for (auto& x : targets)
    {
        cin >> x;
        x--;
    }

    cout << solve(N, K, targets) << endl;
}


Measured memory_bytes: 12800
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            StringBuilder sb = new StringBuilder();
            sb.append(b);
            if (a.equals(sb.reverse().toString())) out.println("YES");
            else out.println("NO");
        }

    }
}



Measured memory_bytes: 21844
#include <stdio.h>

long long fibodp(int n) {
    
    long long fibodp[200];
    fibodp[0] = 1;
    fibodp[1] = 1;
    for(int i =2; i<= n; i++){
        fibodp[i] = fibodp[i-1] +fibodp[i-2];
        
    }
    
    return fibodp[n];
}


int main(void){
    int a;
    scanf("%d",&a);
    printf("%lld\n",fibodp(a));
        
    return 0;
    
}


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

int main() {
  
  int a,b;
  string op;
  cin >> a >> op >> b;

    if (op == "+") {
       cout << a + b << endl;
    } else if(op == "-") {
     
      cout << a - b << endl;
    } 
     return 0; 


}


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

using namespace std;

const long long MAXN = 2e6;

int main () {
  long long n;
  cin >> n;
  vector <long long> pr, lp(MAXN);
  for (long long i = 2; i < MAXN; i++) {
        if (!lp[i]) pr.push_back(i), lp[i] = i;
        for (long long j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN; j++)
            lp[pr[j] * i] = pr[j];
    }
  if (n == 1) {
  	cout << 0;
  	return 0;
  }
  vector <pair <long long, long long>> factorization;
  long long i = 2;
    while (n != 1) {
        long long d;
    	if (n >= MAXN) {
    		d = n;
    		for (; i * i <= n; i++)
    			if (n % i == 0) {
    				d = i;
    				break;
    			}
    	}
    	else d = lp[n];
        factorization.push_back({d, 0});
        while (n % d == 0) {
            factorization.back().second++;
            n /= d;
        }
    }
  vector <long long> a;
  for (long long i = 0; i < factorization.size(); i++)
	a.push_back(factorization[i].second);
  long long ans = 0;
  for (auto &now : a) 
  	for (long long x = 0, sum = 0;sum <= now;sum += ++x, ++ans);
  cout << ans - a.size();
  return 0;
}

Measured memory_bytes: 21000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  vector<int>a;
  cin>>n;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a.push_back(x);
  }
  vector<int>ret;
  for(int t=0;t<n;t++){
    int pos = -1;
    for(int j=int(a.size())-1;j>=0;j--) {
      if (a[j] == j + 1) {
        pos = j;
        break;
      }
    }
      if(pos==-1){
        break;
      }
      ret.push_back(a[pos]);
      vector<int>tmp;
      for(int j=0;j<a.size();j++){
        if(j==pos)continue;
        tmp.push_back(a[j]);
      }
      a = tmp;
  }
  if(a.size()>0){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=n-1;i>=0;i--)cout<<ret[i]<<endl;
  return 0;
}

Measured memory_bytes: 256
fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn main() {
    let s: String = input_one().unwrap();
    let chars: Vec<_> = s.chars().collect();
    let charlen = chars.len();
    let mut result = 0;
    for i in 0..(charlen / 2) {
        if chars[i] != chars[charlen - i - 1] {
            result += 1;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,k,a[305];
long long dp[305][90005][2];
const long long mod=998244353;
long long qpow(long long a,long long b,long long mod){long long r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
int main()
{
    scanf("%d",&n);
    long long ans=0,sum=0;
    for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];
    dp[0][0][0]=dp[0][0][1]=1;
    for(i=1;i<=n;i++)
    {
        for(i0=0;i0<=sum;i0++)dp[i][i0][0]=2*dp[i-1][i0][0],dp[i][i0][1]=dp[i-1][i0][1];
        for(i0=a[i];i0<=sum;i0++)dp[i][i0][0]+=dp[i-1][i0-a[i]][0],dp[i][i0][1]+=dp[i-1][i0-a[i]][1];
        for(i0=0;i0<=sum;i0++)dp[i][i0][0]%=mod,dp[i][i0][1]%=mod;
    }
    //for(i=0;i<=sum;i++)printf("%d %lld----\n",i,dp[n][i]);
    for(i=(sum+1)/2;i<=sum;i++)ans+=dp[n][i][0];
    if(sum%2==0)ans-=dp[n][sum/2][1];
    //printf("%lld %lld\n",qpow(3,n,mod),ans*3);
    ans=ans*3%mod;
    ans=(qpow(3,n,mod)-ans)%mod;
    ans+=mod,ans%=mod;
    printf("%lld\n",ans);
    //ans=qpow(3,n,mod);
    //printf("%lld %lld\n",qpow(3,n,mod),ans*3);
    return 0;
}

Measured memory_bytes: 422912
import sys
sys.setrecursionlimit(10**6)

N,M=map(int, raw_input().split())
par=[ i for i in range(N+1)  ]

def root(x):
	if par[x]==x:
		return x
	else:
		par[x]=root( par[x] )
		return par[x]

def same(x,y):
	return root(x)==root(y)

def unite(x,y):
	x=root(x)
	y=root(y)
	if x==y: return
	par[x]=y


for i in range(M):
	x,y,z=map(int, raw_input().split())
	unite(x,y)


S=set()
for i in range(1,N+1):
	S.add(root(i))

print len(S)


Measured memory_bytes: 48796
#include <cstdio>

typedef long long ll;

const ll MAX_N = 100000;
ll N, x;
ll a[MAX_N + 1];

int main()
{
    scanf("%lld %lld", &N, &x);
    for(int i = 1; i <= N; i++){
        scanf("%lld", &a[i]);
    }

    ll answer = 0;
    for(int i = 1; i <=N; i++){
        if(a[i - 1] + a[i] > x){
            answer += a[i - 1] + a[i] - x;
            a[i] = x - a[i - 1];
        }
    }

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


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

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

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

class unionfind {
	vector<int> par, rank;
	vector<ll> bsum;

public:
	void init(int n, vi bs) {
		par.resize(n);
		rank.resize(n);
		bsum.resize(n);

		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
			bsum[i] = bs[i];
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return ;

		if (rank[x] < rank[y]) {
			par[x] = y;
			bsum[y] += bsum[x];
		} else {
			par[y] = x;
			bsum[x] += bsum[y];
		}

		if (rank[x] == rank[y]) ++rank[x];
	}

	bool same(int x, int y) { return (find(x) == find(y)); }

	ll sum(int v) {
		return bsum[find(v)];
	}
} uf;

const int maxn = 100010;
const ll INF = TEN(18);

vi g[maxn];
bool vis[maxn];
ll dp[maxn];

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

	vector<pii> vec(N);

	vi A(N), B(N), C(N);

	rep(i, N) {
		cin >> A[i] >> B[i];
		C[i] = max(A[i] - B[i], 0);
		vec[i] = mp(C[i], i);
	}

	uf.init(N, B);

	rep(i, M) {
		int a, b;
		cin >> a >> b; --a; --b;
		g[a].pb(b); g[b].pb(a);
	}

	sort(ALL(vec));

	rep(i, N) {
		int v = vec[i].se;
		vis[v] = true;

		ll mini = C[v];

		for (int to : g[v]) if (vis[to]) {
			mini = min(mini, max<ll>(C[v], dp[uf.find(to)]) - uf.sum(to));
		}
		for (int to : g[v]) if (vis[to]) {
			uf.unite(v, to);
		}

		dp[uf.find(v)] = mini + uf.sum(v);
	}

	cout << dp[uf.find(0)] << endl;

	return 0;
}

Measured memory_bytes: 10360
#include <stdio.h>

int linearSearch(int *,int,int);

int main() {
  int i,n,q,S[1000000],T[1000000],ans=0;


  scanf("%d",&n);
  for(i=0;i<n ;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q; i++) scanf("%d",&T[i]);

  for(i=0; i<q; i++){
    ans += linearSearch(S,T[i],n);
  }
  printf("%d\n",ans);

  return 0;
}


int linearSearch(int *A, int key, int n){
  int i=0;
  A[n] = key;
  while(A[i] != key){
    i++;
    if(i == n) return 0;
  }
    return 1;
}

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

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> grid (h);
    for(int i=0; i<h; i++){
        string st;
        cin >> st;
        grid.at(i) = st;
    }
    string ans = "Yes";
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(grid.at(i).at(j) == '.') continue;
            int count = 0;
            int cant = 0;
            if(i+1 <= h-1){
                count++;
                if(grid.at(i+1).at(j) == '.') cant++;
            }
            if(i-1 >= 0){
                count++;
                if(grid.at(i-1).at(j) == '.') cant++;
            }
            if(j+1 <= w-1){
                count++;
                if(grid.at(i).at(j+1) == '.') cant++;
            }
            if(j-1 >= 0){
                count++;
                if(grid.at(i).at(j-1) == '.') cant++;
            }
            if(count == cant){
                ans = "No";
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
ary = readlines.map &:chomp
index = []
(1..ary[0].to_i).each do |i|
  ary[i] = ary[i].split(' ')
  index.push (ary[i][0].to_i)
end
num = index.index(index.max)
result = ary[num+1][0].to_i
score = ary[num+1][-1].to_i
result+= score
print result

Measured memory_bytes: 26620
from collections import deque
def main():
    _map, _input, _int = map, input, int
    n, q = _map(_int, _input().split())
    values = [0] * n
    links = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = _map(_int, _input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    for _ in range(q):
        p, x = _map(_int, _input().split())
        values[p - 1] += x
    d = deque()
    d.append((0, -1))
    while len(d) != 0:
        i, p = d.popleft()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            d.append((j, i))
    print(*values)
main()

Measured memory_bytes: 62132
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 5000
#define MOD 1000000007

ll solve(ll level,ll X){
  if(X==0){
    return 0;
  }
  if(X==((1ull<<(level+2))-3)){
    return (1ull<<(level+1))-1;
  }
  ll x=(1ull<<(level+1))-1;
  if(X<x){
    return solve(level-1,X-1);
  }else if(X>x){
    return (1ull<<level)+solve(level-1,X-x);
  }else{
    return 1ull<<(level);
  }
}

int main(){
  ll N,X;
  cin>>N>>X;
  cout<<solve(N,X)<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    Map<String, String> enc = new HashMap<String, String>();
    Map<String, String> dec = new HashMap<String, String>();
    enc.put(" ", "101");
    enc.put("'", "000000");
    enc.put(",", "000011");
    enc.put("-", "10010001");
    enc.put(".", "010001");
    enc.put("?", "000001");
    enc.put("A", "100101");
    enc.put("B", "10011010");
    enc.put("C", "0101");
    enc.put("D", "0001");
    enc.put("E", "110");
    enc.put("F", "01001");
    enc.put("G", "10011011");
    enc.put("H", "010000");
    enc.put("I", "0111");
    enc.put("J", "10011000");
    enc.put("K", "0110");
    enc.put("L", "00100");
    enc.put("M", "10011001");
    enc.put("N", "10011110");
    enc.put("O", "00101");
    enc.put("P", "111");
    enc.put("Q", "10011111");
    enc.put("R", "1000");
    enc.put("S", "00110");
    enc.put("T", "00111");
    enc.put("U", "10011100");
    enc.put("V", "10011101");
    enc.put("W", "000010");
    enc.put("X", "10010010");
    enc.put("Y", "10010011");
    enc.put("Z", "10010000");
    dec.put("00000", "A");
    dec.put("00001", "B");
    dec.put("00010", "C");
    dec.put("00011", "D");
    dec.put("00100", "E");
    dec.put("00101", "F");
    dec.put("00110", "G");
    dec.put("00111", "H");
    dec.put("01000", "I");
    dec.put("01001", "J");
    dec.put("01010", "K");
    dec.put("01011", "L");
    dec.put("01100", "M");
    dec.put("01101", "N");
    dec.put("01110", "O");
    dec.put("01111", "P");
    dec.put("10000", "Q");
    dec.put("10001", "R");
    dec.put("10010", "S");
    dec.put("10011", "T");
    dec.put("10100", "U");
    dec.put("10101", "V");
    dec.put("10110", "W");
    dec.put("10111", "X");
    dec.put("11000", "Y");
    dec.put("11001", "Z");
    dec.put("11010", " ");
    dec.put("11011", ".");
    dec.put("11100", ",");
    dec.put("11101", "-");
    dec.put("11110", "'");
    dec.put("11111", "?");
    while (scanner.hasNext()) {
      String line = scanner.nextLine();
      String encStr = "";
      String decStr = "";
      for (int ii = 0; ii < line.length(); ii++) {
        encStr += enc.get(line.substring(ii, ii + 1));
      }
      if (encStr.length() % 5 != 0) {
        encStr += "0000";
      }
      encStr = encStr.substring(0, (encStr.length() / 5) * 5);
      for (int ii = 0; ii < encStr.length(); ii += 5) {
        decStr += dec.get(encStr.substring(ii, ii + 5));
      }
      System.out.println(decStr);
    }
  }
}

Measured memory_bytes: 46816
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	char s[100001];
	while(~scanf("%s", s)) {
		int K;
		scanf("%d", &K);
		int n = strlen(s);
		rep(i, n) {
			if(s[i] != 'a') {
				int k = 'z' + 1 - s[i];
				if(k <= K) {
					s[i] = 'a';
					K -= k;
				}
			}
		}
		s[n - 1] = (s[n - 1] - 'a' + K) % 26 + 'a';
		puts(s);
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> array = new ArrayList<>();
        array.add(sc.nextInt());
        array.add(sc.nextInt());

        if(!array.contains(1))
          System.out.println(1);
        else if(!array.contains(2))
          System.out.println(2);
        else
          System.out.println(3);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <fstream>
using namespace std;
typedef long long ll;

int main(){
   ll X,Y,a,b,c;
   cin>>X>>Y>>a>>b>>c;
   vector<ll> p(a),q(b),r(c),v;
   for(int i=0;i<a;i++)cin>>p[i];
   for(int i=0;i<b;i++)cin>>q[i];
   for(int i=0;i<c;i++)cin>>r[i];
   sort(p.rbegin(),p.rend());
   sort(q.rbegin(),q.rend());
   sort(r.rbegin(),r.rend());
   for(int i=0;i<X;i++)v.push_back(p[i]);
   for(int i=0;i<Y;i++)v.push_back(q[i]);
   for(int i=0;i<c;i++)v.push_back(r[i]);
   sort(v.rbegin(),v.rend());
   ll ans=0;
   for(int i=0;i<X+Y;i++)ans+=1ll*v[i];
   cout<<ans;
   
}

Measured memory_bytes: 8816