akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n,k;
  int l[SIZE];

  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
    scanf("%d",l+i);
  }

  sort(l,l+n);

  int ans = 0;

  for(int i=0;i<k;i++){
    ans += l[n-1-i];
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int n,a[maxn],cnt[16],dp[1<<16];
vector<int> v;
int main()
{
    scanf("%d",&n);
    for (int i=0;i<n-1;++i) {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u]^=w;
        a[v]^=w;
    }
    for (int i=0;i<n;++i)
        ++cnt[a[i]];
    int res=0;
    for (int i=1;i<16;++i) {
        res+=cnt[i]/2;
        if (cnt[i]&1)
            v.push_back(i);
    }
    dp[0]=0;
    for (int i=1;i<1<<(int)v.size();++i) {
        int mask=0;
        for (int j=0;j<(int)v.size();++j)
            if (1&(i>>j))
                mask^=v[j];
        for (int j=0;j<(int)v.size();++j)
            if (1&(i>>j))
                dp[i]=max(dp[i],dp[i^(1<<j)]+!mask);
    }
    return cout<<res+v.size()-dp[(1<<(int)v.size())-1]<<endl,0;
}


Measured memory_bytes: 768
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N;
	LL Y;
	cin>>N>>Y;
	Y/=1000;
	int x,y,z;
	for (x=0;x<=N;x++){
		for (y=0;y<=N;y++){
			z=N-x-y;
			if (z>=0){
				if (10*x+5*y+z==Y){
					cout<<x<<" "<<y<<" "<<z<<endl;
					return 0;
				}
			}
		}
	}
	for (y=0;y<=N;y++){
		for (z=0;z<=N;z++){
			x=N-y-z;
			if (x>=0){
				if (10*x+5*y+z==Y){
					cout<<x<<" "<<y<<" "<<z<<endl;
					return 0;
				}
			}
		}
	}
	for (x=0;x<=N;x++){
		for (z=0;z<=N;z++){
			y=N-x-z;
			if (y>=0){
				if (10*x+5*y+z==Y){
					cout<<x<<" "<<y<<" "<<z<<endl;
					return 0;
				}
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}

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

int main(){
  
  long long N, i, _P = 0, _Q = 0, cnt = 0;
  cin >> N;
  vector<long long> P(N), Q(N), St(N), Go(N);
  
  for(i = 0; i < N; i++) {
    
    cin >> P.at(i);
    _P += P.at(i) * pow(10, N - i - 1);
  }
  
  for(i = 0; i < N; i++){
    
    cin >> Q.at(i);
    _Q += Q.at(i) * pow(10, N - i - 1);
  }
  
  if (_Q > _P){
    
    St = P;
    Go = Q;
  }else{

    St = Q;
    Go = P;
  }
  
  while(St != Go){
    
    cnt++;
    next_permutation(St.begin(), St.end());
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N;
    cin >> N;
    int p[N];
    cins(p, p + N);
    sort(p, p + N);
    p[N - 1] /= 2;
    cout << accumulate(p, p + N, 0) << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[200010];
int cnt[60];
int a[200010][60];
int ans[200010][60];
int main()
{
	ll N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		int tmp = A[i];
		for (int j = 0; j < 60; j++) {
			cnt[j] += tmp % 2;
			a[i][j] = tmp % 2;
			tmp /= 2;
		}
	}
	for (int i = 0; i < 60; i++) {
		if (cnt[i] % 2 == 0) {
			for (int j = 0; j < N; j++) {
				ans[j][i] = a[j][i];
			}
		}
		else {
			for (int j = 0; j < N; j++) {
				ans[j][i] = 1 - a[j][i];
			}
		}
	}
	for (int i = 0; i < N; i++) {
		ll sum = 0;
		ll power = 1;
		for (int j = 0; j < 60; j++) {
			sum += ans[i][j] * power;
			power *= 2;
		}
		cout << sum << " ";
	}
	cout << endl;
}


Measured memory_bytes: 98036
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

MOD = pow(10, 9) + 7

def main():
    n = int(input())
    x = list(map(int, input().split()))
    fac = [1]
    for i in range(2, n+1):
        fac.append(fac[-1]*i%MOD)
    ans= 1
    i = 1
    for _x in x:
        if _x < 2*i-1:
            ans = ans * i % MOD
        else:
            i += 1
    ans = ans * fac[i-2] % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 59628
//long long使う！！！！！！
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;

ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
 
const ll big=998244353;
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    ll t=exp(x,y/2);
    return (t*t);
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    ll a,b,c,x,y;cin >> a >> b >> c >> x >> y;
    ll ans=0;
    if(a+b>=2*c){
        ans+=min(x,y)*2*c;
        ll t=min(x,y);
        x-=t;
        y-=t;
        
        if(x==0){swap(x,y);swap(a,b);}//y=0
        if(a<=2*c){
            ans+=a*x;
        }else{
            ans+=2*c*x;
        }
    }else{
        ans=a*x+b*y;
    }
    cout << ans << endl;
}

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

#define int long long
#define INF ((int)1e18)
#define MOD ((int)(1e9) + 7)

string a, b;
vector<pair<string, string> > t;

int solve(string x){
  int mi = INF;

  // cout<<x<<endl;
   //string hogehoge; cin>>hogehoge;

  if(x == b) return 0;
  if(x.size() > b.size()) return INF;
  
  for(int i = 0; i < t.size(); i++){
    string y, z = x, w;
    int f = 0;
    bool flag2 = false;
    for(int j = 0; j < x.size(); j++){
      bool flag = true;
      if(j >= x.size() - t[i].second.size() + 1){
	string temp = x;
	w += temp.erase(0, j);
	break;
      }
      //cout<<"i = "<<i<<" "<<j<<" "<<y<<" "<<z<<endl;
      for(; f < j + t[i].second.size() && f < x.size(); f++){
	z.erase(0, 1);
      }
      // cout<<"i = "<<i<<" "<<j<<" "<<y<<" "<<z<<endl;
      
      for(int k = 0; k < t[i].second.size(); k++){
	if(t[i].second[k] != x[j+k]){
	  flag = false;
	  break;
	}
      }
      //cout<<"flag "<<flag<<endl;
      if(flag){
	flag2 = true;
	//mi = min(mi, solve(y + t[i].first + z) + 1);
	w += t[i].first;
	j += t[i].second.size() - 1;
      } else {
	w += x[j];
      }
      y += x[j];
    }

    if(flag2){
      //cout<<"flag2 "<<w<<endl;
      /*
    string hogehoge; cin>>hogehoge;
      bool flag3 = false;
      for(int k = 0; k < w.size() - t[i].second.size() + 1; k++){
	bool flag4 = true;
	 for(int l = 0; l < t[i].second.size(); l++){
	   if(t[i].second[l] != w[k+l]){
	     flag4 = false;
	     break;
	   }
	 }
	 if(flag4) {
	   flag3 = true;
	   break;
	 }
      }
      */
      // if(flag3 == false)
	mi = min(mi, solve(w) + 1);
    }
    //cout<<"<><><><> "<<endl;
  }
  return mi;
}
signed main(){
  
  while(true){
    int n;
    t.clear();

    cin>>n;

    if(!n) break;

    t.resize(n);
    
    for(int i = 0; i < n; i++){
      cin>>t[i].second>>t[i].first;
    }
    
    cin>>a>>b;

    int temp = solve(a);

    cout<<(temp == INF ? -1 : temp)<<endl;
  }
}



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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for(int i=0; i<N; ++i){
        cin >> V[i];
    }
    long long m = 0;
    for(int n=0; n<=K; ++n){
        for(int i=0; i<=n/2; ++i){
            int r = n - i;
            if(r>N) continue;
            for(int left=0; left<=r; ++left){
                vector<int> c;
                int right = r - left;
                for(int j=0; j<left; ++j) c.push_back(V[j]);
                for(int j=0; j<right; ++j) c.push_back(V[N-j-1]);
                sort(c.begin(), c.end(), [](auto x, auto y){ return x>y; });
                long long sum = 0;
                for(int k=0; k<r-i; ++k){
                    sum += c[k];
                }
                if(sum>m) m = sum;
            }
        }
    }
    cout << m << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, x;
    cin >> N >> x;
    multiset<ll> Set;
    for (int n = 0; n < N; ++n) {
        ll a;
        cin >> a;
        Set.insert(a);
    }
    ll Sum = 0;
    for (auto tmp: Set) {
        Sum += tmp;
    }
    if (x == Sum) {
        cout << N << endl;
        return 0;
    } else if (x > Sum) {
        cout << N-1 << endl;
        return 0;
    }
    int Res = 0;
    for (auto tmp: Set) {
        if (x >= tmp) {
            x -= tmp;
            ++Res;
        }
    }
    cout << Res << endl;

    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 rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> MAX(n, -INF);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        chmax(MAX[a], h[b]);
        chmax(MAX[b], h[a]);
    }
    int ans = 0;
    rep(i, n) ans += MAX[i] < h[i];
    cout << ans << endl;
}

Measured memory_bytes: 4000
s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(s)+1)]
for i in range(10):
    if s[0] == "?":
        dp[1][i] += 1
    else:
        dp[1][int(s[0])] = 1
        break

for i, v in enumerate(s):
    if i == 0:
        continue
    for j in range(13):
        for k in range(10):
            x = (10 * j + k) % 13
            if v != "?":
                if int(v) == k:
                    dp[i + 1][x] += dp[i][j]
                    dp[i + 1][x] %= mod
                else:
                    dp[i + 1][x] += 0
            else:
                dp[i + 1][x] += dp[i][j]
                dp[i + 1][x] %= mod

print(dp[-1][5])

Measured memory_bytes: 62428
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

bool isInCircle(double px,double py,double cx,double cy, double r){
	double a = pow(px - cx,2.0) + pow(py - cy,2.0);
	return a < r*r ? true : false;
}

bool isIntersectCircleAndLine(double px1,double py1,double px2, double py2,double cx,double cy, double r){
	if(isInCircle(px1,py1,cx,cy,r) && isInCircle(px2,py2,cx,cy,r)) return false;


	//vector1: from the center of the circle to the staring point
	double vx1 = (cx - px1);
	double vy1 = (cy - py1);

	//vector2: from the starting point to the ending point
	double vx2 = (px2 - px1);
	double vy2 = (py2 - py1);


	double n1=vx1*vx2 + vy1*vy2;
	double n2=vx2*vx2 + vy2*vy2;
	double n3=vx1*vx1 + vy1*vy1;
	

	if(n1 < 0){

		//distance between the starting point and the center of the circle
		return (pow(px1 - cx,2.0) + pow(py1 - cy,2.0) <= r*r) ? true : false;
	}

	else if(n1 > n2){
		//distance between the ending point and the center of the circle
		return (pow(px2 - cx,2.0) + pow(py2 - cy,2.0) <= r*r) ? true : false;
	}
	else{
		return (n3 - (n1/n2)*n1 <= r*r) ? true : false; 
	}
}

int main(){
	
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<PP> wall;
		for(int i=0;i<n;i++){
			int x,y,r;
			scanf("%d %d %d",&x,&y,&r);
			wall.push_back(PP(P(x,y),r));
		}

		int m;
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			double tx,ty,sx,sy;
			scanf("%lf %lf %lf %lf",&tx,&ty,&sx,&sy);
			bool isSafe = false;
			for(int i=0;i<wall.size();i++){
				if(isIntersectCircleAndLine(tx,ty,sx,sy,wall[i].first.first,
					wall[i].first.second,wall[i].second)){
						isSafe = true;
				}
			}

			printf("%s\n",isSafe ? "Safe" : "Danger");
		}
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[300];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	int ret=1000000007;
	for(int i=-200;i<=200;i++){
		int tmp=0;
		for(int j=0;j<a;j++){
			tmp+=(b[j]-i)*(b[j]-i);
		}
		ret=min(ret,tmp);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val h, w = sc.nextInt()
    val map = Array.ofDim[Char](h, w)

    for (i <- 0 until h) {
      val s = sc.next()
      map(i) = s.toCharArray
    }

    for (i <- 0 until h) {
      for (j <- 0 until w) {
        if (map(i)(j) != '#') {
          val m = Array((i, j + 1), (i + 1, j), (i + 1, j + 1), (i - 1, j), (i, j - 1), (i - 1, j - 1), (i + 1, j - 1), (i - 1, j + 1))
          val n = m.filter(n =>
            0 <= n._1 && n._1 < h && 0 <= n._2 && n._2 < w
          )
          var ca = 0
          for (k <- n.indices) {
            if (map(n(k)._1)(n(k)._2) == '#') ca += 1
          }
          print(ca)
        } else {
          print('#')
        }
      }
      println()
    }
  }
}

Measured memory_bytes: 31980
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;

int cnt[303], dp[303][303][303] = { 1 };

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

	string S; int K; cin >> S >> K;
	int N = S.size(), M = 0; K = min(N, K);

	for (int i = 0; i < N; ++i) S[i] == '0' ? ++M : ++cnt[M];

	for (int i = 0; i <= M; ++i)
		for (int j = 0; j <= K; ++j)
			for (int k = 0; k <= j; ++k)
				for (int l = -min(k,cnt[i]); l <= K-j; ++l)
					(dp[i+1][j+max(l,0)][k+l] += dp[i][j][k]) %= MOD;

	int ans = 0;
	for (int i = 0; i <= K; ++i) (ans += dp[M+1][i][0]) %= MOD;
	cout << ans;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

const int mod = 1e9 + 7;

int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}

int udd(int &x, int y) {
  return x = add(x, y);
}

int sub(int x, int y) {
  return add(x, mod - y);
}

int mul(ll x, ll y) {
  return x * y % mod;
}

const int M = 344;

int n, m;
int d[M][M], h[M][M];

void read() {
  cin >> n >> m;
}

void kill() {
  d[1][n - 1] = 1;
  for (int i = 0; i < m; ++i) {
    
    for (int x = 0; x <= n; ++x)
      for (int y = 0; y <= n; ++y)
        h[x][y] = 0;

    for (int x = 1; x <= n; ++x)
      for (int y = 0; y <= n - x; ++y) {
        int cur = d[x][y];
        udd(h[n - y][y], mul(x, cur));

        if (y > 0) {
          udd(h[x][y - 1], mul(y, cur));
        }

        udd(h[x][y], mul(n - x - y, cur));
      }

    for (int x = 0; x <= n; ++x)
      for (int y = 0; y <= n; ++y)
        d[x][y] = h[x][y];
  }

  cout << d[n][0] << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("f.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();

}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  //input
  int a,p;cin>>a>>p;
  //caricurate
  int l;l=3*a+p;
  //output
  cout<<(l/2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
using VP = vector<P>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int inf = 1e9;
constexpr int mod = 1e9+7;
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}


int main() {
    ll n, m;
    cin >> n >> m;
    
    V a(n);
    rep(i, n) cin >> a[i];

    priority_queue<ll> q;
    rep(i, n) q.push(a[i]);

    rep(i, m) {
        ll t = q.top(); q.pop();
        t /= 2;
        q.push(t);
    }

    ll ret = 0;
    rep(i, n) {
        ret += q.top(); q.pop();
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

#define MAX 1000000

signed main() {
    int k;
    cin >> k;
    int cur = 0;
    for (int i = 1; i <= MAX; i++) {
        cur *= 10;
        cur += 7;
        cur %= k;
        if(cur == 0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

using namespace std;

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node x, int k){
  while(x != NIL && k != x->key){
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);

  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node x){
  if(x == NIL) return;
  inorder(x->left);
  cout << " " << x->key;
  inorder(x->right);
}
void preorder(Node x){
  if(x == NIL) return;
  cout << " " << x->key;
  preorder(x->left);
  preorder(x->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 26572
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	set<int> sugar, water;
	for (int i = 0; c*i <= f; i++) {
		for (int j = 0; d*j <= f; j++) {
			int y = i*c + j*d;
			if (y <= f)
				sugar.insert(y);
		}

	}
	for (int i = 0; a*i*100 <= f; i++) {
		for (int j = 0; b*j*100 <= f; j++) {
			int y = i*a*100 + j*b*100;
			if (y <= f)
				water.insert(y);
		}

	}
	double rate = -1.0;
	int answ=0, anss=0;
	for (set<int>::iterator p = water.begin(); p != water.end(); p++) {
		for (set<int>::iterator q = sugar.begin(); q != sugar.end(); q++) {
			if (*q * 100.0 < (e+EPS) * *p && *p+*q < (f+EPS)) {
				double y = *q * 100.0 / (*p + *q);
				if (y > rate) {
					answ = *p; anss = *q;
					rate = y;
				}

			}	
			
		}
	}
	cout << answ+anss << " " << anss << endl;
	return 0;
}


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

int64_t mod = 998244353 ;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}

int main(){
    int n ;
    cin >> n ;
    int ans = n ;
    int temp,s,t ;
    for (int i = 0; i < n+1; i++)
    {
        temp = 0 ;
        s = i ;
        t = n-i ;
        while(s > 0 || t > 0){
            temp += (s%6 + t%9) ;
            s /= 6 ;
            t /= 9 ;
        }
        ans = min(ans,temp) ;
    }
    cout << ans << endl ;
}

Measured memory_bytes: 3620
k = int(input())
S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(S[k-1])

Measured memory_bytes: 3060
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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

    string S; cin >> S; // R...L
    ll N = S.size();

    vi ans(N);
    int odd = 0, even = 0;
    REP(i,N) {
        if (S[i]=='R') {
            if (i % 2 == 1) odd++;
            else even++;
        } else { // S[i]=='L'
            if (i%2==1) {
                ans[i] += odd;
                ans[i - 1] += even;
            } else {
                ans[i] += even;
                ans[i - 1] += odd;
            }
            odd = 0, even = 0;
        }
    }

    odd = 0, even = 0;
    for(int i=N-1; i>=0; i--) {
        if (S[i]=='L') {
            if (i % 2 == 1) odd++;
            else even++;
        } else { // S[i]=='R'
            if (i%2==1) {
                ans[i] += odd;
                ans[i + 1] += even;
            } else {
                ans[i] += even;
                ans[i + 1] += odd;
            }
            odd = 0, even = 0;
        }
    }

    cout << ans[0];
    FOR(i,1,N) cout << " " << ans[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 1104
#include<stdio.h>

#define M 9

int main(void){
  int box[M][M];
  int flg[M][M];
  int g,h,i,j,k,l,m,n;

  scanf("%d",&g);
  for(h=0;h<g;h++){
    for(i=0;i<M;i++){
      for(j=0;j<M;j++){
	scanf("%d",&box[i][j]);
	flg[i][j]=0;
      }
    }
    
    for(i=0;i<M;i++){
      for(j=0;j<M;j++){
	for(k=0;k<M;k++){
	  //printf("(%d,%d,%d)\n",i,j,k);
	  if(!(j==k)){
	    //printf("[%d,%d]",i,k);
	    if(box[i][j]==box[i][k]){
	      flg[i][j]++;
	      flg[i][k]++;
	    }
	  }
	  if(!(i==k)){
	    //printf("[%d,%d]\n",k,j);
	    if(box[i][j]==box[k][j]){
	      flg[i][j]++;
	      flg[k][j]++;
	    }
	  }
	}
      }
    }
    //printf("\n----------\n");
    for(i=0;i<M;i++){
      for(j=0;j<M;j++){
	if(i<3){
	  k=0;
	}
	else if(i<6){
	  k=3;
	}
	else{ k=6;
	}
	if(j<3){
	  l=0;
	}
	else if(j<6){
	  l=3;
	}
	else{
	  l=6;
	}
	for(m=k;m<k+3;m++){
	  for(n=l;n<l+3;n++){
	    if(i!=m||j!=n){
	      if(box[i][j]==box[m][n]){
		flg[i][j]++;
		flg[m][n]++;
	      }
	    }
	  }
	}
      }
    }

    for(i=0;i<M;i++){
      for(j=0;j<M;j++){
	if(flg[i][j]>0){
	  printf("*");
	}
	else{
	  printf(" ");
	}
	printf("%d",box[i][j]);
      }
      /*
      printf("   ");
      for(j=0;j<M;j++){
	printf("%d",flg[i][j]);
      }
      */
      printf("\n");
    }
    if(h+1!=g){
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
N, K = map(int, input().split())
S = list(input())
if S[K-1] == "A":
  S[K-1] = "a"
elif S[K-1] == "B":
  S[K-1] = "b"
else:
  S[K-1] = "c"
ans = "".join(S)
print(ans)


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
int x, y;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> a >> b;
  if (a >= 10)
    pr(b);
  else
    pr(100 * (10 - a) + b);
}

Measured memory_bytes: 3636
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,c[1005][20],dp[1005][(1<<12)+1];
int cev;
string s;
vector<int> v;

inline int f(int sira,int mask){
	int cevv=inf;
	//~ cout<<sira<<" "<<mask<<endl;
	if(sira>m){
		//~ cout<<mask<<endl;
		if(mask==(1<<(n))-1)return 0;
		return inf;
	}
	if(~dp[sira][mask])return dp[sira][mask];
	cevv=min(cevv,f(sira+1,mask));
	int at=mask;
	for(int i=0;i<b[sira];i++){
		at=(at|(1<<c[sira][i]));
	}
	cevv=min(cevv,f(sira+1,at)+a[sira]);
	return dp[sira][mask]=cevv;
}

main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%lld %lld",&a[i],&b[i]);
		for(int j=0;j<b[i];j++){
			scanf("%lld",&c[i][j]);
			c[i][j]--;
		}
	}
	cev=f(1,0);
	if(cev==inf)cev=-1;
	printf("%lld\n",cev);
	return 0;
}


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

int main(void){
        int N;
        int i;
        string A[200000+1];
        string c;
        cin >> N;
        while(cin >> c){
                A[i] = c;
                i++;
                if(i >= N){
                        break;
                }
        }
        sort(A, A+N);
        for(i=0;i<N-1;i++){
                if(A[i] == A[i+1]){
                        cout << "NO" << "\n";
                        exit(0);
                }
        }
        cout << "YES" << "\n";
        return 0;
}

Measured memory_bytes: 13824
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

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

	string s;
	cin >> s;
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	string t = s.substr(0, (s.size() - 1) / 2);
	rep(i, t.size() / 2) {
		if (t[i] != t[t.size() - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	t = s.substr((s.size() + 3) / 2 - 1, s.size() - (s.size() + 3) / 2 + 1);
	rep(i, t.size() / 2) {
		if (t[i] != t[t.size() - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stack>
#include <stdio.h>
#include <vector>

using namespace std;

#define NMAX 100
#define NIL -1

int d[NMAX + 1];           // start time, 1-origin
int f[NMAX + 1];           // finish time, 1-origin
stack<int> S;              // visited but not finished
vector<int> adj[NMAX + 1]; // adj
int n = 0;
int cnt = 0;

int next_unvisited_adj(int u) { // next not visited adj of u
    for (vector<int>::iterator it = adj[u].begin(); it != adj[u].end(); it++) {
        if (d[*it] == 0) // not finished
            return *it;
    }
    return NIL;
}

int next_unvisited() {
    for (int i = 1; i <= n; i++) {
        if (d[i] == 0)
            return i;
    }
    return NIL;
}

void dfs() {
    int x; // start vertex
    while ((x = next_unvisited()) != NIL) {
        // printf("dfs component of %d\n", x);
        S.push(x);
        d[x] = ++cnt;
        while (!S.empty()) { // dfs this component
            // check if the last visited guy is finished
            // if yes, pop it from the stack
            // if no, push the next unfinished adj of it
            int u = S.top();
            // printf("u=%d\n", u);
            int v = next_unvisited_adj(u);
            if (v != NIL) {
                if (d[v] == 0) { // v is not visited
                    // printf("%d is found\n", v);
                    d[v] = ++cnt;
                    S.push(v);
                }
            } else { // u is finished
                // printf("%d is finished\n", u);
                S.pop();
                f[u] = ++cnt;
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        d[i] = 0; // not visited
        f[i] = 0; // not finished
    }
    for (int i = 0; i < n; i++) {
        int u, k, v;
        scanf("%d", &u);
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            scanf("%d", &v);
            adj[u].push_back(v);
        }
    }
    dfs();
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}


Measured memory_bytes: 2784
n = int(input())
s = int(input())

def f(b, n):
    val = 0
    while n > 0:
        val += n % b
        n //= b
    return val

if s == n:
    print(n+1)
    exit()
for i in range(2, int(n**0.5) + 1):
    if(f(i, n) == s):
        print(i)
        exit()
ans = 10**15
for i in range(1, int(n**0.5) + 1):
    b = (n-s) // i + 1
    if b < 2:
        continue
    if f(b, n) == s:
        ans = min(ans, b)

if ans == 10**15:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3188
import os, sys
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline

n = int(rl())
a = list(map(int, rl().split()))

ans = 987654321
for it in a:
    cnt = 0
    while it > 0 and it % 2 == 0:
        it /= 2
        cnt += 1
    ans = min(ans, cnt)
print(ans)


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

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



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int A,B;

    cin>>A>>B;

    if(A<=8&&B<=8){
        cout<<"Yay!"<<endl;
    }
    else{
        cout<<":("<<endl;
    }

    return 0;
}

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

int main(){

int n;
scanf("%d",&n);
for(int iii=0;iii<n;iii++){

int G[17][17][2]={};
int MT[17][17]={};
int gx,gy;int a;
scanf("%d%d",&gx,&gy);
scanf("%d",&a);
for(int ii=0;ii<a;ii++){
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
int X=x1,Y=y1;
if(X<x2)X=x2;if(Y<y2)Y=y2;
if(x1==x2)G[Y][X][1]+=2;
if(y1==y2){G[Y][X][1]+=1;}
}
G[0][0][0]=1;
for(int i=0;i<=gy;i++)
for(int j=0;j<=gx;j++)
{
if(G[i][j][1]==0&&i>0)G[i][j][0]+=G[i-1][j][0]+G[i][j-1][0];
if(G[i][j][1]==1&&i>0)G[i][j][0]+=G[i-1][j][0];//+G[i][j-1][0];
if(G[i][j][1]==2)G[i][j][0]+=G[i][j-1][0];
if(G[i][j][1]==0&&i==0&&j!=0)G[i][j][0]+=G[i][j-1][0];
//if(G[i][j][1]==3)G[i][j][0]+=G[i-1][j][0]+G[i][j-1][0];
}/*
for(int i=0;i<=gy;i++){
for(int j=0;j<=gx;j++)
cout<<" "<<G[i][j][1];
cout<<endl;
}*/
if(G[gy][gx][0]==0)cout<<"Miserable Hokusai!"<<endl;
else cout<<G[gy][gx][0]<<endl;
}
return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    char arr[110],t[110];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>t[i];
    }
    for(int i=0;i<n;i++)
    {
        cout<<arr[i];
        cout<<t[i];
    }

    cout<<endl;

    //s.append(t);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int n, m, cnt;
vector<vector<int>> g;
vector<int> u;
int dfs(int v) {
  u[v] = 1;
  int res = 1;
  for (int i : g[v])
    if (!u[i])
      res += dfs(i);
  return res;
}
int main() {
  cin >> n >> m;
  g.resize(n);
  u.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < n; ++i)
    if (!u[i]) {
      cnt = max(cnt, dfs(i));
    }
  cout << cnt;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int h = 2, w = 3;
  vector<string> vs(h);
  for (int i = 0; i < h; ++i) {
    cin >> vs[i];
  }

  reverse(vs[0].begin(), vs[0].end());
  if (vs[0] == vs[1]) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }

  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

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


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(){
    int a[18];
    for(int i=0;i<18;i++)cin>>a[i];
    int b[6];
    for(int i=0;i<18;i+=3){
        b[i/3]=a[i]*3600+a[i+1]*60+a[i+2];
    }
    b[0]=b[1]-b[0];
    b[1]=b[3]-b[2];
    b[2]=b[5]-b[4];
    for(int i=0;i<3;i++){
        cout<<b[i]/3600<<" ";
        b[i]%=3600;
        cout<<b[i]/60<<" ";
        b[i]%=60;
        cout<<b[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(),max=-1000001,min=1000001,non;long sum=0;
		for (int a=1;a<=n;a++){
			non=sc.nextInt();
		if (non>=max){max=non;}
		if(non<=min){min=non;}
		sum +=non;
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 31968
N=input()
N_list=list(N)
triple=[N[0],N[0],N[0]]
triple_one=[str(int(N[0])+1),str(int(N[0])+1),str(int(N[0])+1)]
num=int("".join(triple))
num_one=int("".join(triple_one))
N_int=int(N)
if N_int > num and N_int < num_one:
    ans = num_one
elif N_int <= num:
    ans= num

print(ans)

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

int board[10][10];

void small(int x, int y){
	board[x][y]++;
	if(x>=1) board[x-1][y]++;
	if(x<=8) board[x+1][y]++;
	if(y>=1) board[x][y-1]++;
	if(y<=8) board[x][y+1]++;
}

void middle(int x, int y){
	small(x, y);
	if(x>=1 && y>=1) board[x-1][y-1]++;
	if(x>=1 && y<=8) board[x-1][y+1]++;
	if(x<=8 && y>=1) board[x+1][y-1]++;
	if(x<=8 && y<=8) board[x+1][y+1]++;
}

void large(int x, int y){
	middle(x, y);
	if(x>=2) board[x-2][y]++;
	if(x<=7) board[x+2][y]++;
	if(y>=2) board[x][y-2]++;
	if(y<=7) board[x][y+2]++;
}

int main(void){
	
	for(int i=0; i<10; i++)
		for(int j=0; j<10; j++)
			board[i][j] = 0;

	int x, y, size;
	char c1, c2;

	while(cin >> x >> c1 >> y >> c2 >> size){
		switch(size){
		case 1:
			small(x, y);
			break;
		case 2:
			middle(x, y);
			break;
		case 3:
			large(x, y);
			break;
		}
	}

	int max = 0;
	int count = 0;

	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			if(board[i][j] > max) max = board[i][j];
			if(board[i][j] == 0) count++;
		}
	}

	cout << count << endl << max << endl;

	return 0;
}

Measured memory_bytes: 0
N=int(input())
S=input()

look_east=[0]*N
for i in range(1, N):
    if S[i-1]=='E':
        look_east[i]=look_east[i-1]+1
    else:
        look_east[i] = look_east[i - 1]
#print(look_east)

look_west=[0]*N
for i in range(N-2, -1,-1):
    #print(i)
    if S[i+1]=='W':
        look_west[i]=look_west[i+1]+1
    else:
        look_west[i] = look_west[i + 1]
#print(look_west)

ew=[look_west[i]+look_east[i] for i in range(N)]
#print(ew)
print(N-max(ew)-1)

Measured memory_bytes: 29728
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, m;
vector <int> v[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    vector <int> path;
    path.push_back(1);
    vector <int> vis(n + 1);
    vis[1] = 1;
    auto expand = [&](){
        while(1){
            int ok = 1;
            for(auto &i : v[path.back()]){
                if(vis[i]) continue;
                path.push_back(i);
                vis[i] = 1;
                ok = 0;
                break;
            }
            if(ok) break;
        }
    };
    expand();
    reverse(path.begin(), path.end());
    expand();
    cout << path.size() << endl;
    for(auto &i : path) cout << i << " ";
    cout << endl;
}


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

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

  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (cnt == 0) {
      if (s[i] == 'p') {
        --ans;
      }
      ++cnt;
    } else {
      if (s[i] == 'g') {
        ++ans;
      }
      --cnt;
    }
  }
  cout << ans << endl;
}

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

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

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

    int res = 0;
    int btn = 1;
    for (int i = 0; i < 100000; i++) {
        btn = vec.at(btn - 1);
        res++;

        if (btn == 2) {
            cout << res << endl;
            break;
        }
    }

    if (btn != 2) {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long NINF = numeric_limits<long long>::min();
	
int main(){
  long long n,k;
  cin>>n>>k;
  int permu[5005];
  long long score[5005];
  long long ret = NINF;
  for(int i=1; i<=n; i++) cin>>permu[i];
  for(int i=1; i<=n; i++) cin>>score[i];
  int visit_num[n+1]={0};
  long long cycle_psum[5005]={0};
  
  for(int i=1; i<=n; i++){
  	memset(visit_num,0,sizeof(visit_num));
  	memset(cycle_psum,0,sizeof(cycle_psum));
  	long long sum = 0;
  	long long move = k;
  	long long curr = permu[i];
  	int counter = 1;
  	
  	here:
  	while(move && !visit_num[curr]){
  		visit_num[curr] = counter++;
  		sum+=score[curr];
  		cycle_psum[curr] = sum;
  		curr = permu[curr];
  		move--;
  		ret = max(ret,sum);
	}
	if(move){
		if(sum<=0) continue;
		//한사이클이 양수고 한 사이클 이상 돌릴 수 있다면 
		//현재의 sum 은 한 사이클을 돌린 결과가 된다. 
		long long cycle_len = counter-visit_num[curr];
		//cout<<counter<<" "<<visit_num[curr]<<" "<<curr<<'\n';
		long long cycle_value = sum+score[curr]-cycle_psum[curr];
		long long except_cycle = (counter-1)-cycle_len;
		long long cycle_repeat = (k-except_cycle)/cycle_len;
		//cout<<i<<" "<<cycle_len<<" "<<cycle_value<<" "<<except_cycle<<" "<<cycle_repeat<<'\n';
		sum+=(cycle_repeat-1)*cycle_value;
		ret = max(ret,sum);
		memset(visit_num,0,sizeof(visit_num));
		move = k-cycle_repeat*cycle_len-except_cycle;
		vector<long long>cycle;
		
		while(visit_num[curr]==false){
			visit_num[curr] = true;
			cycle.push_back(score[curr]);
			curr = permu[curr];	
		}
		sum-=cycle_value;
		move+=cycle_len;
		for(int i=0; i<move; i++){
			sum+=cycle[i%cycle.size()];
			ret = max(ret,sum);
		}
	}
  }
  cout<<ret;
}

Measured memory_bytes: 3856