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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  a=a*n;
  if(a<b) cout<<a<<endl;
  else cout<<b<<endl;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	priority_queue<int> pq;
	rep(i, N) {
		cin >> A[i];
		pq.push(A[i]);
	}

	while (M--) {
		int i = pq.top();
		pq.pop();
		pq.push(i / 2);
	}

	int ans = 0;
	while (!pq.empty()) {
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());

  ll sum = 0;
  for (int i = K; i < N; ++i) {
    sum += H[i];
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    vector<int> a(3);
    cin >>a[0]>>a[1]>>a[2];
    int count =0;
    sort(a.begin(),a.end());
    if(a[0]%2==a[1]%2){//真ん中と小さい数の偶奇が一致
        count += a[2]-a[1];
        a[0] += count;
        count += (a[2]-a[0])/2;
    }
    else{
        count++;
        a[1]++,a[2]++;
        //後は同じ  
        count += a[2]-a[1];
        a[0] += count-1;
        count += (a[2]-a[0])/2;
    }
    cout <<count<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    string a, b;
    cin >> a >> b;
    if(a==b){
        cout << "H" << endl;
    }else{
        cout << "D" << endl;
    }
    return 0;
}

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

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

int main() {
	int a, b;
	cin >> a >> b;
	cout << (LL) a * b / gcd(a, b) << '\n';
	return 0;
}


Measured memory_bytes: 3608
n = int(input())
a = list(map(int,input().split()))

k = 0
for t in a:
  if t < 0:
    k += 1
k = k%2

b = [abs(t) for t in a]
b.sort(reverse = 1)
#print(b)
print(sum(b)-2*k*b[-1])

Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 1;
vector<int> adj[maxN];
int indegree[maxN], startTime[maxN], dp[maxN], endTime[maxN];
bitset<maxN> visited;
int dfs(int u, int timing){
    if(visited[u]){
        return endTime[u];
    }
    startTime[u] = timing;
    visited[u] = true;
    int k = 0;
    for(auto v : adj[u])
        k = max(k, dfs(v, timing + 1) + 1);
    dp[u] = startTime[u] + k;
    endTime[u] = k;
    return k;
}
int main( ){
    int n, m, x, y;
    scanf("%d %d", &n, &m);
    while(m--){
        cin >> x >> y;
        adj[x].emplace_back(y);
        indegree[y]++;
    }
    for(int i = 1; i <= n; i++){
        if(indegree[i] == 0 && !visited[i]){
            dfs(i, 0);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, dp[i]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 17096
#include <iostream>
#include <vector>
using namespace std;
#define cpy(a,b) tront[a-1] = temp[b-1]

class dice {
public:
	int tront[6];
	int flag;

	dice() {
		flag = 0;
	}
	void ini() {
		for (int i = 0; i < 6; i++) {
			cin >> tront[i];
		}
	}

	void rotation(char c) {
		int temp[6], i;
		for (i = 0; i < 6; i++)
			temp[i] = tront[i];
		switch (c) {
		case 'E':
			cpy(1, 4);
			cpy(4, 6);
			cpy(6, 3);
			cpy(3, 1);
			break;
		case 'N':
			cpy(5, 1);
			cpy(1, 2);
			cpy(2, 6);
			cpy(6, 5);
			break;
		case 'S':
			cpy(2, 1);
			cpy(1, 5);
			cpy(5, 6);
			cpy(6, 2);
			break;
		case 'W':
			cpy(1, 3);
			cpy(3, 6);
			cpy(6, 4);
			cpy(4, 1);
			break;
		}
	}

	void check(dice d1) {
		for (int j = 0; j < 6; j++) {
			if (d1.tront[j] != tront[j])
				return;
		}
		flag = 1;
	}
};
int main() {
	int i, j, k, q, l, m;
	cin >> q;
	vector<dice> d(q);
	for (i = 0; i < q; i++) {
		d[i].ini();
		for (j = 0; j < 2; j++) {
			d[i].rotation('N');
			d[i].rotation('E');
			d[i].rotation('S');
			for (k = 0; k < 4; k++) {
				d[i].rotation('N');
				for (l = 0; l < 4; l++) {
					d[i].rotation('E');
					for (m = 0; m < q; m++) {
						if (i != m)
							d[i].check(d[m]);
					}
				}
			}
		}
	}
	for (i = 0; i < q && !d[i].flag; i++);
	if (i == q)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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 mod= 1e9 + 7;


int main(){
  int n;
  cin >>n;
  cout << n/3 << endl;
}

Measured memory_bytes: 3688
def cal(s)
  num = 0
  s.each do |i|
    num += i.count { |j| j == '#' }
  end
  num
end

h, w, k = gets.split.map(&:to_i)
C = []
num = 0
h.times do
  x = gets.chomp.split('')
  num += x.count { |a| a == '#' }
  C << x
end
ans = 0
(0..h - 1).each do |i|
  (0..w - 1).each do |j|
    sel_h = [*1..h].combination(i).to_a
    sel_w = [*1..w].combination(j).to_a
    sel_h.each do |x|
      z = C.dup
      x.each do |row|
        z[row-1] = Array.new(w,'r')
      end
      sel_w.each do |y|
        v = z.dup.transpose
        y.each do |row|
          v[row-1] = Array.new(h,'r')
        end
        ans += 1 if cal(v) == k
      end
    end
  end
end
puts ans

Measured memory_bytes: 14436
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c, x, count = 0;
  cin >> a >> b >> c >> x;
  for (int i = 0; i < a+1; i++)
  {
    for (int j = 0; j < b+1; j++)
    {
      for (int k = 0; k < c+1; k++) 
        if(500*i + 100*j + 50*k == x) count++; 
    }
  }
  cout << count << endl;
  return 0;
}

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,ans;
string s;

signed main() {
    cin >> n >> s;
    rep(i,n-2) {
       if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}






Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;

pair<string,string> subtree(string tree){
	int i,r=0;
	for(i=1;i<tree.size();i++){
		if(tree[i]=='(')r++;
		else if(tree[i]==')')r--;
		if(!r)break;
	}
	return make_pair(tree.substr(1,i),tree.substr(i+2,tree.size()-3-i));
}
string form(string tree){
	if(tree=="x"){
		return tree;
	}
	pair<string,string> sub = subtree(tree);
	sub.first = form(sub.first);
	sub.second = form(sub.second);
	if(sub.first<=sub.second)tree = '('+sub.first+' '+sub.second+')';
	else tree = '('+sub.second+' '+sub.first+')';
	return tree;
}

struct Rational{
	int x,y;
	Rational(){}
	Rational(int x,int y):x(x),y(y){}
	bool operator < (const Rational a)const{return x*a.y < a.x*y;}
	bool operator > (const Rational a)const{return x*a.y > a.x*y;}
};
map<string,Rational> mp;//木の左右類似度

set<string> f(string tree){
	set<string> s;
	
	if(tree=="x"){
		s.insert("x");
		mp[tree]= Rational(0,1);
		return s;
	}
	pair<string,string> sub = subtree(tree);
	set<string> a=f(sub.first), b=f(sub.second);
	set<string>::iterator i,j;
	int count=0;
	i=a.begin();j=b.begin();
	while(i!=a.end()&&j!=b.end()){
		if(*i==*j){
			++i;++j;
			count++;
		}else if(*i<*j){
			++i;
		}else{
			++j;
		}
	}
	//mp[tree] = (double)count/(a.size()+b.size()-count);
	mp[tree] = Rational(count,a.size()+b.size()-count);
	a.insert(form(tree));
	a.insert(b.begin(),b.end());
	return a;
}
Rational calc(string tree){
	if(mp.find(tree)!=mp.end())return mp[tree];
	f(tree);
	return mp[tree];
}
int comp(string a,string b){
	if(a=="x"&&b=="x")return 0;
	if(calc(a)>calc(b))return -1;
	if(calc(a)<calc(b))return 1;
	pair<string,string> left=subtree(a), right=subtree(b);
	int c=-1;
	c = comp(left.first,left.second);
	if(c==-1)swap(left.first,left.second);
	c = comp(right.first,right.second);
	if(c==-1)swap(right.first,right.second);

	c = comp(left.first,right.first);
	if(c)return c;
	return comp(left.second,right.second); 
}
string solve(string tree,int flag){
	if(tree=="x"){
		return tree;
	}
	pair<string,string> sub = subtree(tree);
	int c = comp(sub.first,sub.second);
	if(c==flag)swap(sub.first,sub.second);
	sub.first = solve(sub.first,-1);
	sub.second = solve(sub.second,1);
	return '('+sub.first+' '+sub.second+')';
}
int main(){
	string s;
	while(getline(cin,s),s[0]!='0'){
		//mp.clear();
		cout<<solve(s,-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1448
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <algorithm>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const int E = numeric_limits<int>::min();

int main(void)
{
    int N, D;
    cin >> N >> D;
    LL DD = (LL)D * D;
    int X, Y, count=0;
    rep(i, N){
        cin >> X >> Y;
        if (((LL)X*X+(LL)Y*Y) <= DD){
            count++;
        }
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 3724
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ANextAlphabet {
public:
    void solve(std::istream& in, std::ostream& out) {
        char C;
        in >> C;
        out << (char)(C + 1) << "\n";
    }
};


signed main() {
    ANextAlphabet solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	string S;
	cin >> S;
	if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3])cout << "Bad" << endl;
	else cout << "Good" << endl;

	return 0;
}

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

using namespace std;

typedef pair<int, int> pii;

int N, M;
int sum;
vector<pii> pvec;

void solve() {
	sort(pvec.begin(), pvec.end(), greater<pii>());
	
	for (int i = 0; i < N; i++) {
		pii p = pvec[i];
		
		if (p.second <= M) {
			M -= p.second;
			sum -= p.first * p.second;
		} else {
			sum -= p.first * M;
			break;
		}
	}
	
	cout << sum << endl;
}

int main() {
	while (1) {
		cin >> N >> M; if (N == 0 && M == 0) break;
		
		pvec.clear();
		sum = 0;
		for (int i = 0; i < N; i++) {
			int D, P; cin >> D >> P;
			sum += D * P;
			pvec.push_back(make_pair(P, D));
		}
		
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1328
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define memo(a,val) memset(a,val,sizeof(a))
#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 1010;
char mat[mxn][mxn];
priority_queue<pair<int,ii>,vector<pair<int,ii>>,greater<pair<int,ii>>>q;
int dist[mxn][mxn];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};

int32_t main(){
	NINJA;

	int n,m; cin >> n >> m;

	for1(i,n){
		for1(j,m){
			dist[i][j] = inf;
		}
	}

	int sx,sy,ex,ey;
	cin >> sx >> sy >> ex >> ey;

	for1(i,n) for1(j,m) cin >> mat[i][j];

	dist[sx][sy] = 0;
	q.push({0,{sx,sy}});

	while(!q.empty()){
		int c = q.top().first;
		int x,y;
		tie(x,y) = q.top().second;
		q.pop();

		fo(i,4){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx<1||ny<1||nx>n||ny>m||mat[nx][ny]=='#') continue;
			if(dist[nx][ny]>dist[x][y]){
				dist[nx][ny] = dist[x][y];
				q.push({c,{nx,ny}});
			}
		}
		for(int i=-2;i<=2;i++){
			for(int j=-2;j<=2;j++){
				int nx = x + i;
				int ny = y + j;
				if(nx<1||ny<1||nx>n||ny>m||mat[nx][ny]=='#') continue;
				if(dist[nx][ny]>dist[x][y]+1){
					dist[nx][ny] = dist[x][y]+1;
					q.push({c+1,{nx,ny}});
				}
			}
		}
	}

	

	int ans = dist[ex][ey];
	if(ans==inf) cout << -1 << endl;
	else cout << dist[ex][ey] << endl;
	
	return 0;
}

Measured memory_bytes: 12572
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
  	cin>>n;
  	long long int a[n];
  for(long long int i=0;i<n;i++){
  	cin>>a[i];	
  }
  long long int dp[n];
  dp[0]=0;
  dp[1]=abs(a[0]-a[1]);
  for(long long int i=2;i<n;i++){
  	dp[i]=min(abs(a[i-1]-a[i])+dp[i-1],abs(a[i-2]-a[i])+dp[i-2]);
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1792
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
pre_S = S
T = input()
s = len(S)
t = len(T)
key = []
for i in range(len(S)-len(T)+1):
    # print(S[i:i+t])
    same = 0
    for j, y in enumerate(S[i:i+t]):
        if y == "?":
            same += 1
            continue
        else:
            if y == T[j]:
                same += 1
    if same == t:
        # print(S[i:i+t])
        key.append(i)
    # print(y)
# l = list(S)
if key:
    ans = "z" * 60
    for i in key:
        S_ = S[:i] + T + S[i+t:]
        tmp = ""
        for i in range(len(S_)):
            if S_[i] == "?":
                tmp += "a"
            else:
                tmp += S_[i]
        ans = min(ans, tmp)
    print(ans)
else:
    print("UNRESTORABLE")



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

int main()
{
    int a[5];
    for(int i=0;i<3;i++)
        cin>>a[i];
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)
        cout<<"YES";
    else cout<<"NO";
  return 0;
}


Measured memory_bytes: 256
# 選択ソート(最小のものを先頭に追加していくイメージ。)

input = []
while (n = gets.to_i) != 0 do
  input = gets.split.map(&:to_i)
end
n = input.size
count = 0

for i in 0..n-1 do
  min_j = i
  for j in i..n-1 do
    min_j = j if input[j] < input[min_j]
  end
  if input[min_j] != input[i]
    tmp = input[min_j]
    input[min_j] = input[i]
    input[i] = tmp
    count += 1
  end
end

puts input*" "
puts count


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


ll cal(ll r,ll c){
  ll L=0,R=1e15,m;
  while(L<R){
    m=(L+R)/2;
    if(r*m/100<c)L=m+1;
    else R=m;
  }
  return L;
}

int main(){
  ll m,rd,rr,cd,cr;
  cin>>m>>rd>>rr>>cd>>cr;
  m-=cal(rd,cd)+cal(rr,cr);
  if(m<0)m=-1;
  cout<<m<<endl;
  return 0;
}



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

using namespace std;

const int N = 1000100;
const int md = (int) 1e9 + 7;

inline void add(int &x, int y) {
  x += y;
  if (x >= md) x -= md;
}

inline void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += md;
}

inline int mul(int x, int y) {
  return 1ll * x * y % md;
}

inline int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1) res = mul(res, x);
    x = mul(x, x);
    y >>= 1;
  }
  return res;
}

inline int inverse(int x) {
  return power(x, md - 2);
}

int fac[N], ifac[N];

void precalc() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = mul(fac[i - 1], i);
  }
  ifac[N - 1] = inverse(fac[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    ifac[i] = mul(ifac[i + 1], i + 1);
  }
}

int C(int n, int k) {
  if (k < 0 || k > n) return 0;
  return mul(fac[n], mul(ifac[k], ifac[n - k]));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  precalc();
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1 << '\n';
    return 0;
  }
  vector<int> g(n);
  int res = 0;
  for (int i = 1; i < n; i++) {
    g[i] = mul(C(i - 1, n - 1 - i), mul(fac[i], fac[n - 1 - i]));
    sub(g[i], g[i - 1]);
    add(res, mul(i, g[i]));
    add(g[i], g[i - 1]);
  }
  cout << res << '\n';
  return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)

ll N;
ll x,y,z;
ll ans;
string s[10005];

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

rep(i,N) cin>>s[i];

rep(i,N){
	rep1(j,s[i].size()){
		if(s[i][j-1]=='A'&&s[i][j]=='B') ans++;
	}
}

rep(i,N){
	ll n=s[i].size();
	if(s[i][0]=='B'&&s[i][n-1]!='A') x++;
	if(s[i][0]=='B'&&s[i][n-1]=='A') z++;
	if(s[i][0]!='B'&&s[i][n-1]=='A') y++;
}

if(x>=y){
	ans+=y+z;
	if(y==0&&x==0&&z>0) ans--;
}else{
	ans+=x+z;
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 768
import java.util.*;

public class Main {
	static Scanner scanner = new Scanner(System.in);

	public static void main(String[]$) {
		int n = scanner.nextInt();
		long c = scanner.nextLong();
		long[][] a = new long[n][2];
		long[] a1 = new long[n];
		long[] a2 = new long[n];
		long[] b1 = new long[n];
		long[] b2 = new long[n];
		long sum = 0;
		for (int i = 0; i < n; i++) {
			long x = scanner.nextLong();
			sum += a[i][1] = scanner.nextInt();
			a1[i] = sum - x * 2;
			a2[i] = sum - x;
			if (i > 0) {
				a2[i] = Math.max(a2[i], a2[i - 1]);
			}
			a[i][0] = c - x;
		}
		sum = 0;
		for (int i = n - 1; i >= 0; i--) {
			sum += a[i][1];
			b1[i] = sum - a[i][0] * 2;
			b2[i] = sum - a[i][0];
			if (i < n - 1) {
				b2[i] = Math.max(b2[i], b2[i + 1]);
			}
		}
		long ans = Math.max(0, Math.max(a2[0], b2[0]));
		for (int i = 1; i < n; i++) {
			ans = Math.max(ans, Math.max(Math.max(a1[i - 1] + b2[i], b1[i] + a2[i - 1]), Math.max(a2[i], b2[i])));
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 98828
def main():
    s = input()
    s1 = s[:int((len(s)-1)/2)]
    s2 = s[int((len(s)+3)/2-1):]
    rs = s[::-1]
    rs1 = s1[::-1]
    rs2 = s2[::-1]


    if s1 == rs1 and s2 == rs2 and s == rs:
        print("Yes")
    else:
        print("No")
    
    return
    
main()


Measured memory_bytes: 8888
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

int pedras[100100];
int dp[100100]; ///Guardo os valores da funcao frog;

int n,k;
const int inf =1e9;

int main(){

    memset(dp,1000000,sizeof(dp));
    cin >>n>>k;

    for(int i=0;i<n;i++){
        cin >> pedras[i];
    }
    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n){
                dp[i+j]=min(dp[i+j],dp[i]+abs(pedras[i]-pedras[i+j]));
            }
        }
    }

    cout<<dp[n-1];
}

Measured memory_bytes: 4368
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e9 + 7);

const ll tam = 100010;

vector<ll> G[tam];
ll val[tam];
bool vis[tam];

ll sum;
void dfs(ll v)
{
	//cout << "(" << v << "," << val[v] << ") ";
	sum += (val[v] + 26);
	sum %= 26;
	vis[v] = true;
	for (ll u : G[v])
	{
		if ( vis[u] ) continue;
		dfs(u);
	}
}

ii E[tam];

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    string s;
    cin >> s;
    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
    	cin >> E[i].F >> E[i].S;
    }
    if (s.size() == 1)
    {
    	cout << "YES" << '\n';
    	return 0;
    }
    s = "a" + s + "a";

    //cout << s << endl;
	for (ll i = 0; i < s.size()-1; i++)
    {
    	val[i] = (s[i+1] - s[i] + 26) % 26;
    	//cout << "(" << val[i] << "[" << i << "," << i+1 << "]) ";
    }
    //cout << endl;

    for (ll i = 0; i < n; i++)
    {
    	//val[ E[i].F-1 ] = (val[ E[i].F-1 ] + 1) % 26;
    	//val[ E[i].S ] = (val[ E[i].S ] - 1 + 26) % 26;
    	G[E[i].F-1].pb( E[i].S );
    	G[ E[i].S ].pb(E[i].F-1);
    }
    /*
    for (ll i = 0; i < s.size()-1; i++)
    {
    	cout << "(" << val[i] << "[" << i << "," << i+1 << "]) ";
    }
    cout << endl;
    */
    for (ll i = 0; i < s.size()-1; i++)
    {
    	G[i].pb( s.size()-2-i );
    }
    clr(vis, false);
    bool poss = true;
    for (ll i = 0; i < s.size()-1; i++)
    {
    	if (vis[i]) continue;
    	//cout << "component: " << endl;
    	sum = 0;
    	dfs(i);
    	//cout << endl << "===============" << endl;
    	if (sum != 0) poss = 0;
    }
    if (poss) cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}
// PLUS ULTRA!

Measured memory_bytes: 11500
N=int(input())
A_list=list(map(int,input().split()))
A_list_sorted=sorted(A_list)


flag = True
for i in range(N-1):
    target = A_list_sorted[i]

    if target == A_list_sorted[i+1]:
        flag = False
        break

if flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 26808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;
void add(ll &a, ll b)
{
    a = (a + b) % MOD;
}
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> field[i][j];
        }
    }
    vector<vector<ll>> dp(h+1, vector<ll>(w+1, 0));
    dp[1][1] = 1;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(field[i][j] == '#')
            {
                dp[i+1][j+1] = 0;
                continue;
            }
            add(dp[i+1][j+1], dp[i][j+1]);
            add(dp[i+1][j+1], dp[i+1][j]);
            add(dp[i+1][j+1], MOD);
        }
    }
    cout << dp[h][w] << endl;
}



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

#define rep(i, n) for(int 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;

vector<pair<ll, ll>> primes;
vector<int> cnt;
ll ans = 1LL << 60;

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            num++;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));

    return res;
}

ll f(ll n) {
    ll cnt = 1;
    while (n / 10) {
        cnt++;
        n /= 10;
    }
    return cnt;
}

void rec(int i) {
    if (i == primes.size()) {
        ll num1 = 1;
        ll num2 = 1;
        rep(i, cnt.size()) {
            rep(j, cnt[i]) num1 *= primes[i].first;
            rep(j, primes[i].second - cnt[i]) num2 *= primes[i].first;
        }
        chmin(ans, f(max(num1, num2)));
        return;
    }

    rep(j, primes[i].second + 1) {
        cnt[i] = j;
        rec(i + 1);
    }
}

int main() {
    ll N;
    cin >> N;
    primes = prime_factorize(N);
    cnt.resize(primes.size());
    rec(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int num[110];

int selectionsort(int num[],int n){

  int i,j,min,tmp,count=0;

  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(num[j]<num[min]){
        min=j;
      }
    }
    tmp=num[i];
    num[i]=num[min];
    num[min]=tmp;
    if(min!=i) count++;
  }
  return count;
}

int main(){

  int n,i,ans;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
  }
  ans=selectionsort(num,n);
  for(i=0;i<n-1;i++) printf("%d ",num[i]);
  printf("%d\n%d\n",num[n-1],ans);
  return 0;
}


Measured memory_bytes: 600
a = int(input())
b = int(a/10)
a -= b*10
if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print("hon")
elif a == 0 or a == 1 or a == 6 or a == 8:
    print("pon")
elif a == 3:
    print("bon")


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

int a[12345];
int grid[123][123];

int main() {
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int c = 1;
	for (int i = 0; i < h; ++i) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; ++j) {
				grid[i][j] = c;
				--a[c];
				if (a[c] == 0) {
					++c;
				}
			}
		} else {
			for (int j = w - 1; j >= 0; --j) {
				grid[i][j] = c;
				--a[c];
				if (a[c] == 0) {
					++c;
				}
			}
		}
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cout << grid[i][j] << ' ';
		}
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 384
# https://twitter.com/tempura_cpp/status/1259483252919635969

n, k = gets.to_s.split.map{|e|e.to_i}
a = [0] + gets.to_s.split.map{|e|e.to_i}

c = 1

while k > 0
  
  c = a[c] if k & 1 > 0
  
  na = Array.new(n+1)
  
  (n+1).times{ |i| na[i] = a[a[i]] }
  
  a.clear
  a = na
  k >>= 1
end

puts c

Measured memory_bytes: 30504
#include <iostream>

using namespace std;
typedef long long ll;

ll memo[40];

ll calc(int n){
    if(memo[n] != -1) return memo[n];
    ll retval = 0;
    for(int i=1;i<=3;i++){
        retval += calc(n-i);
    }
    return memo[n] = retval;
}

int main(){
    for(int i=0;i<40;i++){
        memo[i] = -1;
    }
    memo[1] = 1;
    memo[2] = 2;
    memo[3] = 4;
    calc(30);

    int n;
    while(cin>>n && n != 0){
        cout << calc(n) / 3650 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n,x,y;
   cin>>n>>x>>y;

   x--;
   y--;

   vector<vector<long int>> distance(n,vector<long int>(n));

   for(long int i = 0; i < n; i++)
   	 for(long int j = 0; j < n; j++)
   	 	 distance[i][j] = llabs(i - j);

   distance[x][y] = 1;
   distance[y][x] = 1;

   for(long int i = 0; i < n; i++){
   	for(long int j = 0; j < n; j++){
   		distance[i][j] = min(distance[i][j], distance[i][x] + distance[y][j] + 1);
   		distance[i][j] = min(distance[i][j], distance[i][y] + distance[x][j] + 1);
   	}
   }

   vector<long int> count(n - 1);

   for(long int i = 0; i < n; i++){
   	for(long int j = i + 1; j < n; j++){
   		 count[distance[i][j] - 1]++;
   	}
   }

   for(auto ele : count)
   	cout<<ele<<endl;

   return 0;
}

Measured memory_bytes: 31616
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

int main()
{
    std::string s;
    int cnt = 0;
    std::cin >> s;

    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'o')
            cnt++;
    }

    if (cnt >= 8 || 15 - s.length() + cnt >= 8)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> nums=new ArrayList<Integer>(N);
		for(int i=0;i<N;i++) {
			nums.add(Integer.parseInt(sc.next()));
		}
		int ans=0;
		while(true)
		{
			
			int max=Collections.max(nums);
			if(max==0) {
				break;
			}
			int index=nums.indexOf(max);
			while(true) {
				nums.set(index, max-1);
				if(index==N-1) {
					break;
				}else if(nums.get(index)==nums.get(index+1)-1) {
					index+=1;
				}else {
					break;
				}
			}
			ans++;
			
		}
		System.out.println(ans);
	}
	
}

class FastScanner {
	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() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		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 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();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 21204
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<string,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
bool pairCompare2(P firstElof,P secondElof){
    return (firstElof.second)%1000>(secondElof.second)%1000;
}
bool less_mod1000(int lhs, int rhs) {
  if ((lhs - rhs) % 1000 != 0)
    return lhs % 1000 < rhs % 1000;
  else // 5で割った余りが等しいなら普通に大小比較する
    return lhs < rhs;
}
string A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string a="abcdefghijklmnopqrstuvwxyz";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll p,q,r;cin>>p>>q>>r;
    cout<<p+q+r-max(p,max(q,r))<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

int main() {
  int k, mod = 7, cnt = 1;
  cin >> k;
  rep(i, k) {
    if (mod % k == 0) break;
    cnt++;
    mod = (mod * 10 + 7) % k;
  }
  if (mod % k == 0)
    cout << cnt << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int d[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){ 
  int k;
  cin >> k;
  k--;
  cout << d[k] << endl;
  return 0;
} 

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

const long long INF = 1000000000000000000LL;

int main()
{
#ifdef LOCAL_JUDGE
    freopen("A.in", "r", stdin);
#endif
    int n_, cost[4];
    while (scanf("%d%d%d%d%d", cost, cost + 1, cost + 2, cost + 3, &n_) == 5) {
        long long n = n_ * 4LL;
        long long result = INF;
        long long dp[8];
        for (int i = 0; i < 8; ++ i) {
            dp[i] = INF;
        }
        dp[0] = 0;
        for (int i = 0; i < 4; ++ i) {
            for (int j = 1 << i; j < 8; ++ j) {
                dp[j] = std::min(dp[j], dp[j - (1 << i)] + cost[i]);
            }
        }
        for (int i = 0; i < 4; ++ i) {
            result = std::min(result, dp[n % (1 << i)] + (n / (1 << i)) * cost[i]);
        }
        printf("%lld\n", result);
    }
}

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

int main() {
	int n,m;
	cin >> n >> m;
	vector <int> v(n);
	rep(i,m){
		int a,b;
		cin >> a >> b;
		v[a-1]++;
		v[b-1]++;
	}
	rep(i,n){
		cout << v[i] << endl;
	}
}


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

int main(){
    int a[127]={};
    char s[27];
	cin >> s;
	int l=1;
	for(int i=0;s[i]!='\0';i++)	a[s[i]]=1,l++;
	for(int c='z';c>='a';c--)
		if(!a[c]) s[l++]=c;
	cout << ((next_permutation(s,s+l)) ? s : "-1") << endl;
}

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

/* constant */

#define MAX_P   (46000)
#define MAX_LEN (100000)

/* global variables */

static long long invs[MAX_P];

static char buffer[MAX_LEN + 16];
static int bpt = 0;

static long long pn = 0;

/* subroutines */

long long expression();
long long term();
long long factor();

long long get_inv(long long k) {
  long long m, n;

  m = 1;
  n = pn - 2;

  while (n > 0) {
    if (n & 1) m = (m * k) % pn;
    k = (k * k) % pn;
    n >>= 1;
  }

  return m;
}


long long expression() {
  long long ret, n1;

  ret = term();
  if (ret < 0) return -1;

  for (;;) {
    switch (buffer[bpt]) {
    case '+':
      bpt++;
      n1 = term();
      if (n1 < 0) return -1;

      ret = (ret + n1) % pn;
      break;
    case '-':
      bpt++;
      n1 = term();
      if (n1 < 0) return -1;

      ret = (ret + pn - n1) % pn;
      break;
    default:
      return ret;
    }
  }
}

long long term() {
  long long ret, n1;

  ret = factor();
  if (ret < 0) return -1;

  for (;;) {
    switch (buffer[bpt]) {
    case '*':
      bpt++;
      n1 = factor();
      if (n1 < 0) return -1;

      ret = (ret * n1) % pn;
      break;
    case '/':
      bpt++;
      n1 = factor();
      if (n1 <= 0) return -1;

      ret = (ret * get_inv(n1)) % pn;
      break;
    default:
      return ret;
    }
  }
}

long long factor() {
  long long ret, k;

  if (buffer[bpt] == '(') {
    bpt++;
    ret = expression();
    if (buffer[bpt] != ')') return -1;
    bpt++;
    return ret;
  }

  if (buffer[bpt] == '-') {
    bpt++;
    ret = expression();
    ret %= pn;
    return (pn - ret) % pn;
  }

  ret = 0;
  k = buffer[bpt];
  while (k >= '0' && k <= '9') {
    ret = ret * 10 + (k - '0');
    k = buffer[++bpt];
  }

  return ret;
}

/* main */

int main(int argc, char **argv) {
  int i;
  long long ans;
  char *spt;
  static char line[MAX_LEN + 16];

  for (;;) {
    gets(line);
    if (strcmp(line, "0:") == 0) break;

    for (spt = line; *spt != ':'; spt++);
    *spt = '\0';

    pn = atoi(line);

    for (i = 0, spt++; *spt != '\0'; spt++)
      if (*spt != ' ') buffer[i++] = *spt;
    buffer[i] = '\0';

    bpt = 0;

    ans = expression();

    if (ans < 0)
      puts("NG");
    else
      printf("%s = %lld (mod %lld)\n", buffer, ans, pn);
  }

  return 0;
}

Measured memory_bytes: 680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//マンハッタン距離計算
ll calc(ll x0, ll y0, ll x1, ll y1) {
  return abs(x0 - x1) + abs(y0 - y1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  //inputs
  int n;
  ll m, w, t;
  cin >> n >> m >> w >> t;
  map<string, ll> s;
  vector<ll> v(m), p(m);
  rep(i, m) {
    string si;
    cin >> si >> v[i] >> p[i];
    s[si] = i;
  }
  vector<ll> l(n), x(n), y(n);
  vector<vector<ll>> r(n), q(n);
  rep(i, n) {
    cin >> l[i] >> x[i] >> y[i];
    rep(j, l[i]) {
      string rij;
      ll qij;
      cin >> rij >> qij;
      r[i].push_back(s[rij]);
      q[i].push_back(qij);
    }
  }

  //preprocessing, qijを転売することで得られる利益に変換、負数になる場合は便宜上0にする。
  rep(i, n) {
    rep(j, l[i]) {
      q[i][j] = p[r[i][j]] - q[i][j];
      chmax(q[i][j], 0LL);
      //cout << q[i][j] << '\n';
    }
  }
  //立ち寄る街を決め打ちした際の最小移動距離, 最大利益
  vector<ll> dist((1 << n), INF), maxv((1 << n), 0);
  //bitが立っていたら寄る、そうでなければよらないで全探索
  FOR(i, 1, (1 << n)) {
    //街の集合
    vector<int> vs;
    //商品の{重さ、利益}
    vector<pair<ll, ll>> product(m);
    rep(j, m) product[j] = {v[j], 0};
    //訪れた街で商品を買った場合の利益を更新
    rep(j, n) {
      if (i >> j & 1) {
        vs.push_back(j);
        rep(k, l[j]) {
          chmax(product[r[j][k]].second, q[j][k]);
        }
      }
    }
    int vsn = vs.size();
    //ナップザック問題1:重さwの制限で利益を最大化
    vector<ll> dp(w + 1, 0);
    rep(j, m) {
      rep(k, w + 1 - product[j].first) {
        chmax(dp[k + product[j].first], dp[k] + product[j].second);
      }
    }
    maxv[i] = dp[w];
    //cout << maxv[i] << '\n';
    //最小距離を計算、全探索
    while (1) {
      ll resdist = calc(0, 0, x[vs[0]], y[vs[0]]) + calc(0, 0, x[vs[vsn - 1]], y[vs[vsn - 1]]);
      rep(i, vsn - 1) resdist += calc(x[vs[i]], y[vs[i]], x[vs[i + 1]], y[vs[i + 1]]);
      chmin(dist[i], resdist);
      if (!next_permutation(vs.begin(), vs.end())) break;
    }
    //cout << dist[i] << '\n';
  }
  //ナップザック問題２:時間tの制限で利益を最大化
  vector<ll> dp(t + 1, 0);
  FOR(i, 1, (1 << n)) {
    rep(j, t + 1 - dist[i]) {
      chmax(dp[j + dist[i]], dp[j] + maxv[i]);
    }
  }
  //output
  cout << dp[t] << '\n';



  







  
  return 0;
}


Measured memory_bytes: 3308
# coding: utf-8
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

R,G,B,N = map(int, input().split())

if R<G: R,G=G,R
if G<B: G,B=B,G
if R<G: R,G=G,R

r=g=b=0
ans=0

#p(N//R+2)
#p(N//G+2)
#X=[]
#p(r,g,b)

for r in range(N//R+2):
	if (R*r)>N: break

	for g in range(N//G+2):
		if (R*r)+(G*g)>N:
			break
			X.append("break")
		
		b = (N-(R*r)-(G*g))//B
		n = (R*r)+(G*g)+(B*b)
		if n==N:
			ans+=1
#			X.append([r,g,b])
#		p(r,g,b,n,N,ans)

print(ans)
#p(X)


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

typedef long long int ll;
ll n, m, q, a, b, c, d;
vector<pair<pair<ll, ll>, pair<ll, ll>>> v;

int main() {
    cin >> n >> m >> q;
    for(ll i = 0; i < q; ++i) {
        cin >> a >> b >> c >> d;
        v.push_back(make_pair(make_pair(a, b), make_pair(c, d)));
    }

    queue<vector<ll>> q;
    q.push({1});

    ll res = 0;
    while(!q.empty()) {
        vector<ll> f = q.front();
        q.pop();
        //for(ll i = 0; i < f.size(); ++i) cout << f[i] << ' ';
        //cout << endl;

        if(f.size() == n) {
            ll cnt = 0;
            for(ll i = 0; i < v.size(); ++i) {
                if(f[v[i].first.second - 1] - f[v[i].first.first - 1] == v[i].second.first) cnt += v[i].second.second;
            }

            res = max(res, cnt);
        } else {
            for(ll i = f[f.size() - 1]; i <= m; ++i) {
                vector<ll> g(f);
                g.push_back(i);
                q.push(g);
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 9292