akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder0627
{
	class Program
	{
		static void Main(string[] args)
		{
			C();
		}

		private static void C()
		{
			var ints = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
			var n = ints[0];
			var m = ints[1];
			long k = ints[2];

			var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
			var b = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
			long max = 0;
			var sa = InclusiveSums(a);
			var sb = InclusiveSums(b);
			long sum = 0;

			for (int i = 0; i <= Math.Max(n, m); i++)
			{
				var maxOnlyA = UpperBound(i, a.Length, t => sa[t] - sa[i] <= k - sum) - i;
				var maxOnlyB = UpperBound(i, b.Length, t => sb[t] - sb[i] <= k - sum) - i;

				max = Math.Max(max, Math.Max(maxOnlyA, maxOnlyB) + 2 * i);
				if (i >= n || i >= m || sum + a[i] + b[i] > k)
					break;

				sum += a[i];
				sum += b[i];
			}

			Console.WriteLine(max);
		}

		public static long[] InclusiveSums(long[] list)
		{
			if (list.Length == 0)
				return Array.Empty<long>();

			var result = new long[list.Length + 1];
			result[0] = 0;
			for (int i = 0; i < result.Length-1; i++)
				result[i + 1] = result[i] + list[i];

			return result;
		}

		public static long UpperBound(long min, long max, Predicate<long> test)
		{
			long ans = min;
			long s = min;
			long e = max;
			while (s <= e)
			{
				long mid = (s + e) / 2;
				if (test(mid))
				{
					ans = mid;
					s = mid + 1;
				}
				else
					e = mid - 1;
			}

			return ans;
		}

		private static void B()
		{
			var s = Console.ReadLine();
			var t = Console.ReadLine();
			var count = Enumerable.Range(0, s.Length).Count(x => s[x] != t[x]);
			Console.WriteLine(count);
		}

		private static void A()
		{
			var a = int.Parse(Console.ReadLine());
			Console.WriteLine(a + a * a + a * a * a);
		}
	}
}


Measured memory_bytes: 73516
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;

int main()
{
  int n;
  bool cc=false;
  for(;cin>>n,n;)
    {
      if(cc)
	cout<<endl;
      else
	cc=true;
      int c1,c2,c3,c4;
      cin>>c1>>c2>>c3>>c4;
      int sum=c1*10+c2*50+c3*100+c4*500-n;
      int ans=0;
      int x1=0,x2=0,x3=0,x4=0;
      for(;sum>=500;)
	{
	  x4++;
	  sum-=500;
	}
      for(;sum>=100;)
	{
	  x3++;
	  sum-=100;
	}
      for(;sum>=50;)
	{
	  x2++;
	  sum-=50;
	}
      for(;sum>=10;)
	{
	  x1++;
	  sum-=10;
	}
      if((c1-x1)>0)
	cout<<"10 "<<c1-x1<<endl;
      if((c2-x2)>0)
	cout<<"50 "<<c2-x2<<endl;
      if((c3-x3)>0)
	cout<<"100 "<<c3-x3<<endl;
      if((c4-x4)>0)
	cout<<"500 "<<c4-x4<<endl;
	
    }
}

Measured memory_bytes: 1160
n = gets.chomp.split(" ").map(&:to_i)[0]

values = gets.chomp.split(" ").map(&:to_f).sort

while values.length > 1 do
    mixed_v = (values[0] + values[1]).to_f / 2
    values.shift(2)
    if values.empty?
        values = [mixed_v]
        break
    end
    values.each_with_index do |v, i|
        if mixed_v < v
            values.insert(i, mixed_v)
            break
        end
    end
end

p values[0]


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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


int main(){
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define mod 1000000007 //998244353
#define pb push_back
#define endd '\n'
#define ll long long 
#define mk make_pair 
#define fi first
#define all(a) a.begin(),a.end()
#define test ll int t,o;cin>>o;for(t=1;t<=o;t++)
#define goog(q,aao) cout<<"Case #"<<q<<": "<<aao<<'\n'
#define co(a) cout<<a<<'\n'
#define coo(a,b) cout<<a<<" "<<b<<'\n'
#define cooo(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define take_arr ll i,j,k,n;mul_itr;set_itr;cin>>n;ll arr[n];loop(i,n)cin>>arr[i]
#define take ll i,j,k,n;mul_itr;set_itr;cin>>n
#define print(arr,n) for(ll w=0;w<n;w++)cout<<arr[w]<<" ";cout<<'\n'
#define printdou(arr,n,m) for(ll w=0;w<n;w++){ for(ll o=0;o<m;o++){cout<<arr[w][o]<<" "; }cout<<endd;}
#define dis(w) loop(i,w.size())cout<<w[i]<<" ";cout<<'\n'
#define mem(b,q)  memset(b,q , sizeof(b))
#define set_itr set<ll>:: iterator sitr ,sit
#define mul_itr multiset<ll>:: iterator itr,it
#define se second
#define pii pair<int,int>
#define iterate(s,d) for(d=s.begin();d!=s.end();++d)
#define pll pair<long long,long long>
#define vll vector<ll>
#define vpll vector< pair<ll,ll> >
#define vppll vector < pair<ll, pair<ll,ll> > >
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define loop1(i,a,n) for(i=a;i<n; i++) 
#define loop(i,n) for( i=0;i<n;i++)
#define loop2(n,m) for(int p=0;p<n;p++)for(int q=0;q<m;q++)
#define loop3(n,m,l) for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<l;k++)
#define checkbit(n, b) ((n >> b) & 1)
#define setbits(x) __builtin_popcount(x)  // returns no of set bits in x 
#define maxx 10e18
using namespace std;
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
// NOTE :
// maxx=*max_element(a,a+n); 
// m=(m-1+n)%n;     move anti-clockwise 

//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//int32_t main(){
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  	ll i,j,k,n,sum=0;
  	cin>>n;
  	loop(i,n)
  	{
  		if((i+1)%3 && (i+1)%5)
  		{
  			sum+=i+1;
  			
		  }
	  }
	  cout<<sum;
    return 0;
}

Measured memory_bytes: 3648
import Control.Applicative

swap :: [Int] -> Int -> Int -> [Int]
swap xs i j = (take i xs) ++ [xs !! j] ++ (take (j - i - 1) $ drop (i + 1) xs) ++ [xs !! i] ++ (drop (j + 1) xs)

selection :: Int -> [[Int]] -> [[Int]]
selection n xss = foldl (\yss i -> let h = head yss; m = f h i in if i == m then yss else swap h i m : yss) xss [0 .. n - 1]
    where f ys i = foldl (\j k -> if ys !! k < ys !! j then k else j) i [i + 1 .. n - 1]

solve :: Int -> [Int] -> [[Int]]
solve n xs = selection n [xs]

main :: IO ()
main = do
    n  <- readLn
    xs <- map read <$> words <$> getLine
    let ls = solve n xs
    putStrLn $ unwords $ map show $ head ls
    print $ length ls - 1

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

int main(){
	int a,b;
	cin >> a >> b;
	
	if(a >= 13) cout << b << endl;
	else if(6 <= a && a <= 12) cout << b/2 << endl;
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
        
    for i in range(H):            
        for j in range(W):
            if (i+j) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()

    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

const int limit = 1000010;
ll mary[limit];
ll cary[limit];
ll ary[limit];

int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;

	rep(i,n) mary[i] = (s[i] == 'M');
	rrep(i,n-1) mary[i] += mary[i+1];

	rep(i,n) cary[i] = (s[i] == 'C');
	rrep(i,n-1) cary[i] += cary[i+1];


	rep(i,n){
		ary[i] = 0LL;
		if(s[i] == 'C') ary[i] = mary[i];
	}
	rrep(i,n-1) ary[i] += ary[i+1];

	int q;
	cin >> q;
	rep(loop,q){
		int k;
		cin >> k;
		ll ans = 0LL;
		rep(i,n){
			if(s[i] != 'D') continue;
			const int idx = min(n,i + k);
			const ll cnum = cary[i] - cary[idx];
			ans += cnum * mary[i] - (ary[i] - ary[idx]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 24836
#include<bits/stdc++.h>
using namespace std;
#define MAX 100001
#define MOD 1000000007
#define ll long long
#define ld long double
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main() {
	fast;
	int t = 1;
	// cin >> t;
	while (t--) {
		ll a, b, c, d;
        cin >> a >> b >> c >> d;
        ll mn1 = a, mx1 = b;
        ll mn2 = c, mx2 = d;
        cout << max({mn1 * mn2, mn1 * mx2, mx1 * mn2, mx1 * mx2}) << endl;
	}
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
//using Graph = vector<vector<int>>;


const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

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

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
 string s,t;
 cin >> s >> t;
 ll ma = 0,cnt=0;
 rep (i,s.size()-t.size()+1){
   cnt = 0;
   for (int j = 0;j < t.size();j++){  
     //cout << s[j+i] << t[j] << endl;  
   if (s[j+i]==t[j]){     
     cnt++;
   }
 }
 //cout << endl;
  ma=max(ma,cnt);
 }
 cout << t.size()-ma << endl;
}


Measured memory_bytes: 3728
#include <cstdio>

#define int long long
#define dotimes(i, n) for (int i : range(n))

using namespace std;

class range {
  class iterator {
    int i, s;
  public:
    iterator(int i, int s): i(i), s(s) {}
    int& operator*() {
      return i;
    }
    void operator++() {
      i += s;
    }
    bool operator!=(iterator const& that) {
      return i < that.i;
    }
  };
  iterator b, e;
public:
  range(int e): b({0, 1}), e({e, 1}) {}
  range(int b, int e): b({b, 1}), e({e, 1}) {}
  range(int b, int e, int s): b({b, s}), e({e, s}) {}
  iterator begin() {
    return b;
  }
  iterator end() {
    return e;
  }
};

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

template<typename T>
inline bool maxs(T& a, T const& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
inline bool mins(T& a, T const& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  int N = rint();
  int r = 0;
  for (int i : range(1, N + 1, 2)) {
    int c = 0;
    for (int j : range(1, i + 1))
      if (i % j == 0)
        c++;
    if (c == 8)
      r++;
  }
  wint(r);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<vector>
using namespace std;
int main(){
    for(;;){
        int a,b,c,N;
        scanf("%d%d%d",&a,&b,&c);
        if(a==0&&b==0&&c==0)break;
        vector<int> ar(a+b+c,2);
        scanf("%d",&N);
        vector<vector<int> > ins(N,vector<int>(4));
        vector<bool> ched(N,false);
        for(int i=0;i<N;i++){
            for(int j=0;j<3;j++){
                scanf("%d",&ins[i][j]);
                ins[i][j]--;
            }
            scanf("%d",&ins[i][3]);
            if(ins[i][3]==1){
                ar[ins[i][0]]=ar[ins[i][1]]=ar[ins[i][2]]=1;
                ched[i]=true;
            }
        }
        bool iscont=true;
        while(iscont){
            iscont=false;
            for(int ix=0;ix<N;ix++){
                if(!ched[ix]&&ins[ix][3]==0){
                    int i=ins[ix][0],j=ins[ix][1],k=ins[ix][2];
                    if(ar[i]==1&&ar[j]==1){
                        ar[k]=0;
                        iscont=true;
                        ched[ix]=true;
                    }else if(ar[i]==1&&ar[k]==1){
                        ar[j]=0;
                        iscont=true;
                        ched[ix]=true;
                    }else if(ar[j]==1&&ar[k]==1){
                        ar[i]=0;
                        iscont=true;
                        ched[ix]=true;
                    }
                }
            }
        }
        for(int i=0;i<a+b+c;i++){
            printf("%d\n",ar[i]);
        }
    }
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int a, b;
	char op;
	for (int i = 0; i < 10000000; i++) {
		cin >> a >> op >> b;
		if (op == '?') break;
		else if (op == '+') cout << a + b << endl;
		else if (op == '-') cout << a - b << endl;
		else if (op == '*') cout << a * b << endl;
		else cout << a / b << endl;
	}
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    ll fa=(a-1)/x,fb=b/x;
    if(a==0)cout<<fb+1<<endl;
    else cout<<fb-fa<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

string S;

void solve() {
    ll a = 0;
    ll b = (1<<20);
    vector<int> d;
    for(int i = 0; i < S.size(); i++) {
        if(S.substr(i, 5) == "north") d.push_back(-90);
        if(S.substr(i, 4) == "west") d.push_back(90);
    }
    if(d.back() == 90) a = (1<<20) * 90;
    for(int i = 1; i < d.size(); i++) {
        a += (1 << (20 - i)) * d[d.size()-1-i];
    }
    ll g = __gcd(a, b);
    a /= g;
    b /= g;
    cout << a;
    if(b != 1) {
        cout << "/" << b;
    }
    cout << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> S) {
        if(S == "#") break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3040
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mm(arr) memset(arr, 1, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
using namespace std;

int main(){
    FAST
    int k; cin >> k;
    int cnt=0, mx=0;
    bool ok=0;

    for(int a=1; a<=k; a++){
        for(int b=1;b<=k; b++){
            for(int c=1; c<=k;c++){
                        int ans =__gcd(a,b);
                        cnt+=__gcd(ans,c);

            }
        }
    }
    cout << cnt << endl;



    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int,int> P;
int n;
int a[101000][3];
int dp[100100][3];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i][0]>>a[i][1]>>a[i][2];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
	return 0;
}


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

int main(){
    int n;
    while(cin >> n, n){
        int dp[10][1010];
        memset(dp, 0, sizeof(dp));
        int a[10], m[10];
        for(int i=0; i < n; i++) cin >> a[i] >> m[i];

        dp[0][0] = 1;
        for(int i=0; i < n; i++){
            for(int j=0; j <= 1000; j++){
                for(int k=0; k <= m[i] && k*a[i]+j <= 1000; k++){
                    dp[i+1][j+a[i]*k] += dp[i][j];
                }
            }
        }
        int g;
        cin >> g;
        for(int i=0; i < g; i++){
            int p;
            cin >> p;
            cout << dp[n][p] << endl;
        }
    }
}

Measured memory_bytes: 1204
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
nums = getlist()
ln = len(nums)
maxn, minn = max(nums), min(nums)
already = False

if minn >= 0:
    plus = True

if maxn < 0:
    plus = False

if maxn >= 0 and minn < 0:
    print(ln*2-1)
    already = True
    if abs(maxn) > abs(minn):
        source = nums.index(maxn)
        plus = True
    else:
        source = nums.index(minn)
        plus = False
    for i in range(len(nums)):
        print(source+1, i+1)

if not already:
    print(ln-1)

if plus:
    for i in range(ln-1):
        print(i+1, i+2)
else:
    for i in range(ln-1):
        print(ln-i, ln-i-1)








Measured memory_bytes: 3064
///
// File:  1160.go
// Author: ymiyamoto
//
// Created on Sun Mar  4 20:45:57 2018
//
package main

import (
	"fmt"
)

var w, h int
var graph [][]string

func dfs(visited [][]bool, x, y int) {
	visited[x][y] = true

	for i := -1; i <= 1; i++ {
		for j := -1; j <= 1; j++ {
			dx := x + i
			dy := y + j
			if 0 <= dx && dx < h && 0 <= dy && dy < w && graph[dx][dy] == "1" && !visited[dx][dy] {
				dfs(visited, dx, dy)
			}
		}
	}
}

func main() {
	for {
		fmt.Scan(&w, &h)
		if w == 0 && h == 0 {
			break
		}

		graph = make([][]string, h)
		for i := range graph {
			graph[i] = make([]string, w)
		}

		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				var s string
				fmt.Scan(&s)
				graph[i][j] = s
			}
		}

		visited := make([][]bool, h)
		for i := range visited {
			visited[i] = make([]bool, w)
		}

		count := 0
		for i := range graph {
			for j := range graph[i] {
				if graph[i][j] == "1" && !visited[i][j] {
					dfs(visited, i, j)
					count++
				}
			}
		}

		fmt.Println(count)
	}
}



Measured memory_bytes: 2924
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int a,b,c,d;

int main(){
	cin >> a >> b >> c >> d;
	if(abs(a-c) <= d || (abs(a-b) <= d && abs(c-b) <= d))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;

int n;
vector<vector<vector<int> > > f;
vector<vector<ll> > p;
vector<int> v;

ll dfs(int i) {
    if (i == 10) {
        if (v.size() == 0)
            return -1*(ll)1e15;

        ll tmp = 0;
        vector<int> c(n, 0); //c[i]は店iとかぶっている時間帯の個数
        for (auto x: v) {
            int j = x/2, k = x%2;
            for (int l = 0; l < n; l++) {
                if (f[l][j][k])
                    c[l]++;
            }
        }
        for (int l = 0; l < n; l++)
            tmp += p[l][c[l]];
        return tmp;
    }

    
    v.push_back(i);
    ll res = dfs(i+1);
    v.pop_back();
    res = max(res, dfs(i+1));

    return res;
}

int main() {
    cin >> n;
    f.resize(n, vector<vector<int> >(5, vector<int>(2)));
    p.resize(n, vector<ll>(11));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 5; j++)
            cin >> f[i][j][0] >> f[i][j][1];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++)
            cin >> p[i][j];
    }

    cout << dfs(0) << endl;
    return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,k;
	cin>>n>>k;
	while(n){
		if(abs(n-k)>n)
		break;
		else if(n<k)
		n=abs(n-k);
		else n=n%k;
	}
	cout<<n<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500000
#define INFTY 1000000001
int  H[MAX];

int merge(int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right -mid;
  int L[n1],R[n2];
  int i;
  static int sum=0;
  for(i=0;i<n1;i++)L[i]=H[left+i];
  for(i=0;i<n2;i++)R[i]=H[mid+i];
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  int j=0,k;
  for(k=left;k<right;k++){
    if(L[i]<=R[j])H[k]=L[i++];
    else H[k]=R[j++];
    sum++;
  }
  return sum;
}

int mergesort(int left,int right){
  int a;
  if (left+1<right){
    int mid=(left+right)/2;
    mergesort(left,mid);
    mergesort(mid,right);
    a=merge(left,mid,right);
  }
  return a;
}



int main(){
  int i,n,cnt;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&H[i]);
  cnt=mergesort(0,i);
  for(i=0;i<n;i++){
    if(i!=n-1)printf("%d ",H[i]);
    else printf("%d\n",H[i]);
  }
  printf("%d\n",cnt);
  return 0;
  
}




Measured memory_bytes: 5680
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		for(;;){

			int n = sc.nextInt();

			if(n == 0)break;

			

			int[][] ms = new int[n][n];

			int posy = n/2;

			int posx = n/2-1;

			for(int i = 1 ; i < n*n+1;i++){

				int ny = posy+1;

				int nx = posx+1;

				if(ny >= n){

					ny = 0;

				}

				if(nx >= n){

					nx = 0;

				}

				for(;ms[ny][nx] != 0;){

					ny += 1;

					nx -= 1;

					if(ny >= n){

						ny = 0;

					}

					if(nx < 0){

						nx = n-1;

					}					

				}

				ms[ny][nx] = i;

				posx = nx;

				posy = ny;

			}

			for(int i =0;i < n;i++){

				for(int j = 0; j < n;j++){

					System.out.printf("%4d",ms[i][j]);				

				}

				System.out.println();

			}

		}

		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

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

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

    int n;
    cin >> n;
    int x =n % 10;
    if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
    	cout << "hon";
	}
	else if(x == 3) {
		cout << "bon";
	}
	else cout << "pon";
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  double N; cin >> N;
  double pi = 3.14159265;
  double ans = pi * N * 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3788
N=int(input())
cnt,zero,one,two,three,four,more=0,0,0,0,0,0,0
d=0
A=list(map(int,input().split()))
B=A[:]
for i in range(N):
  while B[i]%2==0:
    if B[i]%2==0:
      B[i]=B[i]//2
      cnt=cnt+1
  if cnt==0:
    zero += 1
  elif cnt==1:
    one += 1
  elif cnt==2:
    two += 1
  elif cnt==3:
    three += 1
  elif cnt==4:
    four += 1
  else:
    more += 1
  cnt=0
#print(zero,one,two,three,four,more)
if one%2==0:
  d=0
else:
  d=1
if (zero+d)>(two+three+four+more+1):
  print("No")
else:
  print("Yes")

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

int main() {
  int N;
  cin >>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
  cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  
    

  cout << A.at(N-1)-A.at(0)<< endl;
}


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

int main() {
  int N; cin >> N;
  int ans = 100000000;
  int wsum = 0;
  int nowsum = 0;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    int wi; cin >> wi;
    v.at(i) = wi;
    wsum += wi;
  }
  for (int i = 0; i < N; i++) {
    nowsum += v.at(i);
    int dif = abs (wsum - 2 * nowsum);
    ans = min(ans, dif);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();
		int l = sc.nextInt();

		int sum = 0; // sum of taste

		// flag
		boolean positive = l >= 0;
		boolean t0 = false;

		for (int i = 1; i <= n; i++) {
			int t = l + i - 1; // taste
			if (positive) {
				if (i == 1) {
					continue;
				}
			} else {
				if (t == 0) {
					t0 = true;
					continue;
				}
				if (!t0 && i == n) {
					continue;
				}
			}
			sum += t;
		}

		System.out.println(sum);

		sc.close();
	}
}


Measured memory_bytes: 21844
N,K = map(int,input().split())
P = list(map(lambda x:int(x)-1,input().split()))
C = list(map(int,input().split()))

ans = -10**18
for si in range(N):
    x = si
    score = []
    total = 0
    while True:
        x = P[x]
        score.append(C[x])
        total += C[x]
        if x == si:break
    
    
    l = len(score)
    t = 0
    for i in range(l):
        t += score[i]
        if i+1 > K:break
        now = t
        if total > 0:
            e = (K-i-1)//l
            now += total*e
        
        ans = max(ans,now)

print(ans)    
    

Measured memory_bytes: 80924
#include <bits/stdc++.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<ll> v(3*n);
    rep(i,0,3*  n)cin >> v[i];
    sort(v.begin(),v.end(),greater<ll>());
    ll ans = 0;
    for(ll i = 1,j = 0;j < n;i += 2,j++)ans += v[i];
    cout << ans << endl;

    return 0;
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 100005;
vector<int> g[N];

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n, m; cin >> n >> m;
	REPU(i, 0, n) {
		int x; cin >> x;
		g[x % m].push_back(x);
	}
	REPU(i, 0, m) if (!g[i].empty()) {
		sort(ALL(g[i]));
	}
	int ans = 0;
	REPU(i, 0, m / 2 + 1) {
		int r = (m - i) % m;
		if (i != r) {
			ans += tmin(g[i].size(), g[r].size());
			if (g[i].size() > g[r].size()) {
				int t = g[i].size(), cnt = 0;
				for (int j = 0; j < g[i].size();) {
					int nxt = upper_bound(ALL(g[i]), g[i][j]) - g[i].begin();
					cnt += (nxt - j) / 2;
					j = nxt;
				}
				ans += tmin((g[i].size() - g[r].size()) / 2, cnt);
			}
			else if (g[i].size() < g[r].size()) {
				int cnt = 0;
				for (int j = 0; j < g[r].size();) {
					int nxt = upper_bound(ALL(g[r]), g[r][j]) - g[r].begin();
					cnt += (nxt - j) / 2;
					j = nxt;
				}
				ans += tmin((g[r].size() - g[i].size()) / 2, cnt);
			}
		}
		else {
			ans += g[i].size() / 2;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define REV(x) (reverse(x.begin(),x.end()))
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N=100002;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	bool ok = false;
	cin >> n >> k;
	vector<ll> a(n,0);
	FOR(i,0,n)cin >> a[i];
	ll ma=0;
	FOR(i,0,n){
		if(a[i]==k)ok=true;
		ma = max(ma,a[i]);
	}
	if(ok){
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	if(ma<k){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}


	ll w = gcd(a[0],a[1]);
	FOR(i,2,n){
		w = gcd(w,a[i]);
	}
	if(w==1){
		cout<<"POSSIBLE"<<endl;
	}else{
		if(k%w!=0)cout<<"IMPOSSIBLE"<<endl;
		else cout<<"POSSIBLE"<<endl;
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

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

	rep(i, n){
		vector<int> nx;
		//show(cr.size())
		for(int i = 0; i < cr.size(); i+=2){
			if(cr[i] == cr[i + 1]) nx.emplace_back(cr[i]);
			else{
				nx.emplace_back(max(cr[i] - cr[i + 1], cr[i + 1] - cr[i]));
			}
		}
		//for(auto i : nx) cout << i << ' '; cout << endl;
		cr = vector<int>(all(nx));
	}
	cout << cr.front() << endl;
}


Measured memory_bytes: 2424
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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 = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  vector<pair<int,int>> AB(n);
  REP(i,n){
    cin >> AB[i].second >> AB[i].first;
  }
  SORT(AB);
  bool clear = true;
  int sum = 0;
  REP(i,n){
    sum += AB[i].second;
    if(sum > AB[i].first) {
      clear = false;
      break;
    }
  }
  Yes(clear);
}

Measured memory_bytes: 3328
url = "https://atcoder.jp/contests/abc082/tasks/abc082_b"


def main():
    s1, s2 = [input() for i in range(2)]
    l1 = sorted(list(s1))
    l2 = sorted(list(s2), reverse=True)
    indx = 0
    if len(l1) > len(l2):
        indx = len(l2)
    else:
        indx = len(l1)
    for i in range(indx):
        if l1[i] < l2[i]:
            print('Yes')
            exit()
    if len(l1) < len(l2) and l1[-1] <= l2[-1]:
        print('Yes')
        exit()
    print('No')




if __name__ == '__main__':
    main()




Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

ll gcd(ll a, ll b) {
    while (1) {
        if (a < b) swap(a, b);
        if (!b) break;
        a %= b;
    }
    return a;
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << b - b / c + b - b / d - b + b / lcm(c, d) -(a-1) + (a - 1) / c - (a - 1) + (a - 1) / d + (a - 1) - (a - 1) / lcm(c, d) << endl;
}


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

int main(){
  string S;
  cin >> S;
  int N, A, B;
  N = S.size();
  A = 0;
  B = 0;
  for ( int i = 0; i < N; i++){
    if ( S.at(i) == '0'){
      A++;
    }
    else {
      B++;
    }
  }
  cout << 2 * min(A, B) << endl;
}
    
    
    

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<unordered_map>
using namespace std;
using ll = long long;
int main(){
    int N, K, A;
    cin >> N >> K;
    vector<int> a(N + 1);
    for(int i = 0;i < N;i++){
        cin >> A;
        a.at(A)++;
    }
    sort(a.begin(), a.end());
    int sum = 0;
    for(int i = a.size() - 1 - K;i >= 0;i--){
        sum += a.at(i);
    }
    cout << sum;
}


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

"""
参考：https://img.atcoder.jp/abc096/editorial.pdf
・こういうの、自分で思いつくようになりたい。
"""

def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:

            # mod 5が同じ数なら5個集まれば5の倍数になるから合成数
            if i % 5 == 1:
	            prime_list.append(i)
            
            for j in range(i + i, n + 1, i):
                table[j] = 1
    
    return prime_list

N = int(input())
print(*(eratosthenes_sieve(10000)[:N]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const pid_t pid = getpid();
// Problem Specific Parameter:

const int half = 11;
const int inf = 1 << 30;
const int limit = 1 << 18;
int v[limit], w[limit];

using pii = pair<int, int>;
vector<pii> query[limit];

int ans[limit];

vector<int> pre, post;
vector<pii> ary[20];

void pre_calc() {
	const int n = pre.size();

	ary[n].clear();
	rep(mask, 1 << n) {
		int cv = 0, cw = 0;
		rep(i, n) {
			if((mask >> i) & 1) {
				cv += v[pre[i]];
				cw += w[pre[i]];
			}
		}
		ary[n].push_back(pii(cw, cv));
	}

	sort(begin(ary[n]), end(ary[n]));
	const int an = ary[n].size();
	rep(i, 1, an) chmax(ary[n][i].second, ary[n][i - 1].second);
}

void calc(int l, int p) {
	int &res = ans[p];
	const int n = pre.size();
	const int m = post.size();

	rep(mask, 1 << m) {
		int cv = 0, cw = 0;
		rep(i, m) {
			if((mask >> i) & 1) {
				cv += v[post[i]];
				cw += w[post[i]];
			}
		}
		if(cw > l) continue;
		chmax(res, cv);
		auto it = prev(upper_bound(begin(ary[n]), end(ary[n]), pii(l - cw, inf)));
		chmax(res, cv + it->second);
	}
}

void dfs(int v, int d, int n) {
	if(v >= n) return;

	if(d < half) {
		pre.push_back(v);
		pre_calc();
	} else {
		post.push_back(v);
	}

	for(auto &elem: query[v]) {
		calc(elem.first, elem.second);
	}

	dfs(2 * v + 1, d + 1, n);
	dfs(2 * v + 2, d + 1, n);

	if(d < half) {
		pre.pop_back();
	} else {
		post.pop_back();
	}
}

int main(void){
	int n;
	cin >> n;
	rep(i, n) cin >> v[i] >> w[i];

	int q;
	cin >> q;
	rep(i, q) {
		int t, l;
		cin >> t >> l;
		t--;
		query[t].push_back(pii(l, i));
	}

	dfs(0, 0, n);

	rep(i, q) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 15400
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}
#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }

    input! {
        x: i64,
    }

    let mut ans = x / 11 * 2;
    let rem = x - ans / 2 * 11;
    if rem > 0 {
        if rem > 6 {
            ans += 1;
        }
        ans += 1;
    }
    println!("{}", ans);
}
fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 5005;
int dp[N], arr[N], good[N];
int n, k, mx;

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    loop(i, n)cin >> arr[i];
    sort(arr, arr + n);
    reverse(arr, arr + n);
    dp[0] = true;
    loop(idx, n) {
        rloop(i, mx) {
            if (dp[i]) {
                if (i + arr[idx] >= k) {
                    good[idx] = true;
                } else {
                    dp[i + arr[idx]] = true;
                    mx = max(mx, i + arr[idx]);
                }
            }
        }
    }

    int ans = 0;
    rloop(i, n - 1) {
        if (good[i])break;
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<a+b/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int aa(int n)
{
	if(n == 0)
	{
		return 1;
	}
	else
	{
		return (2*aa(n - 1)) % 1000000007;
	}
}
int main()
{
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	
	long long ans = 0;
	if(n % 2 == 0)
	{
		for(int i = 0; i < n / 2; i++)
		{
			if(a[i*2] != i*2 + 1 || a[i*2 + 1] != i*2 + 1 || a[i*2] != a[i*2 + 1])
			{
				cout << 0 << endl;
				return 0;
			}
		}
		cout << aa(n/2) << endl;
	}
	else
	{
		if(a[0] != 0)
		{
			cout << 0 << endl;
			return 0;
		}
		
		for(int i = 1; i <= n / 2; i++)
		{
			if(a[i*2 - 1] != i*2 || a[i*2] != i*2 || a[i*2 - 1] != a[i*2])
			{
				cout << 0 << endl;
				return 0;
			}
		}
		cout << aa(n/2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1408