akhauriyash/Code-Regression huggingface dataset:
S = list(input())
answer = 0

for i in range(len(S)):
    counter = 0
    for j in range(i,len(S)):
        if S[j] == "A" or S[j] == "C" or S[j] == "G" or S[j] == "T":
            counter += 1  
            if j == len(S)-1:
                if counter > answer:
                    answer = counter
        else:
            if counter > answer:
                answer = counter
            break
print(answer)

Measured memory_bytes: 3060
n,m=map(int,input().split())
h=list(map(int,input().split()))
P=[list(map(int,input().split())) for i in range(m)]
good=[1]*n
for i in range(m):
  if h[P[i][0]-1]>=h[P[i][1]-1]:
    good[P[i][1]-1]=0
  if h[P[i][1]-1]>=h[P[i][0]-1]:
    good[P[i][0]-1]=0
print(sum(good))

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

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            long N = Long.parseLong(br.readLine());
            long condition = 90000000000000000L;
            long ans = 0;
            long base = 100;
            if (condition < N) {
                N = N / 10000000000000L;
                base = condition / 10000000000000L;
                ans = 3517;
            }
            while (base < N) {
                base = (base * 100 + (base * 1)) / 100;
                ans++;
            }

            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 25332
from itertools import permutations
def main():
    n, m = map(int, input().split())
    path = []
    for _ in range(m):
        path.append(tuple(map(int, input().split())))

    nodes = [i for i in range(2, n + 1)]
    routes = permutations(nodes, n-1)

    r = 0
    for route in routes:
        route = list(route)
        route.insert(0,1)
        for i1 in range(n-1):
            if (route[i1], route[i1+1]) not in path:
                if (route[i1+1], route[i1]) not in path:
                    break
        else:
            r += 1
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
[N, X] = list(map(int, input().split()))
list_m = []
for i in range(N):
  list_m.append(int(input()))
X_leftover = X - sum(list_m)
cnt = 0
while X_leftover >= min(list_m):
  X_leftover -= min(list_m)
  cnt += 1
print(len(list_m) + cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 1e18;
int n,m, a[maxn * 2], cur[maxn * 2];
int nxt[60][maxn];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    cin >> n >> m;
    m *= n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[n + i] = a[i];
    }
    for(int i = 2 * n - 1; i >= 0; i--)
    {
        if(i < n) nxt[0][i] = cur[a[i]] - i + 1;
        cur[a[i]] = i;
    }
    for(int len = 1; len < 60; len++)
    {
        for(int i = 0; i < n; i++)
        {
            int gau = (i + nxt[len - 1][i]) % n;
            nxt[len][i] = min(inf, nxt[len - 1][i] + nxt[len - 1][gau]);
        }
    }
    int gau = 0;
    for(int i = 59; i >= 0; i--)
    {
        if(gau + nxt[i][gau % n] <= m)
        {
            gau += nxt[i][gau % n];
        }
    }
    if(gau == m) return 0;
    gau %= n;
    while(gau < n)
    {
        if(nxt[0][gau] + gau > n)
        {
            cout << a[gau++] << ' ';
        }
        else gau += nxt[0][gau];
    }
}


Measured memory_bytes: 101504
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n % 1000 == 0) {
            System.out.println(0);
            return;
        }
        System.out.println(1000 - (n % 1000));
    }

}


Measured memory_bytes: 35660
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10, mod=1e9+7;

pair<ll, pair<ll, ll> > extendedEuclid(ll a, ll b) {
        if(a == 0) return make_pair(b, make_pair(0, 1));
        pair<ll, pair<ll, ll> > p;
        p = extendedEuclid(b % a, a);
        return make_pair(p.first, make_pair(p.second.second - p.second.first*(b/a), p.second.first));
}

ll modInverse(ll a, ll m) {
    return (extendedEuclid(a,m).second.first + m) % m;
}

int main ()
{
    FASTIO
    ll n,m;
    cin >> n >> m;
    ll sum=0;
    for(ll i=m;i<=n+1;i++){
        ll x = i*(i-1)/2;;
        ll y = (i)*(n+(n-i+1))/2;
        sum += y-x+1;
        sum %= mod;
    }
    cout << sum << endl;
    return 0;
}
/**

*/


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

#define STRLENMAX 100000

int main(void){
  int i;
  char s[STRLENMAX];
  scanf("%s", s);
  for (i = 0; i < strlen(s); i += 2){
    s[i / 2] = s[i];
  }
  s[i / 2] = '\0';
  printf("%s\n", s);
  return(0);
}

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

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; }

using ll = long long;

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

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int> dis(K);
  rep(i,K) cin>>dis[i];
  int t = 0;
  vector<int> like;
  rep(i,10){
    if(t<K&&i==dis[t]) t++;
    else like.push_back(i);
  }
  queue<int> q;
  for(auto x:like) {
    if(x==0)continue;
    q.push(x);
  }
  int s = 0;
  while(s<N){
    s=q.front();
    q.pop();
    for(auto x:like){
      q.push(s*10+x);
    }
  }
  cout<<s<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(int i=l; i<n; ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int,int>;
using pii = pair<int,int>;
using vpii = vector<pair<int,int>>;
using ti3 = tuple<int,int,int>;

int main(){
  ll n,x; cin>>n>>x;
  vi a(n);
  REP(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  ll sum=0;
  REP(i,n-1){
    if(x>=sum+a[i]) sum+=a[i];
    else{
      cout<<i<<endl;
      return 0;
    }
  }
  if(x==sum+a[n-1]) cout<<n<<endl;
  else cout<<n-1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n,k;
std::cin >> n >> k;
std::vector<std::vector<int>> a(n,std::vector<int>(2,0));
for(int i = 0; i < n; i++){
    int tempa,tempb;
    std::cin >> tempa >> tempb;
    a[i][0] = tempa;
    a[i][1] = tempb;
}
std::sort(a.begin(),a.end());
int index = 0;
int sum = 0;
while(sum < k){
    sum += a[index][1];
    index++;
}
std::cout << a[index - 1][0] << std::endl;
return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int a,b,c; cin >> a >> b >> c;
    bool res =false;
    FOR(i,1,b){
        if (a*i%b == c) res =true;
    }
    if (res) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
z=''
while True:
    try:
        z += input()
    except EOFError:
        break
a = []
b = 0
for i in z:
    if i.isupper():
        a += i.lower()
    a += i
al = [chr(i) for i in range(97, 97 + 26)]
for i in al:
    b = str(a.count(i))
    print('{} : {}'.format(i,b))

Measured memory_bytes: 7472
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,p,q;
    ans=0;
    string s1,s2;
    vector<int> v;
    cin>>n>>m>>q;
    int s[q],t[q],l[q],d[q];
    rep(i,0,q){
        cin>>s[i]>>t[i]>>l[i]>>d[i];
    }
    rep(z,0,m){//2
        rep(x,z,m){//3
            rep(c,x,m){//4
                rep(v,c,m){//5
                    rep(b,v,m){//6
                        rep(e,b,m){//7
                            rep(k,e,m){//8
                                rep(j,k,m){//9
                                    rep(i,j,m){//10
                                        int a[10];
                                        a[0]=0;
                                        a[1]=z;
                                        a[2]=x;
                                        a[3]=c;
                                        a[4]=v;
                                        a[5]=b;
                                        a[6]=e;
                                        a[7]=k;
                                        a[8]=j;
                                        a[9]=i;
                                        int u=0;
                                        rep(y,0,q){
                                            if(a[10+t[y]-n-1]-a[10+s[y]-n-1]==l[y])
                                            u+=d[y];
                                        }
                                        ans=max(ans,u);
                                       
                                    }
                                    
                                }
                                
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,w;
    cin>>h>>w;
    //int maze[h][w];
    int d[h*w];
    int n;
    cin>>n;
    int res=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        for(int j=0;j<a;j++){
            d[res]=i+1;
            res++;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i%2==0){
                cout<<d[i*w+j]<<" ";
            }
            else{
                cout<<d[i*w+w-j-1]<<" ";
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include<stdio.h>
#define INF 1000000
#define N 100

int n,S[N],T[N][N],cost[N][N],U[N];

void Root(int a,int b){
  int i;
  U[a] = b;
  for(i=0; i<S[a]; i++){
    if(U[T[a][i]]>b + cost[a][i])Root(T[a][i], b+cost[a][i]);
  }
}

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

  for(i=0; i<n; i++){
    scanf("%d",&m);
    scanf("%d",&S[m]);
    for(j=0; j<S[m]; j++){
      scanf("%d",&T[m][j]);
      scanf("%d",&cost[m][j]);
    }
  }
  for(i=0; i<n; i++) U[i] =INF;
  Root(0,0);
  for(i=0; i<n; i++)printf("%d %d\n",i,U[i]);
  return 0;
  
}



Measured memory_bytes: 2056
s = str(input())
l = len(s)
flag = 0
for i in range(l):
    if i % 2 == 1 and s[i] == 'R':
        flag = 1
        break
    elif i % 2 == 0 and s[i] == 'L':
        flag = 1
        break
if flag == 1:
    print('No')
else:
    print('Yes')


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

int main(void) {
	int i, j, n;
	cin >> n;
	for (i = 1; i <= n; i++) {
		if (i % 3 == 0)
			cout << ' ' << i;
		else {
			for (j = i; j != 0; j /= 10) {
				if (j % 10 == 3) {
					cout << ' ' << i;
					j = 0;
				}
			}
		}
	}
	cout << endl;
	return 0;
}

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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    // dp[j] - maximum points if Taro did activity j on the last day
    vector<int> dp(3);
    for (int i = 0; i < n; i++) {
        vector<int> ndp(3, 0);
        vector<int> c(3);
        for (int& _c : c) cin >> _c;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    ndp[k] = max(ndp[k], dp[j] + c[k]);
                }
            }
        }
        dp = ndp;
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}

int main(void)
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}


Measured memory_bytes: 3604
#include<stdio.h>

int main(){
    int h, w;

    scanf("%d %d", &h, &w);
    char matrix[h + 1][w + 1];
    for(int i = 0; i < h; i++){
        scanf("%s", matrix[i]);
    }
    int score_left[h][w], score_right[h][w], score_up[h][w], score_down[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(matrix[i][j] == '#'){
                score_left[i][j] = 0;
            }else{
                if(j == 0){
                    score_left[i][j] = 1;
                }else{
                    score_left[i][j] = score_left[i][j - 1] + 1;
                }
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = w - 1; j >= 0; j--){
            if(matrix[i][j] == '#'){
                score_right[i][j] = 0;
            }else{
                if(j == w - 1){
                    score_right[i][j] = 1;
                }else{
                    score_right[i][j] = score_right[i][j + 1] + 1;
                }
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(matrix[i][j] == '#'){
                score_up[i][j] = 0;
            }else{
                if(i == 0){
                    score_up[i][j] = 1;
                }else{
                    score_up[i][j] = score_up[i - 1][j] + 1;
                }
            }
        }
    }
    for(int i = h - 1; i >= 0; i--){
        for(int j = 0; j < w; j++){
            if(matrix[i][j] == '#'){
                score_down[i][j] = 0;
            }else{
                if(i == h - 1){
                    score_down[i][j] = 1;
                }else{
                    score_down[i][j] = score_down[i + 1][j] + 1;
                }
            }
        }
    }
    int max = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int score = score_left[i][j] + score_right[i][j] + score_up[i][j] + score_down[i][j] - 3;
            if(score > max){
                max = score;
            }
        }
    }
    printf("%d", max);
}

Measured memory_bytes: 66560
#include <stdio.h>

#define N 9

int board[N];
int rows = 3, cols = 3, zeroIndex;

// for previousMove: 0 is down, 1 is up, 2 is left, 3 is right
int blindSearch(int x, int y, int moves, int previousMove) {
  int i, foundAnswer;

  // answer is less than manhattan distance, not possible
  if (moves < (x + y))
    return 0;

  if (!moves) {
    for (i = 0; i < N - 1; i++) {
      if (board[i] != i + 1)
        return 0;
    }

    return 1;
  }

  if (x > 0 && previousMove != 1) {
    // can expand down
    board[zeroIndex] = board[zeroIndex + rows];
    zeroIndex += rows;

    foundAnswer = blindSearch(x - 1, y, moves - 1, 0);
    if (foundAnswer)
      return 1;

    board[zeroIndex] = board[zeroIndex - rows];
    zeroIndex -= rows;
  }

  if (y > 0 && previousMove != 3) {
    // right
    board[zeroIndex] = board[zeroIndex + 1];
    zeroIndex++;

    foundAnswer = blindSearch(x, y - 1, moves - 1, 2);
    if (foundAnswer)
      return 1;

    board[zeroIndex] = board[zeroIndex - 1];
    zeroIndex--;
  }

  if (y < rows - 1 && previousMove != 2) {
    // left
    board[zeroIndex] = board[zeroIndex - 1];
    zeroIndex--;

    foundAnswer = blindSearch(x, y + 1, moves - 1, 3);
    if (foundAnswer)
      return 1;

    board[zeroIndex] = board[zeroIndex + 1];
    zeroIndex++;
  }

  if (x < cols - 1 && previousMove != 0) {
    // up
    board[zeroIndex] = board[zeroIndex - rows];
    zeroIndex -= rows;

    foundAnswer = blindSearch(x + 1, y, moves - 1, 1);
    if (foundAnswer)
      return 1;

    board[zeroIndex] = board[zeroIndex + rows];
    zeroIndex += rows;
  }

  return 0;
}

int main() {
  int i, x, y, current;

  for (i = 0; i < N; i++) {
    scanf("%d", &board[i]);
    if (!board[i])
      zeroIndex = i;
  }

  x = cols - (zeroIndex / rows) - 1;
  y = rows - (zeroIndex % cols) - 1;

  for (current = 0; current < 50; current++) {
    if (blindSearch(x, y, current, -1)) {
      printf("%d\n", current);
      return 0;
    }
  }
}


Measured memory_bytes: 2100
x, y = map(int, input().split(" "))
if x * y > 0:
  if x > 0:
    if y > x:
      print(y - x)
    elif y < x:
      print(x - y + 2)
    else:
      print(0)
  else:
    if y > x:
      print(y - x)
    elif y < x:
      print(-(y - x) + 2)
    else:
      print(0)
elif x * y < 0:
  if x > 0:
    if x > -y:
      print(x + y + 1)
    elif x < -y:
      print((y * -1) - x + 1)
    else:
      print(1)
  else:
    if -x > y:
      print(-x - y + 1)
    elif -x < y:
      print(x + y + 1)
    else:
      print(1)
else:
  if (x == 0 and y > 0) or (x < 0 and y == 0):
    print(y - x)
  elif (x == 0 and y < 0) or (x > 0 and y == 0):
    print(x - y + 1 )
  else:
    print(0)
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll

int n,k;

signed main(){
  cin>>n>>k;

  int a = n/k;
  int b = n/k+(n%k>=k/2);
  if(k%2!=0) 
    b = 0;

  cout<<a*a*a+b*b*b<<endl;

}

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

using namespace std;

typedef array<double,3> P3;

P3 operator-(P3 p){
  return P3{-p[0],-p[1],-p[2]};
}

P3 operator+(P3 a,P3 b){
  return P3{a[0]+b[0],a[1]+b[1],a[2]+b[2]};
}

P3 operator-(P3 a,P3 b){
  return a+-b;
}

P3 operator-=(P3 &a,P3 b){
  return a=a-b;
}
  
P3 operator*(P3 p,double d){
  return P3{p[0]*d,p[1]*d,p[2]*d};
}
  
P3 operator/(P3 p,double d){
  return p*(1/d);
}

double dot(P3 a,P3 b){
  return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
}

double abs(P3 p){
  return sqrt(dot(p,p));
}

P3 cross(P3 a,P3 b){
  return P3{a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]};
}
  
P3 Rodrigues(P3 r,P3 base,double phy){
  P3 n=base/abs(base);
  P3 nnr=n*dot(n,r);
  return nnr+(r-nnr)*cos(phy)+cross(n,r)*sin(phy);
}

P3 closest_to_origin(P3 a,P3 b){
  P3 x=a-b;
  return b+x*-dot(b,x)/dot(x,x);
}

vector<P3> intersection(P3 p,double r,P3 a,P3 b){
  a-=p;
  b-=p;
  P3 cp=closest_to_origin(a,b);
  double d=abs(cp);
  if(d>r){
    return {};
  }else{
    P3 x=a-b;
    double f=sqrt(r*r-d*d)/abs(x);
    return {cp+x*f+p,cp+x*-f+p};
  }
}


int main(){
  for(int N;cin>>N,N;){
    double u,v,w;
    cin>>u>>v>>w;
    P3 p[100];
    int r[100];
    for(int i=0;i<N;i++){
      double x,y,z;
      cin>>x>>y>>z>>r[i];
      p[i]=P3{x,y,z};
    }
    P3 f{0,0,0},t{u,v,w};
    for(;;){
      double d=1e99;
      P3 nf,nt;
      for(int i=0;i<N;i++){
	if(dot(t-f,p[i]-f)>0){
	  auto res=intersection(p[i],r[i],t,f);
	  for(auto e:res){
	    if(abs(e-f)<d){
	      d=abs(e-f);
	      nf=e;
	      nt=Rodrigues(f-nf,nf-p[i],2*acos(0))+nf;
	    }
	  }
	}
      }
      if(d>1e98)break;
      f=nf;
      t=nt;
    }
    for(int i=0;i<3;i++){
      cout.precision(9);
      cout<<fixed<<f[i]<<" \n"[i==2];
    }
  }
}
 

Measured memory_bytes: 1296
#include <iostream>

using namespace std;

int main(){
    int x, y, tmp;

    while(1){
        cin >> x;
        cin >> y;
        if(x == 0 && y == 0){
            break;
        }
        if(x > y){
            tmp = x;
            x = y;
            y = tmp;
        }
        cout << x << ' ' << y << endl;

    }
    



    return 0;
}


Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
vector<string>v;
void dfs(string str,string t="",int cnt=0){
    if(cnt==2){
        v.push_back(t);
        return;
    }else{
        for(int i=0;i<str.size();i++){
            dfs(str,t+str[i],cnt+1);
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        for(int i=0;i<str.length();i++){
            if(str[i]=='1')cout<<"9";
            else cout<<"1";
        }
        cout<<endl;
    }
    return 0;
}


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

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

  int N;
  cin >> N;
  
  int cakeMax = N / 4;
  int donutMax = N / 7;
  
  for(int i = 0; i <= cakeMax; i++){
    for(int j = 0; j <= donutMax; j++){
      int res = i*4 + j*7;
      if(res == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long

int main()
{
    int n;
    sfi(n)

    int arr[n];
    f(i,0,n)
        sfi(arr[i])

    int dp[n];

    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);

    f(i,2,n)
    {
        int val1=dp[i-1]+abs(arr[i]-arr[i-1]);
        int val2=dp[i-2]+abs(arr[i]-arr[i-2]);

        dp[i]=min(val1,val2);
    }

    pfin(dp[n-1])

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
using namespace std;

typedef long long ll;
using pi = pair<int, int>;

int main() {
  int N;
  cin >> N;
  int arr[4]={0};
  string in;
  while(N--) {
    cin >> in;
    if(in == "AC") arr[0]++;
    else if(in == "WA") arr[1]++;
    else if(in == "TLE") arr[2]++;
    else if(in == "RE") arr[3]++;
  }
  cout << "AC x " << arr[0] << endl;
  cout << "WA x " << arr[1] << endl;
  cout << "TLE x " << arr[2] << endl;
  cout << "RE x " << arr[3] << endl;
  return 0;
}


Measured memory_bytes: 3580
import Data.List

split' :: String	-> [Int]
split' s = map read [(fst . a) s , (tail . snd . a) s]
  where a s = splitAt (head $ elemIndices ',' s) s

conv :: Int -> Int -> [Int] -> [Int]
conv a b list = (take min' list) ++ (list !! max'):[] ++ (drop (min'+1) $ take max' list) ++ (list !! min'):[] ++ (drop (max'+1) list)
  where min' = min a b - 1
	max' = max a b - 1

solve :: [Int] -> [String] -> [Int]
solve ns [] = ns
solve ns (x:xs) = solve (conv (head $ split' x) (last $ split' x) ns) xs

main = getContents >>= mapM_ print . (\(x:_:xs) -> solve [1..read x] xs) . lines

Measured memory_bytes: 4068
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>

using namespace std;

#define N 200008

int n;
int a[N];
long long sum = 0;

void solve()
{
	long long first = a[1];
	long long minn = abs(sum-first-first);
	for (int i = 2; i < n; i++)
	{
		first += (long long)a[i];
		minn = min(minn,abs(sum-first-first));
	}
	printf("%lld\n", minn);
}

void init()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		sum += (long long)a[i];
	}
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int n;
    cin >> n;
    int cnt = 1;
    int len = 0;
    while (cnt <= n)
    {
        n -= cnt;
        cnt *= 26;
        ++len;
    }
    string res;
    for (int i = 0; i < len; ++i)
    {
        res += (char)(n % 26 + 'a');
        n /= 26;
    }
    reverse(res.B(), res.E());
    cout << res << endl;
}

Measured memory_bytes: 3652
n, m = map(int, input().split())
K = [list(map(int, input().split())) for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    flag = [False] * n
    for j in range(n):
        if (i >> j) & 1:
            flag[j] = True
    on = [False] * m
    for j in range(m):
        sw = 0
        for k in range(1, K[j][0] + 1):
            if flag[K[j][k] - 1]:
                sw += 1
        if sw % 2 == P[j]:
            on[j] = True
    if False not in on:
        ans += 1
print(ans)

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

int main() {
    long long int n,w,i,j;
    cin>>n;
    cin>>w;
    long long int a[n],wt[n],dp[n+1][w+1];
    for(i=0;i<n;i++){
        cin>>wt[i]>>a[i];
    }
    for(i=0;i<=n;i++){
        for(j=0;j<=w;j++){
            if(i==0||j==0){
                dp[i][j]=0;
            }
            else if(wt[i-1]<=j){
                dp[i][j]=max(dp[i-1][j-wt[i-1]]+a[i-1],dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w]<<endl;
	return 0;
}

Measured memory_bytes: 79104
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int taxi = b;
        int train = n*a;
        if (taxi < train)
        {
            System.out.println(taxi);
        }
        else {
            System.out.println(train);
        }
    }
}

Measured memory_bytes: 21844
import sys
from collections import Counter


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    bcs = [map(int, input().split()) for _ in range(q)]
    bs, cs = [list(i) for i in zip(*bcs)]
    cnter = Counter(a_list)
    s = sum(a_list)
    for i in range(q):
        m = cnter[bs[i]]
        cnter[bs[i]] = 0
        cnter[cs[i]] += m
        s += m * cs[i] - m * bs[i]
        print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 71996
x=int(input())
dp=[0]*(x+1)
dp[0]=1
for i in range(1,x+1):
  if i-100>=0:
    if dp[i-100]==1 or dp[i-101]==1 or dp[i-102]==1 or dp[i-103]==1 or dp[i-104]==1 or dp[i-105]==1:
      dp[i]=1
print(dp[x])


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cctype>
#include <stack>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long lolo;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef unsigned long long ulolo;

const int maxn = (int)1e3 + 5;
const int INF = 0x3f3f3f3f;
const lolo inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int MOD = (int)1e9 + 7;

template<class T>
inline void read(T &x) {
    x = 0; T flag = 1;char c;
    do { c = (char) getchar(); if (c == '-') break; } while (c < '0' || c > '9');
    if (c == '-') { c = '0', flag = -1;}
    do { x = x * 10 + c - '0';c = (char) getchar();} while (c >= '0' && c <= '9');
    x *= flag;
}
template<class T>
inline void out(T x) {
    if (x > 9) out(x / 10);
    x = x % 10;
    putchar('0' + x);
}
int main() {
//    freopen("../in.txt", "r", stdin);
    int n, K;
    int v[55];
    scanf("%d%d", &n, &K);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", v+i);

    }
    v[0] = v[n+1] = 0;
    multiset<int> S;
    int suml = 0, sumr = 0;
    for (int i = 0; i <= n; ++i) {
        if (i > K) {
            break;
        }
        if (i&&v[i]<0) {
            S.insert(v[i]);
        }
        suml += v[i];
        multiset<int> oldS = S;
        sumr = 0;
        for (int j = 0; j <= n-i; ++j) {
            if (i+j > K) {
                break;
            }
            if (j&&v[n-j+1]<0) {
                S.insert(v[n-j+1]);
            }
            sumr += v[n-j+1];
            int tmp = suml + sumr;
            int k = 0;
            for (multiset<int>::iterator it = S.begin(); it!=S.end()&&k < K-i-j; ++k, ++it) {
                tmp -= *it;
            }
            ans = max(tmp, ans);
        }
        S = oldS;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bitset>
#include<string.h>

using namespace std;

vector<int> ans;
const int max_dp = 1<<20;
int main(){
	while(true){
		int n,k,s;
		cin >> n >> k >> s;
		if(n == 0 && k == 0 && s == 0) break;
		
		int count = 0;
		for(int i = 0;i < (1<<n);i++){
			bitset<20> bs(i);
			int sum = 0;
			int used = 0;
			for(int j = 0;j < n;j++){
				if(bs[j]){
					sum += j+1;
					used++;
				}
			}
			if(used == k && sum == s) count++;
		}
		ans.push_back(count);
	}
	
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#ifndef LOCAL
#pragma GCC optimize("O2")
#endif
#include <iostream>
#include <vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
   long long int N; cin >> N;
    long long int score;score = __LONG_LONG_MAX__;
    for(int i=1; i<=(int)sqrt(N) + 1; i++)
    {
        if(N%i == 0)
        {
            //cout << score << "\n";
            score = min(i+N/i-2, score);
        }
    }

    cout << score ;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
ll n;
  cin>>n;
  ll h[n];
  for(ll i=0;i<n;i++){
  cin>>h[i];
  }
  ll count=1;
    for(ll i=1;i<n;i++){
      ll flag=1;
      for(ll j=0;j<i;j++){
      if(h[i]-h[j]<0){
        flag=0;
      }
      }
      if(flag==1){
        count++;
      }
  
  }
  cout<<count;
  return 0;
 
}
 


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n, m;
struct Edge {
    int to, cost;
};
vector<Edge> G[100010];
int score[100010];
const int INF = -1e16;
const int MAX = 1e16;

signed main() {
    cin >> n >> m;
    rep(i,0,m) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(Edge{b, c});
    }

    queue<pii> q;
    rep(i,1,n) score[i] = INF;
    q.push(pii(0, 0));
    set<pii> usededge;
    while(!q.empty()) {
        pii temp = q.front(); q.pop();
        int csc = temp.first, from = temp.second;

        for(auto e : G[from]) {
            if(score[e.to] < csc + e.cost) {
                if(score[e.to] == MAX) continue;
                if(usededge.count(pii(from, e.to))) score[e.to] = MAX;
                else score[e.to] = csc + e.cost;
                usededge.insert(pii(from, e.to));
                q.push(pii(score[e.to], e.to));
            }
        }
    }
    if(score[n-1] == MAX) cout << "inf" << endl;
    else cout << score[n-1] << endl;
    return 0;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    string s;
    cin >> s;
    if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI atan(1)*4
using namespace std;
int main(){
	io;
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	bool f = 1;
	while(k--){
		if(b > 2*a){
			a*= 2;
		}
		else{
			if(c > 2*b){
				b *= 2;
			}
			else{
				c *= 2;
			}
		}
	}
	if(a < b && b < c){
		cout << "Yes";
	}
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std ;
vector<pair<string,int>>lol;
map<pair<string,int>,int>aaa;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        string s;
        cin>>s>>x;
        lol.push_back({s,-x});
        aaa[{s,x}]=i+1;
    }
    sort(lol.begin(),lol.end());
    for(int i=0;i<n;i++)
    {
        cout<<aaa[{lol[i].first,-lol[i].second}]<<endl;
    }
}


Measured memory_bytes: 256
import bisect
x = int(input())
def primes(max_number):
    pr = list(range(3, max_number+1, 2))
    lpr = len(pr)
    for i,n in enumerate(pr):
        if n:
            if n*n > max_number:
                break
            for j in range(i+n, lpr, n):
                pr[j] = 0
    yield 2
    yield from[i for i in pr if i]

a = list(primes(101000))
bi = bisect.bisect(a, x)
if a[bi-1] == x:
    print(x)
else:
    print(a[bi])

Measured memory_bytes: 5108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, m;
    int ACnum=0, WAnum=0;
    vector<int> WA(100010);
    vector<bool> AC(100010);

    cin >> n >> m;

    for(int i=1; i<=n; i++){
        WA[i] = 0;
        AC[i] = false;
    }

    while(m--){
        int p;
        string s;
        cin >> p >> s;
        if(AC[p]) continue;
        if(s == "AC"){
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        }
        else{
            WA[p]++;
        }
    }
    out(ACnum);
    out(WAnum);
    
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n;
  cin>>n;
  cin.ignore();
  while(n--){
    string s,t,u;
    getline(cin,s);
    t = "Hoshino";
    u = "Hoshina";
    for(int i = 0 ; i < s.size() ; i ++){
      if(s.substr(i,t.size()) == t){
	cout<<u;
	i+= t.size() - 1 ;
      }else{
	cout<<s[i];
      }
    }
    cout<<endl;
  }

}

Measured memory_bytes: 1212
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll dp[2001][2001];
int main(){
	int N;
	ll x,a[2001];
	scan(N>>x);
	rep(i,N){
		scan(a[i]);
	}
	rep(i,N) rep(j,N) dp[i][j]=INFl;
	rep(i,N) dp[i][0]=a[i];
	rep(i,N){
		rep(j,N){
			dp[i][j+1]=min(dp[i][j],a[(i-j-1+N)%N]);
		}
	}
	ll ans=INFl;
	rep(j,N){
		ll sum=x*j;
		rep(i,N) sum+=dp[i][j];
		ans=min(ans,sum);
	}
	prin(ans);
	return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

	int N;
    cin >> N;
    vector<int> A(1 << N);
    FOR(i, 0, 1 << N) {
        cin >> A[i];
    }

    vector<vector<priority_queue<int, vector<int>, greater<int>>>> K(N + 1, vector<priority_queue<int, vector<int>, greater<int>>>(A.size()));

    FOR(i, 0, A.size()) {
        K[0][i].push(A[i]);
        K[0][i].push(0);
    }
    FOR(i, 0, K.size() - 1) {
        FOR(j, 0, K[0].size()) {
            int a = K[i][j].top(); K[i][j].pop();
            int b = K[i][j].top(); K[i][j].pop();

            K[i + 1][j].push(a);
            K[i + 1][j].push(b);
            while (K[i + 1][j].size() > 2) {
                K[i + 1][j].pop();
            }

            int r = 1 << i;
            if (j % (1 << (i + 1)) < (1 << i)) {
                if (j + r < K[0].size()) {
                    K[i + 1][j + r].push(a);
                    K[i + 1][j + r].push(b);
                    while (K[i + 1][j + r].size() > 2) {
                        K[i + 1][j + r].pop();
                    }
                }
            }
        }
    }

    LL maxi = 0;
    FOR(j, 1, K[0].size()) {
        LL a = K[K.size() - 1][j].top(); K[K.size() - 1][j].pop();
        LL b = K[K.size() - 1][j].top(); K[K.size() - 1][j].pop();
        maxi = max(maxi, a + b);
        print(maxi);
    }

	return 0;
}

Measured memory_bytes: 315516
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		StringBuilder strBul = new StringBuilder(str).reverse();
		String[] ar = strBul.toString().split("");
		int mod = 2019;
		int[] a_array = new int[str.length()];
		int[] ruiseki = new int[str.length()+1];
		int[] ten_mod = new int[str.length()];
		ten_mod[0] = 1;
 		for(int i=1;i<str.length();i++) {
 			ten_mod[i]=ten_mod[i-1]*10%mod;
		}
 		for(int i=0;i<str.length();i++) {
 			a_array[i] = Integer.parseInt(ar[i])*ten_mod[i]%mod;
		}
 		for(int i=0;i<str.length();i++) {
 			ruiseki[i+1] = (a_array[i]+ruiseki[i])%mod;
		}
 		int[] cnts= new int[2019];
 		for(int i=1;i<str.length()+1;i++) {
// 			System.out.println(ruiseki[i]);
 			cnts[ruiseki[i]]++;
 		}
 		long ans=0;
 		for(int i=0;i<2019;i++) {
 			if (cnts[i]>1) {
 				ans+=cnts[i]*(cnts[i]-1)/2;
 			}
 		}
 		ans += cnts[0];
 		System.out.println(ans);
	}

}


Measured memory_bytes: 67304
#include <iostream>
using namespace std;
int main(){
    int a,b,t;
    while(1){
        cin>>a>>b;
        if(a==0){
            if(b==0){
                break;
            }
        }
        if(a>b){
            t=a;
            a=b;
            b=t;
        }
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}


Measured memory_bytes: 3052
pt = raw_input()
g = p = 0
score = 0
for c in pt:
    t = "g"
    if g > p:
        t = "p"
    if t == "p": p += 1
    if t == "g": g += 1
    if c == "g" and t == "p": score += 1
    if c == "p" and t == "g": score -= 1

print score


Measured memory_bytes: 2692
# AOJ 0614: Railroad Trip
# Python3 2018.7.4 bal4u

import sys
from sys import stdin
input = stdin.readline

n, m = map(int, input().split())
p = list(map(int, input().split()))
tbl = []
for i in range(n-1):
	a, b, c = map(int, input().split())
	tbl.append((a, b, c))
f = [0]*n
for i in range(m-1):
	u, v = p[i]-1, p[i+1]-1
	if u > v: u, v = v, u
	f[u] += 1
	f[v] -= 1
for i in range(n-1): f[i+1] += f[i]
ans = 0
for i in range(n-1):
	cash = tbl[i][0] * f[i]
	ic = tbl[i][1] * f[i] + tbl[i][2]
	ans += min(cash, ic)
print(ans)


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

long long gcd(long long a, long long b) {
    if (a%b==0) return b;
    else return gcd(b, a%b);
}

long long lcm(long long a, long long b) {
    return a*b / gcd(a,b);
}

int main() {
    long long A,B;
    cin >> A >> B;
    cout << lcm(A,B) << endl;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long 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 INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int x, a, b; cin >> x >> a >> b;
    int dista = abs(x-a);
    int distb = abs(x-b);
    if(dista < distb) cout << "A" << endl;
    else cout << "B" << endl;

    return 0;
}


Measured memory_bytes: 256
A,B,C,D = map(int,input().split(" "))
Takahasi = [A,B]
Aoki = [C,D]
while(1):
    Aoki[0]-=Takahasi[1]
    if Aoki[0]<=0:
        print("Yes")
        break
    Takahasi[0]-=Aoki[1]
    if Takahasi[0]<=0:
        print("No")
        break

Measured memory_bytes: 9184