akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 19999999999999;

long long int N,M,a,d,n,cou=0;

bool sosu(long long int p){
    if(p==1){return false;}
    else if(p==2){return true;}
    for(long long int i =2;i*i<=p;i++){
        if(p%i==0){return false;}
    }
    return true;
}

int main()
{
    cout << fixed << setprecision(18);
    cin>>a>>d>>n;
    while(a!=0){
        cou=0;
        while(n!=cou){
            if(sosu(a)){cou++;}
            a+=d;
        }
        cout<<a-d<<endl;
        cin>>a>>d>>n;
        
    }
}




Measured memory_bytes: 3080
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace::std;

int main()
{
	int N, M;
  	cin >> N >> M;
	int child_count[100005];
  	vector<int> edges[100005];
  	int new_num[100005];
  	
  	for(int i = 0; i < N-1+M; i++){
      	int a, b;
      	cin >> a >> b;
      	a--;
        b--;
    	child_count[a]++;
    	edges[b].push_back(a);
    }
  	int num = 0;
  	queue<int> que;
  	for(int i = 0; i < N; i++){
    	if(child_count[i] == 0)
          que.push(i);
    }
  
  	while(!que.empty()){
    	int v = que.front();
      	que.pop();
      	new_num[v] = num++;
        for(int j = 0; j < edges[v].size(); j++){
            int to = edges[v][j];
            child_count[to]--;
            if(child_count[to] == 0)
              que.push(to);
        }   
    }
  	for(int i = 0; i < N; i++){
        int min = 100005;
        int par = -1;
        for(int j = 0; j < edges[i].size(); j++){
            if(min > new_num[edges[i][j]]){
                min = new_num[edges[i][j]];
                par = edges[i][j];
            }
        }
        cout << par+1 << endl;
    }
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
bool solve(ll len,ll sx,vector<ll>s,vector<ll>t){
  ll n=s.size();
  bool ret=true;
  ll l=-1,r=len;
  rrep(i,0,n){
    if(t[i]==1)l=max(-1LL,l-1);
    else if(t[i]==-1)r=min(len,r+1);
    if(s[i]==1)r=r-1;
    else if(s[i]==-1)l=l+1;
    if(r<=l+1)ret=false;
    //cout<<l spa r<<endl;
  }
  //cout<<endl;
  if(sx<=l||sx>=r)ret=false;
  return ret;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll h,w,n;cin>>h>>w>>n;
  ll sr,sc;cin>>sr>>sc;sr--;sc--;
  string s,t;cin>>s>>t;
  vector<ll>sx(n),tx(n),sy(n),ty(n);
  rep(i,0,n){
    if(s[i]=='R')sy[i]++;
    if(s[i]=='L')sy[i]--;
    if(s[i]=='U')sx[i]--;
    if(s[i]=='D')sx[i]++;
    if(t[i]=='R')ty[i]++;
    if(t[i]=='L')ty[i]--;
    if(t[i]=='U')tx[i]--;
    if(t[i]=='D')tx[i]++;
  }
  //debug(sx,n);debug(sy,n);debug(tx,n);debug(ty,n);
  ans2(solve(h,sr,sx,tx)&&solve(w,sc,sy,ty));
  return 0;
}

Measured memory_bytes: 13464
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    ll ret = 0;
    map<pii, ll> cnt;
    for (int i = 1; i < 10; ++i) {
        for (int j = 1; j < 10; ++j) {
            cnt[{i, j}] = 0;
        }
    }
    for (int i = 1; i <= n; ++i) {
        int l = i;
        while (l / 10 != 0)
            l /= 10;
        int r = i % 10;
        if (r != 0) {
            cnt[{l, r}]++;
        }
    }
    ll pp = 0;
    for (auto &p : cnt) {
        if (p.first.first == p.first.second) {
            pp += p.second * (p.second);
        } else {
            ret += p.second * cnt[{p.first.second, p.first.first}] * 2;
        }
    }
    ret /= 2;
    ret += pp;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool isp (int n) {
  if (n<2) return false;
  if (n==2 || n==3 || n==5) return true;
  if (n%2==0) return false;
  for (int i=3; i*i<=n; i+=2)
    if (n%i==0) return false;
  return true;
}
int main() {
  int x; cin>>x;
  while (!isp(x)) x++;
  cout<<x<<endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()

front_not_close = 0
end_not_close = 0

for s in list(S):
    if s == '(':
        front_not_close += 1
    else:
        if front_not_close > 0:
            front_not_close -= 1
        else:
            end_not_close += 1


for i in range(end_not_close):
    S = '(' + S

for i in range(front_not_close):
    S = S + ')'

print(S)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>

using namespace std;

int a[100001];

int main( void ) {

    
    int n,c,k;
    
    scanf("%d %d %d",&n,&c,&k);
    
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    sort(a,a+n);
    
    int start = 0;
    int ans = 0;
    
    for(int i=1;i<n;i++){
        int end = i;
        if(end-start+1 <= c && a[end]-a[start] <=k){
            continue;
        }else{
            start = i;
            ans++;
        }
    }
    printf("%d\n",ans+1);
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
//#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;



ll junk;
ll unchi;
ll junkind;

void dfs(vl &pitsu,vl &tel,ll now,ll cnt){
    if(pitsu[now] != -1){
        junk = cnt-pitsu[now];
        unchi = pitsu[now];
        junkind = now;
        return;
    }
    pitsu[now] = cnt;
    dfs(pitsu,tel,tel[now],cnt+1);
}

int main(void){
    ll n,k;
    cin>>n>>k;
    vl a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    vl pitsu(n,-1);
    dfs(pitsu,a,0,0);
    if(unchi >= k){
        ll now = 0;
        rep(i,k){
            now = a[now];
        }
        cout<<now+1<<endl;
    }
    else{
        k -= unchi;
        k %= junk;
        ll now = junkind;
        rep(i,k){
            now = a[now];
        }
        cout<<now+1<<endl;
    }
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;

int main(){
    ll n,k; cin >> n >> k;
    ll ans = n%k;
    cout << min(ans,k-ans) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
	int m1,d1,m2,d2;
	cin>>m1;
	int f=0;
	for(int i=m1;i>=1;i--)
	{
		double tmp=i*1.08;
		if(floor(tmp)==m1)
		{
			cout<<i<<endl;
			f=1;
			break;
		}
	}
	if(!f)
	{
		cout<<":("<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int t;

void solve() {
    int n;
    int s,f;
    int sum = 0;
    cin>>n;
    rep(i,n) {
        cin>>s>>f;
        sum += f-s;
    }

    if(t<=sum) {
        cout<<"OK"<<endl;
    }
    else {
        cout<<t-sum<<endl;
    }
}

int main() {
    while(cin>>t) {
        if(t==0) break;
        solve();
    }
    return 0;
}

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

#define ll long long
#define ull unsigned long long

int main(void) {
    ll D, N;
    cin >> D >> N;
    switch(D) {
        case 0:
        if(N != 100) cout << N << endl;
        else cout << 101 << endl;
        break;
        case 1:
        if(N != 100) cout << N * 100 << endl;
        else cout << 10100 << endl;
        break;
        case 2:
        if(N != 100) cout << N * 10000 << endl;
        else cout << 1010000 << endl;
        break;
    }
    return 0;
}


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

int main(){
	int n;
	scanf("%d", &n);
	set<int> s;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		if(s.count(x)) s.erase(x);
        else s.insert(x);
	}
	printf("%lu\n", s.size());
}


Measured memory_bytes: 4864
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	rep(i, n) {
		int put;
		cin >> put;
		ans += min(put, m - put)*2;
	}
	cout << ans << endl;

	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))

ans = []
for i in range(N):
    a = a_list[i]
    if i == 0:
        for j in range(1, N):
            if j % 2 == 0:
                a += a_list[j]
            else:
                a -= a_list[j]
        ans.append(a)
    else:
        a = a_list[i - 1]
        ans.append(2 * (a - ans[-1] // 2))

for a in ans:
    print(a)


Measured memory_bytes: 14028
#include <iostream>
#include <string>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)


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

  //cout<<s.substr(0,n/2)<<endl;
  //cout<<s.substr(n/2)<<endl;
  if(n%2==0){

    if(s.substr(0,n/2)==s.substr(n/2))

      cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }else cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
const int MX = 1000000000;

int main() {
	int x;
	cin >> x;
	if (x == 0) {
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
}

Measured memory_bytes: 3616
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextInt()
  val xy = Array.fill(n)((sc.nextLong(), sc.nextLong()))
  val xyks = xy.sortBy(_._1).inits.flatMap(_.tails).filter(_.length >= k)

  val ans = xyks.map{ xyk =>
    val xl = xyk.last._1 - xyk.head._1
    val yl = xyk.map(_._2).sorted.sliding(k).map(yk => yk.last - yk.head).min
    xl * yl
  }.min
  println(ans)
}


Measured memory_bytes: 61708
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()


def solve():
    cum = [0] * (N + 1)
    for i in range(N - 1, -1, -1):
        cum[i] = cum[i + 1] + A[i]
    count = Counter()
    ans = 0
    for i in range(N):
        if A[i] == 0:
            ans += 1
        ans += count[cum[i] - A[i]]
        count[cum[i]] += 1
    return ans


print(solve())


Measured memory_bytes: 45060
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<utility>	// 値入れ替えの関数 wrap
#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++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;

// 最大公約数（ユークリッドの互除法）
ll GCD(ll x, ll y) {
	if (x > y) {
		swap(x, y);
	}
	int r = y % x;
	while (r != 0) {
		y = x;
		x = r;
		r = y % x;
	}
	return x;
}

// 最小公倍数
ll LCM(ll x, ll y) {
	ll gcd = GCD(x, y);
	return x * y / gcd;
}


int main(void) {

	double w, h, x, y;
	cin >> w >> h >> x >> y;
	if (x*2 == w && y*2 == h) {
		cout << h * w / 2 << " 1" << endl;
	}
	else {
		cout << h * w / 2 << " 0" << endl;
	}

	return 0;

}

Measured memory_bytes: 256
tp = {}
while 1:
	t,p = map(int,raw_input().split(","))
	if t == p == 0: break
	tp[t] = p
plist = sorted(list(set([tp[key] for key in tp.keys()])),reverse = True)
while 1:
	try:
		team = int(raw_input())
	except:
		break
	print plist.index(tp[team])+1

Measured memory_bytes: 4212
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a<b){
        cout<<"a < b"<<endl;
    }else if(a>b){
        cout<<"a > b"<<endl;
    }else{
        cout<<"a == b"<<endl;
    }
}




Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    ll x;
    cin >> x;
    for (ll a = -2000; a <= 2000; a++){
        for (ll b = -2000; b <= 2000; b++){
            if(a*a*a*a*a-b*b*b*b*b==x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

	#define ONLINE_JUDGE
	#define ll long long
	#define PI 3.14159265359
	#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
	#define pb(a) push_back(a)

	//////////// Solution /////////////////////////////////

	void solve() {
		vector<pair<int,int>> my_vec;
		for (int i = 0; i < 5; ++i) {
			int val;
			cin >> val;
			if (val%10 == 0) {
				my_vec.pb(make_pair(0,val));
			} else {
				my_vec.pb(make_pair((val/10+1)*10 - val, val));
			}
		}

		sort(my_vec.begin(), my_vec.end());
		int t = 0;
		for (auto x : my_vec) {
			t += x.second + x.first;
		}
		t -= my_vec.back().first;
		cout << t << '\n';
	}

		/////////// End Solution ///////////////////////////////////////

		//////// Initialization ////////////////////////////////////

	int main() {

			#ifndef ONLINE_JUDGE
		FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
		clock_t time_start = clock();
			#endif

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

		solve();

			#ifndef ONLINE_JUDGE
		fclose(FIN);
		cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
			#endif

		return 0;
	}

		//////// End Initialization ///////////////////////////////////////

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
ll h[5005],p[5005];
ll dp[5005][5005];
vector<P> a;

bool sorter(const P& a,const P& b){
  return a.fi+a.se<b.fi+b.se;
}

int main(){
	cin>>n;
  rep(i,n){
    cin>>h[i]>>p[i];
    a.push_back(P(h[i],p[i]));
  }
  sort(all(a),sorter);
  rep(i,5005)rep(j,5005)dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,n)rep(j,n+1){
    if(dp[i][j]<=a[i].fi&&j<n){
      minch(dp[i+1][j+1],dp[i][j]+a[i].se);
    }
    minch(dp[i+1][j],dp[i][j]);
  }
  ll res=0;
  rep(j,n+1)if(dp[n][j]!=INF)maxch(res,j);
  cout<<res<<endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

typedef long long int ll;

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  rep(i, n) { cin >> v[i]; }

  std::map<std::string, int> dic;
  int max = 0;
  rep(i, n) {
    dic[v[i]] += 1;
    if (max < dic[v[i]]) {
      max = dic[v[i]];
    }
  }
  for (auto a: dic){
      if(a.second != max){
          continue;
      }
      cout << a.first << endl;
  }
}




Measured memory_bytes: 28800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

vector<bool> seen;
vector<ll> distT;
vector<ll> distA;
void dfsT(const vector<vector<int>> &G,int v){
    seen[v] = true;
    REP(i,G[v].size()){
        if(seen[G[v][i]])continue;
        distT[G[v][i]] = distT[v] + 1;
        dfsT(G,G[v][i]);
    }
}
void dfsA(const vector<vector<int>> &G,int v){
    seen[v] = true;
    REP(i,G[v].size()){
        if(seen[G[v][i]])continue;
        distA[G[v][i]] = distA[v] + 1;
        dfsA(G,G[v][i]);
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),u = in()-1,v = in()-1;
    vector<vector<int>> graph(N);
    REP(i,N-1){
        int as = in()-1,asd = in()-1;
        graph[as].pb(asd);
        graph[asd].pb(as);
    }
    seen.assign(N,false);
    distA.assign(N,1000000);
    distT.assign(N,1000000);
    distA[v] = 0;
    distT[u] = 0;
    dfsT(graph,u);
    seen.assign(N,false);
    dfsA(graph,v);
    ll same = 0;
    ll answer = 0;
    REP(i,N){
        if(distT[i] < distA[i]){
            chmax(answer,distA[i] - 1);
        }else if(distT[i] == distA[i]){
            if(same == 0)same = 1000000;
            chmin(same,distT[i]);
        }
    }
    chmax(answer,same);
    cout << answer<< "\n";
}

Measured memory_bytes: 11136
import sys
for i in range(sys.maxsize):
    w=input()
    if w=="-":
        break
    else:
        m=int(input())
        for j in range(m):
            h = int(input())
            if j ==0:
                s = w[h:]+w[:h]
            else:
                s = s[h:]+s[:h]
        print(s)


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; cin >> N;
  int T[101], P[101], X[101];
  rep(i, N) cin >> T[i];
  int M; cin >> M;
  rep(i, M) cin >> P[i] >> X[i];

  int64_t base = 0;
  rep(i, N) {
    base += T[i];
  }

  rep(i, M) {
    cout << base + X[i] - T[P[i] - 1] << "\n";
  }
    
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int S = scan.nextInt();
        
        int h, m, sec;
        
        h = S / 3600;
        S = S % 3600;
        m = S / 60;
        sec = S % 60;
        
        System.out.println(h + ":" + m + ":" + sec);
    }
}

Measured memory_bytes: 26176
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 401;
int n, m;
char a[N][N];
const int V = N * N;
vector <int> g[V];
bool ch(int i, int j) {
    return 0 <= i && i < n && 0 <= j && j < m;
}   
int num(int i, int j) {
    return i * m + j;
}   
vector <pair <int, int> > v = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
bool used[V];
int cnt[V][2];
void dfs(int u, int c, bool t) {
    ++cnt[c][t];
    used[u] = 1;
    for (int v : g[u]) {
        if (!used[v]) dfs(v, c, t ^ 1);
    }   
}
signed main() {
    #ifdef HOME
        freopen("input.txt", "r", stdin);
    #else 
        ios_base::sync_with_stdio(0);
        cin.tie(0);    
    #endif
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) cin >> a[i][j];
    }   
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            for (auto e : v) {
                if (ch(i + e.first, j + e.second) && a[i + e.first][j + e.second] != a[i][j]) {
                    g[num(i, j)].push_back(num(i + e.first, j + e.second));
                }   
            }   
        }   
    }   
    int ans = 0;
    int ptr = 0;
    for (int i = 0; i < n * m; ++i) {
        if (!used[i]) {
            dfs(i, ptr, 0);
            ans += cnt[ptr][0] * cnt[ptr][1];
            ++ptr;
        }
    }
    cout << ans << '\n';
    #ifdef HOME
        cerr << "TIME : " << (double)clock()/CLOCKS_PER_SEC<<'\n';
    #endif
}   

Measured memory_bytes: 19840
import bisect as bis
n, m = map(int, input().split())
p, y = [], []
idx = lambda x: x-1
for _ in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
val = [[] for _ in range(n)]
for i in range(m):
    val[idx(p[i])].append(y[i])
for i in range(n):
    val[i].sort()
for i in range(m):
    v = p[i]
    id = bis.bisect_right(val[idx(v)], y[i])
    print(str(v).zfill(6) + str(id).zfill(6))

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

long long a, b;

int main(){
    cin >> a >> b;
    if (b % 4 == 1) b = 1;
    else if (b % 4 == 2) b++;
    else if (b % 4 == 3) b = 0;
    if (a == 0){
        cout << b << "\n";
        return 0;
    }
    a--;
    if (a % 4 == 1) a = 1;
    else if (a % 4 == 2) a++;
    else if (a % 4 == 3) a = 0;
    cout << (b ^ a) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
const static int w = 3;

int main() {
    string s;
    while (cin >> s) {
        const int l = s.length(); int joi = 0, ioi = 0;
        for (int i = 0; i <= l - w; i++) {
            const string s_w = s.substr(i, w);
            if (s_w == "JOI") joi++; else if (s_w == "IOI") ioi++;
        }

        cout << joi << endl << ioi << endl;
    }
}


Measured memory_bytes: 3152
#include<iostream>
int main(){
	while(1){
		int d,s=0;
		std::cin>>d;
		if(std::cin.eof())break;
		for(int i=0;i<600;i+=d)s+=i*i*d;
		std::cout<<s<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
#define INF 0x3f3f3f3f3f3f3f3f
#define W 100000000
typedef pair<int, int>P;
#define int long long

int dp[400000];
int a[200000], b[200000];

signed main() {
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	bool sx = false, sy = false;
	if (y1 > y2) {
		sy = true;
		y1 = W - y1 - 1;
		y2 = W - y2 - 1;
	}
	if (x1 > x2) {
		sx = true;
		x1 = W - x1 - 1;
		x2 = W - x2 - 1;
	}
	int n; cin >> n;
	vector<P>v;
	rep(i, n) {
		scanf("%lld%lld", &a[i], &b[i]);
		if (sx)a[i] = W - a[i] - 1;
		if (sy)b[i] = W - b[i] - 1;
		if (x1 <= a[i] && a[i] <= x2 && y1 <= b[i] && b[i] <= y2) {
			v.push_back(P(a[i], b[i]));
		}
	}
	if (x1 == x2) {
		bool flag = false;
		rep(i, n) {
			if (a[i] == x1&&y1 <= b[i] && b[i] <= y2)flag = true;
		}
		printf("%.20lf\n", (y2 - y1) * 100 + flag*(10 * M_PI - 20));
		return 0;
	}
	if (y1 == y2) {
		bool flag = false;
		rep(i, n) {
			if (b[i] == y1&&x1 <= a[i] && a[i] <= x2)flag = true;
		}
		printf("%.20lf\n", (x2 - x1) * 100 + flag*(10 * M_PI - 20));
		return 0;
	}
	sort(v.begin(), v.end());
	memset(dp, 0x3f, sizeof(dp));
	rep(i, v.size()) {
		*lower_bound(dp, dp + n, v[i].second) = v[i].second;
	}
	int ans = lower_bound(dp, dp + n, INF) - dp;
	int d = min(y2 - y1, x2 - x1);
	printf("%.20lf\n", ((x2 - x1) + (y2 - y1)) * 100 - min(d, ans)*(20 - 5 * M_PI) + max(0LL, ans - d)*(10 * M_PI - 20));
}

Measured memory_bytes: 8176
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N, M;
	cin >> N >> M;

	vvint edge(N);
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			edge[i].emplace_back(false);
		}
	}


	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
	
		edge[a-1][b-1] = true;
		edge[b-1][a-1] = true;
	
	}

	vint perm = {};
	for (int i = 0; i < N; i++)
	{
		perm.emplace_back(i);
	}

	int ans = 0;


	for (int i = 0; i < N - 1; i++)
	{
		if (edge[perm[i]][perm[i + 1]])
		{
			if (i == N - 2)
			{
				ans++;
				//for (int j = 0; j < N; j++) {
				//	cout << perm[j] << " ";
				//}
				//cout << endl;
			}
		}
		else {
			break;
		}
	}


	while (next_permutation(perm.begin(), perm.end()))
	{
		if (perm[0] != 0)
		{
			continue;
		}

		for (int i = 0; i < N-1; i++)
		{
			if (edge[perm[i]][perm[i + 1]])
			{
				if (i == N - 2)
				{
					ans++;
					//for (int j = 0; j < N; j++) {
					//	cout << perm[j] << " ";
					//}
					//cout << endl;
				}
			}
			else {
				break;
			}
		}


	}


	cout << ans;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int n;
    cin>>n;
    int A,B,C,D;
    int sum=0;
    A=n/1000,n%=1000;
    B=n/100,n%=100;
    C=n/10,n%=10;
    D=n;
    string s="=7";
    vector<int>num={A,B,C,D};
    vector<char>op(3);
    /*考え方:
    全探索を考える（オーダー的にもOK)
     ・opの入れ方は+か-の2通り
     ・op1,op2,op3がある
     ->2^3通り ->ビット全探索orループ*/
    for(int bit=0;bit<(1<<3);bit++){
        bitset<3>s(bit);
        /*operantの決定*/
        for(int l=0;l<3;l++){
            if(s.test(l)){//bitがいならtrue
                op[l]='+';
            }else{
                op[l]='-';
            }
        }
        sum+=A;
        rep(l,3){
            if(op[l]=='+'){
                sum+=num.at(l+1);
            }else{
                sum-=num.at(l+1);
            }
        }
        if(sum==7){
            cout<<A<<op.at(0)<<B<<op.at(1)<<C<<op.at(2)<<D;
            cout<<"=7"<<endl;
            return 0;
        }else{
            sum=0;
        }
    }
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var WHN = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            var W = WHN[0];
            var H = WHN[1];
            var N = WHN[2];
            var x1 = 0;
            var x2 = W;
            var y1 = 0;
            var y2 = H;
            for (var i=0;i<N;i++)
            {
                var WHA = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
                if(WHA[2]==1)
                {
                    if(x1 < WHA[0])  x1 = WHA[0];
                }
                else if (WHA[2] == 2)
                {
                    if (x2 > WHA[0]) x2 = WHA[0];
                }
                else if (WHA[2] == 3)
                {
                    if (y1 < WHA[1]) y1 = WHA[1];
                }
                else if (WHA[2] == 4)
                {
                    if (y2 > WHA[1]) y2 = WHA[1];
                }
            }
            if(x2-x1<0 || y2-y1<0)
            {
                Console.WriteLine(0);
                return;
            }
            Console.WriteLine((x2 - x1) * (y2 - y1));
        }
    }
}

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

using namespace std;
using ull = unsigned long long;

int main(){
    ull A;
    float b;
    cin >> A >> b;
    int B = (int)(b * 100 + 0.5);
    ull res=0;
    if(A == 0 || B == 0){
        res = 0;
    }else if(A*B >= A){
        res = A*B / 100;
    }else{
        if((ULLONG_MAX % 100 + (A*B + 1) % 100) >= 100)res = ULLONG_MAX/100 + (A*B + 1)/100 + 1;
        else res = ULLONG_MAX/100 + (A*B + 1)/100;
    }
    cout << res << endl;
}

Measured memory_bytes: 3736
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=200005;
int vis[27],res,r[maxn],l[maxn],cnt;
char s[maxn];
int main()
{
	cin>>s;
	int len=strlen(s);
	res=26;r[0]=len-1;
	for(int i=len-1;i>=0;i--)
		if(!vis[s[i]-'a'])
		{
			vis[s[i]-'a']=1;res--;
			if(!res)
			{
				l[cnt]=i;r[++cnt]=i-1;
				memset(vis,0,sizeof(vis));res=26;
			}
		}
	int last=0;l[cnt]=0;
	char t;
	for(int i=cnt;i>=0;i--)
	{
		memset(vis,0,sizeof(vis));res=26;
		for(int j=last;j<=r[i];j++)vis[s[j]-'a']=1;
		for(int j=0;j<26;j++)
			if(!vis[j])
			{
				printf("%c",j+'a');
				t=j+'a';break;
			}
		for(int j=last;j<len;j++)
			if(s[j]==t)
			{
				last=j+1;break;
			}
	}
	
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(ll i=(n);i<(x);++i)
#define SORT(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end()
using ll = long long;

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i, 0, n) cin >> a[i]; SORT(a);
	rep(i, 0, n) cin >> b[i]; SORT(b);
	rep(i, 0, n) cin >> c[i]; SORT(c);

	ll ans = 0;
	rep(i, 0, n) {
		auto itr1 = lower_bound(all(a), b[i]);
		auto itr2 = upper_bound(all(c), b[i]);
		ans += (itr1 - a.begin()) * (c.end() - itr2);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
N, K = map(int, input().split())
a = list(map(int, input().split()))

acum_a = [a[0]]
acum_b = [max(0, a[0])]
for i in range(1, N):
    acum_a.append(acum_a[-1] + a[i])
    acum_b.append(acum_b[-1] + max(0, a[i]))

ans = 0
for i in range(N - K + 1):
    score = 0
    if i == 0:
        score += max(0, acum_a[K - 1])
    else:
        score += acum_b[i - 1]
        score += max(0, acum_a[i + K - 1] - acum_a[i - 1])
    score += acum_b[N - 1] - acum_b[i + K - 1]
    ans = max(ans, score)
print(ans)


Measured memory_bytes: 17636
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int N=105,INF=~0u>>2;
int a[N],ans=INF,maxn=-INF,minn=INF,n;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
		maxn=max(a[i],maxn);
		minn=min(a[i],minn);
	}
	for(int i=minn;i<=maxn;++i){
		int tmp=0;
		for(int j=1;j<=n;++j){
			tmp+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,tmp);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
n,m = list(map(int,input().split()))
mod = 10**9+7 #出力の制限
import math

def perm(n, r):
    ''' nPr % mod '''
    if r > n:
        return 0
    return g1[n] * g2[n-r] % mod

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 5 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for k in range(n+1):
    a = cmb(n,k,mod)
    p1 = perm(m,k)
    p2 = perm(m-k, n-k)
    ans += (a * (-1)**k * p1 * p2**2)

print(ans%mod)

Measured memory_bytes: 68624
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    string c[3];
    rep(i, 3) { cin >> c[i]; }
    rep(i, 3) { cout << c[i][i]; }
    cout << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset> 
#include <cstdio> 
#include <vector>
using namespace std;
int n,m;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a*3+b)/2;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int n,a,b,i;
  while(1){
    int sa=0,sb=0;
    scanf("%d",&n);
    if(n==0)
      break;
    for(i=0;i<n;i++){
      scanf("%d %d",&a,&b);
      if(a>b)
	sa+=(a+b);
      else if(b>a)
	sb+=(a+b);
      else{
	sa+=a;sb+=b;
      }
    }
    printf("%d %d\n",sa,sb);
  }

  return 0;
}

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

int main(){
	int n, k, q;
	scanf("%d%d%d", &n, &k, &q);
	
	int i;
	int a[q];
	
	for(i = 0; i < q; i++)
	{
		scanf("%d", &a[i]);
	}
	
	int seikai[n + 1];
	
	for(i = 0; i < n + 1; i++)
	{
		seikai[i] = 0;
	}
	
	for(i = 0; i < q; i++)
	{
		seikai[a[i]]++;
	}
	
	for(i = 1; i < n + 1; i++)
	{
		if(k - q + seikai[i] > 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(void){
    int i,R0,W0,C,R;
    for(;;){
        cin>>R0>>W0>>C>>R;
        if(R0==0&&W0==0&&C==0&&R==0){
            break;
        }
        
        if(R0/W0>=C){
            cout<<0<<endl;
        }else{
            for(i=1;;i++){
                if((R0+i*R)/W0>=C){
                    break;
                }
            }
            cout<<i<<endl;
        }
        
        
    }
}



Measured memory_bytes: 3080
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		string[] a=new string[s[0]];
		for(int i=0;i<s[0];i++){
			a[i]=Console.ReadLine();
		}
		bool[] h=new bool[s[1]];
		for(int i=0;i<s[1];i++){
			for(int j=0;j<s[0];j++){
				if(a[j][i].ToString()=="#"){h[i]=true;break;}
			}
		}
		for(int i=0;i<s[0];i++){
			if(a[i].IndexOf("#")!=-1){
				var c=a[i].ToCharArray();
				for(int j=0;j<s[1];j++){
					if(h[j]){Console.Write("{0}",c[j]);}
				}
				Console.WriteLine();
			}
		}
	}
}

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

int main(void){
    int n;
    cin>>n;
    vector <string> s(n);
    rep(i, n) cin>>s[i];
    map<string, int> m;
    rep(i, n){
        auto itr=m.find(s[i]);
        if(itr!=m.end()){
            m[s[i]]++;
        }
        else m[s[i]]=0;
    }
    int max=0;
    for (auto x : m){
        if(x.second>max){
            max=x.second;
        }
    }
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second == max) {
            cout << it->first << endl;
        }
    }

}

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

int main() {
	int K, T, a, count = 0;
	cin >> K >> T;
	int x = (K + 1) / 2;
	for (int i = 0; i < T; i++) {
		cin >> a;
		if (a > x) count = a * 2 - K - 1;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int INF = 1 << 30;

template<class T> inline bool chmin(T &a, T b) {
    if (a > b) a = b; return true;
    return false;
}

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

    int n;
    cin >> n;

    vector<int> h(n);
    REP(i, n) cin >> h[i];

    vector<int> dp(n + 2, INF);

    dp[0] = 0;
    REP(i, n) {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    cout << dp[n - 1] << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define nl '\n'
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

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

  int n;
  cin >> n;
  int a[1+n];
  for(int i=1; i<=n; i++)
    cin >> a[i];
  sort(a+1, a+1+n);
  int x = a[n], y = a[1];
  for(int i=2; i<n; i++) {
    if( abs(2*a[i] - x) < abs(2*y - x) )
      y = a[i];
  }
  cout << x << ' ' << y << endl;

  return 0;
}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 640
function Main(input) {
  let a = input % 10;
  if (a === 2 || a === 4 || a === 5 || a === 7 || a === 9) {
    console.log("hon");
  } else if (a === 0 || a === 1 || a === 6 || a === 8) {
    console.log("pon");
  } else if (a === 3) {
    console.log("bon");
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29604
n = gets.to_i

ab = []
f = Array.new(n+1){[]}
(n-1).times do |i|
    a, b = gets.split.map(&:to_i)
    f[a] << i
    f[b] << i
    ab << [a, b]
end

ans = Array.new(n-1)
que = [1]
pc = Array.new(n+1, 0)
mc = 0

while x = que.shift
    c = 1

    f[x].each do |i|
        next if ans[i]
        y = ab[i][0] == x ? ab[i][1] : ab[i][0]
        c += 1 if c == pc[x]

        ans[i] = c
        pc[y] = c
        mc = c if mc < c
        que << y
        c += 1
    end
end

puts mc, ans

Measured memory_bytes: 19884
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  string nm;
  int tm;
  queue<int>qt;
  queue<string>qn;
  cin>>n>>q;
  for(int i=0;i<n;i++){
    cin>>nm>>tm;
    qn.push(nm);
    qt.push(tm);
  }
  int ans=0;
  while(qn.empty()==0){
    nm=qn.front();
    tm=qt.front();
    qn.pop();
    qt.pop();
    if(tm<=q){
      ans+=tm;
      cout<<nm<<" "<<ans<<endl;
    }
    else{
      ans+=q;
      qn.push(nm);
      qt.push(tm-q);
    }
  }
}

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

int main(){
	int n,x,t;
	cin >> n >> x >> t;
	if(n%x!=0){
		cout << (int(n/x)+1)*t << endl;
		return 0;
	}
	else {
		cout << (n/x) * t << endl;
		return 0;
	}
}

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

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

int main(){

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

    string s;
    cin >> s;

    string a = s.substr(0, 2);
    string b = s.substr(2, 2);

    int x = stoi(a);
    int y = stoi(b);
    bool mona = false, monb = false;
    if(0 < x and x <= 12) mona = true;
    if(0 < y and y <= 12) monb = true;

    if(mona and monb) ppp("AMBIGUOUS");
    else if(mona and !monb) ppp("MMYY");
    else if(!mona and monb) ppp("YYMM");
    else if(!mona and !monb) ppp("NA");
    return 0;
}


Measured memory_bytes: 256