akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=105;
int a[N];
int n,X; 
int main()
{
	scanf("%d%d",&n,&X);
	for (int u=1;u<=n;u++) scanf("%d",&a[u]);
	sort(a+1,a+1+n);
	int ans=0;
	for (int u=1;u<=n;u++)
	{
		if (X>=a[u])	
		{
			X-=a[u];
			ans++;
		}
		else break;
	}
	if (ans==n)
	{
		if (X!=0) ans--;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //gp_hash_table

#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define sz(a) (int) a.size()
#define bitcount(a) __builtin_popcount(a)

using namespace std;
// using namespace __gnu_pbds;


typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll oo = 1e15;
const int N = (int) 1010;
const int M = 1e4 + 10;

struct item {
    int w, s, v;
    item(int w, int s, int v): w(w), s(s), v(v) {}
    bool operator<(const item& o) const {
        return s - o.w < o.s - w;
    }
};

void solve() {
    int n; cin >> n;
    vector<item> a;
    for(int i = 0; i < n; ++i) {
        int w, s, v; cin >> w >> s >> v;
        a.eb(w, s, v);
    }
    sort(all(a)); a.insert(a.begin(), item(-1, -1, -1));
    vector<vector<ll>> dp(n + 1, vector<ll>(2 * M, -oo));
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        for(int w = 0; w < 2 * M; ++w) {
            dp[i][w] = dp[i - 1][w];
        }
        for(int pw = 0; pw <= M && pw <= a[i].s; ++pw) {
            dp[i][pw + a[i].w] = max(dp[i][pw + a[i].w], dp[i - 1][pw] + a[i].v);
        }
    }
    cout << *max_element(all(dp[n])) << '\n';
}

int main() {
    // freopen("input.in", "r", stdin);
    // freopen("input.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    // int t; cin >> t; while(t--)
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 163696
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

void print_vector(vector<int> v){
  rep(i, sz(v)){
    cout << v[i] << " ";
  }
  cout << endl;
  return;
}

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int score = 0;

  rep(i, N-1){
    if(S[i]==S[i+1]) score++;
  }

  int ans = min(score+2*K, N-1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <complex>
#include <math.h>

typedef long long ll;

using namespace std;

double pi=2*acos(0);
const int INF = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

bool is_prime(int x)
{
    if(x<=1) return false;
    for(int i=2; i*i<=x; i++)
    {
        if(x%i == 0) return false;
    }
    return true;
}

int main()
{
    int x;
    cin >> x;

    int p=x;
    while(!is_prime(p)) p++;

    cout << p << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main()
{
	int n;
	double q;
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	q=a[0];
	for(int i=1;i<n;i++) {
		q=(q+a[i])/2;
	}
	cout<<q;
	return 0;
} 

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    //INT_MAX = 2147483647, UINT_MAX = 4294967295

    int s, w;
    cin >> s >> w;

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

    return 0;
}

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

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int M = a[0];
    for(int i = 1; i < n; i++){
        M = max(a[i] - a[i - 1], M);
    }
    M = max(k - a[n - 1] + a[0], M);

    cout << k - M << endl;
    
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    int x,y;
    cin>>x>>y;
    
    if(y-(2*x)<0){
        cout<<"No";
        
    }
    else{
        int ans = (y-(2*x));
        if(ans%2==0 && ans/2<=x){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
	// your code goes here
	return 0;
}


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

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* main */
void Main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



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

struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

int main(){
  int N,M;
  cin>>N>>M;
  std::vector<int> K(N);
  std::vector<int> L[N];
  for(int i=0;i<N;i++){
    cin>>K[i];
    for(int j=0;j<K[i];j++){
      int afj;
      cin>>afj;
      L[i].push_back(afj);
    }
  }
  UnionFind uf(M+1);
  for(int i=0;i<N;i++){
    for(int j=1;j<K[i];j++){
      uf.unite(L[i][0],L[i][j]);
    }
  }
  int out=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<K[i];j++){
      if(!uf.same(L[0][0],L[i][j]))out++;
    }
  }
  if(out)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


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

int main() {
    int n;
    cin >> n;
    n--;
    int c[n], s[n], f[n];
    rep(i, n) cin >> c[i] >> s[i] >> f[i];

    rep(i, n) {
        int t = s[i] + c[i];
        for (int j = i + 1; j < n; j++) {
            if (t < s[j])
                t = s[j];
            else if (t % f[j] == 0)
                ;
            else
                t = t + f[j] - t % f[j];
            t += c[j];
        }
        cout << t << endl;
    }

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
	int n;
	int val[200000];
	int ret = -pow(10,9);
	int max = 0;
	int max_i = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&val[i]);
		if(max <= val[i]){
			max = val[i];
			max_i = i;
		}
	}
	for(int i = 0; i < n - 1; i++){
		if(max_i == i){
			max = 0;
			max_i = 0;
			for(int u = i + 1; u < n; u++){
				if(max <= val[u]){
					max = val[u];
					max_i = u;
				}
			}
		}
		if(ret < max - val[i]){
			ret = max - val[i];
		}
	}
	
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 2564
#include<iostream>
#include<map>
#include<utility>
#include<cmath>

using namespace std;

double px[223],py[223],pz[223],vx[223],vy[223],vz[223],r[223],vr[223];

double sqr(double d){
  return d*d;
}

double dist(int i,int j,double t){
  return sqrt(sqr(px[i]+vx[i]*t-(px[j]+vx[j]*t))+
	      sqr(py[i]+vy[i]*t-(py[j]+vy[j]*t))+
	      sqr(pz[i]+vz[i]*t-(pz[j]+vz[j]*t)))-
    (r[i]-vr[i]*t)-(r[j]-vr[j]*t);
}

int main(){
  for(int n;cin>>n,n;){
    double vt[223];
    multimap<double,pair<int,int> > ev;
    for(int i=0;i<n;i++){
      cin>>px[i]>>py[i]>>pz[i]>>vx[i]>>vy[i]>>vz[i]>>r[i]>>vr[i];
      vt[i]=r[i]/vr[i];
      ev.insert(make_pair(vt[i],make_pair(i,i)));
    }
    int NI=100;
    for(int i=0;i<n;i++){
      for(int j=0;j<i;j++){
	double l=0,h=min(vt[i],vt[j]);
	for(int k=0;k<NI;k++){
	  double lh=l+(h-l)/3,hl=l+(h-l)*2/3;
	  if(dist(i,j,lh)<dist(i,j,hl)){
	    h=hl;
	  }else{
	    l=lh;
	  }
	}
	if(dist(i,j,l)<0){
	  double bl=0,bh=l;
	  for(int k=0;k<NI;k++){
	    double m=(bl+bh)/2;
	    ((dist(i,j,m)>0)?bl:bh)=m;
	  }
	  ev.insert(make_pair(bl,make_pair(i,j)));
	}
      }
    }
    bool di[223]={};
    int r=n;
    double ans[223];
    for(auto e:ev){
      int s1=e.second.first;
      int s2=e.second.second;
      if(!di[s1]&&!di[s2]){
	di[s1]=true;
	di[s2]=true;
	ans[s1]=e.first;
	ans[s2]=e.first;
	r-=1+(s1!=s2);
      }
    }
    for(int i=0;i<n;i++){
      cout.precision(9);
      cout<<fixed<<ans[i]<<endl;
    }
  }
}

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

using namespace std;

int main() {
	vector<int> arr{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<arr[k-1]<<"\n";
	return 0;
}


Measured memory_bytes: 256
/**
 *      ABC 54 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-06 04:22:29
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M; cin >> N >> M;
    string A[N + 10] = {}; string B[M + 10] = {};
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> B[i];
    }

    bool check1 = false;

    for (int i = 0; i < N - M + 1 ; ++i) {
        for (int j = 0; j < N - M + 1; ++j){
            bool check2 = true;
            for (int k = 0; k < M; ++k) {
                for (int l = 0; l < M; ++l) {
                    if (A[i + k][j + l] != B[k][l]){
                        check2 = false;
                    }                    
                }                
            }
            if (check2) check1 = true;
        }
    }
    check1 ? cout << "Yes" : cout << "No";

    return 0;

}


Measured memory_bytes: 256
# coding: utf-8

import heapq

N, M = map(int, input().split())

works = {}
for _ in range(N):
    a, b = map(int, input().split())
    works.setdefault(a, []).append(b)

ans = 0
heap = []

for i in range(M+1):
    if i in works:
        [heapq.heappush(heap, work) for work in map(lambda x: x * -1, works[i])]
    if heap:
        ans += heapq.heappop(heap) * -1

print(ans)


Measured memory_bytes: 27352
//Main(`31415926535897932384626433832795028841971693993751058209749445923078164062862089986280`);

function Main(input) {
  const data = input.trim().split("").map(Number);
  const sum = data.reduce((acc,crt) => acc+crt);

  console.log(sum%9 === 0? 'Yes':'No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 35180
l, m, n = map(int,input().split())
a = [[0 for i in range(m)] for i in range(l)]
b = [[0 for i in range(n)] for i in range(m)]
c = [[0 for i in range(n)] for i in range(l)]

for i in range(l):
 a[i] = [int(x) for x in input().split()]

for i in range(m):
 b[i] = [int(x) for x in input().split()]

for i in range(l):
 for j in range(n):
  for k in range(m):
   c[i][j] += (a[i][k] * b[k][j])
 print(" ".join([str(x) for x in c[i]]))

Measured memory_bytes: 8980
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define ull unsigned long long int
#define gcu getchar_unlocked
#define pc(x) putchar(x);
#define pcu(x) putchar_unlocked(x);
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

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

//void readint(ll &x)
//    {
//        bool neg=false;
//        ll c;
//        x =0;
//        c=gc();
//        if(c=='-')
//        {
//            neg = true;
//            c=gc();
//        }
//        for(;(c>47 && c<58);c=gc())
//            x = (x<<1) + (x<<3) +c -48;
//        if(neg)
//            x *=-1;
//    }
//
//inline void input(ll *n)
//{
////    register char c=getchar_unlocked();
//    *n=0;
//    for(;(c<'0'||c>'9');c=getchar_unlocked());
//    for(;(c<='9'&&c>='0');c=getchar_unlocked())
//    {
//        *n=((*n)<<1) + ((*n)<<3) + c - 48;
//    }
//}

//inline void writeInt (ll n)
//{
//    ll N = n, rev, count = 0;
//    rev = N;
//    if (N == 0) { pc('0'); pc('\n'); return ;}
//    if (N*(-1)>0){pc('-');rev=rev*(-1);N=N*(-1);}
//    while ((rev % 10) == 0) { count++; rev /= 10;}
//    rev = 0;
//    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
//    while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
//    while (count--) pc('0');


//ll power(ll x, ll y,ll p)
//{
//    ll res = 1;
//    x = x % p;
//
//    while (y > 0)
//    {
//        if (y & 1)
//            res = (res*x) % p;
//
//        y = y>>1;
//        x = (x*x) % p;
//    }
//    return res;
//}

int main()
{
    SPEED
    ll a;
    string s;
    cin>>a>>s;
    if(a>=3200)
        cout<<s<<"\n";
    else
        cout<<"red\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;

    long a_i;
    priority_queue<long> Price_q;
    FOR(i, N) {
        cin >> a_i;
        Price_q.push(a_i);
    }

    FOR(i, M) {
        long p = Price_q.top();
        Price_q.pop();
        Price_q.push((long)(p / 2));
    }

    long ans = 0;
    FOR(i, N) {
        ans += Price_q.top();
        Price_q.pop();
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a;
    cin >> b;
    cin >> c;
    if (a<b and b<c){
        cout << "Yes" << "\n";
    }else {
        cout << "No" << "\n";
    }
}


Measured memory_bytes: 3052
#include<stdio.h>
int main(){
  int i,k,num=7;
  scanf("%d",&k);
  for(i=1;i<=k;i++){
    if(num%k==0){
      printf("%d\n",i);
      return 0;
    }
    num%=k;
    num=num*10+7;
  }
  puts("-1");
  return 0;
}


Measured memory_bytes: 1716
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N;
  std::cin >> N;
  std::cout << 180 * (N - 2) << std::endl;

  // Main

  // Output

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define W(x) cout << #x << " = " << x << endl;
#define pii pair<int, int>
#define ff first
#define ss second
#define ll long long
#define sort(x) sort(x.begin(), x.end())
using namespace std;



int main(){
	double t, x;
	cin >> t >> x;
	printf("%.13lf\n",  double(t/x));
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        //static long Mod = (long)1e9 + 7;
        static List<long>[] tree;
        static long[] query;
        static bool[] cmp;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Sarray();
            if (Ai.Max() < K)
            {
                WriteLine("IMPOSSIBLE");
                return;
            }
            var gcd = 0L;
            foreach (var a in Ai)
                gcd = Gcd(gcd, a);
            if (K % gcd != 0)
            {
                WriteLine("IMPOSSIBLE");
                return;
            }
            WriteLine("POSSIBLE");
            //Out.Flush();
        }
        static long Gcd(long x, long y) => y == 0 ? x : Gcd(y, x % y);
    }
}


Measured memory_bytes: 22880
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 1<<30

static const int N = 100;

int main() {
    int n;
    int p[N+1], m[N+1][N+1];
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> p[i-1] >> p[i];
    }

    for (int i=1; i<=n; i++) {
        m[i][i] = 0;
    }
    for (int l=2; l<=n; l++) {
        for (int i=1; i<=n-l+1; i++) {
            int j = i+l-1;
            m[i][j] = INF;
            for (int k=i; k<=j-1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }

    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {};
    
    void init(int n) { par.assign(n, -1); }

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

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

    bool merge(int x, int y){
        x = root(x);
        y = root(y);

        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};




int main(){

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

    ll n, m, k; cin >> n >> m >> k;
    ll a[m], b[m], c[k], d[k];

    set<ll> st_friend[n], st_block[n];
    UnionFind uf(n);

    uf.init(n);
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        uf.merge(a[i], b[i]);
        st_friend[a[i]].insert(b[i]);
        st_friend[b[i]].insert(a[i]);
    }
    rep(i, k){
        cin >> c[i] >> d[i];
        c[i]--; d[i]--;
        if(!uf.issame(c[i], d[i])) continue;
        st_block[c[i]].insert(d[i]);
        st_block[d[i]].insert(c[i]);
    }

    rep(i, n){

        ll ans = uf.size(i) - st_friend[i].size()
                            - st_block[i].size() - 1;
        cout << ans << " ";
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

void In(ll& I)
{
	cin >> I;
}

void In(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void Out(ll& O)
{
	cout << O;
}

void Out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

int main()
{
	ll A, B;
	In(A);
	In(B);

	ll Max;

	Max += A > B ? A-- : B--;
	Max += A > B ? A : B;

	Out(Max);

	return 0;
}

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

import sys
input=sys.stdin.readline

n=int(input())
s=input()
ws=s.count('W')
rs=s.count('R')
ans=min(ws,rs)
posw=[]
posr=[]
for i in range(n):
    if s[i]=='W':
        posw.append(i)
    else:
        posr.append(i)
posr=posr[::-1]
for i in range(min(len(posw),len(posr))):
    if posw[i]>posr[i]:
        ans=min(ans,i)
        break
print(ans)

Measured memory_bytes: 81380
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;


int main(){
    int N = 0,K = 0;
    cin>>N;
    cin>>K;
    int h[N];
    for(int i = 0; i < N; ++i){
        cin >> h[i];
    }
    
    int memo[N];
    memo[0] = 0;
    if(N < K) {
        cout <<abs(h[N-1] - h[0]);
        return 0;
    }
    for(int i = 1; i < K; ++i){
        memo[i] = abs(h[i] - h[0]);
    }
    vector<int> A(K);
    for(int j = K; j < N; ++j){
        for(int k = 1; k <= K; ++k){
            A[k-1]= memo[j-k] + abs(h[j] - h[j-k]);
        }
        sort(A.begin(),A.end());
        memo[j] = A[0];
    }
    int ans = memo[N-1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

public class AIDU0011
    {
        public static void Main(string[] args) {
            uint w = uint.Parse(Console.ReadLine()),
                n = uint.Parse(Console.ReadLine());
            uint[] t = new uint[2];
            string[] ss=new string[n];
            uint[] res = new uint[w];
            int i = 0;
            for (i = 0; i < w; i++) res[i] = (uint)i + 1;
            for (i = 0; i < n; i++) {
                ss = Console.ReadLine().Split(',');
                t[0] = uint.Parse(ss[0]);
                t[1] = uint.Parse(ss[1]);
                Swap(res, t[0], t[1]);
            }
            for (i = 0; i < w; i++) Console.WriteLine(res[i]);
            Console.ReadLine();
        }

        public static void Swap(uint[] res, uint a, uint b) {
            uint pool;
            pool = res[a - 1]; res[a - 1] = res[b - 1];res[b - 1] = pool;
        }
    }

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
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; }
const ll MOD = 1e9+7;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A;
    A.push_back(0);
    REP(i,N){
        ll a;
        cin >> a;
        a %= K;
        A.push_back(a);
    }

    N = N+1;
    vector<ll> S(N);
    S[0] = A[0];
    REPi(i,1,N){
        S[i] = S[i-1] + A[i];
    }

    vector<ll> X(N);
    map<ll, ll> ma;
    queue<ll> que;
    ll ans = 0;
    REP(i,N){
        ll a = S[i];
        a = (a-i+K) % K;
        X[i] = a;
        ans += ma[a];
        ma[a] += 1;
        que.push(a);
        if(que.size() >= K){
            ll t = que.front();
            que.pop();
            ma[t] -= 1;
        }
            
    }

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


Measured memory_bytes: 19056
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
using namespace std;


int main(){
  int N,K;
  cin>>N>>K;
  long long int DP[2100][2100];
  
  for(int i=0; i<2100; ++i){
    DP[i][0]=1;
    DP[i][i]=1;
  }
  
  for(int i=1; i<2100; ++i){
    for(int j=1; j<i; ++j){
      DP[i][j]=(DP[i-1][j]+DP[i-1][j-1])%1000000007;
    }
  }
  
  
  for(int i=1; i<=K; ++i){
    cout<<(DP[N-K+1][i]*DP[K-1][i-1])%1000000007<<endl;
  }
}


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

#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl         "\n"
#define int          long long
#define all(v)       v.begin(),v.end()
#define sz(v)        (int)v.size()
#define pii          pair<int,int>
#define fi           first
#define se           second
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define deb(x)       cout << #x << ' ' << x << endl
#define clock        cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl;

void INPUT() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int n, w;
pii p[105];
int cache[105][100005];

int dp(int idx, int val) {
	if (val == 0) return 0;
	if (val < 0 || idx == n) return (int)1e15;
	int &ans = cache[idx][val];
	if (ans != -1) return ans;
	ans = min(dp(idx + 1, val), p[idx].fi + dp(idx + 1, val - p[idx].se));
	return ans;
}

int32_t main(){
    IOS //INPUT();
    cin >> n >> w;
    forn(i, 0, n) cin >> p[i].fi >> p[i].se;
    memset(cache, -1, sizeof(cache));
    int ans = 0;
    forn(i, 1, 1e5 + 1) {
    	int mwt = dp(0, i);
    	if (mwt <= w) ans = i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 82304
N, M = map(int, input().split())
base = []
for i in range(M):
  (a, b) = map(int, input().split())
  base.append((a, b, i))
sorted_target = sorted(base) 

prefecture_index = sorted_target[0][0]

i=0
result = {}

for target in sorted_target:
  if prefecture_index == target[0]:
    i+=1
  else:
    prefecture_index = target[0]
    i = 1
  result[target[2]] = [prefecture_index, i]

for i in range(M):
  print("{:0=6}{:0=6}".format(result[i][0], result[i][1]))

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


int main() {
  string S;
  cin >> S;
  int ans = 0;
  int cnt = 0;
 
  if (S == "RRR") ans = 3;
  else if (S == "RRS" || S == "SRR") ans = 2;
  else if (S == "RSS" || S == "SSR" || S == "SRS" || S == "RSR" ) ans = 1;
  else ans = 0;

  cout << ans << endl;


  return 0;
}









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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n;

int main() {
	read(n);
	print(180 * (n - 2));
}


Measured memory_bytes: 3648
N = int(input())
hoge = input().split()
v = []
for i in range(N):
  v.append(int(hoge[i]))

_v = sorted(v, reverse=True)

gu = _v.pop(N-1)
if N == 2:
  print((_v[0]+gu)/2)
else:
  for i in range(N-2,-1,-1):
    gu = (gu + _v.pop(i))/2
  print(gu)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

di = {}
B = set(A)
for b in B:
  di[b] = 0
total = 0
for a in A:
  di[a]+=1
for v in di.values():
  total += v*(v-1)//2
#print(di.values(),total)
ans = []
for a in A:
  ans.append(total-di[a]+1)
print(*ans,sep='\n')

Measured memory_bytes: 34664
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>


using namespace std;
int main() {
    int a, b;
    cin >> a >> b;

    printf("%d %d %.5lf\n", a / b, a % b, (double)a / b);
    return 0;
}



Measured memory_bytes: 3200
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    let k = input.trim().to_owned();
    input.clear();
    io::stdin().read_line(&mut input);
    let d = input.trim().parse::<usize>().unwrap();
    input.clear();

    let ks: Vec<char> = k.chars().collect();
    // 0 is not max, 1 is max.
    let mut dp = vec![vec![vec![-1; ks.len()]; d as usize]; 2];
    let mut result = solve(&mut dp, 0, 0, true, d, &ks);
    // delete all 0
    result = result + 1_000_000_007;
    result -= 1;
    result %= 1_000_000_007;
    println!("{}", result);
    Ok(())
}

fn solve(
    dp: &mut Vec<Vec<Vec<i64>>>,
    index: usize,
    remain: usize,
    is_max: bool,
    d: usize,
    k: &[char],
) -> i64 {
    if index == k.len() {
        if remain == 0 {
            return 1;
        } else {
            return 0;
        }
    }
    let first_index = if is_max { 1 } else { 0 };
    if dp[first_index][remain][index] != -1 {
        return dp[first_index][remain][index];
    }

    if is_max {
        let mut result = 0;
        let number = k[index].to_digit(10).unwrap() as usize;
        for i in 0..number {
            let new_remain = (remain + i) % d;
            result += solve(dp, index + 1, new_remain, false, d, k);
            result %= 1_000_000_007;
        }
        let new_remain = (remain + number) % d;
        result += solve(dp, index + 1, new_remain, true, d, k);
        result %= 1_000_000_007;
        dp[1][remain][index] = result;
        return result;
    }

    let mut result = 0;
    for i in 0..10 {
        let new_remain = (remain + i) % d;
        result += solve(dp, index + 1, new_remain, false, d, k);
        result %= 1_000_000_007;
    }
    dp[0][remain][index] = result;
    result
}


Measured memory_bytes: 21756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
const int SZ = 2345678;
 
 
 int main(){
    int a[] = {400,600,800,
1000,
1200,
1400,
1600,
1800};
int n;
cin >> n;
    for(int i = 0; i < 8; i++){
        if(i < 7 && n < a[i+1]){
            cout << 8-i;
            return 0;
        }
    }
    cout << 1;
 }


Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    ll remain = K;
    if(remain > A){
        ans += A;
        remain -= A;
    }else{
        ans += remain;
        cout << ans;
        return 0;
    }
    if(remain > B){
        remain -= B;
    }else{
        cout << ans;
        return 0;
    }
    if(remain > C){
        ans -= C;
        cout << ans;
        return 0;
    }else{
        ans -= remain;
        cout << ans;   
    }


}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    priority_queue<int> que;
    REP(i,n){
        int a = 0;
        cin >> a;
        que.push(a);
    }
    ll ans = 0;
    REP(i,m){
        int a = que.top();
        if(a <= 0)break; 
        a /= 2;
        que.pop();
        que.push(a);
    }
    REP(i,n){
        ans += que.top();
        que.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

int main(void) {
	ll N,K;	
	inp(N);
	inp(K);
	vector<ll> a;
	rep(i,N){
		ll num;
		inp(num);
		a.push_back(num);
	}
	vector<vector<ll>> dp(N,vector<ll>(K+1,0));
	rep(j,K+1){
		if(j<=a[0]) dp[0][j]=1;
		else dp[0][j]=0;
	}
	rep(i,N) dp[i][0]=1;
	rep2(i,1,N)rep2(j,1,K+1){		
		if(a[i]>=j) dp[i][j] = dp[i-1][j]+dp[i][j-1];
		else dp[i][j] = dp[i-1][j]+dp[i][j-1]+MOD-dp[i-1][j-a[i]-1];
		dp[i][j]%=MOD;
	}
/*  	rep(i,N){
		rep(j,K+1) cout << dp[i][j] << ",";
		cout << endl;
	}  */
	out(dp[N-1][K]);
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k ;
    cin>>k;
    int sum=0;
    for(int i=1;i<=k;i++){
    	for(int j=1;j<=k;j++){
    		for(int r=1;r<=k;r++){
    			sum+=gcd(r,gcd(j,i));
    		}
    	}
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 3620
from itertools import product


N, M = map(int, input().split())
km = []
sm = []
pm = []
for m in range(M):
  tmp = list(map(int, input().split()))
  km.append(tmp[0])
  sm.append(tmp[1:])
pm = list(map(int, input().split()))
prod = list(product([1,0], repeat=N))

ans = 0

for p in prod:
  on = [0] * M
  for m in range(M):
    sw_num = 0
    for es in sm[m]:
      sw_num += p[es-1]
    if sw_num%2 == pm[m]:
      on[m] = 1
  if sum(on) == M:
    ans += 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
int main() {
	// D , D , 앳코더 1회 ㄱ? 
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll a, b; cin >> a >> b;
	
	for (int i = 1; i < 999; i++) {
		int nx = i * (i + 1) / 2;
		int ny = (i + 1) * (i + 2) / 2;
		if (nx - a == ny - b) {
			cout << nx - a << '\n'; return 0;
		}
	}
	

}

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

int main(){
  int N;
  cin >> N;
  
  string result;
  bool fin = false;
  
  for (int i=0; i<20; i++) {
    for (int j=0; j<30; j++) {
      
      int sum = 7*i + 4*j;
      
      if (sum == N) {
        
        result = "Yes";
        
        fin = true;
        
        break;
      }
      else {
        
        result = "No";
        
      }
    }
    if (fin) {
      
      break;
      
    }
  }
  cout << result <<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
#include <complex>
#include <cassert>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define deb(a) cerr<< #a << "= " << (a)<<"\n";

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef complex<double> base;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p;p>>=1){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

ll N,a[100]; vector<pii> ans;

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

    int i,maxid=1,minid=1;
    for (i=1; i<=N; i++){
        cin >> a[i];
        if (a[i]>a[maxid]) maxid=i;
        if (a[i]<a[minid]) minid=i;
    }

    if (a[maxid]+a[minid]>=0){
        for (i=1; i<=N; i++)
            ans.pb({maxid,i});

        for (i=2; i<=N; i++)
            ans.pb({i-1,i});
    }

    else{
        for (i=1; i<=N; i++)
            ans.pb({minid,i});

        for (i=N-1; i>0; i--)
            ans.pb({i+1,i});
    }

    cout << ans.size() << "\n";
    for (pii p : ans)
        cout << p.fi << " " << p.se << "\n";
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}


int main(){
    ll x,y,n,m,p,h,k,max=-10000000,min=1000000000,ans=0,sum=0;
    string s,t;
    cin >> n >> s;
    //VI a(n)
    for(int i=0; i<n;i++){
        t.push_back(s[i]);
        if(s==t+t){
            cout << "Yes" << endl;    
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/








int N, Q; string S;
int ok[101010], sm[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q >> S;
	rep(i, 0, N - 1) if (S[i] == 'A' and S[i + 1] == 'C') ok[i] = 1;
	sm[0] = ok[0];
	rep(i, 1, N) sm[i] = sm[i - 1] + ok[i];

	rep(q, 0, Q) {
		int L, R; cin >> L >> R; L--; R--;

		int ans = sm[R];
		if (L) ans -= sm[L - 1];

		if (R + 1 < N and S[R] == 'A' and S[R + 1] == 'C') ans--;
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1872
N,Q=map(int,input().split())
arr_ab = [[] for j in range(N)]
for _ in range(N-1):
    a,b=map(int,input().split())
    arr_ab[a-1].extend([b])
arr_px = [0]*N
for _ in range(Q):
    p,x=map(int,input().split())
    arr_px[p-1]+=x

ans = [0]*N

for i in range(N-1):
    for j in arr_ab[i]:
        arr_px[j-1]+=arr_px[i]
print(' '.join(list(map(str, arr_px))))

Measured memory_bytes: 60488
#include<iostream>
using namespace std;
int main(){
  int n,lsum=0,rsum=0,cnt=0;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]==')'){
      if(lsum==0){
        cnt++;
      }else{
        lsum--;
      }
    }else{
      lsum++;
    }
  }
  for(int i=0;i<cnt;i++) cout <<'('; 
  cout << s;

  cnt=0;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='('){
      if(rsum==0){
        cnt++;
      }else{
        rsum--;
      }
    }else{
      rsum++;
    }
  }
  for(int i=0;i<cnt;i++) cout <<')'; 
  cout <<endl;
}


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

ans = 200000
i = 0

while i < N:
    count1 = 0
    count2 = 0
    for j in range(i+1):
        count1 += W[j]
    for j in range(i+1,N):
        count2 += W[j]
    if ans > abs(count1 - count2):
        ans = abs(count1 - count2)
    i += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;
typedef long long ll;

int main()
{
    FAST_IO;
    int a,b,c;
    cin >> a >> b >>c;
    cout << min(a+b, min(a+c, b+c)) << endl;
    return 0;
}

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

int main(){
  int a, b;
  scanf("%d%d", &a, &b);
  (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? printf("Possible\n") : printf("Impossible\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

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

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

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



signed main(){

    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vec A(X); readv(A);
    vec B(Y); readv(B);
    vec C(Z); readv(C);

    vec AB;
    REP(i, X) REP(j, Y) AB.pb(A[i] + B[j]);
    Sort(AB); Reverse(AB);

    vec ABC;
    REP(i, min(K, X * Y)) REP(j, Z) ABC.pb(AB[i] + C[j]);
    Sort(ABC); Reverse(ABC);

    REP(i, K) cout << ABC[i] << endl;

    return 0;
}


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

ll INF = 1e+18;
int iINF = 1e9;

vector<ll> memo(51, 0);

int 
main()
{
  ll H; cin >> H;
  ll num = 1;
  ll cnt = 1;
  while(H != 1){
    H /= 2;
    num *= 2;
    cnt += num;
  }
  cout << (cnt / 2) + num << endl;
}

Measured memory_bytes: 3584