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

long long floor_sum(long long n, long long m, long long a, long long b) {
    long long sum = 0;
    if (a >= m) {
        sum += (a / m) * n * (n - 1) / 2;
        a %= m;
    }
    if (b >= m) {
        sum += (b / m) * n;
        b %= m;
    }
    long long y = (a * n + b) / m;
    if (y == 0) return sum;
    long long x = (m * y - b + a - 1) / a;
    sum += (n - x) * y + floor_sum(y, a, m, a * x - m * y + b);
    return sum;
}

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

    int T;
    cin >> T;
    while (T--) {
        int N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, M, A, B) << "\n";
    }
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Template
{
    public class Scanner
    {
        public string NextLine => Console.ReadLine();
        public int NextInt => int.Parse(NextLine);
        public long NextLong => long.Parse(NextLine);
        public double NextDouble => double.Parse(NextLine);
 
        public string[] StrAry(char separator = ' ') => Console.ReadLine().Split(separator);
        public int[] IntAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), int.Parse);
        public long[] LongAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), long.Parse);
        public double[] DoubleAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), double.Parse);
    }
 
    internal class Template
    {
        public static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
        private static void Fill<T>(T[] src, T value, int len) { for (int i = 0; i < len; i++) { src[i] = value; } }
 
        static void Solve() 
        {
            var scan = new Scanner();
            var line = scan.IntAry();
            var tuple = Tuple.Create(line[0] * line[1], line[2] * line[3]);
            Console.WriteLine((tuple.Item1 > tuple.Item2) ? tuple.Item1 : tuple.Item2);            
        }
 
        private static void Main()
        {
            Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
        }
    }
}

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

int main()
{
    long N,K,X,Y,z,pro;
    scanf("%ld %ld %ld %ld",&N,&K,&X,&Y);
    if(K<=N)
    {
        z=K*X;
        pro=(N-K)*Y;
        printf("%ld\n",z+pro);
    }
   else{z=N*X;
        printf("%ld\n",z);
        }
    return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std; 
int n;
int a[200010];
int ans;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==ans+1)ans++;
	}
	if(ans==0)cout<<"-1"<<endl;else
	cout<<n-ans<<endl;
    return 0; 
}/*
*/

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N,C = map(int, input().split())
    d = [list(map(int, input().split())) for _ in range(C)]
    c = [list(map(int, input().split())) for _ in range(N)]
    # 各余りのマスのグループをi番目の色に変えた時の違和感の総和
    iwakan = [[0]*C for _ in range(3)]

    for i in range(N):
        for j in range(N):
            amari = (i+j+2) % 3
            color = c[i][j]
            for k in range(C):
                iwakan[amari][k] += d[color-1][k]
    
    res = 10**20
    for i in permutations(range(C), 3):
        res = min(res, iwakan[0][i[0]]+iwakan[1][i[1]]+iwakan[2][i[2]])
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 44636
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int h, w, d;
	cin >> h >> w >> d;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	int ans = 0;
	rep(i, h) {
		int cnt = 0;
		rep(j, w) {
			if(s[i][j] == '#') cnt = 0;
			else {
				if(cnt == d -1) ans++;
				else cnt++;
			}
		}
	}
	rep(j, w) {
		int cnt = 0;
		rep(i, h) {
			if(s[i][j] == '#') cnt = 0;
			else {
				if(cnt == d -1) ans++;
				else cnt++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> e;
};

Vertex V[100005];
bool U[100005];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].e.push_back(b);
        V[b].e.push_back(a);
    }

    stack<int> s;
    s.push(0);
    vector<int> ans;
    ans.push_back(1);
    auto collect = [&](stack<int> s) {
        while (!s.empty())
        {
            int t = s.top();
            s.pop();
            U[t] = true;
            REP(i, V[t].e.size())
            {
                int n = V[t].e[i];
                if (U[n])
                    continue;
                s.push(n);
                ans.push_back(n + 1);
                break;
            }
        }
    };
    collect(s);

    std::reverse(ans.begin(), ans.end());
    collect(s);

    cout << ans.size() << endl;
    REP(i, ans.size())
    {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6904
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    input = Console.ReadLine().Split('-');
    Console.WriteLine((2 == input.Length && input[0].Length == A && input[1].Length == B) ? "Yes" : "No");
  }
}

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

typedef long long ll;
using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 700;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'o') ans += 100;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
k = int(input())
from collections import deque
que = deque()
for i in range(1,10):
    que.append(i)
for i in range(k):
    x = que.popleft()
    if x%10 != 0:
        que.append(10*x + x%10 -1)
    que.append(10*x + x%10)
    if x%10 != 9:
        que.append(10*x + x%10 +1)
    if i == k-1:
        print(x)

Measured memory_bytes: 11888
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    int a[n];
    double sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=(1.0/a[i]);
    }cout<<1.0/sum;



















return 0;}


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

using namespace std;

int main() {
    int a;
    cin >> a;
    int h = a/3600;
    int m = a%3600/60;
    int s = a%3600%60;
    cout << h << ":" << m << ":" << s <<endl;
    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>

int main(void){
  int i,j;
  int h,w;
  char map[101][101],hoge;
  int curY,curX;

  for(;;){
    scanf("%d%d",&h,&w);
    if(!h && !w)
      break;

    for(i=0;i<h;i++){
      scanf("%c",&hoge);
      for(j=0;j<w;j++)
        scanf("%c",&map[i][j]);
    }

    curY=0;
    curX=0;

    for(;;){
      if(map[curY][curX]=='+'){
        printf("LOOP\n");
        break;
      }
      if(map[curY][curX]=='.'){
        printf("%d %d\n",curX,curY);
        break;
      }
      if(map[curY][curX]=='<'){
        map[curY][curX]='+';
        curX--;
      }
      else if(map[curY][curX]=='>'){
        map[curY][curX]='+';
        curX++;
      }
      else if(map[curY][curX]=='^'){
        map[curY][curX]='+';
        curY--;
      }
      else if(map[curY][curX]=='v'){
        map[curY][curX]='+';
        curY++;
      }
    }
  }

  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,X;
    cin>>N>>X;
    vint M(N);rep(i,N)cin>>M[i];

    X-=accumulate(all(M),0ll);
    cout<<N+X/(*min_element(all(M)))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
    bool flag = true ;
    int i = 1 ;
    while(flag){
        int x ;
        cin >> x ;
        if(x==0){
            flag = false ;
        }
        else{
            cout << "Case "<<i<<":"<<" "<<x<<endl ;
            i++ ;
        }
        
    }

  return 0 ;
}


Measured memory_bytes: 3068
<?php
$S = fgets(STDIN);
$pattern ='/(^..)(.*)(.$)/';
preg_match($pattern,$S,$match);
if(preg_match('/^A/',$match[1]) && (substr_count($match[2], "C") == 1) && ctype_lower(preg_replace('/[AC]/','',$match[0])))
{
     echo "AC";
}else{
     echo "WA";
}
?>

Measured memory_bytes: 3576
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> arr(n);
    for (int i=0; i<n; i++) cin >> arr[i].first >> arr[i].second;
    sort(arr.begin(), arr.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.second<b.second;
    });
    long long time = 0;
    bool yes = true;
    for (int i=0; i<n; i++) {
        time += arr[i].first;
        if (time > arr[i].second) {
            yes = false;
            break;
        }
    }
    cout << (yes ? "Yes" : "No");
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 105;
const ll INF = pow(10,15);

ll A[MAX_N][MAX_N]; int n;

void init(){
    rep(i,MAX_N){
        rep(j,MAX_N){
            A[i][j] = (i == j ? 0: INF);
        }
    }
}

void warshallFloyd(){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                A[i][j] = min(A[i][j], A[i][k]+A[k][j]);
            }
        }
    }
}

bool isNegative(){
    rep(i,n){
        rep(j,n){
            if(i == j && A[i][j] < 0) return true;
        }
    }
    return false;
}

void printpath(){
    rep(i,n){
        rep(j,n){
            if(A[i][j] > pow(10,12)) cout << "INF";
            else cout << A[i][j];
            if(j != n-1) cout << " ";
        }
        cout << endl;
    }
}

int main()
{
    cin >> n;
    int e; cin >> e;
    init(); // 初期化
    rep(_,e){
        int u, v, c; cin >> u >> v >> c;
        A[u][v] = c;
    }
    warshallFloyd();
    if(isNegative()) cout << "NEGATIVE CYCLE" << endl;
    else printpath();
}


Measured memory_bytes: 3180
#include <stdio.h>


int main(void)
{
    int frequency[101] = {0}, input;
    int i, max;

    while(scanf("%d", &input) != EOF){
        frequency[input]++;
    }
    max = 0;
    for (i = 1; i <= 100; i++){
        if (frequency[i] > max) max = frequency[i];
    }
    for (i = 1; i <= 100; i++){
        if (frequency[i] == max) printf("%d\n", i);
    }

    return (0);
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define ft              first
#define sd              second
#define ll          long long
#define pb              push_back
#define mkp           make_pair
#define pll             pair<ll,ll>
#define vll             vector<int>
#define mll             map<ll,ll>
#define pqg             priority_queue<ll>
#define pqs             priority_queue<ll,vll,greater<ll>>
#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 MAXN   10000001
void online_judge()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}

void ISO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {

    ISO();
   // online_judge();
    ll a;
    cin >> a;
    ll x;
    x = a*(1 + (a) + (a*a));
    cout << x <<"\n";
  //  cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
    return 0;
}

Measured memory_bytes: 3644
program main
      implicit none
      integer(8) :: n
      integer(8), allocatable :: a(:), num(:)
      integer(8) :: i, j, k, cnt

      read(*,*) n
      allocate( a(n) )
      read(*,*) a
      
      allocate( num(n) )
      num(:) = 0
      do i = 1, n
        j = a(i)
        num(j) = num(j) + 1
      end do
      
      cnt = 0 
      do i = 1, n
        cnt = cnt + num(i) * ( num(i) - 1 ) / 2
      end do

      do i = 1, n
        j = a(i)
        k = cnt - (num(j) - 1)
        print *, k
      end do
      
end program


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (a < b && b < c ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3084
n, m = gets.chomp.split(' ').map(&:to_i)
arr = []
m.times do
  arr << gets.chomp.split(' ').map(&:to_i)
end
arr.sort_by! { |i| i[1] }
pivot = arr[0]
count = 1
(1...m).each do |i|
  if arr[i][0] >= pivot[1]
    count += 1
    pivot = arr[i]
  end
end
puts count

Measured memory_bytes: 12664
let therefore n =
  let n_mod_10 = n mod 10 in
  if n_mod_10 = 2 then "hon"
  else if n_mod_10 = 4 then "hon"
  else if n_mod_10 = 5 then "hon"
  else if n_mod_10 = 7 then "hon"
  else if n_mod_10 = 9 then "hon"
  else if n_mod_10 = 0 then "pon"
  else if n_mod_10 = 1 then "pon"
  else if n_mod_10 = 6 then "pon"
  else if n_mod_10 = 8 then "pon"
  else "bon"

let () = Printf.printf "%s\n" (therefore (read_int ()))

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

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define PI 3.14159265
#define take(a,n) for(int i=0;i<(n);i++) cin>>(a)[i]
#define out(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int (i)=0;i<(n);(i)++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}


ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

void fastscan(int &number)
{
    bool negative = false;
    register int c;

    number = 0;

    // extract current character from buffer
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }

    // Keep on extracting characters if they are integers
    // i.e ASCII Value lies from '0'(48) to '9' (57)
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}

ll poww(ll a,ll b)
{
  ll ans=1;
  for(int i=1;i<=b;i++)
  {
    ans*=a;
  }
  return ans;
}

ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

ll ncr(int n,int r)
{
  ll ans=1;
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t=1;
  while(t--)
  {
    int n,z;
    cin>>n;
    cout<<n*n*n;
  
  }


}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll H,W;
char s[2020][2020];
ll lva[2020][2020];
ll lhr[2020][2020];
ll i,j,k,ans;
int main(){
    scanf("%lld%lld", &H,&W);
    fornum(i,0,H){
        scanf("%s", s[i]);
    }
    fornum(i,0,W){
        ll a = 0,b=0;
        fornum(j,0,H){
            if(s[j][i]=='#'){
                fornum(k,b,j){
                    lva[k][i] = a;
                }
                a = 0;
                b = j + 1;
            }else{
                a++;
            }
        }
        fornum(k,b,H){
            lva[k][i] = a;
        }
    }
    fornum(i,0,H){
        ll a = 0,b=0;
        fornum(j,0,W){
            if(s[i][j]=='#'){
                fornum(k,b,j){
                    lhr[i][k] = a;
                }
                a = 0;
                b = j + 1;
            }else{
                a++;
            }
        }
        fornum(k,b,W){
            lhr[i][k] = a;
        }

    }
    fornum(i,0,H){
        fornum(j,0,W){
            if(s[i][j]=='.'){
                ll a = lva[i][j] + lhr[i][j]-1;
                if(ans<a){
                    ans = a;
                    //printf("%lld %lld %lld %lld\n", i, j, lva[i][j], lhr[i][j]);
                }
            }
        }
    }

    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 67968
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b;
	char c;
	scanf("%d%d",&a,&b);
	if(a==b)
	printf("Draw\n");
	else if(a==1)
	printf("Alice\n");
	else if(b==1)
	printf("Bob\n");
	else
	{
		if(a<b)
		printf("Bob\n");
		else
		printf("Alice\n");
	}
	return 0;
}

Measured memory_bytes: 128
def calc_score(now_ans, one_counter, N):
    score = 0
    length = len(one_counter)
    for i, cn in enumerate(zip(now_ans, one_counter[::-1])):
        c = cn[0]
        n = cn[1]
        point = pow(2, length - i - 1)
        if c == "0":
            score += n*point
        else:
            score += (N-n)*point
    return score


def main():
    N, K = map(int, input().split(" "))
    A = list(map(int, input().split(" ")))
    Abin = map(bin, A)
    ans_length = max(len(bin(K)), len(bin(max(A)))) - 2
    one_counter = [0 for i in range(ans_length)]
    for abin in Abin:
        rabin = abin[::-1]
        for i, c in enumerate(rabin):
            if ans_length <= i:
                break
            if c == "1":
                one_counter[i] += 1
            elif c == "b":
                break
    # print(one_counter)
    border = N/2
    temp_ans = ""
    for i, n in enumerate(one_counter[::-1]):
        if n >= border:
            temp_ans += "0"
        else:
            temp_ans += "1"

    binK = bin(K)[2:].zfill(ans_length)
    ans = calc_score(binK, one_counter, N)
    # print(temp_ans)
    # print(binK)
    for i, c in enumerate(binK):
        if c == "0":
            continue
        now_ans = binK[:i] + "0" + temp_ans[i+1:]
        temp = calc_score(now_ans, one_counter, N)
        ans = max(ans, temp)
        # print(now_ans, temp)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14620
#include<stdio.h>
int main()
{
	int h,w,i,j,x[100],y[100];
	char a[100][100];

	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++)
		scanf("%s",a[i]);

	for(i=0;i<h;i++){
		for(j=0;j<w;j++)
			if(a[i][j]=='#'){
				x[i]=1;
				y[j]=1;
			}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(x[i]==1&&y[j]==1)
				printf("%c",a[i][j]);
		}
		if(x[i]==1)
			printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
from functools import reduce

n = int(input())
values = list(map(int, list(input().split())))


def mymin(a, b):
    if a < b:
        return a
    else:
        return b

def mymax(a, b):
    if a > b:
        return a
    else:
        return b

def mysum(a, b):
    return a + b

print(reduce(mymin, values, 1000001), reduce(mymax, values, -1000001), reduce(mysum, values, 0))


Measured memory_bytes: 7268
#include <vector>
#include <queue>
#include <iostream>
using namespace std;


class TopologicalSort {
public:
  TopologicalSort(int V): V(V), G(V, vector<int>(0)), indeg(V, 0) {}

  void addEdge(int s, int t) {
    G[s].push_back(t);
    indeg.at(t)++;
  }

  vector<int> getVertices() {
    return vs;
  }

  bool sort() {
    queue<int> Q;
    vector<bool> done(V, false);

    for (int i=0; i<V; i++) {
      if (indeg.at(i) == 0) {
        Q.push(i);
        while (Q.size()) {
          int v = Q.front();Q.pop();
          if (done.at(v)) continue;
          done.at(v) = true;
          vs.push_back(v);
          for (auto u: G[v]) {
            if (--indeg.at(u) == 0) Q.push(u);
          }
        }
      }
    }

    return vs.size() == V;
  }

private:
  int V;
  vector<vector<int> > G;
  vector<int> indeg;
  vector<int> vs;
};


#define MAX_E 1001
int V, E;
int S[MAX_E], T[MAX_E];


void input() {
  int s, t;
  cin >> V >> E;
  for (int i=0; i<E; i++) {
    cin >> S[i] >> T[i];
  }
}

void solve() {
  TopologicalSort ts(V);
  for (int i=0; i<E; i++) ts.addEdge(S[i], T[i]);
  if (ts.sort()) cout << 0 << endl;
  else cout << 1 << endl;
}

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



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

using namespace std;
typedef long long ll;
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    int h,w;cin>>h>>w;
    vector<string> grid(h);
    rep(i,h)cin>>grid[i];
    int d[4]={1,0,-1,0};
    int res = 0;
    queue<pair<int,int>> q;
    rep(i,h)rep(j,w){
        if(grid[i][j]=='#')continue;
        
        q.push({i,j});
        vector<vector<int>> step(h,vector<int>(w,-1));
        step[i][j]=0;
        while(!q.empty()){
            int x=q.front().first;
            int y=q.front().second;
            q.pop();
            rep(k,4){
                int nx=x+d[k];
                int ny=y+d[k^1];
                if(0<=nx&&nx<h&&0<=ny&&ny<w&&grid[nx][ny]=='.'&&step[nx][ny]==-1){
                    step[nx][ny]=step[x][y]+1;
                    q.push({nx,ny});
                }
            }
        }
        int tmp = -1;
        rep(a,h)rep(b,w)if(step[a][b]!=-1)tmp=max(tmp,step[a][b]);
        res=max(res,tmp);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int id,d,l,r,ll=0,rr=1e6;
	cin>>id>>d;
	for(int i=0;i<d;i++){
		cin>>l>>r;
		ll=ll>l?ll:l;
		rr=rr<r?rr:r; 
	}
	if(rr<ll)cout<<0;
	else cout<<rr-ll+1;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N, M;

  cin >> N >> M;

  cout << (N == M ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int x;
	s.length()%2==0?x=(s.length()/2)-1:x=(s.length()/2);
	int count=0;
	for(int i=0;i<=x;i++)
	{
		if(s[i]!=s[s.length()-i-1])
			count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 105;
vector<int> gra[MAXN];
int par[MAXN], ch[MAXN], n, rt;
P far;
void dfs1(int u, int fa, int d) {
	chkmax(far, P(d, u)), par[u] = fa;
	for (int v : gra[u]) if (v != fa) dfs1(v, u, d + 1);
}

void dfs2(int u, int fa, int d) {
	chkmax(ch[d], (int)gra[u].size() - (fa > 0));
	for (int v : gra[u]) if (v != fa) dfs2(v, u, d + 1);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v; scanf("%d%d", &u, &v);
		gra[u].push_back(v), gra[v].push_back(u);
	}
	dfs1(1, 0, 0);
	rt = far.second, far = P(0, 0);
	dfs1(rt, 0, 0);
	int dis = far.first, a = far.second;
	printf("%d ", dis / 2 + 1);
	for (int i = 0; i < dis >> 1; i++) a = par[a];
	
	if (dis & 1) {
		int b = par[a];
		dfs2(a, b, 0);
		dfs2(b, a, 0);
		LL ans = 2;
		for (int i = 0; i < dis >> 1; i++) ans *= ch[i];
		return printf("%lld\n", ans), 0;
	}
	
	dfs2(a, 0, 0);
	LL ans = 1;
	for (int i = 0; i < dis >> 1; i++) ans *= ch[i];
	for (int v : gra[a]) {
		memset(ch, 0, sizeof(ch));
		dfs2(a, v, 0);
		dfs2(v, a, 0);
		LL cur = 2;
		for (int i = 0; i < dis >> 1; i++)
			if (ch[i]) cur *= ch[i];
		chkmin(ans, cur);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        var count = 1;
        
        while(true){
            var message = "Case ";
            var num = int.Parse(Console.ReadLine());
            
            if(num == 0){
                break;
            }
            
            message += count + ": " + num;
            
            Console.WriteLine(message);
            
            count++;
        }
    }
}



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

int main() {
  int N;
  cin >> N;
  int min_v = 1001;
  int max_v = -1;
  for (int i = 0; i < N; ++i) {
    int ai;
    cin >> ai;
    min_v = min(min_v, ai);
    max_v = max(max_v, ai);
  }
  cout << max_v - min_v << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author rn-sshawish
 */
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int y = input.nextInt();
        int z = input.nextInt();
        int n = input.nextInt();
        int count = 0;
        for (int i = 0; i <= x; i++) {
            for (int j = 0; j <= y; j++) {
                for (int k = 0; k <= z; k++) {
                    if (((i*500) +(j*100) + (k*50)) == n) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22100
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・N=6とする。
・[1,1,1,1,1,1],[0,1,1,1,1,1],[0,0,1,1,1,1],[0,0,0,1,1,1],[0,0,0,0,1,1],[0,0,0,0,0,1],[0,0,0,0,0,0]
合計ちょうど6個の線形結合 → 任意の単調数列。最初のやつは1回以上使わなければいけない。
・1,0,-1,-2,-2,-1,0 合計5個で0以上を作る
・-1,0,1,2,2,1,0 合計5個で0以下を作る
・0,1,2,3,3,2,1 合計5個で5以下を作る
・1,2,3,3,2,1 任意個数で5以下を作る
"""

N,MOD = map(int,read().split())

if N % 2 == 0:
    A = list(range(1,N//2+1))*2
else:
    A = list(range(1,N//2+1))*2+[(N+1)//2]

A.sort()

# 和 -> 通り
dp = [1] + [0] * (N+N+10)
for x in A:
    for i in range(N+1):
        dp[i] %= MOD
        dp[i+x] += dp[i]

answer = sum(dp[:N]) % MOD
print(answer)

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

int main() {
  int a,b,c;
  cin >>a >>b >>c;
  if(a==b){
    if(b==c){
      cout <<"Yes" <<endl;
      return 0;
    }
  }
  cout <<"No" <<endl;
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s,t,jwb="";
ll dp[5000][5000];
ll f(ll n, ll m){
	if (n<0 || m<0) return 0;
	if(dp[n][m]!=-1)return dp[n][m];
	if (s[n]==t[m]){
		dp[n][m]=f(n-1,m-1)+1;
	}
	else{
		dp[n][m]=max(f(n-1,m),f(n,m-1));
	}
	return dp[n][m];
}
void rec(ll n, ll m){
	if(n<0 || m<0)return;
	if (s[n]==t[m]){
		jwb+=s[n];
		rec(n-1,m-1);
	}
	else{
		if(f(n-1,m)>=f(n,m-1))rec(n-1,m);
		else rec(n,m-1);
	}
}
int main(){
	cin >> s >> t;
	memset(dp,-1,sizeof dp);
	rec(s.size()-1, t.size()-1);
	reverse(jwb.begin(),jwb.end());
	cout << jwb << endl;
}

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

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

    vector<int> vec_num;
    for(int i = 0;i < n;i++){
        cin >> input_num;
        vec_num.push_back(input_num);
    }

    int nmin=vec_num[0],nmax=vec_num[0];
    long nsum = 0;

    for (auto x : vec_num){
        if(nmin > x)
          nmin = x;
        if(nmax < x)
          nmax = x;
        nsum += x;
    }
    cout << nmin << " " << nmax << " " << nsum << endl;
}


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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());

        var inputA = Console.ReadLine().Split(" ");
        var inputB = Console.ReadLine().Split(" ");
        var inputC = Console.ReadLine().Split(" ");

        var A = new List<int>();
        var B = new List<int>();
        var C = new List<int>();
        for (int i = 0; i < N; i++)
        {
            A.Add(int.Parse(inputA[i]));
            B.Add(int.Parse(inputB[i]));
            C.Add(int.Parse(inputC[i]));
        }

        // それぞれをソートする
        A.Sort();
        B.Sort();
        C.Sort();

        var count = 0L;
        for (int i = 0; i < N; i++)
        {
            // Bの要素を基準にAの個数、Cの個数を数える
            long leftA = ExecuteBinarySearchMax(B[i], A) + 1;
            long rightC = N - ExecuteBinarySearchMin(B[i], C);

            count += leftA * rightC;
        }

        Console.WriteLine(count);
    }

    // numより数値が小さくなる最大のindexを求める
    static int ExecuteBinarySearchMin(int num, List<int> list)
    {
        int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
        int ok = list.Count();// 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

        /* ok と ng のどちらが大きいかわからないことを考慮 */
        while (Math.Abs(ok - ng) > 1)
        {
            int mid = (ok + ng) / 2;

            if (list[mid] > num) ok = mid;
            else ng = mid;
        }
        return ok;
    }

    // numより数値が大きくなる最小のindexを求める
    static int ExecuteBinarySearchMax(int num, List<int> list)
    {
        int ng = list.Count();
        int ok = -1;

        /* ok と ng のどちらが大きいかわからないことを考慮 */
        while (Math.Abs(ok - ng) > 1)
        {
            int mid = (ok + ng) / 2;

            if (list[mid] < num) ok = mid;
            else ng = mid;
        }
        return ok;
    }
}

Measured memory_bytes: 52992
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <unordered_map>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL D,a[30],K,res,d[30],b[30];
unordered_map<int,int> cnt;

void gen(LL p){
    if (p<=(K+1)/2){
        int i;
        for (i=K; i>(K+1)/2; i--){
            b[i]=d[i];
            if (cnt[b[i]]==0) return;
        }

        for (i=1; i<=(K+1)/2; i++)
            b[i]=-d[K-i+1];

        int cr=0;
        for (i=1; i<=K; i++){
            b[i]-=cr,cr=0;
            if (b[i]<0) b[i]=10+b[i],cr=1;
            if (b[i]!=a[i]) return;
        }

        if (cr) return;

        LL ways=1;
        for (i=K-1; i>=(K+2)/2; i--){
            ways*=cnt[d[i]];
        }

        ways*=(cnt[d[K]]-1);
        res+=ways;
        return;
    }

    d[p]=a[p];
    gen(p-1);
    d[p]=a[p]+1;
    gen(p-1);
    d[p]=a[p]-10;
    gen(p-1);
    d[p]=a[p]-9;
    gen(p-1);
}

int main(){
    cin >> D;

    while (D){
        a[++K]=D%10;
        D/=10;
    }

    int x,y;
    for (x=0; x<10; x++)
        for (y=0; y<10; y++)
            cnt[x-y]++;

    for (; K<=19; K++){
        memset(d,0,sizeof(d));
        gen(K);
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

		int result = N.chars().map(s -> Character.getNumericValue(s)).sum();
		
		if (Integer.parseInt(N) % result == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}


Measured memory_bytes: 27988
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    A, B = LI()

    if A == B:
        print(A)
        return
    if B - A < 20:
        xor = B
        for i in range(A, B):
            xor ^= i
        print(xor)
        return

    to_xor = []
    while A%4 != 0:
        to_xor.append(A)
        A += 1
    while B%4 != 3:
        to_xor.append(B)
        B -= 1
    xor = 0
    for i in to_xor:
        xor ^= i
    print(xor)


main()

Measured memory_bytes: 3064
#include <cstdio>

int main()
{
  int M,D;
  scanf("%d%d",&M,&D);
  int count=0;
  for(int d1=2;d1<10;d1++){
    for(int d2=2;d2<10;d2++){
      if(d1*d2<=M&& 10*d1+d2<=D){
	count++;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int a=scan.nextInt();
        a=a % 10;
        if (a==2 ||a==4||a==5||a==7||a==9){
            System.out.println("hon");
        }else if(a==0 ||a==1||a==6||a==8){
            System.out.println("pon");
        }else{
            System.out.println("bon");
        }

    }
}

Measured memory_bytes: 35740
n, m = io.read("*n", "*n")
t = {}
for i = 1, 8 do t[i] = {} end
for i = 1, n do
  a, b, c = io.read("*n", "*n", "*n")
  for flg = 1, 8 do
    aflg = flg % 2 == 0 and 1 or -1
    bflg = flg % 4 <= 1 and 1 or -1
    cflg = flg <= 4 and 1 or -1
    t[flg][i] = a * aflg + b * bflg + c * cflg
  end
end
for i = 1, 8 do
  table.sort(t[i], function(x, y) return x > y end)
end

summax = 0
for flg = 1, 8 do
  sum = 0
  for i = 1, m do
    sum = sum + t[flg][i]
  end
  if(flg == 1) then summax = sum else summax = math.max(summax, sum) end
end
print(summax)


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

int a[5];
int ans = 1e9;
 
void solve(){
    for(int i = 0; i < 5; i++) cin >> a[i];
    do{
        int sum = 0;
        for(int i = 0; i < 4; i++){
            //cout << a[i] << ' ';
            int x = (a[i] % 10 == 0) ? a[i] : (a[i] / 10 + 1) * 10;
            sum += x;
        }
        //cout << " :: " << sum + a[4] << endl;
        ans = min(sum + a[4], ans);
    }
    while(next_permutation(a, a + 5));
    cout << ans;
}

 
int main() {
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    string s;
    cin >> s;
    stack<char> st;
    for(int i=0;i<s.length();i++){
        if(!st.size()) st.push(s[i]);
        else if(st.top()=='S'&&s[i]=='T') st.pop();
        else st.push(s[i]);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 644
#include<stdio.h>
int main()
{
  int n, x=0, i;
  char m;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%c", &m);
    if(m=='Y'){
      x+=1;
    }
  }
  if(x==0){
    printf("Three\n");
  }else{
    printf("Four\n");
  }
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env ruby
# require 'pry'

# N
# a_1 b_1
# ...
# a_N b_N
# ↑を[[a_1,..a_N],[b_1,..b_N]]にする
# N = gets.to_i
# a, b = N.times.map{gets.split.map(&:to_i)}.transpose

def has_8_divider?(num)
  count = 0
  1.upto(num) do |i|
    count +=1 if num % i == 0
  end
  count == 8 ? true : false
end

n = gets.to_i
ary = [*(1..n)].select(&:odd?)
output = 0
ary.map do |e|
  output +=1 if has_8_divider?(e)
end

puts output

Measured memory_bytes: 14124
# Written by Shagoto
s = input()
i = 0
check = True
while(i < len(s)):
    if(i % 2 == 0 and s[i] == "L"):
        check = False
        break
    elif(i % 2 == 1 and s[i] == "R"):
        check = False
        break
    i += 1

if(check):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61576
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
   
    if(a==1){
        printf("1\n");
    }
    else if(a<=b&&a!=1){
        printf("%d\n",a);
    }
    else if(a>b){
        printf("%d\n",a-1);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[1<<20];
P dp[1<<20];
void cmax(P &a, P b){
	if(a.fi < b.fi){a.se = max(a.fi, b.se);a.fi = b.fi;}
	else a.se = max(a.se, b.fi);
}

signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,1<<n)scanf("%lld", &a[i]);
	rep(i,1<<n)dp[i] = P(a[i], -INF);
	rep(i,n)rep(bit,1<<n)if((bit>>i) & 1)cmax(dp[bit], dp[bit^(1<<i)]);
	int ans = -INF;
	rep(i,1<<n){
		int tmp = dp[i].fi+dp[i].se;
		chmax(ans, tmp);
		if(i > 0)printf("%lld\n", ans);
	}
	return 0;
}




Measured memory_bytes: 13312
#include <bits/stdc++.h>
 
// headers {{{
using namespace std;
// using namespace rel_ops;
 
typedef long long int64;
typedef unsigned long long uint64;
const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define mem(a,b) memset(a, b, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ff first
#define ss second
#ifdef LOCAL
#define dbg(args...) printf(args); //##__VA_ARGS__
#define dout cout
#define out(x) (cout<<#x<<": "<<x<<endl)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
#else
#define dbg(...)
#define dout if(true);else cout
#define out(...)
#define show(...)
#endif
// }}}

int main() {
    int N;
    while (cin >> N) {
        auto solve = [&]() {
            vector<int64> v(N);
            rep(i, N) cin >> v[i];
            int64 s = 1e18, ans = 1;
            rep(i, N) {
                if (v[i] == 0) { cout << 0 << endl; return; }
                s/=v[i];
                ans*=v[i];
            }
            if (s<1) cout << -1 << endl;
            else cout << ans << endl;
        };
        solve();
    }
    return 0;
}



Measured memory_bytes: 4040
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rev(x) reverse(x,x+strlen(x))
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int N=1e5+1;
int n,m,maxn,tmp;
char nn[101][101];
char mm[101][101];
int main(){
    scanf("%d%*c",&n);
    for(int i=0;i<n;i++) scanf("%s",nn[i]);
    scanf("%d%*c",&m);
    for(int i=0;i<m;i++) scanf("%s",mm[i]);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(strcmp(nn[i],nn[j])==0) tmp++;
        }
        for(int j=0;j<m;j++){
            if(strcmp(nn[i],mm[j])==0) tmp--;
        }
        maxn=max(tmp,maxn);
        tmp=0;
    }
    cout<<maxn<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "os"
    "bufio"
    "strconv"
    "sort"
    "math"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Split(bufio.ScanWords)
    n := nextInt()
    m := [][]int{}
    m = append(m, []int{0,0,0})
    for i := 0; i < n; i++ {
        m = append(m, nextIntArr(3))
    }

    ans := "Yes"

    for i := 1; i < len(m); i++ {
        dt := int(math.Abs(float64(m[i-1][0] - m[i][0])))
        dx := int(math.Abs(float64(m[i-1][1] - m[i][1])))
        dy := int(math.Abs(float64(m[i-1][2] - m[i][2])))
        if dt < dx + dy || dt % (dx + dy) != 0 {
            ans = "No"
            break
        }
    }

    fmt.Println(ans)
}

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 13696
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
c=1
ans=1
if a[0]==1 and n==0:
    print(1)
    exit()
if a[0]>0:
    print(-1)
    exit()
for i in a[1:]:
    b-=i
    c=min(c*2-i,b)
    ans+=c
    if c<0:
        print(-1)
        exit()
print(ans+sum(a))

Measured memory_bytes: 19900
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
const ll MOD=1e9+7;

string str;
int t;

int num(int &i){
  int re=0;
  while(i<str.size() && isdigit(str[i])){
    re*=10;
    re+=str[i]-'0';
    ++i;
  }
  return re;
}

string Str(int &i){
  //cout<<i<<endl;
  string re;
  while(i<str.size()){
    if(isalpha(str[i]))
      re+=str[i++];
    else if(isdigit(str[i])){
      int n=num(i);
      string tmp;
      if(str[i]=='('){
	++i;
	tmp=Str(i);
	++i;
      }else{
	tmp=str[i++];
      }
      rep(i,n){
	re+=tmp;
	if(re.size()>t) return re;
      }
    }else if(str[i]==')') break;
  }
  if(re.size()>t) return re;
  return re;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  while(cin>>str>>t,str!="0" || t){
    int n=str.size(),i=0;
    //cout<<str<<endl;
    string re=Str(i);
    //cout<<re<<endl;
    if(re.size()<=t){
      cout<<0<<endl;
    }else{
      cout<<re[t]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8672