akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int n, r;
	cin >> n >> r;
	int res;
	if (n < 10) {
		res = 100 * (10 - n) + r;
	} else {
		res = r;
	}
	put(res);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  vector<vector<char>> in(h,vector<char>(w));
  vector<vector<char>> out(h,vector<char>(w));
  for(int i=0;i<h;++i)for(int j=0;j<w;++j)cin>>in[i][j];
  for(int i=0;i<h;++i)for(int j=0;j<w;++j)out[i][j]='.';
  
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      bool r=false;
      if(in[i][j]=='#'){
        if(i>0)if(in[i-1][j]=='#')r=true;
        if(i<h-1)if(in[i+1][j]=='#')r=true;
        if(j>0)if(in[i][j-1]=='#')r=true;
        if(j<w-1)if(in[i][j+1]=='#')r=true;
        if(r)out[i][j]='#';
      }
    }
  }
  for(int i=0;i<h;++i) for(int j=0;j<w;++j)if(in[i][j]!=out[i][j])return cout<<"No",0;
  cout<<"Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);
  int ans;
  //string ans;

  int n; string s; cin >> n >> s;
  rep(i, s.size()){
    s[i] += n;
  }
  rep(i, s.size()) if (s[i] > 'Z') s[i] -= 26;

  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[int(s) for s in input().split()]
b=0
for i in range(n):
  if a[i]%2==0:
    if a[i]%3!=0 and a[i]%5!=0:
      b+=1
if b==0:
  print("APPROVED")
else:
  print("DENIED")


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << (a + b - n > 0 ? a + b - n : 0) << "\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 rep1(i, n) for (int i = 1; i < (int)(n); i++)

int main() {
    string s;
    cin >>s;
    if (s=="Sunny")
        cout << "Cloudy";
    else if (s=="Rainy")
        cout << "Sunny";
    else if (s=="Cloudy")
        cout << "Rainy";

    return 0;
}


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

cs = list(map(int, input().split()))
_max = 10 ** 1000

dp = [_max for _ in range(n+1)]
dp[1] = 1
dp[0] = 0

for i in range(2, n+1):
    for c in cs:
        if i-c >= 0:
            dp[i] = min(dp[i], dp[i-c]+1)

print(dp[n])
 


Measured memory_bytes: 7376
#include<bits/stdc++.h>
using namespace std;
int n,m,t,ans,a[55];
int main(){
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++) ans+=a[i]*a[j];
  }
  cout<<ans<<endl;
  return 0;
}


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

int solve_small(const vector<int>& as)
{
    int n = as.size();
    map<int, int> mm;
    vector<bool> f(n, false);
    for (auto& a : as) {
        int t = mm[a]++;
        int ix = a - t - 1;
        if (ix >= 0)
            f[ix] = true;
    }

    int ret = 0;
    for (auto&& b : f) {
        if (!b)
            ret++;
    }
    return ret;
}

int main()
{
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<int> as(n);
    for (auto& a : as)
        cin >> a;

    vector<pair<int, int>> ps(m);
    for (auto& p : ps) {
        cin >> p.first >> p.second;
        p.first--;
    }

    // assert(n <= 200 && m <= 200);

    // for (auto& p : ps) {
    //     as[p.first] = p.second;
    //     cout << solve_small(as) << endl;
    // }

    vector<int> cnt(n + 1, 0);
    vector<int> cov(n + 1, 0);
    int cc = 0;
    for (auto& a : as) {
        cnt[a]++;
        int ix = a - cnt[a] + 1;
        if (ix > 0) {
            cov[ix]++;
            if (cov[ix] == 1)
                cc++;
        }
    }

    // for (auto& t : cov) {
    //     cout << "* " << t << endl;
    // }

    for (auto& p : ps) {
        int f = as[p.first];
        int t = p.second;
        as[p.first] = t;

        {
            int ix = f - cnt[f] + 1;
            if (ix > 0) {
                cov[ix]--;
                if (cov[ix] == 0) {
                    cc--;
                }
            }
            cnt[f]--;
        }
        {
            cnt[t]++;
            int ix = t - cnt[t] + 1;
            if (ix > 0) {
                cov[ix]++;
                if (cov[ix] == 1) {
                    cc++;
                }
            }
        }

        cout << (n - cc) << endl;
    }

    return 0;
}


Measured memory_bytes: 5376
N = int(input())
X = list(map(int,input().split()))
X.sort()
add = 0
mi = (X[0]-X[-1])**2*N
for i in range(X[0],X[-1]):
  for j in range(N):
    add += (X[j]-i)**2
  if add < mi:
    mi = add
    add = 0
print(mi)

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

int main()
{
    int n, m;
    cin >> n >> m;

    vector<lint> imos1(m * 2 + 1), imos2(m * 2 + 1);

    int a, anew;
    cin >> a;
    a %= m;
    lint sum_normal = 0;

    for (int i = 0; i < n - 1; i++)
    {
        cin >> anew;
        if (anew < a) anew += m;
        imos2[a+2]++;
        imos2[anew + 1] -= 1;
        imos1[anew + 1] -= anew - a - 1;

        sum_normal += anew - a;

        a = anew % m;
    }
    for (int i = 1; i < m * 2 + 1; i++) imos1[i] += imos1[i-1];
    for (int i = 1; i < m * 2 + 1; i++) imos2[i] += imos2[i-1];
    for (int i = 1; i < m * 2 + 1; i++) imos2[i] += imos2[i-1];

    // for (int i = 0; i < m * 2 + 1; i++)
    // {
    //     cout << imos1[i] << " " << imos2[i] << " " << imos1[i] + imos2[i] << endl;
    // }
    // cout << sum_normal << endl;

    lint maxtmp = 0;
    for (int i = 0; i < m; i++)
    {
        maxtmp = max(maxtmp, imos1[i] + imos2[i] + imos1[i+m] + imos2[i+m]);
    }
    cout << sum_normal - maxtmp << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec(200001, 0);
  int c = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++vec[a];
    c += vec[a] == 1;
  }

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

  int ans = 0;
  for (auto &v : vec) {
    if (c <= k)
      break;
    else if (v == 0)
      continue;
    else {
      ans += v;
      --c;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4020
points = []
for _ in range(3):
    points.append(list(map(int, input().split())))

N = int(input())
nums = []
for _ in range(N):
    nums.append(int(input()))


for num in nums:
    for i in range(3):
        if num in points[i]:
            j = points[i].index(num)
            points[i][j] = 0

if (points[0][0] == 0) and (points[1][0] == 0) and (points[2][0] == 0):
    print("Yes")
elif (points[0][1] == 0) and (points[1][1] == 0) and (points[2][1] == 0):
    print("Yes")
elif (points[0][2] == 0) and (points[1][2] == 0) and (points[2][2] == 0):
    print("Yes")
elif (points[0][0] == 0) and (points[0][1] == 0) and (points[0][2] == 0):
    print("Yes")
elif (points[1][0] == 0) and (points[1][1] == 0) and (points[1][2] == 0):
    print("Yes")
elif (points[2][0] == 0) and (points[2][1] == 0) and (points[2][2] == 0):
    print("Yes")
elif (points[0][0] == 0) and (points[1][1] == 0) and (points[2][2] == 0):
    print("Yes")
elif (points[0][2] == 0) and (points[1][1] == 0) and (points[2][0] == 0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
n = int(input())
H = [0]+list(map(int, input().split()))
dp = [0]*(n+1)
dp[2] = abs(H[2]-H[1])

for i in range(3, n+1):
  dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))

print(dp[-1])

Measured memory_bytes: 20704
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

class BComparingStrings {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		int a,b;cin >> a >> b;
		string s = "",t = "";
		for (int i = 0; i < a; ++i)
		{
			s += (char)('0' + b);
		}
		for (int i = 0; i < b; ++i)
		{
			t += (char)('0' + a);
		}
		cout << min(s,t) << endl;
	}
};


int main() {
	BComparingStrings solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

bool is_in(int a, int b, int c){
  return a <= b && b <= c;
}

int main()
{
  for (int T = in(); T--;){
    int X, Y, W, H;
    int N;
    cin >> X >> Y >> W >> H;
    cin >> N;

    int cnt = 0;
    for (int i = 0; i < N; i++){
      int x, y;
      cin >> x >> y;
      if (is_in(X, x, X + W) && is_in(Y, y, Y + H)) cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1236
coins = (10,50,100,500)
isfirst = True
while 1:
    cost = int(raw_input())
    if cost == 0: break
    if not isfirst: print
    have = map(int,raw_input().split())

    budget = sum(i*j for i,j in zip(coins,have))
    change = budget-cost

    ans = [0]*4
    for i in reversed(range(4)):
        c = change/coins[i]
        ans[i] = c
        change -= c*coins[i]

    for i in range(4):
        if have[i]-ans[i] <= 0: continue
        print coins[i],have[i]-ans[i]

    isfirst = False

Measured memory_bytes: 4240
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  string s;
  cin>>s;
  if(s[2]==s[3] && s[4]==s[5])
  cout<<"Yes\n";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        boolean[] snuke = new boolean[N];
        for(int i = 0 ; i < N ; i++){
            snuke[i] = true;
        }

        for(int i = 0 ; i < K ; i++){
            int d = sc.nextInt();
            for(int j = 0 ; j < d ; j++){
                snuke[sc.nextInt()-1] = false;
            }
        }

        int ans = 0;
        for(int i = 0 ; i < N ; i++){
            if(snuke[i]){
                ans++;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 46564
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, m, p, correct = 0, penalty = 0;
   string s;
   cin >> n >> m;
   bool isAC[n] = {};
   int WAcount[n] = {};
   FOR(i, 0, m)
   {
      cin >> p >> s;
      if (!isAC[p - 1])
      {
         if (s == "AC")
         {
            correct++;
            penalty += WAcount[p - 1];
            isAC[p - 1] = true;
         }
         else
         {
            WAcount[p - 1]++;
         }
      }
   }
   printf("%d %d\n", correct, penalty);
   return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, m;
    cin >> n >> m;
    ll l = 0, r = LLONG_MAX;
    for (ll i = 0; i < m; i++)
    {
        ll tl, tr;
        cin >> tl >> tr;
        l = max(l, tl);
        r = min(r, tr);
    }
    if (l > r)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << r - l + 1 << endl;
    }
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &i : a) {
		cin >> i;
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	int alice = 0, bob = 0;
	for (int i = 0; i < n; i++) {
		((i % 2 == 0) ? alice : bob) += a[i];
	}
	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1);





int main() 
{
  ll L,R,d; cin>>L>>R>>d;
  ll ans=0;
  for(int i=L;i<=R;i++)
  {
    if(i%d==0) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3620
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

struct edge {
	ll to;
	ll cost;
};
typedef pair<ll, ll> P;
vector<vector<edge>> G;
int N, u, v, ans = 0;
vector<int> adist,bdist;

void dfs1(int pos, int depth) {
	adist[pos] = depth;
	for (int i = 0; i < G[pos].size(); i++) {
		if (adist[G[pos][i].to] != -1)continue;
		dfs1(G[pos][i].to, depth + 1);
	}
}

void dfs2(int pos, int depth) {
	bdist[pos] = depth;
	for (int i = 0; i < G[pos].size(); i++) {
		if (bdist[G[pos][i].to] != -1)continue;
		dfs2(G[pos][i].to, depth + 1);
	}
}


int main() {
	cin >> N >> u >> v;
	G = vector<vector<edge>>(N + 1);
	bdist = adist = vector<int>(N + 1, -1);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		G[a].push_back({ b,1 });
		G[b].push_back({ a,1 });
	}
	dfs1(v, 0); dfs2(u, 0);
	for (int i = 1; i <= N; i++) {
		//if (G[i].size() == 1) {
			if (bdist[i] < adist[i]) {
				ans = max(ans, adist[i]);
			}
		//}
	}
	cout << ans - 1 << endl;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
  ll n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> sum(n);
  sum[0] = a[0];
  for(int i=1;i<n;i++) sum[i]= sum[i-1]+a[i];
  ll max_sum = sum[k-1];
  for(int i =1; i<(n-k+1);i++){
    max_sum=max(sum[i+k-1]-sum[i-1],max_sum);
    //cout << sum[i+k-1]-sum[i-1] << endl;
  }
  double ans = max_sum+k;
  ans /=2;
  printf("%.10f\n", ans);
}

Measured memory_bytes: 2560
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = "CODEFESTIVAL2016";
        int ans = 0;
        for(int i=0;i<16;i++){
            if(s.charAt(i)!=t.charAt(i)) ans++;
        }
        System.out.println(ans);
    }
}


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

using namespace std;
//C - Five Transportations
int main(void){
    long long n;
    std::cin >> n;
    long long minP=LLONG_MAX;
    for (int i = 0; i < 5; i++) {
        long long p;
        std::cin >> p;
        if(minP>p){
            minP=p;
        }
    }
    std::cout << 5+(n-1)/minP << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
struct node{int to,nxt;}sq[200200];
int all=0,head[100100];
int n,k,dep[100100],son[100100];
ll fac[100100],invfac[100100];

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

void add(int u,int v)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;
}

ll qpow(ll x,int y)
{
	ll ans=1;
	while (y)
	{
		if (y&1) ans=ans*x%maxd;
		x=x*x%maxd;y>>=1;
	}
	return ans;
}

void dfs(int u,int fu)
{
	dep[u]=dep[fu]+1;
	for (int i=head[u];i;i=sq[i].nxt)
	{
		int v=sq[i].to;
		if (v==fu) continue;
		dfs(v,u);son[u]++;
	}
}

ll A(int n,int m)
{
	if (n<m) return 0;
	return fac[n]*invfac[n-m]%maxd;
}

int main()
{
	n=read();k=read();
	fac[0]=invfac[0]=1;
	rep(i,1,N) fac[i]=fac[i-1]*i%maxd;
	invfac[N]=qpow(fac[N],maxd-2);
	per(i,N-1,1) invfac[i]=invfac[i+1]*(i+1)%maxd;
	rep(i,1,n-1)
	{
		int u=read(),v=read();
		add(u,v);add(v,u);
	}
	ll ans=k;
	dfs(1,0);
	//rep(i,1,n) cout << i << " " << son[i] << endl;
	rep(i,1,n)
	{
		if (dep[i]==1) ans=ans*A(k-1,son[i])%maxd;
		else ans=ans*A(k-2,son[i])%maxd;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 8064
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    map<int, int> mapa;
    rep(i, 0, n) {
        int x;
        cin >> x;
        mapa[x]++;
    }
    for (auto &it : mapa) {
        if (it.se >= 3) {
            if (it.se % 2 == 1) {
                it.se = 1;
            } else {
                it.se = 2;
            }
        }
    }
    int tot = 0, bad = 0;
    for (auto &it : mapa) {
        tot += it.se;
        if (it.se == 2) {
            bad++;
        }
    }
    tot -= (bad + 1) / 2 * 2;
    cout << tot << "\n";
    return 0;
}

Measured memory_bytes: 4992
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"20"# => r#"23"#,
r#"2"# => r#"2"#,
r#"99992"# => r#"100003"#,
}

fn is_prime(x: usize) -> bool {
    if x <= 1 {
        return false;
    }
    for i in 2..x {
        if x % i == 0 {
            return false;
        }
    }
    return true;
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        x: usize,
    }

    let mut p = x;
    while is_prime(p) == false {
        p += 1;
    }

    p.to_string()
}

Measured memory_bytes: 4352
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>arr(n-1);
    ll ans=0;
    for(ll i=0;i<(n-1);i++)
    {
        cin>>arr[i];
    }
    ans+=arr[0];
    ans+=arr[n-2];
    for(ll i=1;i<(n-1);i++)
    {
        ans+=min(arr[i],arr[i-1]);
    }
    cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 256
from sys import stdin, exit

a, b = (int(x) for x in stdin.readline().rstrip().split())

i = 1
while i <= 1000:
    if (int(i * 0.08) == a) and (int(i * 0.1) == b):
        print(i)
        exit()
    else:
        i += 1
print(-1)

Measured memory_bytes: 3060
#include <iostream>

int main() {
        int n;
        std::cin >> n;

        bool find = [n] {
                for (auto cake = 0; cake <= n; cake += 4) {
                        for (auto donut = 0; donut <= n; donut += 7) {
                                if (cake + donut == n) {
                                        return true;
                                }
                        }
                }
                return false;
        }();

        if (find) {
                std::cout << "Yes" << std::endl;
        }
        else {
                std::cout << "No" << std::endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

// [l, r]
ll dfs(int l, int r, vvl &dp, vl const &a) {
    if (dp[l][r] != -1)
        return dp[l][r];
    if (l == r)
        return dp[l][r] = 0;
    ll mini = INF;
    for (int m = l; m < r; ++m) {
        chmin(mini, dfs(l, m, dp, a) + dfs(m + 1, r, dp, a) + a[r] - (l == 0 ? 0 : a[l - 1]));
    }
    return dp[l][r] = mini;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i < n; ++i) {
        a[i] += a[i - 1];
    }
    vvl dp(n, vl(n, -1));
    cout << dfs(0, n - 1, dp, a) << "\n";
    return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var NK = IO.RSLong;
            var a = IO.RSLong;

            var cum = new long[NK[0] + 1];
            for (int i = 0; i < NK[0]; i++)
            {
                cum[i + 1] = cum[i] + a[i];
            }

            for (int i = 0; i < NK[0] - NK[1]; i++)
            {
                var now = cum[NK[1] + i] - cum[i];
                var next = cum[NK[1] + i + 1] - cum[i + 1];
                if (next > now)
                {
                    WriteLine("Yes");
                }
                else
                {
                    WriteLine("No");
                }
            }
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 45464
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++)
  {
    cin >> S.at(i);
  }

  vector<vector<int>> ans0(H, vector<int>(W, 0));

  for (int i = 0; i < H; i++)
  {
    int a = 0;
    int start = 0;
    for (int j = 0; j < W; j++)
    {
      if (S.at(i).at(j) == '.') a++;
      if (S.at(i).at(j) == '#' || j == W - 1)
      {
        for (int k = start; k <= j; k++)
        {
          ans0.at(i).at(k) += a;
        }
        a = 0;
        start = j + 1;
      }
    }
  }
  
  for (int j = 0; j < W; j++)
  {
    int a = 0;
    int start = 0;
    for (int i = 0; i < H; i++)
    {
      if (S.at(i).at(j) == '.') a++;
      if (S.at(i).at(j) == '#' || i == H - 1)
      {
        for (int k = start; k <= i; k++)
        {
          ans0.at(k).at(j) += a;
        }
        a = 0;
        start = i + 1;
      }
    }
  }
  
  int ans = -INF;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      chmax(ans, ans0.at(i).at(j));
    }
  }
  
  ans--;
  
  cout << ans << endl;
}

Measured memory_bytes: 35712
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    vector<int >v;
    cin>>s;
    int la=0;
    s+='*';
    if(s[0]=='0')
    {
        v.push_back(0);
    }
    for(int i=1; i<=n; i++)
    {
        if(s[i]!=s[i-1])
        {
            v.push_back(i-la);
            la=i;
        }
    }
    if(s[n-1]=='0')
    {
        v.push_back(0);
    }
    int sum=0,ma;
    if(2*k+1>=v.size())
    {
        cout<<n<<endl;
        return 0;
    }
    for(int i=0; i<2*k+1; i++)
    {
        sum+=v[i];
    }
    ma=sum;
    for(int i=2*k+1; i<v.size(); i+=2)
    {
        sum-=v[i-2*k-1];
        sum-=v[i-2*k];
        sum+=v[i];
        sum+=v[i+1];
        ma=max(ma,sum);
    }
    cout<<ma<<endl;
    return 0;
}


Measured memory_bytes: 4020
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef pair<int, int> P;
typedef long long int ll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

struct edge{int u, v; double cost; };
int n, m;
int rank[10000], par[10000];
edge es[100000];
double a;

void init(int x){
	rep(i,x){
		rank[i] = 0;
		par[i] = i;
	}
}

int find(int x){
	if(par[x] == x) return x;
	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;
	else{
		par[y] = x;
		if(rank[x] == rank[y]) rank[x]++;
	}
}

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

bool comp(const edge& e1, const edge& e2){
	return e1.cost > e2.cost;
}

int main(){
	scanf("%d%d", &n, &m);
	Vp node(n);
	rep(i,n) scanf("%d%d", &node[i].fi, &node[i].sec);
	rep(i,m){
		int tmp1, tmp2;
		scanf("%d%d", &tmp1, &tmp2);
		tmp1--; tmp2--;
		edge e;
		e.u = tmp1; e.v = tmp2;
		e.cost = sqrt((node[tmp1].fi-node[tmp2].fi)*(node[tmp1].fi-node[tmp2].fi)+(node[tmp1].sec-node[tmp2].sec)*(node[tmp1].sec-node[tmp2].sec));
		es[i] = e;
		a += e.cost;
	}
	sort(es, es+m, comp);
	init(n);
	double ans = 0.0;
	rep(i,m){
		edge e = es[i];
		if(!same(e.u, e.v)){
			unite(e.u, e.v);
			ans += e.cost;
		}
	}
	printf("%0.5f\n", a-ans); 
}

Measured memory_bytes: 1836
n = gets.to_i
s = []
t = []
for i in 0...n do
  s[i], t[i] = gets.split
  t[i] = t[i].to_i
end
x = gets.chomp
flag = false
sum = 0
for i in 0...n do
  sum += t[i] if flag
  if s[i] == x
    flag = true
  end
end
puts sum


Measured memory_bytes: 3836
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;
int n,k;
ll x[55],y[55];

struct node{
	int x,y;
}arr[55];

int main(){
	memset(x,0,sizeof(x));
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		ll u,v;
		scanf("%lld%lld",&u,&v);
		x[i]=u;	y[i]=v;
		arr[i].x=u;	arr[i].y=v;
	}
	sort(x,x+n);	sort(y,y+n);
	ll ans=5e18;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int L=0;L<n;L++){
				for(int R=L+1;R<n;R++){
					ll x1=x[i],x2=x[j];
					ll y1=y[L],y2=y[R];
					int tmp=0;
					for(int p=0;p<n;p++){
						if(arr[p].x>=x1&&arr[p].x<=x2&&arr[p].y>=y1&&arr[p].y<=y2){
							tmp++;
							if(tmp==k){
								ans=min(ans,(y2-y1)*(x2-x1));
								break;
							}
						}
					}
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 10
using namespace std;

int main() {
    int data[N];
    for (int i=0; i<N; i++) {
        cin >> data[i];
    }
    sort(data,data+N);
    reverse(data,data+N);
    for (int i=0; i<3; i++) {
        printf("%d\n",data[i]);
    }
    return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	cout << N * 800 - (N / 15) * 200 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1234567;
 
int dist[N];
vector < pair <int, int> > g[N];
vector <int> new_g[N], all[N];
int was[N];
int x[N];
int ptr[N];
 
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int foo, bar, qwe;
    scanf("%d %d %d", &foo, &bar, &qwe);
    foo--; bar--;
    g[foo].push_back(make_pair(qwe, bar));
    g[bar].push_back(make_pair(qwe, foo));
    all[qwe].push_back(foo);
    all[qwe].push_back(bar);
  }
  for (int i = 0; i < n; i++) {
    sort(g[i].begin(), g[i].end());
    ptr[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    was[i] = -1;
  }
  int new_n = n;
  for (int i = 0; i < N; i++) {
    new_g[i].clear();
  }
  for (int color = 0; color < N; color++) {
    if (all[color].empty()) {
      continue;
    }
    for (int it = 0; it < (int) all[color].size(); it++) {
      int v = all[color][it];
      if (was[v] == color) {
        continue;
      }
      int b = 0, e = 1;
      x[0] = v;
      was[v] = color;
      while (b < e) {
        while (ptr[x[b]] < (int) g[x[b]].size()) {
          int c = g[x[b]][ptr[x[b]]].first;
          if (c != color) {
            break;
          }
          int u = g[x[b]][ptr[x[b]]].second;
          if (was[u] != color) {
            was[u] = color;
            x[e] = u;
            e++;
          }
          ptr[x[b]]++;
        }
        b++;
      }
      for (int i = 0; i < e; i++) {
        new_g[x[i]].push_back(new_n);
        new_g[new_n].push_back(x[i]);
      }
      new_n++;
    }
  }
  for (int i = 0; i < new_n; i++) {
    dist[i] = -2;
  }
  int b = 0, e = 1;
  x[0] = 0;
  dist[0] = 0;
  while (b < e) {
    for (int j = 0; j < (int) new_g[x[b]].size(); j++) {
      int u = new_g[x[b]][j];
      if (dist[u] == -2) {
        dist[u] = dist[x[b]] + 1;
        x[e] = u;
        e++;
      }
    }
    b++;
  }
  printf("%d\n", dist[n - 1] / 2);
  return 0;
}


Measured memory_bytes: 116096
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long
 
#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")
 
#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))
 
#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())
 
#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()
 
#define MX1     30001
#define MX2     1000000
#define Inf     1000000000000000
#define mod		1000000007
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;
 
    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }
 
        b=b>>1;
        a=(a*a)%mod;
    }
 
 return result;
}
 
int main()
{
    opt;
 
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    lli N,i;
    cin>>N;
    
    string s;
    cin>>s;
    
    stack<char>Stk;
    rep(i,0,N)
    {
        if(Stk.empty())
        {
            Stk.push(s[i]);
        }
        else
        {
            if(s[i]=='(')
            {
                Stk.push(s[i]);
            }
            else
            {
                if(Stk.top()=='(')
                {
                    Stk.pop();
                }
                else
                {
                    Stk.push(s[i]);
                }
            }
        }
    }
    
    while(!Stk.empty() and Stk.top()=='(')
    {
        s.pb(')');
        Stk.pop();
    }
    
    rep(i,0,Stk.sz())
    {
        cout<<'(';
    }
    
    cout<<s;
    
    
    
    
    
    
 
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
using namespace std;

vector<vector<int>> E;
vector<vector<int>> E2; //親の情報
vector<int> V;

int graph(int par, int p){
  for(int i = 0; i < E[p].size(); i++){
    if(E[p][i] == par) continue;
    E2[p].push_back(E[p][i]);
    graph(p, E[p][i]);
  }
}

int add(int p){
  for(int i = 0; i < E2[p].size(); i++){
    V[E2[p][i]] += V[p];
    add(E2[p][i]);
  }
  return 0;
}


int main(){
  int N, Q; cin >> N >> Q;
  E.resize(N);
  E2.resize(N);
  V.resize(N);
  for(int i = 0; i < N; i++) V[i] = 0;
  for(int i = 0; i < N - 1; i++){
    int a, b; cin >> a >> b; a--; b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  graph(-1, 0);
  for(int i = 0; i < Q; i++){
    int p, x;
    cin >> p >> x;
    p--;
    V[p] += x;
  }
  add(0);
  for(int i = 0; i < N; i++){
    cout << V[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 34432
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <string>
using namespace std;

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main() {
	int e=1;
	do {
		scanf("%d", &e);
		if (e == 0) break;
		int x=0, y=0, z=e;
		int m = x + y + z;
		for (z = 100;z >= 0;z--) {
			for (y = 1000;y >= 0;y--) {
				x = e - z*z*z - y*y;
				if (x >= 0 && x + y + z < m) m = x + y + z;
			}
		}
		cout << m << endl;
	} while (e != 0);

}



Measured memory_bytes: 3168
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

n, k = rm()
a = rl()
a = heapsort(a)
cnt = 0
for i in a:
    k -= i
    if k < 0:
        break
    else:
        cnt += 1
else:
    if k != 0:
        cnt -= 1
print(cnt)




Measured memory_bytes: 12396
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
SP = []

for i in range(N):
    s,p = SL()
    SP.append([s,int(p),i+1])

sp = sorted(SP,key=itemgetter(1),reverse=True)
sp = sorted(sp,key=itemgetter(0))

for i,j,k in sp:
    print(k)

Measured memory_bytes: 21216