akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=100005;

int H,W,N;
set<pair<int,int> > ans[10],blk;
map<int,vector<int> > p2;
pair<int,int> P[MAXN];

int Count(pair<int,int> R)
{
	int cnt=0;
	for(int i=R.first;i<R.first+3;i++)
		for(int j=R.second;j<R.second+3;j++)
			cnt+=blk.count(make_pair(i,j));
	return cnt;
}

int main()
{
	scanf("%d%d%d",&H,&W,&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%d%d",&P[i].first,&P[i].second);
		if(P[i].first<=H-2)
			p2[P[i].first].push_back(P[i].second);
		if(P[i].first>1&&P[i].first<=H-1)
			p2[P[i].first-1].push_back(P[i].second);
		if(P[i].first>2)
			p2[P[i].first-2].push_back(P[i].second);
		if(!blk.count(P[i]))
			blk.insert(P[i]);
	}
	
	for(int i=1;i<=N;i++)
	{
		for(int x=max(P[i].first-2,1);x<=P[i].first&&x+2<=H;x++)
			for(int y=max(P[i].second-2,1);y<=P[i].second&&y+2<=W;y++)
			{
				pair<int,int> r=make_pair(x,y);
				int c=Count(r);
				ans[c].insert(r);
			}
	}
	long long ans0=0;
	if(N)
	{
		ans0+=1LL*(p2.begin()->first-1)*(W-2);
		for(map<int,vector<int> >::iterator i=p2.begin(),k;i!=p2.end();)
		{
			sort(i->second.begin(),i->second.end());
			int sz=i->second.size();
			/*
			printf("%d:",i->first);
			for(int j=0;j<sz;j++)
				printf("%d ",i->second[j]);
			puts("");
			*/
			ans0+=max((i->second[0]-1)-2,0);
			for(int j=0;j<sz-1;j++)
				ans0+=max((i->second[j+1]-i->second[j]-1)-2,0);
			ans0+=max((W-i->second[sz-1])-2,0);
			k=i;
			i++;
			if(i==p2.end())
				break;
			ans0+=1LL*(i->first-k->first-1)*(W-2);
		}
		ans0+=1LL*(H-p2.rbegin()->first-2)*(W-2);
	}
	else
		ans0=1LL*(H-2)*(W-2);
	printf("%lld\n",ans0);
	for(int i=1;i<10;i++)
		printf("%u\n",ans[i].size());
	
	return 0;
}


Measured memory_bytes: 80640
n = int(input())
s = str(input())

#n = 12
#s = 'WEWEWEEEWWWE'

w = [0] * (n+1)
e = [0] * (n+1)

for i in range(n):
  w[i+1] = w[i]
  e[i+1] = e[i]
  if s[i] == 'W':
    w[i+1] += 1
  else :
    e[i+1] += 1

#  w  ([0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 5, 6, 6],
#  e   [0, 0, 1, 1, 2, 2, 3, 4, 5, 5, 5, 5, 6])

ans = n
for i in range(1,n+1):
  # 自分より左にいるwの数 w[i-1]
  # 自分より右にいるeの数 e[n] - e[i]
  ans = min(ans, w[i-1] + (e[n] - e[i]) )

print(ans)



Measured memory_bytes: 17568
"""
hour minutes second
"""
def main():
    x=int(input())
    h=int(x/3600)
    m=int((x-3600*h)/60)
    s=x-h*3600-m*60
    print('{0}:{1}:{2}'.format(h,m,s))
    
if __name__=="__main__":
    main()


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
ll A[100000],B[100000];

ll D[100000];
void solve(){
	rep(i, N){
		D[i] = A[i] - B[i];
	}
	sort(D, D + N);
	int top = N - 1;
	int ans = 0;
	int c = 0;
	rep(i, N){
		if(D[i] < 0){
			while(c + D[i] < 0){
				if(D[top] <= 0){
					cout<<-1<<endl;
					return;
				}
				c += D[top];
				top--;
				ans++;
			}
			c += D[i];
			ans++;
		}
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>N;
	rep(i, N) {
		cin>>A[i];
	}
	rep(i, N) {
		cin>>B[i];
	}
		solve();
	return 0;
}


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


int main()
{
	//freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll a,b,x,t1,t2;
	cin>>a>>b>>x;
	t1=b/x;
	t2=a%x==0?a/x-1:a/x;
	cout<<t1-t2;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

char *clas[8]={"AAA","AA","A","B","C","D","E","NA"};
int rnk5[7]={3550,3750,4000,4300,5000,5500,7000};
int rnk10[7]={7100,7700,8300,8900,10500,11600,14800};

int judge(int i,int a5,int a10){
  while(i<7){
    if((a5<rnk5[i])&&(a10<rnk10[i])){
      return i;
    }
    else{
      i++;
    }
  }
  return 7;
}

void doit(double x5,double x10){
  int a5=(int)(100*x5);
  int a10=(int)(100*x10);
  printf("%s\n",clas[judge(0,a5,a10)]);
}

int main(){
  double x5,x10;
  while(scanf("%lf %lf",&x5,&x10)!=EOF){
    doit(x5,x10);
  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;

vll prime_factorize(ll n) {
    vll v;
    while (n % 2 == 0) {
        v.push_back(2);
        n /= 2;
    }

    for (ll i = 3; i <= sqrt(n); i += 2) {
        while (n % i == 0) {
            v.push_back(i);
            n /= i;
        }
    }
    if (n > 2) v.push_back(n);
    return v;
}

int main()
{
    ll n; cin >> n;
    vll v = prime_factorize(n);
    map<ll, ll> mp;
    rep(i, v.size()) {
        mp[v[i]]++;
    }

    ll count = 0;
    for (auto p : mp) {
        ll c = 0;
        ll i = 1;
        while (i <= p.second) {
            count++;
            p.second -= i;
            i++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

int main() {

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

	int n,k;
	cin>>n>>k;

	std::vector<int> a(n);
	int i;
	for (i=0;i<n;i++) cin>>a[i];

	ll lo = 1, hi = *max_element(all(a));

	while (lo<hi) {
		ll mid = lo+(hi-lo)/2;

		ll br=0ll;
		for (i=0;i<n;i++)
		if (a[i]>mid) {
			br += ceil((double)a[i]/mid);
		} else
			br++;

		if (br>n+k) {
			lo = mid+1;
		} else
			hi = mid;
	}

	cout<<hi<<"\n";

    return 0;
}

Measured memory_bytes: 3992
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    REP(i,n-1){
        if(a[i]==a[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            int l = s - i - j;
            if (l >= 0 && l <= k)
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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


void solve(long long N, std::vector<long long> a){
    long long cnt = 0;
    for(long long i : a)
    {
      while(i % 2 == 0){
          cnt++;
          i /= 2;
      }  
    }

    cout << cnt << endl;
    
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

map <string, int> m;
queue <string> q;
priority_queue <pair<int, string>> pq;
set <string> ans;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    m[s]++;
    q.push(s);
  }
  while (q.size() > 0) {
    s = q.front();
    pq.push(make_pair(m[s], s));
    q.pop();
  }
  int may = pq.top().first;
  ans.insert(pq.top().second);
  pq.pop();
  while (pq.size() > 0 && pq.top().first == may) {
    ans.insert(pq.top().second);
    pq.pop();
  }
  for (auto it = ans.begin(); it != ans.end(); it++) {
    cout << *it << '\n';
  }
  return 0;
} 

Measured memory_bytes: 36848
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<(int)S.size();++i)
#define fore(i,x) for(int i = head[x] ; i ; i = e[i].next)
#define mp make_pair
#define pb push_back
#define int long long
#define PII pair<int,int>
#define maxn 1000005
#define ll long long 
#define fi first
#define int ll
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std; 
int k,a,b;
int du[maxn];

signed main()
{ cin>>k>>a>>b;
  if(b-a>2)
     {int ans=a+(b-a)*( (k-a+1)/2);
      if((k-a+1)%2==1) ans++;
      cout<<ans;
	 }
  else cout<<k+1;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}

int n;
ll ans = 1LL;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    rep(i, 0, n) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}


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

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

using namespace std;

typedef long long ll;

int main(){
	int n; scanf("%d",&n);
	static int l[499999],r[499999],depth[499999];
	rep(u,n-1){
		scanf("%d%d",l+u,r+u), l[u]--, r[u]--;
		if(l[u]!=n-1) depth[l[u]]=depth[u]+1;
		if(r[u]!=n-1) depth[r[u]]=depth[u]+1;
	}

	static int leaf[500000]; // leaf[u] := ( 頂点 u を根とする部分木の葉の数 )
	static ll dp1[500000]; // dp1[u] := ( 頂点 u にいて, u でセーブする. 以降セーブせずに u 以下の葉を全攻略するための最小時間 )
	static ll dp2[500000]; // dp2[u] := ( 頂点 u にいて, 好きにセーブしてもいいとしたときの, u 以下の葉を全攻略するための最小時間 )
	leaf[n-1]=1;
	for(int u=n-2;u>=0;u--){
		leaf[u]=leaf[l[u]]+leaf[r[u]];

		dp1[u]=leaf[u]+dp1[l[u]]+dp1[r[u]];

		dp2[u]=1+dp2[l[u]]+depth[u]+1+dp2[r[u]]; // このケースでは左の子に行った先でセーブしてしまうので, u に戻るにはまた 0 から降りなおしてこないといけない
		dp2[u]=min(dp2[u],leaf[l[u]]+dp1[l[u]]+1+dp2[r[u]]);
		dp2[u]=min(dp2[u],leaf[r[u]]+dp1[r[u]]+1+dp2[l[u]]);
	}

	printf("%lld\n",dp2[0]);

	return 0;
}

Measured memory_bytes: 16648
#include <bits/stdc++.h>
#define pi 3.14159
#include <map>
#include <iterator>
using namespace std;
int main()
{
	long long int a,b,n,i,c=0;
	string s;
	cin>>s;
	a=(s[0]-'0')*10+(s[1]-'0');
	b=(s[2]-'0')*10+(s[3]-'0');
//	cout<<a<<" "<<b;
	if(a<=12&&b<=12&&a>0&&b>0)
		cout<<"AMBIGUOUS"<<endl;
	else if(a>0&&a<=12)
		cout<<"MMYY"<<endl;
	else if(b>0&&b<=12)
		cout<<"YYMM"<<endl;
	else
		cout<<"NA"<<endl;
	}

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

int main()
{
    int a[26];

    for (int i = 0; i < 26; i++) {
        a[i] = 0;
    }

    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        a[s[i] - 'a'] = 1;
    }

    int m = -1;
    for (int i = 0; i < 26; i++) {
        if (a[i] == 0) {
            m = i;
            break;
        }
    }
    if (m == -1) {
        cout << "None" << endl;
    } else {
        cout << (char)(m + 'a') << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#define CPP17
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#ifdef CPP17
#include <variant>
#endif

// Yay!!
#define endl codeforces

// macros for iterator
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

// alias
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

// variadic min/max
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }

// variadic chmin/chmax
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

// multi demension array
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

#ifdef CPP17
// fill container
template <typename T, typename F, typename... Args> 
void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable<F, Args...>::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } }
#endif

// make multi dimension vector
template <typename T> vec<T> make_v(ssize_t sz) { return vec<T>(sz); }
template <typename T, typename... Tail> auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); return vec<decltype(v)>(hs, v); }

// init
namespace init__ { 
struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; 
}


int main() {
    std::string s;
    std::cin >> s;
    std::cout << s.substr(0, 3) << "\n";
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define pb push_back
//#define int long long
#define mod 1000000007
#define fi first
#define se second
#define ll long long
#define scan() ll n; cin>>n ; ll a[n]; for(ll i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(ll i=x;i<y;i++)
using namespace std;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<ll,ll> pll ;
int main()
{
	fast;
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++)
	{
		if(i%3!=0 && i%5!=0)
		sum+=i;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    int a;
    int b;

    scanf("%d %d",&a,&b);
if  (b<a){
    for (int i=0;i<a;i++)
        printf("%d",b);
}
    else {
    for (int i=0;i<b;i++)
        printf("%d",a);
    }

return EXIT_SUCCESS;
}


Measured memory_bytes: 128
//Volume0-0095
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Player implements Comparable<Player>{
	public int a,
	           v;
	Player(int a,int v){
		this.a = a;
		this.v = v;
	}

	public int compareTo(Player t){
		return this.a - t.a;
	}
}

public class Main {

	public static void main(String[] args){

		//declare
		ArrayList<Player> ar = new ArrayList<Player>();

		int Champion = 0,
			num      = Integer.MIN_VALUE;

		//input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n-- > 0){
        	ar.add(new Player(sc.nextInt(),sc.nextInt()));
        }
        //calculate
        Collections.sort(ar);

        for(Player p:ar){
           	if( p.v > num){
           		Champion = p.a;
           		num      = p.v;
       		}
        }
       	//output
        System.out.println(Champion+" "+num);
	}
}

Measured memory_bytes: 17396
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
int dx[4] = {0, 1, -1, 0}, dy[4] = {1, 0, 0, -1};
bool use[101][101];
char maze[101][101];
int n, m;
void dfs(char ch, int x, int y)
{
    if(use[x][y])
        return ;
    use[x][y] = true;
    int i, nx, ny;
    for(i = 0;i < 4;i++)
    {
        nx = x + dx[i];
        ny = y + dy[i];
        if(nx >= 0 && nx < n && ny >= 0 && ny < m && maze[nx][ny] == ch)
            dfs(ch, nx, ny);
    }
}
int main()
{
    while(scanf("%d%d", &n, &m), n || m)
    {
        int i, j;
        for(i = 0;i < n;i++)
            scanf("%s", maze[i]);
        memset(use, false, sizeof(use));
        int ans = 0;
        for(i = 0;i < n;i++)
        {
            for(j = 0;j < m;j++)
            {
                if(!use[i][j])
                {
                    ans ++;
                    dfs(maze[i][j], i, j);
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

bool cmp(ii a, ii b) {
    return a.f+a.s < b.f+b.s;
}

ll f[MX], dp[MX];

ll qpow(ll b, ll e) {
    if (!e) return 1LL;
    if (e&1) return (qpow(b,e-1)*b)%MOD;
    ll res = qpow(b,e/2)%MOD;
    return (res*res)%MOD;
}

ll inv(ll x) {
    return qpow(x,MOD-2)%MOD;
}

ll combo(ll n, ll k) {
    ll up = f[n]%MOD;
    ll down = (f[n-k])%MOD; down = (down*f[k])%MOD;
    return (up*inv(down))%MOD;
}

ll paths(ii p1, ii p2) {
    return combo(p2.f-p1.f+p2.s-p1.s,p2.f-p1.f)%MOD;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    f[0] = 1LL;
    F0R(i,MX-2) f[i+1] = ((f[i]%MOD)*((i+1)%MOD))%MOD;

    int H,W,N; cin >> H >> W >> N;

    vii arr(N+1);
    F0R(i,N) cin >> arr[i].f >> arr[i].s;
    arr[N] = {H,W};
    sort(all(arr),cmp);

    F0R(i,N+1) {
        ll tmp = paths({1,1},arr[i]);
        F0R(j,i) {
            if (arr[i].f >= arr[j].f && arr[i].s >= arr[j].s) {
                ll res = dp[j]%MOD; res = (res*paths(arr[j],arr[i]))%MOD;
                tmp = (tmp-res+MOD)%MOD;
            }
        }
        dp[i] = tmp%MOD;
    }

    cout << dp[N] << "\n";

}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int H[1010];
int main(){
  int N,T,A;
  cin>>N>>T>>A;
  int ans,d=INT_MAX;
  for(int i=1;i<=N;i++){
    int H;
    cin>>H;
    if(abs((T*1000-H*6)-A*1000)<d){
      d=abs((T*1000-H*6)-A*1000);
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    bool table[6][6];
    bool tmp[6][6];
    rep(i,6){
        rep(j,6){
            table[i][j] = false;
        }
    }
    char c;
    rep(i,h){
        rep(j,w){
            cin >> c;
            if(c == '.')
                table[i][j] = false;
            else
                table[i][j] = true;
        }
    }
    
    int ans = 0;

    rep(i,1 << h){
        rep(j,1 << w){
            rep(y,h){
                rep(x,w){
                    tmp[y][x] = table[y][x];
                }
            }

            rep(k,h){
                if(i & (1 << k)){
                    rep(l,w){
                        tmp[k][l] = false;
                    }
                }
            }

            rep(k,w){
                if(j & (1 << k)){
                    rep(l,h){
                        tmp[l][k] = false;
                    }
                }
            }

            int cnt = 0;
            rep(y,h){
                rep(x,w){
                    if(tmp[y][x])cnt++;
                }
            }
            if(cnt == k)ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
#define ld long double
#define rep(i,a,n) for (ll i= (a) ; i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(),(v).end()
#define M_PI 3.14159265358979323846
const ll MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
const int N = 100005;

void solve() {
	int n;
	cin >> n;
	int ans = 0;
	while ( ans < n) {
		ans += 1000;
	}

	cout << ans - n;

}


int main() {

	int t = 1;

	//cin >> t;
	ll k = 1;
	while (t--) {
		//cout << "Case #" << k++ << ": ";
		solve();
	}
	return 0;
}


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

int main()
{
 char a[11],b[11],c[11];
 int an,bn;

 scanf("%s %s %s",a,b,c);
 an=strlen(a);
 bn=strlen(b);

 if((a[an-1]==b[0])&&(b[bn-1]==c[0]))printf("YES");
 else printf("NO");

 return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
int n;
double p[3005],dp[3005][3005];
int main(){
	cin>>n;
	dp[0][0]=1.00;
	for(int i=1;i<=n;i++)	cin>>p[i];
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
			dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1.0-p[i]);
	double ans=0;
	for(int i=(n+1)/2;i<=n;i++)	ans+=dp[n][i];
	cout<<setprecision(11)<<ans<<endl;
}

Measured memory_bytes: 68992
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int main(){
    
    
   
    double a;
    cin>>a;
    double men = a*a*M_PI;
    double syu = 2*a*M_PI;
    printf("%f %f",men,syu);
    
    return 0;

}


Measured memory_bytes: 3300
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>
#include <string.h>
#include <limits>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <chrono>

using namespace std;

namespace
{

}

#if 1
int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;

	if (a > b)
	{
		swap(a, b);
	}
	if (a > c)
	{
		swap(a, c);
	}
	if (b > c)
	{
		swap(b, c);
	}

	int sum = c * 10 + a + b;

	std::cout << sum;

	return 0;
}
#endif


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define gcd(a,b)	__gcd__(a,b)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0
const ll inf = (ll)1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

vector <tuple<int, ll, int>> edge[110];
int level[110];
int itr[110];

void bfs(int s, int t) {
	REP(i, t)	level[i] = -1;
	level[s] = 0;
	queue<int> q;
	q.push(s);
	while (!q.empty()) {
		int v = q.front();	q.pop();
		for (auto it : edge[v]) {
			int to, rev;	ll cap;
			tie(to, cap, rev) = it;
			if (cap > 0 && level[to] == -1) {
				level[to] = level[v] + 1;
				q.push(to);
			}
		}
	}
}

ll dfs(int s, int t, ll f) {
	if (s == t)	return f;
	for (; itr[s] < edge[s].size();itr[s]++) {
		int i = itr[s];
		int to, rev;	ll cap;
		tie(to, cap, rev) = edge[s][i];
		if (cap > 0 && level[s] < level[to]) {
			ll d = dfs(to, t, min(f, cap));
			if (d > 0) {
				edge[s][i] = mt(to, cap - d, rev);
				edge[to][rev] = mt(s, get<1>(edge[to][rev]) + d, i);
				return d;
			}
		}
	}
	return 0;
}

ll dinic(int s, int t) {
	ll ret = 0;
	while (true) {
		bfs(s, t);
		if (level[t] < 0)	return ret;
		REP(i, t)	itr[i] = 0;
		ll f = 0;
		while ((f=dfs(s,t,inf)) > 0) {
			ret += f;
		}
	}
}

int main() {
	int n;	cin >> n;
	ll ret = 0;
	rep(i, n) {
		ll a;	cin >> a;
		if (a > 0) {
			edge[i + 1].push_back(mt(n + 1, a, edge[n + 1].size()));
			edge[n + 1].push_back(mt(i + 1, 0, edge[i + 1].size() - 1));
			ret += a;
		}
		else {
			edge[0].push_back(mt(i + 1, -a, edge[i + 1].size()));
			edge[i + 1].push_back(mt(0, 0, edge[0].size() - 1));
		}
	}
	SREP(i, 1, n) {
		for (int j = i; j <= n; j += i) {
			edge[i].push_back(mt(j, inf, edge[j].size()));
			edge[j].push_back(mt(i, 0, edge[i].size() - 1));
		}
	}
	cout << ret - dinic(0, n + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
  int l,r,largest;
  l = 2 * i;
  r = 2 * i + 1;

  if((l <=H) && (A[l] > A[i])) largest = l;
  else largest = i;
  if((r <= H) && (A[r] > A[largest])) largest = r;

  if(largest != i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  cin >> H;

  for(int i=1;i<=H;i++) cin >> A[i];
  
  for(int i=H/2;i>=1;i--) maxHeapify(i);
  
  for(int i=1;i<=H;i++){
    cout << " " << A[i];
  }
  
  cout << endl;

  return 0;
}



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

#define range 524289
#define mod 998244353
#define eps 1e18
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <ll> vi;
typedef vector<vi> vvi;
typedef pair <ll, ll> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;


int e[8] = {1,-1,1, -1, 2,2,-2,-2};
int z[8] = {2, 2,-2, -2, 1,-1,1,-1};

ll n, k;
vii w;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin>>t;
    while(t--){
        cin>>n>>k;
        w = vii(n);
        ll sum = 0;
        for (int i = 0; i < n; ++i)
        {
            /* code */
            ll x, y;
            cin>>x>>y;
            w[i].fi = y;
            w[i].se = x;
            sum+=y;
        }
        sort(w.begin(), w.end());
        vi dp(sum+1, eps);

        dp[0] = 0;
        ll maxm = 0;
        for (int i = 0; i < n; ++i)
        {
            /* code */
            for(int v = sum-w[i].fi; v>=0; v--){
                dp[v+w[i].fi] = min(dp[v+w[i].fi], w[i].se+dp[v]);
            }
        }
        for (int i = 0; i < sum+1; ++i)
        {
            /* code */
            if(dp[i]<=k){
                maxm = max(maxm, (ll)i);
            }
        }
        cout<<maxm<<endl;




    }

}



Measured memory_bytes: 1024
#include<stdio.h>
int main(void){

	int n,m,i,j,flag;
	char ah[70],bh[70],de;

	while(1){
		scanf("%d ",&n);
		if(!n) break;
		for(i=0;i<n;i++){
			scanf("%c %c ",&ah[i],&bh[i]);
		}
		scanf("%d ",&m);
		for(i=0;i<m;i++){
			scanf("%c ",&de);
			flag=0;
			for(j=0;j<n;j++){
				if(de==ah[j]){
					printf("%c",bh[j]);
					flag=1;
					break;
				}
			}
			if(!flag) printf("%c",de);
		}
		puts("");
	}
	return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> prev(n);
    vector<int> dist(n);
    queue<int> que;

    // BPS
    int MAX_DIST = 10000000;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            dist[i] = 0;
        } else {
            dist[i] = MAX_DIST;
        }
    }
    que.push(0);

    unordered_set<int> not_visited;
    for (int i = 0; i < n; i++) {
        not_visited.insert(i);
    }

    while (!que.empty()) {
        int u = que.front();
        que.pop();

        // visited
        if (not_visited.find(u) == not_visited.end()) {
            continue;
        }
        for (int v: to[u]) {
            int d = dist[u] + 1;
            if (dist[v] > d) {
                dist[v] = d;
                prev[v] = u;
                que.push(v);
            }
        }
        not_visited.erase(u);
        if (not_visited.size() == 0) {
            break;
        }
    }

    // for (int i = 0; i < n; i++) {
    //     if (dist[i] >= MAX_DIST) {
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            cout << "Yes" << endl;
        } else {
            cout << (prev[i] + 1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 14704
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  ll n,a,ans=0;
  cin>>n;
  for(ll i=0;i<n;i++){
    cin>>a;
    ans+=(a-1);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a<b){
    if(b<c){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 580
import java.io.*;
import java.util.*;

public class Main{

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

	int n=Integer.parseInt(br.readLine());

	matrix=new int[n+1][n+1];
	p=new int[n+1];

	for(int i=1;i<=n;i++){
	    String str[]=br.readLine().split(" ");

	    int r=Integer.parseInt(str[0]);
	    int c=Integer.parseInt(str[1]);

	    p[i-1]=r;
	    p[i]=c;
	}
	matrixCM(n);

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

    static void matrixCM(int n){
	for(int i=1;i<=n;i++){
	    matrix[i][i]=0;
	}

	for(int l=2;l<=n;l++){
	    for(int i=1;i<=n-l+1;i++){
		int j=i+l-1;
		matrix[i][j]=Integer.MAX_VALUE;
		for(int k=i;k<j;k++){
		    matrix[i][j]=Math.min(matrix[i][j],matrix[i][k]+matrix[k+1][j]+p[i-1]*p[k]*p[j]);
		}
	    }
	}
    }
}



Measured memory_bytes: 24556
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int maxn = 1e6+10;
LL n,t,a,b,c,d;
map<LL,LL>mp;
LL dfs(LL x){
    if(x==0) return 0;
    if(x==1) return d;
    if(mp.count(x)) return mp[x];

    LL l2 = (x/2)*2;
    LL r2 = ((x+1)/2)*2;
    LL l3 = (x/3)*3;
    LL r3 = ((x+2)/3)*3;
    LL l5 = (x/5)*5;
    LL r5 = ((x+4)/5)*5;

    LL res=1e18;
    if(res/d>x)res=x*d;

    res=min(res,dfs(l2/2)+(x-l2)*d+a);
    res=min(res,dfs(r2/2)+(r2-x)*d+a);

    res=min(res,dfs(l3/3)+(x-l3)*d+b);
    res=min(res,dfs(r3/3)+(r3-x)*d+b);

    res=min(res,dfs(l5/5)+(x-l5)*d+c);
    res=min(res,dfs(r5/5)+(r5-x)*d+c);

    mp[x]=res;
    return res;
}

int main(){
//    op;
    scanf("%lld",&t);
    while(t--) {
        mp.clear();
        scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
//        cout<<n<<" "<<b<<" "<<c<<" "<<d<<endl;
        printf("%lld\n",dfs(n));
    }
    return 0;
}

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

int n,q;
string s;
vector<pair<char,char>> p(200100);

int del(int now){
    for(int i = 0;i < q;i++){
        if(s[now] == p[i].first){
            if(p[i].second == 'R') now++;
            else now--;
        }
        if(now < 0) return -1;
        if(now >= n) return 1;
    }
    return 0;
}

int main(void){
    cin >> n >> q >> s;
    for(int i = 0;i < q;i++){
        cin >> p[i].first >> p[i].second;
    }
    
    int left = -1,right = n+1,tmp;
    while(right-left > 1){
        int mid = (right+left)/2;
        if(del(mid) == -1) left = mid;
        else right = mid;
    }
    tmp = right;
    
    
    left = -1,right = n+1;
    int tmp2;
    while(right-left > 1){
        int mid = (right+left)/2;
        if(del(mid) == 1) right = mid;
        else left = mid;
    }
    tmp2 = right;
    
    cout << tmp2-tmp << endl;
    return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
def main():
    import sys

    input = sys.stdin.readline

    A, B, C, K = map(int, input().split())

    if K <= A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A - (K - A - B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
import fractions
A, B = map(int, input().split())
f=fractions.gcd(A,B)

ans = 1
i = 2
while i ** 2 <= f:
    if f % i == 0:
        ans += 1
    while f % i == 0:
        f = f//i
    i += 1

ans +=(f>1)
print(ans)

Measured memory_bytes: 5176
n,m = map(int,input().split())
a = 1
b = 1+m
c = 2+m
d = 1+2*m
for i in range(m):
    if i%2 == 0:
        print(str(a)+' '+str(b))
        a += 1
        b -= 1
    else:
        print(str(c)+' '+str(d))
        c += 1
        d -= 1

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

int cost[11] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};


int main() {

    int N, M;
    int A[9];

    cin >> N >> M;
    
    for (int i = 0; i < M; i++) {
        cin >> A[i];
    }

    vector<int> dp(10001);
    dp[0] = 0;
    for (int i = 1; i <= N; i++) {
        dp[i] = -100000;
        for (int j = 0; j < M; j++) {
            if ( i >= cost[A[j]]){
                dp[i] = max(dp[i - cost[A[j]]] + 1, dp[i]);
            }
        }
    }
    sort(A, A + M, greater<int>());
    int index = N;
    string str;
    for (int i = 0; i < dp[N]; i++) {

        for (int j = 0; j < M; j++) {

            int n = cost[A[j]];
            if (index >= n and dp[index - n] == dp[index] - 1) {

                index -= n;
                str += A[j] + '0';
                break;
            }
        }
    }
    cout << str << '\n';
}


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

int main() {
	vector<int> v(3);

	for (int i = 0; i < 3; i++) {
		cin >> v.at(i);
	}

	sort(v.begin(), v.end());

	cout << v.at(0) + v.at(1) << endl;


	return 0;
}

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

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

	rep(i,(n-1)/2){
		if(s[i] != s[n-i-1]) {
			cout << "No\n";
			return 0;
		}
	} 
	rep(i,(n-1)/4){
		if(s[i] != s[(n-1)/2 - i -1]){
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int N,M;
    cin>>N>>M;
    int a[M];
    int b[M];
    rep(i,M){
        cin>>a[i];
        cin>>b[i];
    }
    rep(i,N){
        cout<<count(a,a+M,i+1)+count(b,b+M,i+1)<<endl;
    }
}


Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>

int n, s;
bool numbers[10] = { true };
int ans;

void dfs(int sum, int i, int num){
	if (i == n){
		if (sum == s) ans++;
		return ;
	}
	for (int j = num+1; j < 10; ++j){
		if(sum + j <= s)dfs(sum + j, i + 1,j);
	}
}

int main(){
	while (std::cin >> n >> s){
		if (n == 0 && s == 0)break;
		ans = 0;
		dfs(0, 0, -1);
		std::cout << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;  //これで"std::cout"が"cout"と書ける

//MACRO
typedef long long ll;                  //64bit以上を表現可能な型
#define INF 100000000                  //ほぼ無限
#define itn int                        //タイポ対策
#define ALL(x) (x).begin(), (x).end()  //sort(all(x))などとする
#define SZ(x) ((int)(x).size())        //size()簡略化
//repetition
#define FOR(i, p, b) for (int i = (p); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repR(i, n) for (int i = n; i >= 0; i--)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \<< " " << __FILE__ << endl;
template <class T>
bool chMAX(T &a, const T &b) {  //aよりbが大きければaに代入(参照渡し)
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chMIN(T &a, const T &b) {  //aよりbが小さければaに代入//参照渡し
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int ctoi(const char c) {  //CtoI(int) charを渡すとintに変換する、数字以外だと-1を返す
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}

//
//
//

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<char> alf = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

    rep(i, SZ(s)) {
        rep(j, SZ(alf)) {
            if (s[i] == alf[j]) {
                s[i] = alf[(j + n) % SZ(alf)];
                break;
            }
        }
    }
    cout << s << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	string s;
	cin >> n >> s >> q;
	vector<set<int>> v(26);
	rep(i,n){
		v[(s[i] - 'a')].insert(i);
	}
	int k, i, l, r;
	char c;
	rep(loop,q){
		cin >> k;
		if(k == 1){
			cin >> i >> c;
			i--;
			v[(s[i] - 'a')].erase(i);
			s[i] = c;
			v[(s[i] - 'a')].insert(i);
		}
		else{
			cin >> l >> r;
			l--; r--;
			int ans = 0;
			rep(j,26){
				auto it = v[j].lower_bound(l);
				if(it != v[j].end() && *it <= r) ans++;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 24348
#include <stdio.h>

int main(void) {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int max = a;
	if(b > max) max = b;
	if(c > max) max = c;
	printf("%d\n", a+b+c-max);
	return 0;
}

Measured memory_bytes: 128
import itertools

n = int(input())
c1 = tuple(map(int,input().split()))
c2 = tuple(map(int,input().split()))
a = []
for i in range(n):
    a.append(i + 1)

b=list(itertools.permutations(a))

for i in range(len(b)):
    if(c1 == b[i]):
        k1 = i
    if(c2 == b[i]):
        k2 = i
    

ans = abs(k1 -k2)
print(ans)


Measured memory_bytes: 8052
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    string A,B;
    while(cin>>A>>B){
        int hit=0,blow=0;
        if(A=="0")break;
        for(int i=0;i<4;i++){
            if(A[i]==B[i]){
                hit++;
                A[i]='A';B[i]='B';
            }
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(A[i]==B[j]){
                    blow++;
                    B[j]='B';
                    break;
                }
            }
        }
        cout<<hit<<" "<<blow<<endl;
    }

    return 0;
}

Measured memory_bytes: 1184
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		a: isize,
		b: isize,
		c: isize,
	}

	if a == b {
		println!("{}", c);
		return;
	}
	if a== c {
		println!("{}", b);
		return;
	}
	println!("{}", a);
}



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

int h,w,n;

inline int origin(int a, int b){
  int left = (a&1)==(b&1) ? 1 : 0;
  int rem = left ? b : w-1-b;
  if(rem >= a){
    if(left)return rem-a;
    else return b+a;
  }
  a -= rem;

  int rev = (a/w)&1;
  rem = a%w;
  if(left == 1-rev)return max(0,rem-1);
  else return min(w-1,w-rem);
}

int main(){
  scanf("%d%d%d",&h,&w,&n);
  vector< pair<int,int> > bars(n);
  for(int i=0;i<n;i++){
    int a,b; scanf("%d%d",&a,&b); a--; b--;
    bars[i] = make_pair(a,b);
  }
  sort(bars.begin(),bars.end());


  vector<int> perm(w);
  for(int i=0;i<w;i++)perm[i] = i;

  for(int i=0;i<n;i++){
    int a = origin(bars[i].first, bars[i].second);
    int b = origin(bars[i].first, bars[i].second+1);
    swap(perm[a],perm[b]);
  }

  vector<int> inv_perm(w);
  for(int i=0;i<w;i++)inv_perm[perm[origin(h,i)]] = i;

  for(int i=0;i<w;i++)printf("%d\n",inv_perm[i]+1);
}

Measured memory_bytes: 4160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Search(int i, int x, List<int> P)
        {
            foreach (int p in P)
            {
                if (p >= x) { return p; }
            }
            return -1;
        }

        static int Solve(int N, string S)
        {
            var p = new List<int>[10];
            for (int i = 0; i < 10; ++i) { p[i] = new List<int>(); }
            for (int i = 0; i < N; ++i)
            {
                p[S[i] - '0'].Add(i);
            }
            int cnt = 0;
            for (int i = 0; i < 10; ++i)
            {
                int x = Search(i, 0, p[i]);
                if (x < 0) { continue; }
                for (int j = 0; j < 10; ++j)
                {
                    int y = Search(j, x + 1, p[j]);
                    if (y < 0) { continue; }
                    for (int k = 0; k < 10; ++k)
                    {
                        int z = Search(k, y + 1, p[k]);
                        if (z >= 0) { ++cnt; }
                    }
                }
            }
            return cnt;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            var S = Read();
            Console.WriteLine(Solve(N, S));
        }
    }
}


Measured memory_bytes: 13408
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>

using namespace std;
typedef long long ll;
#define MP make_pair

int main(void) {
    int s,w;
    cin>>s>>w;

    if(w>=s)cout<<"unsafe\n";
    else cout<<"safe\n";
    
    
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define ff first 
#define endl "\n"
#define ss second 
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int,int>
#define vii vector<pair<int,int> >
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom  pair<int,pair<int,int> >
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
#define mod 1000000007
ll power(int a,int n,int m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans*a)%m;
        }
        n=n>>1;
        a=((a%m)*(a%m))%m;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll dp[n]={0};
    dp[0]=0;
    int op1,op2;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        op1=abs(arr[i]-arr[i-1]);
        op2=abs(arr[i]-arr[i-2]);
        dp[i]=min(dp[i-1]+op1,dp[i-2]+op2);
    }
    cout<<dp[n-1];
    return 0;
}

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

int main(){
    ll n, d;
    cin>>n>>d;
    ll r = d*2 + 1; 
    ll ans;
    if(n%r==0){
        ans = n/r;
    }else{
        ans= n/r + 1;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
  string input; cin >> input;
  long long ans = 0;
  int n = input.size();

  for (int i = 0; i < (1<<n-1); i++) {
    int idx = 0;
    for (int j = 0; j < n-1; j++) {
      if(i & (1<<j)) {
        ans += stoll(input.substr(idx, j-idx+1));
        idx = j+1;
      }
    }
    ans += stoll(input.substr(idx, input.size()));
  }

  cout << ans << endl;
}


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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.rbegin(),a.rend());
	vector<ll> b;
	REP(i,n-1){
		b.push_back(a[i]);
		b.push_back(a[i]);
	}
	ll ans = a[0];
	rep(i,n-2){
		ans += b[i];
	}
	cout << ans << endl;
    return 0;
}



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

using namespace std;

int main() {
	long long n;
	cin >> n;

	int ans = 0;

	for(long long i = 2; i * i <= n; ++i) {
		if(n % i == 0) {
			int cnt = 0;
			while(n % i == 0) {
				n /= i;
				cnt += 1;
			}
			int j = 1;
			while(cnt >= j) {
				cnt -= j;
				j += 1;
				ans += 1;
			}
		}
	}

	if(n > 1) {
		ans += 1;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3624