akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[0] !='A'){
        cout << "WA"<<endl;
        return 0;
    }
    int count = 0;
    int ic;
    for(int i=2;i<s.size()-1;i++){
        if(s[i] == 'C'){
            count++;
            ic = i;
        }
    }
    if(count != 1){
        cout << "WA" << endl;
        return 0;
    }
    for(int i=1;i<s.size();i++){
        if(i == ic){
            continue;
        }
        if(s[i] < 'a' || s[i] > 'z'){
            cout << "WA" << endl;
            return 0;
        }
    }
    cout << "AC" << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, h; read(n, h);
	vector<int> m;
	int ma = 0;

	m.reserve(n);

	rep(i, 0, n) {
		int a, b; read(a, b);
		chmax(ma, a);
		m.push_back(b);
	}

	sort(all(m));

	int ans = 0;

	while (h > 0 && m.size() && m.back() > ma)
		h -= m.back(), ans++, m.pop_back();;
	if (h > 0) ans += (h + ma - 1) / ma;

	die(ans);
}


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

using namespace std;

int digsum(int x){
  int tmp=0;
  while(x){
    tmp+=x%10;
    x/=10;
  }
  return tmp;
}

int main(){
  int a,n,m; cin >> a >> n >> m;
  int ans=0;
  for(int i=1;i<=m;++i){
    int du=1;
    for(int j=0;j<n;++j) du*=(i+a);
    if(du>m) break;
    if(digsum(du)==i) ans++;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H;
  int W;
  cin >> H >> W;
 vector<vector<char>> data(H, vector<char>(W));
 vector<vector<char>> answer(H+2, vector<char>(W+2));
  // データを受け取る
  for (int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
    cin >> data.at(i).at(j);
  }
  }
  for (int i = 0; i < H+2; i++) {
    for(int j = 0; j < W+2; j++) {
     if(i==0 || i== H+1 || j== 0 || j==W+1){
     answer.at(i).at(j) =  '#';
     }else{      
    answer.at(i).at(j) = data.at(i-1).at(j-1);
     }
  }
  }
  
  for (int i = 0; i < H+2; i++) {
    for(int j = 0; j < W+2; j++) {
   if(j!=W+1){cout << answer.at(i).at(j);}
      else{cout << answer.at(i).at(j) << endl;}
  }
  }
  
}

Measured memory_bytes: 256
// https://arc076.contest.atcoder.jp/tasks/arc076_c
#include<iostream>
#include<vector>
#include<algorithm>

#ifdef _GLIBCXX_DEBUG
#define cin cin_
#include<sstream>
namespace std{std::stringstream cin(R"(
1 1 2
0 0 1 1
1 0 0 1
)");}
#endif

int r,c;
int process(int x,int y){
	if(y==0)return x;
	if(x==r)return r+y;
	if(y==c)return r+c+(r-x);
	if(x==0)return r+c+r+(c-y);
	return -1;
}

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

	int n;std::cin>>r>>c>>n;
	struct data{int pos,id;bool close;};
	std::vector<data>lines;lines.reserve(n);
	for(int id=0;id<n;++id){
		int x1,y1,x2,y2;std::cin>>x1>>y1>>x2>>y2;
		int p1=process(x1,y1);
		int p2=process(x2,y2);
		if(p1<0||p2<0)continue;
		lines.push_back({std::min(p1,p2),id,false}); // not close
		lines.push_back({std::max(p1,p2),id,true }); // close
	}
	std::sort(lines.begin(),lines.end(),[](data x,data y){return x.pos<y.pos;});
	std::vector<int>stack;
	for(auto x:lines){
		if(x.close){
			if(stack.back()!=x.id){std::cout<<"NO\n";return 0;}
			stack.pop_back();
		}else
			stack.push_back(x.id);
	}
	std::cout<<"YES\n";
}


Measured memory_bytes: 3584
#include <stdio.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
	int A, B, C, ans = 0;
	scanf("%d %d %d", &A, &B, &C);

	ans = max(0, C - max(0, A - B));
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

// http://kyopro.hateblo.jp/entry/2019/01/28/002707
int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N) { cin >> A[i] >> B[i]; }
    // A-BもしくはB-Aが規準になる
    vector<tuple<int, int, int>> C(N);
    REP(i, N) { C[i] = make_tuple(-(A[i] + B[i]), A[i], B[i]); }
    sort(C.begin(), C.end());
    // v.erase(v.begin());
    // v.pop_back();
    ll takahasi = 0;
    ll aoki = 0;
    REP(i, N) {
        if(i % 2 == 0) {
            // takahasi
            takahasi += get<1>(C[i]);
        } else {
            aoki += get<2>(C[i]);
        }
    }
    // cout << takahasi << ": " << aoki << endl;
    cout << takahasi - aoki << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <string.h>

int adj[100][100];
int vertex;
int ans;

int max(int a, int b)
{
    return (a > b ? a : b);
}

void dfs(int v, int num, int *vis)
{
    int i;
    int flag;
    
    flag = 0;
    for (i = 0; i < vertex; i++){
        if (adj[v][i] && vis[i] == 0){
            adj[v][i] =  0;
            vis[i] = 1;
            dfs(i, num + 1, vis);
            adj[v][i] = 1;
            vis[i] = 0;
          }
    }
    if (flag == 0){
        ans = ans > num ? ans : num;
    }
    return;
}

int main(void)
{
    int vis[100];
    int n;
    int i, j;
    int from, to;
    int count[100], mc;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(count, 0, sizeof(count));
        memset(adj, 0, sizeof(adj));
        vertex = 0;
        
        for (i = 0; i < n; i++){
            scanf("%d%d", &from, &to);
            vertex = vertex < from ? from : vertex;
            vertex = vertex < to ? to : vertex;
            from--;
            to--;
            count[from]++;
            count[to]++;
            adj[from][to] = adj[to][from] = 1;
        }
        
        mc = 10000;
        
        for (i = 0; i < vertex; i++){
            if (count[i] != 0){
                mc = mc > count[i] ? count[i] : mc;
            }
        }
        
        ans = 0;
        for (i = 0; i < vertex; i++){
            if (mc == count[i]){
                memset(vis, 0, sizeof(vis));
                vis[i] = 1;
                if (n == 100 && ans == 9){
                    break;
                }
                dfs(i, 1, vis);
            }
        }
        
        if (ans == 3){
            ans++;
        }
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 448
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0;
	cin >> n;
	vector<int> a(n); map<int, int> mpa;
	for (auto &i : a)
	{
		cin >> i; ++mpa[i];
	}
	vector<int> b(n); map<int, int> mpb;
	for (auto &i : b)
	{
		cin >> i; ++mpb[i];
	}
	int m = -1, pos = -1;
	for (int i = 1; i <= n; ++i)
		if (mpa[i] + mpb[i] > m)
		{
			m = mpa[i] + mpb[i]; pos = i;
		}
	if (m > n)
	{
		cout << "No" << endl; return 0;
	}
	set<pair<int , int> > s;
	for (int i = 0; i < n; ++i)
		if (a[i] != pos)
			s.insert({a[i], i});
	vector<int> v(n, -1);
	vector<bool> vis(n);
	int d = n - m;
	for (int i = 0; i < n; ++i)
		if (b[i] != pos)
		{
			if (d == 0)
				break;
			auto p = *s.begin(); auto pr = *s.rbegin();
			if (p.fi != b[i])
			{
				v[p.se] = b[i]; s.erase(s.begin());
				vis[i] = true; --d;
			}
			else if (pr.fi != b[i])
			{
				v[pr.se] = b[i]; s.erase(--s.end());
				vis[i] = true; --d;
			}
		}
	vector<int> aux;
	for (int i = 0; i < n; ++i)
		if (a[i] == pos)
			aux.pb(i);
	for (int i = 0; i < n; ++i)
		if (!vis[i] && b[i] != pos)
		{
			v[aux.back()] = b[i]; aux.pop_back();
		}
	for (int i = 0; i < n; ++i)
		if (b[i] == pos)
			aux.pb(b[i]);
	for (int i = 0; i < n; ++i)
		if (v[i] < 0)
		{
			v[i] = aux.back(); aux.pop_back();
		}
	cout << "Yes" << endl;
	for (int i = 0; i < n; ++i)
		cout << v[i] << " ";
	cout << endl;
}

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

const int MAX_V = 160000;
int par[MAX_V];
int depth[MAX_V];
int black_num[MAX_V];
int white_num[MAX_V];

void init(int n) {
    for(int i = 0; i < n; i++)
    {
        par[i] = i;
        depth[i] = 0;
    }
}

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

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    black_num[x] += black_num[y];
    black_num[y] = black_num[x];
    white_num[y] += white_num[x];
    white_num[x] = white_num[y];

    if (depth[x] < depth[y]) par[x] = y;
    else {
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

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

int get_black(int x) {
    return black_num[root(x)];
}

int get_white(int x) {
    return white_num[root(x)];
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s.at(i).at(j);
        }
    }

    init(h * w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s.at(i).at(j) == '#') black_num[i * w + j] = 1;
            else white_num[i * w + j] = 1;
        }
    }

    int dx[] = {0, 0, 1, -1};
    int dy[] = {1, -1, 0, 0};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < 4; k++) {
                int ny = i + dy[k], nx = j + dx[k];
                if (0 <= ny && ny < h && 0 <= nx && nx < w && s.at(i).at(j) != s.at(ny).at(nx)) {
                    unite(i * w + j, ny * w + nx);
                }
            }
        }
    }
    
    vector<bool> done(h * w);
    long long cnt = 0;
    for (int i = 0; i < h * w; i++) {
        if (done.at(root(i))) continue;
        
        cnt += (long long)get_black(i) * get_white(i);
        done.at(root(i)) = true; 
    }
    
    cout << cnt << endl;
}

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

int main() {
  int n, a, d;
  cin >> n >> a >> d;
  map<int, int> ops;
  auto getItem = [&](int i) {
    if(ops.count(i)) {
      return ops[i];
    } else {
      return a + d * (i - 1);
    }
  };
  int m;
  cin >> m;
  for(int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    if(x) {
      ops[y] = getItem(z);
    } else {
      int temp = getItem(z);
      ops[z] = getItem(y);
      ops[y] = temp;
    }
  }
  int k;
  cin >> k;
  cout << getItem(k) << endl;
  return 0;
}

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

using namespace std;


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

    vector<int> e(n + 1, 0), w(n + 1, 0);

    for (int i = 0; i < n; ++i) {
        e[i + 1] = e[i];
        w[i + 1] = w[i];
        if (s[i] == 'E') e[i + 1]++;
        else w[i + 1]++;
    }

    int ans = 300010;
    for (int i = 0; i < n; ++i) {
        int num = w[i] + e[n] - e[i + 1];
        ans = min(ans, num);
    }

    cout << ans << endl;

}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    string s, t;
    cin>>s>>t;
    vector<int> start;
    rep(i, s.size() - t.size() + 1) {
        if(s[i] == t[0] || s[i] == '?') start.push_back(i);
    }
    int res = -1;
    bool flag;
    each(i, start) {
        flag = true;
        rep(j, i, i + t.size()) {
            if(s[j] != t[j - i] && s[j] != '?') flag = false;
        }
        if(flag) res = i;
    }
    if(res == -1) {
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    rep(i, s.size()) {
        if(s[i] == '?') s[i] = 'a';
    }
    rep(i, t.size()) {
        s[res + i] = t[i];
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;

int main(void){
    char s[10];
    scanf("%s",s);
    int res = 0;
    vector<char> p;
    for(int i=0;i<strlen(s);i++){
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G'){
            p.push_back(s[i]);
        }else{
            if(!p.empty()&&res < p.size())res = p.size();
            p.clear();
        }
    }
    if(!p.empty()&&res < p.size())res = p.size();
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 888
def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 or visitct!=n:
    ct+=1
    for i in range(len(next)):
      distance[next[i]]=ct
      visited[next[i]]=1
      visitct+=1
      for j in range(len(connection[next[i]])):
        if visited[connection[next[i]][j]]==-1:
          next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

import sys
input = sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
 
f=bfs(0);s=bfs(n-1)
ctf=0;cts=0
for i in range(n):
  if f[i]<=s[i]:
    ctf+=1
  else:
    cts+=1
 
if ctf>cts:
  print('Fennec')
else:
  print('Snuke')

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

using namespace std;
const int N = 5e5+7; 

struct Node{
	int l,r;
	int i;
}q[N];

int tr[N];
int n,m;
int a[N],vis[N];
int ans[N];

int lowbit(int x){
	return x&-x;
}

void add(int x,int v){
	for(int i = x;i<=n;i+=lowbit(i))
	tr[i] += v; 
}

int query(int x){
	int ans=0;
	for(int i=x;i;i-=lowbit(i)) ans+=tr[i];
	return ans;
}

bool cmp(Node a,Node b){
	return a.r<b.r;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].i = i;
	}
	sort(q+1,q+m+1,cmp);
	int j = 1;
	for(int i=1;i<=m;i++){
		while(j <= q[i].r){
			if(vis[a[j]]) add(vis[a[j]],-1);
			add(j,1);
			vis[a[j]] = j;
			j++;
		}
		ans[q[i].i] = query(q[i].r) - query(q[i].l-1);
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 17436
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int N = reader.nextInt();
		double[] V = new double[N];
		for (int i=0; i<N; i++) {
		    V[i] = (double)reader.nextInt();
		}
		Arrays.sort(V);
		solver(N, V);
	}
	
	public static void solver(int N, double[] V) {
		// write logic
		double ans = V[0];
		for(int i=1; i<N; i++) {
		    ans = (ans+V[i])/2;
		}
		System.out.println(ans);
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 21332
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    if (char(s[0]) != '1' || char(s[n - 1]) != '0') {
        cout << -1 << endl;
        return 0;
    }

    int a[100010], b[100010], bef = 0, idx = 0;
    if (1) {
        for (int i = 0; i < n - 1; i++) {
            if (i < n / 2 && char(s[i]) != char(s[n - 2 - i])) {
                cout << -1 << endl;
                return 0;
            }
            a[idx] = bef;
            b[idx] = i + 1;
            idx++;
            /*
            a[idx] = n - 1 - bef;
            b[idx] = n - 2 - i;
            idx++;
            */
            if (char(s[i]) == '1') bef = i + 1;
        }
        for (int i = 0; i < idx; i++) {
            cout << a[i] + 1 << " " << b[i] + 1 << endl;
        }
    }

}

Measured memory_bytes: 2432
S = input()
a = 0
 
if S == 'SUN':
  a = 7
elif S == 'MON':
  a = 6
elif S == 'TUE':
  a = 5
elif S == 'WED':
  a = 4
elif S == 'THU':
  a = 3
elif S == 'FRI':
  a = 2
elif S == 'SAT':
  a = 1

print(a)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define rep1(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define PI acos(-1.0)
#define LONG_LONG_MAX 9223372036854775807
#define LONG_LONG_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

const int maxn = 1e5 + 10;
int n, m, a, b;
vector<int> vec[maxn];
multiset<int> mts;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    rep(i, n) {
        cin >> a >> b;
        if (m - a >= 0) vec[m-a].pb(b);
    }
    ll ans = 0;
    for (int i = m; i >= 0; --i) {
        while (!vec[i].empty()) {
            mts.insert(*prev(vec[i].end()));
            vec[i].pop_back();
        }
        if (!mts.empty()) {ans += *prev(mts.end());
        mts.erase(prev(mts.end()));}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7808
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

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

    int N, K;
    cin >> N >> K;
    
    vi A(N);
    int g = 0, ma = 0;
    rep(i, N) {
        int a; cin >> a;
        smax(ma, a);
        g = gcd(g, a);
    }

    string ans = "IMPOSSIBLE";
    if (K <= ma && K%g == 0)ans = "POSSIBLE";
    cout << ans << endl;
}


Measured memory_bytes: 640
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

H, W = map(int, input().split())
h, w = map(int, input().split())
print(H * W - h * W - w * H + (h * w))



Measured memory_bytes: 63980
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
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;}
template<class T> inline bool chmax(T& a, T b){if(a<b) {a=b; return 1;} return 0; }
template<class T> inline bool chmin(T& a, T b){if(a>b) {a=b; return 1;} return 0; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;

int main(){
	//入力
	ll L; cin>>L;

    printf("%.7f\n",(double)L*L*L/27);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, max;
  int t[100] = {0};

  while (cin >> n)
    t[n - 1] += 1;

  for (int i = max = 0; i < 100; i++)
    if (t[i] > 0)
      if (max < t[i]) max = t[i];

  for (int i = 0; i < 100; i++)
    if (t[i] == max)
      cout << i + 1 << endl;

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string w; cin >> w;
  map<char, int> c;
  for (auto x: w) c[x]++;

  string result = "Yes";
  for (auto x: c) if (x.second%2!=0) result = "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
dp = [0]

def calc(A, n, dp):
    dp += [A[0] * A[1]]
    rsum = A[0] + A[1]
    for i in range(2, n):
        dp += [dp[-1] + rsum * A[i]]
        rsum += A[i]

    i = dp.index(max(dp))
    rsum = 0
    for j in range(i + 1):
        rsum += A[j]
    res = max(dp)
    dp2 = max(dp)
    for j in range(0, i):
        rsum -= A[j]
        dp2 -= A[j] * rsum
        res = max(dp2, res)
    return res

ans = calc(a, n, dp) % mod
print(ans)



Measured memory_bytes: 31156
#include <iostream>
#include <string>
#define rep(i,n) for(long long i=0;i<n;i++)

using namespace std;
using ll = long long;

int main(void)
{
    int n,m,s,c;
    cin >>n>>m;
    int a[n];
    rep(i,n) a[i]=10;
    rep(i,m)
    {
        cin>>s>>c;
        if(a[s-1]==10)
        {
            a[s-1]=c;
        }else{
        if(a[s-1]==c)
        {
        }else{
            cout<<-1<<endl;
            return 0;
            }}
    }
    if(a[0]==10)
    {
        if(n==1) a[0]=0;
        if(n!=1) a[0]=1;
    }
    if(a[0]==0 && n!=1) 
    {
        cout<<-1<<endl;
        return 0;
    }
    rep(i,n)
    {
        if(a[i]==10) {cout<<0;}else{cout<<a[i];}
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int A, B, C; cin >> A >> B >> C;
    int S = A + B + C;
    Ans(S <= 21, "win", "bust");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  long long co=0;
  long long v;
  cin >> n >> v;
  vector<vector<long long> >a(4,vector<long long>(n,0));
  vector<long long>b;
  vector<long long>c;
  for(int i=0;i<4;i++){
    for(int j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      b.push_back(a[0][i]+a[1][j]);
      c.push_back(a[2][i]+a[3][j]);
    }
  }
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  for(int i=0;i<b.size();i++){
    co+=upper_bound(c.begin(),c.end(),v-b[i])-lower_bound(c.begin(),c.end(),v-b[i]);
  }
  cout << co << endl;
  return 0;
}

Measured memory_bytes: 18772
import math
import calendar
import fractions
import itertools

n = int(input())
a = []
for i in range(n):
    b = int(input())
    a.append(b)
a = sorted(a)
ans = 0
cnt = 0
for i in range(len(a)):
    if i == 0:
        cnt += 1
    else:
        if a[i] == a[i - 1]:
            cnt += 1
        else:
            if cnt % 2 == 1:
                ans += 1
                cnt = 1
            else:
                cnt = 1
if cnt % 2 == 1:
    ans += 1
print(ans)



Measured memory_bytes: 84948
#include<stdio.h>


int main(){
  int x,n;
  scanf("%d%d",&x,&n);
  if(n==0){
    printf("%d\n",x);
    return 0;
  }
  int i,j,p[n],out1,out2,ans;
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(i=0;i<n+1;i++){
    out1=0;
    out2=0;
    for(j=0;j<n;j++){
      if(x+i==p[j]){
        out1=1;
      }
      if(x-i==p[j]){
        out2=1;
      }
    }
    if(out2==0){
      printf("%d\n",x-i);
      return 0;
    }
    if(out1==0){
      printf("%d\n",x+i);
      return 0;
    }
  }

}


Measured memory_bytes: 1712
#include<bits/stdc++.h>
        #define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
        #define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
        using namespace std;
         
         
        int main(){
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);
          char b;
          cin>>b;
          if(b=='A')cout<<'T';
          if(b=='T')cout<<'A';
          if(b=='G')cout<<'C';
          if(b=='C')cout<<'G';
          return 0;
        }

Measured memory_bytes: 256
def main():
    N,K=map(int,input().split())
    ab=[0]*N
    for i in range(N):
        x=list(map(int,input().split()))
        ab[i]=x
    ab.sort(key=lambda x:x[0])

    count=0
    for i in range(N):
        count+=ab[i][1]
        if count>=K:
            print(ab[i][0])
            break

if __name__=="__main__":
    main()

Measured memory_bytes: 29144
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
    int x,a,b;
    cin>>x;
    cin>>a;
    cin>>b;
    int y;
    y = x-a;
    int ans = y%b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
//using fs = unordered_set;
//#define fs set//unordered_set
vector<ll> S(0);

ll FFi(ll i){
    if(S[i]==i)return i;
    return S[i]=FFi(S[i]);
    
}

void marge(ll a,ll b){
    
    ll aa=FFi(a),bb=FFi(b);
    if(aa==bb)return;
    S[aa]=bb;
}


int main() {
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> A(N);
    for(ll i=0;i<N;i++)S.push_back(i);
    for(ll i=0;i<M;i++){
        ll sub1,sub2;
        cin >> sub1 >> sub2;
        marge(sub1-1, sub2-1);
     
        
    }
   
    vector<ll> CO(N,0);
    for(ll i:S){
        CO[FFi(i)]++;
    }
    sort(CO.begin(), CO.end(), [](ll a,ll b){return a>b;});
    
    cout << CO[0] << endl;
    
    
}


Measured memory_bytes: 14164
#include <iostream>

int main() {
    int N;
    long long D;
    std::cin >> N >> D;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        long long X, Y;
        std::cin >> X >> Y;
        if (X * X + Y * Y <= D * D) cnt++;
    }
    std::cout << cnt << std::endl;
}

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

int main(){
  int n;
  while(cin>>n,n){
    int Max=0;
    string airport[50];
    string code[50];
    for(int i=0;i<n;i++){
      cin>>airport[i];
      code[i]=airport[i][0];
      bool vowel=false;
      for(int j=0;j<airport[i].size();j++){
	if(vowel) code[i].push_back(airport[i][j]);
	if(airport[i][j]=='a'||airport[i][j]=='i'||airport[i][j]=='u'||
		airport[i][j]=='e'||airport[i][j]=='o') vowel=true;
	else vowel=false;
      }
      if(code[i].size()>Max) Max=code[i].size();
    }
    bool can=false;
    for(int i=1;i<=Max;i++){
      set<string> s;
      for(int j=0;j<n;j++){
	if(code[j].size()<i) code[j].push_back('$');
	s.insert(code[j].substr(0,i));
      }
      //cout<<s.size()<<endl;
      if(s.size()==n){
	cout<<i<<endl; can=true; break;
      }
    }
    if(!can) cout<<"-1"<<endl;
  }
}


Measured memory_bytes: 1248
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] c = new int[n];
		HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();
		int[] place = new int[n];
		for (int i=0;i<=200_000;i++) {
			map.put(i, new ArrayList<Integer>());
		}
		for (int i=0;i<n;i++) {
			c[i]=sc.nextInt();
			place[i]=map.get(c[i]).size();
			map.get(c[i]).add(i);
		}
		long MOD = 1_000_000_007;
		long[] ans = new long[n];

		ans[0]=1;
		for (int i=1;i<n;i++) {
			ans[i]=ans[i-1];
			if (c[i]!=c[i-1]) {
				if (place[i]==1) {
					if (map.get(c[i]).get(0)>0) {
						ans[i]+=ans[map.get(c[i]).get(0)-1];
					}
					else {
						ans[i]++;
					}
					ans[i]%=MOD;
				}
				if (place[i]>1) {
					ans[i]+=ans[map.get(c[i]).get(place[i]-1)];
					ans[i]%=MOD;

				}
			}
		}

		System.out.println(ans[n-1]);
	}
}


Measured memory_bytes: 122424
import java.util.*;
public class Main {
	static long dp[][][]=new long[3002][3002][2];
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long arr[]=new long[n];
		long sum=0;
		for(int i=0;i<n;i++){
			arr[i]=sc.nextLong();
			sum+=arr[i];
		}
		long ans=helper(0,n-1,0,arr);
		System.out.println(2*ans-sum);
	}
	public static long helper(int i,int j,int turn,long[] arr){
		if(i>j){
			return 0;
		}
		if(dp[i][j][turn]!=0){
			return dp[i][j][turn];
		}
		if(turn==0){
			return dp[i][j][turn]=Math.max(arr[i]+helper(i+1,j,1,arr),arr[j]+helper(i,j-1,1,arr));
		}
		else{
			return dp[i][j][turn]=Math.min(helper(i+1,j,0,arr),helper(i,j-1,0,arr));
		}
	}
}


Measured memory_bytes: 364860
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        h: [i64; n],
    }

    let mut dp = vec![1 << 50; n + 1];
    dp[0] = 0;
    for i in 1..n {
        dp[i] = std::cmp::min(dp[i], dp[i - 1] + (h[i] - h[i - 1]).abs());
        if i >= 2 {
            dp[i] = std::cmp::min(dp[i], dp[i - 2] + (h[i] - h[i - 2]).abs());
        }
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
/*input
11009 11332
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii; 


#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define syso(n) cout<<n<<endl;
#define sysom(message, n) cout<<message<<n<<endl;
#define all(c) c.begin(), c.end() 
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(all(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 


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

ll lcm(ll fir, ll sec){
    return (fir*sec)/(gcd(fir, sec));
}

//x^n%M
// log(n) time, log(n) memory
ll modularExponentiation(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}

const int MOD = 1e9 + 7;
const string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
const int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(5) << f << '\n';


// ios_base::sync_with_stdio(false);
// cin.tie(NULL);

bool pali(int x){
    // syso("here");
    string s = to_string(x);
    // what_is(s);
    string r = s;
    reverse(r.begin(), r.end());
    if(r==s){
        return true;
    }
    return false;
}

int main(){
    int a,b;
    cin>>a>>b;
    int ans = 0;
    for (int i = a; i <= b; ++i){
        if(pali(i)){
            ans++;
        }
    }
    syso(ans);
}

Measured memory_bytes: 256
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = set(table)
    return table

def main():
    A, B, K = list(map(int, input().split()))

    divisors = divisor(A).intersection(divisor(B))
    divisors = sorted(divisors)[::-1]
    print(divisors[K-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	string input;
	getline(cin, input);

	const int ul = 'a' - 'A';
	for (auto& c : input)
	{
		if ('A' <= c&&c <= 'Z')
		{
			c += ul;
		}
		else if ('a' <= c&&c <= 'z')
		{
			c -= ul;
		}
	}

	cout << input << endl;

	return 0;
}

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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int r;
    cin >> r;
    double pi = atan2(0, -1);
    cout << r * 2 * pi << '\n';
    return 0;
}


Measured memory_bytes: 3804
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 100500;

int n, a[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
    {
        if ((a[i] >= i && i == n) || (a[i] >= i && a[i + 1] < i + 1))
        {
            int up = (a[i] - i);
            int right = 0;
            int j = i + 1;
            while (j <= n && a[j] >= i) right++, j++;
            //cout << i << endl;
            if (up % 2 == 0 && right % 2 == 0)
            {
                cout << "Second";
            }
            else
            {
                cout << "First";
            }
        }
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 640
#include<stdio.h>
#define SENTINEL 1000000000
#define MAX 5000000

int  N,c=0,L[MAX/2+2], R[MAX/2+2];
void Merge(int A[],int left,int mid,int right){
   int i,j,k,n1,n2;
   n1 = mid - left;
   n2 = right - mid;

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

   L[n1] = SENTINEL;
   R[n2] = SENTINEL;
   i = 0;
   j = 0;
   for(k=left;k<right;k++){
     c++;
     if(L[i]<=R[j]){
       A[k]=L[i];
       i = i + 1;
     }
     else {
       A[k] = R[j];
       j = j + 1;
     }
   }
 }

void Mergesort(int A[],int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    Mergesort(A, left, mid);
  Mergesort(A, mid, right);
  Merge(A, left, mid, right);
  }
}

int main(){

  int i,A[MAX];

   scanf("%d",&N);
   for(i=0;i<N;i++){
    scanf("%d",&A[i]);

   }

   Mergesort(A,0,N);

   for(i=0;i<N;i++){
     if(i!=N-1)printf("%d ",A[i]);
     else printf("%d",A[i]);
   }
   printf("\n");
   printf("%d\n",c);
   return 0;
 }


Measured memory_bytes: 5716
w,h,x,y,r = gets.split(" ").map(&:to_i)
b = [x-r, y-r, w-x-r, h-y-r]
sum = 0
4.times do |i|
        sum += b[i].abs - b[i]
end
r = ["No", "Yes"]
puts r[sum ** -sum]

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

def count(s, c):
    for i in range(0, len(s)):
        idx = ord(s[i]) - ord('a')
        if idx < 30:
            c[idx] += 1

max = 0
for i in range(1, n):
    a = s[0:i]
    b = s[i:]
    ca = [0 for i in range(30)]
    cb = [0 for i in range(30)]
    count(a, ca)
    count(b, cb)

    t = 0
    for j in range(0, 26):
        if ca[j] > 0 and cb[j] > 0:
            t += 1
    if t > max:
        max = t
print(max)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int num = 0;
        int n = sc.nextInt();
        num = n/25;
        n%=25;
        num += n/10;
        n%=10;
        num += n/5;
        n%=5;
        num += n;
        System.out.println(num);
    }
}


Measured memory_bytes: 26400
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int MAXN=1e5+10;
int a[MAXN];
int main()
{
	int k,l,m,n,ans;

	scanf("%d",&n);
	ans=0;
	m=0;
	l=0;
	for (int i=1;i<=n;i++)
	{
		m++;	
		scanf("%d",&k);
		if (k!=l)
		{
			l=k;
			ans=ans+(m-1)/2;
			m=1;
		}
	} 
	ans=ans+m/2;

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


Measured memory_bytes: 256
N = gets.chomp.to_i
# A, P = gets.chomp.split.map(&:to_i)
# A = Array.new(N + 1, 0)  # 0 means no trap, 1 means existence of trap. 1-indexed

pairs = []
N.times do |i|
  s, p = gets.chomp.split
  pairs << [s, p.to_i, i]
end

pairs.sort_by { |(s, p, i)| [s, - p] }.each do |(s, p, i)| 
  p i + 1
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int>> dist(h, vector<int>(w, INF));
  queue<P> q;
  rep(i, h) rep(j, w) if (s[i][j] == '#') {
    q.emplace(i, j);
    dist[i][j] = 0;
  }
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    auto push = [&]{
      rep(i, 4) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (0 <= nx && nx < h && 0 <= ny && ny < w && dist[nx][ny] == INF) {
          dist[nx][ny] = dist[x][y] + 1;
          q.emplace(nx, ny);
        }
      }
    };
    push();
  }

  int ans = 0;
  rep(i, h)rep(j, w) {
    chmax(ans, dist[i][j]);
  }
  cout << ans << endl;

}

Measured memory_bytes: 13456
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String b = sc.next();
        if ("A".equals(b)) {
            System.out.println("T");
        } else if ("T".equals(b)) {
            System.out.println("A");
        } else if ("C".equals(b)) {
            System.out.println("G");
        } else {
            System.out.println("C");
        }
    }

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
typedef long long ll;
const int num = 1e3 + 5;

ll n,h,ans = INT_MAX;
ll f[N],v[N],w[N];


int main(){
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin>>h>>n;
  for(int i = 1;i <= n;i++){
    cin>>v[i]>>w[i];    
  }
  for(int i = 1;i <= 20000;i++) f[i] = INT_MAX;
  f[0] = 0;
  for(int i = 1;i <= n;i++){
    for(int j = v[i];j <= 20000;j++){
      
      f[j] = min(f[j],f[j-v[i]]+w[i]);
    }
  }
  ll maxx = f[h];
  for(int i = h;i <= 10000;i++){
    maxx = min(maxx,f[i]);
  }
  cout<<maxx<<endl;
  return 0;
}




Measured memory_bytes: 512
A,B,C,K=input().split()
res=0
cnt=0
if int(K)-int(A)<=0:
  		res=1*int(K)
else:
  		res=1*int(A)
cnt=int(K)-int(A)-int(B)
if cnt>0:
        res-=1*cnt
print(res)

Measured memory_bytes: 9076
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
typedef long long ll;
ll dp[100000];
char s[100001], t[100001];

int main(void){ 
	int n;
	cin >> n;
	cin >> s >> t;
	ll d[26];
	fill(d, d + 26, 0);
	d[s[0] - 'a']++;
	fill(dp, dp + n, 0);
	for(int i = 1; i < n; i++){
		int to = t[i] - 'a';
		dp[i] = (dp[i] + d[to]) % INF;
		int e = s[i] - 'a';
		d[e] = (d[e] + dp[i]) % INF;
 	}
/*	for(int i = 0; i < n; i++) cout << dp[i] << ' ';
	cout << endl;*/
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 4084