akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

ll n;
int main(){
	cin >> n;
	ll ans = 0;
	ans = (ll)n / 10;
	for(int i = 1; i < 50; i++){
		ll temp = pow(5,i) * 10;
		ans += (ll) n / temp;
	}
	if(n%2 != 0)ans = 0;
	cout << ans << endl;
 }

Measured memory_bytes: 256
const main = input => {
  const [N, K] = input.trim().split(' ').map(x => parseInt(x))
  let count = 0
  for (let i = 0; i < N; i++) {
    if (i === 0) {
      count += K
      continue
    }
    count *= (K - 1)
  }

  console.log(count)
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;

int main() {
	ll N, M;
	cin >> N >> M;
	if (N >= M / 2) {
		cout << M / 2 << endl;
	}
	else {
		ll ans = N;
		M -= N * 2;
		ans += M / 4;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  ll cnt[5] = {};
  for(int i=0;i<N;i++){
    string str;
    cin >> str;
    char s = str[0];
    if(s=='M') cnt[0]++;
    else if(s=='A') cnt[1]++;
    else if(s=='R') cnt[2]++;
    else if(s=='C') cnt[3]++;
    else if(s=='H') cnt[4]++;
  }
  //cout << mp['M'] << endl;

  ll ans = 0LL;
  for(int i=0; i<(1 << 5) ; i++){
    vector<int> use;
    int tmpi = i;
    for(int j=0;j<5;j++){
      if(tmpi%2==1) use.push_back(j);
      tmpi /= 2;
    }
    if(use.size()==3){
      ans += cnt[use[0]] * cnt[use[1]] * cnt[use[2]];
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque


def LI():
    return list(map(int, input().split()))


def LSH(h):
    return [list(input()) for _ in range(h)]


H, W = LI()
MAP = LSH(H)
d = deque()
d.append([0, 0])
looked = [[0 for i in range(W)]for j in range(H)]
looked[0][0] = 1
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
while d:
    x = d.popleft()
    h = x[0]
    w = x[1]
    for i in move:
        a = h+i[0]
        b = w+i[1]
        if not(0 <= a < H) or not(0 <= b < W) or looked[a][b] != 0 or MAP[a][b] == "#":
            continue
        d.append([a, b])
        looked[a][b] = looked[h][w]+1
if looked[H-1][W-1] == 0:
    print(-1)
    sys.exit()

white = 0
for i in range(H):
    for j in range(W):
        if MAP[i][j] == ".":
            white += 1

print(white-looked[H-1][W-1])


Measured memory_bytes: 9508
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX 110000

int n;
vector<pair<int,int>> G[MAX];
int dis[MAX];

void dfs1(int node, int previous){
	int maximum = 0;
	
	for(int i = 0; i < G[node].size(); i++){
		if(previous == G[node][i].first) continue;
		dfs1(G[node][i].first, node);
		maximum = max(maximum, dis[G[node][i].first] + G[node][i].second);
	}
	
	dis[node] = maximum;
}

int dfs2(int node, int previous, int pmax){
	vector<pair<int,int>> dis2;
	int maximum = 0, res = 0;
	
	dis2.push_back(make_pair(pmax, previous));
	
	for(int i = 0; i < G[node].size(); i++){
		if(previous == G[node][i].first) continue;
		dis2.push_back(make_pair(dis[G[node][i].first] + G[node][i].second, G[node][i].first));
	}
	
	sort(dis2.begin(), dis2.end(), greater<pair<int,int>>());
	
	for(int i = 0; i < dis2.size() && i < 2; i++){
		maximum += dis2[i].first;
	}
	
	
	for(int i = 0; i < G[node].size(); i++){
		if(previous == G[node][i].first) continue;
		int npmax = 0;
		if(dis2.size() && G[node][i].first != dis2[0].second) npmax = dis2[0].first;
		if(dis2.size() >= 2 && G[node][i].first == dis2[0].second)  npmax = dis2[1].first;
		
		maximum = max(maximum, dfs2(G[node][i].first, node, npmax + G[node][i].second));
	}
	
	return maximum;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int s, t, w;
	int start = 0;
	
	cin >> n;
	
	for(int i = 0; i < n-1; i++){
		cin >> s >> t >> w;
		G[s].push_back(make_pair(t,w));
		G[t].push_back(make_pair(s,w));
	}
	
	dfs1(start,-1);
	
	cout<<dfs2(start, -1, 0)<<endl;
	return 0;
}


Measured memory_bytes: 26684
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
ll n;
ll cnt;
ll a[100000];
ll za[100000];
int main()
{
	cin>>n;
	rep(i,n) cin>>a[i];
	za[0]=1;
	cnt=1;
	rep1(i,n-1){
		if(a[i]^a[i-1]) za[cnt-1]++;
		else{
			za[cnt]++;
			cnt++;
		}
	}
	ll ans=0;
	rep(i,cnt){
		ans=max(ans,za[i]+za[i+1]+za[i+2]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4280
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = int;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

vector<ll>prefix_function(vector<ll> s) {
	vector<ll> p(s.size());
	ll n = s.size();
	for (ll i = 1; i < n; i++) {
		ll j = p[i - 1];
		while (s[j] != s[i] && j > 0) {
			j = p[j - 1];
		}
		if (s[i] == s[j]) {
			j++;
		}
		p[i] = j;
	}
	return p;
}

void inter(unordered_set<ll> &s1, unordered_set<ll> &s2) {
	vector<ll>to_del;
	for (auto x : s1) {
		if (!s2.count(x)) {
			to_del.push_back(x);
		}
	}
	for (auto x : to_del) {
		s1.erase(x);
	}
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n = 2e5 + 5; cin >> n;
	vector<ll>a(n), b(n);
	for (ll i = 0; i < n; i++) { a[i] = gen() % (1LL << 30) + 1; cin >> a[i]; };
	for (ll i = 0; i < n; i++) { b[i] = gen() % (1LL << 30) + 1; cin >> b[i]; };

	for (ll i = 0; i < n; i++) {
		a.push_back(a[i]);
	}

	unordered_set<ll>st;
	for (ll i = 0; i < n; i++) {
		st.insert(i);
	}

	for (ll bit = 0; bit < 31; bit++) {
		if (st.empty()) break;
		unordered_set<ll>new_st;
		auto aa0 = a;
		for (auto& x : aa0) {
			x = 1 & (x >> bit);
		}
		auto aa1 = a;
		for (auto& x : aa1) {
			x = 1 ^ (1 & (x >> bit));
		}
		auto bb = b;
		for (auto& x : bb) {
			x = 1 & (x >> bit);
		}

		auto v0 = bb; v0.push_back(-1);
		for (auto x : aa0) v0.push_back(x);

		auto v1 = bb; v1.push_back(-1); 
		for (auto x : aa1) v1.push_back(x);

		auto pr0 = prefix_function(v0);
		auto pr1 = prefix_function(v1);
		for (ll i = 2 * n; i < 3 * n; i++) {
			if (pr0[i] == n || pr1[i] == n) {
				new_st.insert((i - 2 * n));
			}
		}
		inter(st, new_st);
	}
	
	vector<int> ans;
	for (auto x : st) ans.push_back(x);
	sort(all(ans));
	for (auto x : ans) {
		cout << x << " " << (a[x] ^ b[0]) << '\n';
	}

	return 0;
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 33228
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional> 
#include <vector>

using namespace std;

int main(){

    int n;
    cin >> n;

    if((n/1000) == (n/100)%10 && (n/10)%10 == (n/100)%10){
        cout << "Yes";
    }else if((n%10) == (n/100)%10 && (n/10)%10 == (n/100)%10){
        cout << "Yes";
    }else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

class solver {
public:
	int N;
	vector<vector<pair<int, int>>> G;
	vector<bool> done;
	vector<ll> D;
	solver(const vector<vector<pair<int, int>>>& g)
		: G(g), N((int)g.size()), done(N), D(N)
	{ }
	bool dfs(int cur, ll S)
	{
		if (done[cur]) {
			if (D[cur] != S) {
				return false;
			}
			return true;
		}
		done[cur] = true;
		D[cur] = S;
		for (const auto& e : G[cur]) {
			if (!dfs(e.first, S + e.second))
				return false;
		}
		return true;
	}

	bool solve()
	{
		for (int i = 0; i < N; i++)
			if (!done[i])
				if (!dfs(i, 0))
					return false;
		return true;
	}
};

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<pair<int, int>>> G(N, vector<pair<int, int>>());
	for (int i = 0; i < M; i++) {
		int L, R, D;
		cin >> L >> R >> D;
		L--; R--;
		G[L].emplace_back(R, D);
		G[R].emplace_back(L, -D);
	}
	solver S(G);
	bool ans = S.solve();
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 17408
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld radian(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible\n";
	else
		cout << "Impossible\n";
	getchar(); getchar();
}

Measured memory_bytes: 256
n,*p=map(int,open(0).read().split())
p=[0]+p
ans=0
for i in range(1,n):
  if p[i]==i:
    p[i],p[i+1]=p[i+1],p[i]
    ans+=1
if p[n]==n:
  p[n-1],p[n]=p[n],p[n-1]
  ans+=1
print(ans)

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

typedef long long ll;
const int N = 200000;
const int INFTY = 1000000001;


ll merge(int left, int mid, int right, int A[]) {
  ll cnt = 0;
  int i, j, k, n1, n2, *L, *R;
  
  n1 = mid - left;
  n2 = right - mid;
  L = new int[n1+1];
  R = new int[n2+1];

  for (i = 0; i < n1; i++) L[i] = A[left+i];
  for (i = 0; i < n2; i++) R[i] = A[mid+i];
  L[n1] = R[n2] = INFTY;

  j = k = 0;
  for (i = left; i < right; i++) {
    if (L[j] <= R[k]) {
      A[i] = L[j++];
    } else {
      A[i] = R[k++];
      cnt += n1 - j;
    }
  }

  delete [] L;
  delete [] R;

  return cnt;
}

ll merge_sort(int left, int right, int A[]) {
  if (left + 1 < right) {
    ll cnt1, cnt2, cnt3;
    int mid = (left + right) / 2;
    cnt1 = merge_sort(left, mid, A);
    cnt2 = merge_sort(mid, right, A);
    cnt3 = merge(left, mid, right, A);
    return cnt1 + cnt2 + cnt3;
  } else {
    return 0;
  }
}
  

int main() {
  int n;
  int A[N];

  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];

  ll cnt = merge_sort(0, n, A);

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 4384
#include<stdio.h>
int main(){
  int n,m,i;
  scanf("%d%d",&n,&m);
  int gcd=m/n;
  for(i=gcd;i>0;i--){
    if(m%i==0){
      printf("%d\n",i);
      return 0;
    }
  }
  return 0;
}


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

#define lowbit(x) ((x) & -(x))

const int maxn = 1e5 + 20;
const int MOD = (int) 1e9 + 7;

int n;
pair<string, int> p[maxn];
int rk[maxn];

int cmp(int x, int y)
{
    if(p[x].first != p[y].first) return p[x].first < p[y].first;
    return p[x].second > p[y].second;
}

void work()
{
    cin >>n;
    for(int i = 0; i < n; i++)
        cin >>p[i].first >>p[i].second;

    for(int i = 0; i < n; i++)
        rk[i] = i;
    sort(rk, rk + n, cmp);

    for(int i = 0; i < n; i++)
        cout <<rk[i] + 1 <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    int tc = 1;
//    cin >>tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main() {
    int N;
	string A, B, C;
	cin >> N >> A >> B >> C;
	int ans=0;
	for(int i=0; i<N; ++i){
	    if(A[i]!=B[i]){
	        ++ans;
	        if(A[i]!=C[i] && B[i]!=C[i]) ++ans;
	    }
	    else if(A[i]!=C[i]) ++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

string solve() {
  string in, ret;
  cin >> in;
  const int sz = in.size();
  ret.insert(0, 1, in[0]);
  for (int i = 0; i < sz; i+=3) {
    if (i == sz-1) {
      continue;
    } else {
      int l = -1;
      rep (j,ret.size()) if (in[i] == ret[j]) { l = j; break; }
      char c = in[i+3];
      if (in[i+2] == '>') {
        if (l == ret.size() - 1) {
          ret.insert(l+1, 1, c);
        }
      } else {
        if (l == 0) {
          ret.insert(l, 1, c);
        }
      }
    }
  }
  return ret;  
}

int main() {
  int n;
  cin >> n;
  rep (i,n) cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 0
N = int(input())
text = list("MARCH")
dict = {}
for t in text:
    dict[t] = 0
for _ in range(N):
    x = input()[0]
    if x in text:
        dict[x] += 1

ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += dict[text[i]]*dict[text[j]]*dict[text[k]]
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
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(){
  int n;
  double ans = 0;
  cin >> n;
  REP(i, n){
    int d;
    cin >> d;
    ans += (double)1.0/(double)d;
  }
  cout << shosu(20) << (double)1.0/(double)ans << endl;
}

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

using namespace std;

const int ATOZ = 26;

int satisfaction(int d, int prev_v, const vector<int>& c, const vector<vector<int> >& s, const vector<int>& t, map<int, int>& last) {
    int v = prev_v + s[d][t[d]];
    last[t[d]] = d;
    for (int i = 0; i < ATOZ; ++i) {
        v -= c[i] * (d - last[i]);
    }
    return v;
}

int finalSatisfaction(const vector<int>& c, const vector<vector<int> >& s, const vector<int>& t, map<int, int>& last) {
    int v = 0;
    for (int d = 0; d < s.size(); ++d) {
        v = satisfaction(d, v, c, s, t, last);
    }
    return v;
}

void reset(map<int, int>& last) {
    last.clear();
    for (int i = 0; i < ATOZ; ++i) {
        last.insert(make_pair(i, -1));
    }
}

void Main() {
    int D;
    cin >> D;
    vector<int> c(ATOZ, 0);
    for (int i = 0; i < ATOZ; ++i) {
        cin >> c[i];
    }
    vector<vector<int> > s(D, vector<int>(ATOZ, 0));
    for (int i = 0; i < D; ++i) {
        for (int j = 0; j < ATOZ; ++j) {
            cin >> s[i][j];
        }
    }

    vector<int> t(D, 0);
    for (int d = 0; d < D; ++d) {
        auto maxIt = max_element(s[d].begin(), s[d].end());
        t[d] = 1 + distance(s[d].begin(), maxIt);
        cout << t[d] << endl;
    }

    //map<int, int> last;
    //reset(last);
    //int v = 0;
    //for (int d = 0; d < D; ++d) {
    //    v = satisfaction(d, v, c, s, t, last);
    //    cout << v << endl;
    //}
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int alice = 0,bob = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int t;

    for (int i = 0; i < n; i++){
        t = n - 1 - i;
        if (i % 2 == 0){
            alice += a[t];
        }else{
            bob += a[t];
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

vector<vector<char>> M(52, vector<char>(52, '.'));

bool can_draw(int i, int j) {
    if (M[i - 1][j] == '.' && M[i + 1][j] == '.' && M[i][j - 1] == '.' && M[i][j + 1] == '.') {
        return false;
    }
    return true;
}

int main() {
    int h, w; cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> M[i][j];
        }
    }

    bool flag = true;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (M[i][j] == '#') {
                if (!can_draw(i, j)) flag = false;
            }
        }
    }
    
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    int a;
    std::string s;

    std::cin >> a;
    std::cin >> s;

    if (a >= 3200) {
        std::cout << s << std::endl;
    }
    else if (a < 3200) {
        std::cout << "red" << std::endl;
    }
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
int field[1000][1000] = {};
#define MAX_SIZE 1000001
int main(void)
{
  int h, w;
  int ans = 0;
  string f[1000] = {};
  cin >> h >> w;
  rep(i, h){
    rep(j, w){
      field[i][j] = MAX_SIZE;
    }
  } 
   rep(i, h){
   cin >> f[i];
  }
  rep(i, h){
    int tmp = MAX_SIZE;
    rep(j, w){
      if(f[i][j] == '#') tmp = 0;
      else tmp++;
      chmin(field[i][j], tmp);
      tmp = field[i][j];
    }
  } 
  rep(i, h){
    int tmp = MAX_SIZE;
    for(int j = w - 1; j >= 0; j--){
      if(f[i][j] == '#') tmp = 0;
      else tmp++;
      chmin(field[i][j], tmp);
      tmp = field[i][j];
    }
  }
  rep(j, w){
    int tmp = MAX_SIZE;
    rep(i, h){
      if(f[i][j] == '#') tmp = 0;
      else tmp++;
      chmin(field[i][j], tmp);
      tmp = field[i][j];
    }
  }
  rep(j, w){
    int tmp = MAX_SIZE;
    for(int i = h - 1; i >= 0; i--){
      if(f[i][j] == '#') tmp = 0;
      else tmp++;
      chmin(field[i][j], tmp);
      tmp = field[i][j];
      chmax(ans, tmp);
    }
  }
  cout << ans << endl;
  // rep(i, h){rep(j, w){cout << field[i][j] << " ";}cout << endl;}
  return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int iin();
long long llin();
double din();
char cin();
void stin(char *s);
void iout(int i);
void llout(long long i);
void dout(double i);
void cout(char c);
void stout(char *s);
int gcd(int a, int b);
int lcm(int a, int b);
long long llgcd(long long a, long long b);
long long lllcm(long long a, long long b);
int asc(const void *a, const void *b);
int desc(const void *a, const void *b);

//main function
int main() {
    int x = iin();
    stout(x < 1200 ? "ABC" : "ARC");
    return 0;
}

//body function
int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

/*
    int型の最大公約数
*/

int gcd(int a, int b) {
    int r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    int型の最小公倍数
*/

int lcm(int a, int b) {
    int r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    long long型の最大公約数
*/

long long llgcd(long long a, long long b) {
    long long r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    long long型の最小公倍数
*/

long long lllcm(long long a, long long b) {
    long long r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    int型の昇順用比較関数
*/

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

/*
    int型の降順用比較関数
*/

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}


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

int cnt[26];

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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c; cin >> c;
      cnt[c - 'a']++;
    }
  }

  int v1 = 0, v2 = 0, v4 = 0;
  if ((n & 1) && (m & 1)) {
    v1 = 1;
  }
  if (n & 1) v2 += m / 2;
  if (m & 1) v2 += n / 2;
  v4 = (n / 2) * (m / 2);

  priority_queue<int> q;
  for (int i = 0; i < 26; i++) {
    if (cnt[i]) q.push(cnt[i]);
  }

//  cout << v1 << " " << v2 << " " << v4 << endl;
  while (!q.empty() && (v1 || v2 || v4)) {
    int v = q.top(); q.pop();
    if (v4) v -= 4, v4--;
    else if (v2) v -= 2, v2--;
    else if (v1) v -= 1, v1--;
    if (v < 0) {
      cout << "No" << endl;
      return 0;
    }
    if (v) q.push(v);
  }
  if (q.size() || v1 || v2 || v4) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String str = String.valueOf(S1);
       String W2=null;
       String W1=null;
        for(int count=1; count<=4;count++){
            
         W1 = str.substring(count-1,count);
        
         
            if(W1.equals(W2)){
            System.out.print("Bad");
            return;
            
        }
        
        W2=W1;
        }
        System.out.print("Good");
    }
    
}

Measured memory_bytes: 22996
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n, m = map(int, input().split())

prime_factors = []
i = 2
while i ** 2 <= m:
    ext = 0
    while m % i == 0:
        ext += 1
        m //= i
    if ext:
        prime_factors.append((i, ext))
    i += 1
if m != 1:
    prime_factors.append((m, 1))

ans = 1
for pf, num in prime_factors:
    numerator = 1
    denominator = 1
    for i in range(num):
        numerator *= ((num + (n - 1)) - i)
        denominator *= (num - i)
    ans = (ans * (numerator // denominator)) % MOD
print(ans)


Measured memory_bytes: 63148
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
 
      if(S. equals ("Sunny")){
    System.out.println("Cloudy");
      }else if(S. equals ("Cloudy")){
	System.out.println("Rainy");
      }else {
	System.out.println("Sunny");
      }
      }
}

Measured memory_bytes: 20692
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    a.push_back(k + a.at(0));

    int l = 0;
    rep(i, n) {
        l = max(l, a.at(i + 1) - a.at(i));
    }

    int ans = k - l;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4808
N, M = map(int, input().split())

ab = []
for _ in range(M):
    a, b = map(int, input().split())
    ab.append((a, b))
ab.sort(key=lambda ab: ab[::-1])

ans = 0
last = -1
for a, b in ab:
    if not a <= last < b:
        last = b - 1
        ans += 1
print(ans)

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (2*b == a + c) {
		cout << "YES" << endl;
	}
	if (2*b != a + c) {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

set<string> st;
int main() {
	int n; cin >> n;
	while(n--) {
		string s; cin >> s;
		st.insert(s);
	}
	cout << st.size() << '\n';
	return 0;
}

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

using namespace std;

int main(){
  int i, a, b, leap, count=0;
  vector<int> leapyear;

  while(1){
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    else if(count != 0) cout << endl;

    for(i=a; i<=b; ++i){
      if(i%400 == 0)
	leap = 1;
      else if(i%100 == 0)
	leap = 0;
      else if(i%4 == 0)
	leap = 1;
      else
	leap = 0;

      if(leap == 1)
	leapyear.push_back(i);
    }

    if(leapyear.size() == 0){
      cout << "NA" << endl;
    }else{
      for(vector<int>::size_type i=0; i != leapyear.size(); ++i)
	cout << leapyear[i] << endl;
    }

    leapyear.clear();
    ++count;
  }

  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll c = abs(a - b);
  if (c % 2 == 0) {
    cout << c / 2;
  } else {
    //
    ll x = (n - b) + (c + 1) / 2;
    ll y = (a - 1) + (c + 1) / 2;
    cout << min(x, y);
  }
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	vector<int> a(100000, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	map<int, int> mp; //連想配列
	for (int i = 0; i < n; i++) mp[a[i]]++; //数字a[i]の個数
	int ans = 0;
	for (auto p : mp) {
		int x = p.first; //数字
		int n = p.second; //に対する個数
		if (n < x) { //数字に対する個数が足らないときはすべて削除
			ans += n;
		}
		else { //個数が多いときはn-x個削除
			ans += n - x;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define endl '\n'
#include <math.h>
# define M_PIl 3.141592653589793238462643383279502884L
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long int R = 0;
    cin>>R;
    cout<<M_PIl*2LL*R<<endl;
    return 0;
}



Measured memory_bytes: 3808
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector> //*max_element(all(変数))で最大値を獲得
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
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; }

int main() {
  int n;  cin >> n;
  vector<int> h(n);  rep0(i,n) cin >> h[i];

  int tall = 0, ans = 0;
  rep0(i,n){
    if(tall < h[i]) ans += h[i]-tall;
    tall = h[i];
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc104() {
	ll d, g;
	ll ans = 0;

	cin >> d >> g;

	vector<ll> p(d), c(d);
	rep(i, d) {
		cin >> p[i] >> c[i];
	}

	ll score;
	ll num;
	ll diff;
	ans = INF;
	rep(i, 1 << 11) {
		score = num = 0;
		rep(j, d) {
			if (((i >> j) & 1) == 1) {
				num += p[j];
				score += 100 * (j + 1) * p[j] + c[j];
			}
		}
		if (score >= g) {
			ans = min(ans, num);
		}
		else {
			rrep(j, d - 1, 0) {
				if (((i >> j) & 1) == 0) {
					rep(k, p[j]) {
						score += 100 * (j + 1);
						num++;
						if (score >= g) {
							break;
						}
					}
				}
				if (score >= g) {
					break;
				}
			}
			ans = min(ans, num);
		}
	}

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

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

	solve_abc104();

	return 0;
}

Measured memory_bytes: 256
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=110;
int n,A[maxn],vis[maxn],S[maxn],lim[maxn]; 
void GG() {puts("Impossible");exit(0);}
int main() {
	n=read();
	rep(i,1,n) A[i]=read();
	int mx=0,x=0,y=0;
	rep(i,1,n) mx=max(mx,A[i]);
	rep(i,1,n) if(A[i]==mx) {
		if(!x) x=i;
		else y=i;
	}
	if(!y) GG();
	vis[x]=vis[y]=1;
	if(mx==1) {
		if(n==2) puts("Possible");
		else GG();
		return 0;
	}
	if(mx%2==0) {
		rep(i,1,n) if(!vis[i]) {
			S[A[i]]++;
		}
		if(S[mx/2]!=1) GG();
		rep(i,mx/2+1,mx-1) if(S[i]<2) GG();
		rep(i,0,mx/2-1) if(S[i]) GG();
		puts("Possible");
	}
	else {
		rep(i,1,n) if(!vis[i]) {
			S[A[i]]++;
		}
		if(S[(mx/2)+1]!=2) GG();
		rep(i,mx/2+2,mx-1) if(S[i]<2) GG();
		rep(i,0,mx/2) if(S[i]) GG();
		puts("Possible");
	}
	return 0;
}


Measured memory_bytes: 256
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_g
VER : AC
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 100009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
vector<int> graph[MAX];
int n,m;
bool vis[MAX];
int dp[MAX];
void dfs(int v)
{
	vis[v]=true;
	int ans=0;
	for(int u:graph[v])
	{
		if(!vis[u])
		{	
			dfs(u);
		}
		ans=max(dp[u]+1,ans);
	}
	dp[v]=ans;
}
int main() {
	fastIO
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		graph[x].pb(y);
	}
	for(int i=1;i<=n;i++)
	if(!vis[i])
	dfs(i);
	cout<<*max_element(dp+1,dp+n+1);
	
	return 0;
}

Measured memory_bytes: 8320
import  itertools
import numpy as np

N,M,X = map(int, input().split())
A = []
for i in range(N):
    A.append(np.array(list(map(int, input().split()))))

#print(A)
l = [1, 0]
ll = list(itertools.product(l, repeat=N))
#print(ll)
ans = float("inf")
for i in ll:
    jdg = np.array([0] * (M+1))
    for k in range(N):
        if i[k] == 1:
             jdg = jdg + A[k]
    #print(jdg)
    if min(jdg[1:]) >= X:
        ans = min(ans,jdg[0])
    #print(min(jdg[1:]))
if ans != float("inf"):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 27412
import java.util.Scanner;

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

		switch(S){
			case "Sunny":
			System.out.println("Cloudy");
			break;
			case "Cloudy":
			System.out.println("Rainy");
			break;
			case "Rainy":
			System.out.println("Sunny");
			break;
		}
	}
}

Measured memory_bytes: 24148
import java.util.*;

public class Main {
	static int[] a,b,c;
	static int n;
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		a=new int[n];
		b=new int[n];
		c=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=scan.nextInt();
			c[i]=scan.nextInt();
		}
		dp=new int[n][4];
		for(int i=0;i<n;i++) {
			for(int j=0;j<4;j++) dp[i][j]=-1;
		}
		System.out.println(go(0,0));
	}
	static int[][] dp;
	public static int go(int at, int prev) {
		if(at==n) return 0;
		if(dp[at][prev]!=-1) return dp[at][prev];
		int res=0;
		if(prev!=1) res=Math.max(res,a[at]+go(at+1,1));
		if(prev!=2) res=Math.max(res,b[at]+go(at+1,2));
		if(prev!=3) res=Math.max(res,c[at]+go(at+1,3));
		return dp[at][prev]=res;
	}
}

Measured memory_bytes: 105612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,k,m=0;
  cin>>n>>k;
  ll a[n],b[n+1]={},c[n+1]={};
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[i+1]=b[i]+a[i];
    c[i+1]=c[i]+max(0LL,a[i]);
  }
  for(int i=k;i<=n;i++){
    m=max({m,b[i]-b[i-k]+c[n]-c[i]+c[i-k],c[n]-c[i]+c[i-k]});
  }
  cout<<m;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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;
}
template<class T>
void DEBUG_DP(T* viewdp, int ilen, int jlen){
    REP(i,ilen){
        REP(j,jlen){
            if(viewdp[i][j] != -1)
                printf("[% 4d]", viewdp[i][j]);
            else
                printf("[    ]");
        }
        puts("");
    }
}

int main() {
    //ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;

    vi a(m);
    vi b(m);
    vi c(m);

    const int g = (1<<n) ;
    const int M = 1002;

    int dp[g+1];

    REP(i,m){
        cin>>a[i]>>b[i];
        REP(j,b[i]){
            int tempc;
            cin>>tempc;
            c[i] = c[i] | 1<<tempc-1; 
        }
    }

    const int INF =  INT_MAX-1;
    REP(i,g+1){
            dp[i]= INF; 
    }
    dp[0] = 0;

    REP(i,m){
        REP(j,g){
                int dpidx = j | c[i];
                if(dp[j]==INF) continue;
                if( (dp[dpidx]) > dp[j] + a[i]){
                    dp[dpidx] = dp[j]+ a[i];
                }
        }
    }

    if(dp[g-1] == INF){
        cout << "-1" << endl;
        return 0;
    }

    cout << dp[g-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Struct declaration */
struct node {
  int key;
  struct node *prev;
  struct node *next;
};
typedef struct node * NodePointer;

/* Prototype declaration */
void init(void);
void insert(int);
NodePointer search(int);
void delete(int);
void deleteFirst(void);
void deleteLast(void);
void listprint(void);


/* Global variable */
NodePointer dummy;


int main() {

  int i, n;
  char command[15];
  int x;

  dummy = (NodePointer)malloc(sizeof(struct node));
  init();

  /* Input and Process */
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s", command);
    if(strcmp(command, "insert") == 0) {
      scanf("%d", &x);
      insert(x);
    }else if(strcmp(command, "delete") == 0) {
      scanf("%d", &x);
      delete(x);
    }else if(strcmp(command, "deleteFirst") == 0) {
      deleteFirst();
    }else if(strcmp(command, "deleteLast") == 0) {
      deleteLast();
    }
  }
  
  /* Output */
  listprint();

  return 0;
  
}

/* Initialize  Sentinel */
void init(void){
  dummy->prev = dummy;
  dummy->next = dummy;
}

/* Insert to Doubly Linked List */
void insert(int keydata) {
  NodePointer x;

  x = (NodePointer)malloc(sizeof(struct node));

  x->next = dummy->next;
  dummy->next->prev = x;
  dummy->next = x;
  x->prev = dummy;

  x->key = keydata;
  
}

/* Delete arbitrary data from Doubly Linked List */
void delete(int keydata) {
  NodePointer x;

  x = search(keydata);

  if(x != dummy) {
    x->prev->next = x->next;
    x->next->prev = x->prev;

    free(x);
  }
}

/* Search */
NodePointer search(int keydata) {
  NodePointer x;
  x = dummy->next;
  while((x != dummy) && (x->key != keydata)) 
    x = x->next;
  
  return x;
}

/* Output Doubly Linked List */
void listprint(void) {
  NodePointer x;
  x = dummy->next;
  while(x != dummy) {
    printf("%d", x->key);
    if(x != dummy->prev) printf(" ");
    x = x->next;
  }printf("\n");
  
}

/* Delete first data from Doubly Linked List */
void deleteFirst(void) {
  NodePointer x;
  x = dummy->next;

  x->prev->next = x->next;
  x->next->prev = dummy;

  free(x);
}

/* Delete last data from Doubly Linked List */
void deleteLast(void) {
  NodePointer x;
  x = dummy->prev;

  x->prev->next = dummy;
  dummy->prev = x->prev;

  free(x);
}

Measured memory_bytes: 31788
import bisect
N=int(input())
S=input()

d=dict()
c=0
for i in range(10):
    d[i] = []
for i,s in enumerate(S):
    d[int(s)].append(i)
for i in range(1000):
    s=str(i).zfill(3)
    x=int(s[0])
    y=int(s[1])
    z=int(s[2])
    if len(d[x]) == 0:
        pass
    else:
        try:
            p1 = d[x][0]      
            p2 = d[y][bisect.bisect_right(d[y],p1)]
            p3 = d[z][bisect.bisect_right(d[z],p2)]

            if p3 < N:
                #print(x,y,z,p1,p2,p3)
                c += 1
            else:
                pass
        except:
            pass
print(c)

Measured memory_bytes: 40048
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CChocolateBar {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h % 3 == 0 || w % 3 == 0) {
                out.println(0);
                return;
            }
            long best = Long.MAX_VALUE;
            for (int i = 1; i < h; i++) {
                long[] act = new long[3];
                act[0] = (long) i * w;
                long rem = h - i;
                act[1] = (rem / 2) * w;
                act[2] = (rem - rem / 2) * w;
                Arrays.sort(act);
                best = Math.min(best, act[2] - act[0]);
                act = new long[3];
                act[0] = (long) i * w;
                rem = h - i;
                act[1] = rem * (w / 2);
                act[2] = rem * (w - w / 2);
                Arrays.sort(act);
                best = Math.min(best, act[2] - act[0]);
            }
            for (int i = 1; i < w; i++) {
                long[] act = new long[3];
                act[0] = (long) i * h;
                long rem = w - i;
                act[1] = (rem / 2) * h;
                act[2] = (rem - rem / 2) * h;
                Arrays.sort(act);
                best = Math.min(best, act[2] - act[0]);
                act = new long[3];
                act[0] = (long) i * h;
                rem = w - i;
                act[1] = rem * (h / 2);
                act[2] = rem * (h - h / 2);
                Arrays.sort(act);
                best = Math.min(best, act[2] - act[0]);
            }
            out.println(best);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 36308
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  bool flag = true;
  cin >> s;
  for(int i = 0; i < s.size()-1; i++) {
    if(s.at(i) == s.at(i+1)) flag = false;
  }
  if(flag) cout << "Good" << endl;
  else cout << "Bad" << endl;
  return 0;
}

Measured memory_bytes: 256