akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> vs(h);
    map<char, int> m;
    int ecnt = 0, ocnt = 0;
    bool ans = false;
    rep(i, h) cin >> vs[i];
    rep(i, h) {
        rep(ii, w) {
            m[vs[i][ii]]++;
        }
    }
    for (auto x : m) {
        if (x.second % 2 != 0) {
            ocnt++;
        }
        else {
            ecnt++;
        }
    }
    if ((w == 1) && (h == 1)) {
        ans = true;
    }
    else if (w == 1) {
        if ((h % 2 == 1) && (ocnt == 1)) ans = true;
        else if ((h % 2 == 0) && (ocnt == 0)) ans = true;
    }
    else if (h == 1) {
        if ((w % 2 == 1) && (ocnt == 1)) ans = true;
        else if ((w % 2 == 0) && (ocnt == 0)) ans = true;
    }
    else {
        priority_queue<int> pq;
        for (auto x : m) pq.push(x.second);
        int ftimes, ttimes, otimes;
        if ((w % 2 == 0) && (h % 2 == 0)) {
            ftimes = (h * w) / 4; ttimes = 0; otimes = 0;
        }
        else if (w % 2 == 0) {
            ftimes = ((h / 2) * (w / 2)); ttimes = w / 2; otimes = 0;
        }
        else if (h % 2 == 0) {
            ftimes = ((h / 2) * (w / 2)); ttimes = h / 2; otimes = 0;
        }
        else {
            ftimes = ((h / 2) * (w / 2)); ttimes = (h + w - 2) / 2; otimes = 1;
        }
        rep(i, ftimes) {
            if (pq.top() < 4) {
                cout << "No" << endl;
                return 0;
            }
            int v = pq.top();
            pq.pop();
            v -= 4;
            pq.push(v);
        }
        rep(i, ttimes) {
            if (pq.top() < 2) {
                cout << "No" << endl;
                return 0;
            }
            int v = pq.top();
            pq.pop();
            v -= 2;
            pq.push(v);
        }
        if (otimes == 1) {
            if ((sz(pq) == 0) || (pq.top() != 1)) {
                cout << "No" << endl;
                return 0;
            }
        }
        ans = true;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


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

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

struct UnionFind{
	vector<int> par;

	UnionFind(int N) : par(N){
		for(int i=0; i<N; i++) par[i] = i;
	}

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

	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx==ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y){
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};


int main(){
	int N;
	cin >> N;
	vector<P> X,Y;
	rep(i,N){
		int x,y;
		cin >> x >> y;
		X.push_back(make_pair(x,i));
		Y.push_back(make_pair(y,i));
	}

	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());

	vector<TP> G;
	rep(i,(int)X.size()-1){
		int d = X[i+1].first - X[i].first;
		G.push_back(make_tuple(d,X[i+1].second,X[i].second));
	}

	rep(i,(int)Y.size()-1){
		int d = Y[i+1].first - Y[i].first;
		G.push_back(make_tuple(d,Y[i+1].second,Y[i].second));
	}

	sort(G.begin(),G.end());
	UnionFind uf(N);
	ll ans = 0;
	rep(i,(int)G.size()){
		int d = get<0>(G[i]);
		int a = get<1>(G[i]);
		int b = get<2>(G[i]);
		if(!uf.same(a,b)) {
			ans += d;
			uf.unite(a,b);
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 7144
N = int(input())
A = list(map(int,input().split()))
B = []

for i in range(N,0,-2):
    B.append(A[i-1])

if i%2==0:
    for j in range(i-1,N+1,2):
        B.append(A[j-1])
else:
    for j in range(i+1,N+1,2):
        B.append(A[j-1])

mapB = map(str,B)
B = ' '.join(mapB)
print(B)

Measured memory_bytes: 29764
def solve():
    from sys import stdin
    f_i = stdin
    
    n, q = map(int, f_i.readline().split())
    
    from heapq import heappop, heappush
    Q = [[] for i in range(n)]
    
    ans = []
    
    for op in (line.split() for line in f_i):
        op_type = op[0]
        t = int(op[1])
        pq_t = Q[t]
        if op_type == '0':
            heappush(pq_t, -int(op[2]))
        elif pq_t:
            if op_type == '1':
                ans.append(-pq_t[0])
            else:
                heappop(pq_t)
    print('\n'.join(map(str, ans)))

solve()


Measured memory_bytes: 18128
#include<stdio.h>
#include<limits.h>

#define SENTINEL 2000000000

typedef struct box{
	int a;//初期の位置を格納
	int b;//重さ
	int c;//サイクル別にサイクル番号を格納
} num;

long int cnt=0;//case#19で解がint型の最大値を越えるためlongを用いる

void merge(num *A,int left,int mid,int right)//分割した配列を小さい順に結合
{
  int n1 = mid - left;
  int n2 = right - mid;
  num L[n1+1],R[n2+1];
  int k,i,j;
  for (i=0;i<n1;i++) {
  	L[i].a = A[left + i].a;
  	L[i].b = A[left + i].b;
  }
  for (i=0;i<n2;i++) {
  	R[i].a = A[mid + i].a;
  	R[i].b = A[mid + i].b;
  }
  L[n1].b = SENTINEL;//EOF
  R[n2].b = SENTINEL;//EOF
  i = 0;
  j = 0;
    
  for(k=left;k<right;k++){//iが左の要素番号,jが右の要素番号
    if(L[i].b<=R[j].b){//左が小さい場合
      A[k].a = L[i].a;
      A[k].b = L[i].b;
      i=i+1;
    }else{ //右が小さい場合
      A[k].a = R[j].a;
       A[k].b = R[j].b;
      if(L[i].b!=SENTINEL) cnt+=(n1-i);//SENTINELと比較する場合を除いて左側の未ソート部分の要素数をcntに加算
      j = j + 1;
    }
  }
}


void mergeSort(num *A,int left,int right)
{
  int mid,i;
  if(left+1<right){//二分探索のように左端が右端を超えたら終了
    mid = (left + right)/2;
    mergeSort(A, left, mid);//左半分で再帰
    mergeSort(A, mid, right);//右半分で再帰
    merge(A, left, mid, right);//結合
  }
}
int minsearch(num *A,int n,int group)//サイクル外の最小値を返す
{
    int i,min=INT_MAX;
    group--;
    for(i=0;i<n;i++){
        if(A[i].c!=group&&min>A[i].b) min=A[i].b;
    }
    return min;
}

int main(void)
{
    int n,i,j;
    num A[500001];//荷物の情報を格納
    int left,right;
    int box=0,start,sum=0;
    int min=INT_MAX,cnt=0,S,T,group=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) {
    	scanf("%d",&A[i].b);
    	A[i].a=i;
    	A[i].c=-1;
    }
    
    left=0;
    right=n;
    mergeSort(A,left,right);
    
    for(i=0;i<n;i++)
    {
        if(A[i].c==-1){//サイクルグループに属していない場合
    	    if(i!=A[i].a){//入れ替える必要がある場合サイクルを探索
    		    start=i;
    	    	j=i;
    		    for(;;){
    			    box+=A[j].b;
    			    if(min>A[j].b) min=A[j].b;
    			    A[j].c=group;
    			    cnt++;
    			    if(start==A[j].a){
    			       group++;
    			       break;
    		    	}
    			    j=A[j].a;
    		    }
    	        S=box+min+(cnt+1)*minsearch(A,n,group);// サイクル外から最小値を借りた場合
    	        T=min*(cnt-2)+box;//借りない場合
    	        if(S>T||S<0) sum+=T;
    	        else sum+=S;
            }else{//移動しない場合
    	        A[i].c=group;
    	        group++;
    	    }
    	    min=INT_MAX;
    	    box=0;
    	    cnt=0;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;

int main(){ 
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  rep(i,n) cin >> s[i];
  rep(i,m) cin >> t[i];

  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

  dp[0][0] = 1;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0 && j == 0) continue;
      if (i == 0) {
        dp[i][j] = dp[i][j - 1];
        continue;
      }
      if (j == 0) {
        dp[i][j] = dp[i - 1][j];
        continue;
      }
      (dp[i][j] += dp[i - 1][j]) %= mod;
      (dp[i][j] += dp[i][j - 1]) %= mod;
      ((dp[i][j] -= dp[i - 1][j - 1]) += mod) %= mod;
      if (s[i - 1] == t[j - 1]) (dp[i][j] += dp[i - 1][j - 1]) %= mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0; 
} 


Measured memory_bytes: 19076
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
cnt = 0
for i in range(len(a)):
    if x>=a[i]:
        cnt += 1
    x -= a[i]
if x>0:
    cnt-=1
print(cnt)



Measured memory_bytes: 12388
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
ll intpow(int n,int m){
    if(m==0)return 1;
    return n*intpow(n,m-1);
}
ll gcd(ll n,ll m){
    n = max(n,m);
    m = min(n,m);
    if(n%m == 0)return m;
    return gcd(m,n%m);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
using Graph = vector<vector<int>>;

vector<ll>seen;
vector<bool> sn;
void dfs(const Graph &G,int v){
    sn[v]=1;
    for(auto next_v : G[v]){
        if(sn[next_v]==1)continue;
        seen[next_v]+=seen[v];
        dfs(G,next_v);
    }
}
int main(){
    int n,q;cin>>n>>q;

    Graph G(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    seen.assign(n,0);
    sn.assign(n,0);
    rep(i,q){
        int p;
        ll x;
        cin>>p>>x;
        p--;
        seen[p]+=x;
    }
    dfs(G,0);
    rep(i,n)cout<<seen[i]<<" ";

}

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

#define ll long long

struct mise {
    string s;
    int p;
    int n;
};

int main() {
    int N;
    cin >> N;
    mise nya[N];
    for(int i = 0;i < N;i++) {
        cin >> nya[i].s >> nya[i].p;
        nya[i].n = i + 1;
    }
    auto cmp = [](mise a, mise b) {return a.s == b.s ? a.p > b.p : a.s < b.s;};
    sort(nya, nya + N, cmp);
    cout << endl;
    for(int i = 0;i < N;i++) {
        cout << nya[i].n << endl;
    }
    return 0;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,k = mi()
a = [0] * n

for i in range(k):
    d = ii()
    at = li()
    for j in at:
        a[j-1] += 1

ans = 0
for i in range(n):
    if a[i] == 0:
        ans += 1

print(ans)

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int b[1 << 20];
int c[1 << 20];

int cmp(int x, int y)
{
	return c[x] > c[y];
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	VI a(n);
	FOR(i, 0, n) cin >> a[i];
	FOR(i, 0, m) cin >> b[i] >> c[i];
	VI idx(m);
	iota(ALL(idx), 0);
	sort(ALL(idx), cmp);
	
	multiset<int> s;
	FOR(i, 0, m)
	{
		int tut = c[idx[i]];
		int cnt = b[idx[i]];
		while(cnt-- && SZ(s) < n) s.insert(tut);
	}
	
	FOR(i, 0, n) s.insert(a[i]);
	while(SZ(s) > n) s.erase(s.begin());
	
	cout << accumulate(ALL(s), 0LL) << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 12928
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int A[100];
int main()
{
  int N;
  cin >>N;
  for(int i = 0;i < N;i++){
    cin >>A[i];
  }
  int ans = 0;

  for(int i = 0;i < N-1;i++){
    int mini = i;
    for(int j = i+1;j <N;j++){
      if(A[j]<A[mini]){
	mini = j;
      }
    }
    if(i !=mini){
	swap(A[i],A[mini]);
	ans++;
    }
  }
  for(int i = 0;i < N;i++){
    cout <<A[i];
    if(i !=N-1)
      cout <<" ";
  }
  cout <<endl;
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;

template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  

  int row, col; cin >> row >> col;
  if(row != 1) row -= 2;
  if(col != 1) col -= 2;
  cout << (LL)row * col << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

vector<ll> a,p;
ll f(ll n,ll x){
	if(n==0){
		if(x<=0){
			return 0;
		}else{
			return 1;
		}
	}else if(x<=1+a[n-1]){
		return f(n-1,x-1);
	}else{
		return p[n-1]+1+f(n-1,x-2-a[n-1]);
	}
}

int main(){
	//source
	ll n,x;
	cin >> n >> x;
	a.push_back(1);
	p.push_back(1);
	rep(i,n){
		a.push_back(a[i]*2+3);
		p.push_back(p[i]*2+1);
	}

	cout << f(n,x) << endl;
	return 0;
}


Measured memory_bytes: 256
/*ॐॐ*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it. 
                                       -Prince Vegeta  */

 /* “Strength is the only thing that matters in this world. Everything else is just a delusion for the weak.” – Vegeta */

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

ll K,N;
/*ll freq[200005];*/
void solve(){
   /*memset(freq,0,sizeof(freq));*/
  cin>>N>>K;


  ll val = log2(N)/log2(K);

  val = floor(val)+1;

  cout<<val<<'\n'; 

}



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

  return 0;
}


Measured memory_bytes: 3780
#include<iostream>
#include<cmath>
 
using namespace std;
 
typedef struct PointTag{
   int x;
   int y;
   int h;
} Point;
 
int dist(int sx, int sy, int tx, int ty);
int search(int cx, int cy, Point* points, int n);
 
int main(){
   int n;
   cin >> n;
   Point* ps = new Point[n];
   int x,y,h;
   for(int i=0;i<n;i++){
      cin >> x >> y >> h;
      ps[i].x = x;
      ps[i].y = y;
      ps[i].h = h;
   }
 
   Point ans = {0};
   for(int i=0;i<=100;i++){
      for(int j=0;j<=100;j++){
         ans.h = search(i,j,ps,n);
 
         if(ans.h != -1){
            ans.x = i;
            ans.y = j;
 
            goto lbl_print_ans;
         }
      }
   }
 
lbl_print_ans:
 
   cout << ans.x << " " << ans.y << " " << ans.h << endl;
}
 
int search(int cx, int cy, Point* points, int n){
   int count;
   for(int i=0;i<n;i++){
      if(points[i].h != 0){
         count = dist(cx, cy, points[i].x, points[i].y) + points[i].h;
         break;
      }
   }
 
   for(int i=0;i<n;i++){
      if(max(count - dist(cx, cy, points[i].x, points[i].y),0) != points[i].h){
         return -1;
      }
   }
 
   return count;
}
 
int dist(int sx, int sy, int tx, int ty){
   return abs(sx - tx) + abs(sy - ty);
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	string A, B, C;
	cin >> N >> A >> B >> C;

	ll res = 0;
	REP(i, N){
		if(A[i]!=B[i]&&B[i]!=C[i]&&C[i]!=A[i]){
			res += 2;
		}
		if((A[i]==B[i]||A[i]==C[i]||B[i]==C[i]) && (!(A[i]==B[i]&&B[i]==C[i]))){
			res += 1;
		}
	}
	cout << res << endl;
    return 0;
}

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

int main(){
	long n, k; cin >> n >> k;
	
	if(!k){
		cout << n * n << endl;
		return 0;
	}
	
	long ans = 0;
	for(int i = k + 1; i <= n; i++){
		long A = (n + 1) / i;
		long B = (n + 1) % i;
		
		ans += A * (i - k);
		if(B > k) ans += B - k;
	}
	
	cout << ans << endl;
	return 0;
}


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

using namespace std;

struct tree
{
	vector<int> con;
	vector<long long> dis;
	vector<int> child;
	long long from_root;
	bool end;
};

tree node[100005];

void preorder(int id)
{
	node[id-1].from_root=0;
	node[id-1].end=true;
	for(int i=1;i<=node[id-1].con.size();i++)
	{
		int ad=node[id-1].con[i-1];
		if(node[ad-1].end==true)
			node[id-1].from_root+=node[ad-1].from_root+node[id-1].dis[i-1];
		else
			node[id-1].child.push_back(node[id-1].con[i-1]);
	}
	for(int i=1;i<=node[id-1].child.size();i++)
	{
		preorder(node[id-1].child[i-1]);
	}
}

int main(void)
{
	int n;
	cin >> n;
	for(int i=1;i<=n-1;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		node[a-1].con.push_back(b);
		node[a-1].dis.push_back(c);
		node[b-1].con.push_back(a);
		node[b-1].dis.push_back(c);
	}
	for(int i=1;i<=n;i++)node[i-1].end=false;
	
	int q,k;
	cin >> q >> k;
	preorder(k);
	
	for(int i=1;i<=q;i++)
	{
		int x,y;
		cin >> x >> y;
		cout << node[x-1].from_root+node[y-1].from_root << endl;
	}
}

Measured memory_bytes: 24448
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<string>a(vector<string>b) {
	vector<string>ans(8, string(8, 'a'));
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) {
			ans[7 - j][i] = b[i][j];
		}
	}
	return ans;
}

int main() {
	int N; cin >> N;
	while (N--) {
		int h, m;
		scanf("%d:%d", &h, &m);
		m = h * 60 + m;
		int ans = 11*m;
		ans %= 720;
		if (ans >= 360)ans = 720 - ans;
		if (ans < 60)cout << "alert" << endl;
		else if(ans < 180)cout << "warning" << endl;
		else cout << "safe" << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#if 0
date +%Y.%m.%d

题解先咕着。
        ▁▃▄▄▄▃▃▃▃▄▶
      ▗▇▀▔    ▔▔▔▔
     ▄▛   ▃▅━━■▄▂
    ▟▊   ▐▘     ▀▙
   ▟▜▌   ▐▖   ▋  ▐▍
  ▟▘ ▜   ▝▀▇▆●▘  ▐▌
▗▟▘   ▜▃       ▁▅▛
▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔   CopyRight :)
      ▔▔▔▔▔▔
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

const int maxn = 5050, mod = 1000000007;
int fa[maxn];
int deg[maxn];
int size[maxn];
int topsort[maxn], tp;
int bl[maxn];
int a[maxn], ap;
ll f[maxn];

inline int find (int x) {
	if (bl[x] == x) return x;
	return bl[x] = find(bl[x]);
}

inline ll power (ll x, int k) {
	if (k < 0) k += mod - 1;
	ll res = 1;
	while (k) {
		if (k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

int main () {
	int n = read, tot = 0;
	for (int i = 1; i <= n; i ++) {
		read(fa[i]);
		if (fa[i] != -1) ++ deg[fa[i]];
		else ++ tot;
	}

	for (int i = 1; i <= n; i ++)
		if (!deg[i])
			topsort[++ tp] = i;

	for (int i = 1; i <= tp; i ++) {
		int u = topsort[i];
		++ size[u];
		if (fa[u] != -1) {
			if (-- deg[fa[u]] == 0)
				topsort[++ tp] = fa[u];
			size[fa[u]] += size[u];
		}
	}

	ll sum = 0, inv = power(n - 1, -1);
	for (int i = 1; i <= n; i ++)
		if (fa[i] == -1) {
			(sum += (n - size[i]) * inv) %= mod;
			a[++ ap] = size[i];
		}

	f[0] = 1;
	for (int i = 1; i <= ap; i ++) {
		for (int j = i; j; j --)
			(f[j] += f[j - 1] * a[i] % mod * inv) %= mod;
	}

	ll fac = 1;
	for (int i = 2; i <= ap; i ++) {
		(fac *= i - 1) %= mod;
		(sum += (mod - fac) * f[i]) %= mod;
	}

	for (int i = 1; i <= n; i ++) bl[i] = i;
	for (int i = 1; i <= n; i ++)
		if (fa[i] != -1) {
			int x = find(i), y = find(fa[i]);
			bl[x] = y;
		}

	int C = 0;
	for (int i = 1; i <= n; i ++)
		if (bl[i] == i)
			++ C;

	printf("%lld\n", (n - C + sum) * power(n - 1, tot) % mod);
}


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

int main()
{
    int H,W,K;
    cin >> H >> W >> K;

    vector<string> c(H);
    rep(i, H) cin >> c[i];

    ll ans = 0;

    for (int bh = 0; bh < (1<<H); bh++){
        for (int bw = 0;bw<(1<<W); bw++){
            ll cnt = 0;

            for (int h = 0; h < H;h++){
                if (!((bh >> h) & 1)) continue;
                for (int w = 0; w < W; w++) {
                    if (!((bw >> w) & 1)) continue;

                    if (c[h][w] == '#') cnt++;
                }
            }

            if (cnt == K) ans++;

        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3656
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[100005]={},cnt=0,ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n-1; i++) {
    if(a[i]>=a[i+1]) {
      cnt++;
      ans=max(ans,cnt);
    }
    else {
      cnt=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
    int a,b,c,i,n=0,s;
    scanf("%d%d%d",&a,&b,&c);
    for(i=0;i<b-a+1;i++){
        if(c%(i+a)==0){
            s=n+1;
        }
        else{
            s=n;
        }
        n=s;
    }
    printf("%d\n",n);
    return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n,m;
    cin>>n>>m;
    lint x[1005];
    lint y[1005];
    lint z[1005];
    rep(i,n){
        cin>>x[i]>>y[i]>>z[i];
    }
    lint res=0;
    rep(i,1<<3){
        lint sum=0;
        vector<lint> v;
        v.resize(n);
        rep(j,n){
            if(i>>0 & 1){
                v[j]+=-x[j];
            }else{
                v[j]+=x[j];
            }
            if(i>>1 & 1){
                v[j]+=-y[j];
             }else{
                v[j]+=y[j];
            }
            if(i>>2 & 1){
                v[j]+=-z[j];
             }else{
                v[j]+=z[j];
            }
        }
        sort(v.rbegin(),v.rend());
        rep(j,m){
            sum+=v[j];
        }
        res=max(res,sum);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
cnt = 0
ans = 0
for i in range(len(s)):
  if s[i] == 'A' or s[i] == 'T' or s[i] == 'G' or s[i] == 'C':
    cnt += 1
  else:
    ans = max(ans, cnt)
    cnt = 0
  
print(max(ans, cnt))

Measured memory_bytes: 3060
N, M, X = map(int, input().split())
A=[['' for i in range(M)] for j in range(N)]
C=[0 for j in range(N)]
check=[]
minMoney=12000001
flag=False
for i in range(N):
    x=list(map(int,input().split()))
    C[i]=x[0]
    A[i]=x[1:]
for i in range(2**N):
    count=0
    Acheck=[0 for i in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            flag=True
            count+=C[j]
            for k in range(M):
                Acheck[k]+=A[j][k]
                if Acheck[k]<X:
                    flag=False
    
    if flag:
        minMoney=min(count,minMoney)
    #print(i,"通り目", minMoney,Acheck)
if minMoney==12000001:
    print(-1)
else:
    print(minMoney)

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

int main(void) {
    const string ret[3] = {"Alice", "Bob", "Draw"};
    int a, b, pos;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    a = (a == 1)? a + 13 : a;
    b = (b == 1)? b + 13 : b;
    if (a > b) {
        pos = 0;
    } else if (a < b) {
        pos = 1;
    } else {
        pos = 2;
    }

    cout << ret[pos] << "\n";
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    D, G = map(int, input().split())
    G //= 100

    P, C = [], []
    for _ in range(D):
        p, c = map(int, input().split())
        c //= 100
        P.append(p)
        C.append(c)

    dp = [[INF] * (2 * 10 ** 5 + 10) for _ in range(11)]
    dp[0][0] = 0
    for i in range(D):
        for j in range(len(dp[0])):
            if dp[i][j] == INF:
                continue

            for k in range(P[i] + 1):
                score = (i + 1) * k
                if k == P[i]:
                    score += C[i]
                dp[i + 1][j + score] = min(dp[i + 1][j + score], dp[i][j] + k)

    ans = INF
    for i in range(len(dp)):
        for j in range(len(dp[0])):
            if j >= G:
                ans = min(ans, dp[i][j])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 113076
#include <assert.h>
#include <stdio.h>

int main() {
  unsigned int k, n, i, first, last, a, max = 0;
  assert(scanf("%d %d", &k, &n) == 2);
  assert(scanf("%d", &first) == 1);
  last = first;
  for (i = 1; i < n; i++) {
    assert(scanf("%d", &a) == 1);
    a = a - last;
    last += a;
    if (max < a) {
      max = a;
    }
  }
  a = k - (last - first);
  if (max < a) {
    max = a;
  }
  printf("%d\n", k - max);
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

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

    //行をi列打って列をj列打った時に黒になる数がKかどうか全探索する
    for(int i=0;i<=N;i++){
      for(int j=0;j<=M;j++){
        //i行j列打つと、黒になる数は、i*N+j*M-i*j*2
        if(K==i*M+j*N-i*j*2){
          System.out.println("Yes");
          return;
        }
      }
    }
    //見つからなかったら終わり
    System.out.println("No");




  }

    


}


Measured memory_bytes: 23892
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 500005;

// fenwick

ll fen_tree[N];

void update(ll x,ll n){
    while(x<N){
        fen_tree[x] += n;
        x += (x&(-x));
    }
}
 
ll query(ll x){
    ll ans=0;
    while(x>0){
        ans += fen_tree[x];
        x -= (x&(-x));
    }
    return ans;
}

ll last[N], A[N], ans[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, q;
    cin >> n >> q;
    rep(i,1,n+1)	cin >> A[i];
    vector<pair<pll,ll>> v;
    rep(i,0,q){
    	ll l,r;
    	cin >> l >> r;
    	v.pb({{r, l}, i});
    }
    sort(all(v));
    ll cur_r = 0;
    rep(j,0,q){
    	while(cur_r < v[j].ft.ft){
	    	cur_r++;
	    	ll i = cur_r;
	    	if(last[A[i]] == 0){
	    		last[A[i]] = i;
	    		update(i, 1);
	    	}
	    	else{
	    		update(last[A[i]], -1);
	    		last[A[i]] = i;
	    		update(i, 1);
	    	}
	    }
	    ll g = query(cur_r) - query(v[j].ft.sd - 1);
    	ans[v[j].sd] = g;
    }
    rep(i,0,q)	cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 31264
N = gets.to_i
line = gets.split(' ').map(&:to_i)

a = 0
for i in 1..N-1
    if line[i-1] - line[i] > 0
        a += line[i-1] - line[i]
        line[i] = line [i-1]
    end
end
p a


Measured memory_bytes: 28036
#include<stdio.h>

int main()
{
        int a,b,c,d,p;
        int cost_x, cost_y;

        scanf("%d%d%d%d%d", &a, &b, &c, &d, &p);

        cost_x = a*p;
        cost_y = b + ((p<=c)?(0):(d*(p-c)));
        printf("%d\n", (cost_x>cost_y)?cost_y:cost_x);

        return 0;
}

Measured memory_bytes: 596
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let x: usize = sc.read();
    println!("{}", 1 ^ x);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int x = Integer.parseInt(s[0]);
        int y = Integer.parseInt(s[1]);
        for(int i=0; i<=x; i++) {
            int b = x - i;
            if(2*i + 4*b == y) {
                System.out.print("Yes");
                return;
            }
        }
        System.out.print("No");
    }
}

Measured memory_bytes: 32816
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll n, m;
vector<ll> s, t;
ll memo[2200][2200];
ll rec(ll i, ll j){
    if(i == 0 && j == 0) return 1;
    if(memo[i][j] != -1) return memo[i][j];
    ll res = 0;
    if(s[i - 1] == t[j - 1]){
        if(i - 1 >= 0 && j - 1 >= 0) res += rec(i - 1, j - 1);
    }
    res %= MOD;
    if(i - 1 >= 0) res += rec(i - 1, j);
    res %= MOD;
    if(j - 1 >= 0) res += rec(i, j - 1);
    res %= MOD;
    if(i - 1 >= 0 && j - 1 >= 0) res -= rec(i - 1, j - 1);
    res %= MOD;

    //cout << i << " " << j << " " << res << endl;
    return memo[i][j] = res;
}
int main(void){
    int n, m;
    cin >> n >> m;
    s.resize(n);
    t.resize(m);
    rep(i,n) cin >> s[i];
    rep(i,m) cin >> t[i];
    rep(i,2020){
        rep(j,2020){
            memo[i][j] = -1;
        }
    }
    ll ans = rec(n, m);
    while(ans < 0) ans += MOD;
    cout << ans % MOD << endl;
}

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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  ll n;
  cin >> n;
  bool ans=true;
  ll max=0;
  vector<ll> v(n);
  rep(i,n){
    cin >>v[i];
  }
  rep(i,n-1){
    if (n==1){
      ans=true;
      break;
    }
    if (v[i]>v[i+1]){
      max=v[i];
      for (ll j=i+1; j < n;j++){
        if (v[i]> v[j]+1){
          ans=false;
          break;
        }
      }
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
      
    
  return 0;
}


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

int main () {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<int> count(N);
    for (int i = 0; i < N; i++) {
        count.at(A.at(i) - 1)++;
    }
    sort(count.begin(), count.end());
    reverse(count.begin(), count.end());
    int ans = 0;
    for (int i = K; i < N; i++) {
        ans += count.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string S;
    cin >> S;
    //すべてWにする
    // BBWWWWのときは1
    // BBWBWWときはみぎにBおいてWWで3
    // Bが連結してないといけない
    int ans = 0;
    REP(i, S.length()) {
        if(i == 0 and S[i] == 'B') {
            ans++;
        } else if(S[i] == 'B' and S[i - 1] != 'B') {
            ans += 2;
        }
        if(i == S.length() - 1 and S[i] == 'B') {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Solve()
    {
        var i = ReadInts();

        Console.WriteLine((i[0] * 3 + i[1]) / 2);
    }


    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();

    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}

Measured memory_bytes: 13396
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
arr.some(function(v){
   if(v==0)return true;
   var cnt=0;
   for(var a=1;a<=181;a++){
      var A=a*a;
      if(v<A)break;
      if(A==v)cnt++;
      for(var b=a;b<=181;b++){
         var B=A+b*b;
         if(v<B)break;
         if(B==v)cnt++;
         for(var c=b;c<=181;c++){
            var C=B+c*c;
            if(v<C)break;
            if(C==v)cnt++;
            for(var d=c;d<=181;d++){
               var D=C+d*d;
               if(v<D)break;
               if(D==v)cnt++;
   }}}}
   console.log(cnt);
});

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

using namespace std;

int main(){
  int n;
  vector<string> sub;
  map<string, int> s;
  cin >> n;
  for(int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    sub.push_back(tmp);

    auto itr = s.find(tmp);
    if(itr != s.end()) {
      itr->second += 1;
    } else {
      s.insert(make_pair(tmp, 1));
    }
  }

  sort(sub.begin(), sub.end());
  sub.erase(unique(sub.begin(), sub.end()), sub.end());

  int max_str = 0;
  for(string x : sub) {
    auto itr = s.find(x);
    int s_cnt = itr->second;
    max_str = max(max_str, s_cnt);
  }

  for(string x : sub) {
    auto itr = s.find(x);
    int s_cnt = itr->second;
    if(max_str == s_cnt) cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 25124
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


vector<vector<ll>> bargers(51, vector<ll>());
vector<ll> make_barger(int level){

	if(level == 0){
		vector<ll> vec = {1};
		return vec;
	}
	if(level == 1){
		vector<ll> vec = {1, 3, 1};
		return vec;
	}
	if(bargers[level].size() != 0) return bargers[level];
	
	vector<ll> left = make_barger(level - 1);
	vector<ll> right = left;
	left[0]++;		right.back()++;
		
	vector<ll> barger = left;
	barger.push_back(1);
	barger.insert(end(barger), begin(right), end(right));//barger.push_back(right);

	return bargers[level] = barger;
	
}


ll calc(int level, ll X){

	// an = 2 a_n-1  + 3 を解くと
	// an = 4 2^n  -3  　なので  a_n-1 = 4 2^(n-1) -3	
	ll a_n_1 = 4 * pow((ll)2, level-1) -3; 	
	ll a_n =   4 * pow((ll)2, level)   -3;
	// ll a_n_1 = (ll)4*((ll)1 << (level-1)) - 3; 	
	// ll a_n =  (ll)4 * ((ll)2 << (level)) -3;
	//if(X == 0) return 0;
	if(level == 0 && X <= 0) return 1;
	if(level == 0) return 1;
	
	if(X == 1) return 0;
	if(X <= a_n_1 + 1) return calc(level-1, X - 1);
	if(X == a_n_1 + 2) return calc(level-1, a_n_1) + 1;
	if(X == a_n) return 2 * calc(level-1, a_n_1) + 1;
	return calc(level-1, a_n_1) + 1 + calc(level-1, X-a_n_1-2);// (B  レベルN-1   p) の中のパティの個数  +  レベルN-1の途中のパティの個数
	// ll p_n_1 = pow(2, level) - 1; // pn = 2^(n+1) - 1;  // pn = 1 + 2pn_1を解いた
	// if(X == a_n_1 + 2) return p_n_1 + 1;
	// if(X == a_n) return 2 * p_n_1 + 1;
	// return p_n_1 + 1 + calc(level-1, X-a_n_1-2);
}

int main(){
	int N;
	ll X;
	cin >> N >> X;
	// vector<ll> barger = make_barger(N);

	// ll ans = 0;
	// for(ll i=0; i<barger.size(); i++){
	// 	if(i%2 == 1) ans += min(X, barger[i]);
	// 	X -= barger[i];
	// 	if(X <= 0) break;
	// }


	ll ans = calc(N, X);
	cout << ans << endl;

}



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

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n)
    {
        cin >> c.at(i);
        rep(j, m)
        {
            cin >> a.at(i).at(j);
        }
    }

    int answer = INT_MAX;
    for (int bit = 0; bit < (1 << n); ++bit)
    {
        vector<int> s; // 選ばれた参考書
        for (int i = 0; i < n; ++i)
        {
            if (bit & (1 << i))
            {
                s.push_back(i);
            }
        }

        vector<int> sum_algo(m, 0);
        int price = 0;
        for (int i = 0; i < (int)s.size(); ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                sum_algo.at(j) += a.at(s.at(i)).at(j);
            }
            price += c.at(s.at(i));
        }

        bool is_all_ok = true;
        rep(i, m)
        {
            if (sum_algo.at(i) < x)
            {
                is_all_ok = false;
            }
        }

        if (is_all_ok)
            answer = min(answer, price);
    }

    if (answer == INT_MAX)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << answer << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::unordered_set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui a, b; cin >> a >> b;
  auto ans = a <= 8 && b <= 8;

  cout << (ans ? "Yay!" : ":(" ) << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int N,cnt;
vector<int>A;
void bubbleSort(){
  bool flag=true;
  while(flag){
    flag=false;
    for(int i=N-1;i>0;i--){
      if(A[i]<A[i-1]){
        swap(A[i],A[i-1]);
        flag=true;
        cnt++;
      }
    }
  }
}
int main(void){
  cin>>N;
  A.resize(N);
  for(int i=0;i<N;i++)cin>>A[i];
  bubbleSort();
  for(int i=0;i<N;i++)cout<<A[i]<<(i==N-1?'\n':' ');
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}





int main(){
  int n,N;
  cin >> n;
  N = 3*n;
  ll a[N];
  rep(i,N) cin >> a[i];
  sort(a,a+N,greater<int>());
  ll ans = 0;
  int idx = 0;
  for(int i = 0;; i++){
    if(i%2==1){
      ans += a[i];
      idx++;
    }
    if(idx == n) break;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 2560
from collections import OrderedDict
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    d = OrderedDict({
        "AC": 0,
        "WA": 0,
        "TLE": 0,
        "RE": 0
    })

    for _ in range(N):
        s = input().strip()
        d[s] += 1

    for k, v in d.items():
        print("{} x {}".format(k, v))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 9476