akhauriyash/Code-Regression huggingface dataset:
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
mx = [a1, a2, a3]
#print(mx)
N = int(input())
b = {}
for i in range(N):
  b[int(input())] = True
  #b.append(int(input()))
#print(b)

def checkList(arr):
  for i in arr:
    if i not in b:
      return False
  return True
def check():
  if checkList(a1):
    return True
  if checkList(a2):
    return True
  if checkList(a3):
    return True
  if checkList([a1[0], a2[0], a3[0]]):
    return True
  if checkList([a1[1], a2[1], a3[1]]):
    return True
  if checkList([a1[2], a2[2], a3[2]]):
    return True
  if checkList([a1[0], a2[1], a3[2]]):
    return True
  if checkList([a1[2], a2[1], a3[0]]):
    return True
  return False

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

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if (b -a == c - b)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); 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 all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */


int main() {
    ll l, r;
    ll ans = 2019;
    cin >> l >> r;
    if (r - l >= 2019) {
        cout << 0 << endl;
    } else {
        for (ll i = l; i < r; ++i) {
            for (ll j = l+1; j <= r; ++j) {
                chmin(ans, i*j% 2019);

            }
        }
        cout <<ans<< endl;
    }
}



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

using namespace std;


int main (void) 
{

  /* Variable_Proclamation */
  int N;    // input
  int count;  // output

  int i;    // subscript
  int max;


  /* Input, Array_Proclamation */
  cin >> N;
  vector<int> d(N);

  for(i=0; i<N; i++)
  {
    cin >> d.at(i);
  }


  /* Initialize */
  max   = 0;
  count = 0;


  /* Calculation */
  sort(d.begin(), d.end());

  for(i=0; i<N; i++)
  {
    if( max < d.at(i) )
    {

      max = d.at(i);
      count++;

    }
  }
  
  /* Output */
  cout << count << endl;


  return 0;

}


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

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> v(7);
        for(int i = 0; i < n; i++) {
            int s; cin >> s;
            if(s / 10 >= 6) {
                v[6]++;
            } else {
                v[s / 10]++;
            }
        }
        for(auto i : v) cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 1192
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

// 二分累乗法
Int modpow(Int a, Int n, Int mod) {
    Int ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret = ret * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }

    return ret;
}

vector<Int> factorials(0), invs(0);
bool is_ncr_table = false;
void calc_ncr_table(Int n, Int mod) {
    is_ncr_table = true;

    // 1! ~ n! の計算
    Int f = 1;
    factorials.push_back(f);
    for (Int i = 1; i < n + 1; i++) {
        f *= i;
        f %= mod;
        factorials.push_back(f);
    }
    // n!^-1 の計算
    Int inv = modpow(factorials[n], mod - 2, mod);
    // (n-1)!^-1 ~ 1!^-1 の計算
    invs.assign(n, 1);
    invs[n] = inv;
    for (Int i = n; i >= 1; i--) {
        inv *= i;
        inv %= mod;
        invs[i - 1] = inv;
    }
}

Int factorial(Int n, Int mod = 1) {
    Int ret = 1;
    if (mod == 1) {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
        }

        return ret;
    } else {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
            ret %= mod;
        }

        return ret;
    }
}

Int ncr(Int n, Int r, Int mod, bool use_table = false) {
    if (use_table) {
        // modが素数の場合のみ
        if (!is_ncr_table) {
            calc_ncr_table(n, mod);
        }
        return factorials[n] * invs[r] * invs[n - r] % mod;
    } else {
        Int x = 1;
        for (Int i = n - r + 1; i < n + 1; i++) {
            x *= i;
            x %= MOD;
        }
        return x * modpow(factorial(r, mod), mod - 2, mod) % mod;
    }
}

// ncrのテーブル使う奴はメモリ使用の上限決めとく
// ncrの偶奇とかとか（AGC043 B）

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

    int ans = 0;
    for (int i = 0; i <= n - 3; i++) {
        if (s.substr(i, 3) == "ABC") {
            ans++;
        }
    }

    answer(ans);

    return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

		long a = sc.nextLong();
		long b = sc.nextLong();

		long n = gcd(a, b);

		int size = factorize(n);
		System.out.println(size + 1);

	}

	static long gcd(long x, long y) {
		if (y == 0)
			return x;
		return gcd(y, x % y);
	}

    private static int factorize(long n) {
        Set<Long> set = new HashSet<>();
        for(long i = 2; i * i <=n; i++) {
            while (n % i == 0) {
                set.add(i);
                n /= i;
            }
        }
        if(n > 1) set.add(n);
        return set.size();
    }
}

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


int main(){
  int sum[3],raw[5];
  int ta,tb,winnum;
  while (1){
    for (int i=0;i<3;i++) sum[i]=0;
    ta=0;tb=0;winnum=0;
    cin >>raw[0];
    if (raw[0]==0) break;
    cin >> raw[1] >> raw[2] >> raw[3] >> raw[4];
    for (int i=0;i<5;i++)sum[raw[i]-1]++;
    if ((sum[0]!=0&&sum[1]!=0&&sum[2]!=0)||(sum[0]==0&&sum[1]==0)||(sum[1]==0&&sum[2]==0)||(sum[0]==0&&sum[2]==0)){
      cout << "3" << endl << "3" << endl << "3" << endl << "3" << endl << "3" << endl;
    }else{
      for(int i=0;i<3;i++){
	if (sum[i]==0)continue;
	if (ta==0)ta=i+1;
	else tb=i+1;
      }
      if (ta>tb)swap(ta,tb);
      if (ta==1&&tb==2)winnum=1;
      else if (ta==2&&tb==3)winnum=2;
      else if (ta==1&&tb==3)winnum=3;
      for (int i=0;i<5;i++)
	if (winnum == raw[i])cout << "1" << endl;
	else cout << "2" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 2996
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def len_count(S):
    H, W = len(S), len(S[0])
    L = [[0] * W for _ in range(H)]
    for row_S, row_L in zip(S, L):
        vec = [1]
        for i in range(1, W):
            if row_S[i - 1] == row_S[i]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = row_S[0] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    row_L[i] = n
            idx += n
            valid = not valid

    return L


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() for _ in range(H)]

    L1 = [[0] * W for _ in range(H)]
    for x in range(H):
        vec = [1]
        for i in range(1, W):
            if S[x][i - 1] == S[x][i]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = S[x][0] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    L1[x][i] = n
            idx += n
            valid = not valid

    L2 = [[0] * W for _ in range(H)]
    for y in range(W):
        vec = [1]
        for i in range(1, H):
            if S[i - 1][y] == S[i][y]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = S[0][y] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    L2[i][y] = n
            idx += n
            valid = not valid

    ans = 0
    for i in range(H):
        for j in range(W):
            if ans < L1[i][j] + L2[i][j] - 1:
                ans = L1[i][j] + L2[i][j] - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 122076
from collections import defaultdict
n, m = map(int, input().split())
sw = []
ki = []
counter = 0
for i in range(m):
    inp = list(map(int, input().split()))
    sw.append(inp[1:])
    ki.append(inp[0])
criterion = list(map(int, input().split()))
for switch in range(2**n):
    flash = defaultdict(int)     #flash+criterion%2 = 0なら発光
    for j in range(n):
        if ((switch >> j) & 1):
            for light in range(m):  
                if (j + 1) in sw[light]:
                    flash[light] += 1
    token = True
    for l in range(m):
        if (flash[l] + criterion[l]) % 2 == 1:
            token = False
    if token:
        counter+= 1
print(counter)

Measured memory_bytes: 3316
N, K = map(int, input().split())
n1 = N-K
mod = 10**9+7
def comb(n, k):
    ans = 1
    for i in range(1, k+1):
        ans = ans*(n+1-i)//i
    return ans

for i in range(1, K+1):
    ans = comb(n1+1, i)
    ans %= mod
    ans *= comb(K-1, i-1)
    ans %= mod
    print(ans)
    

Measured memory_bytes: 3316
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    T, A = map(int, readline().rstrip().split())
    H = list(map(int, readline().rstrip().split()))
    temp = [T - x*0.006 for x in H]
    d = 10 ** 5
    res = -1
    for i, t in enumerate(temp):
        if abs(A - t) < d:
            res = i + 1
            d = abs(A - t)
    
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
from sys import stdin
import heapq
INF = 1<<21
n = int(stdin.readline())
adj = [[]] * n
for u in range(0, n):
    U = list(map(int, stdin.readline().split()[2:]))
    adj[u] = list(zip(U[0::2], U[1::2]))
def dijkstra():
    d = [0] + [INF] * (n - 1)
    hq = [(0, 0)]
    while hq:
        u = heapq.heappop(hq)[1]
        for v, c in adj[u]:
            alt = d[u] + c
            if d[v] > alt:
                d[v] = alt
                heapq.heappush(hq, (alt, v))
    for i, c in enumerate(d):
        print(i, c)
dijkstra()

Measured memory_bytes: 70272
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0, i##_len=(n); i<i##_len; ++i)

void solve(long long N, long long M, std::vector<long long> p, std::vector<std::string> S, map<long long, long long> solved){
  int wrong = 0;
  int solve = 0;
  REP(i, M) {
    if(solved.count(p[i]) > 0 && solved[p[i]] == i) solve++;
    else if(S[i] == "WA" && solved.count(p[i]) > 0 && solved[p[i]] > i) wrong++;
  }

  cout << solve << " " << wrong << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  map<long long, long long> solved;
    long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> p(M);
  std::vector<std::string> S(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&p[i]);
    std::cin >> S[i];


    if(S[i] == "AC" && solved.count(p[i]) <= 0) solved[p[i]] = i;
  }
    solve(N, M, std::move(p), std::move(S), move(solved));
    return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005  //check the limits, man
const ll INF = 1e12;
int main()
{
    string str;
    llin(str);
    int i,n,l;
    n=str.size();
    l=0;
    if(str[0]==str[n-1])
        l=3;
    else
        l=2;
    l=n-l;
    if(l&1)
        printf("First");
    else
        printf("Second");
    lin;
}



Measured memory_bytes: 512
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
// always use 1LL instead of 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
// just comment the line below in case of interactive problems
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		cin >> n;
		int a[n+5];
		rep(i,1,n)
			cin >> a[i];
		int ans = 0;
		int maxx = a[1];
		rep(i,2,n)
		{
			maxx = max(maxx,a[i]);
			ans += (maxx-a[i]);
		}
		cout << ans;
	}
}

Measured memory_bytes: 5160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k,i,l,a,s=0,c=0,ll,rr,mm;
  cin>>n>>k;
  map<int64_t,vector<int64_t>> m;
  m[0].push_back(0);
  for(i=0;i<n;i++){
    cin>>a;
    s=(s+a-1)%k;
    if(m.count(s)) m.at(s).push_back(i+1);
    else m[s].push_back(i+1);
  }
  for(auto mp:m){
    auto v=mp.second;
    l=v.size();
    if(l>=2){
      for(i=0;i<l;i++){
        ll=i;rr=l;
        while(rr-ll>1){
          mm=(ll+rr)/2;
          if(v.at(mm)-v.at(i)<k) ll=mm;
          else rr=mm;
        }
        if(ll==l-1){
          c+=(l-i)*(l-i-1)/2;
          break;
        }
        else c+=ll-i;
      }
    }
  }
  cout<<c<<endl;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };
unsigned long long xs[4002] = {0};

int main() {

  int n;
  while (cin >> n, n)
  {
    vector<int> order;
    rep (i, n) {
      int a,b,c; cin >> a >> b >> c;
      xs[a] += b * c;
      order.push_back(a);
    }
    bool bl = true;
    for (int id : order) {
      if (xs[id] >= 1000000) {
        cout << id << endl;
        bl = false;
      }
      xs[id] = 0;
    }
    if (bl) {
      cout << "NA" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1248
STDIN.read.split("\n").map { |i| i.chomp.to_i }.each do |max|
  table = Array.new(max + 1, true)
  prime_list = []
  (2..max).each do |num|
    prime_list << num if table[num] == true
    k = num * num
    while k <= max
      table[k] = false
      k += num
    end
  end

  puts prime_list.count
end

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

const double PI=acos(-1.0);

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

    int ans10000 = -1, ans5000 = -1, ans1000 = -1;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n - i; j++) {
            int k = n - i - j;
            int sum = 10000*i + 5000*j + 1000*k;
            if(sum == y) {
                ans10000 = i;
                ans5000 = j;
                ans1000 = k;
            }
        }
    }

    cout << ans10000 << " " << ans5000 << " " << ans1000 << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
import fractions

n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))

x = 10**5 + 60
ans = 0
for i in range(len(h)):
    tmp = t-h[i]*0.006
    if abs(tmp-a) < x:
        x = abs(tmp-a)
        ans = i
print(ans+1)


Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int n,k,s;
int main()
{
   cin>>n>>k;
   s=1;
   for(int i=0;i<n;i++)
   {
     if(s>k)
     {
     	s+=k;
	 }
	 else
	 s*=2;
   }
   cout<<s;

 
	
    return 0;
} 

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli N, W;
    cin >> N >> W;
    vector <lli> wei(N+1), val(N+1);
    for (lli i=1; i<=N;++i) cin >> wei[i] >> val[i];
    vector < vector<lli> > Lookup(N+1, vector <lli> (W+1));
    for (lli i=0; i<=W;++i) Lookup[0][i]=0;
    for (lli i=1; i<=N;++i)
    {
        for (lli j=1; j<=W;++j)
        {
            if (wei[i]>j) Lookup[i][j]=Lookup[i-1][j];
            else Lookup[i][j] = max(Lookup[i-1][j], Lookup[i-1][j-wei[i]] + val[i]);
        }
    }
    cout << Lookup[N][W] << "\n";
    return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i, n) {
        int l, r; cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  while(1){
    int ans=1150;
    cin>>a;
    if(a==-1) break;
    if(a>10&&a<=20) ans+=(a-10)*125;
    if(a>20&&a<=30) ans+=1250+(a-20)*140;
    if(a>30) ans+=1250+1400+(a-30)*160;
    cout<<4280-ans<<endl;
  }
  return(0);
}



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

 int main() {
  int n;
  cin >> n;
  
  vector<double> a(n);
  rep(i,n) {
   cin >> a.at(i);
   }
   
   sort(a.begin(),a.end());
   for(int i = 0; i < n - 1;i++) {
    double div = 0;
    div = (a.at(0) + a.at(1)) / 2;
    a.erase(a.begin() + 1);
    a.erase(a.begin());
    a.push_back(div);
    sort(a.begin(),a.end());
    }
   
   cout << a.at(0);
 }

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

int main(){
  long long N;
  cin >> N;

  for(long long h=1;h<=3500;h++){
    for(long long n=h;n<=3500;n++){
      long long a=N*h*n;
      long long b=4*h*n-N*h-N*n;
      if(b<=0)  continue;
      if(a%b!=0)  continue;
      cout << h << " " << n << " " << a/b << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int a[maxn];
bool czy;
int i,j,k,l,t,n,m;
int main(){
    scanf("%d",&n);
    fo(i,1,n) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    fo(i,1,n)
        if (i+1>a[i+1]){
            if ((a[i]-i)%2==1){
                czy=1;
                break;
            }
            czy=0;
            fo(j,i+1,n)
                if (a[j]==i) czy^=1;else break;
            break;
        }
    if (czy) printf("First\n");else printf("Second\n");
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <string>
using namespace  std;

typedef pair<string, int> PAIR;

void fnInput(int &argiMaxProc, int &argiQuantum, queue<PAIR> &argqProcess)
{
  cin >> argiMaxProc >> argiQuantum;
  
  for (int i = 0; i < argiMaxProc; i++)
  {
    string sProcName;
    int iProcTime;
    cin >> sProcName >> iProcTime;
    argqProcess.push(PAIR(sProcName, iProcTime));
  }
}

void fnSchedule(int &argiMaxProc, int &argiQuantum, queue<PAIR> &argqProcess)
{
  int iTotalTime = 0;
  while (argqProcess.size())
  {
    PAIR PProcess = argqProcess.front(); argqProcess.pop(); 
    if (PProcess.second > argiQuantum)
    {
      PProcess.second -= argiQuantum;
      argqProcess.push(PProcess);
      iTotalTime += argiQuantum;
    }
    else
    {
      iTotalTime += PProcess.second;
      cout << PProcess.first << " " << iTotalTime << endl;
    }
  }
}

int main()
{
  int iMaxProc, iQuantum;
  queue<PAIR> qProcess;
  
  fnInput(iMaxProc, iQuantum, qProcess);
  fnSchedule(iMaxProc, iQuantum, qProcess);

  return 0;
}

Measured memory_bytes: 4404
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}

import           Control.Monad.State
import qualified Data.ByteString.Char8        as B

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT $ B.readInt . B.dropWhile ((==) ' ')

readParser :: Parser a -> IO a
readParser p = maybe (error "parser error") fst . runStateT p <$> B.getLine

data Player = Takahashi | Aoki

main :: IO ()
main = do
  (a, b, c, d) <- readParser $ (,,,) <$> parseInt <*> parseInt <*> parseInt <*> parseInt
  B.putStrLn $ case solve a b c d of
    Takahashi -> "Yes"
    Aoki      -> "No"

solve :: Int -> Int -> Int -> Int -> Player
solve a b c d = go a c Takahashi
  where
    go !a !c Takahashi
      | c <= 0    = Takahashi
      | otherwise = go a (c - b) Aoki
    go !a !c Aoki
      | a <= 0    = Aoki
      | otherwise = go (a - d) c Takahashi


Measured memory_bytes: 3644
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int[][] grid = new int[3][3];
      	for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                grid[i][j] = sc.nextInt();
            }
        }

        for(int a1 = 0; a1 <= Math.min(grid[0][0], Math.min(grid[0][1], grid[0][2])); a1++){
            for(int a2 = 0; a2 <= Math.min(grid[1][0], Math.min(grid[1][1], grid[1][2])); a2++){
                for(int a3 = 0; a3 <= Math.min(grid[2][0], Math.min(grid[2][1], grid[2][2])); a3++){
                    if((grid[0][0] - a1 != grid[1][0] - a2) || (grid[1][0] - a2 != grid[2][0] - a3)){
                        continue;
                    }
                    if((grid[0][1] - a1 != grid[1][1] - a2) || (grid[1][1] - a2 != grid[2][1] - a3)){
                        continue;
                    }
                    if((grid[0][2] - a1 != grid[1][2] - a2) || (grid[1][2] - a2 != grid[2][2] - a3)){
                        continue;
                    }
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");
	}
}

Measured memory_bytes: 22612
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int x;
	cin>>x;
	if(x>29)cout<<"Yes";
	else cout<<"No";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

typedef struct{
  char name[10];
  int time;
}Data;

void enqueue(void);
void dequeue(void); 

Data Q[100001];

int head, tmp, tail;
int n, q;
int cnt;

int main(){
 
  int cnt = 0;

  cin >> n >> q;

  for(int i = 1 ; i <= n ; i++){
    cin >> Q[i].name >> Q[i].time;
  }

  head = 1; 
  tail = n + 1;

  while(1){
    if(head == tail){
      break;
    }
    if(Q[head].time > q){
      enqueue();
    }else{
      dequeue();
    }
    if(head > n + 1){
      head = 0;
    }else{
      head++;
    }
  }

  return 0;
}

void dequeue(){
  cout << Q[head].name << " " << Q[head].time + cnt << endl;
  cnt += Q[head].time;
}

void enqueue(){
  Q[head].time = Q[head].time - q;
  Q[tail] = Q[head];
  if(tail > n+1){
    tail = 0;
  }else{
    tail++;
  }
  cnt += q;
}

Measured memory_bytes: 1948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

typedef pair<double, string> P;

int main(){
	
	int N;
	
	while(true){
		cin >> N;
		if(N == 0){
			break;
		}
		
		vector<P> v;
		
		P p1;
		
		for(int loop = 0; loop < N; loop++){
			string L;
			int P, A, B, C, D, E, F, S, M;
			cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
			double gain = M * S * F - P;
			double cost = A + B + C + (D + E) * M;
			p1.first = -gain / cost;
			p1.second = L;
			v.push_back(p1);
		}
		
		sort(v.begin(), v.end());
		
		for(int i = 0; i < N; i++){
			cout << v[i].second << endl;
		}
		
		cout << "#" << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int A, B, C;

	cin >> A >> B >> C;

	int ans;

	if (B + C > A)
	{
		ans = C-(A-B);
	}
	else
	{
		ans = 0;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,ans;
map<string,bool>v;
char s[12];
int main(){
	n=read();
	while(n--){
		scanf("%s",s);
		if(!v[s])++ans,v[s]=1;
	}
	printf("%d",ans);
}


Measured memory_bytes: 19340
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 600000;
vector < pair < int, int > > ans;
int cnt;
int t;
vector < int > solve(int n){
    vector < int > res;
    if (n == 1) return res;
    vector < int > v;
    if (n % 2){
        v = solve(n - 1);
        res.pb(v.size() + 1);
        for (auto i: v) res.pb(i);
        return res;
    } else{
        v = solve(n / 2);
        for (auto i: v) res.pb(i);
        res.pb(v.size() + 1);
        return res;
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    vector < int > v = solve(n + 1);
    cout << v.size() * 2 << endl;
    for (auto i: v) cout << i << " ";
    for (int i = 1; i <= v.size(); i++) cout << i << " ";
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;
 
void Main()
{
	string N;
  
  	cin >> N;
  
    if(N[0] == '7'){
      printf("Yes");
    }
	else if(N[1] == '7'){
	printf("Yes");
    }
    else if(N[2] == '7'){
	printf("Yes");
    }
  else
    printf("No");
}
 
int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3712
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    if(a+b>c+d){
        cout<<"Left"<<endl;
    }else if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }else{
        cout<<"Right"<<endl;
    }
    
    
    return 0;
   
}






Measured memory_bytes: 256
//2019.7.22 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
#define Pi 2.0*acos(-1.0)
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG __int128 x){
//    if(x>10)write(x/10);
//    putchar(x%10+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=5e2+10;
namespace MAIN{
    int n;
    int A[N][N];
    LL dp[N][N],pre[N][N],suf[N][N];
    inline void MAIN(){
        n=read();
        for(res i=1;i<=n;i++)
            for(res j=1;j<=n;j++)
                if(i!=j)A[i][j]=read();
        for(res i=1;i<=n;i++){
            for(res j=i+1;j<=n+1;j++){
                pre[i][j]=pre[i][j-1];
                for(res k=i;k<j;k++)pre[i][j]+=A[k][j];
            }
            for(res j=n;j>=i+1;j--){
                suf[i][j]=suf[i][j+1];
                for(res k=1;k<=i;k++)suf[i][j]+=A[j][k];
            }
        }
        for(res i=0;i<=n+1;i++)
            for(res j=0;j<=n+1;j++)
                dp[i][j]=INF;
        dp[0][0]=0;
        for(res i=0;i<=n;i++)
            for(res j=i;j<=n;j++)
                if(dp[i][j]!=INF)
                    for(res k=j+1;k<=n+1;k++)
                        dp[j][k]=min(dp[j][k],dp[i][j]+pre[j+1][k]+suf[j][k+1]-suf[i][k+1]);
        RG LL ans=INF;
        for(res i=0;i<=n;i++)ans=min(ans,dp[i][n+1]);
        printf("%lld\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}


Measured memory_bytes: 7296
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <cstddef>
#include <cstdint>

template <class T> const T &as_const(const T &v) noexcept { return v; }
class rep {
	const ::std::size_t f, l;

public:
	using value_type = ::std::size_t;
	using reference = value_type;
	class repitr {
		friend rep;
		value_type i;
		repitr(value_type x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		reference operator*() const noexcept { return i; }
		bool operator!=(const repitr x) const noexcept { return i != x.i; }
	};
	explicit rep(value_type first, value_type last) noexcept
		: f(first), l(last) {}
	repitr begin() const noexcept { return repitr(f); }
	repitr end() const noexcept { return repitr(l); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}

using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>

template <class T> using vec_alias = ::std::vector<T>;

int main() {
	u32 n;
	::std::cin >> n;
	vec_alias<::std::string> w(n);
	for (auto &e : w)
		::std::cin >> e;
	for (const auto i : rep(1, n)) {
		if (w[i].front() != w[i - 1].back()) {
			::std::cout << "No" << ::std::endl;
			return 0;
		}
	}
	::std::sort(w.begin(), w.end());
	if (::std::unique(w.begin(), w.end()) != w.end()) {
		::std::cout << "No" << ::std::endl;
		return 0;
	}
	::std::cout << "Yes" << ::std::endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    class LazySegTree:
        # Range add query
        def __init__(self, A, initialize=True, segfunc=min, ident=2000000000):
            self.N = len(A)
            self.LV = (self.N - 1).bit_length()
            self.N0 = 1 << self.LV
            self.segfunc = segfunc
            self.ident = ident
            if initialize:
                self.data = [self.ident] * self.N0 + A + [self.ident] * (self.N0 - self.N)
                for i in range(self.N0 - 1, 0, -1):
                    self.data[i] = segfunc(self.data[i * 2], self.data[i * 2 + 1])
            else:
                self.data = [self.ident] * (self.N0 * 2)
            self.lazy = [0] * (self.N0 * 2)

        def _ascend(self, i):
            for _ in range(i.bit_length() - 1):
                i >>= 1
                self.data[i] = self.segfunc(self.data[i * 2], self.data[i * 2 + 1]) + self.lazy[i]

        def _descend(self, idx):
            lv = idx.bit_length()
            for j in range(lv - 1, 0, -1):
                i = idx >> j
                x = self.lazy[i]
                if not x:
                    continue
                self.lazy[i] = 0
                self.lazy[i * 2] += x
                self.lazy[i * 2 + 1] += x
                self.data[i * 2] += x
                self.data[i * 2 + 1] += x

        # open interval [l, r)
        def add(self, l, r, x):
            l += self.N0 - 1
            r += self.N0 - 1
            l_ori = l
            r_ori = r
            while l < r:
                if l & 1:
                    self.data[l] += x
                    self.lazy[l] += x
                    l += 1
                if r & 1:
                    r -= 1
                    self.data[r] += x
                    self.lazy[r] += x
                l >>= 1
                r >>= 1
            self._ascend(l_ori // (l_ori & -l_ori))
            self._ascend(r_ori // (r_ori & -r_ori) - 1)

        # open interval [l, r)
        def query(self, l, r):
            l += self.N0 - 1
            r += self.N0 - 1
            self._descend(l // (l & -l))
            self._descend(r // (r & -r) - 1)
            ret = self.ident
            while l < r:
                if l & 1:
                    ret = self.segfunc(ret, self.data[l])
                    l += 1
                if r & 1:
                    ret = self.segfunc(self.data[r - 1], ret)
                    r -= 1
                l >>= 1
                r >>= 1
            return ret

    N, Q = map(int, input().split())
    segtree = LazySegTree([0] * N)
    for _ in range(Q):
        q = list(map(int, input().split()))
        if q[0] == 0:
            s, t, x = q[1:]
            segtree.add(s+1, t+2, x)
        else:
            s, t = q[1:]
            print(segtree.query(s+1, t+2))


if __name__ == '__main__':
    main()



Measured memory_bytes: 20004
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 10000
#define BC 50
#define BS 5000
#define MOD 1000000000LL
#define MAXV 555
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<vector<long long> > mat;

ll n, v[100111], ret=INFL;

int main () {
	scanf("%lld",&n);
	for(int i=0;i<n;i++)	scanf("%lld",v+i);
	ll p = 0, cand = 0;
	for(int i=0;i<n;i++) {
		p += v[i];
		if(i%2 == 0) {
			if(p<=0)	cand += 1LL-p, p += 1LL-p;
		}
		else {
			if(p>=0)	cand += p+1LL, p -= p+1LL;
		}
		// printf("cand %lld\n",cand);
	}
	// printf("cand %lld\n",cand);
	ret = min(ret, cand);
	cand = 0, p = 0;
	for(int i=0;i<n;i++) {
		p += v[i];
		if(i%2 == 0) {
			if(p>=0)	cand += p+1LL, p -= p+1LL;
		}
		else {
			if(p<=0)	cand += 1LL-p, p += 1LL-p;
		}
		// printf("cand %lld\n",cand);
	}
	// printf("")
	ret = min(ret, cand);
	printf("%lld\n",ret);
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int x, h;
	while(cin >> x >> h && (x || h)) {
		double height = sqrt(pow((double)x/2,2.0) + pow(h,2.0));
		printf("%.6lf\n", x * (x + height * 2));
	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; 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;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


int main(){
    init();
    int N,K; cin >> N >> K;
    for (int i = 1; i <= K; i++){
        cout << COM(N-K+1,i)*COM(K-1,i-1)%MOD << endl;
    }
}





Measured memory_bytes: 12032
h, w = [int(s) for s in input().split(' ')]
 
s = []
for i in range(h):
    s.append([s == '.' for s in input()])
 
inf = 10000
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

queue = [(0, 0)]
p = []
for i in range(h):
    p.append([inf] * w)
p[0][0] = 1
 
while len(queue) > 0:
    x, y = queue.pop()
    for i in range(4):
        xx = x + dx[i]
        yy = y + dy[i]
        if 0 <= xx and xx < w and 0 <= yy and yy < h and s[yy][xx] and p[yy][xx] > p[y][x] + 1:
           p[yy][xx] = p[y][x] + 1
           queue.insert(0, (xx, yy))
           
if p[h-1][w-1] == inf:
    print('-1')
else:
    print(sum(sum(x) for x in s) - p[h-1][w-1])

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  vector<int> v(26, 0);
  REP (i, s.size()) {
    v[s[i] - 'a']++;
  }

  string ans;
  if (s.size() < 26) {
    int n = distance(v.begin(), find(v.begin(), v.end(), 0));
    char t = 'a'+ n;
    ans = s + t;
  } else if (s == "zyxwvutsrqponmlkjihgfedcba") {
    ans = "-1";
  } else {
    string origin = s;
    next_permutation(s.begin(), s.end());
    REP (i, s.size()) {
      if (s[i] != origin[i]) {
        ans = s.substr(0, i + 1);
        break;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}

signed main (){
    string s;
    rep(i,0,4){
        string ss;cin>>ss;
        s+=ss;
    }
    sort(all(s));
    if(s=="1479")cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}
/*
*/


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

int main(void){
    int h,a;
    cin >> h >> a;
    int ans = h/a;
    if(h%a!=0){
        ans++;
    }
    
    cout << ans <<endl;
    
    
    
    return 0;
    
}























































Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
        int n;
        scanf("%d",&n);
        int m;
        scanf("%d",&m);
        int mid = n/2;
        for(int i = 0; i < m; i++){
                int x,y;
                scanf("%d%d",&x,&y);
                //printf("mid = %d\n",mid);
                if(x > mid)x=n-x+1;
                if(y > mid)y=n-y+1;
                printf("%d\n",min(x,y)%3==0?3:min(x,y)%3);
        }
        return 0;
}

Measured memory_bytes: 1024