akhauriyash/Code-Regression huggingface dataset:
program main
  implicit none
  integer :: H,M
  integer :: hs,ws
  integer,allocatable :: mass(:,:)
  integer :: i
  read(*,*) H,M
  read(*,*) hs,ws
  allocate(mass(H,M))

  mass = 1
  do i = 1,hs
     mass(i,:) = 0
  end do
  do i = 1,ws
     mass(:,i) = 0
  end do

  write(*,'(i0)')sum(mass)

  stop
end program main


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int a[200],b[200],v1[200],v2[200];
struct node
{
	string x;
}s[100+5];
node t[100+5];
int main()
{
	int n,m;//n-赚,m-亏
	int i,j,sum=0,M,ans=-100000;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		cin>>s[i].x;
	scanf("%d",&m);
	for(i=1;i<=m;i++)
		cin>>t[i].x;
	if(m>n)
		M=m;
	else
		M=n;
	for(i=1;i<=M;i++)
	{
		sum=0;
		if(!v1[i])
		{
			for(j=1;j<=n;j++)
			{
				if(!v1[j]&&s[j].x==s[i].x)
				{
					sum++;
					v1[j]=1;
				}
			}
			v1[i]=1;
			for(j=1;j<=m;j++)
			{
				if(!v2[j]&&t[j].x==s[i].x)
				{
					sum--;
					v2[j]=1;
				}
			}
		}
		if(sum>ans)
			ans=sum;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;

int used[1000];

void solve(){
	int x,n;
	cin>>x>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		used[a[i]]=1;
	}
	if(!used[x]){
		cout<<x;
		return;
	}
	int mx=1e9,ans=0;
	for(int i=0;i<=200;i++){
		if(!used[i]){
			if(abs(i-x)<mx){
				mx=abs(i-x);
				ans=i;
			}
		}
	}
	cout<<ans;

}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x <= W - r && y <= H - r && x - r >= 0 && y - r >= 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define M 100005
int n,i,a[M],x;
int main() {
	scanf("%d",&n);
	for(i=1; i<=n; i++) {
		scanf("%d",&a[i]);
		if(i&1)x-=a[i];
		else x+=a[i];
	}
	for(x=-x,i=1; i<=n; i++) {
		printf("%d",x);
		if(i!=n)printf(" ");
		else printf("\n");
		x=2*a[i]-x;
	}
	return 0;
}

Measured memory_bytes: 1664
from heapq import heappush, heappop

infi = 10 ** 20
n, m, s = map(int, input().split())

s = min(s, 2500)

edges = [[] for _ in range(51 * 2501 + 1)]
# edge:1-50, max silver=0-2500

for _ in range(m):
    u, v, a, b = map(int, input().split())
    for i in range(a, 2501):
        edges[v + 50 * i].append((b, u + 50 * (i - a)))
        edges[u + 50 * i].append((b, v + 50 * (i - a)))


for edge_num in range(1, n + 1):
    c, d = map(int, input().split())
    # c枚, d分
    for i in range(2501):
        # 点edge_num+ i * 50のところに
        if edge_num + (i + c) * 50 <= 51 * 2501:
            edges[edge_num + i * 50].append((d, edge_num + min((i + c), 2500) * 50))
start = 1 + 50 * s


def dijkstra(edges, start):
    time = [infi] * (51 * 2501 + 1)
    used = [False] * (51 * 2501 + 1)
    time[start] = 0
    edgelist = []
    heappush(edgelist, (0, start))
    while edgelist:
        nowtime, nowedge = heappop(edgelist)
        if used[nowedge] is True:
            continue
        used[nowedge] = True
        time[nowedge] = nowtime
        for vt, v in edges[nowedge]:
            if used[v] is True:
                continue
            newtime = nowtime + vt
            heappush(edgelist, (newtime, v))
    return time


time = dijkstra(edges, start)

ans = [infi] * (51)
for i in range(1, 51 * 2501 + 1):
    temp = time[i]
    a = i % 50
    if a == 0:
        a += 50
    ans[a] = min(temp, ans[a])

print(*ans[2 : (n + 1)], sep="\n")


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

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

    ll a, b, v, w, t;

    cin >> a >> v >> b >> w >> t;

    ll diff = 0;
    diff = abs(a-b);

    if (v*t >= diff + w*t) cout << "YES" << "\n";
    else cout << "NO" << "\n";

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<MAX; i++){
		fac[i] = fac[i-1]*i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		finv[i] = finv[i-1] * inv[i] % mod;
	}
}


ll com(ll n, ll k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
	ll n,m,k; cin >> n >> m >> k;
	comInit();
	ll sum = 0;
	REP(i,1,m){
		sum += n*n%mod*i%mod*(m-i)%mod;
		sum %= mod;
	}
	REP(i,1,n){
		sum += m*m%mod*i%mod*(n-i)%mod;
		sum %= mod;
	}
	cout << sum*com(n*m-2,k-2)%mod << endl;
}

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

class Set
{
private:
    struct Node
    {
        Node(shared_ptr<Node> par_, shared_ptr<Node> left_, shared_ptr<Node> right_, int val) :
            par(par_), left(left_), right(right_), key(val){}
        shared_ptr<Node> par, left, right;
        int key;
    };
    
    void preorder(shared_ptr<Node>& x){
        cout << ' ' << x->key;
        if(x->left != nullptr){
            preorder(x->left);
        }
        if(x->right != nullptr){
            preorder(x->right);
        }
    }
    
    void inorder(shared_ptr<Node>& x){
        if(x->left != nullptr){
            inorder(x->left);
        }
        cout << ' ' << x->key;
        if(x->right != nullptr){
            inorder(x->right);
        }
    }
    
public:
    Set():size(0){}
    void insert(int val){
        if(size == 0){
            root = make_shared<Node>(nullptr, nullptr, nullptr, val);
        } else {
            shared_ptr<Node> y = nullptr;
            shared_ptr<Node> x = root;
            while(x != nullptr){
                y = x;
                if(val < x->key){
                    x = x->left;
                } else {
                    x = x->right;
                }
            }
            
            if(val < (y->key)){
               y->left = make_shared<Node>(y,nullptr,nullptr,val);
            } else {
               y->right = make_shared<Node>(y,nullptr,nullptr,val);
            }
        }
        ++size;
    }


    void print(){
        if(size == 0) return;
        inorder(root);
        cout << endl;
        preorder(root);
        cout << endl;
    }
    
private:
    shared_ptr<Node> root;
    int size;
};

int main()
{
    ios_base::sync_with_stdio(false);
    int n, k;
    string s;
    Set set;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> s;
        if(s == "insert"){
           cin >> k;
           set.insert(k);
        } else {
            set.print();
        }
    }
}

Measured memory_bytes: 48104
import collections
import operator

N = int(input())
D = list(map(int, input().split()))

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

# l = []
# for i in range(int(max(D))):
#     if D_dict_sorted[i][0] + 1 == D_dict_sorted[i+1][0]
#     l.append()

if (D[0] == 0) and (D_dict_sorted[0][1] == 1) :
    ans = 1
    for i in range(len(D_dict_sorted)-1):
        if D_dict_sorted[i][0] + 1 == D_dict_sorted[i+1][0]:
            ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1]
            if ans >= 998244353:
                ans = ans % 998244353
        else:
            ans = 0
else:
    ans = 0

print(ans)

Measured memory_bytes: 21980
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("in","r",stdin);
	string a,b; cin >> a >> b;
	int cnt1,cnt2; cin >> cnt1 >> cnt2;
	string c; cin >> c;
	if(c==a) cout << cnt1-1 << " " << cnt2 << endl;
	else cout << cnt1 << " " << cnt2-1 << endl;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            long a_cookies = long.Parse(input[0]);
            long b_cookies = long.Parse(input[1]);
            long k_action = long.Parse(input[2]);

            long has_a = 0;
            long has_b = 0;

            if (a_cookies - k_action < 0)
            {
                k_action -= a_cookies;
                has_a = 0;

                if (b_cookies - k_action < 0)
                {
                    has_b = 0;
                } else
                {
                    has_b = b_cookies - k_action;
                }


            } else
            {
                has_a = a_cookies - k_action;
                has_b = b_cookies;
            }

            Console.WriteLine(has_a + " " + has_b);

        }
    }
}


Measured memory_bytes: 13140
/*
s[r] - s[l] = r - l (mod k)
s[r] - r = s[l] - l (mod k)
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 200010;

int n, k;
ll s[N];
map<ll,ll>S;

int main() {
	cin >> n >> k;
	for(int i = 1, x; i <= n; ++i) {
		cin >> x;
		s[i] = s[i - 1] + x;
	}
	S[0] = 1;
	ll ans = 0;
	int l = 0;
//	for(int i = 1; i <= n; ++i) printf("%d ", (s[i] - i + k) % k);
//	puts("");
	for(int i = 1; i <= n; ++i) {
		if(i >= k) {S[(s[l] - l + k) % k]--; ++l;}
		ans += S[(s[i] - i + k) % k];
//		printf("%d ", S[(s[i] - i + k) % k]);
		S[(s[i] - i + k) % k]++;
	}//puts("");
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 14336
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
const int INF=1001001001001001;
int N,M,C;//?????´??? N ???????????? M ??¬???????????°???????????´?????????????????¢????????´??°??? C
struct node{
    int to;
    int cost;
};
struct road{
    int d;
    int t1,t2;
};
int m=0;//???????????????????¨??????????
road roads[200002];//???????????±?????????????????????
vector<pair<int,int> > R;//?????????????????????????????????????????????????????????????????¢??¨??????????????????????????????????????¨
vector<node> nodes[100002];//dijkstra??¨
int d[100002];//???????????¢??????
vector<int > ds;//?????¢????????????????????¨
class JOIpark{
    private:
    void dijkstra(int s){
        fill(d,&d[N],INF);
        priority_queue< pair<int,int> , vector< pair<int,int> > ,greater<pair<int,int> > > que;
        que.push( mp(0,s) );
        while(que.size() ){
            pair<int,int> p=que.top(); que.pop();
            int v=p.second;int c=p.first;
            if(d[v]<c)continue;
            d[v]=c;
            ds.push_back(d[v] );//////////
            rep(i,nodes[v].size()){
                int t=nodes[v][i].to;
                if(d[v]+nodes[v][i].cost<d[t]){
                    d[t]=d[v]+nodes[v][i].cost;
                    que.push(mp(d[t],t) );
                }
            }
        }
    }
    public:
    int solve(){
        int ans=INF;
        scanf("%lld %lld %lld",&N,&M,&C);
        
        rep(i,M){
            int a,b,d;
            scanf("%lld %lld %lld",&a,&b,&d);
            m+=d;
            a--;b--;
            roads[i].d=d;roads[i].t1=a;roads[i].t2=b;
            node n;
            n.to=b;n.cost=d;
            nodes[a].push_back(n);
            n.to=a;
            nodes[b].push_back(n);
        }
        dijkstra(0);
        sort(ds.begin(),ds.end() );
        rep(i,M){//??????????????????????????¢???????????????x??\???????????¢???????????¨?????????????¶??????????????????¨?????????x?????????
            int a=roads[i].t1;int b=roads[i].t2;
            int k=max(d[a],d[b]);
            R.push_back( mp(k,roads[i].d) );
        }
        sort(R.begin(),R.end());
        int t=0;//??????????????????????????????
        rep(i,N){
            if(d[i]==d[i+1])continue;//???????????¢???????????????????????????
            int x=ds[i];
            int sans=0;
            sans=C*x;
            for(;R[t].first<=x&&t<R.size();t++){
                m-=R[t].second;//???????¶??????????????????¨?????¨???
            }
            sans+=m;
            ans=min(sans,ans);
        }
        return ans;
    }
};
signed main(void){
    JOIpark ans;
    printf("%lld\n",ans.solve());
}

Measured memory_bytes: 25584
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int LCS(string X, string Y){
    int m = X.length();
    int n = Y.length();
    int C[m+1][n+1];
    int ans = 0;
    
    for(int i = 0; i <= m; i++) C[i][0] = 0;
    for(int i = 1; i <= n; i++) C[0][i] = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            
            if(X[i-1] == Y[j-1]){
                C[i][j] = C[i-1][j-1] + 1;
            } 
            else if(C[i-1][j]> C[i][j -1]) {
                C[i][j] = C[i-1][j];
            }
            else C[i][j] = C[i][j-1];
            
            if(ans < C[i][j]) ans = C[i][j];
        }
    }
    
    return ans;
    
}
int main(){
    string x,y;
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> x >> y;
        cout << LCS(x,y) << endl;
    }
    return 0;
}


Measured memory_bytes: 7144
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b <= a+c && a+b <= b+c)
    cout << a+b << endl;
  else if(a+c <= a+b && a+c <= b+c)
    cout << a+c << endl;
  else
    cout << b+c << endl;
}


Measured memory_bytes: 256
W, H, N = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(N)]
S = [0,0]
F = [W,H]

def adjust(x, y, a, S, F):
	if a == 1:
		S[0] = max(x, S[0])
	elif a == 2:
		F[0] = min(x, F[0])
	elif a == 3:
		S[1] = max(y, S[1])
	else:
		F[1] = min(y, F[1])

for l in L:
	adjust(l[0], l[1], l[2] ,S ,F)

dX = F[0]-S[0]
dY = F[1]-S[1]

if dX <= 0 or dY <= 0:
	print(0)
else:
	print(dX*dY)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#define int long long
#define P pair<int,int>
using namespace std;

int a[100000];
vector<int>r[100000];
int d[100000];
int p[100000];
vector<P>W;
vector<int>V[100000];
void DFS(int x) {
	for (int y : r[x]) {
		if (d[y] == -1) {
			p[y] = x;
			d[y] = d[x] + 1;
			DFS(y);
		}
	}
}
signed main() {
	int n; scanf("%lld", &n);
	for (int b = 0; b < n; b++)scanf("%lld", &a[b]);
	for (int b = 1; b < n; b++) {
		int x, y; scanf("%lld%lld", &x, &y); x--; y--;
		r[x].push_back(y);
		r[y].push_back(x);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0;
	DFS(0);
	for (int i = 0; i < n; i++) {
		W.push_back({ d[i],i });
	}
	sort(W.begin(), W.end(), greater<P>());
	for (P t : W) {
		if (V[t.second].size() == 0) {
			V[p[t.second]].push_back(a[t.second]);
		}
		else {
			int sum = 0;
			for (int i : V[t.second]) {
				sum += i;
			}
			if (sum < a[t.second]) {
				puts("NO");
				return 0;
			}
			int need = (sum - a[t.second]);//作るペアの数
			if (t.second == 0 && V[t.second].size() == 1) {
				if (V[t.second][0] == a[t.second]) {
					puts("YES");
				}
				else puts("NO");
				return 0;
			}
			if (t.second == 0) {
				int MAX = 0;
				for (int i : V[t.second]) {
					MAX = max(MAX, i);
				}
				MAX = min(sum - MAX, sum / 2);
				if (MAX < need) { puts("NO"); return 0; }
				if (sum - need * 2 == 0)puts("YES");
				else puts("NO");
				return 0;
			}
			int MAX = 0;
			for (int i : V[t.second]) {
				MAX = max(MAX, i);
			}
			MAX = min(sum - MAX, sum / 2);
			if (MAX < need) { puts("NO"); return 0; }
			V[p[t.second]].push_back(sum - need * 2);
		}
	}
	puts("YES");
}

Measured memory_bytes: 17776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  string S;
  cin>>N>>S;
  int R=0;
  rep(i,N) if(S[i]=='R') R++;
  if(R>N/2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define ll long long

using namespace std;

const int MAXN = 200010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m, k;
int tot, cnt;

int a[MAXN], f[MAXN], ans[MAXN];
int head[MAXN];

struct edge {
	int to, next;
}e[MAXN * 2];

void add_edge(int x, int y) {
	e[++tot].to = y;
	e[tot].next = head[x];
	head[x] = tot;
	return;
}

void Dfs(int x, int fa) {
	int last;
	int l = 1, r = ans[fa], mid;
	if (!fa) f[1] = a[x], ans[1] = 1;
	else {
		while (l <= r) {
			mid = (l + r) >> 1;
			if (a[x] <= f[mid]) r = mid - 1;
			else l = mid + 1;
		}
		last = f[l];
		f[l] = a[x];
		ans[x] = ans[fa];
		if (l > ans[fa]) ++ans[x];
	}
	for (int i = head[x]; i; i = e[i].next) {
		int v = e[i].to;
		if (v != fa) Dfs(v, x);
	}
	f[l] = last;
	return;
}

int main(){
	int t;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d%d", &u, &v);
		add_edge(u, v);
		add_edge(v, u);
	}
	
	Dfs(1, 0);
	
	for (int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}



Measured memory_bytes: 23684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 1e6+10;
int N;
ll num[MAX_N];

void cal(int x)
{
	int res=0;
	bool f = false;
	for(int i=1;i*i<=x;++i){
		if(x%i==0){
			res+=2;
		}
	    if(i*i==x){
	        f=true;
	    }
	}
	if(f) res--;
	num[x]=res;
}

void solve()
{
	for(int i=1;i<=N;++i) cal(i);
	ll res = 0;
	for(int c=1;c<N;++c){
		res += num[N-c];
	}
	cout<<res<<'\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> N;
	solve();
	return 0;
}

Measured memory_bytes: 11424
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    BContests solver = new BContests();
    solver.solve(1, in, out);
    out.close();
  }

  static class BContests {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int a = in.nextInt();
      int b = in.nextInt();
      List<Integer> set = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        set.add(in.nextInt());
      }
      int countA = 0;
      int countB = 0;
      int countC = 0;
      for (Integer integer : set) {
        if (integer <= a) {
          countA++;
        } else if (integer <= b) {
          countB++;
        } else {
          countC++;
        }
      }
      out.println(Math.min(countA, Math.min(countB, countC)));
    }

  }

  static class InputReader implements AutoCloseable {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      //reader = new BufferedReader(new FileReader(stream), 32768);
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public void close() {
    }

  }
}



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

using namespace std;

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

int H, W;
string field[10];
int dx[] = {1, 0};
int dy[] = {0, 1};
int cnt;

void dump(){
  rep(i,H){
    rep(j, W){
      cout << field[i][j];
    }
    puts("");
  }
  puts("");
}

void check(){
  rep(i,H){
    rep(j, W){
      if(field[i][j]=='#'){
	cout << "Impossible" << endl;
	exit(0);
      }
    }
  }
  cout << "Possible" << endl;    
  exit(0);
}
void solve(int x, int y){

  field[y][x] = '.';
  

  if(x == W-1 && y == H-1){
    check();
  }

  if(field[y+1][x]=='#' && field[y][x+1]=='#') return;

  rep(i, 2){
    int nx = x + dx[i]; int ny = y + dy[i];
    if(0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx]=='#'){
      solve(nx, ny);
    }
  }
}


int main(){
  cin >> H >> W;
  
  rep(i, H) cin >> field[i];
  
  solve(0,0);
  
  check();
}


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

int main(){
  string S;
  cin >> S;
  bool a=false;
  for(int i=0;i<S.size()-1;i++){
    for(int j=i+1;j<S.size();j++){
      if(S.at(i)=='C' && S.at(j)=='F'){
        a=true;
      }
    }
  }
  if(a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}   

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

int main(){
  int a,b,c;
  int k;
  int f=-1;
  cin >> a >> b >> c;
  cin >> k;

  while(k>0){
    if(a>=b){
      b=b*2;
    }else if(b>=c){
      c=c*2;
    }

    if((a<b)&&(b<c)){
      f=1;
      break;
    }

    k--;
  }
  if(f==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" <<endl;
  }
  return(0);
}


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

void BubbleSort(vector< pair<char, int> > &C)
{
    int N = C.size();
    for (int i = 0; i < N; ++i)
    {
        for (int j = N - 1; j > i; --j)
        {
            if (C[j].second < C[j - 1].second)
            {
                iter_swap(C.begin() + j, C.begin() + j - 1);
            }
        }
    }
}

void SelectionSort(vector< pair<char, int> > &C)
{
    int N = C.size();
    for (int i = 0; i < N; ++i)
    {
        vector< pair<char, int> >::iterator minj = C.begin() + i;
        for (int j = i; j < N; ++j)
        {
            if (C[j].second < minj->second)
            {
                minj = C.begin() + j;
            }
        }
        iter_swap(C.begin() + i, minj);
    }
}

int main()
{
    int N;
    vector< pair<char, int> > A;
    vector< pair<char, int> > B;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        string temp;
        cin >> temp;
        pair<char, int> p = make_pair(temp[0], int(temp[1] - '0'));
        A.push_back(p);
    }
    B = A;
    BubbleSort(A);
    for (int i = 0; i < N; ++i)
    {
        if (i == N - 1)
        {
            cout << A[i].first << A[i].second << endl;
        }
        else
        {
            cout << A[i].first << A[i].second << " ";
        }
    }
    cout << "Stable" << endl;
    SelectionSort(B);
    for (int i = 0; i < N; ++i)
    {
        if (i == N - 1)
        {
            cout << B[i].first << B[i].second << endl;
        }
        else
        {
            cout << B[i].first << B[i].second << " ";
        }
    }
    if (B != A)
    {
        cout << "Not stable" << endl;
    }
    else
    {
        cout << "Stable" << endl;
    }
}


Measured memory_bytes: 3152
#include<iostream>
using namespace std;
int main(void)
{
  int w,a,b;
  cin>>w>>a>>b;
  int x=b-(a+w);
  int y=a-(b+w);
  if(a+w<b)
    cout<<b-(a+w)<<endl;
  else if(a<b || a<b+w)
    cout<<0<<endl;
  else
    cout<<a-(b+w)<<endl;
  return 0;
      
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
int main(){
      int n,ans = INT_MIN,minnum = INT_MAX,tmp;
      cin >> n;
      for(int i= 0;i<n;i++){
            cin >> tmp;
            if(i!=0) ans = max(ans,tmp - minnum);
            minnum = min(tmp,minnum);
      }
      cout << ans << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;string s;cin>>s;
    vector<int> a(n,0),b(n,0);
    rep(i,n){
        if(s[i]=='W')a[i]++;
        else b[i]++;
    }
    reverse(b.begin(),b.end());
    rep(i,n-1){
        a[i+1]+=a[i];
        b[i+1]+=b[i];
    }
    reverse(b.begin(),b.end());
    int res=1e6;
    rep(i,n)chmin(res,(a[i]+b[i]-1));
    cout<<res<<endl;
}

Measured memory_bytes: 6152
def add(lhs: int, rhs: int) -> int:
    return lhs + rhs


def sub(lhs: int, rhs: int) -> int:
    return lhs - rhs


def multiply(lhs: int, rhs: int) -> int:
    return lhs * rhs


def divide(lhs: int, rhs: int) -> int:
    return int(lhs / rhs)


op_map = {'+': add, '-': sub, '*': multiply, '/': divide}

while True:
    in_str = input()
    a, op, b = in_str.split()
    if op == '?':
        exit()
    a = int(a)
    b = int(b)
    ans = op_map[op](a, b)
    print(ans)



Measured memory_bytes: 5596
marks = "SHCD"
cards = { 'S':{}, 'H':{}, 'C':{}, 'D':{} }

N = int(input())

for _ in range(N):
    m, n = input().split()
    cards[m][int(n)] = n

for m in marks:
    for i in range(1, 14):
        if i not in cards[m]:
            print(m, i)



Measured memory_bytes: 5596
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;
const long long INF = (1e18);

int main(){
  int N;
  while(cin >> N, N){
    map< pair<long long, long long>, long long > F;
    map< long long, vector< pair<long long, long long> > > M;
    F[{-INF,0}] = -1;
    for(int i = 0; i < N; ++i){
      char c;
      cin >> c;
      if(c == 'W'){
        long long l, s, r = 0;
        cin >> l >> s;
        vector< pair<long long, long long> > V;
        for(auto itr = F.begin(); itr != F.end(); ++itr){
          r = max(r, itr->first.second);
          auto itr_ = itr;
          ++itr_;
          if(itr_ == F.end()) continue;
          if(itr_->first.first != itr->first.second){
            long long n = min(s, itr_->first.first - itr->first.second);
            s -= n;
            V.emplace_back(itr->first.second,itr->first.second+n);
            if(!s) break;
          }
        }
        if(s){
          V.emplace_back(r,r+s);
        }
        for(int j = 0; j < (int)V.size(); ++j){
          F[V.at(j)] = l;
          M[l].push_back(V.at(j));
        }
        /*
        sort(M[l].begin(), M[l].end());
        V = {};
        long long x = -2, y = -1;
        for(int j = 0; j < (int)M[l].size(); ++j){
          if(y == M[l].at(j).first){
            F.erase(F.find({x,y}));
            F.erase(F.find(M[l].at(j)));
            y = M[l].at(j).second;
            F[{x,y}] = l;
            V.pop_back();
            V.emplace_back(x,y);
          }else{
            x = M[l].at(j).first;
            y = M[l].at(j).second;
            V.emplace_back(x,y);
          }
        }
        M[l] = V;
        */
      }else if(c == 'D'){
        long long l;
        cin >> l;
        for(int j = 0; j < (int)M[l].size(); ++j) F.erase(F.find(M[l].at(j)));
        M[l] = {};
      }else{
        long long p;
        cin >> p;
        auto itr = F.upper_bound({p,INF});
        //cout << itr->first.first << " " << itr->first.second << " " << itr->second << endl;
        assert(itr != F.begin());
        --itr;
        if(itr->first.second <= p) cout << -1 << endl;
        else cout << itr->second << endl;
      }
      //for(auto itr = F.begin(); itr != F.end(); ++itr) cout << "[" << itr->first.first << ", " << itr->first.second << ") =  " << itr->second << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 35732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
using namespace std;
int main()
{

    long long n, ans[1000] = {};
    cin >> n;
    for (long long i = 1; i <= n; i++)
    {
        long long j = 2;
        long long tmp = i;
        while (j <= tmp)
        {
            if (tmp % j == 0)
            {
                ans[j]++;
                tmp /= j;
            }
            else
                j++;
        }
    }
    long long c = 1;
    for (long long i = 2; i < 1000; i++)
    {
        if (ans[i] > 0)
        {
            c *= ans[i] + 1;
            c %= (long long)1e9 + 7;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

def sieve(n):
    """Sieve of Eratosthenes"""
    if n < 2:
        is_prime = [False for _ in range(n+1)]
        return is_prime

    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False

    prime = []
    for i in range(n+1):
        if is_prime[i]:
            prime.append(i)

    return prime


def main():
    input = sys.stdin.readline
    N = int(input())
    MOD = 10**9 + 7

    if N == 1:
        return 1

    prime = sieve(N)
    d = defaultdict(lambda: 0)
    for i in range(2, N+1):
        m = i
        for p in prime:
            if p > m:
                break

            while m % p == 0:
                d[p] += 1
                m //= p
    
    ans = 1
    for key in d.keys():
        ans *= d[key] + 1

    return ans % MOD


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3436
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

int Search(vector<string>&v, vector<string>&w, string c, string goal, int num) {
//	cout << c << " " << goal << " " << num << endl;
	int ret = MOD;
	num++;
	for (int i = 0; i < N; i++) {
		string t;
		int j = 0;
		for (; j + v[i].size() <= c.size(); j++) {
			if (c.substr(j, v[i].size()) == v[i]) {
				t += w[i];
				j--;
				j += v[i].size();
			}
			else {
				t.push_back(c[j]);
			}
		}
		while (j < c.size()) {
			t.push_back(c[j]);
			j++;
		}
		if (c == t) {

		}
		else if (t.size() > goal.size()) {

		}
		else if (t.size() == goal.size()) {
			if (t != goal) {

			}
			else {
				ret = min(ret, num);
			}
		}
		else {
			ret = min(ret, Search(v, w, t, goal, num));
		}
	}
	return ret;
}

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

	while (cin >> N, N) {
		vector<string>v(N);
		vector<string>w(N);
		for (int i = 0; i < N; i++) {
			cin >> v[i] >> w[i];
		}
		string s, t;
		cin >> s >> t;
		int ans = Search(v, w, s, t, 0);
		if (ans == MOD)ans = -1;
		cout << ans << endl;
	}
}


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

int n,x,a,b,t[105];

int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%d",&x);
		t[x]++,a=max(a,x);
	}
	b=a+1>>1;
	for(int i=b+1; i<=a; i++)
		if(t[i]<2) {
			printf("Impossible");
			return 0;
		}
	if(a&1) {
		if(t[b]<2) {
			printf("Impossible");
			return 0;
		}
		t[b]-=2;
	} else {
		if(t[b]<1) {
			printf("Impossible");
			return 0;
		}
		t[b]-=1;
	}
	for(int i=1; i<=b; i++)
		if(t[i]) {
			printf("Impossible");
			return 0;
		}
	printf("Possible");
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef signed long long lint;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  cout << (abs(a-b) <= (v-w)*t ? "YES" : "NO") << endl;
  return 0;
}


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

//long long
using ll = long long;

// pair<int, int>
using PII = pair<int, int>;

//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;

//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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

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

int main(){
    int N, M;
    cin >> N >> M;
    priority_queue<ll>que;
    REP(i, N){
        ll x;
        cin >> x;
        que.push(x);
    }
    REP(i, M){
        ll x = que.top();
        que.pop();
        x /= 2;
        que.push(x);
    }
    ll ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    print(ans);
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

static inline bool check(char a) {
    return a == 'A' || a == 'C' || a == 'G' || a == 'T';
}
int main() {
    string s;
    cin >> s;
    int n=s.length();
    int res = 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (check(s[i])) {
            ++cnt;
        } else {
            res = max(res, cnt);
            cnt = 0;
        }
    }
    res = max(res, cnt);
    cout << res << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n+10);
  rep(i,n) cin >> p[i];
  int ans = 0;
  for(int i = 1;i < n-1;++i){
    if(p[i-1] > p[i] && p[i] > p[i+1]) ++ans;
    else if(p[i-1] < p[i] && p[i] < p[i+1]) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
Int MOD = 1000000007;
int main(){
    Int n,m,ans = 1;
    cin >> n >> m;
    if(abs(n-m)>1){
        cout << 0 << endl;
        return 0;
    }
    for(int i=1;i<=n;i++) ans = ans*i%MOD;
    for(int i=1;i<=m;i++) ans = ans*i%MOD;
    cout << (abs(n-m)==0?ans*2%MOD:ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int> a(9);
  int  n;
  string ans = "No";
  for(int i = 0; i < 9; i++){
    cin >> a[i];
  }
  cin >> n;
  vector<int> b(n);
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 9; j++){
      if(b[i] == a[j]){
        a[j] = 0;
      }
    }
  }
  if((a[0] == 0 && a[1] == 0 && a[2] == 0) || (a[0] == 0 && a[3] == 0 && a[6] == 0) || 
     (a[0] == 0 && a[4] == 0 && a[8] == 0) || (a[1] == 0 && a[4] == 0 && a[7] == 0) ||
     (a[2] == 0 && a[5] == 0 && a[8] == 0) || (a[3] == 0 && a[4] == 0 && a[5] == 0) ||
     (a[6] == 0 && a[7] == 0 && a[8] == 0) || (a[2] == 0 && a[4] == 0 && a[6] == 0)){
    ans = "Yes";
  }
  
  
  cout << ans <<endl;
}


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

#pragma region Macros
using ll = long long;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define int ll
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#pragma endregion

const int MAX_N = 100010;

signed main() {
    IOS;

    int X, Y;
    cin >> X >> Y;
    for(int i = 0; i <= X; ++i) {
        int rem = X - i;
        if(i * 2 + rem * 4 == Y) {
             print("Yes");
             return 0;
        }
    }
    print("No");

    return 0;
}


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

using ll = long long;

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (auto &a : A)
    cin >> a;

  vector<ll> B(N);
  vector<ll> C(N);
  for (ll i = 0; i < N; i++) {
    B[i] = -A[i] - i;
    C[i] = A[i] - i;
  }

  ll ans = 0;

  sort(C.begin(), C.end());
  for (auto b : B) {
    auto lo = lower_bound(C.begin(), C.end(), b);
    auto up = upper_bound(C.begin(), C.end(), b);
    ans += up - lo;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8016
/*
    OUTLAW!!
           ---SIDHU MOOSEWALA
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli M=1000000007;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
//map<ll,lli> dp;
//set<lli> s[100005];
//lli dp[3005][3005];
//ost s[500005];
bool cmp(ll a,ll b)
{
    if(a.second==b.second)
    return a.first<b.first;
    return a.second<b.second;
}
//string sdp[3005][3005];
lli vis[3000004];
lli mk[3000004];
lli keep[3000004];
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    lli d=((n-1)*(n-2))/2;
    if(k>d)
    cout<<-1;
    else
    {
        vector<ll> vv;
        for(int i=2;i<=n;i++)
        vv.push_back({1,i});
        d-=k;
        for(int i=2;i<=n;i++)
        {
            if(d==0)
            break;
            for(int j=i+1;j<=n;j++)
            {
                vv.push_back({i,j});
                d--;
                if(d==0)
                break;
            }
        }
        cout<<vv.size()<<"\n";
        for(auto &i: vv)
        cout<<i.first<<" "<<i.second<<"\n";
    }
    //for(int i=1;i<=n;i++)
}

Measured memory_bytes: 512
n=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

div=make_divisors(n)
sum=0
for i in div:
    if i!=1 and n//(i-1)==n%(i-1):
        sum+=i-1
print(sum)

Measured memory_bytes: 3264
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int , int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 

int main() {
    int r ;
    cin >> r ;
    cout << 3*r*r << endl ;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+50;
int n,a[N];
int dp[N],sum[N],vis[N],ret[N];

int main() {
	n=rd();
	REP(i,1,n) a[i]=rd();
	n=unique(a+1,a+1+n)-a-1;
	int ans = 0;
	dp[0] = 1, sum[0] = 1;
	REP(i,1,n) {
		if (vis[a[i]]) dp[i] = ret[a[i]];
		ret[a[i]] = (ret[a[i]]+sum[i-1])%P;
		vis[a[i]] = i;
		sum[i] = (sum[i-1]+dp[i])%P;
	}
	printf("%d\n", sum[n]);
}








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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;



int main() {
	int a, p;

	cin >> a >> p;


	cout << (a * 3 + p) / 2;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){	
	ll n, t;
	scanf("%ld %ld", &n, &t);
	std::vector<P> ab(n);
	for(ll i=0; i<n; i++) scanf("%ld %ld", &ab[i].first, &ab[i].second);
	std::sort(ab.begin(), ab.end());
	ll a[n], b[n];
	for(ll i=0; i<n; i++) std::tie(a[i], b[i]) = ab[i];

	ll dp[t+4000] = {};
	for(ll i=0; i<n; i++){
		for(ll j=t+3999; j>=0; j--){
			if(j-a[i]<0 or t<=j-a[i]) continue;
			dp[j] = std::max(dp[j], dp[j-a[i]] + b[i]);
		}
	}

	ll ans = 0;
	for(ll i=0; i<t+4000; i++) ans = std::max(ans, dp[i]);
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 3912
// 2011/02/16 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		// üÍi³ÒÌj
		int n;
		cin >> n;
		if(n==0)
			break;

		// üÍi³ÒÌîñjÆZ
		int p_max = 0;		// Å·Ì³ÒÌÔiúlÍ0j
		int d_max = -1;		// Å·Ìà¢½£iúlÍ-1j
		for(int i=0; i<n; i++){
			int p, d1, d2;
			cin >> p >> d1 >> d2;
			if(d_max<d1+d2){		// àµà¢½£ª·©Á½ç
				p_max = p;
				d_max = d1+d2;
			}
		}

		// oÍ
		cout << p_max << ' ' << d_max << endl;
	}

	return 0;
}

Measured memory_bytes: 868
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = [input() for _ in range(n)]
s = [Counter(i) for i in s]
ans = ''
for i in range(26):
    t = chr(ord('a') + i)
    cnt = inf
    for j in range(n):
        cnt = min(cnt,s[j][t])
    ans += t*cnt
print(ans)

Measured memory_bytes: 39408