akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
struct Dice {
	int s[6];
	void roll(char c) {
		int b;
		if (c == 'E') {
			b = s[0];
			s[0] = s[3];
			s[3] = s[5];
			s[5] = s[2];
			s[2] = b;
		}
		if (c == 'W') {
			b = s[0];
			s[0] = s[2];
			s[2] = s[5];
			s[5] = s[3];
			s[3] = b;
		}
		if (c == 'N') {
			b = s[0];
			s[0] = s[1];
			s[1] = s[5];
			s[5] = s[4];
			s[4] = b;
		}
		if (c == 'S') {
			b = s[0];
			s[0] = s[4];
			s[4] = s[5];
			s[5] = s[1];
			s[1] = b;
		}
		if (c == 'R') {
			b = s[1];
			s[1] = s[2];
			s[2] = s[4];
			s[4] = s[3];
			s[3] = b;
		}
	}
	int top() {
		return s[0];
	}
	int right() {
		return s[2];
	}
	int left() {
		return s[3];
	}
	int front() {
		return s[1];
	}
};

bool same(Dice a, Dice b) {
	for (int i = 0; i < 6; i++) if (a.s[i] != b.s[i])return false;
	return true;
}
int main() {
	Dice d[100];
	int n; cin >> n;

	for (int j = 0; j < n; j++) {
		for (int i = 0; i < 6; i++) { cin >> d[j].s[i]; }
	}
	bool ff = true;
	for (int k = 0; k < n - 1; k++) {
		for (int l = k + 1; l < n; l++) {
			bool f = false;

			for (int i = 0; i < 4; i++) {
				d[l].roll('R');
				for (int j = 0; j < 4; j++) {
					d[l].roll('N');
					if (same(d[k], d[l])) f = true;
				}


			}
			d[l].roll('E');
			for (int j = 0; j < 4; j++) {
				d[l].roll('N');
				if (same(d[k], d[l])) f = true;
			}
			d[l].roll('W');
			d[l].roll('W');
			for (int j = 0; j < 4; j++) {
				d[l].roll('N');
				if (same(d[k], d[l])) f = true;
			}
			if (f)ff = false;
		}
	}
	cout << (ff ? "Yes" : "No")<<endl;
	return 0;
}



Measured memory_bytes: 3116
# coding: utf-8
# Your code here!
N=int(input())

pre=int(input())
if pre!=0:
    print(-1)
    exit()

ans=0
count=0
for _ in range(N-1):
    A=int(input())
    if A-pre>1:
        print(-1)
        exit()
    if A==pre:
        count+=1
    else:
        ans+=pre*count
        if A<pre:
            ans+=(A-1)
        ans+=1
        count=0
        #print(_,ans)
    pre=A

print(ans+pre*count)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main()
{
  double a, b, c;
  scanf("%lf %lf %lf", &a, &b, &c);
  long double aa = a, bb = b, cc = c;
  if(aa + bb + 2 * sqrtl(aa * bb) < cc) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
# TODO: itertools を使わない解き方
# https://python.civic-apps.com/itertools-combinations/

import sys
# sys.stdin = open('input.txt')

import itertools

def add_lists(a, b):
    result = [0 for i in range(len(a))]
    for i in range(len(a)):
        result[i] = a[i] + b[i]
    return result

n, m, x = map(int, input().split())
c = []
a = [[0] for i in range(n)]
for i in range(n):
    cj, *aj = input().split()
    c.append(int(cj))
    aj = list(map(int, aj))
    a[i] = aj

# solution 1 (itertools)
# INF = float('inf')
# ans = INF
#
# for flags in itertools.product([0,1], repeat=n):
#     tot = [0 for i in range(m)]
#     now = 0
#     for i in range(len(flags)):
#         if flags[i] == 1:
#             tot = add_lists(tot, a[i])
#             now += c[i]
#     flag = True
#     for i in tot:
#         if i < x:
#             flag = False
#     if flag:
#         ans = min(ans, now)
#
# if ans == INF:
#     print(-1)
# else:
#     print(ans)

# solution 2
INF = float('inf')
ans = INF

for s in range(1<<n):  # ビット演算ですべての組み合わせを試す
    tot = [0 for i in range(m)]  # 理解度
    now = 0  # 現在のコスト
    for i in range(n):
        if s >> i & 1:  # 右シフトすると対象になるかどうかのフラグが一番右の位に来る -> 1 とビットマスク
            tot = add_lists(tot, a[i])
            now += c[i]
    flag = True
    for i in tot:
        if i < x:
            flag = False
    if flag:
        ans = min(ans, now)

if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9268
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));
    ll sum = 0;
    REP(i,n){
        if (i == n - 1) sum += a[i] / 2;
        else sum += a[i];
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> h(N,0);
	for (int i=0; i<h.size(); ++i) {
		cin >> h[i];
	}
	vector<int> score(N,0);
	for (int i=1; i<N; ++i) {
		score[i] = score[i-1] + abs(h[i] - h[i-1]);
		if (i<2) continue;
		int temp = (score[i-2] + abs(h[i] - h[i-2]));
		if (score[i] > temp) {
			score[i] = temp;
		}	
	}
	/*
	for (int i=0; i<N; ++i) {
		cout << score[i] << ",";
	}
	cout << endl;
	*/
	cout << score[N-1] << endl;
	return 0;
}



Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define cst first
#define dur second
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;

ll a[N];
int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0 ; i <= n ; ++i)
        scanf("%lld", a + i);
    ll ans = 0;
    for(int i = 0 ; i < n ; ++i){
        ll x;
        scanf("%lld", &x);
        if(x >= a[i])
            ans += a[i], x -= a[i];
        else ans += x, x = 0;
        if(x >= a[i + 1])
            ans += a[i + 1], a[i + 1] = 0;
        else ans += x, a[i + 1] -= x;
    }
    printf("%lld\n", ans);
}

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

//初見×
//2次元配列でなく1次元配列+string
int main()
{
    int H, W;
    cin >> H >> W;

    vector<string> picture(H);
    for (int i = 0; i < H; i++)
    {
        cin >> picture.at(i);
    }

    cout << string(W + 2, '#') << endl;
    for (int i = 0; i < H; i++)
    {
        cout << '#' << picture.at(i) << '#' << endl;
    }
    cout << string(W + 2, '#') << endl;
}


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

int main() {
  
  int N,K;
  cin >> N >> K;
  
  int sum = 0;
  
  for(int i = 0; i<N; i++){
  	
    int x;
    cin >> x;
    
    if(x <= K-x){
    	sum += 2*x;
    }
    
    else{
    	sum += 2*(K-x);
    }
    
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

using Weight = ll;
Weight INF = 1000000000000000l;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
}

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  using P = pair<Weight,int>;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    for(auto&& i:irange(0ul,g[v].size())){
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

constexpr ll MOD = 1000000007;

ll dfs(const Graph& g, vecll& cnt, int i) {
  if (cnt[i] >= 0) return cnt[i];
  ll sum = 0;
  for(auto&& e:g[i]) {
    sum += dfs(g, cnt, e.dest);
    sum %= MOD;
  }
  return cnt[i] = sum;
}

int main()
{
  int n,m;
  cin>>n>>m;
  int s,t;
  cin>>s>>t;
  --s;--t;
  Graph g(n);
  Edges ve;
  for(auto&& i:irange(0,m)) {
    int u,v;
    cin>>u>>v;
    ll d;
    cin>>d;
    --u;--v;
    add_edge(g, u, v, d);
    add_edge(g, v, u, d);
    ve.push_back(Edge{u, v, d});
  }
  Array ds;
  dijkstra(g, ds, s);
  Array dt;
  dijkstra(g, dt, t);
  ll st = ds[t];
  Graph g2(n);
  Graph g3(n);
  Edges vme;
  for(auto&& e:ve) {
    int src = e.src, dest = e.dest;
    if (ds[src] > ds[dest]) swap(src, dest);
    if (ds[src] + e.weight != ds[dest]) continue;
    if (dt[dest] + e.weight != dt[src]) continue;
    if (ds[src] + dt[src] != st) continue;
    if (ds[dest] + dt[dest] != st) continue;
    add_edge(g2, src, dest, e.weight);
    add_edge(g3, dest, src, e.weight);
    vme.push_back(Edge{src, dest, e.weight});
  }
  vecll cntt(n, -1);
  cntt[t] = 1;
  dfs(g2, cntt, s);
  vecll cnts(n, -1);
  cnts[s] = 1;
  dfs(g3, cnts, t);
  ll total = cntt[s] * cnts[t] % MOD;
  for (auto&& i:irange(0,n)) {
    if (ds[i] == dt[i] && ds[i] + dt[i] == st) {
      ll tmp = cntt[i] * cnts[i] % MOD;
      tmp *= tmp;
      tmp %= MOD;
      total += MOD - tmp;
      total %= MOD;
    }
  }
  for (auto&& e:vme) {
    if (2 * ds[e.src] >= st || 2 * ds[e.dest] <= st) continue;
    ll tmp = cnts[e.src] * cntt[e.dest] % MOD;
    tmp *= tmp;
    tmp %= MOD;
    total += MOD - tmp;
    total %= MOD;
  }
  cout<<total<<endl;
  return 0;
}


Measured memory_bytes: 38764
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[100001];
	int flg1[100001];
	int x;
	int i;
	int flg;
	int cnt;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>box[i];
		flg1[i]=0;
	}
	cnt=1;
	x=box[1];
	flg1[1]=1;
	flg=0;
	while(1){
		if(flg1[x]==1){
			flg=1;
			break;
		}
		if(x==2)	break;
		flg1[x]=1;
		x=box[x];
		cnt++;
	}
	if(flg==1)	cout<<-1<<endl;
	else		cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll nmax=1e5+2;
#define int ll
int n, x;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>x;
    for(int i=x-n+1; i<=x+n-1; i++) cout<<i<<" ";
}


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

int findSet(int x, vector<int> &p){
	if(x != p[x])
		p[x] = findSet(p[x], p);
	return p[x];
}

bool isSameSet(int x, int y, vector<int> &p){
	return findSet(x, p) == findSet(y, p);
}

void link(int x, int y, vector<int> &p, vector<int> &rank){
	if(rank[x] > rank[y]){
		p[y] = x;
	}else{
		p[x] = y;
		if(rank[x] == rank[y])
			rank[y]++;
	}
}

void unite(int x, int y, vector<int> &p, vector<int> &rank){
	link(findSet(x, p), findSet(y, p), p, rank);
}

int main(){
	int n, q, com, x, y;
	vector<int> p, rank;

	cin>>n>>q;
	
	for(int i=0;i<n;i++){
		p.push_back(i);
		rank.push_back(0);
	}

	for(int i=0;i<q;i++){
		cin>>com>>x>>y;

		if(com == 0)
			unite(x, y, p, rank);
		else if(com == 1)
			cout<<isSameSet(x, y, p)<<endl;
	}

	return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;


vector < vector <int> > Graph;
vector <int> beforeNode;
vector <int> depth;
queue <int> topSort;

int bfsTopSort(int n) {

    queue <int> inWaiting;

    for(int i = 0; i < n; ++i)
        if(beforeNode[i] == 0)
            inWaiting.push(i); // Dodam one koji nemaju nikog prije

    while(!inWaiting.empty()) {
        int curr = inWaiting.front();
        inWaiting.pop();

        topSort.push(curr); // Ovo ovdje nije bitno

        for(int child : Graph[curr]) {
            beforeNode[child] -= 1; // Maknek trenutnog sa sve njegove dijece
            if(beforeNode[child] == 0) { // Ako ne treba nikog vise
                depth[child] = depth[curr] + 1;
                inWaiting.push(child);
            }
        }
    }

    int mx = 0;
    for(int i = 0; i < n; ++i)
        mx = max(mx, depth[i]); // Trazim node s najvecom dubinom
    
    return mx;
}

int main() {
    int n, m; cin >> n >> m;
    Graph.resize(n);
    beforeNode.resize(n, 0);
    depth.resize(n, 0);

    int u, v; // Put u -> v
    while(m--) {
        cin >> u >> v;
        u -= 1; v -= 1;
        Graph[u].push_back(v);
        beforeNode[v] += 1; // Prije nego dodem do v, moram obraditi u
    }

    int mx = bfsTopSort(n);

    cout << mx << '\n';

    return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;

const int mod = 1e9+7;
const int N = 6e5+2;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
string s[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main() {
    //de(pow(-1,1.6));
    int be = 0;
    string t;
    cin>>t;
    //de(t);
    rep(i, 0, 7) {
        //dd(i);de(s[i]);
        if(t==s[i]) { be = i; break; }
    }
    //de(be);
    int ret = 0;
    if(s[be]=="SUN") { cout<<7<<endl; return 0; }
    while(s[be] != "SUN") {
        //dd(be);de(s[be]);
        be++, be %=7, ret++;
    }
    cout<<ret<<endl;
    return 0;
}


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

void main_()
{
    vector<vector<int>> css(3);
    for (auto&& cs : css) {
        copy_n(istream_iterator<int>(cin), 3, back_inserter(cs));
    }

    bool ok = true;
    for (int i = 0; i < 2; ++i) {
        if (!(css[0][i] - css[0][i + 1] == css[1][i] - css[1][i + 1]
                && css[0][i] - css[0][i + 1] == css[2][i] - css[2][i + 1])) {
            ok = false;
        }
    }
    for (int i = 0; i < 2; ++i) {
        if (!(css[i][0] - css[i + 1][0] == css[i][0] - css[i + 1][0]
                && css[i][0] - css[i + 1][0] == css[i][2] - css[i + 1][2])) {
            ok = false;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int 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 MAX 1000000001;
using namespace std;
typedef long long ll;

ll n,m;

int main(){
 std::cin >> n >> m;
 if(n==1&&m==1){
   std::cout << "1" << '\n';
 }else if(n==1){
   std::cout << m-2 << '\n';
 }else if (m==1){
   std::cout << n-2 << '\n';
 }else{

   ll corner = 4;
   ll edge = 2*(m+n) -2*corner;
   ll normal = n*m - corner- edge;
   std::cout <<(m-2)*(n-2) << '\n';
 }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;

using namespace std;

int main(){
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        ll x,n; cin >> x >> n;
        map<ll,ll> mp;
        vector<ll> p(n);
        rep(i,n){
                cin >> p[i];
                mp[p[i]]++;
        }
        sort(all(p));
        ll d = 0;
        while(1){
                if(mp.find(x-d) == mp.end()){ cout << x-d << endl; return 0;}
                else if(mp.find(x+d) == mp.end()){ cout << x+d << endl; return 0;}
                else d++;
        }

        return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  ll H;
  cin >>N>>H;
  
  
  vl a(N);
  vl b(N);
  rep(i,N) {
cin >>a.at(i)>>b.at(i);
  }

  sort(all(a));
  ll x=a.at(N-1);
  
  rep(i,N) {
if(b.at(i)<x) {
  b.at(i)=0;
}
  }
  
  
  
  sort(b.rbegin(),b.rend());
  
  ll c=0;
  rep(i,N) {
    if((H>0) &&(b.at(i)>0)){
      H=H-b.at(i);
      c++;
    }
    else {
      break;
    }
  }
  
  
  if(H<=0) {
    cout<<c<<endl;
    return 0;
  }
  else {
    cout<<c+(H+x-1)/x<<endl;
  }
  
}
    
  
    
 

Measured memory_bytes: 1792
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int x, a, b;

int main() {
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
}

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

int a,b,c,x,y,res;
int main()
{
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
	res=x*a+y*b;
//	cout<<res<<endl;
	int ji;
	ji=c*2*x;
	if(x<y)
	ji+=(y-x)*b;
	res=min(res,ji);
//	cout<<res<<endl;
	ji=0;
	ji=c*2*y;
	if(y<x)
	ji+=(x-y)*a;
	res=min(res,ji);
//	cout<<res<<endl;
	ji=max(x,y);
	res=min(res,ji*c*2);
//	cout<<res<<endl;
	printf("%d\n",res);
	return 0;
}

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


int main (){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  rep(i, k){
    if(a >= c || b >= c) c *= 2;
    else if(a >= b) b *= 2;
    else break;
  }
  
  if(a < b && b < c) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
    using namespace std;
     
    int main(){
      string n;cin>>n;
      int a=0,b=0;
      for(int i=0; i<3; i++){
        if(n[i]=='A')a++;
        else b++;
      }
      if(b==2 && a==1 || b==1 && a==2)cout<<"Yes"<<'\n';
      else cout<<"No"<<'\n';
    }

Measured memory_bytes: 256
from fractions import gcd

N, X = map(int, input().split())
xs = [int(x) for x in input().split()]

if N == 1:
    print(abs(xs[0] - X))
    exit()

dists = [abs(x - X) for x in xs]
D = gcd(dists[0], dists[1])
for d in dists[2:]:
    D = gcd(D, d)

print(D)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll ans = 0;
    vector<int> cnt(s.size() + 1);
    rep (i, s.size()) {
        if (s[i] == 'B') {
            cnt[i] += 1;
        }
    }
    FOR (i, 1, cnt.size()) {
        cnt[i] = cnt[i] + cnt[i - 1];
    }
    rep (i, s.size()) {
        if (s[i] == 'W') ans += cnt[i];
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 1428
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;

int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    /*
    ios::sync_with_stdio(0);
    */
    int n,i,a,b,mi=(int)1e9;
    ll s=0;
    cin>>n;
    fo(i,n)
    {
        scanf("%d%d",&a,&b);
        s+=a;
        if (b<a)
        {
            mi=min(mi,b);
        }
    }
    if (mi==(int)1e9)
    {
        cout<<0;
        re 0;
    }
    cout<<s-mi;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char in[120];
pair<pair<string,int>,int> p[110];

int main(){
    int a;
    scanf("%d", &a);
    for (int i = 0; i < a; i++)
    {
        int t;
        scanf("%s%d", in, &t);
        string tmp = in;
        p[i] = make_pair(make_pair(in,-t),i);
    }
    std::sort(p,p+a);
    for(int i = 0; i < a; i++)
    cout << p[i].second + 1 << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vec A(n);
    rep(i,n) cin>>A[i];
    sort(all(A));
    ll ans=0;
    rep(i,k) ans+=A[i];
    cout<<ans;
}

Measured memory_bytes: 3640
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    int N,i;
    cin >> N >> i;
    
    cout << N-i+1 << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,a,b,sum;
	scanf("%d",&n);
	if (n == 1){
		printf("Hello World\n");
	}
	else if (n == 2){
		scanf("%d%d",&a,&b);
		sum = a + b;
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 128
def main():

    inf = 1<<29
    n,w = map(int,input().split())
    A = []
    for _ in range(n):
        a,b = map(int,input().split())
        A.append([a,b])
    dp = [0]*(w+1)
    for i in range(1,w+1):
        for j in range(n):
            if i-A[j][1]<0:continue
            dp[i] = max(dp[i],dp[i-A[j][1]]+A[j][0])
    res = 0
    for i in range(w+1):res = max(res,dp[i])
    print(res)


if __name__ == '__main__':
    main()




Measured memory_bytes: 5916
#include<bits/stdc++.h>
using namespace std;
typedef vector<double> vec;
typedef vector<vec> mat;
double eps=1e-8;

void gauss_jordan(mat& A){
  int n=A.size();
  int m=A[0].size();
  
  int rank=0;
  
  vector<bool> flg(n,false);
  
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=0;j<n;j++){
      if(flg[j])continue;
      if(abs(A[j][i]) > abs(A[pivot][i]))pivot=j;
    }


    
    swap(A[pivot],A[i]);
    
    if(abs(A[i][i]) < eps)continue;
    
    rank++;
    flg[i]=true;
    
    double val=A[i][i];
    for(int j=0;j<m;j++)A[i][j]/=val;
    
    for(int j=0;j<n;j++){
      if(i==j)continue;
      double va=A[j][i];

      for(int k=0;k<m;k++){
        A[j][k]-=A[i][k]*va;
      }
    }
  }
  /*
  cout<<"rank = "<<rank<<endl;
  cout<<" n = "<<n<<endl;
  cout<<" m = "<<m<<endl;

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      printf("%3d",(int)A[i][j]);
    }
    cout<<endl;
  }

  */
  cout<<m-rank<<endl;
}

int N,M;
int G[500][500];

int main(){
  memset(G,-1,sizeof(G));
  mat A;
  cin>>N>>M;
  if(M==0){
    cout<<0<<endl;
    return 0;
  }
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a][b]=i;
  }

  for(int i=0;i<N;i++){
    bool flg=false;
    vec B(M,0);
    for(int j=0;j<N;j++){
      if(G[i][j]==-1)continue;
      int id=G[i][j];
      B[ id ]=1;
      flg=true;
    }
    for(int j=0;j<N;j++){
      if(G[j][i]==-1)continue;
      int id=G[j][i];
      B[ id ]=-1;
      flg=true;
    }
    if(flg)  A.push_back(B);
  }

  while(A.size()<A[0].size()){
    vec B(M,0);
    A.push_back(B);
  }

  gauss_jordan(A);
  return 0;
}

Measured memory_bytes: 100000
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(*args):
    print(*args,file=sys.stderr)

def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
     
#input

                
def resolve():
    N=int(input())
    b=list(pin())
    ans=[]
    t=0
    for elem in range(N):
        for i in range(N-t,0,-1):
            if b[i-1]==i:
                ans.append(i)
                b.pop(i-1)
                t+=1
                break
    if len(ans)!=N:print("-1")
    else:
        for wa in reversed(ans):
            print(wa)
        #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()

"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
1 2 1"""
        output = """1
1
2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2
2 2"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """9
1 1 1 2 2 1 2 3 2"""
        output = """1
2
2
3
1
2
2
1
1"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Measured memory_bytes: 83436
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

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

    a += b;

    int n = stoi(a);


    int i = 1;
    while(i*i <= n){
	if(i*i == n){
	    Yes;
	    ret 0;
	}
	i++;
    }
    No;
    
    return 0;
}


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


int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  for (;;){
    C -= B;
    if (C <= 0){
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if (A <= 0){
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3624
MOD = 10**9 + 7
k = gets.to_i
s = gets.chomp
size = s.size

@fac = [1, 1]
@finv = [1, 1]
@inv = [1, 1]

2.upto(2 * 10**6) do |i|
  @fac[i] = @fac[i - 1] * i % MOD
  @inv[i] = MOD - @inv[MOD % i] * (MOD / i) % MOD
  @finv[i] = @finv[i - 1] * @inv[i] % MOD
end

def com(n, k)
  return 0 if n < k || n < 0 || k < 0
  @fac[n] * (@finv[k] * @finv[n - k] % MOD) % MOD
end

pow25 = Array.new(k + 1)
pow26 = Array.new(k + 1)
pow25[0] = pow26[0] = 1

k.times do |i|
  pow25[i + 1] = pow25[i] * 25 % MOD
  pow26[i + 1] = pow26[i] * 26 % MOD
end

ret = 0
0.upto(k) do |i|
  ret += com(i + size - 1, size - 1) * pow25[i] * pow26[k - i] % MOD
end

puts ret % MOD

Measured memory_bytes: 79128
#include<stdio.h>


int main()
{
    int str[20][20]={0},STR[20]={0},N=0,M=0,C=0,i=0,j=0,count=0,ans=0;
    scanf("%d%d%d",&N,&M,&C);
    for(i=0;i<M;i++)
    {
        scanf("%d",&STR[i]);
    }
    for(i=0;i<N;i++)
    {
        for(j=0;j<M;j++)
        {
            scanf("%d",&str[i][j]);
        }
    }
    
    
    i=0;
    j=0;
    

    while(i<N)
    {
        for(j=0;j<M;j++)
        {
            ans+=str[i][j]*STR[j];
        }
        if((ans+C)>0)
        {
            count+=1;

        }
        i++;
        ans=0;
    }
    printf("%d",count);

    
    return 0;
}

Measured memory_bytes: 128
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      if(N % 2 == 1){
        N *= 2;
      }
      myout(N);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33052
#include<iostream>
using namespace std;
int a, b, c, d, e[500000][5], n, cnt;
int main() {
	while (true) {
		cin >> n; cnt = 0; if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> e[i][0] >> e[i][1] >> e[i][2] >> e[i][3];
			e[i][4] = e[i][1] * 4 + e[i][2] * 9 + e[i][3] * 4;
		}
		cin >> a >> b >> c >> d;
		for (int i = 0; i < n; i++){
			if (a >= e[i][1] && b >= e[i][2] && c >= e[i][3] && d >= e[i][4]) {
				cout << e[i][0] << endl; cnt++;
			}
		}
		if (cnt == 0) { cout << "NA" << endl; }
	}
}

Measured memory_bytes: 1184
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n, m, tot, ans = 0;
vector<int> adj[19];

void dfs(int u, int p = 0) {
	p |= (1 << u);
	if (p == tot) {
		ans++;
		return;
	}
	for (int i=0; i<sz(adj[u]); i++) {
		int v = adj[u][i];
		if (p & (1 << v)) continue;
		dfs(v, p);
	}
}

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	cin >> n >> m;
	tot = (1 << n) - 1;
	for (int i=0; i<m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(0);
	
	cout << ans;
}


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

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

    vector<int> broken(N + 1);
    rep(i, M)
    {
        int a;
        cin >> a;
        broken[a] = true;
    }

    vector<int> dp(N + 1);
    const int mod = 1e9 + 7;
    dp[0] = 1;
    for (int first = 0; first < N; first++)
    {
        for (int second = first + 1; second <= min(N, first + 2); second++)
        {
            if (broken[second])
            {
                dp[second] = 0;
                continue;
            }
            dp[second] += dp[first];
            dp[second] %= mod;
        }
    }
    cout << dp[N] << endl;
    return 0;
}

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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define test 1
#define TEST if(test)

using namespace std;

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

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N, K;
vector<int> v;
vector<int> sum;
map<int, int> mp;
ll ans;

int main(){
	scanf("%d%d", &N, &K);
	v.pb(0);
	mp[0] = 1;
	for(int i=1; i<=N; i++){
		if(i-K>=0){
			mp[v[i-K]]--;
		}
		int a; scanf("%d", &a);
		v.pb((v.back() + a - 1) % K);
		ans += (ll)mp[v[i]];
		mp[v[i]]++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 10356
#include<stdio.h>

int main(void){
	int a[10];
	int i,j,k,temp;
	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	for(j=0;j<9;j++){
		for(k=9;k>j;k--){
			if(a[k-1]<a[k]){
				temp = a[k];
				a[k] = a[k-1];
				a[k-1] = temp;
			}
		}
	}
	printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,N;
    cin >> a >> b;
    if(b == 100){
        N = 1000*a + b;
    }
    else if(b == 1 || b == 2 || b == 3 || b == 4 || b == 5 || b == 6 || b == 7 || b == 8 || b == 9 ){
        N = 10*a + b;
    }
    else{
        N = 100*a + b;
    }
    
    for(int i = 4;;i++){
    if(i*i == N){
      cout << "Yes" << endl;
      break;
    }
    else if(i*i > N){
      cout << "No" << endl;
      break;
    }
    else
      continue;
  }
}


Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def run():
    S = input()

    l = 0
    r = len(S) - 1

    ans = 0
    while l < r:
        if S[l] == S[r]:
            l+=1
            r-=1
        elif S[l] == 'x':
            l += 1
            ans += 1
        elif S[r] == 'x':
            r -= 1
            ans += 1
        else:
            print(-1)
            return
    print(ans)

if __name__ == "__main__":
    run()

Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	
	int ans = k;
	
	for (int i = 1; i < n; i++) {
		ans *= (k - 1);
	}
	
	cout << ans << endl;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

string A, B;

void solve()
{
    cin >> A >> B;
    if(A.length() > B.length())
    {
        cout << "GREATER" << endl;
        return;
    }
    else if(A.length() < B.length())
    {
        cout << "LESS" << endl;
        return;
    }

    REP(i, A.length())
    {
        int a, b;
        a = (int)A[i];
        b = (int)B[i];
        if(a > b)
        {
            cout << "GREATER" << endl;
            return;
        }
        else if(a < b)
        {
            cout << "LESS" << endl; 
            return;
        }
    }
    
    cout << "EQUAL" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

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

int main()
{
    int x,y;
    cin>>x>>y;
    string s;
    cin>>s;
    if(s[x] != '-'){
        cout<<"No"<<endl;
        return 0 ;
    }

    string s2 = s.substr(0,x);
    //cerr<<s2<<endl;
    string s3 = s.substr(x+1,y);
    //cout<<s3<<endl;
    for(int i=0;i<s2.size();i++){
        if(s2[i]>='0'&& s2[i]<='9')continue;
        else {
            cout<<"No"<<endl;
            return 0 ;
        }
    }
    for(int i=0;i<s3.size();i++){
        if(s3[i]>='0'&& s3[i]<='9')continue;
        else {
            cout<<"No"<<endl;
            return 0 ;
        }
    }
    cout<<"Yes"<<endl;
    return 0 ;
}


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

int main() {
    int N; cin >> N;
    map<int,int> M;
    rep(i,N) {
        int j; cin >> j;
        M[j]++;
    }
    int k = M.size();
    if (k % 2 == 1)
        cout << k << endl;
    else
        cout << k - 1 << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)

int main(){

    fast;
    ll n,i,j;
    cin>>n;
    ll mx=n+1;
    ll p[mx]={0};
    p[0] = p[1] = 1; 
    for (ll i = 2; i < mx; i++) { 
        if (p[i] == 0) { 
            for (ll j = i * 2; j < mx; j += i) { 
                if (p[j] == 0) { 
                    p[j] = i; 
                } 
            } 
            p[i] = i; 
        } 
    } 
    
    if(n==1)
    {
    	cout<<1;
    	return 0;
	}
	ll ans=1;
    for(i=2;i<=n;i++)
    {
    	ll x=i;
    	ll z=x;
    	while(x!=1)
    	{
    		ll y=p[x];
    		ll cnt=0;
    		while(x%y==0)
    		{
    			x=x/y;
    			cnt++;
			}
			z=z*(cnt+1);
			
		}
		ans+=z;
	}
	cout<<ans;
    
	
    
}

Measured memory_bytes: 81712
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x) do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<#x<<': "';\
for(auto&e: x)cerr<<e<<" ";cerr<<"\n";}while(0)

using namespace std;
using ll=long long;


bool visited[100*1000+10];
vector<int> A[100*1000+10];

void dfs(int u) {
  visited[u] =true;
  for(auto v: A[u]) {
    if(!visited[v]) dfs(v);
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  int N, M; cin >> N >> M;
  rep(i,0,M-1) {
    int xi,yi,zi;
    cin >> xi >> yi >> zi;
    A[xi].push_back(yi);
    A[yi].push_back(xi);
  }
  int ans = 0;
  rep(i,1,N) {
    if (!visited[i]) {
      ans++;
      dfs(i);
    }
  }

  cout << ans << endl;

}



Measured memory_bytes: 8960