akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

        int k = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();

        long ans = 1;
        long money = 0;
        if(a + 2 < b){
            for(int i = k; 0 < i; i--){
                if(1 <= money){
                    ans += b;
                    money--;
                }else{
                    if(1 < i){
                        if(ans >= a){
                            ans -= a;
                            money++;
                        }else{
                            ans++;
                        }
                    }else{
                        ans++;
                    }
                }
            }
        }else{
            ans += k;
        }
        System.out.println(ans);

    }
}


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

using namespace std;

int main() {
    int n ; cin >> n;
    vector<int>p(n);
    for(int& i : p)cin >> i;
    int sum = accumulate(p.begin() , p.end() , 0);
    int m ; cin >> m; 
    for(int i = 0 ; i < m; ++i){
        int x , v; cin >> x >> v;
        cout << sum - p[x -1] + v << endl;
    }
    
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

void Init();
int Root(int x);
bool Unite(int x, int y);

int root[SIZE];

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

    int n, q;
    cin >> n >> q;
    Init();

    while( q-- ) {
        int seq, x, y;
        cin >> seq >> x >> y;
        if( seq == 0 ) {
            Unite(x, y);

        } else {
            if( Root(x) == Root(y) ) {
                cout << 1;

            } else {
                cout << 0;

            }
            cout << endl;

        }
    }
    return 0;
}

void Init() {
    for( int i = 0; i <= 100005; ++i ) {
        root[i] = i;

    }

    return;
}

int Root(int x) {
    if( x == root[x] ) return x;
    return root[x] = Root(root[x]);

}

bool Unite(int x, int y) {
    int rx, ry;
    rx = Root(x);
    ry = Root(y);

    if( rx == ry ) return false;

    if( rx < ry ) {
        root[ry] = rx;

    } else {
        root[rx] = ry;

    }

    return true;
}




Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  int N,Q,sum=0;
  cin >> N;
  vector<int>vec(N),V(100005,0);
  for(int i=0; i<N; i++){
	  cin >> vec[i];
	  sum += vec[i];
	  V[vec[i]]++;
  }
  cin >> Q;
  for(int i=0; i<Q; i++){
	  int a,b;
	  cin >> a >> b;
	  sum = sum-((a-b)*V[a]);
      cout << sum << endl;
      V[b] += V[a];
      V[a] = 0;
  }
}


Measured memory_bytes: 4844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a + b >= 10) {
            System.out.println("error");
        } else {
            System.out.println(a + b);
        }
    }
}


Measured memory_bytes: 23636
#include<cstdio>
#include<vector>

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

using namespace std;

typedef	vector<int>	vi;

int main(){
	const int Ne=10010;
	static bool er[Ne]; er[0]=er[1]=true;
	for(int i=2;i*i<Ne;i++) if(!er[i]) for(int j=i*i;j<Ne;j+=i) er[j]=true;
	vi p; rep(i,Ne) if(!er[i]) p.pb(i);

	for(int n;scanf("%d",&n),n;){
		int cnt=0;
		rep(i,p.size()){
			if(p[i]>n)	break;
			int sum=0;
			for(int j=i;;j++){
				sum+=p[j];
				if(sum>=n)	break;
			}
			if(sum==n)	cnt++;
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <iomanip>
#include"stdio.h"
#include <cstring>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include"time.h"
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
template<class T>inline void read(T &res){
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
ll mod=1e9+7;
int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n;i++){
        ans+=n*i-i*i+i+1;
        ans%=mod;
    }
    ans++;ans%=mod;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
#define R register
int main()
{
    ll x,a,b,c,ans=0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(R int i=0;i<=a;i++)
        for(R int j=0;j<=b;j++)
            for(R int z=0;z<=c;z++)
            {
                int k=i*500+j*100+z*50;
                if(k==x)ans++;
                if(k>x)break;
            }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <regex>
#include <sstream>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr int INF = 1e9 + 10;
constexpr ll INFL = 1e18 + 10;

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

struct edge
{
public:
    int to;
    int cost;
};

// O(|E|(log|V|))
void dijkstra(std::vector<int> &dist, const std::vector<std::vector<edge>> &graph, int s)
{
    typedef std::pair<int, int> P;
    std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
    for (auto &e : dist)
    {
        e = INF;
    }

    dist[s] = 0;
    // P(distance from start, vertex index)
    pq.push(P(0, s));
    while (!pq.empty())
    {
        P cur = pq.top();
        pq.pop();
        int v = cur.second;
        int cost = cur.first;
        if (dist[v] < cost)
        {
            continue;
        }
        for (const auto &next : graph[v])
        {
            if (dist[next.to] > next.cost + dist[v])
            {
                dist[next.to] = next.cost + dist[v];
                pq.push(P(dist[next.to], next.to));
            }
        }
    }
}

void restorePath(
    std::vector<int> &path,
    const std::vector<int> &dist,
    const std::vector<std::vector<edge>> &graph,
    int e)
{
    int cur = e;
    path.push_back(e);
    while (dist[cur] != 0)
    {
        for (const auto &n : graph[cur])
        {
            if (dist[n.to] + n.cost == dist[cur])
            {
                path.push_back(n.to);
                cur = n.to;
                break;
            }
        }
    }
    std::reverse(path.begin(), path.end());
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

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

    ll a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b){
        cout << "Zero" << "\n";
        return 0;
    }
    if (0 < a && 0 < b){
        cout << "Positive" << "\n";
        return 0;
    }
    if ((b - a + 1) % 2 == 0){
        cout << "Positive"
             << "\n";
        return 0;
    }
    cout << "Negative"
         << "\n";

    return 0;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;

    switch( N%10 ){
       case 2:
       case 4:
       case 5:
       case 7:
       case 9:
          cout << "hon" << endl;
          break;
       case 0:
       case 1:
       case 6:
       case 8:
          cout << "pon" << endl;
          break;
       case 3:
          cout << "bon" << endl;
          break;
    }
}


Measured memory_bytes: 3604
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;

int main(){

             long long int i,n,k=0;
             cin>>n;

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

                if(i%3==0||i%5==0||i%15==0){

                    ;
                }
                else{
                    k=k+i;
                }


             }
             cout<<k;


}


Measured memory_bytes: 3632
A,B,C=map(int,input().split())
x=A*7+B
y=C//(A*7+B)
z=x*y
w=C-z

if (A*7)<w<x:
    print((y+1)*7)
else:
    coin=0
    day=0
    while coin<w:
        coin+=A
        day+=1
    print(y*7+day)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
int main(){
    int n;
    cin>>n;
    for(int i=0;i*4<=n;i++){
        for(int j=0;j*7<=n;j++){
            if(i*4+j*7==n){
                cout<<"Yes"<<endl;return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] cnt = new int[N];
		for(int i=0; i<M*2; i++) {
			cnt[sc.nextInt()-1]++;
		}
		
		boolean ok = true;
		for(int i=0; i<N; i++) {
			if(cnt[i]%2!=0) {
				ok = false;
				break;
			}
		}
		
		System.out.println(ok ? "YES" : "NO");
		
		sc.close();
	}
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

ll a, b;


void solve() {

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	solve();
	cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
	int a, b;
	cin >> a >> b;
	if (a > 100 || a < 2 || b>100 || b < 2) {
		return 0;
	}
	cout << (a - 1)*(b - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,w,h;
  while(scanf("%d %d",&h,&w)){
    if ((h==0) && (w==0))
      break;
    char Tiles[h][w];
    int data[h][w];
    for (i=0;i<h;i++)
      for (j=0;j<w;j++){
        scanf(" %c",&Tiles[i][j]);
        data[i][j]=0;
      }
    int x=0,y=0,cnt=0;
    while(cnt<h*w){
      if (data[y][x]==1){
        printf("LOOP\n");
        break;
      }
      switch(Tiles[y][x]){
      case '>':data[y][x++]++;break;
      case '<':data[y][x--]++;break;
      case '^':data[y--][x]++;break;
      case 'v':data[y++][x]++;break;
      case '.':printf("%d %d\n",x,y);cnt=h*w;break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 660
function main(input) {
   input = input.trim();
  const a = input.split(" ").map(Number);
 console.log(Math.abs(a[2]-a[0])<=a[3]
		|| (Math.abs(a[1]-a[0])<=a[3] && Math.abs(a[1]-a[2])<=a[3])?"Yes":"No");

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

char s[2100000], t[2100000];
int len;

long long calc(int &en)
{
    if (t[en] == '>'){
        en--;
        long long l = calc(en);
        l = (l * l) % 1000000007;
        en -= 2;
        if (en < 0 || t[en] == '<') return (l);
        en -= 2;
        
        long long l2 = calc(en);
        while (l-- && l2){
            l2 /= 2;
        }
        return (l2);
    }
    else {
        long long l = 0, b = 1;
        while (isdigit(t[en])){
            l = l + (t[en--] - '0') * b;
            b *= 10;
        }
        
        if (en < 0 || t[en] == '<') return (l);
        en -= 2;
        
        long long l2 = calc(en);
        while (l-- && l2){
            l2 /= 2;
        }
        
        return (l2);
    }
}

int main()
{
    while (fgets(s, sizeof(s), stdin) && s[0] != '#'){
        len = 0;
        for (int i = 0; s[i]; i++){
            if (s[i] != ' ' && s[i] != '\n') t[len++] = s[i];
        }
        
        --len;
        printf("%lld\n", calc(len));
    }
    
    return (0);
}

Measured memory_bytes: 4300
string=str(input())
swich1=0
swich2=0
final_swich=0
for i in range(len(string)):
    if string[i]=='C':
        swich1=1
    elif swich1==1 and string[i]=='F':
        swich2=1
        print("Yes")
        final_swich=1
        break
if final_swich==0:
    print("No")

Measured memory_bytes: 3060
import sys

n=int(input())
c=input()
black=c.count("#")
white=c.count(".")

if black==n:
  print(0)
  sys.exit()

b=0
w=0
now=0
ans=float('inf')

for i in range(n):
  if c[i]=="#":
    b+=1
  w=(i+1)-b

  now=b+(white-w)
  ans=min(ans,now)
  
print(min(ans,white))

Measured memory_bytes: 9508
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = list(map(int, readline().split()))
    print(a*b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61640
def isPrime( x )
	return true if 2 == x
	
	for i in ( 2 .. x )
		break if x < i*i 
		return false if 0 == x%i
	end
	
	return true
end

n = gets.to_i
nums = []
n.times {
	nums.push( gets.to_i )
}

cnt = 0
for i in ( 0 ... nums.length )
	if isPrime( nums[i] )
		cnt += 1
	end
	i += 1
end
puts( cnt )

Measured memory_bytes: 6176
using System;

namespace Android{
  class Solver{
    static void Main(){
      int[] array=new int[6];
      for(int i=0;i<6;i++){
        array[i]=int.Parse(Console.ReadLine());
      }
      
      if(array[4]-array[0]<=array[5])Console.WriteLine("Yay!");
      else Console.WriteLine(":(");
      }
    }
  }

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)  	
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
const double pi = acos(-1.0);
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
ll read()     //输入外挂
{
    ll res = 0, ch, flag = 0;
    if ((ch = getchar()) == '-')
        flag = 1;
    else if (ch >= '0' && ch <= '9')
        res = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9')
        res = res * 10 + ch - '0';
    return flag ? -res : res;
}
ll a[maxn];
bool cmp(ll aa, ll b) {
    return aa > b;
}
int main() {
    ll n, ans = 0;
    cin >> n;
    ll m = n;
    while (m) {
        ans++;
        m /= 2;
    }
    ll res = pow(2, ans) - 1;
    printf("%lld\n", res);
}

Measured memory_bytes: 384
#include<stdio.h>

int num_a, num_b;
int integral_value, remainder_value;
double floating_value, floating_a, floating_b;

int main() {
	scanf("%d %d", &num_a, &num_b);
	remainder_value = num_a % num_b;
	integral_value = (num_a - remainder_value) / num_b;

	floating_a = num_a;
	floating_b = num_b;
	floating_value = floating_a / floating_b;

	printf("%d %d %lf\n", integral_value, remainder_value, floating_value);

	return 0;
}


Measured memory_bytes: 2068
s = input()
lens = len(s)
ans = [1]*len(s)
for i in range(lens-2):
  if s[i] == 'R' and s[i+1] == 'R':
    ans[i+2] += ans[i]
    ans[i] = 0
  if s[-(i+1)] == 'L' and s[-(i+2)] == 'L':
    ans[-(i+3)] += ans[-(i+1)]
    ans[-(i+1)] = 0
print(*ans)

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

    ll N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];

    ll m = N/2;
    ll k = (N % 2) ? 3 : 2;
    vll dp(k, 0);

    rep(i, m) for(ll j = k-1; j >= 0; j--) dp[j] = *max_element(dp.begin(), dp.begin()+j+1) + A[2*i+j];
    cout << *max_element(dp.begin(), dp.end()) << endl;
}


Measured memory_bytes: 4788
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

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    nodedict = {}

    preorder_list = []

    class Node:
        def __init__(self, id):
            self.id = id
            self.childlist = []
            self.p = 0
            self.walked = False

        def __repr__(self):
            return str(self.__dict__)

        def preorder(self, p):
            if self.walked:
                return 0

            self.p = self.p + p

            self.walked = True
            preorder_list.append(self.id)

            for child in self.childlist:
                child.preorder(self.p)

            return 0


    N, Q = LI()

    for i in range(1, N+1):
        nodedict[i] = Node(i)

    for i in range(N-1):
        a, b = LI()
        nodedict[a].childlist.append(nodedict[b])

    for i in range(Q):
        p, x = LI()
        nodedict[p].p += x

    # preorder
    nodedict[1].preorder(0)

    dprint(preorder_list)
    print(' '.join([str(nodedict[i].p) for i in range(1, N+1)]))

solve()

Measured memory_bytes: 327708
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[10010];string s;ll l;double d;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	double nextDouble(){scanf("%lf", &d);return d;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

int main(){
	while(1){
		int r = in.nextInt(), n = in.nextInt();
		if(r == 0 && n == 0) break;
		map<int, int> mpl, mpr;
		mpr[-r] = INF;
		mpl[r] = INF;
		for(int i = 0; i < n; i++){
			int x1 = in.nextInt(), x2 = in.nextInt(), h = in.nextInt();
			for(int x = x1; x < x2; x++){
				mpl[x] = max(mpl[x], h);
			}
			for(int x = x1+1; x <= x2; x++){
				mpr[x] = max(mpr[x], h);
			}
		}
		double ans = 1e18;
		for(int x = -r; x <= r; x++){
			double y = -r + sqrt(r*r-x*x);
			double dl = -y + mpl[x];
			double dr = -y + mpr[x];
			ans = min({ans, dl, dr});
		}
		printf("%.15lf\n", ans);
	}
}

Measured memory_bytes: 3188
#include<stdio.h>

int main(){
  int i,j,k,N,K;
  
  scanf("%d %d",&N,&K);
  int A[N];
  for(i=0;i<N;i++)
    scanf("%d ",&A[i]);
  int tmp;
   for (i=0; i<N; ++i) {
    for (j=i+1; j<N; ++j) {
      if (A[i] < A[j]) {
        tmp =  A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }

  k=0;
  for(i=0;i<K;i++)
    k+=A[i];
  
  printf("%d\n",k);
  return 0;
}

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

int main() {
	ll a,b,c;
	cin >> a >> b >> c;
	if(c-a-b>0 && 4ll*a*b<(c-a-b)*(c-a-b))
		cout << "Yes";
	else
		cout << "No";
	cout << endl;
}

Measured memory_bytes: 256
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string s;
int main() {
	while (cin >> n, n) {
		vector<string> l; vector<string> x(n); vector<vector<string> > g(n);
		for (int i = 0; i < n; i++) {
			cin >> s;
			int p = 0;
			for (int j = 1; j < s.size(); j++) {
				if (s[j] == ':' || s[j] == ',' || s[j] == '.') {
					string t = s.substr(p, j - p);
					if (p == 0) x[i] = t;
					else g[i].push_back(t);
					l.push_back(t);
					p = j + 1;
				}
			}
		}
		sort(l.begin(), l.end());
		l.erase(unique(l.begin(), l.end()), l.end());
		vector<vector<int> > G(l.size());
		for (int i = 0; i < n; i++) {
			int s = lower_bound(l.begin(), l.end(), x[i]) - l.begin();
			for (string j : g[i]) {
				int ptr = lower_bound(l.begin(), l.end(), j) - l.begin();
				G[s].push_back(ptr);
			}
		}
		int r = lower_bound(l.begin(), l.end(), x[0]) - l.begin();
		vector<bool> vis(l.size(), false); vis[r] = true;
		queue<int> que; que.push(r);
		while (!que.empty()) {
			int u = que.front(); que.pop();
			for (int i : G[u]) {
				if (!vis[i]) {
					vis[i] = true;
					que.push(i);
				}
			}
		}
		int ret = 0;
		for (int i = 0; i < l.size(); i++) {
			if (vis[i] && G[i].size() == 0) ret++;
		}
		cout << ret << endl;
	}
	return 0;
}

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

int n, m;
vector<set<int>> c, p;

int main(){
    cin >> n >> m;
    c.resize(n);
    p.resize(n);
    rep(i, n + m - 1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        c[a].insert(b);
        p[b].insert(a);
    }
    int s;
    rep(i, n){
        if (p[i].empty()){
            s = i;
            p[i].insert(-1);
            break ;
        }
    }
    queue<int> que;
    que.push(s);
    while (!que.empty()){
        int x = que.front();
        que.pop();
        for (auto nx : c[x]){
            if (p[nx].size() == 1)
                que.push(nx);
            else p[nx].erase(x);
        }
    }
    rep(i, n){
        cout << *p[i].begin() + 1 << endl;
    }
}

Measured memory_bytes: 22544
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    if (b >= a) cout << a << endl;
    else cout << a-1 << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    vector<string> S(3);
    rep(i, 3) cin >> S.at(i);

    int cnt = 0;
    rep(i, N) {
        char a = S.at(0).at(i);
        char b = S.at(1).at(i);
        char c = S.at(2).at(i);
        if(a == b && b != c) {
            cnt++;
        } else if(a != b && b == c) {
            cnt++;
        } else if(a == c && b != c) {
            cnt++;
        } else if(a != b && b != c) {
            cnt += 2;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  string s;
  cin >> s;
  int n = sz(s);
  vector<int> l(n+1,0), r(n+1,0);
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') l[i+1] = l[i] + 1;
    else l[i+1] = 0;

    if (s[n-i-1] == '>') r[n-i-1] = r[n-i] + 1;
    else r[n-i-1] = 0;
  }
  ll res = 0;
  for (int i = 0; i < n+1; i++) res += max(l[i], r[i]);
  cout << res << endl;
  return 0;
} 

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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> P(N), Q(N + 1);
  for (long i = 0; i < N; i++) cin >> P.at(i);
  for (long i = 1; i <= N; i++) Q.at(i) = Q.at(i - 1) + P.at(i - 1) + 1;
  long ans = 0;
  for (int i = 0; i + K <= N; i++) {
    ans = max(ans, Q.at(i + K) - Q.at(i));
  }
  cout << fixed << setprecision(6) << (double) ans / 2 << "\n";
}

Measured memory_bytes: 3328
n = gets.to_i
a = gets.split.map(&:to_i)
n.times do |i|
  i.downto(1) do |j|
    if a[j] < a[j - 1]
      a[j - 1], a[j] = a[j], a[j - 1]
    else
      break
    end
  end
  puts a * " "
end


Measured memory_bytes: 8932
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int A, B, Q;
	cin >> A >> B >> Q;

	vector<ll> v(A);
	rep(i, A) cin >> v[i];

	vector<ll> w(B);
	rep(i, B) cin >> w[i];

	rep(i, Q){
		ll x;
		cin >> x;

		ll ans = 1LL << 62;

		// 右神社　→　右寺
		if(x <= v[A-1]){
			ll t = 0;
			auto it = lower_bound(v.begin(), v.end(), x);
			t += abs(*it - x);
			if(*it <= w[B-1]){
				auto it2 = lower_bound(w.begin(), w.end(), *it);
				t += abs(*it2 - *it);
				ans = min(ans, t);
			}
		}

		// 右神社　→　左寺
		if(x <= v[A-1]){
			ll t = 0;
			auto it = lower_bound(v.begin(), v.end(), x);
			t += abs(*it - x);
			if(*it >= w[0]){
				auto it2 = lower_bound(w.begin(), w.end(), *it);
				t += abs(*(it2-1) - *it);
				ans = min(ans, t);
			}
		}

		// 左神社　→　右寺
		if(x >= v[0]){
			ll t = 0;
			auto it = lower_bound(v.begin(), v.end(), x);
			it--;
			t += abs(*it - x);
			if(*it <= w[B-1]){
				auto it2 = lower_bound(w.begin(), w.end(), *it);
				t += abs(*it2 - *it);
				ans = min(ans, t);
			}
		}

		// 左神社　→　左寺
		if(x >= v[0]){
			ll t = 0;
			auto it = lower_bound(v.begin(), v.end(), x);
			it--;
			t += abs(*it - x);
			if(*it >= w[0]){
				auto it2 = lower_bound(w.begin(), w.end(), *it);
				it2--;
				t += abs(*it2 - *it);
				ans = min(ans, t);
			}
		}

		// 右寺　→　右神社
		if(x <= w[B-1]){
			ll t = 0;
			auto it = lower_bound(w.begin(), w.end(), x);
			t += abs(*it - x);
			if(*it <= v[A-1]){
				auto it2 = lower_bound(v.begin(), v.end(), *it);
				t += abs(*it2 - *it);
				ans = min(ans, t);
			}
		}

		// 右寺　→　左神社
		if(x <= w[B-1]){
			ll t = 0;
			auto it = lower_bound(w.begin(), w.end(), x);
			t += abs(*it - x);
			if(*it >= v[0]){
				auto it2 = lower_bound(v.begin(), v.end(), *it);
				t += abs(*(it2-1) - *it);
				ans = min(ans, t);
			}
		}

		// 左寺　→　右神社
		if(x >= w[0]){
			ll t = 0;
			auto it = lower_bound(w.begin(), w.end(), x);
			it--;
			t += abs(*it - x);
			if(*it <= v[A-1]){
				auto it2 = lower_bound(v.begin(), v.end(), *it);
				t += abs(*it2 - *it);
				ans = min(ans, t);
			}
		}

		// 左寺　→　左神社
		if(x >= w[0]){
			ll t = 0;
			auto it = lower_bound(w.begin(), w.end(), x);
			it--;
			t += abs(*it - x);
			if(*it >= v[0]){
				auto it2 = lower_bound(v.begin(), v.end(), *it);
				it2--;
				t += abs(*it2 - *it);
				ans = min(ans, t);
			}
		}

		cout << ans << endl;
	}
}


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

int main(){
  int N;
  cin >> N;
  set<string> S;
  rep(i,N){
    string t;
    cin >> t;
    if(!S.count(t)){
      S.insert(t);
    }
  }
  cout << S.size() << endl;
}


Measured memory_bytes: 19208
// ARC095B.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5 + 200;

int n;
pair<int, int> ai[MAX_N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i].first), ai[i].second = ai[i].first;
    sort(ai + 1, ai + 1 + n);
    for (int i = 1;i < n; i++)
        if (ai[i].first > (ai[n].first >> 1))
            ai[i].first = ai[n].first - ai[i].first;
    sort(ai + 1, ai + 1 + n);
    printf("%d %d\n", ai[n].second, ai[n - 1].second);
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int n,m;
  
  cin >> n >> m;

  cout << (n-1)*(m-1)<< endl;

 return 0;
}

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

int main(){
  string s;
  int k;
  cin >> k >> s;

  if(s.size()>k){
    rep(i, k)cout << s[i];
    cout << "...";
  }else{
    cout << s;
  }
    
  return 0;
}


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

using namespace std;
using ll = long long;

ll solve(vector<vector<ll>> &v, int i, int j, vector<vector<ll>> &memo) {
  if (i == v.size()) {
    return 1;
  }

  if (j >= v[i].size()) {
    return 0;
  }

  if (memo[i][j] == -1) {
    ll ans = solve(v, i, j + 1, memo);

    if (i + 1 < v.size()) {
      auto it = upper_bound(v[i + 1].begin(), v[i + 1].end(), v[i][j]);
      ans += solve(v, i + 1, distance(v[i + 1].begin(), it), memo);
    } else {
      ans++;
    }

    memo[i][j] = ans;
  }

  return memo[i][j];
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<ll> va(n), vb(n), vc(n);
  for (int i = 0; i < n; ++i) cin >> va[i];
  for (int i = 0; i < n; ++i) cin >> vb[i];
  for (int i = 0; i < n; ++i) cin >> vc[i];

  sort(va.begin(), va.end());
  sort(vb.begin(), vb.end());
  sort(vc.begin(), vc.end());

  vector<vector<ll>> memo(5, vector<ll>(n + 10, -1));
  vector<vector<ll>> v{va, vb, vc};
  cout << solve(v, 0, 0, memo) << '\n';

  return 0;
}

Measured memory_bytes: 32664
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

        }

        public void Solve(ConsoleInput cin)
        {
            var In = cin.Read;


            WriteLine(In.Replace("2017","2018"));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint H, W, A, B; cin >> H >> W >> A >> B;
    range(i, 0, H - B) {
        range(_, 0, A) cout << 1;
        range(_, 0, W - A) cout << 0;
        cout << "\n";
    }
    range(i, 0, B) {
        range(_, 0, A) cout << 0;
        range(_, 0, W - A) cout << 1;
        cout << "\n";
    }
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 1000000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m, q;
    scanf("%d %d %d", &n, &m, &q);
    char a[n][m];
    rep(i, 0, n)
        rep(j, 0, m)
            scanf(" %c", &a[i][j]);
    int cnt[n + 1][m + 1];
    rep(i, 0, n)
    	rep(j, 0, m)
    		cnt[i][j] = 0;
    rep(i, 0, n)
    	rep(j, 0, m)
    		cnt[i][j] = (a[i][j] - '0');
    rep(i, 0, n)
    	rep(j, 1, m)
    		cnt[i][j] += cnt[i][j - 1];
    rep(i, 1, n)
    	rep(j, 0, m)
    		cnt[i][j] += cnt[i - 1][j];
    int hor[n][m], ver[n - 1][m + 1];
    rep(i, 0, n)
    {
        hor[i][0] = 0;
        rep(j, 1, m)
            hor[i][j] = hor[i][j - 1] + (a[i][j - 1] == a[i][j] && a[i][j] == '1');
    }
    rep(i, 1, n)
    	rep(j, 0, m)
    		hor[i][j] += hor[i - 1][j];
    rep(i, 0, n - 1)
    {
        ver[i][0] = 0;
        rep(j, 0, m)
            ver[i][j + 1] = ver[i][j] + (a[i][j] == a[i + 1][j] && a[i][j] == '1');
    }
    rep(i, 1, n - 1)
    	rep(j, 0, m + 1)
    		ver[i][j] += ver[i - 1][j];
    rep(query, 0, q)
    {
        int x1, y1, x2, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        x1--; y1--; x2--; y2--;
        int V = 0;
        V += cnt[x2][y2];
        if (x1 > 0)
        	V -= cnt[x1 - 1][y2];
        if (y1 > 0)
        	V -= cnt[x2][y1 - 1];
        if (x1 > 0 && y1 > 0)
        	V += cnt[x1 - 1][y1 - 1];
        int E = 0;
        E += (hor[x2][y2] - hor[x2][y1]);
        if (x1 > 0)
        	E -= (hor[x1 - 1][y2] - hor[x1 - 1][y1]);
        if (x2 > 0)
        	E += (ver[x2 - 1][y2 + 1] - ver[x2 - 1][y1]);
        if (x1 > 0)
        	E -= (ver[x1 - 1][y2 + 1] - ver[x1 - 1][y1]);
        printf("%d\n", V - E);
    }
    return 0;
}

Measured memory_bytes: 52608
#include<cstdio>
#include<algorithm>
#include<cstring> 
#define LL long long
using namespace std;
int n, x;
long long f[1000][1000];
bool b[1000][1000];
int main() {
	scanf("%d", &n);
	LL ans = 0;
	//memset(f, 0x3f3f, sizeof(f));
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			scanf("%d", &x);
			//e[++tot] = edge(i, j, x);
			f[i][j] = x;
			ans += x;
		}
	}
	for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++) 
				if(i != j && j != k && i != k) {
					if(f[i][j] == f[i][k] + f[k][j]) b[i][j] = 1;
					if(f[i][j] > f[i][k] + f[k][j]) {
					//	printf("%d %d %d\n", i, j, k);
						printf("-1");
						return 0;
					}
				}
	ans = 0;
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= n; j++) if(i < j && !b[i][j]) ans += f[i][j]; 
	printf("%lld\n", ans);
} 

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	double N=0,x=0,y=0,b=0,p=0,sum1=0;
	scanf("%lf",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%lf %lf %lf %lf",&x,&y,&b,&p);
		sum1=x*b+y*p;
		if(b>=5&&p>=2){printf("%.0lf\n",(x*b+y*p)*0.8);}
		else
		{
			if(b<5&&p<2){if(sum1>(x*5+y*2)*0.8){sum1=(x*5+y*2)*0.8;}}
			else{ 
				if(b<5&&p>=2){if(sum1>(x*5+y*p)*0.8){sum1=(x*5+y*p)*0.8;}}
			if(p<2&&b>=5){if(sum1>(x*b+y*2)*0.8){sum1=(x*b+y*2)*0.8;}}}
			printf("%.0lf\n",sum1);
		}
	}
	return 0;
}


Measured memory_bytes: 3232
def pop_count(n):
    return bin(n).count("1")


def f(n):
    if n == 0:
        return 0
    return f(n % pop_count(n)) + 1


N = int(input())
X = list(map(int, input()))
X_m = 0
X_p = 0
pop_X = X.count(1)
for i in range(N):
    if X[i] == 0:
        continue
    X_p += pow(2, N - i - 1, pop_X + 1)
    X_p %= pop_X + 1
    if pop_X > 1:
        X_m += pow(2, N - i - 1, pop_X - 1)
        X_m %= pop_X - 1

for i in range(N):
    ans = 1
    if X[i] == 0:
        ans += f((X_p + pow(2, N - i - 1, pop_X + 1)) % (pop_X + 1))
    elif pop_X > 1:
        ans += f((X_m - pow(2, N - i - 1, pop_X - 1)) % (pop_X - 1))
    else:
        ans = 0
    print(ans)


Measured memory_bytes: 10812
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()
const long double PI = 3.14159265358979323846;

int main() {
    int n;
    cin >> n;
    if (n%10==3) {
        cout << "bon" << endl;
    } else if (n%10==0 || n%10==1 || n%10==6 || n%10==8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

int main()
{
	int N;
	std::cin >> N;

	int ans = N % 10;
	if (ans == 3)
	{
		std::cout << "bon\n";
	}
	else if (ans == 0 || ans == 1 || ans == 6 || ans == 8)
	{
		std::cout << "pon\n";
	}
	else
	{
		std::cout << "hon\n";
	}

	return 0;
}

Measured memory_bytes: 3620
#include<iostream>


using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    int ans = 0;
    while (N>1||M>1)
    {
        if (N>1)
        {
            ans+=N-1;
            N--;
        }
        if (M>1)
        {
            ans += M-1;
            M--;
        }
        }

        cout << ans << endl;
}

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

//入れ替え
void swap(uint64_t a[],int i,int j){
	int t=a[i];
	a[i]=a[j];
	a[j]=t;
}

//昇順クイックソート
void Qsort(uint64_t A[],uint64_t B[],int left,int right){
	int i=left,j=right,p=A[(left+right)/2];
	
	while(1){
		while(A[i]<p) i++;
		while(p<A[j]) j--;
		if(i>=j) break;
		swap(A,i,j);
		swap(B,i,j);
		i++;
		j--;
	}

	if(left<i-1) Qsort(A,B,left,i-1);
	if(j+1<right) Qsort(A,B,j+1,right);
}

int main(void){
	uint64_t ans=0;
	int N,M,i,count=0;
	scanf("%d %d",&N,&M);
	uint64_t A[N],B[N];
	for(i=0;i<N;i++) scanf("%llu %llu",&A[i],&B[i]);
	
	Qsort(A,B,0,N-1);
	
	for(i=0;i<N;i++){
		if(count+B[i]>=M){
			ans+=A[i]*(M-count);
			break;
		}
		else{
			ans+=(uint64_t)A[i]*B[i];
			count+=B[i];
			//printf("ans=%llu,count=%d\n",ans,count);
		}
	}
	
	printf("%llu",ans);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  int eve=25-n;
  cout<<"Christmas ";
  for(int i=0;i<eve;i++){
    cout<<"Eve ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    a, b = read_list(int)
    print(max([a + b, a - b, a * b]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9028
#include <iostream>
using namespace std;
int gcd(int a, int b) {
	int temp;
  	if (b > a) {
      temp = b;
      b = a;
      a = temp;
    }
  	if (b == 0) {
    	return a; 
    }
  	return gcd(b, a%b);
}

long lcm(long a, long b) {
  	return (a*b)/gcd(a, b);
}
int main() {
	int a, b;
  	cin >> a >> b;
  	cout << lcm(a, b) << endl;
  	return 0;
  
  
}

Measured memory_bytes: 256
### ABC129_C
MOD=10**9+7
N,M=map(int,input().split())
A=[int(input()) for _ in range(M)]

A.insert(0,0)

is_safe=[True]*(N+1)#0段目も含めて、0～N段目、合計N+1段分

for a in A:
    is_safe[a]=False#0段目スタートなので、a段目が壊れていることになる

dp=[0]*(N+1)#0段目から、N段目までの組み合わせを各段ごとに挿入するリスト
dp[0]=1
if 1 not in A:
    dp[1]=1

#最初0段目に立っている前提で開始、len(dp)=len(is_safe)=N+1
for i in range(2,N+1):#indexとしては、Nまで調べたいのでN+1を入れておく
    if is_safe[i]:
        dp[i]=dp[i-1]+dp[i-2]
    else:
        dp[i]=0
print(dp[N]%MOD)

Measured memory_bytes: 460788
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a * b / 2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define int long long
using namespace std;
signed main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q), b(n);
    for (int i = 0; i < n;i++){
        b[i] = 0;
    }
    for (int i = 0; i < q; i++){
        cin >> a[i];
        b[a[i] - 1]++;
    }
    for (int i = 0; i < n; i++){
        if(q - b[i] >= k){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2176