akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

void input(vector<int>& rvnHigh)
{
  int nHighSiz;
  cin >> nHighSiz;
  rvnHigh.resize(nHighSiz);

  for (int& rnHigh : rvnHigh)
    cin >> rnHigh;
}

llong calcMinStepHigh(vector<int>& rvnHigh)
{
  llong nMinStepHigh = 0;

  for (int i = 0; i < rvnHigh.size() - 1; ++i)
    if (rvnHigh[i] - rvnHigh[i + 1] > 0)
    {
      nMinStepHigh += rvnHigh[i] - rvnHigh[i + 1];
      rvnHigh[i + 1] = rvnHigh[i];
    }

  return nMinStepHigh;
}
  
int main()
{
  vector<int> vnHigh;
  
  input(vnHigh);
  cout << calcMinStepHigh(vnHigh) << endl;

  return 0;
}

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

int x,a,b;

int main(){
  cin>>x>>a>>b;
  int da=abs(x-a);
  int db=abs(x-b);

  int res=min(da,db);

  char cres;
  if (res==da) cres='A';
  else cres='B';

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



Measured memory_bytes: 256
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    static String P = "";
    static String Q = "";
    static int countP = 0;
    static int countQ = 0;
    static boolean isP = false;
    static boolean isQ = false;
    public static void main(String[] args) {
        int N = nextInt();
        int M = nextInt();

        if(N == M) println("Yes");
        else println("No");
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
string s;
ll n;
int main(){FAST;
cin>>n>>s;
ll ans = 0;
for(int i=0;i<n-2;++i){
  if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C'){
    ans++;
  } 
}
cout<<ans;
return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
//#define int unsigned long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

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

	int N; cin >> N;
	int ans = 0;
	FOR(i, 1, N + 1) {
		if (1 <= i && i < 10) {
			ans++;
		}
		else if (100 <= i && i < 1000)ans++;
		else if (10000 <= i && i < 100000) {
			ans++;
		}
	}
	print(ans);
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,x=0;
    cin>>n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin>>a[i];
        x=x^a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cout<<(x^a[i]);
        if(i==n-1) cout<<endl;
        else cout<<" ";
    }
    
    
    return 0;
}

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

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> cnt(n + 2), pref(n + 2), suff(n + 2);
    const ll mod = 1e9 + 7;
    for (ll i = 1; i <= n + 1; i++) {
        pref[i] = pref[i - 1] + i - 1;
    }
    for (ll i = 1; i <= n + 1; i++) {
        suff[i] = suff[i - 1] + (n - i + 1);
    }
    for (ll i = 1; i <= n + 1; i++) {
        ll mn = pref[i];
        ll mx = suff[i];
        cnt[i] = mx - mn + 1;
    }
    ll ans = 0;
    for (ll i = k; i <= n + 1; i++) {
        ans += cnt[i];
        ans %= mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 8008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		int n,m;
		int[] b,c;
		int[][] A;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine().split(" ");
		n = Integer.parseInt(str[0]);
		m = Integer.parseInt(str[1]);
		A = new int[n][m];
		b = new int[m];
		c = new int[n];
		for(int i=0;i<n;i++){
			str = br.readLine().split(" ");
			for(int j=0;j<m;j++){
				A[i][j] = Integer.parseInt(str[j]);
			}
		}
		for(int i=0;i<m;i++){
			int num = Integer.parseInt(br.readLine());
			for(int j=0;j<n;j++){
				c[j] += A[j][i] * num;
			}
		}
		for(int i=0;i<n;i++){
			System.out.println(c[i]);
		}
		br.close();
	}
}

Measured memory_bytes: 27512
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[10001][4],d[10001],f,g,h,j,i,k;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			for(j=0;j<3;j++) scanf("%d",&s[i][j]);
				if(s[i][0]==100||s[i][1]==100||s[i][2]==100) d[i]=1;
				else if((s[i][0]+s[i][1])/2>=90) d[i]=1;
				else if((s[i][0]+s[i][1]+s[i][2])/3>=80) d[i]=1;
				else if((s[i][0]+s[i][1]+s[i][2])/3>=70) d[i]=2;
				else if((s[i][0]+s[i][1]+s[i][2])/3>=50&&s[i][0]>=80||s[i][1]>=80) d[i]=2;
				else d[i]=3;
		}
		for(i=0;i<a;i++){
			if(d[i]==1) printf("A\n");
			if(d[i]==2) printf("B\n");
			if(d[i]==3) printf("C\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2700
#include <stdio.h>

int main(){
   int A,B,a[100000],b[100000],m,i,x,y,c,ans,ma,mb;
 
   scanf("%d %d %d",&A,&B,&m);
   for (i=0;i<A;i++) {
      scanf("%d",&a[i]);
      if (i==0) ma=a[0];
      else if (ma>a[i]) ma=a[i];
   }
   for (i=0;i<B;i++) {
      scanf("%d",&b[i]);
      if (i==0) mb=b[0];
      else if (mb>b[i]) mb=b[i];
   }
   ans=ma+mb;
   for (i=0;i<m;i++) {
      scanf("%d %d %d",&x,&y,&c);
      if (ans>a[x-1]+b[y-1]-c) ans=a[x-1]+b[y-1]-c;
   }
   printf("%d\n",ans);
   return 0;
}


Measured memory_bytes: 896
using System;
using System.Linq;

namespace ABC167
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int index = input.IndexOf("7");

            if(index != -1)
            {
                Console.WriteLine("Yes");

            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 26120
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  ll n,answer=0,count=0;
  cin >> n;
  rep(i,(n+1)/2){
    rep(j,(2*i+1)/3+1){
      if((2*i+1)%(j+1)==0){count++;}
    }
    if(count==7){answer++;}//自分自身以外の約数の合計が7個
    count=0;
  }
  cout << answer << endl;
}


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

int main()
{
    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;
    int cnt = 0;
    for (int i = 0; i < A+1; i++)
    {
        for (int j = 0; j < B+1; j++)
        {
            for (int k = 0; k < C+1; k++)
            {
                if (500 * i + 100 * j + 50 * k == X)
                {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 892
#include <stdio.h>
#include <stdlib.h>

#define MAX 100

void show_array(int *a, int n)
{
     int i;
     
     for (i = 0; i < n; i++) {
         if (i > 0) printf(" ");
         printf("%d", a[i]);    
     }
     printf("\n");
}

selection_sort(int *a, int n)
{
    int i, j, cnt = 0;
    int minj = 0, minv;
    int t;
    
    for (i = 0; i < n; i++) {
        minv = a[i];
        minj = i;
        for (j = i; j < n; j++) {
            if (a[j] < minv) {
                minv = a[j];
                minj = j;
            }
        }
        if (minj != i) {
            t = a[i];
            a[i] = a[minj];
            a[minj] = t;  
            cnt++;  
        }
    }
    
    show_array(a, n);
    printf("%d\n", cnt);
}

int main(int argc, char *argv[])
{
	int i, n, a[MAX];

	scanf("%d", &n);
  
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
  
        selection_sort(a, n);
  	
	return 0;
}


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

int size;
char hand_up[100][100];
int map[100][100];

int main(void) {
	int i,j;
	int ctarget,cpos;
	int found;
	while(1) {
		scanf("%d",&size);
		if(size==0)break;
		for(i=0;i<size;i++) {
			for(j=0;j<size;j++)scanf("%d",&map[i][j]);
		}
		memset(hand_up,0,sizeof(hand_up));
		for(i=0;i<size;i++) {
			ctarget=0x7fffffff;
			cpos=-1;
			for(j=0;j<size;j++) {
				if(map[i][j]<=ctarget) {
					ctarget=map[i][j];
					cpos=j;
				}
			}
			hand_up[i][cpos]|=1;
		}
		for(i=0;i<size;i++) {
			ctarget=0;
			cpos=-1;
			for(j=0;j<size;j++) {
				if(map[j][i]>=ctarget) {
					ctarget=map[j][i];
					cpos=j;
				}
			}
			hand_up[cpos][i]|=2;
		}
		found=0;
		for(i=0;i<size;i++) {
			for(j=0;j<size;j++) {
				if(hand_up[i][j]==3) {
					printf("%d\n",map[i][j]);
					found=1;
				}
			}
		}
		if(!found)puts("0");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<ll, ll>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int n, v[5], k[5];
map<int, int> m;


int main(void) {
  cin >> n;
  
  rep(i, 0, n) {
    int a;
    cin >> a;
    m[a]++;
  }
  
  if (sz(m)>3) {
    puts("No");
    return 0;
  }
  int i = 0;
  for (auto itr=m.bg; itr!=m.en; itr++) {
    k[i] = itr->first;
    v[i] = itr->second;
    i++;
  }
  
  bool ok = false;
  
  if (i==1) {
    if (k[0]==0) ok = true;
  } else if (i==2) {
    if (k[0]==0) {
      swap(k[0], k[1]);
      swap(v[0], v[1]);
    }
    if (k[1]==0 && (v[0]+v[1])%3==0 && v[0]==(v[1]*2)) ok = true;
  } else {
  if ((k[0]^k[1])==k[2] && v[0]==v[1] && v[0]==v[2]) ok = true;
  }
  if(ok) puts("Yes");
  else puts("No");
    

    return 0;
}



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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
const int N=1e5 + 5;

string s;

string substr(int i, int j)
{
	string str ="";
	int k;
	for(k=i;k<=j;k++)
	{
		str += s[k];
	}
	return str;
}

bool ok(string x){
    vector < ll > cnt(27, 0);
    for(ll i : x)
        cnt[i - 'a']++;
    for(ll i : x){
        if(cnt[i - 'a'] > (ll)x.size() / 2)
            return 1;
    }
    return 0;
}
 

int32_t main()
{
	IOS;
	cin >> s;
	int n=s.size();
	int cur=2;
	int i=0;
	int j=0;
	int k=0;
	for(cur=2;cur<=min(n,5ll);cur++)
	{
		for(j=0;j + cur - 1 < n;j++)
		{
			string str= s.substr(j,cur);
			if(ok(str)==1)
			{
				cout << j+1 << " " << j+cur << endl;
				return 0;	
			}	
		}	
	}
	cout << "-1 -1 " << endl;
}


Measured memory_bytes: 512
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next().toList()
    println(s.filter { it == '1' }.size)
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31880
#include<iostream>
#include<cstdio>
#define mod 1000000007
using namespace std;
int f[1001000],n,m,k;
long long fac[1010000],inv[1010000],mi[1010000];
int C(int a,int b){return 1ll*fac[a]*inv[b]%mod*inv[a-b]%mod;}
int main()
{
	inv[0]=inv[1]=fac[0]=mi[0]=1;
	for(int i=1;i<=900000;i++)fac[i]=fac[i-1]*i%mod;
	for(int i=2;i<=900000;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod; 
	for(int i=1;i<=900000;i++)inv[i]=inv[i-1]*inv[i]%mod;
	for(int i=1;i<=900000;i++)mi[i]=mi[i-1]*3%mod;
	scanf("%d%d%d",&n,&m,&k);
	f[0]=1;
	for(int t=1;t<=m+k;t++)
		f[t]=((f[t-1]*2-(t-k-1>=0?C(t-1,t-k-1):0)-(t-1>=m?C(t-1,m):0))%mod+mod)%mod;
	
	long long ans=0;
	for(int t=0;t<=m+k;t++)
		ans=(ans+C(t+n-1,n-1)*mi[m+k-t]%mod*f[t]%mod)%mod;
	printf("%lld\n",ans);return 0;
}
/*把三个人记为ABC 
考虑他们的出牌顺序：记为AACBACBABC.....
A表示A出了一张牌，B，C同理
显然，每个出牌顺序对应一种三个人的手牌
枚举他们一共出了几张牌，在这个出牌顺序中，A要出现正好n次，且B，C出现次数要分别<=m，<=k 
记他们出的牌数为n+t
ans=∑( C(t+n-1,n-1)  *  3^(m+k-t)  *  ∑C(t,i)(max(0,t-k)<=i<=min(t,m))  ) 
        A出现的位置  剩余的牌             i为枚举B的出现次数 

记f(t)=∑C(t,i)(max(0,t-k)<=i<=min(t,m))

因为C(t,i)=C(t-1,i)+C(t-1,i-1)
把f(t)里的所有C(t,i)用C(t-1,i)+C(t-1,i-1)带，可以得到 
f(t)=(f(t-1)-(t-k-1>=0?C(t-1,t-k-1)))
    +(f(t-1)-(t-1>=m?C(t-1,m)))
因为i的取值范围不同，所以要进行一些微调(即后面减的部分)

*/ 

Measured memory_bytes: 26880
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

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

    int m[N];
    REP(i, N) m[i] = -1;

    bool f = true;
    REP(i, M) {
        int s, c;
        cin >> s >> c;
        --s;
        if (N > 1 && s == 0 && c == 0) {
            f = false;
            break;
        }

        if (m[s] == -1) m[s] = c;
        else {
            if (c != m[s]) {
                f = false;
                break;
            }
        }
    }

    if (!f) cout << -1 << endl;
    else {
        string out;
        REP(i, N) {
            int o = m[i];
            if (o == -1) {
                if (i == 0 && N > 1) o = 1;
                else o = 0;
            }

            out += to_string(o);
        }
        cout << out << endl;
    }
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,k,a[1005],sum;
bool cmp(int a,int b){
	return a<b;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);in(k);for(int i=1;i<=n;i++)in(a[i]);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=k;i++)sum+=a[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 3764
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct node {
	int key;
	node *pre, *nex;
};
node *nil;
void init() {
	nil = (node *)malloc(sizeof(node));
	nil->nex = nil;
	nil->pre = nil;
}
void insert(int key) {
	node *a = (node*)malloc(sizeof(node));
	a ->key = key;
	a->nex = nil->nex;
	nil->nex->pre = a;
	nil->nex = a;
	a->pre = nil;
}
node* search(int key) {
	node *cur;
	cur = nil->nex;
	while (cur != nil && cur->key != key) {
		cur = cur->nex;
	}
	return cur;
}
void deletenode(node *pt) {
	if (pt != nil) {
		pt->nex->pre = pt->pre;
		pt->pre->nex = pt->nex;
		free(pt);
	}
	else return;
	
}
void deleteFirst() {
	deletenode(nil->nex);
}
void deleteLast() {
	deletenode(nil->pre);
}
void deletekey(int key) {
	deletenode(search(key));
}
void printNode() {
	node *cur = nil->nex;
	/*while (cur != nil) {
		printf("%d", cur->key);
		cur = cur->nex;
	}*/
	int i = 0;
	while (1) {
		if(cur == nil)break;
		if (i++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->nex;
	}
	printf("\n");
}
int main() {
	
	int n, key;
	char com[20];
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') {
			insert(key);
		}
		else if (com[6] == 'F') {
			deleteFirst();
		}
		else if (com[6] == 'L') {
			deleteLast();
		}
		else {
			deletekey(key);
		}
		
				

			}
		
	
		printNode();
		return 0;
}

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

int main(){
  int n, a;
  bool flag = false;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    if(a % 2 == 0){
      if(a % 3 != 0 && a % 5 != 0){
        flag = true;
      }
    }
  }
  string ans = "APPROVED";
  if(flag) ans = "DENIED";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b,n;
  for(;cin>>a>>b>>n;)
    {
      int s=0;
      a=a%b;
      for(int i=0;i<n;i++)
	{
	  a*=10;
	  s+=a/b;
	  a%=b;
	}
      cout<<s<<endl;

    }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cap, rev;
    Edge(){};
    Edge(int to0, int cap0){to = to0; cap = cap0;}
    Edge(int to0, int cap0, int rev0){to = to0; cap = cap0; rev = rev0;}
};

int maxFlow(const vector<vector<Edge> >& edges0, int source, int sink)
{
    static vector<vector<Edge> > edges;
    static vector<bool> used;

    class Func{
    public:
        static int dfs(int s, int t, int f){
            if(s == t)
                return f;
            used[s] = true;
            for(unsigned i=0; i<edges[s].size(); ++i){
                Edge& e = edges[s][i];
                if(!used[e.to] && e.cap > 0){
                    int g = dfs(e.to, t, min(f, e.cap));
                    if(g > 0){
                        e.cap -= g;
                        edges[e.to][e.rev].cap += g;
                        return g;
                    }
                }
            }
            return 0;
        }
    };

    int n = edges0.size();
    edges.assign(n, vector<Edge>());
    for(int i=0; i<n; ++i){
        for(unsigned j=0; j<edges0[i].size(); ++j){
            const Edge& e = edges0[i][j];
            edges[i].push_back(Edge(e.to, e.cap, edges[e.to].size()));
            edges[e.to].push_back(Edge(i, 0, edges[i].size()-1));
        }
    }

    int ret = 0;
    for(;;){
        used.assign(n, false);
        int f = Func::dfs(source, sink, INT_MAX);
        if(f == 0)
            return ret;
        ret += f;
    }
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> x1(n), y1(n), v(n);
        for(int i=0; i<n; ++i)
            cin >> x1[i] >> y1[i] >> v[i];

        vector<int> x2(m), y2(m);
        for(int i=0; i<m; ++i)
            cin >> x2[i] >> y2[i];

        vector<pair<double, pair<int, int> > > a;
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j){
                double d = sqrt(pow(x1[i] - x2[j], 2.0) + pow(y1[i] - y2[j], 2.0)) / v[i];
                a.push_back(make_pair(d, make_pair(i, j)));
            }
        }
        sort(a.begin(), a.end());

        int left = 0;
        int right = n * m - 1;
        while(left < right){
            int mid = (left + right) / 2;

            vector<vector<Edge> > edges(n+m+2);
            for(int i=0; i<n; ++i)
                edges[0].push_back(Edge(i+1, 1));
            for(int i=0; i<m; ++i)
                edges[n+1+i].push_back(Edge(n+m+1, 1));
            for(int i=0; i<=mid; ++i)
                edges[a[i].second.first+1].push_back(Edge(a[i].second.second+n+1, 1));


            if(maxFlow(edges, 0, n+m+1) == m)
                right = mid;
            else
                left = mid + 1;
        }

        printf("%.10f\n", a[left].first);
    }
}

Measured memory_bytes: 1972
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    String s=gs();



        //System.out.print("No");

        if (N%2==0 && s.substring(0, N/2).equals(s.substring(N/2))) {
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35588
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

X,Y = map(int,input().split())
if (X+Y)%3 == 0:
  a = (X+Y)//3
  X -= a
  Y -= a
  if X >= 0 and Y >= 0:
    n = X+Y
    r = X
    print(cmb(n, r, p))
    exit()

print(0)

Measured memory_bytes: 122128
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=500010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
    ll n,k;cin>>n>>k;
    priority_queue<P,vector<P>,greater<P>> q;
    for(int i=0;i<n;i++){
        ll a,b;cin>>a>>b;
        q.push(P(a,b));
    }
    while(!q.empty()){
        P p=q.top();
        q.pop();
        k-=p.second;
        if(k<=0){
            cout<<p.first<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 2420
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 2005
#define LL long long
LL n,x;
LL a[MAXN],dp[MAXN][MAXN];
int main()
{
	LL ans=1LL<<60LL;
	scanf("%lld %lld",&n,&x);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		dp[i][0]=a[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n-1;j++)
		{
			int pos=i-j;
			if(pos<=0) pos=n+pos;
			dp[i][j]=min(dp[i][j-1],a[pos]);
		}
	for(int j=0;j<n;j++)
	{
		LL sum=0;
		for(int i=1;i<=n;i++)
			sum+=dp[i][j];
		ans=min(ans,sum+x*j);
	}
	printf("%lld\n",ans);
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n + 5);
	for (int i = 0, tmp; i < n; i++) {
		cin >> tmp; a[i] = tmp;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == i + 1)ans++, swap(a[i], a[i + 1]);
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
	int a;
	int b;
	int c;

	cin >> a >> b >> c;

	int max;
	int mid;
	int min;

	if (a <= b && a <= c) {
		min = a;
		if (b < c) {
			max = c;
			mid = b;
		}
		else {
			max = b;
			mid = c;
		}
	}
	else if (b <= a && b <= c) {
		min = b;
		if (a < c) {
			max = c;
			mid = a;
		}
		else {
			max = a;
			mid = c;
		}
	}
	else if (c <= a && c <= b) {
		min = c;
		if (a < b) {
			max = b;
			mid = a;
		}
		else {
			max = a;
			mid = b;
		}
	}

	cout << min << " " << mid << " " << max << endl;

	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
std::vector<int > ReturnBit(long long val){
  std::vector<int > bit(45, 0);
  int counter = 0;
  while(val>0){
    bit[counter]=val%2;
    //printf("bit[%d]=%d\n",counter,bit[counter]);
    val = val/2;
    counter++;
  }
  std::reverse(bit.begin(), bit.end());
  return bit;
}

int main(){
  int N;
  long long K;
  scanf("%d",&N);
  scanf("%lld",&K);
  std::vector<long long > A(N);
  std::vector<int > sum(45, 0);
  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    std::vector<int > getbit = ReturnBit(A[i]);
    for (int j=0; j<45; j++){
      sum[j] += getbit[j];
    }
  }
  std::vector<int > Kbit = ReturnBit(K);
  std::vector<std::vector<long long > > dp(46, std::vector<long long> (2, -1));
  dp[0][0] = 0;
  long long ans = 0;
  for (int i=1; i<=45; i++){
    long long kurai = (long long)1<<(45-i);
    //printf("Kbit[%d]=%d, sum[%d]=%d\n",i-1,Kbit[i-1],i-1,sum[i-1]);
    //printf("kurai=%lld\n",kurai);
    if (Kbit[i-1]==0){
      if (dp[i-1][1]!=-1){
        dp[i][1] = dp[i-1][1] + std::max(sum[i-1], N-sum[i-1])*kurai;
      }
      dp[i][0] = dp[i-1][0] + sum[i-1]*kurai; // 0を選択
    } else {
      dp[i][0] = dp[i-1][0] + (N-sum[i-1])*kurai; // 1を選択
      dp[i][1] = dp[i-1][0] + sum[i-1]*kurai; // 0を選択
      if (dp[i-1][1]!=-1){
        dp[i][1] = std::max(dp[i][1], dp[i-1][1]+std::max(sum[i-1], N-sum[i-1])*kurai);
      }
    }
    //printf("dp[%d][1]=%lld\n",i,dp[i][1]);
    //printf("dp[%d][0]=%lld\n",i,dp[i][0]);
  }
  printf("%lld\n",std::max(dp[45][0],dp[45][1]));
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    
    int a,b,kei;
    char op;

    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '?'){
            break;
        }
        if(op == '+'){
            kei = a+b;
            printf("%d\n",kei);
        }else if(op == '-'){
            kei=a-b;
            printf("%d\n",kei);
        }else if(op =='*'){
            kei=a*b;
            printf("%d\n",kei);
        }else if(op == '/'){
            kei=a/b;
            printf("%d\n",kei);
        }
    }
}


Measured memory_bytes: 2120
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};


template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

const i64 MOD = 1e9 + 7;
using fp = modint<MOD>;

fp dp[101010][13];

int main() {
  string s;
  cin >> s;
  reverse(all(s));
  i64 N = s.size();
  dp[N][0] = fp(1);

  for(i64 i = N - 1;i >= 0;i--) {
    for(i64 m = 0; m < 13; m++) {
      if(s[i] == '?') {
        for(i64 next = 0; next <= 9; next++) {
          dp[i][(m * 10 + next) % 13] += dp[i + 1][m];
        }
      }
      else {
        i64 next = (s[i] - '0');
        dp[i][(m * 10 + next) % 13] += dp[i + 1][m];
      }
    }
  }

  cout << dp[0][5].value() << endl;
}


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

template <typename T> constexpr int intof(const T x) {
    return static_cast<int>(x);
}

constexpr int mmax(const int x, const int y) { return max(x, y); }
constexpr int e() { return 0; }

int solve(const vector<int> &xs, const int k) {
    const int hi = *max_element(cbegin(xs), cend(xs));
    atcoder::segtree<int, mmax, e> max_lengths_by_val(hi + 1);

    for (const int x : xs) {
        const int h =
            max_lengths_by_val.prod(max(0, x - k), min(hi + 1, x + k + 1));
        max_lengths_by_val.set(x, h + 1);
    }

    return max_lengths_by_val.all_prod();
}

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

    int N, K;
    cin >> N >> K;

    vector<int> xs(N, 0);
    for (auto &x : xs) cin >> x;

    cout << solve(xs, K) << '\n';

    return 0;
}


Measured memory_bytes: 9780
S = input()

kisu = S[0::2]
gusu = S[1::2]
kisu = kisu.replace("R", "")
kisu = kisu.replace("U", "")
kisu = kisu.replace("D", "")
gusu = gusu.replace("L", "")
gusu = gusu.replace("U", "")
gusu = gusu.replace("D", "")

if len(kisu) == len(gusu) == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a[5],mi=1e18,n;
    cin>>n;
    for(int i=0;i<5;i++){
        cin>>a[i];
        mi=min(mi,a[i]);
    }
    ll ans=4;
    if(n%mi){
        ans+=n/mi+1;
    }
    else{
        ans+=n/mi;
    }
    cout << ans<<endl;
    return 0;
}



Measured memory_bytes: 256
/**
 *   author: bholuakku
**/

#include <bits/stdc++.h>
#define Endl cout<<"\n"
#define Test cout<<"Hello\n"

using namespace std;
using ll = long long;

int main(){
    #ifndef ONLINE_JUDGE
        //freopen("C:\\Users\\ACER\\Desktop\\Codes\\input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin>>s;
    int n =s.size();
    vector<int> A(n+1, 0), B(n+1, 0);
    A[1] = 1;
    s = " "+s;
    for(int i = 2; i<=n; i++){
        //taking 1 section
        int Max = 0;
        Max = max(Max, 1+B[i-1]);
        if(s[i]!=s[i-1]) Max = max(Max, 1+A[i-1]);
        A[i] = Max;
        //taking 2 section
        Max = 0;
        Max = max(Max,1+A[i-2]);
        //if(s[i]!=s[i-2]&&s[i-1]!=s[i-3])
        B[i] = Max;
    }
    //for(int i = 1; i<=n; i++
    cout<<max(A[n], B[n]);
}


Measured memory_bytes: 2324
#include<stdio.h>
 
int main(void)
{
	int n,c=0;
	scanf("%d",&n);
	if(n>=105) c++;
	if(n>=135) c++;
	if(n>=165) c++;
	if(n>=189) c++;
	if(n>=195) c++;
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	int n, ma, mb;
	cin >> n >> ma >> mb;
	vector<pair<pair<int, int>, int> > v;
	for(int i = 0; i < n; i++){
		int a, b, c;
		cin >> a >> b >> c;
		v.push_back(make_pair(make_pair(a, b), c));
	}
	int result[401][401];
	for(int i = 0; i < 401; i++){
		for(int j = 0; j < 401; j++){
			result[i][j] = mod;
		}
	}
	result[0][0] = 0;
	for(int i = 0; i < n; i++){
		int a = (v[i].first).first;
		int b = (v[i].first).second;
		int c = v[i].second;
		for(int j = 400 - a; j >= 0; j--){
			for(int k = 400 - b; k >= 0; k--){
				result[j + a][k + b] = min(result[j + a][k + b], result[j][k] + c);
			}
		}
	}
	int ans = mod;
	for(int i = 1; i * ma < 401 && i * mb < 401; i++){
		ans = min(ans, result[i * ma][i * mb]);
	}
	if(ans == mod) cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll suma = 0,sumb = 0;
    rep(i,n) {
        suma += a[i];
        sumb += b[i];
    }
    if(suma < sumb){
        cout << -1 << endl;
        return 0;
    }else{
        ll cnt = 0, under = 0;
        vector<ll> v;
        rep(i,n){
            if(a[i] < b[i]){
                cnt++;
                under += b[i] - a[i];
            }
            else{
                v.push_back(a[i] - b[i]);
            }
        }
        sort(v.rbegin(), v.rend());
        ll sum = 0;
        int itr = 0;
        while(sum < under){
            sum += v[itr];
            itr++;
        }
        cout << itr + cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 5704
s=list(input())
n=len(s)
if s[0] != "1" or s[-1]=="1" or s[:(n-1)//2] != s[n-2:n//2-1:-1]:
  print(-1)
  exit()
chain = [1]
ans = []
s[-1] = "1"
for i in range(1,n):
  if s[i] == "1":
    chain.append(i+1)
    ans.append((chain[-2],chain[-1]))
c = len(chain)
for i in range(1,c):
  for j in range(chain[i-1]+1,chain[i]):
    ans.append((j,chain[i]))
for edge in ans:
  print(*edge)

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

using namespace std;

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

  int N; cin>>N;
  vector<double> V(N); for (auto& v : V) cin>>v;
  sort(V.begin(), V.end());
  double ans = V[0];
  for (int i = 1; i < N; i++) {
    ans += V[i];
    ans /= 2;
  }
  cout << fixed << setprecision(6) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 100100;
long long n, k, ans, sum, a[N], b[N];

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> k;
	for(long long i= 1; i <= n; i++)
		cin >> a[i];

	for(long long i = 1; i <= n; i++)
		b[i] = max(a[i], 0LL);

	for(long long i = 2; i <= n; i++)
		a[i] += a[i - 1], b[i] += b[i - 1];

	for(long long i = 1; i + k - 1 <= n; i++) 
		ans = max(ans, b[i - 1] + max(a[i + k - 1] - a[i - 1], 0LL) + b[n] - b[i + k - 1]);
	cout << ans << '\n';
}	

	

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
using namespace std;

#define MAX 120

struct Node {
	int key;
	Node *p, *l, *r;
};

Node *root, *NIL;

void insert(int k) {
	Node *x = root;
	Node *y = NIL;
	Node *z;
	z = new Node;
	z->key = k; z->l = NIL; z->r = NIL;
	while (x != NIL) {
		y = x;
		if (z->key < x->key) x = x->l;
		else x = x->r;
	}
	z->p = y;

	if (y == NIL) root = z;
	else if (z->key < y->key) y->l = z;
	else y->r = z;
}

void preorder(Node *u) {
	if (u == NIL) return;
	cout << " " << u->key;
	preorder(u->l);
	preorder(u->r);
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->l);
	cout << " " << u->key;
	inorder(u->r);
}

void print() {
	inorder(root);
	cout << endl;
	preorder(root);
	cout << endl;
}

int main() {
	int n;
	int num;
	cin >> n; cin.ignore();
	string line;
	for (int i = 0; i < n; i++) {
		getline(cin, line);
		if (line[0] == 'i') {
			num = atoi(line.substr(7).c_str());
			insert(num); 
			
		}
		else print();
	}
}

Measured memory_bytes: 26460
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d)cout<<"Left"<<endl;
  else if(a+b<c+d)cout<<"Right"<<endl;
  else cout<<"Balanced"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,p;
	cin>>n>>p;
	if(n==1){
		cout <<p;
		return 0;
	}
	ll ans=1;
	for(ll i=2;i*i<=p;i+=2){
		ll cnt=0;
		while(p%i==0){
			cnt++;
			p/=i;
		}
		if(cnt!=0){
		cnt/=n;
		ans*=pow(i,cnt);
		}
		if(i==2){
			i=1;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using ll = long long;
using namespace std;
int main() {
  ll N, M, D;
  cin >> N >> M >> D;
  double prob = D == 0 ? 1.0/N : 2.0 * (N - D) / (N * N);
  cout << setprecision(10) << prob * (M - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=200005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
struct node
{
	int m;
	string s;
}a[200005];
bool cmp(node x,node y)
{
	if(x.m>y.m)return 1;
	if(x.m==y.m&&x.s<y.s)return 1;
	return 0;
}
int n,cnt=1;
map<string,int>mp;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	while(n--)
	{
		string t;
		cin>>t;
		if(!mp[t])
		{
			mp[t]=cnt;
			node x;
			x.m=1;
			x.s=t;
			a[cnt]=x;
			cnt++;
		}
		else a[mp[t]].m++;
	}
	sort(a+1,a+1+cnt,cmp);
	forn(i,cnt)
	{
		if(a[i+1].m==a[1].m)
			cout<<a[i+1].s<<endl;
	}
	return 0;
}

Measured memory_bytes: 27008
sums = [1]  # pair number sum until index
csums = {}  # pair number sum of each color

N = int(input())
C = []      # color stone list
lastc = -1  # last color of input
for i in range(N):
    c = int(input())
    if(lastc == c):
        continue
    lastc = c
    C.append(c)

#print("C = " + str(C))

for i, c in enumerate(C, 1):
    if(c in csums):
        sums.append(sums[-1] + csums[c])
        csums[c] += sums[i - 1]
    else:
        sums.append(sums[-1])
        csums[c] = sums[i - 1]

#    print("i = {}, c = {}".format(i, c))
#    print("csums = " + str(csums))
#    print("sums = " + str(sums))

print(sums[-1] % (10 ** 9 + 7))


Measured memory_bytes: 773420
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000003;
int f[P];

ll powmod(int n, int k) {
    ll r = 1, t = n;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
//a*x+b*y=1
//a>b>0
//b*y+(a-a/b*b)*x=1
//a*x+b*(y-a/b*x)=1
//-b<x<b -(a-a/b*b)<y<a-a/b*b
//-a=-(a-a/b*b)-a/b*b<y-a/b*x<a-a/b*b+a/b*b=a
int extgcd(int a, int b, int &x, int &y) {
    if (b == 1) {
        x = 0; y = 1;
    } else {
        int q = a / b;
        int r = a % b;
        extgcd(b, r, y, x);
        y -= q * x;
    }
}
//P*x+n*y=1
//0<n<P
ll inv(int n) {
    int x, y;
    extgcd(P, n, x, y);
    if (y < 0) y += P;
    return y;
}

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

    int q;
    cin >> q;

    f[0] = 1;
    for (int i = 1; i < P; i++) {
        f[i] = (ll)f[i - 1] * i % P;
    }

    for (int h = 0; h < q; h++) {
        int x, d, n;
        cin >> x >> d >> n;

        if (d == 0) {
            cout << powmod(x, n) << '\n';

        } else {
            int y = (ll)x * inv(d) % P;

            if (y == 0 || y + n - 1 >= P) {
                cout << 0 << '\n';

            } else {
                cout << f[y + n - 1] * inv(f[y - 1]) % P * powmod(d, n) % P << '\n';
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4864