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

int main() {
  int a,b,c;
  vector<int>data(3);
  cin >> data.at(0) >> data.at(1) >> data.at(2);
  sort(data.begin(),data.end());
  a = data.at(0);b = data.at(1);c = data.at(2);
  
  if((c-a)%2 == 0 && (c-b)%2 == 0){
    cout << c-(a+b)/2 << endl;
    return 0;
  }
  else if(((c-a)%2 == 0 && (c-b)%2 == 1)||((c-a)%2 == 1 && ((c-b)%2) == 0)){
    cout << c-(a+b)/2+1 << endl;
    return 0;
  }
  else{
    cout << c-(a+b)/2 << endl;
    return 0;
  }
}


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

struct edge {int to, cost;};

//=============dijkstra============================
vector<long long> dijkstra(int s, int V, vector<vector<edge>> G)
{
  vector<long long> d(V, INF);
  typedef pair<long long, int> P;// first は最短距離　second は頂点の番号
  priority_queue<P, vector<P>, greater<P>> que;
  d.at(s) = 0;
  que.push(P(0, s));
  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d.at(v) < p.first) continue;
    for (int i = 0; i < G.at(v).size(); ++i)
    {
      edge e = G.at(v).at(i);
      if (d.at(e.to) > d.at(v) + e.cost)
      {
        // cout << d.at(v) + e.cost << " " << e.to << endl;
        d.at(e.to) = d.at(v) + e.cost;
        que.push(P(d.at(e.to), e.to));
      }
    }
  }
  return d;
}
//=================================================

int main()
{
  int V, E, r;
  cin >> V >> E >> r;
  vector<vector<edge>> G(V, vector<edge>(0));
  int s, t, d;
  for (int i = 0; i < E; ++i)
  {
    cin >> s >> t >> d;
    edge e = {t, d};
    G.at(s).push_back(e);
    // cout << e.to << e.cost << endl;
    // G.at(t).push_back({s, d});
  }
  vector<long long> ans = dijkstra(r, V, G);
  for (int i = 0; i < V; ++i)
  {
    if (ans.at(i) == INF)
    {
      cout << "INF" << endl;
    }
    else
    {
      cout << ans.at(i) << endl;
    }
  }
}



Measured memory_bytes: 21612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> V(N);
  vector<int> C(N);
  
  for (int i =0; i<N; i++){
    cin >> V[i];
  }
  for (int i =0; i<N; i++){
    cin >> C[i];
  }
  
  int ans=0;
  
  for (int i = 0; i < N; i++){
    if(V[i] > C[i]){
      ans+=V[i]-C[i];
      
    }
  }
  
  cout << ans << endl;
  
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int fx4[] = {1 , -1 , 0 , 0};
int fy4[] = {0 , 0 , 1 , -1};
int Kfx[]= {-2,-2,2,2,1,1,-1,-1}; ///knight move x - exis
int Kfy[]= {1,-1,1,-1,2,-2,2,-2}; ///knight move y- exis
int fx8[]= {1,1,1,0,0,-1,-1,-1};
int fy8[]= {0,1,-1,1,-1,0,1,-1};
#define ll long long int
#define pii pair<int,int>
#define llu unsigned long long
#define inf 1<<28
#define gama 0.57721566490
#define PI              acos(-1.0)
#define INF             0x7fffffff
#define MOD             1000000007
#define EPS             1e-7
#define all(r)(r).begin(),(r).end()
/*
bool status[mx];
void sieve(){
   long long int  i,j;
    for(i=2;i<=mx;i++)
    {
        status[i]=0;
    }
    for( i=2;i<=sqrt(mx);i++){
        if(status[i]==0)
        {
            for(j=i*i;j<=mx;j+=i){
                status[j]=1;
            }
        }
    }
}*/
ll BM( ll a , ll b , ll m )
{
    if ( b == 0 ) return 1 ;
    ll x = BM(a,b/2,m);
    x = (( x % m) * (x % m))%m;

    if( b % 2 ) x = (( x % m) * (a %m)) % m ;
    return x ;
}
#define dd double
#define sc scanf
#define pr printf
#define VI vector<int>
#define VS vector<string>
#define VC vector<char>
#define VLL vector<long long int>
#define FILE freopen("input.txt","rt",stdin); freopen("output.txt","w",stdout);
#define p_b push_back
#define mem(x,y) memset(x,y,sizeof(x))
#define F(i,a,b) for(i=a;i<=b;i++)
#define sc1(a) scanf("%d",&a)
#define scL1(a) scanf("%lld",&a)
#define scL2(a,b) scanf("%lld%lld",&a,&b)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define fori(N)          for(int i = 0; i<(N); i++)
#define forj(N)         for(int j = 0; j<(N); j++)
#define fork(N)         for(int k = 0; k<(N); k++)
#define forl(N)         for(int l = 0; l<(N); l++)
#define ford(N)         for(int d = 0; d<(N); d++)
#define fori1(N)          for(int i = 1; i<=(N); i++)
#define forj1(N)         for(int j = 1; j<=(N); j++)
#define fork1(N)         for(int k = 1; k<=(N); k++)
#define ford1(N)         for(int d = 1; d<=(N); d++)
#define sqr(x)           (x)*(x)
#define TEST int test,te=0;cin>>test;
#define segment_tree int l=(n*2),r=(n*2)+1,mid=(l+r)/2
#define Mx 100005
#define mx 10005

int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);///Beware of use it, if u use it dont use scanf or printf
    int a,b;
    cin>>a>>b;
    int c=a+b;
    if(c==3){
    	cout<<c<<endl;
	}
	else{
		cout<<abs(a-b)<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x%mod;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res%mod;
}
int n;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	printf("%.8f",double(n-n/2)/n);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
int main() {
	double a, b, c, d, e, f, x, y;
	while(cin >> a >> b >> c >> d >> e >> f) {
		y=(a*f-c*d)/(a*e-d*b);
		x=(c-b*y)/a;
		cout<<fixed<<setprecision(3)<<x<<" "<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()
    dic = {}
    for i in a:
        dic[i] = dic.get(i,0) + 1
    ans = 0
    for i,k in dic.items():
        if i < k:
            ans += k-i
        elif i > k:
            ans += k
    print(ans)


if __name__=="__main__":
    main()


Measured memory_bytes: 93420
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <string>

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

int main() {
	ll n, k;
	cin >> n >> k;
	ll count = 0;

	while (true)
	{	
		if (n <= 0)break;
		n /= k;
		count++;

	}

	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	string s;cin>>s;
	map<char,int> mp;
	int n=s.size();
	rep(i,n) mp[s[i]]++;

	if(abs(mp['a']-mp['b'])<=1&&abs(mp['c']-mp['b'])<=1&&abs(mp['a']-mp['c'])<=1) cout<<"YES"<<"\n";
	else cout<<"NO"<<"\n";
	}

Measured memory_bytes: 512
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces_279B
//o(n * log(n))
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Math.*;
import java.math.*;

public class Main{

	static PrintWriter go = new PrintWriter(System.out);
	
	public static void main(String args[]) throws IOException,FileNotFoundException {
		BufferedReader gi = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-1"));
		int[] l = parseArray(gi);
		int n = l[0];
		int m = l[1];
		int[][] jobs = new int[n][];
		for ( int k = 0; k < n; k++ ){
			jobs[k] = parseArray(gi);
		}
		Arrays.sort(jobs, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});
		int ans = 0;
		int cur = 0;
		Queue<pair> q = new PriorityQueue<>();
		for ( int k = 1; k <= m; k++ ){
			while (cur < n && jobs[cur][0] <= k) {
				q.add(new pair(jobs[cur][1], cur));
				cur++;
			}
			if (!q.isEmpty()) ans += q.poll().x;
		}
		go.println(ans);
		go.close();
	}

	static class pair implements Comparable {
		public int x, y;
		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(Object p) {
			return ((pair)p).x - this.x;
		}
	}

	static int[] parseArray(BufferedReader gi) throws IOException{
		String[] line = gi.readLine().split(" ");
		int[] rez = new int[line.length];
		for ( int k = 0; k < line.length; k++){
			rez[k] =  Integer.parseInt(line[k]);
		}
		return rez;
	}

}



Measured memory_bytes: 47256
import sys
N,M = [int(n) for n in input().split()]
S = str(input())
T = str(input())

# N < M
def gcd(N,M):
    if(N > M):
        tmp = N
        N = M
        M = tmp
    r = M % N
    while(r != 0):
        M = N
        N = r
        r = M%N
    return N

def lcm(N,M):
    return(N*M/gcd(N,M))

if (N % M == 0):
    if S == T:
        print(M)
    else:
        p = int(N/M)
        for i in range(M):
            if T[i] != S[i*p]:
                print(-1)
                sys.exit()
        print(N)
elif (M % N == 0):
    if S == T:
        print(M)
    else:
        p = int(M/N)
        for i in range(N):
            if S[i] != T[i*p]:
                print(-1)
                sys.exit()
        print(M)
else:
    mngcd = gcd(N,M)
    k = int(N/mngcd)
    m = int(M/mngcd)
    for i in range(mngcd):
        if S[i*k] != T[i*m]:
            print(-1)
            sys.exit()
    print(int(lcm(N,M)))


Measured memory_bytes: 3444
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, m, t, p, d, c, x, y, k;
  while( 1 ) {
    scanf("%lld%lld%lld%lld", &n, &m, &t, &p);
    if(!n) break;
    ll a[n * (t + 1)][m * (t + 1)], ans = 0, now = 0, ox = 0, oy = 0, lx = n, ly = m;
    for(i = 0; i < n * (t + 1); ++i) for(j = 0; j < m * (t + 1); ++j) {
      if(i < n && j < m) a[i][j] = 1;
      else a[i][j] = 0;
    }
    for(k = 0; k < t; ++k) {
      scanf("%lld%lld", &d, &c);
      if(d == 1) {
        for(i = ox; i < c + ox; ++i) for(j = oy; j < ly; ++j) {
          a[2 * (c + ox) - i - 1][j] += a[i][j];
        }
        lx = lx > 2 * c + ox ? lx : 2 * c + ox, ox = ox + c;
      } else {
        for(i = oy; i < c + oy; ++i) for(j = ox; j < lx; ++j) {
          a[j][2 * (c + oy) - i - 1] += a[j][i];
        }
        ly = ly > 2 * c + oy ? ly : 2 * c + oy, oy = oy + c;
      }
    }
    for(i = 0; i < p; ++i) {
      scanf("%lld%lld", &x, &y);
      printf("%lld\n", a[ox + x][oy + y]);
    }
  }
  return 0;
}


Measured memory_bytes: 5052
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
struct node{ int key;
	         node *prev,*next;
  };
node *null;
void init(){

	null=(node*)malloc(sizeof(node));
	null->next=null;
	null->prev=null;
}
void insert(int key){

	node *x=(node*)malloc(sizeof(node));
	x->key=key;
	x->next=null->next;
	null->next->prev=x;
	null->next=x;
	x->prev=null;
}
node* Search(int key){

	node *cur=null->next;
	while(cur!=null&&cur->key!=key){
	
		cur=cur->next;
	}
	return cur;
}
void Delete(node *d){
	if(d==null)
	return;
	d->prev->next=d->next;
	d->next->prev=d->prev;
	free(d);
}
void Deletefirst(){
	Delete(null->next);
}
void Deletelast(){

	Delete(null->prev);
}
void Deletekey(int key){

	Delete(Search(key));
}
void printlist(){

	node *cur=null->next;
	int i=0;
	while(1){
	
		if(cur==null)
		break;
		if(i++>0) printf(" ");
		printf("%d",cur->key);
		cur=cur->next;
	}
	printf("\n");
}
main(){
	int i,n,key;
	char com[20];
	init();
	scanf("%d",&n);
	for(i=0;i<n;i++){
	
		scanf("%s %d",com,&key);
		if(com[0]=='i') insert(key);
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F') Deletefirst();
				else if(com[6]=='L') Deletelast();
			}
			else Deletekey(key);
			
		}
	}
	printlist();
	
	return 0;
}


Measured memory_bytes: 34352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <deque>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<double, LL> PDL;
deque<PDL> dq;
const int maxn = 5*1e5 + 100;
double ans, t[maxn];
LL V, v[maxn], L;
inline PDL Mix(PDL x){
    PDL y = dq.back();
    ans -= y.fi*y.se;
    dq.pop_back();
    V -= y.se;
    return mp((x.fi*x.se+y.fi*y.se)/(x.se+y.se), x.se+y.se);
}

inline void prePush(PDL x){
    V += x.se;
    while(V > L){
        PDL &y = dq.front();
        if(V-y.se <= L){
            LL Vt = V-L;
            ans -= y.fi*Vt;
            V = L;
            y.se -= Vt;
        } else {
            ans -= y.fi*y.se;
            V -= y.se;
            dq.pop_front();
        }
    }
}
int n;
int main(){
    cin>>n>>L;
    for(int i = 0; i < n; i++) cin>>t[i]>>v[i];
    dq.push_back(mp(t[0], v[0]));
    ans = t[0]*v[0]; V = L;
    printf("%.7f\n", ans/L);
    for(int i = 1; i < n; i++){
        PDL x = mp(t[i], v[i]);
        prePush(x);
        while(dq.size() > 0 && dq.back().fi >= x.fi) x = Mix(x);
        dq.push_back(x);
        ans += x.fi*x.se;
        V = L;
        printf("%.7f\n", ans/L);
    }
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

typedef pair<int, char> PC;

int main() {

    ll n;
    cin >> n;

    ll bn = INF;
    rep(i, 5) {
        ll t;
        cin >> t;
        bn = min(t, bn);
    }

    ll ans = 4 + ((n + bn - 1) / bn) ;

    cout << ans << endl;

}



Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

double calc(int lh, int rh, int h){
    double LH=abs(h-lh), RH=abs(h-rh);
    double S;
    
    // tow triangles
    if((h-lh>0 && h-rh<0) || (h-lh<0 && h-rh>0)){
        S=(LH/(LH+RH))*LH/2+(RH/(LH+RH))*RH/2;
    }
    else{
        S=(LH+RH)/2;
    }

    return S;
}

int main(){
    int n; cin>>n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin>>h[i];

    vector<vector<double>> dp(n+10, vector<double>(310, INF));
    for(int i=0; i<=300; i++){
        dp[1][i]=calc(1, i, h[0]);
    }

    for(int i=1; i<n; i++){
        for(int j=1; j<300; j++){ // left height
            for(int k=1; k<300; k++){ // right height
                dp[i+1][k]=min(dp[i+1][k], dp[i][j]+calc(j, k, h[i]));
            }
        }
    }

    double ans=INF;
    for(int i=1; i<300; i++){
        chmin(ans, dp[n][i]);
    }

    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3460
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() { 
    int a[5], ans = 0;
    vector<pair<int, int>> r;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    for(int i = 0; i < 5; ++i) {
        r.push_back(make_pair(a[i]%10, a[i]));
        if(r[i].first == 0) {
            r[i].first = 10;
        }   
    }
    sort(r.begin(), r.end());
    for(int i = 4; i > 0; --i) {
        ans += r[i].second + 10 - r[i].first;
    }
    cout << (ans + r[0].second) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
 
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
 
int tm;
cin>>tm;
int h,m,s;
h = tm/(60*60);
tm %= 60*60;
m = tm/60;
s = tm%60;
printf("%d:%d:%d\n",h,m,s);
 
  return 0;
}

Measured memory_bytes: 1144
N, Y = map(int, input().split())
count = 0
for x in range(N+1):
    for y in range(N+1):
        z = N-x-y
        if Y == 10000*x + 5000*y + 1000*z and count == 0 and z >= 0:
            print(x, y, z)
            count += 1
            break
        else:
            continue
if count == 0:
    print('-1 -1 -1')

Measured memory_bytes: 3060
function Main(input) {
  "use strict"
	const n = parseInt(input);
  let counter = 0;
  for(let i = 1; i <= n; i++){
    if(Math.ceil(Math.log10(i + 1)) % 2 === 1) counter++;
  } 
  console.log(counter)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8396
import bisect
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_A.sort()
list_B.sort()
list_C.sort()
ans = 0

for i in range(n):
    b = list_B[i]
    left = bisect.bisect_left(list_A, b)
    right = n - bisect.bisect_right(list_C, b)
    ans += left * right

print(ans)

Measured memory_bytes: 29428
N, W = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(N)]

INF = float("inf")
"""
Wの最大が大きすぎるのでふつうのDPはできない
総重量W以下で、価値Vを得るときの最小重さをDPで求める感じ
"""

dp = [{} for _ in range(N+1)]
#何も選ばないときの価値が０で重さが０で初期化。忘れない
dp[0][0] = 0

for i,(w,v) in enumerate(wv):
    for v_sum,w_sum in dp[i].items():

        # i番目の品について考えるとき、i-1までに同じ価値の品があるなら軽いほうを選択、ないならi番目を選択
        if v_sum in dp[i+1]:
            dp[i+1][v_sum] = min(dp[i+1][v_sum], w_sum)
        else:
            dp[i+1][v_sum] = w_sum

        # i-1番目までで起こりえる組み合わせとi番目を選んだ場合に制限を超えるなら飛ばす
        if w + w_sum > W: continue

        # i-1番目までで起こりえる組み合わせとi番目を選んだ場合に、その価値の組み合わせがすでにあるなら軽いほうを、ないならその組み合わせの重さを保存
        if v + v_sum in dp[i+1]:
            dp[i+1][v+v_sum] = min(dp[i+1][v+v_sum], w + w_sum)
        else:
            dp[i+1][v+v_sum] = w + w_sum

#print(dp)
print(max(dp[N].keys()))

Measured memory_bytes: 286856
import math

pi = math.pi
A, B, H, M = map(int, input().split())
theta_h = 2 * pi * (H + M / 60) / 12
theta_m = 2 * pi * M / 60
x_h = A * math.cos(theta_h)
y_h = A * math.sin(theta_h)
x_m = B * math.cos(theta_m)
y_m = B * math.sin(theta_m)
d = math.sqrt((x_h - x_m) ** 2 + (y_h - y_m) ** 2)
result = d
print(result)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t h;
    cin >> h;

    int64_t ans = 0;
    int64_t n = 1;
    while (h > 0) {
        if (h == 1) {
            ans += n;
            h = 0;
        } else {
            ans += n;
            h /= 2;
            n *= 2;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main(){
	

	double r,are,circ;
	cin >> r;
	
	are = 2*3.141592653589*r;
	
	circ = r*r*3.141592653589;
	
	
	printf("%f %f\n", circ, are);


	
return 0;
}

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

int main()
{
	char s[8];
	scanf("%s",s);
	for(int i=0;i<3;i++)
		if(s[i]=='1')s[i]='9';
		else s[i]='1';
	printf("%s",s);
}


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

int main(void)
{
	char s[202] = {0};
	char p[101] = {0};
	char tmp[101] = {0};
	int i;
	
	scanf("%s", tmp);
	scanf("%s", p);
	
	for (i = 0; i < strlen(tmp); ++i) {
		s[i] = tmp[i];
		s[i + strlen(tmp)] = tmp[i];
	}

	if (strstr(s, p)) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define dd double
#define ll long long

using namespace std;

int main()
{
    ll q;
    cin >> q;
    deque <ll> A;
    while(q--){
    ll qq,x,d,p;
    cin >> qq;
    if(qq==0){
        cin >> d >> x;
        if(d == 0){
            A.push_front(x);
        }
        else
            A.push_back(x);
    }
    if(qq==1){
        cin >> x;
        cout << A[x] << endl;
    }
    if(qq==2){
            cin >> d;
        if(d == 0){
            A.pop_front();
        }
        else
            A.pop_back();
    }
    }

    return 0;
}




Measured memory_bytes: 6228
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
 
using namespace std;
 
const int N = 100;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
vector <int> v;
long double x[N], y[N];
void solve () {
	int n;
	cin >> n;
	long double sum = 0, kol = 1;
	for (int i = 1; i <= n; i ++) {
	 	cin >> x[i] >> y[i];
	 	kol *= i;	
		v.pb (i);
	}
	do {
		for (int i = 0; i < n - 1; i ++) {
			sum += sqrt ((x[v[i]] - x[v[i + 1]]) * (x[v[i]] - x[v[i + 1]]) + (y[v[i]] - y[v[i + 1]]) * (y[v[i]] - y[v[i + 1]]));		
		}
	}while (next_permutation (all (v)));
	cout << fixed << setprecision (6) << sum / kol;
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//	cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,s,temp;
    cin >> a >> s;
    vector <int> b;
    for(int i=0;i<s;i++){
        cin >> temp;
        b.push_back(temp-a);
    }
    sort(b.begin(),b.end());
    //
    temp = 0;
    while(temp < s && b[temp]!=0) temp++;

    if (temp >=s) {cout << a;return 0;}

    int i=0,j=0;
    
    while(temp-i>=0 && temp+j<s){
        
        if(b[temp-i]!=-1*i) {
            cout << a-i;
            return 0;
        }
        else if(b[temp+j]!=j) {
            cout << a+j;
            return 0;
        }
        i++;j++;
        
    }
    if(temp-i>=0 && b[temp-i]!=-1*i) cout << a-i;
    else if(temp-i<0) cout << a-i;
    else if(temp+j>=s) cout << a+j;
    else cout << a+j;
    return 0;
}


Measured memory_bytes: 3596
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        List<Integer> t = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            t.add(l + i - 1);
        }
        int absMinimum = Integer.MAX_VALUE;
        int minimum = Integer.MAX_VALUE;
        int sum = 0;
        for (Integer num : t) {
            sum += num;
            if (Math.abs(num) < absMinimum) {
                absMinimum = Math.abs(num);
                minimum = num;
            }
        }
        System.out.println(sum - minimum);
    }
}


Measured memory_bytes: 23124
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -linf;
    vi x, y;
    x.pb(a);
    x.pb(b);
    if (b >= 0 and a <= 0) x.pb(0);
    y.pb(c);
    y.pb(d);
    if (d >= 0 and c <= 0) y.pb(0);
    for (int i : x)
        for (int j : y) {
            chmax(ans, (ll) i * j);
        }
    cout << ans << endl;
}

Measured memory_bytes: 3652
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
cnt=0
before=50
for i in A:
    cnt+=B[i-1]
    if before+1==i:cnt+=C[i-2]
    before=i
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
ll mod = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vector<int> as(N, 0);

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

  int count = 0;
  if(N % 2 == 0) { // 偶数の場合
    for(int i = 0; i < as.size(); ++i) {
      if(i % 2 == 0 && as[i] != 0) {
        // Nが偶数の場合は
        cout << 0 << endl;
        return 0;
      } else if(i % 2 == 1) {
        if(as[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
        count++;
      }
    }
  } else {           // 奇数の場合
    if(as[0] != 1) { // 真ん中がいないのはおかしい
      // cout << "e1 : ";
      cout << 0 << endl;
      return 0;
    }
    for(int i = 1; i < as.size(); ++i) {
      if(i % 2 == 1 && as[i] != 0) {
        // Nが奇数の場合は奇数項は0のハズ
        // cout << "e2 : ";
        cout << 0 << endl;
        return 0;
      } else if(i % 2 == 0) {
        if(as[i] != 2) {
          // cout << "e3 : ";
          cout << 0 << endl;
          return 0;
        }
        count++;
      }
    }
  }
  ll ans = 1;
  for(int i = 0; i < count; ++i) {
    ans *= 2;
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define endl            "\n"
#define forn(i,x,n)     for(int i=x; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zeus()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int fast_pow(long long base, long long n, long long M)
{
    if (n == 0)
        return 1;
    if (n == 1)
        return base;
    long long halfn = fast_pow(base, n / 2, M);
    if (n % 2 == 0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}

int findMMI_fermat(int n, int M)
{
    return fast_pow(n, M - 2, M);
}

int32_t main() {

    zeus();

    int x, y; cin >> x >> y;

    if ((y - 2 * x) % 2 == 0 && y >= 2 * x && 4 * x >= y) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}




Measured memory_bytes: 3612
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = sread();
    auto B = sread();
    auto C = sread();
    long ans;
    foreach (i; 0 .. N)
    {
        if (A[i] == B[i] && A[i] == C[i])
        {
            ans += 0;
        }
        else if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i])
        {
            ans += 1;
        }
        else
        {
            ans += 2;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main(){
  int h,w; cin >> h >> w;
  vector<string> ans;
  for(int i=0;i<h;i++){
    string s; cin >> s;
    ans.push_back(s);
    ans.push_back(s);
  }
  for(auto a:ans) cout << a << "\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n,m,c;
    cin >> n >> m >> c;
    int b[100];
    for(int i=0;i<m;i++) {
        cin >> b[i];
    }
    int cnt=0;
    for(int i=0;i<n;i++) {
        int res = 0;
        for(int j=0;j<m;j++) {
            int a;
            cin >> a;
            res += b[j] * a;
        }
        //cout << res << endl;
        res += c;
        if (res >0){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,H;
    cin >> N >> H;
    vector<int> A(N),B(N);
    rep(i,0,N)cin >> A[i] >> B[i];
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    int cnt = 0;
    rep(i,0,N){
        if(H <= 0 || A[0] >= B[i])break;
        H -= B[i];
        cnt++;
    }
    if(H > 0)cnt += (H + A[0] - 1) / A[0];
    cout << cnt << endl;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{0};
    for(unsigned long i{1}; i <= N; ++i)ans += i * (N / i) * (N / i + 1) / 2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'



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

	unsigned long long r, d, x;

	cin >> r >> d >> x;

	rep(i, 0, 10)
	{
		x = (r * x) - d;
		cout << x << endl;
	}

	return 0;
}


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

#define MOD 1000000007
#define MAX 100000
int p2[MAX+5];
int f[MAX + 5];

int main()
{
	int i, t;
	int N, M;

	p2[0] = 1;
	for (i = 1; i <= MAX; i++) p2[i] = (p2[i - 1] << 1) % MOD;

	scanf("%d%d", &N, &M);

	f[M] = 1;

	for (i = M + 1; i < N && i <= 2 * M; i++) {
		f[i] = ((f[i - 1] << 1) % MOD + p2[i - M - 1]) % MOD;
	}

	for (; i <= N; i++) {
		t = p2[i - M - 1] - f[i - M - 1];
		if (t < 0) t += MOD;
		f[i] = ((f[i - 1] << 1) % MOD + t) % MOD;
	}
	printf("%d\n", f[N]);
	return 0;
}


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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 )
	   a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
			return false;
	return true;
}

int a, b;

int main()
{
	cin >> a >> b;
	if ( a > b )
		swap( a, b );
	if ( a == 1 && b == 2 )
		cout << "3\n";
	if ( a == 1 && b == 3 )
		cout << "2\n";
	if ( a == 2 && b == 3 )
		cout << "1\n";
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  string s;
  cin >> s;
  int a=0,b=0,c=0;
  rep(i,0,s.size()){
    if(s[i]=='a') a++;
    if(s[i]=='b') b++;
    if(s[i]=='c') c++;
    
  }
  
  if(max({a,b,c})-min({a,b,c})<=1) cYES;
  else cNO;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair

int main(){
	string s;
	cin >> s;
	ll n=s.size();
	vector<ll> lr;
	vector<ll> rl;
	lr.push_back(-1);
	for(ll i=0;i<n-1;i++){
		if(s[i]=='R'&&s[i+1]=='L') rl.push_back(i);
		if(s[i]=='L'&&s[i+1]=='R') lr.push_back(i);
	}
	lr.push_back(n-1);
	vector<ll> res(n,0);
	for(ll i=0;i<rl.size();i++){
		ll countR=rl[i]-lr[i];
		ll countL=lr[i+1]-rl[i];
		res[rl[i]]=countR-(countR/2)+countL/2;
		res[rl[i]+1]=countL-(countL/2)+countR/2;
	}
	for(ll i=0;i<n;i++) cout << res[i] << endl;
}


Measured memory_bytes: 5032
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#define RG register
#define LL long long
using namespace std;
const int N=1e5+10;
const LL mod=1e9+7;
int n,fi[N];
LL ans=1,t[N],a[N],ri[N],maxx;
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
inline void endd(){printf("0\n"); exit(0);}
int main()
{
//	freopen("Two Alpinists.in","r",stdin);
	read(n);
	for(RG int i=1;i<=n;i++)
	{
		read(t[i]);
		if(t[i]!=t[i-1]) ri[i]=t[i], fi[i]=1, maxx=t[i];
		else ri[i]=maxx;
	}
	for(RG int i=1;i<=n;i++) read(a[i]);
	for(RG int i=n;i;i--)
	 if(a[i]!=a[i+1])
	 {
		if(fi[i] && a[i]!=t[i]) endd();
		if(a[i]>ri[i]) endd();
		ri[i]=a[i]; fi[i]=1; maxx=a[i];
	 }
	 else ri[i]=mi(ri[i],maxx);
	for(RG int i=1;i<=n;i++)
	{
		if(fi[i]) continue ;
		(ans*=ri[i])%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
int n;
void solve() {
	cin >> n;
	while(n) {
		if (n%10==7) {
			cout << "Yes\n";
			return;
		}
		n/=10;
	}
	cout << "No\n";
}
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin >> t;
	// for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	// }
}

Measured memory_bytes: 3624
// Problem : E - Tr/ee
// Contest : AtCoder - AtCoder Regular Contest 103
// URL : https://atcoder.jp/contests/arc103/tasks/arc103_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <cstdio>
#include <cstring>
char s[100005];
int p[100005];
bool check()
{
 int n=strlen(s+1);
 for(int i=1;i<n;i++)
  if(s[i]!=s[n-i])return false;
 return true;
}
int main()
{
 scanf("%s",s+1);
 int n=strlen(s+1);
 if(s[1]!='1'||s[n]!='0'||!check())
 {
  puts("-1");
  return 0;
 }
 int tot=0;
 for(int i=1;i<=n;i++)
  if(s[i]=='1')p[++tot]=i;
 for(int i=1;i<=tot;i++)
  printf("%d %d\n",i,i+1);
 int cnt=tot+1;
 for(int i=1;i<=tot;i++)
 {
  int d=p[i]-p[i-1]-1;
  while(d--)
   printf("%d %d\n",i,++cnt);
 }
 return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			String x = sc.next();
			if (x.equals("0")) {
				break;
			}
			int sum = 0;
			for (int i = 0; i < x.length(); i++) {
				sum += x.charAt(i) - '0';
			}
			System.out.println(sum);
		}
	}
}



Measured memory_bytes: 26072
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
import java.util.*;
/**
 * Created by takaesumizuki on 2018/06/22.
 */
public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        Integer q = sc.nextInt();
        UnionFind uni = new UnionFind(n);

        while (q-- > 0) {
            Integer com, x, y;
            com = sc.nextInt();
            x = sc.nextInt();
            y = sc.nextInt();

            if (com == 0) {
                uni.merge(x, y);
            } else {
                if (uni.same(x, y)) {
                    System.out.println(1);
                } else {
                    System.out.println(0);
                }
            }


        }

    }


    public class UnionFind {
//        ArrayList<Integer> unions;
        int[] unions;

        /**
         * 0 ~ size - 1までの集合を
         *
         * @param size 集合のサイズ
         */
        UnionFind(Integer size) {
//            this.unions = new ArrayList<>();
            this.unions = new int[size];
            for (Integer i = 0; i < size; i++) {
                this.unions[i] = i;
            }
        }

        int find(int v) {
            if (unions[v] == v) {
                return v;
            } else {
//                Integer ret = find(this.unions.get(v));
                int ret = find(this.unions[v]);
//                this.unions.set(v, ret);
                this.unions[v] = ret;
                return ret;
            }
        }

        /**
         * v1の集合 を v2の集合にする
         *
         * @param v1
         * @param v2
         */
        void merge(int v1, int v2) {
            int v1Root = find(v1);
            int v2Root = find(v2);

//            this.unions.set(v1Root, v2Root);
            this.unions[v1Root] = v2Root;
        }

        Boolean same(int v1, int v2) {
            return find(v1) == (find(v2));
        }
    }
}



Measured memory_bytes: 100696
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#define ll long long
using namespace std;

#define MOD 1000000007

class Solve
{
private:
	ll w, h;
	vector<ll> p;
	vector<ll> q;

public:
	Solve(){
		cin >> w >> h;
		for (ll i = 0; i < w; ++i)
		{
			ll tmp;
			cin >> tmp;
			p.push_back(tmp);
		}
		for (ll i = 0; i < h; ++i)
		{
			ll tmp;
			cin >> tmp;
			q.push_back(tmp);
		}
		sort(p.begin(), p.end());
		sort(q.begin(), q.end());

	}

	void exec(){
		ll i1 = 0;
		ll i2 = 0;
		ll ans = 0;
		for (ll i = 0; i < w + h; ++i)
		{
			if(i1 == w) {
				ans += q[i2] * (w - i1 + 1);
				i2++;
				continue;
			}

			if(i2 == h) {
				ans += p[i1] * (h - i2 + 1);
				i1++;
				continue;
			}

			if(p[i1] < q[i2]) {
				ans += p[i1] * (h - i2 + 1);
				i1++;
			} else {
				ans += q[i2] * (w - i1 + 1);
				i2++;
			}
		}

		cout << ans << endl;
	}
};

int main(){
	Solve solver = Solve();
	solver.exec();
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

///////////////////////////////////////////////////////////////////////////
ll n,W,w,v;
map<ll,p_queue(ll)> m;
rp_queue(ll) rp;

ll dfs(ll sum,ll ww){
//	P(sum);
	if(rp.empty()){
		return sum;
	}
	ll nn = rp.top();
	
	if(ww-nn < 0){
		return sum;
	}
	
	if(m[nn].empty()){
		rp.pop();
		ll ans = dfs(sum,ww);
		rp.push(nn);
		ret ans;
	}else{ 
		ll v = m[nn].top();
		m[nn].pop();
		ll ans = dfs(sum+v,ww-nn);

		rp.pop();
		ans = max (ans,dfs(sum,ww));
		rp.push(nn);
		
		m[nn].push(v);
		ret ans;
	}
}

int main(){
    cin >> n >> W;
    rep(i,0,n){
        cin >> w >> v;
        m[w].push(v);
    }
    for(auto it:m)rp.push(it.ft);

    P(dfs(0,W));
       
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // ?¨±??????????????????????????£????????????
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}
namespace std {
  bool operator<(const P a, const P b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}
VP convexHull(VP ps) {  // ????????????????????????????????????????????????VP&???
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;  // ????¨?????????????????????? == -1 ??¨??????
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;
  ch.resize(k-1);
  return ch;
}
int main(){
  int n;
  cin>>n;
  VP v;
  while(n--){
    double a,b;
    cin>>a>>b;
    v.push_back(P(a,b));
   }
  v=convexHull(v);
  cout<<v.size()<<endl;
  int p=0;
  double a=1e9,b=1e9;
  rep(i,v.size()){
    if(v[i].Y<b){
      a=v[i].X;
      b=v[i].Y;
      p=i;
    }
    else if(v[i].Y==b&&v[i].X<a){
      a=v[i].X;
      b=v[i].Y;
      p=i;
    }
  }
  for(int i=0;i<v.size();i++,p++){
    cout<<v[p%(int)v.size()].X<<' '<<v[p%(int)v.size()].Y<<endl;
  }
}

Measured memory_bytes: 9144
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll t = Y / X;
  int ans = 0;
  while (t > 0) {
    ++ans; t >>= 1;
  }

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


Measured memory_bytes: 256