akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

class Point{
public:
  int x, y;
  Point(int x = 0, int y = 0) : x(x), y(y) {}
};

int main() {
  static Point blocks[7][4];
  blocks[0][0] = Point(0, 0);
  blocks[0][1] = Point(1, 0);
  blocks[0][2] = Point(0, 1);
  blocks[0][3] = Point(1, 1);
  blocks[1][0] = Point(0, 0);
  blocks[1][1] = Point(0, 1);
  blocks[1][2] = Point(0, 2);
  blocks[1][3] = Point(0, 3);
  blocks[2][0] = Point(0, 0);
  blocks[2][1] = Point(1, 0);
  blocks[2][2] = Point(2, 0);
  blocks[2][3] = Point(3, 0);
  blocks[3][0] = Point(1, 0);
  blocks[3][1] = Point(0, 1);
  blocks[3][2] = Point(1, 1);
  blocks[3][3] = Point(0, 2);
  blocks[4][0] = Point(0, 0);
  blocks[4][1] = Point(1, 0);
  blocks[4][2] = Point(1, 1);
  blocks[4][3] = Point(2, 1);
  blocks[5][0] = Point(0, 0);
  blocks[5][1] = Point(0, 1);
  blocks[5][2] = Point(1, 1);
  blocks[5][3] = Point(1, 2);
  blocks[6][0] = Point(1, 0);
  blocks[6][1] = Point(2, 0);
  blocks[6][2] = Point(0, 1);
  blocks[6][3] = Point(1, 1);

  string data[8];
  while(getline(cin, data[0])) {
    for(int i = 1; i < 8; i++) {
      getline(cin, data[i]);
    }
    getchar();
    for(int i = 0; i < 8; i++) {
      for(int j = 0; j < 8; j++) {
	if(data[i][j] == '1') {
	  for(int n = 0; n < 7; n++) {
	    bool flag = true;
	    int ox = j - blocks[n][0].x;
	    int oy = i - blocks[n][0].y;
	    for(int p = 1; p < 4; p++) {
	      int nx = ox+blocks[n][p].x;
	      int ny = oy+blocks[n][p].y;
	      if(nx < 0 || nx >= 8 || ny < 0 || ny >= 8) {
		flag = false;
		break;
	      }

	      if(data[ny][nx] != '1') {
	        flag = false;
	        break;
	      }
	    }
	    if(flag) {
	      cout << (char)((int)'A'+n) << endl;
	      break;
	    }
	  }
	  i = 8;
	  break;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    for(i=3;i<=n;i++){
        if(i%10==3||i%100/10==3||i%10000/1000==3||i%1000/100==3||i%3==0){
            printf(" %d",i);
        }
    }
    printf("\n");
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

double f(double x) {
    return x * x * x;
}

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

    double a = (double)L / 3;
    printf("%.15f\n", f(a));
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int x,y,z;
  int temp;
  scanf("%d", &x); scanf("%d", &y); scanf("%d", &z);
  
  temp=x;
  x=y;
  y=temp;
  
  temp=x;
  x=z;
  z=temp;
  
  printf("%d %d %d", x,y,z);
  
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define MOD2 998244353
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;

template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}

int main(){
    FAST;
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        loop(j, 1, n+1) {
            loop(k, 1, n+1) {
                ans += __gcd(__gcd(i, j), k);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

int main() {
	cin >> P >> Q >> R;
	cout << min(P+Q,min(P+R,Q+R)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

ll N;

ll calc(vector<l_l> &v, bool is_l){
    ll res = 0;
    int sz = v.size();
    priority_queue<ll> pq;
    sort(all(v));
    //大きい方から
    if(is_l){
        // vの中のidxを尺取りみたいにもつ
        int idx = sz-1;
        for(int i = N - 1; i >= 0; i--){
            while(idx >= 0 && v[idx].first == i){
                pq.push(v[idx].second);
                idx--;
            }
            if(pq.empty())continue;
            res += pq.top();
            pq.pop();
        }
    }
    //小さい方から
    else{
        int idx = 0;
        for(int i = 0; i < N; i++){
            while(idx < sz && v[idx].first == i){
                pq.push(v[idx].second);
                idx++;
            }
            if(pq.empty())continue;
            res += pq.top();
            pq.pop();
        }
    }
    return res;
}
void solve(){
    cin >> N;
    vector<l_l> lefts;
    vector<l_l> rights;
    ll base = 0;
    rep(i,N){
        ll K, L, R;
        cin >> K >> L >> R;
        K--;
        if(L >= R){
            base += R;
            lefts.emplace_back(K, L-R);
        }
        else{
            base += L;
            rights.emplace_back(K+1, R-L);
        }
    }
    ll ans = base + calc(lefts,true) + calc(rights,false);
    cout << ans << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int t;
    cin >> t;
    while(t--)solve();
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

const ll mod = 1e9 + 7;

int main()
{
    ll n, k;

    cin >> n >> k;

    ll resenje = 0LL;

    ll donjaSuma = 0LL, gornjaSuma = 0LL;

    for(ll i = 1; i <= n+1; ++i)
    {
        donjaSuma += (i-1);
        gornjaSuma += (n-(i-1));

        if(i >= k)
        {
            resenje = (resenje + (gornjaSuma - donjaSuma + 1)%mod)%mod;
        }
    }

    cout << resenje << '\n';

    return 0;
}


Measured memory_bytes: 3580
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int[] list = new int[4];
            int count = 0;
            for (int i = n < 28 ? 0 : n - 27; i <= Math.min(n, 9); i++) {
                if (n - i > 27) {
                    continue;
                }
                for (int j = n < 28 ? 0 : n - 27; j <= Math.min(n - i, 9); j++) {
                    if (n - i - j > 18) {
                        continue;
                    }
                    for (int k = n < 28 ? 0 : n - 27; k <= Math.min(n - i - j, 9); k++) {
                        if (n - i - j - k > 9) {
                            continue;
                        }
                        list[0] = i;
                        list[1] = j;
                        list[2] = k;
                        list[3] = n - i - j - k;
                        if (list[3] < 10 && sum(list) == n) {
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }

        sc.close();
    }

    static int sum(int[] list) {
        return Arrays.stream(list).sum();
    }
}


Measured memory_bytes: 34120
# 045B
import sys
from collections import deque

Sa = deque(list(sys.stdin.readline().rstrip()))
Sb = deque(list(sys.stdin.readline().rstrip()))
Sc = deque(list(sys.stdin.readline().rstrip()))


now = Sa.popleft()

while True:
    if now =='a':
        if len(Sa)==0:
            print('A')
            break
        now = Sa.popleft()
    if now =='b':
        if len(Sb)==0:
            print('B')
            break
        now = Sb.popleft()
    if now =='c':
        if len(Sc)==0:
            print('C')
            break
        now = Sc.popleft()

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (x, a, b) = Read3Longs();
            return Math.Abs(x - a) > Math.Abs(x - b) ? "B" : "A";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28084
mod= 998244353

n,m,k=map(int,input().split())

ans=0
cmb=1
for i in range(k+1):
    ans+=cmb*m*pow(m-1,n-1-i,mod)
    ans%=mod
    cmb*=(n-1-i)*pow(i+1,mod-2,mod)
    cmb%=mod
print(ans)


Measured memory_bytes: 68420
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define pb push_back
using namespace std;
const int P=924844033,G=5,iG=554906420,maxn=8e5+10;
int n,r[maxn],fac[maxn],ifac[maxn],sz[maxn],N,l,u,v;vector<int> H[maxn];
typedef vector<int> Poly;
inline int Add(int x,int y){x+=y;return x>=P?x-P:x;}
inline int Dec(int x,int y){x-=y;return x<0?x+P:x;}
inline int Mul(int x,int y){return 1ll*x*y%P;}
int ksm(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=Mul(a,a)) if(b&1) ans=Mul(ans,a);
	return ans;
}
void DFT(Poly &a,int k){
	rep(i,0,N-1){
		r[i]=(i&1)?(r[i^1]|(1<<l-1)):(r[i>>1]>>1);
		if(i<r[i]) swap(a[i],a[r[i]]);
	}
	for(int mid=1;mid<N;mid<<=1){
		int wn=ksm(k==1?G:iG,(P-1)/(mid<<1));
		for(int R=mid<<1,j=0;j<N;j+=R){
			int w=1,*l=&a[j],*r=&a[j+mid];
			for(int k=0;k<mid;++k,++l,++r,w=Mul(w,wn)){
				int x=*l,y=Mul(*r,w);
				*l=Add(x,y);*r=Dec(x,y);
			}
		}
	}
	if(k==-1){
		int inv=ksm(N,P-2);
		rep(i,0,N-1) a[i]=Mul(a[i],inv);
	}
}
Poly operator *(Poly a,Poly b){
	int n=a.size()+b.size()-1;
	for(N=1,l=0;N<=n;N<<=1,l++);a.resize(N);b.resize(N);
	DFT(a,1);DFT(b,1);
	rep(i,0,N-1) a[i]=Mul(a[i],b[i]);
	DFT(a,-1);a.resize(n);
	return a;
}
void pre(int n){
	fac[0]=1;
	rep(i,1,n) fac[i]=Mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);
	per(i,n-1,0) ifac[i]=Mul(ifac[i+1],i+1);
}Poly a,b;
void dfs(int u,int fa){
	sz[u]=1;
	for(int v:H[u]) if(v^fa) dfs(v,u),sz[u]+=sz[v],++a[sz[v]];
	++a[n-sz[u]];
}
inline int C(int n,int k){return Mul(fac[n],Mul(ifac[k],ifac[n-k]));}
int main(){
	scanf("%d",&n);pre(n);a.resize(n+1);b.resize(n+1);
	rep(i,1,n-1) scanf("%d%d",&u,&v),H[u].pb(v),H[v].pb(u);
	dfs(1,0);
	rep(i,1,n) a[i]=Mul(a[i],fac[i]);reverse(a.begin(),a.end());
	rep(i,0,n) b[i]=ifac[i];
	a=a*b;a.resize(n+1);reverse(a.begin(),a.end());
	rep(i,1,n) printf("%d\n",Dec(Mul(C(n,i),n),Mul(ifac[i],a[i])));
	return 0;
}

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

int main(void) {
  int n, m, x, y, xn[1000], ym[1000], zn = -1000, zm = 1000, z, flag = 0;

  if(scanf("%d %d %d %d", &n, &m, &x, &y) != 0);

  for(int i = 0; i < n; i++) {
    if(scanf("%d", &xn[i]) != 0);
    if(zn < xn[i]) {
      zn = xn[i];
    }
  }
  for(int i = 0; i < m; i++) {
    if(scanf("%d", &ym[i]) != 0);
    if(zm >= ym[i]) {
      zm = ym[i];
    }
  }

  if(zn <= zm) {
    z = zn;
    while(1) {
      if(x < z && z <= y && zn < z & zm >= z) {
        flag = 1;
        break;
      } else if(z > zm) {
        break;
      }
      z++;
    }
  }

  if(flag) {
    printf("No War");
  } else {
    printf("War");
  }

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;
int prime[55560]={};

int main(){
    int n;
    cin >> n;
    vector<int> ffe;
    for(int i=2;i<=55555;i++){
        if(prime[i]==0&&i%5==1){
            ffe.push_back(i);
        }
        for(int j=i*2;j<=55555;j+=i){
            prime[j]=1;
        }
    }
    rep(i,n){
        cout << ffe[i] << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(void){
  
  int N, A, count = 0, i, 
      minCount = -1;
  bool isOdd = false;
  
  cin >> N;
  
  for(i = 0; i < N; i++){
    cin >> A;
    count = 0;
    while(A%2 == 0){
      A /= 2;
      count += 1;
    }
    if(count < minCount || 
       minCount == -1){
      minCount = count;
    }
  }
  
  cout << minCount << endl;
  
  return 0;
}
      

Measured memory_bytes: 256
#include<iostream>


#define NMAX 1000
#define WMAX 1000
using namespace std;

int main(void){

	int W,N;
	char gav;
	int k[NMAX+1],o[NMAX+1];
	int dp[2][WMAX+1];
	int max;

	for(int i=1;;i++){
		cin>>W;
		if(W==0) break;
		cin>>N;
		for(int j=0;j<N;j++){
			cin>>k[j]>>gav>>o[j];
		}
		for(int j=0;j<2;j++){
			for(int l=0;l<=W;l++){
				dp[j][l]=-1;
			}
		}
		dp[0][0]=0;
		for(int j=0;j<N;j++){
			for(int l=0;l<=W;l++){
				if(dp[0][l]>=0){
					if(l+o[j]<=W){
						if(dp[0][l]+k[j]>dp[0][l+o[j]]){
							dp[1][l+o[j]]=dp[0][l]+k[j];
						}
					}
				}
			}
			for(int l=0;l<=W;l++){
				if(dp[1][l]!=-1) dp[0][l]=dp[1][l];
			}
		}
		max=0;
		for(int j=0;j<=W;j++){
			if(dp[0][j]>dp[0][max]) max=j;
		}
		cout<<"Case "<<i<<":"<<endl;
		cout<<dp[0][max]<<endl;
		cout<<max<<endl;
	}

	return 0;
}

Measured memory_bytes: 1172
using System;
class AntiDiv{
	static void Main(string[] args){
		string[] ABCD = Console.ReadLine().Split(' ');
		long A = long.Parse(ABCD[0]);
		long B = long.Parse(ABCD[1]);
		long C = long.Parse(ABCD[2]);
		long D = long.Parse(ABCD[3]);
		long AntiDiv = (B - A + 1) - BetDiv(A,B,C) - BetDiv(A,B,D) + BetDiv(A,B,LCM(C,D));
		Console.WriteLine(AntiDiv);
	}
	static long BetDiv(long A,long B,long C){
		return (B / C) - ((A - 1) / C);
	}
	static long GCD(long A,long B){
		if((A % B) == 0)return B;
		else return GCD(B,A % B);
	}
	static long LCM(long A,long B){
		return A * B / GCD(A,B);
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

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

    if (X>=30) {
        cout<< "Yes"<< endl;
    } else {
        cout<< "No"<< endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int l;
    cin >> l;
    int p = 0;
    while (l >= pow(2, p+1)) ++p;
    int lastn = p + 1;
    int e = 0;
    VI a,d;
    RREP(i,0,p) if (l - (LL)pow(2,i) >= pow(2,p)) {
        //cout << i + 1 << " " << lastn << " " << minv + 1 << endl;
        a.push_back(i+1);
        d.push_back(l - (LL)pow(2,i));
        l -= pow(2,i);
        ++e;
    }
    cout << lastn << " " << (lastn - 1) * 2 + e << endl;
    REP(i,0,p) {
        cout << i + 1 << " " << i + 2 << " " << 0 << endl;
        cout << i + 1 << " " << i + 2 << " " << (LL)pow(2,i) << endl;
    }
    REP(i,0,e) cout << a[i] << " " << lastn << " " << d[i] << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, a, b; cin >> n >> a >> b;
    if ((long long)a * b < n || a + b > n + 1) { cout << -1 << endl; return 0; }
    vector<int> ans;
    for (int i = 0; i < b; i++) ans.push_back(b-i);
    int x = b;
    for (int i = 0; i < a-1; i++) {
        int y = x + (n-b) / (a-1);
        if ((n-b)%(a-1) > i) y++;
        for (int z = y; z > x; z--) ans.push_back(z);
        x = y;
    }
    for (int i : ans) cout << i << ' '; cout << endl;
}


Measured memory_bytes: 3440
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int A[N], B[N], C[N];
  for(int i=0;i<N;i++){
    A[i] = i+1;
  }
  rep(i,N) cin >> B[i];
  rep(i,N) cin >> C[i];

  int W = 0, M = 0, Y, Z;
  bool ans1 = false, ans2 = false;
  do {
    for(int i=0;i<N;i++){
      if(A[i] != B[i]){
        ans1 = true;
        break;
      }
    }
    if(ans1) W++;
    else Y = W;
    ans1 = false;
  }while (next_permutation(A, A+N));

  do {
    for(int i=0;i<N;i++){
      if(A[i] != C[i]){
        ans2 = true;
        break;
      }
    }
    if(ans2) M++;
    else Z = M;
    ans2 = false;
  }while (next_permutation(A, A+N));

  cout << abs(Y-Z)<< endl;

}

Measured memory_bytes: 256
from math import hypot

T = input()
for t in xrange(1, T + 1):
    x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
    x4 = (((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) /
          (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3)))
    y4 = (((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) /
          (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3)))
    print "%.3f %.3f %.3f" % (x4, y4, hypot(x1 - x4, y1 - y4))

Measured memory_bytes: 4432
#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>

using namespace std;

const int N = 3003;
const int INF = 1e9 + 239;

int dp[N][N];

//prefix i dishes, time j

int a[N];
int b[N];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, x;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	
	vector<int> ind(n);
	iota(ind.begin(), ind.end(), 0);
	sort(ind.begin(), ind.end(), [&](int i, int j) {
		return a[i] < a[j];
	});

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = -INF;
		}
	}
	dp[0][0] = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int ri = ind[i];
		for (int j = 0; j < N; j++) {
			//not take
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			//take
			if (j + a[ri] < N) {
				dp[i + 1][j + a[ri]] = max(dp[i + 1][j + a[ri]], dp[i][j] + b[ri]);
			}
			if (j < x && j + a[ri] >= x) {
				ans = max(ans, dp[i][j] + b[ri]);
			}
		}
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < x; j++) {
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 35584
import math

e = 10**(-7)
n,k = map(int, input().split())
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += 1
    else:
        ans += (1/2)**(int(math.log2((k-e)/i))+1)
    
print(ans / n)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// typedef pair<ll,ll> Pair;
// ll mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,c,i,j,k,temp,temp2,n,m,sum=0;
    string a,b,tem;
    cin >> a;
    for(i=0;i<a.size();i=i+2){
        if(a[i]!='h'||a[i+1]!='i'){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    
}

Measured memory_bytes: 256
using System;

namespace Atcoder
{
    class ABC118_A
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            Console.Write(b % a == 0 ? a + b : b - a);
        }
    }
}


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




int main(){
    int n,k;
    int a;
    vector<int> v;
    cin>>n>>k;
    for(int i=0; i<n; i++){
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=1; i<=k; i++){
        ans+=v[n-i];
    }
    cout<<ans<<endl;
    return 0;
  }


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

int main(void) {
  // input
  int k, x;
  cin >> k >> x;

  vector<int> v(2*k-1);
  for (int i=0; i<v.size(); i++) {
    v[i] = x-k+1+i;
  }

  // output
  for (int i=0; i<v.size(); i++) {
    if (i!=0) cout << " ";
    cout << v[i];
  }
  return 0;
}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 998244353;

int n,c[8];
char s[maxn];

int main() {
    read(n);scanf("%s",s+1);
    for(int i=1;i<=n*3;i++) s[i]=s[i]=='R'?0:(s[i]=='G'?1:2);
    int ans=1;c[0]=n;
    for(int i=1;i<=n*3;i++) {
        int t;
        if(c[t=7-(1<<s[i])]) {ans=1ll*ans*c[t]%mod,c[t]--;continue;}t=0;
        for(int x=0;x<3;x++)
            if(x!=s[i]&&c[1<<x]) {t=1;ans=1ll*ans*c[1<<x]%mod;c[1<<x]--,c[(1<<x)|(1<<s[i])]++;break;}
        if(!t) ans=1ll*ans*c[0]%mod,c[0]--,c[1<<s[i]]++;
        // for(int x=0;x<=7;x++) printf("%d ",c[x]);puts("");
    }
    write(ans);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back;
using namespace std;
string s,a,b,c,d,tmp;
bool sabi;
int main(){
    cin>>s;
    tmp=s;
    sabi=1;
    reverse(tmp.begin(),tmp.end());
    if(s!=tmp)sabi=0;
    for(int i = 0;i<=(s.length()-3)/2;i++){
        a+=s[i];
    }
    b = a;
    // cout<<sabi<<endl;
    reverse(b.begin(),b.end());
    if(a!=b)sabi=0;
    // cout<<sabi<<endl;
    // for(int i = (s.length()+1)/2;i<s.length();i++){
    //     c+=s[i];
    // }
    // d = c;
    // reverse(d.begin(),d.end());
    // if(c!=d)sabi=0;
    if(sabi)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
from itertools import combinations

N, K = map(int, input().split())
coord = sorted([tuple(map(int, input().split())) for _ in range(N)])
ans = float('inf')
for left, right in combinations(range(N), 2):
    n_points = right - left + 1
    if n_points < K: continue
    width = coord[right][0] - coord[left][0]
    y_coords = sorted([y for _, y in coord[left: right+1]])
    for i in range(n_points - K + 1):
        height = y_coords[i+K-1] - y_coords[i]
        ans = min(ans, width*height)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int MAXN = 100 + 4;
const int INF = 0x3f3f3f3f;
const int WHITE = 0;
const int BLACK = 1;
const int GRAY = 2;
int G[MAXN][MAXN];
int d[MAXN], p[MAXN], status[MAXN];
int N;

int prim()
{
    int u, min_d;
    memset ( p, -1, sizeof(p) );
    memset ( status, WHITE , sizeof(status) );
    d[0] = 0;
    for ( int i = 1; i <= N; i++ ) d[i] = INF;

    while ( true ) {
        min_d = INF;
        u = -1;
        for ( int i = 0; i < N; i++ ) {
            if ( min_d > d[i] && status[i] != BLACK ) {
                u = i;
                min_d = d[i];
            }
        }

        if ( u == -1 ) break;
        status[u] = BLACK;
        for ( int v = 0; v < N; v++ ) {
            if ( G[u][v] != INF && status[v] != BLACK ) {
                if ( d[v] > G[u][v] ) {
                    d[v] = G[u][v];
                    p[v] = u;
                    status[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for ( int i = 0; i < N; i++ )
        if ( p[i] != -1 ) sum += G[i][p[i]];

    return sum;
}

int main()
{
    int e;
    cin>>N;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            cin>>e;
            G[i][j] = e == -1 ? INF : e;
        }
    }
    int ans = prim();
    cout<<ans<<endl;
}



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

typedef long long ll;
typedef unsigned long long ull;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout<<i<<endl;
#define AS(i) cout<<i<<" ";

const int INF = 1001001001;

using namespace std;


int main() {

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

    int ans = 0;

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

    string now = a[0];
    ans++;
    rep(i, n) {
        if (a[i] != now) {
            now = a[i];
            ans++;
        }
    }

    AA(ans);
}

Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main () {
	int a,b;
 	cin >> a >> b;
  	string s(b, '0'+a);
  	string t(a, '0'+b);
  	cout << min(s, t) <<endl;
  
  
  	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cerr << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
    return 0;
}
 
const int MOD = 998244353, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37;
int n;
vec<vec<int>> p;
vec<int> ans;
vec<int> prefix;
vec<int> v, h;
 
void check(int i) {
    if (i == n) {
        int cnt = 0;
        h.clear(), v.clear();
        for (int i = 0; i < n; ++i) {
            if (prefix[i] >= 1) {
                cnt++;
            }
            if (prefix[i] == 1) {
                h.pb(p[i][1]);
            }
            if (prefix[i] == 2) {
                v.pb(p[i][0]);
            }
        }   
        v.pb(0);
        h.pb(0);
        int cur = 0;
        for (int i = 0; i < n; ++i) {
            if (prefix[i] == 1 || prefix[i] == 2) continue;
            int tmp = INF;
            for (int j = 0; j < $(h); ++j) {
                tmp = min(tmp, abs(h[j] - p[i][1]));
            }
            for (int j = 0; j < $(v); ++j) {
                tmp = min(tmp, abs(v[j] - p[i][0]));
            }
            cur += tmp * p[i][2];
        }
        ans[cnt] = min(ans[cnt], cur);
        return;
    }
    else {
        for (int j = 0; j < 3; ++j) {
            prefix.pb(j);
            check(i + 1);
            prefix.pop_back();
        }
    }
}
 
void solve() {
    cin >> n;
    p.resize(n, vec<int>(3));
    cin >> p;
    ans.resize(n + 1, INF);
 
    check(0);
 
    for (int i = 0; i <= n; ++i) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f",d,r,f);
    return 0;
}


Measured memory_bytes: 2132
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
	int n;
	scanf("%d", &n);

	mii ma, mb;
	for (int i = 0; i < n; i++) {
		int v;
		scanf("%d", &v);
		if (i % 2 == 0) {
			ma[v]++;
		} else {
			mb[v]++;
		}
	}
	
	vp va, vb;
	for (pii p : ma) {
		va.push_back(pii(p.second, p.first));
	}
	va.push_back(pii(0, 0));
	for (pii p : mb) {
		vb.push_back(pii(p.second, p.first));
	}
	vb.push_back(pii(0, 0));
	sort(va.begin(), va.end());
	sort(vb.begin(), vb.end());

	int ans = 0;
	if (va[va.size()-1].second != vb[vb.size()-1].second) {
		ans = va[va.size()-1].first + vb[vb.size()-1].first;
	} else {
		ans = max(va[va.size()-1].first + vb[vb.size()-2].first,
				  va[va.size()-2].first + vb[vb.size()-1].first);
	}

	printf("%d\n", n - ans);

	return 0;	
}

Measured memory_bytes: 6136
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

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

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl

int32_t main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N; cin >> N; vector<int> H(N); for(int i = 0; i < N; i++) cin >> H[i];
    int ret = 0;
    int temp = 0;
    int cur = H[0];
    
    for(int i = 0; i < N; i++)
    {
        if(H[i] <= cur)
        {
            temp += 1;
        }
        else
        {
            ret = max(ret, temp);
            temp = 1;
        }
        cur = H[i];
    }
    ret = max(ret, temp);
    cout << ret - 1 << endl;
      
    return 0;
}


Measured memory_bytes: 1024
#16:07
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
now = []
for i in range(n):
  j = raw[i][cnt[i]]
  if i < j and i == raw[j][cnt[j]]:
    now.append(i)
    now.append(j)
ans = 0
while now:
  ans += 1
  last = now
  now = []
  for x in last:
    cnt[x] += 1
    if cnt[x] < n-1:
      y = raw[x][cnt[x]]
      if x == raw[y][cnt[y]]:
        now.append(x)
        now.append(y)
  #print(now)
if cnt == [n-1 for _ in range(n)]:
  print(ans)
else:
  print(-1)


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

values = {}
cnt = n

for i in range(n):
    if a[i] in values:
        values[a[i]] += 1
    else:
        values[a[i]] = 1

    if values[a[i]] == a[i]:
            cnt -= a[i]

print(cnt)

Measured memory_bytes: 21856
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

void deb(vector<int> &da){
    int x=da.size();
    rip(i,x,0){
        if(i==x-1){
            cout << da[i] << endl;
        }else{
            cout << da[i] << ' ';
        }
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> da(n,vector<int>(m));
    rip(i,n,0){
        rip(j,m,0){
            cin >> da[i][j];
            da[i][j]--;
        }
    }
    vector<int> co(m,0);
    vector<bool> ju(m,true);
    vector<int> po(n,0);
    int no=0,ans=n+1;
    rip(i,n,0){
        co[da[i][0]]++;
    }
    rip(i,m-1,0){
        //deb(co);
        int ma=0;
        rip(j,m,0){
            if(co[j]>ma){
                ma=co[j];
                no=j;
            }
        }
        ans=min(ans,ma);
        ju[no]=false;
        rip(j,n,0){
            while(!ju[da[j][po[j]]]){
                co[da[j][po[j]]]--;
                po[j]++;
                co[da[j][po[j]]]++;
            }
        }
    }
    int ma=0;
    rip(i,m,0){
        if(co[i]>ma){
            ma=co[i];
        }
    }
    ans=min(ans,ma);
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    map <ll,ll,greater<ll>> mapp;
    for (int z=0;z<n;z++){
    	ll temp;
    	cin >> temp;
    	mapp[temp]++;
    }
    for (int z=0;z<m;z++){
    	ll b,c;
    	cin >> b >> c;
    	mapp[c] += b;
    }
    ll ans = 0;
    for (auto it = mapp.begin();it !=mapp.end() && n > 0;it++){
    	ans += (it->first)*min((it->second),n);
    	n -= it->second;
    }
    cout << ans << endl;
    cin >> n;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 998244353;



int a[1005][1005];

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



	REP(i, n)REP(j, n - 1) {
		cin >> a[i][j];
		a[i][j]--;
	}

	REP(i, n) {
		a[i][n-1] = -1;
	}

	
	int ans = 0;

	VB b(n, false);
	VB c(n, false);
	VI d(n);
	VI e(n, 0);
	REP(i, n) {
		d[i] = a[i][0];
	}
	while (true) {
		bool f = false;

		REP(i, n) {
			if (d[i] == -1)continue;
			if (d[d[i]] == -1)continue;
			if (d[d[i]] == i) {
				f = true;
				if (b[d[i]] || b[d[d[i]]])continue;
				b[i] = true;
				b[d[i]] = true;
				e[i]++;
				e[d[i]]++;
				int k = d[i];
				d[i] = a[i][e[i]];
				d[k] = a[k][e[k]];
			}
		}
		b = c;
		if (!f)break;
		ans++;
	}

	REP(i, n) {
		if (d[i] != -1) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << ans << endl;
	
}





Measured memory_bytes: 4224
import fractions
a, b, c, d=map(int, input().split())
k=fractions.gcd(c, d)
lcm=c*d//k
x=b//c - (a-1)//c
y=b//d - (a-1)//d
z=b//lcm - (a-1)//lcm
print(b-a+1-(x+y-z))

Measured memory_bytes: 5560
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 100010

using namespace std;

inline int read(int &T) {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return T = f ? -s : s;
}

const int mod = 998244353;

void print(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + 48);
}

int n;

int a[MAXN], b = 1;

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++) {
		if (a[i] == 0) {puts("0"); return 0;}
		b *= a[i];
		if (b > (int)(1e18) || b <= 0) {puts("-1"); return 0;}
	} 
	cout << b;
}

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

using namespace std;

map<string, bool> record;

int main(int argc, char const *argv[])
{
    int n;
    string oper, s;
    while (~scanf("%d", &n))
    {
        record.clear();
        for (int i = 0; i < n; ++i)
        {
            cin >> oper >> s;
            if("insert" == oper) record[s] = true;
            else
            {
                if(record[s]) printf("yes\n");
                else printf("no\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 52628
#include <iostream>
#include <cstdio>

using namespace std;

double l[10];
double v1, v2;

int main()
{
  while (scanf("%lf", &l[0]) == 1) {
    int sum = l[0];
    for (int i = 1; i < 10; i++) {
      scanf(",%lf", &l[i]);
      sum += l[i];
    }
    scanf(",%lf,%lf", &v1, &v2);
    
    double x = (sum * v1) / (v1 + v2);

    int c;
    for (c = 0; x > 0; c++) {
      x -= l[c];
    }
    
    printf("%d\n", c);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<62)-1
#define MAX 1000000000
signed main(){
    int K; cin>>K;
    priority_queue<pii,vector<pii>,greater<pii>> Q;
    vi F(K,INF);
    rep(i,1,10){
        if(F[i%K]>i){
            Q.push(mp(i,i%K));
            F[i%K]=i;
        }
    }
    while(Q.size()>0){
        int X=Q.top().first,Y=Q.top().second; Q.pop();
        if(Y==0){
            cout<<X<<endl;
            break;
        }
        if(F[Y]<X) continue;
        rep(i,0,10){
            int Z=(Y*10+i)%K,P=X+i;
            if(F[Z]>P){
                F[Z]=P;
                Q.push(mp(P,Z));
            }
        }
    }
}


Measured memory_bytes: 6512
N,M = [int(x) for x in input().split()]

A = [int(x) for x in input().split()]
A.sort()
max = 0
BC = []
for i in range(M):
    b,c = [int(x) for x in input().split()]
    max += b
    BC.append([c,b])

BC.sort(reverse = True)
str =[]
for c,b in BC:
    str+=[c]*b
    # print(str)
    if(len(str) > N):
        break

now = 0
for i in range(len(A)):
    if(now >= max or str[now] < A[i]):
        break
    if(A[i] < str[now]):
        A[i] = str[now]
        now+=1

# print(A)
print(sum(A))


Measured memory_bytes: 26444
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    ans = sum(b)

    for i in range(1, n):
        if a[i] - a[i - 1] == 1:
            ans += c[a[i - 1] - 1]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, A;
  cin >> N;
  cin >> A;
  
  N = N % 500;
  
  if (N - A <= 0){
    cout << "Yes" <<endl;
  }else{ 
    cout << "No" <<endl;
  }
  
  return 0;
}

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

int main() {
    int X, N;
    cin >> X >> N;
    if (N == 0) {
        cout << X;
    }
    else {
        vector<int>p(N);
        for (int i = 0; i < N; i++) {
            cin >> p.at(i);
        }
        sort(p.begin(), p.end()); 
        bool check = false;
        int num = 0;
        for (int i = 0; i < N; i++) {
            if (p.at(i) == X) {
                check = true;
                num = i;
                break;
            }
        }
        if (!check) {
            cout << X;
        }
        else {
            if (num == 0) {
                cout << X - 1;
            }
            else if (num == N-1) {
                if (p.at(N-1) - p.at(N-2) > 1) {
                    cout << X - 1;
                }
                else {
                    cout << X + 1;
                }
            }
            else {
                int small = p.at(0) - 1, large = p.at(N-1) + 1;
                for (int i = num; i > 0; i--) {
                    if (p.at(i) - p.at(i-1) > 1) {
                        small = p.at(i) - 1;
                        break;
                    }
                }
                for (int i = num; i < N-1; i++) {
                    if (p.at(i+1) - p.at(i) > 1) {
                        large = p.at(i) + 1;
                        break;
                    }
                }
                if (large - X < X - small) {
                    cout << large;
                }
                else {
                    cout << small;
                }
            }
        }
    }
}

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

#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

const ll oo=1e18;
const int MOD=1000000007;
const int INF=1000000000;
const ld EPS=0.000000001;

string s1,s2,ans="";
int dp[3005][3005];

signed main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>s1>>s2;
    for(int i=1;i<=s1.length();++i) {
        for(int j=1;j<=s2.length();++j) {
            if(s1[i-1]==s2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=s1.length(),j=s2.length();
    while(i>0&&j>0) {
        if(s1[i-1]==s2[j-1]) {
            ans=s1[i-1]+ans;
            --i;--j;
        }
        else {
            if(dp[i][j-1]>dp[i-1][j]) --j;
            else --i;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
    const int c = 400;
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> rate(9, 0);
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    for(int i=0; i<n; ++i){
        for(int j=1; j<=9; ++j){
            if(j == 9){
                rate[8]++;
                break;
            }
            else if(a[i] < c * j){
                rate[j-1]++;
                break;
            }
        }
    }
    int min = 0;
    int max = 0;
    for (int i=0; i<8; ++i){
        if(i == 7){
            min += (rate[7] > 0 || rate[8] > 0) ? 1 : 0;
        }
        else {
            min += (rate[i] > 0) ? 1 : 0;
            max += (rate[i] > 0) ? 1 : 0;
        }
    }
    max += rate[8] + ((rate[7] > 0) ? 1 : 0);
    cout << min << " " << max << endl;
}

Measured memory_bytes: 256