akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n,m; cin >> n >> m;
    vector<int> s[m];
    int ans = 0;
    int p[m];
    rep(i,m){
        int k; cin >> k;
        rep(j,k){
            int x; cin >> x;
            x--;
            s[i].push_back(x);
        }
    }
    rep(i,m) cin >> p[i];
    for(int bit = 0; bit < (1 << n); bit++){
        bool ok = true;
        for(int i = 0; i < m; i++){
            int cnt = 0;
            for(int j = 0; j < s[i].size(); j++){
                if(bit & (1 << s[i][j])) cnt++;
            }
            if(p[i] != (cnt % 2)) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

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

int main()
{
    char b;
    cin >> b;

    switch (b)
    {
        case 'A':
            cout << 'T' << endl;
            break;
        case 'C':
            cout << 'G' << endl;
            break;
        case 'G':
            cout << 'C' << endl;
            break;
        case 'T':
            cout << 'A' << endl;
            break;
        default:
            break;
    }
    return 0;
}

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

void maxHeapify(std::vector<int> &v, int i, int node_num) {
	int left = i * 2;
	int right = i * 2 + 1;
	int largest = i;
	// ????????????????????????????????§???????????§????????????????????¶
	if (left <= node_num && v[left] > v[i])
		largest = left;
	if (right <= node_num && v[right] > v[largest])
		largest = right;

	if (largest != i) {// i ???????????????????????§????????´???
		std::swap(v[i], v[largest]);
		maxHeapify(v, largest, node_num); // ?????°??????????????????
	}
}

void buildMaxHeap(std::vector<int> &v, int node_num) {
	for (int i = node_num / 2; i >= 1; i--) {
		maxHeapify(v, i, node_num);
	}
}

int main() {
	int node_num;

	std::cin >> node_num;
	std::vector<int> v(node_num + 1);

	for (int i = 1; i <= node_num; i++) {
		int num;
		std::cin >> num;
		v[i] = num;
	}

	buildMaxHeap(v, node_num);

	for (int i = 1;	i <= node_num; i++) {
		std::cout << " " << v[i];
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>

int kakuketa(int i){
    int sum = 0;
    while (i){
        sum += i % 10;
        i /= 10;
    }
    return sum;
}

int main(void){
    int N, A, B;
    scanf("%i %i %i", &N, &A, &B);
    int counter = 0;
    for (int i = 1; i <= N; i++){
        int wa = kakuketa(i);
        if (A <= wa && wa <= B){
            counter += i;
        }
    }
    printf("%i\n", counter);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    int n,x,m=1000;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int j=0;j<n;j++)
    {
        int y=0;
        for(int i=0;i<n;i++)
        {
            if(i<=j)
            y+=a[i];
            else
            y-=a[i];
        }
        //if(y>=0)
        m=min(m,abs(y));
    }
    cout<<m<<endl;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号
  vector<int> siz;  //葉の値を持つ

  UnionFind(int n)
      : par(n),
        siz(n, 1)  //初期化
  {
    for (int i = 0; i < n; i++) par[i] = i;
  }

  int root(int x)  //データxが属する木の根を再帰で得る
  {
    if (par[x] == x)
      return x;
    else
      return par[x] = root(par[x]);
  }

  int size(int x) { return siz[root(x)]; }

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

  bool unite(int x, int y)  // xとyの木を併合
  {
    if ((x = root(x)) == (y = root(y)))  // xとyの根が同じ時はそのまま
      return false;
    if (siz[y] > siz[x]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;  // yの根にxをつける
    return true;
  }
};

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  UnionFind uf(n + 1);

  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
  }
  int ans = 0;
  rep(i, 1, n) {
    if (!uf.same(0, i)) {
      uf.unite(0, i);
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int main() {
	
	int n,i,k;
	cin>>n>>k;
	int arr[n],dp[n];
	for(i=0;i<n;i++)
	cin>>arr[i];
	dp[0]=0;
	
	for(i=1;i<n;i++)
	{
	    dp[i]=2147483600;
	    for(int j=max(0,i-k);j<i;j++)
	    {
	        dp[i]=min(dp[i], dp[j] + abs(arr[i]-arr[j]));
	    }
	}
	cout<<dp[n-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 x, y, z;
  cin >> x >> y >> z;
  std::swap(x, y);
  std::swap(x, z);
  cout << x << " " << y << " " << z << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pri 1000000007

using namespace std;
void run(){
ll n;
cin>>n;
ll e=sqrt(n);
ll pr[e+1]={0};

for(ll i=2;i<=e;i++){
	if(pr[i]==0){
	for(ll j=2*i;j<=e;j+=i){
		pr[j]=1;
	}}
}
ll na=n;
ll c=1;
ll ans=1;
for(ll i=2;i<=e+1;i++){
	
	if(pr[i]==0){
		//cout<<i<<endl;
	ll se=1;
    ll ca=1;
	ll ja=i;
	while(na%i==0){
		na=na/i;
		se+=ja;
		ja*=i;
		ca++;
	}
	c=c*ca;
	ans=ans*(se);
	}

}
if(na!=1){
	c=c*2;
	ans=ans*(na+1);
}
for(ll i=1;i<=n;i++){
	if(n%i==0&&n/i>=(i-1))ans-=(i-1);
	if(n/i<(i-1))break;
}
//cout<<ans;
cout<<ans-c<<endl;

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
//	cin>>t;
	for(ll i=0;i<t;i++)run();
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 8064
// 参考:https://ei1333.github.io/luzhiled/snippets/graph/strongly-connected-components.html

#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

struct edge {
  int src, to;
  int cost;

  edge(int to, int cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, int cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

struct StronglyConnectedComponents {
  const vector<vector<int>> &g;
  vector<vector<int>> gg, rg;
  vector<int> comp, order, used;

  StronglyConnectedComponents(vector<vector<int> > &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return comp[k];
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector<vector<int>> &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
  }
};

int main() {
  int v,e,q;
  scanf("%d %d", &v, &e);
  vector<vector<int>> g(v), buff;
  
  for(int i = 0;i < e;++i) {
    int u,v;
    scanf("%d %d", &u, &v);
    g[u].emplace_back(v);
  }
  
  StronglyConnectedComponents scc(g);
  scc.build(buff);
  scanf("%d", &q);
  while(q--) {
    int u, v;
    scanf("%d %d", &u, &v);
    puts(scc[u] == scc[v] ? "1" : "0");
  }
}


Measured memory_bytes: 4544
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//トライ木って何よ
int T[100001][2];

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


	int N;
	ll L;
	scanf("%d", &N);
	scanf("%lld", &L);
	getchar_unlocked();
	int k = 0;
	ll kotae = 0;
	rep(i, N) {
		int mae = 0;
		ll d = L;
		char c;
		while ((c = getchar_unlocked()) >= '0') {
			int C = c - '0';
			if (!T[mae][C]) {
				T[mae][C] = ++k;
				kotae ^= d & -d;
			}
			mae = T[mae][C];
			d--;
		}
	}
	if (kotae) printf("Alice\n");
	else printf("Bob\n");

	Would you please return 0;
}

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

int main(){
  string s, first_part, last_part;
  cin >> s;
  
  int n = s.size();
   
  first_part = s.substr(0, (n - 1) / 2);
  last_part = s.substr((n + 3) / 2 - 1);
  
  if(first_part == last_part){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  //cout << first_part << endl;
  //cout << last_part << endl;
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;

public class Main {
	static HashMap<String, Integer> map = new HashMap<String, Integer>();

	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int n = Integer.parseInt(br.readLine());
		ArrayList<Integer> s = new ArrayList<>();
		int mod10 = 0;
		for(int i = 0; i < n; i++){
			int num = Integer.parseInt(br.readLine());
			if(num%10==0){
				mod10+=num;
			}else{
				s.add(num);
			}

		}
		Collections.sort(s);
		solve(s,s.size(),mod10);
	}

	static void solve(ArrayList<Integer> s, int n,int mod10){
		Queue<ArrayList<Integer>> q = new ArrayDeque<>();
		q.add(s);
		while(q.peek()!=null){
			ArrayList<Integer> num = q.poll();
			int sum = 0;
			for(int i = 0; i < n; i++){
				sum += num.get(i);
			}
			if(sum%10!=0){
				System.out.println(sum+mod10);
				return;
			}
			for(int i = 0; i < n; i++){
				if(num.get(i) != 0){
					ArrayList<Integer> next = new ArrayList<>();
					for(int j = 0; j < n; j++){
						next.add(num.get(j));
					}
					next.set(i,0);
					q.add(next);
				}
			}
		}
		System.out.println(0);
	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pie 3.141592653589793
#define fi first
#define se second
using namespace std ;
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

void solve()
{
	lli n;
	cin>>n;
	pll p[n];
	bool ani=false;
	for(lli i=0;i<n;i++)cin>>p[i].fi>>p[i].se;
	for(lli i=0;i<n-2;i++){
		if(p[i].fi==p[i].se && p[i+1].fi==p[i+1].se && p[i+2].fi==p[i+2].se)
		ani=true;
	}
	if(ani)cout<<"Yes";
	else cout<<"No";
}
int main()
{
/////////////////////////////////////
    fastio;
/////////////////////////////////////  
    lli t,m;
    //cin>>t;
    t=1;
    while(t--)
    {
    	solve();  
    	m++;  
    	cout<<endl;
    }
}

Measured memory_bytes: 3648
fun main(args: Array<String>) {
    val (n, p) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!.reversed()

    val ans = if (10 % p == 0) {
        (0 until n)
                .filter { (s[it] - '0') % p == 0 }
                .map { 0L + n - it }
                .sum()
    } else {
        val a = IntArray(n)
        var b = 1
        for (i in 0 until n) {
            a[i] = (s[i] - '0') * b % p
            b = b * 10 % p
        }

        val cs = IntArray(n + 1)
        for (i in 0 until n) {
            cs[i + 1] = (cs[i] + a[i]) % p
        }

        val cnt = IntArray(p)
        (0..n).map { 0L + cnt[cs[it]]++ }.sum()
    }

    println(ans)
}


Measured memory_bytes: 50316
#include <bits/stdc++.h>
#define ll long long
//vector<int> g1;
//g1.push_back(i);

using namespace std;

int main()
{
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	pair<int, int> apple[a+b+c+5];
	for(int i=0;i<a;i++)
	{
		cin >> apple[i].first;
		apple[i].second = 0;
	}
	for(int i=0;i<b;i++)
	{
		cin >> apple[a+i].first;
		apple[a+i].second = 1;
	}
	for(int i=0;i<c;i++)
	{
		cin >> apple[a+b+i].first;
		apple[a+b+i].second = 2;
	}
	sort (apple,apple+a+b+c);
	int z = 0;
	int count = a+b+c-1;
	ll otpt = 0;
	while(x+y-z>0)
	{
		if(apple[count].second == 0 && x>0)
		{
			x--;
			otpt += apple[count].first;
		}
		if(apple[count].second == 1 && y>0)
		{
			y--;
			otpt += apple[count].first;
		}
		if(apple[count].second == 2)
		{
			z++;
			otpt += apple[count].first;
		}
		count--;
	}
	cout << otpt << endl;
}



Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <time.h>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int, int> Pii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const LL mod = 1000000007;
const int N = 150 + 5;
const double Pi = acos(-1.0);
const int maxn = 2e5 + 5;

int main() {
#ifdef local
    freopen("in", "r", stdin);
    //  freopen("w","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    int ev = 0,od = 0;
    cin>>n;
    int x;
    for(int i = 0; i < n; i++){
        cin>>x;
        if(x&1){
            od++;
        }
        else ev++;
    }
    if(od%2==0){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}


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

int main(){
  priority_queue<int> a;
  int n, m;
  cin >> n >> m;
  int tmp;
  for(int i=0;i<n;i++){
    cin >> tmp;
    a.push(tmp);
  }
  
  for(int i=0;i<m;i++){
    tmp=a.top()/2;
    a.pop();
    a.push(tmp);
  }
  
  long long int sum = 0;
  for(int i=0;i<n;i++){
    //cout << v[i] << ",";
    sum+=a.top();
    a.pop();
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 892
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.lang.Math;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r=sc.nextDouble();
        System.out.printf("%.5f %.5f\n",r*r*Math.PI,2*r*Math.PI);
    }
}


Measured memory_bytes: 28300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    vector<ll> x(5,0);
    for(int i = 0; i < 5; i++) cin >> x[i];

    for(int i = 0; i < 5; i++) if(x[i] == 0) cout << i + 1 << endl;
    
}

Measured memory_bytes: 3624
N,M=map(int,input().split())
edges=[list(map(int,input().split())) for i in range(M)]
ans=0
for x in edges:
    l=list(range(N))
    for y in edges:
        if y!=x:l=[l[y[0]-1] if l[i]==l[y[1]-1] else l[i] for i in range(N)]
    if len(set(l))!=1:ans+=1
print(ans)

Measured memory_bytes: 40176
#include <cstdio>
#include <vector>

const int MAXN=2e5+10;

using namespace std;


int N,K,C;

char buf[MAXN];

int cnt[MAXN];

int main(){

    scanf("%d%d%d\n",&N,&K,&C);
    scanf("%s",buf+1);

    cnt[N]=(buf[N]=='o');
    for(int i=N-1;i>=0;i--){
        int pre=i+C+1;
        if (pre>N){
            if (buf[i]=='o') cnt[i]=1; else cnt[i]=cnt[i+1];
        }else{
            if (buf[i]=='o') cnt[i]=1+cnt[pre]; else cnt[i]=cnt[i+1];
        }
    }
    
    if (cnt[1]==K){
        for(int i=1;i<=N;i+=(C+1)){
            while(buf[i]!='o') i++;
            int j=i+1;
            bool antoher_exists=false;
            while(cnt[j]==cnt[i]&&j<=N){
                if (buf[j]=='o'){
                    antoher_exists=true;
                    break;
                }
                j++;
            }
            if (!antoher_exists) printf("%d\n",i);
        }
    }

    return 0;
}

Measured memory_bytes: 2432
#include<stdio.h>
#include<string.h>
int a[5000];
int main()
{
	int n;
	while(scanf("%d",&n)==1)
	{
		long i,j;
		int max=1;
		memset(a,0,sizeof(a));
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		long t=i;
		int sum=0;
			for(j=0;j<t;j++)
			 {
 				sum+=a[j]-1;
 			}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 128
#include<iostream>
#include <bits/stdc++.h> 
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;

const int Max = 1e9 + 5;


int main(){
  int w,n;
  cin >> w >> n;
  vector<int> a(w+1,Max);
  int value , cost;
  a[0] = 0;
  while (n--)
  {
    cin >> value >> cost;

    for(int i=0;i<=w;i++){
      int j = min(w,i+value);
      a[j] = min(a[j],a[i] + cost);
    }
  }
  cout << a[w] << endl;
  
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    long n;
    cin >> n;
    vector<long> b(n+1);
    vector<long> a(n);
    for (int i = 0; i < n+1; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long ans = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] <= a[i]) {
            ans += b[i];
            a[i] -= b[i];
            b[i] == 0;
        }
        else {
            ans += a[i];
            continue;
        }
        if (b[i+1]<=a[i]) {
            ans += b[i+1];
            b[i+1] = 0;
        }
        else {
            ans += a[i];
            b[i+1] -= a[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
struct st
{
	long long stlen;
	long long num;


};
st g[2000005];
bool cmp(st a,st b)
{
	if(a.stlen>b.stlen)
		return true;
	else
		return false;

}
int main()
{
	long long n,i,a;
	map<long long,int>q;
	while(~scanf("%lld",&n))
	{
		
		q.clear();
		for(i = 0;i<n;i++)
		{
		 scanf("%lld",&a);
		 q[a]++;
		}
		int k = 0;
		for(map<long long,int>::iterator j = q.begin();j!=q.end();j++)
		{
			if(j->second>=2)
			{
				g[k].num = j->second;
				g[k].stlen=j->first;
				k++;
			}
		
		
		}
		sort(g,g+k,cmp);
		long long bian[20];
		bian[0]=0;
		bian[1]=0;
		int kk=0;
		for(i = 0;i<k;i++)
		{
			
			if(g[i].num>=4&&kk==0)
			{
				bian[0]=g[i].stlen;
				bian[1]=g[i].stlen;
				break;
			
			}
			else
			{
			 bian[kk] = g[i].stlen;
			 kk++;
			 if(kk==2)
			 {
			  break;
			 }
			}


		}
		printf("%lld\n",bian[0]*bian[1]);
	
	
	}
	
	
	
  
	
}
   
   



Measured memory_bytes: 6528
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  string s;
  cin>>s;
  
  rep(i,3){
    if(s[i]=='1') s[i]='9';
    else if(s[i]=='9') s[i]='1';
  }
  cout<<s<<endl;
  
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	public void run(){
		Scanner scan = new Scanner(System.in);
		double[] point = new double[8];
		while(scan.hasNext()){
			for(int i = 0;i < 8;i++){
				point[i] = scan.nextDouble();
			}
			if(Math.max(point[0],point[2]) < Math.min(point[4],point[6])
					|| Math.min(point[0],point[2]) > Math.max(point[4],point[6])
					|| Math.max(point[1],point[3]) < Math.min(point[5],point[7])
					|| Math.min(point[1],point[3]) > Math.max(point[5],point[7])){
				System.out.println("NO");
			}else{
				System.out.println("YES");
			}
		}
	}
}

Measured memory_bytes: 20756
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
constexpr auto MOD = 998244353;
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; }

ll C[51][51] = {};

int main() {

    int n, a, b;
    ll v;
    cin >> n >> a >> b;
    map<ll, int> m;
    FOR(i, 0, n) {
        cin >> v;
        m[v]++;
    }

    vector<ll> d;
    for (auto i : m)d.push_back(i.first);
    rSORT(d, [](ll a, ll b) {return a > b; });
    double ave = 0;

    int cnt = a, itr = 0;
    if (m[d[0]] > a)ave = d[0];
    else {
        while (1) {
            if (cnt <= m[d[itr]]) {
                ave += d[itr] * cnt;
                break;
            }
            else {
                ave += d[itr] * m[d[itr]];
                cnt -= m[d[itr++]];
            }
        }
        ave /= a;
    }
    printf("%.11lf\n", ave);

    eFOR(i, 0, n) {
        eFOR(j, 0, i) {
            if (j == 0 || j == i) {
                C[i][j] = 1LL;
            }
            else {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            }
        }
    }

    ll ans = 0;
    if (d[0] != d[itr]) {
        ans = C[m[d[itr]]][cnt];
    }
    else eFOR(i, a, min(m[d[0]], b))ans += C[m[d[0]]][i];
    cout << ans << endl;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
	int n;
	cin>>n;
	vi h(n);
	for (int i = 0; i < n; i++){
		cin>>h[i];
	}

	vi dp(n,1e+9);
	dp[0]=0;
	for (int i = 0; i < n; i++){
		dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
	}

	cout<<dp[n-1]<<endl;

	return 0;
}


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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};
using namespace std;
void solve(){
    int a;
    cin>>a;
    int t=0;
    for(int i=1;i<=a;i++){
          int count=0;
        if(i%2!=0){
          for(int j=1;j<=i;j++)
                  if(i%j==0)
                      count++;
          if(count==8)
              t++;
       }
    }
    cout<<t;
}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vec;
typedef vector<vec> mat;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

const int MAX_N = 100010;
vec dp(MAX_N,-1);//1-indexed
mat G(MAX_N,vec(0));//1-indexed

int longest(ll v){
    int ans = 0;
    for(auto i : G.at(v)){
        if(dp.at(i) != -1) ans = max(ans,dp.at(i)+1);
        else ans = max(ans,longest(i)+1);
    }
    dp.at(v) = ans;
    return ans;
}

int main() {
    int V,E;
    scanf("%d %d", &V, &E);
    for(int i = 0; i < E; i++) {
        // sからtへの辺を張る
        int s,t;
        scanf("%d %d", &s, &t);
        G[s].push_back(t);
        // G[t].push_back(s); 無向グラフの場合
    }
    int ans = 0;
    reps(i,1,V+1) ans = max(ans,longest(i));
    cout<<ans<<endl;    
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
int a[100005];
int dp[100005];
int n, k;
int main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> k;
    for(int i = 1 ; i <= n ; i++){
        cin >> a[i];
    }
    for(int i = 0 ; i <= k ; i++){
        for(int s = 1; s <= n; s++){
            if(i>=a[s]&&dp[i-a[s]]==0)dp[i] = 1;
        }
    }
    if(dp[k]==1){cout << "First";return 0;}
    cout << "Second";
}


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

int main()
{
    const int kMaxNum = 100;
    int array[kMaxNum];

    int num = 0;
    cin >> num;
    
    for (int i=0; i<num; ++i)
    {
        cin >> array[i];
    }
    for (int i=0; i<num; ++i)
    {
        if (i != 0) cout << " ";
        cout << array[num-1 -i];
    }
    cout << endl;
    
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int hp;
  cin >> hp;
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    hp = gcd(hp, a);
  }

  cout << hp << endl;
  return 0;
}


Measured memory_bytes: 3632
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Prime prime = new Prime();
		prime.addPrime(n);
//		prime.printPrime(n);
		List<Integer> list = new ArrayList<>();
		for (int i = 1; i <= n; i++) {
			list.addAll(prime.getPrimeFactor(i));
		}
		Map<Integer, List<Integer>> map = list.stream()
			.collect(Collectors.groupingBy(i -> i));
		List<Integer> list2 = map.keySet()
			.stream()
			.map(e -> map.get(e).size())
			.collect(Collectors.toList());
		BigInteger bigInteger = new BigInteger("1");
		for (Integer integer : list2) {
//			System.out.println(integer);
//			ans *= (integer + 1);
			bigInteger = bigInteger.multiply(new BigInteger("" + (integer + 1)));
		}
		System.out.println(bigInteger.mod(new BigInteger("1000000007")));
	}
	
	public static class Prime {
		private List<Integer> list = new ArrayList<>();
		public Prime() {
			list.add(2);
			list.add(3);
		}

		/**
		 * リストにn未満の素数があるかを判定する
		 * @return trueであればリストされている
		 */
		public boolean isListed(int n) {
			return list.get(list.size() - 1) >= n;
		}

		/**
		 * n未満の素数を表示する
		 * @param n nの数字
		 */
		public void printPrime(int n) {
			if (!isListed(n)) {
				addPrime(n);
			}
			list.stream()
				.filter(e -> e < n)
				.forEach(System.out::println);
		}

		/**
		 * n未満の整数をリストに追加する
		 * @param n
		 */
		public void addPrime(int n) {
			if (n <= 2) {
				return;
			}
			for (int i = list.get(list.size() - 1) + 2; i < n; i += 2) {
				if (new Check() {
					@Override
					public boolean accept(int i) {
						for (Integer integer : list) {
							int sq = (int) Math.sqrt(i);
							if (integer > sq) {
								return true;
							}
							if (i % integer == 0) {
								return false;
							}
						}
						return true;
					}
				}.accept(i)) {
					list.add(i);
				}
				
			}
		}

		/**
		 * @param n 素因数分解する変数を代入する
		 * @return 素因数因子のリストを返却する
		 */
		public List<Integer> getPrimeFactor(int n) {
			if (!isListed(n + 1)) {
				addPrime(n + 1);
			}
			int a = n;
			List<Integer> list = new ArrayList<>();
			for (int i = 0; i < this.list.size(); i++) {
				int b = this.list.get(i);
				if (a % b == 0) {
					list.add(b);
					i--;
					a /= b;
				}
				if (a < b ) {
					break;
				}
			}
			return list;
		}
	}
	public static interface Check{
		public boolean accept(int i);
	}
}


Measured memory_bytes: 16312
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?(テァツクツョテ・ツーツ湘ァツ可?

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;
double R, theta;
int x[25], y[25];
vector<pdi> to[25][25];
double rec[25][25][10001];

// テァツ崢エテァツキツ?ab テ」ツ?ィ ac テ」ツ?ョテ・ツ??ァツゥツ?
double dot(int a, int b, int c) {
    int px = x[b] - x[a], qx = x[c] - x[a];
    int py = y[b] - y[a], qy = y[c] - y[a];
    return px * qx + py * qy;
}

// テ」ツδ凖」ツつッテ」ツδ暗」ツδォ ab テ」ツ?ョテゥツ閉キテ」ツ??
double absvec(int a, int b) {
    double px = x[b] - x[a], py = y[b] - y[a];
    return sqrt(px*px + py*py);
}

// テ・ツシツァテ・ツコツヲテヲツウツ陛」ツ?ォテァツ崢エテ」ツ??
double to_rad(double t) {
    return M_PI * t / 180.0;
}

struct Elem {
    int cur, prev, res;
};

bool operator<(const Elem &a, const Elem &b) {
    return rec[a.cur][a.prev][a.res] > rec[b.cur][b.prev][b.res];
}

signed main() {
    cin >> N >> R >> theta;
    double val = cos( to_rad(theta) );
    rep(i,0,N) cin >> x[i+1] >> y[i+1];

    repq(i,1,N) repq(j,1,N) {
        if(i == j) continue;
        repq(k,1,N) {
            if(i == k || j == k) continue;
            double temp = - dot(i, j, k) / absvec(i, j) / absvec(i, k);
            if(val <= temp) to[i][j].push_back(pdi(absvec(i, k), k));
        }
    }

    // テヲツ慊?・ツ按敕」ツ?ッテ」ツ?ゥテ」ツ?禿」ツ?ォテ」ツ?ァテ」ツつづィツ。ツ古」ツ?妥」ツつ?
    repq(i,2,N) {
        to[1][0].push_back(pdi(absvec(1, i), i));
    }

    rep(i,0,25) rep(j,0,25) rep(k,0,10001) rec[i][j][k] = INF;
    rec[1][0][0] = 0.0;

    priority_queue<Elem> q;
    q.push(Elem{1, 0, 0});

    while(!q.empty()) {
        Elem t = q.top(); q.pop();
        for(auto x : to[t.cur][t.prev]) {
            int nx = x.second; double cost = x.first;
            if(rec[nx][t.cur][t.res+1] > rec[t.cur][t.prev][t.res] + cost) {
                if(rec[t.cur][t.prev][t.res] + cost > R) continue;
                rec[nx][t.cur][t.res+1] = rec[t.cur][t.prev][t.res] + cost;
                q.push(Elem{nx, t.cur, t.res+1});
            }
        }
    }

    int ans = 0;
    repq(i,1,N) repq(j,1,N) rep(k,0,10001) {
        if(rec[i][j][k] == INF) continue;
        chmax(ans, k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 52468
from fractions import gcd

def factorization(n):
    res = []
    m = 2
    while m ** 2 <= n:
        if n % m == 0:
            cnt = 0
            while n % m == 0:
                cnt += 1
                n //= m
            res.append([m, cnt])
        m += 1

    if n > 1:
        res.append([n, 1])

    return res


a, b = map(int, input().split())
print(len(factorization(gcd(a, b))) + 1)

Measured memory_bytes: 64876
// #include<iostream>
// using namespace std;
// int main(){
// 	string s;
// 	cin >> s;
// 	if(s[0] == '7' || s[1] == '7' || s[2]== '7') cout << "Yes";
// 	else cout << "No";
// }

#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		if(i % 3 && i % 5) sum += i;
	}
	cout << sum;
}

Measured memory_bytes: 3192
def main(w, a, b):
    if a <= w and b <= w:
        print(0)
    elif a <= b:
        print(b - (w + a))
    else:
        print(a - (w + b))


if __name__ == "__main__":
    w, a, b = map(int, input().split())

    main(w, a, b)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define vec vector
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false
using namespace std;


ll kmm(ll a, ll b) {
	return(a*b) / __gcd(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 1e5+5;
ll modpower(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modpower((x*x)%mod,n/2);
    else
        return (x*modpower((x*x)%mod,(n-1)/2))%mod;

}

ll facpower(ll x){
	if(x==0)
		return 1;
	return ((x%mod)*(facpower(x-1)%mod))%mod;
}



ll a,b;
int main() {
    cin >> a >> b;
    cout << kmm(a,b);

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder01
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Allmasu = Console.ReadLine().Split(' ');
            string[] Masu = Console.ReadLine().Split(' ');
            int a = int.Parse(Allmasu[0]);
            int b = int.Parse(Allmasu[1]);
            int c = int.Parse(Masu[0]);
            int d = int.Parse(Masu[1]);
            int aku = (a * b) - ((c * b) + (d * a) - (c * d));
            Console.WriteLine(aku);
        }
    }
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#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, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

bool is_res(int n){
    map<int,int> p;
    for(int i = 2;i*i<=n;i++){
        while(n%i == 0){
            n/=i;
            p[i]++;
        }
    }
    if(n > 1)p[n]++;
    ll res = 1;
    for(auto a:p){
        res *= a.second + 1;
    }
    if(res == 8)return true;
    return false;
}
signed main()
{   
    gearup;
    ll a,b,c,x,y; cin>>a>>b>>c>>x>>y;
    ll res;
    res = min(a*x+b*y,2*c*max(x,y));
    ll z = min(x,y);
    res = min(res,2*c*z+a*(x-z)+b*(y-z));
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <utility>

using namespace std;
typedef pair<int, int> pii;
const int INF = 1000000;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

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

int search(const vector< vector<int> > &weight, int sx, int sy, int gx, int gy){
	int H = weight.size(), W = weight[0].size();
	priority_queue< pii, vector<pii>, greater<pii> > pq;
	vector< vector<int> > mincost(H, vector<int>(W, INF));
	pq.push(pii(0, sx + sy * W));
	mincost[sy][sx] = 0;
	while(!pq.empty()){
		pii p = pq.top();
		pq.pop();
		int cost = p.first, x = p.second % W, y = p.second / W;
		if(cost > mincost[y][x]){ continue; }
		if(x == gx && y == gy){ return cost; }
		for(int i = 0; i < 4; ++i){
			int ny = y + dy[i], nx = x + dx[i];
			if(!between(0, ny, H) || !between(0, nx, W)){ continue; }
			int nc = cost + weight[y][x];
			if(nc >= mincost[ny][nx]){ continue; }
			mincost[ny][nx] = nc;
			pq.push(pii(nc, nx + ny * W));
		}
	}
	return INF;
}

int main(){
	int W, H;
	cin >> W >> H;
	vector<string> field(H);
	for(int i = 0; i < H; ++i){ cin >> field[i]; }
	vector< vector<int> > weight(H, vector<int>(W, 1));
	int sx, sy, gx, gy;
	vector<int> mx, my;
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			if(field[i][j] == 'S'){
				sx = j;
				sy = i;
			}else if(field[i][j] == 'G'){
				gx = j;
				gy = i;
			}else if(field[i][j] == 'M'){
				mx.push_back(j);
				my.push_back(i);
			}else if(field[i][j] == '#'){
				for(int y = -2; y <= 2; ++y){
					for(int x = -2; x <= 2; ++x){
						if(!between(0, i + y, H) || !between(0, j + x, W)){
							continue;
						}
						int d = max(abs(y), abs(x));
						if(d == 0){
							weight[i + y][j + x] = INF;
						}else if(d == 1){
							weight[i + y][j + x] = max(weight[i + y][j + x], 3);
						}else if(d == 2){
							weight[i + y][j + x] = max(weight[i + y][j + x], 2);
						}
					}
				}
			}
		}
	}
	int M = mx.size();
	vector<int> scost(M), gcost(M);
	vector< vector<int> > cmat(M, vector<int>(M, INF));
	for(int i = 0; i < mx.size(); ++i){
		scost[i] = search(weight, sx, sy, mx[i], my[i]);
		gcost[i] = search(weight, mx[i], my[i], gx, gy);
		for(int j = 0; j < mx.size(); ++j){
			cmat[i][j] = search(weight, mx[i], my[i], mx[j], my[j]);
		}
	}
/*
for(int i = 0; i < M; ++i){ cout << scost[i] << " "; }
cout << endl;
for(int i = 0; i < M; ++i){ cout << gcost[i] << " "; }
cout << endl << endl;
for(int i = 0; i < M; ++i){
	for(int j = 0; j < M; ++j){ cout << cmat[i][j] << " "; }
	cout << endl;
}
*/
	vector<int> perm(M);
	for(int i = 0; i < M; ++i){ perm[i] = i; }
	int answer = INF;
	do {
		int sum = scost[perm[0]] + gcost[perm[M - 1]];
		for(int i = 1; i < M; ++i){
			sum += cmat[perm[i - 1]][perm[i]];
		}
		answer = min(answer, sum);
	} while(next_permutation(perm.begin(), perm.end()));
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1348
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        h: u32,
        a: u32
    }
    println!("{}", (h + a - 1) / a);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

class Dis{
  public:
  vector<ll> rank,p,siz;
  
  Dis(int s){
    rank.resize(s,0);
    p.resize(s,0);
    siz.resize(s,1);
    rep(i,s) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
  
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      siz[x]+=siz[y];
    }
    else{
      p[x]=y;
      siz[y]+=siz[x];
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int findSet(int x){
    if(x != p[x]) p[x]=findSet(p[x]);
    return p[x];
  }
  
  ll size(int x){
    return siz[findSet(x)];
  }
};


int main(){
  ll n,m;
  cin>>n>>m;
  
  vector<int> A(m),B(m);
  int a,b;
  rep(i,m){
    cin>>a>>b;
    A[i]=a-1;
    B[i]=b-1;
  }
  
  int ans=0;
  rep(i,m){
    Dis ds=Dis(n);
    
    rep(j,m){
      if(j==i) continue;
      ds.unite(A[j],B[j]);
    }
    if(!ds.same(A[i],B[i])) ans++;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
bool flag = true;
int main()
{
    string s;
    cin >> s;
    string tmp = "";
    rrep(i, s.size())
    {
        tmp += s[i];
        if (tmp.size() > 7)
            break;
        if (tmp == "maerd" || tmp == "remaerd" || tmp == "resare" || tmp == "esare")
            tmp = "";
    }
    if (tmp == "")
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <list>
#include <algorithm>

using namespace std;

#define max 110000


int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	//素数テーブル作成
	vector<bool> v;
	for(int i = 0; i < max; i++)
		v.push_back(true);

	v.at(0) = false;
	v.at(1) = false;
	for(int i = 2; i < max; i++) {
		if( v.at(i) == false ) continue;
		for(int j = 2 * i; j < max; j += i )
			v.at(j) = false;
	}


	while( 1 ) {
		int N, P;
		cin >> N >> P;
		if( N == -1 && P == -1 ) break;

		vector<int> plist;
		for(int i = N + 1; plist.size()*(plist.size() - 1) / 10 < P  && i < max ; i++)
			if( v.at(i) == true ) plist.push_back(i);
		
		vector<int> sumlist;

		for(int i = 0; i < plist.size(); i++) {
			sumlist.push_back( 2 * plist.at(i) );
			for(int j = i + 1; j < plist.size(); j++)
				sumlist.push_back( plist.at(i) + plist.at(j) );
		}

		sort( sumlist.begin(), sumlist.end() );
		
		cout << sumlist.at(P-1) << endl;

	}

	//while(1){}
	return 0;
}

Measured memory_bytes: 1252
import java.util.*;

class Main{
  public static void main(String[] args){
     Scanner sc=new Scanner(System.in);
     int n=sc.nextInt();
     int T=sc.nextInt();

     int answer=1001;
     for(int i=0;i<n;i++){
       int c=sc.nextInt();
       int t=sc.nextInt();
       if(c<answer&&t<=T){
         answer=c;
       }
     }
     System.out.println(answer!=1001?answer:"TLE");
  }
}

Measured memory_bytes: 22996
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a > k:
    print(":(")
elif e - b > k:
    print(":(")
elif e - c > k:
    print(":(")
elif e - d > k:
    print(":(")
else:
    print("Yay!")


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<tuple<string,int,int>> a(n);
	rep(i,n){
		string s; int p;
		cin >> s >> p;
		p *= -1;
		a[i] = make_tuple(s,p,i+1);
	}
	SORT(a);
	rep(i,n){
		cout << get<2>(a[i]) << endl;
	}
}


Measured memory_bytes: 3636