akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e6 + 10,mod = 1e9 + 7;

int dp[N],fac[N],S[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-') ch = getchar();
	if(ch == '-') flag = -1,ch = getchar();
	while(isdigit(ch)) x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

int main() {

	int n = read(),h = read(),d = read(),sum = 0;
	fac[0] = 1;
	For(i,1,n) fac[i] = 1ll * fac[i - 1] * i % mod,sum = (sum + fac[i]) % mod;
	dp[0] = 1,S[0] = 1;
	For(i,1,h - 1) {
		dp[i] = 1ll * (S[i - 1] - (i - d - 1 < 0 ? 0 : S[i - d - 1]) + mod) * sum % mod;
		S[i] = (S[i - 1] + dp[i]) % mod;
	}
	int ans = 0;
	For(i,h - d,h - 1) ans = (ans + dp[i]) % mod;
	printf("%lld\n",1ll * ans * fac[n] % mod);
	return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n&1) {
    cout << (b[n/2]-a[n/2]+1) << endl;
  } else {
    cout << (b[n/2-1]+b[n/2]-a[n/2-1]-a[n/2]+1) << endl;
  }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,l;
  cin >> n >> l;
  vector<string> vs(n);
  rep(i,n){
    cin >> vs[i];
  }
  sort(all(vs));
  string res ="";
  rep(i,n){
    res += vs[i];
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
    string s;
    cin >> s;
    int check[26] = {0};
    for (int i = 0; i < s.length(); i++) {
        check[s[i] - 'a'] += 1;
    }/*
    for (int i = 0; i < 26; i++) {
        cout << check[i];
    }
    cout << endl;*/
    int cnt = 0;
    for (int i = 0; i < 26; i++) {
        if (check[i] == 0) {
            cnt++;
            printf("%c" , i + 'a');
            break;
        }
    }
    if (cnt == 0) {
        cout << "None" << endl;
    }
}


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

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 998244353


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 	int k;
 	cin>>k;

 	if (k%2==0 || k%5==0)
 	{
 		cout << "-1";
 		return 0;
 	}
 	int i = 0, rem = 0 ;
 	while(1)
 	{
 		i++;
 		rem = (rem*10 + 7)%k;
 		if (rem == 0)
 		{
 			cout << i << "\n";
 			return 0;
 		}
 	}
    
    return 0;
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n&&n){
    vector<ll> ans;
    vector<ll> P(n),Q(n),R(n),C(n),a(n);
    rep(i,n){
      cin >> a[i] >> P[i] >> Q[i] >> R[i];
      C[i] = (P[i]+R[i]) * 4 + Q[i] * 9;
    }
    ll p,q,r,c;
    cin >> p >> q >> r >> c;
    rep(i,n){
      if(P[i] <= p && Q[i] <= q && R[i] <= r && C[i] <= c){
        ans.pb(a[i]);
      }
    }
    if(ans.size())
    rep(i,ans.size()){
      cout << ans[i] << endl;
    }
    else
      cout << "NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3240
S = input()
while len(S)>0:
    if S[-7:] == "dreamer":
        S = S[:-7]
    elif S[-6:] == "eraser":
        S = S[:-6]
    elif S[-5:] == "dream":
        S = S[:-5]
    elif S[-5:] == "erase":
        S = S[:-5]
    else:
        break
print("YES" if len(S)==0 else "NO")

Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
bool cmp(const int A,const int B){
	return A>B;
}
int main(){
    int n,k,ans=0;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++){
    	scanf("%d",&a[i]);
	}
	sort(a,a+n,cmp);
	for(int i=0;i<k;i++){
		ans+=a[i];
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map(&:to_i)

s=a.inject(:+)
x=[s-(n*(n-1)+1), 0].max
# x=[a-(n*n*n+1), 0].max
y=x
a=a.map{|e| e+x}
a.each_with_index do |e, i|
  m=[e/(n+1), x].min
  a[i]-=m*(n+1)
  x-=m
end

raise if x!=0

while a.max>=n
  y+=1
  m=a.max
  i=a.index(m)
  n.times do |j|
    if i==j
      a[j]-=n
    else
      a[j]+=1
    end
  end
end

# puts a.join(' ')
puts y

=begin
5 5 4 3 => 17
1 6 5 4
2 2 6 5
3 3 2 6
4 4 3 2 => 13
0 5 4 3
1 1 5 4
2 2 1 5
3 3 2 1

9 9 8 7

10 3 2 1 => 16
6 4 3 2
2 5 4 3
3 1 5 4 => 13
4 2 1 5 => 12
5 3 2 1
1 4 3 2
2 0 4 3
3 1 0 4
4 2 1 0
0 3 2 1

13 6 5 4
3

=end


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

ll f(ll a){
    switch(a%4){
        case 0: return a;
        break;
        case 1: return 1LL;
        break; 
        case 2: return a^1;
        break;
        case 3: return 0LL;
        break;
        default:
        break;
    }
    return 0LL;
}

int main(){
    ll a, b;
    cin >> a >> b;
    cout << (f(a-1)^f(b)) << endl;
}

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

int main() {
    string s; cin >> s;
    for (int i = 0; i < s.length(); i++) {
        if (i == 5 || i == 13) cout << " ";
        else cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
N,D = map(int,input().split())
X_list = [list(map(int,input().split())) for i in range(N)]

ans = 0
import math
for i in range(N):
    for x in X_list[i+1:]:
        result = 0
        for j in range(D):
            result += (X_list[i][j]- x[j]) ** 2
        if math.sqrt(result).is_integer():
            #print(result,'result')
            #print(math.sqrt(result),'result')
            ans +=1

print(ans)

Measured memory_bytes: 3060
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	string sOrig = "CODEFESTIVAL2016";
	string sInput;
	int i,n=0;
	cin >> sInput;
	for (i = 0; i < sInput.length(); ++i){
		if (sInput[i] != sOrig[i])
			++n;
	}
	cout << n << endl;
endapp:
	//system("pause > nul");
	return 0;
}

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

#define ifor(a , b) for(int i = a ; i < b ; i++ )

using namespace std ;

int main()
{
  int n ;
  scanf("%d" , &n) ;
  int arr[n] ;
  ifor(0 , n) scanf("%d" , &arr[i]) ;
  int prod = 0 ;
  ifor(0 , n - 1)
  {
  	for(int j = i + 1 ; j < n ; j++)
    {
    	prod += (arr[i] * arr[j]) ;
    }
  }
  printf("%d" , prod) ;
  return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <cmath>
#include <set>

using namespace std;
#define iter(b) for(long long i = 1;i <= (b);i++)
#define VVI vector<vector<int>>



int main(){
    long long sum = 0;
    long long n;
    cin >> n;
    iter(n){
        if(i % 3 != 0 && i % 5 != 0) sum += i;
    }
    cout << sum;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

ll n,x;
vector<ll> v;

ll gcd(ll x, ll y) {
  if (y > x) swap(x,y);
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main() {
  cin >> n >> x;
  if (n == 1) {
    ll t;
    cin >> t;
    cout << abs(x - t) << endl;
    return 0;
  }

  rep(i,n) {
    ll t; cin >> t;
    v.pb(abs(t - x));
  }

  ll ans = 0;

  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    ans = gcd(*itr, ans);
  }

  cout << ans << endl;
}


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

using namespace std;
int main () {
  int t;
  cin>>t;int t2=t;
vector <string> s1;vector<int>t1;
  while(t-- > 0) {
  	string s;int y;
  	cin>>s>>y;
  	s1.push_back(s);
  	t1.push_back(y);
  }
  string s2;
  cin>>s2;
  int i,c;c=0;int k,j,b;
  for(i=0;i<t2;i++)
  {
  	int b=s2.compare(s1[i]);
  	
  	if(b==0)
  	{
	  
  	j=i;
  	break;
  }
  }
  for(k=j+1;k<t2;k++)
  c+=t1[k];
  cout<<c<<endl;
}
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

ll A, B, C, D;
ll INF = 1e18;

unordered_map<ll, ll> mp;

ll go(ll n) {
  if (n == 0)
    return 0;
  if (n == 1)
    return D;
  ll &res = mp[n];
  if (res == 0)
    res = INF;
  else
    return res;

  if (n % 2 == 0)
    res = min(res, go(n / 2) + A);
  else
    res = min(res, min(go((n - 1) / 2) + D + A, go((n + 1) / 2) + D + A));

  if (n % 3 <= 1)
    res = min(res, go(n / 3) + D * (n % 3) + B);
  else
    res = min(res, go(n / 3 + 1) + D + B);

  if (n % 5 <= 2)
    res = min(res, go(n / 5) + D * (n % 5) + C);
  else
    res = min(res, go(n / 5 + 1) + D * (5 - n % 5) + C);

  if (res / D >= n)
    res = min(res, n * D);

  debug("n = %lld  res %lld\n", n, res);
  return res;
}

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    mp.clear();
    ll N;
    scanf("%lld%lld%lld%lld%lld", &N, &A, &B, &C, &D);
    ll ans = go(N);
    printf("%lld\n", ans);
  }
  return 0;
}


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

int main(){
    int N,Y;
    cin >> N >> Y;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            int k = N - i- j;
            if(k<0) continue;
            int ans = 1000*i + 5000*j + 10000*k;
            if(ans == Y) {
                cout<<k<<" "<<j<<" "<<i;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll dp[25][100100];
int main(){
    ll n, m; cin >> n >> m;
    vector<ll> c;
    for (ll i = 0; i < m; i++) {
        ll x; cin >> x;
        c.push_back(x);
    }
    for (ll i = 0; i < 25; i++) {
        for (ll j = 0; j < 100100; j++) {
            if(j == 0) dp[i][j] = 0;
            else dp[i][j] = INF; 
        }
    }

    for (ll i = 0; i < m; i++) {
        for (ll j = 0; j <= n; j++) {
            if(j >= c[i]){
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-c[i]]+1);
            }
            dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
        }
    }
    
    cout<<dp[m][n]<<endl;
    return 0;
}


Measured memory_bytes: 22700
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int s,w;
  cin >> s >> w;
  if (s <= w){
    cout << "unsafe\n";
  }
  else{
    cout << "safe\n";
  }
  return 0;
}

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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int h, n;
  cin >> h >> n;
  int ans=h/n;
  if(h%n) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,M;
  cin >> N >> M;
  
  vector<int>s(M),c(M);
  for(int i=0; i<M; i++) cin >> s[i] >> c[i];
  
  
  if(M==0){
    if(N==1) cout << 0;
    if(N>1){
      cout << 1;
      for(int i=1; i<N; i++){
        cout << 0;
      }
   } 
    return 0;
  }///M=0の時の全パターン
  
  
  if(s[0]==1 && c[0]==0){
    if(N>1){
      cout << -1 << endl;
      return 0;
    }
  }
  for(int i=0; i<M-1; i++){ 
   if(s[i+1]==1 && c[i+1]==0){
     cout << -1 << endl;
     return 0;
   }
   for(int j=i+1; j<M; j++){
     if(s[i]==s[j] && c[i]!=c[j]){
       cout << -1 << endl;
       return 0;
     }
   } 
  }///-1を出力する時の全パターン
  
  
  
  for(int i=0; i<N; i++){
    bool Ans=false;
   for(int j=0; j<M; j++){
    if(s[j]==i+1){
      cout << c[j];
      Ans=true;
      break;
    }
   }
    if(Ans==false && i==0) cout << 1;
    else if(Ans==false) cout << 0;
  }
}

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 = 2147483647;

#define MAX_E 1001
#define MAX_V 100

struct edge{
    int to, cost;
    bool f;
};
typedef pair<int, int> P;

int V,E;
vector<edge> G[MAX_V];
int d[MAX_V];
int preV[MAX_V];

void input_graph(){
    int s,t,c;
    REP(i,E){
        cin>>s>>t>>c;s--;t--;
        G[s].push_back({t,c,false});
        G[t].push_back({s,c,false});
    }
}

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d+V, INF);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        REP(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                preV[e.to]=v;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
  cin>>V>>E;
  input_graph();
  REP(i,V){
    REP(j,V) preV[j]=-1;
    dijkstra(i);
    REP(j,V){
      int pre=preV[j],next=j;
      while(pre!=-1){
        REP(k,G[pre].size()) if(G[pre][k].to==next) G[pre][k].f=1;
        REP(k,G[next].size()) if(G[next][k].to==pre) G[next][k].f=1;
        next=pre;
        pre=preV[pre];
      }
    }    
  }
  int ans=E*2;
  REP(i,V) REP(j,G[i].size()) if(G[i][j].f) ans--;
  cout<<ans/2;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a_1(N), a_2(N), s(N);
  for (int i = 0; i < N; i++) cin >> a_1.at(i);
  for (int i = 0; i < N; i++) cin >> a_2.at(i);
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (j < i) {
        s.at(i) += a_1.at(j);
      } else if (j == i) {
        s.at(i) += a_1.at(j) + a_2.at(j);
      } else if (j > i) {
        s.at(i) += a_2.at(j);
      }
    }
  }
  
  sort(s.begin(), s.end());
  cout << s.at(N - 1) << endl;
}

Measured memory_bytes: 256
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;

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

	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; i++)
	{
		cin >> L[i];
	}
	sort(L.begin(), L.end());

	int ans = 0;
	for (int b = 0; b < N; b++)
	{
		for (int a = 0; a < b; a++)
		{
			int ab = L[a] + L[b];
			int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
			int l = b + 1;
			ans += r - l;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void fn(int n) {
   int x,y,z,ans,x2,y2,n2,n3;

   ans=0;
   for (x=1;x*x<=n;x++) {
      x2=x*x;n2=n-x2;
      for (y=1;y*y<=n2-x*y;y++) {
         y2=y*y;n3=n2-y2-x*y;
         for (z=1;z*z<=n3;z++)
            if (z*(x+y+z)==n3) ans++;
      }
   }
   printf("%d\n",ans);
}

int main(){
   int n,i;

   scanf("%d",&n);
   for (i=1;i<=n;i++) fn(i);
   return 0;
}


Measured memory_bytes: 1704
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);

		String T = sc.next();
		String S = sc.next();
      
		StringBuilder t = new StringBuilder();
		StringBuilder s = new StringBuilder();

		t.append(T);
		s.append(S);

		int count = 0;

		for(int i=0;i<t.length();i++) {      
			if(!t.substring(i,i+1).equals(s.substring(i, i+1))) count++;
		}

		System.out.println(count);

	}

}

Measured memory_bytes: 55376
'''from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
'''
S = input()
RLlist = [None]*len(S)
location = []
for i in range(len(S)-1):
    if S[i]=='R' and S[i+1] == 'L':
        RLlist[i] = 'r'
        RLlist[i+1] = 'l'
        location.append(i)

location.sort()
def findhigh(x, ylist):
    for i in range(len(ylist)):
        if x < ylist[i]:
            return ylist[i]


def findlow(x, ylist):
    for i in range(len(ylist)):
        if x < ylist[i]:
            return ylist[i-1]
    return ylist[-1]

ans_list = [1 if RLlist[i] != None else 0 for i in range(len(S))]

for i in range(len(S)):
    if S[i] == 'R' and RLlist[i] != 'r':
        high =findhigh(i,location) 
        diff = abs(high-i)
        if diff%2 == 1:
            ans_list[high+1]+=1
        else:
            ans_list[high]+=1
    if S[i] == 'L' and RLlist[i] != 'l':
        low = findlow(i, location)
        diff = abs(low-i)
        if diff%2 == 1:
            ans_list[low+1]+=1
        else:
            ans_list[low]+=1
        

print(*ans_list)

Measured memory_bytes: 52624
n, k = gets.split.map &:to_i
a = gets.split.map &:to_i
b = Array.new(n,0)
[k,41].min.times do
  for i in 0...n
    l = [0,i-a[i]].max
    r = [n-1,i+a[i]].min
    b[l] += 1
    b[r+1] -= 1 if r+1 < n
  end
  for i in 1...n
    b[i] += b[i-1]
  end
  a = b
  b = Array.new(n,0)
end

puts a.join(" ")

Measured memory_bytes: 82176
#include <cstdio>
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#define N 200005

int n, len;
std::string a[N];
std::unordered_map<std::string, int> cnt;

struct node {
    std::string val;
    int cnt;
} A[N];

inline bool cmp(const node &a, const node &b) { return a.cnt > b.cnt || a.cnt == b.cnt && a.val < b.val; }

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) std::cin >> a[i], ++cnt[a[i]];
    for (int i = 0; i < n; ++i)
        if (cnt[a[i]]) {
            A[++len].val = a[i];
            A[len].cnt = cnt[a[i]];
            cnt[a[i]] = 0;
        }
    std::sort(A + 1, A + len + 1, cmp);
    std::cout << A[1].val << std::endl;
    for (int i = 2; i <= len; ++i) 
        if (A[i].cnt != A[1].cnt) break;
        else std::cout << A[i].val << std::endl;
    return 0;
}


Measured memory_bytes: 29128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;


void solve()
{
	long long int X, Y;
	cin >> X >> Y;
	long long int cur = X;
	long long int cnt = 0;
	while (cur <= Y)
	{
		cur *= 2;
		++cnt;
	}
	cout << cnt << endl;
}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)){
		int a = scanner.nextInt();
		int b = scanner.nextInt();

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

}


Measured memory_bytes: 23636
a,b=map(int,input().split())
ans = 0
flag = True
if int(b/10)==0:
    ans+=a*10+b
elif int(b/10)>=1 and int(b/10)<=9:
    ans+=a*100+b
else:
    ans+=a*1000+b
for i in range(ans):
    tmp=i*i
    if tmp==ans:
        print("Yes")
        flag=False
        break
if flag:
    print("No")


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

int main() {
  int n;
  cin >> n;
  vector<pll> p(n);
  for(int i=0;i<n;i++) {
    ll x,y;
    cin >> x >> y;
    p[i]=pll(x,y);
  }
  sort(p.begin(), p.end());
  map<pll,ll> pq;
  for(int i=0;i<n-1;i++) {
    for(int j=i+1;j<n;j++) {
      pll temp=pll(p[j].first-p[i].first,p[j].second-p[i].second);
      pq[temp]++;
    }
  }
  ll many=0;
  for(auto num:pq) {
    many=max(many,num.second);
  }
  cout << n-many << endl;
}

Measured memory_bytes: 384
N = int(raw_input())

T = []
A = []

for n in range(N):
	t,a = [int(x) for x in raw_input().split(" ")]
	T.append(t)
	A.append(a)

cntA = A[0]
cntT = T[0]

for i in range(N-1):
	if A[i+1] < cntA or T[i+1] < cntT:
		x = -(-cntA // A[i+1]) 
		y = -(-cntT // T[i+1])

		cntA = max(x,y) * A[i+1]
		cntT = max(x,y) * T[i+1]


	else:
		cntA = A[i+1]
		cntT = T[i+1]

print cntA + cntT


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

struct star{int x,y,b;};

bool operator<(const star& s1,const star& s2){
    return s1.b < s2.b;
}

star s[200001];

int main() {

    int n;
    int d;

    cin >> n >> d;

    for(int i=0;i<n;i++){
        cin >> s[i].x >> s[i].y >> s[i].b;
    }

    sort(s,s+n);

    long long int ans = 0;

    map<int,int> x,y;

    for(int k=0,i=0;k<n;k++){

        x[s[k].x] += 1;
        y[s[k].y] += 1;

        while(s[i].b + d < s[k].b){
            x[s[i].x]--;
            y[s[i].y]--;
            if(x[s[i].x] == 0){
                x.erase(s[i].x);
            }
            if(y[s[i].y] == 0){
                y.erase(s[i].y);
            }
            i++;
        }

        long long int dx = x.rbegin()->first - x.begin()->first;
        long long int dy = y.rbegin()->first - y.begin()->first;

        ans = max(ans,dx*dy);

    }

    cout << ans << endl;





    return 0;
}

Measured memory_bytes: 17260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N , A , s;
 cin>> N >> A;
 s = N % 500 - A;
 if (s<=0) {   
 cout << "Yes" << endl;
 }
 else {
 cout << "No" <<endl;
 }
}

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

n,k = map(int, input().split())
h = list(map(int, input().split()))

if n<=k:
    print(0)
else:
    h = sorted(h, reverse=True)
    ans = sum(h)
    for i in range(k):
        ans -= h[i]
    print(ans)


Measured memory_bytes: 26024
#include <iostream>
#include <string>
using namespace std;
int n,b[77]={7, 17, 37, 47, 67, 97, 107, 127, 137, 157, 167, 197, 227, 257, 277, 307, 317, 337, 347, 367, 397, 457, 467, 487, 547, 557, 577, 587, 607, 617, 647, 677, 727, 757, 787, 797,
827, 857, 877, 887, 907, 937, 947, 967, 977,
997, 1087, 1097, 1117, 1187, 1217, 1237, 1277, 1297,
 1307, 1327, 1367, 1427, 1447, 1487, 1567, 1597, 1607,
 1627, 1637, 1657, 1667, 1697, 1747, 1777, 1787, 1847, 1867, 1877, 1907, 1987, 1997};
int len=0,len1=0,tmp;

int f(int x)//0是合数 1素数
{
    int i;
    for(i=2;i<x;i++)
    if(x%i==0) return 0;
    return 1;
}

int main()
{
    int x=2;
    int h=7;
    cin>>n;
    cout<<b[0];
    for(int i=1;i<n;i++)
    cout<<" "<<b[i];
    return 0;
}


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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    ll x;
//    x=1ll << 59;
//    ll y=(1ll << 59) - 1ll;
//    cout<<((double)(x)==(double)(x-1))<<endl;
    string a,b,c,d;
    ll x,y,s=0;
    cin>>x>>y;
    for(int i=x;i<=y;i++){
        a=to_string(i);b=a;
        reverse(a.begin(),a.end());
        if(a==b)s++;
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<climits>
#include<string>
#include<sstream>

#define pii pair<int,int>
#define ll long long
#define MOD 1000000007
#define in2d(i,j,H,W)(0<=i&&i<H&&0<=j&&j<W)

using namespace std;
struct UFT{
	vector<int>par;
	int getpar(int i){
		if(par[i]==i)return i;
		return par[i]=getpar(par[i]);
	}
	void unite(int i,int j){
		int t=getpar(i);
		par[t]=getpar(j);
	}
	bool uf(int i,int j){
		return getpar(i)==getpar(j);
	}
	UFT(int n){
		par=vector<int>(n);
		for(int i=0;i<n;i++)par[i]=i;
	}
	~UFT(){
		delete &par;
	}
};
struct SegT{
	vector<ll>container;
	int n;
	void update(int i,ll x){
		int ii=i+n-1;
		container[ii]=x;
		while(ii>0){
			ii=(ii-1)/2;
			//////////////////////////////////////////
			container[ii]=max(container[2*ii+1],container[2*ii+2]);
			//////////////////////////////////////////
		}
	}
	ll get(int l,int r,int l2=0,int r2=-1,int k=0){
		if(r2==-1)r2=n;
		if(r2<=l||r<=l2)return 0;
		if(l<=l2&&r2<=r)return container[k];
		ll vl=get(l,r,l2,(l2+r2)/2,2*k+1);
		ll vr=get(l,r,(l2+r2)/2,r2,2*k+2);
		///////////////////////////
		return max(vl,vr);
		///////////////////////////
	}
	////////////////new///////////////////////
	SegT(vector<int> &A){
		n=pow(2,(int)log2(A.size())+1);
		container=vector<ll>(2*n,0);
		for(int i=0;i<A.size();i++)update(i,A[i]);
	}
	~SegT(){
		delete &container;
	}

};
int main(){
	cout<<fixed<<setprecision(11);
	int N,M;cin>>N>>M;
	vector<pii >key(M,pii(0,0));
	for(int i=0;i<M;i++){
		cin>>key[i].first;
		int b;cin>>b;
		while(b--){
			int tmp;cin>>tmp;
			key[i].second+=(1<<(tmp-1));
		}
	}
	vector<int>dp((1<<N),INT_MAX);
	dp[0]=0;
	for(int k=0;k<M;k++)for(int i=0;i<(1<<N);i++)if(dp[i]!=INT_MAX){
		int j=i|key[k].second;
		//cout<<j<<endl;
		dp[j]=min(dp[j],dp[i]+key[k].first);
	}
	//for(int i=0;i<(1<<N);i++)cout<<dp[i]<<endl;
	int ans=dp[(1<<N)-1];
	if(ans==INT_MAX)ans=-1;
	cout<<ans<<endl;

	return 0;
}



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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  REP(i, N) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  vector<int> ans;
  REP(i, N - K + 1) {
    ans.push_back(h[i + K - 1] - h[i]);
  }
  cout << *min_element(ans.begin(), ans.end()) << endl;
  return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<long long> da(n);
	for (int i = 0;i < n;i++) {
		cin >> da[i];
	}
	sort(da.begin(), da.end());
	if (da[0] >= 0) {
		long long ans = -da[0];
		for (int i = 1;i < n;i++) {
			ans += da[i];
		}
		cout << ans << endl;
		for (int i = 1;i < n - 1;i++) {
			cout << da[0] << ' ' << da[i] << endl;
			da[0] -= da[i];
		}
		cout << da[n - 1] << ' ' << da[0] << endl;
	}
	else if (da[n - 1] < 0) {
		long long ans = da[n - 1];
		for (int i = 0;i < n - 1;i++) {
			ans -= da[i];
		}
		cout << ans << endl;
		for (int i = 0;i < n - 1;i++) {
			cout << da[n - 1] << ' ' << da[i] << endl;
			da[n - 1] -= da[i];
		}
	}
	else if (da[n - 2] <= 0) {
		long long ans = 0;
		for (int i = 0;i < n;i++) {
			ans += abs(da[i]);
		}
		cout << ans << endl;
		for (int i = 0;i < n-1;i++) {
			cout << da[n - 1] << ' ' << da[i] << endl;
			da[n - 1] -= da[i];
		}
	}
	else {
		long long ans = 0;
		for (int i = 0;i < n;i++) {
			ans += abs(da[i]);
		}
		cout << ans << endl;
		long long num = 0;
		while (da[num] < 0) {
			num++;
		}
		long long jio = num;
		num -= 1;
		while (num > 0) {
			cout << da[jio] << ' ' << da[num] << endl;
			da[jio] -= da[num];
			num--;
		}
		while (jio < n - 1) {
			cout << da[0] << ' ' << da[jio] << endl;
			da[0] -= da[jio];
			jio++;
		}
		cout << da[n - 1] << ' ' << da[0] << endl;
		return 0;
	}
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{
    vector<int> a;
    a = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    cin >> x >> y;
    if(a[x] == a[y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main(){
    int A,B,M; cin >> A >> B >> M;
    vector<int> a(A),b(B),x(M),y(M),c(M);
    for(int i = 0; i < A; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < B; i++) {
        cin >> b[i];
    }
    int cost=INT_MAX;
    for(int i = 0; i < M; i++) {
        cin >> x[i] >> y[i] >> c[i];
        cost = min(cost,a[x[i]-1]+b[y[i]-1]-c[i]);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    cost = min(cost, a[0]+b[0]);
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#define N 100

int main(){
  int A[N], n, i, j, minj, change, cont = 0;

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

  for(i=0; i<n-1; i++){
    minj = i;
    for(j=i; j<n; j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(A[i] != A[minj]){
    change = A[i];
    A[i] = A[minj];
    A[minj] = change;
    cont++;
    }  
  }

  for(i=0; i<n-1; i++)
    printf("%d ", A[i]);
  printf("%d\n", A[n-1]);
  printf("%d\n", cont);
  
  return 0;
}



Measured memory_bytes: 2136
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    int ans,a,b,c; cin >> a >> b >>c;
    ans = c-(a-b);
    if(ans<0){
        cout << "0" << endl;
    }
    else{
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 3656
import java.io.*;
import java.util.*;


/**
 * AIZU ONLINE JUDGE
 * 3123
 *  2020/5/1
 */
public class Main {



    boolean main() throws IOException {

        Scanner sc = new Scanner(systemin);

        int N = sc.nextInt();
        int M = sc.nextInt();


        System.out.printf("%d\n", N * M);

        sc.close();
        return false;
    }



    PrintStream log;
    PrintStream result = System.out;
    BufferedReader systemin;

    static Main instance = new Main();

    Main() {
        systemin = new BufferedReader(new InputStreamReader(System.in));
        log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    }

    public static void main(String[] args) throws IOException {

        instance.main();

        instance.systemin.close();
    }


}




Measured memory_bytes: 26376
pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

fn main(){
    let mut scan = Scanner::new();
    let s:i32 = scan.next();
    let w:i32 = scan.next();

    if s > w {
        println!("safe");
    }else{
        println!("unsafe");
    }
}


Measured memory_bytes: 2132
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int64_t pop(int64_t n, int64_t d) {
    int64_t ret = 0;
    for (;;) {
        const auto  q = n / d;
        const auto r = n % d;
        ret += r;
        if (q == 0) {
            break;
        }
        n = q;
    }
    return ret;
}


int main()
{
    int64_t N;
    std::cin >> N;

    int64_t ans = INT64_MAX;
    for (int64_t i = 0; i <= N; ++i) {
        ans = std::min(ans, pop(i, 6) + pop(N-i, 9));
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
def insert(tree,k):
    y = None
    x = tree
    z = {'key':k, 'parent':None, 'left':None, 'right':None}
    while x != None:
        y = x
        if x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    z['parent'] = y
    if y == None:
        tree = z
    elif y['key'] > k:
        y['left'] = z
    else:
        y['right'] = z
    return tree

def get_successor(x):
    if x['right'] != None:
        return get_minimum(x['right'])
    else:
        y = x['parent']
        while y != None and x == y['left']:
            x = y
            y = y['parent']
        return y

def get_minimum(x):
    while x['left'] != None:
        x = x['left']
    return x

def delete_node(tree,z):
    if z['left'] == None or z['right'] == None:
        y = z
    else:
        y = get_successor(z)

    if y['left'] != None:
        x = y['left']
    else:
        x = y['right']

    if x != None:
        x['parent'] = y['parent']

    if y['parent'] == None:
        tree = x
    else:
        if y['parent']['left'] != None and y['parent']['left']['key'] == y['key']:
            y['parent']['left'] = x
        else:
            y['parent']['right'] = x

    z['key'] = y['key']

    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            return x
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    return None

def middleorder(x):
    if x != None:
        middleorder(x['left'])
        print x['key'],
        middleorder(x['right'])

def preorder(x):
    if x != None:
        print x['key'],
        preorder(x['left'])
        preorder(x['right'])



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'f':
        x = find(tree, int(c[5:]))
        if x == None:
            print "no"
        else:
            print "yes"
    elif c[0] == 'd':
        z = find(tree, int(c[7:]))
        if not z == None: tree = delete_node(tree,z)
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print

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

int main() {
    int a,b;
    cin >> a >> b;
    string strA = "", strB = "";
    ostringstream ssA;
    ostringstream ssB;
    ssA << a;
    ssB << b;
    rep(i, b) strA = strA + ssA.str();
    rep(i, a) strB = strB + ssB.str();
    if (strA > strB)
        cout << strB << endl;
    else cout << strA << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

if S in T:
    print('0')
else:
    count = 0
    for i in range(len(S) - len(T) + 1):
        tmp = 0
        for p in range(len(T)):
            if S[i + p] == T[p]:
                tmp += 1
        
        if count < tmp:
            count = tmp
    
    print(len(T) - count)

Measured memory_bytes: 9124
#include<stdio.h>
#include<string.h>
int main(void)
{
  char add[100][10],sub[100][10];
  int i,j,count,max=0,n,m;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%s",add[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++)
  {
    scanf("%s",sub[i]);
  }
  for(i=0;i<n;i++)
  {
    count=0;
    for(j=0;j<n;j++)
    {
      if(strcmp(add[i],add[j])==0) count++;
    }
    for(j=0;j<m;j++)
    {
      if(strcmp(add[i],sub[j])==0) count--;
    }
    if(count>max) max=count;
  }
  printf("%d",max);
  return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var n int
	fmt.Scan(&n)
	// a := make(map[int]int, 0)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	sort.Ints(a)
	ans := 0
	prev, cnt := a[0], 1
	for i := 1; i < n; i++ {
		if a[i] == prev {
			cnt++
		} else {
			if cnt%2 != 0 {
				ans++
			}
			prev = a[i]
			cnt = 1
		}
		if i == n-1 && cnt%2 != 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int maxN = 100010; 
const int INF = 1000000000;
const int MOD = 1000000007;
char s[maxN];
ll f[maxN][4];
char t[4];
int main()
{
	scanf("%s",s+1);
	int len = strlen(s+1);
	ll ans = 0;
	t[1] = 'A';
	t[2] = 'B';
	t[3] = 'C';
	for(int i=0;i<=len;i++)
	{
		for(int j = 0;j<=3;j++)
		{
			if(i == 0)
			{
				f[i][j] = (j==0)?1:0;
			}
			else
			{
				if(s[i] == '?')
				{
					f[i][j] = 3ll*f[i-1][j];
				}
				else
					f[i][j] = f[i-1][j];
				if(j>0 && (s[i] == '?' || s[i] == t[j]))
				{
					f[i][j] += f[i-1][j-1];
				}
			}
			f[i][j] %= MOD;
		}
	}
	printf("%lld\n",f[len][3]);
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }
    vi cur(n+1), nxt(n+1);
    rep(i, n) cur[i] = a[i];
    rep(_, k) {
        rep(i, n+1) nxt[i] = 0;
        rep(i, n) {
            int x = max(0, i - cur[i]);
            int y = min(n-1, i+cur[i]);
            nxt[x] += 1;
            nxt[y+1] -= 1;
        }
        rep(i, n) nxt[i+1] += nxt[i];
        swap(cur, nxt);
        int mi = 1e9;
        rep(i, n) chmin(mi, cur[i]);
        if(mi == n) break;
    }
    rep(i, n) {
        cout << cur[i] << (i+1 == n ? '\n': ' ');
    }
    return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int d;cin>>d&&d;){
		cout<<"Christmas";
		rep(i,25-d) cout<<" Eve";
		cout<<endl;
	}
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

nums = [a, b, c, d, e]

for i in range(0, 5):
    if abs(nums[i] - nums[i-1]) > k:
        print(':(')
        exit()
print('Yay!')

Measured memory_bytes: 3064
import java.util.*
import java.io.PrintWriter



fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val cout = PrintWriter(System.`out`)
    val n = cin.nextInt()
    val b = Array<Int>(n - 1, { cin.nextInt() })

    var ans = 0

    for (i in 0..n-1) {
        if (i == 0) {
            ans += b[i]
        } else if (i == n-1) {
            ans += b[i-1]
        } else {
            if (b[i-1] < b[i]) {
                ans += b[i-1]
            } else {
                ans += b[i]
            }
        }
    }
    cout.println(ans)
    
    cout.flush()
}


fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

Measured memory_bytes: 31516