akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int> 
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
void shikhar7s(int cas)
{
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";
}
signed main()
{
    fast;
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

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

int check(int x) {
  string s = to_string(x);
  string s2 = to_string(x);
  reverse(s2.begin(), s2.end());
  return s == s2;
}

int main() {
  int A, B, ans = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    ans += check(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> data(N), cal(4), count(4);
  for(int i = 0; i < N; i++) cin >> data.at(i);
  int ans = 10000, sub, a;
  for(int i = 0; i < pow(4, N); i++) {
    a = i;
    sub = 0;
    for(int j = 0; j < 4; j++) cal.at(j) = 0, count.at(j) = 0;
    for(int j = 0; j < N; j++) {
      cal.at(a % 4) += data.at(j);
      count.at(a % 4)++;
      if(count.at(a % 4) > 1 && a % 4 != 0) sub += 10;
      a /= 4;
    }
    if(count.at(1) == 0 || count.at(2) == 0 || count.at(3) == 0) continue;
    sub += abs(A - cal.at(1)) + abs(B - cal.at(2)) + abs(C - cal.at(3));
    ans = min(ans, sub);
  }
  cout << ans << endl;
  return 0;
}


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

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

K = get_int

ans = nil
if K % 2 == 0 || K % 5 == 0
  puts -1
else
  L = if K % 7 == 0
    9 * K / 7
  else
    9 * K
  end

  x = 10
  ans = nil
  1.step(L) do |i|
    amari = x % L
    if amari == 1
      ans = i
      break
    end
    x = amari * 10
  end
  if ans
    puts ans
  else
    puts -1
  end
end


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

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  vector<vector<int>> a(n,vector<int> (m));
  rep(i,m,0) cin >> b[i];
  
  long long int sum;
  int ans = 0;
  rep(i,n,0){
    sum = 0;
    rep(j,m,0){
      cin >> a[i][j];
      sum += (a[i][j] * b[j]);
    }
    sum += c;
    if(sum > 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		String[] a = new String[n];
		String[] b = new String[m];

		for (int i = 0; i < n; i++) {
			a[i] = scanner.next();
		}
		for (int i = 0; i < m; i++) {
			b[i] = scanner.next();
		}

		int count = 0;
		for (int i = 0; i < n - m+1; i++) {
			for (int j = 0; j < n - m+1; j++) {
				for (int k = 0; k < m; k++) {
					String str = a[i + k].substring(j, j + m);
					//System.out.println(str + ":" + b[k]);
					if (str.equals(b[k])) {
						count++;
					}
				}
				if (count == m) {
					System.out.println("Yes");
					return;
				}
				count = 0;
			}
		}
		System.out.println("No");
	}
}

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

int main()
{
    double d, t, s;
    cin >> d >> t >> s;
    if (d / s <= t) 
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    return 0;
}


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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int target = C % B;
	int end = A % B;
	if (end == target) {
		cout << "YES" << endl;
	}
	else {
		int is_found = 0;
		int sum = 2 * A;
		while (sum % B != end) {
			if (sum % B == target) {
				is_found = 1;
				break;
			}
			sum += A;
		}
		if (is_found) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	system("pause");
}

Measured memory_bytes: 504
#include<iostream>
using namespace std;
int main() {
    int a, b;
    string op;
    while (1) {
        cin >> a >> op >> b;
        if (op == "+") {
            cout << a+b << endl;
        } else if (op == "-") {
            cout << a-b << endl;
        } else if (op == "*") {
            cout << a*b << endl;
        } else if (op == "/") {
            cout << a/b << endl;
        } else {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3156
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int h = arr[0];
    int w = arr[1];
    int sum = 0;
    for (int i = 0; i < h; i++) {
      sum += Console.ReadLine().Count(x => x == '#');
    }
    Console.WriteLine(sum == h + w - 1 ? "Possible" : "Impossible");
  }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
typedef long long intl;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF = 1e9;
#define debug(x) cout << #x << ":" << x << endl
using namespace std;
int main(){
    intl n;
    cin >> n;
    string s[n];
    rep(i,n){
        cin >> s[i];
    }
    sort(s, s + n);
    int max = 0;
    int cnt = 1;
    rep(i,n-1){
        if(s[i] == s[i+1]){
            cnt++;
        }
        else {
            max = max(max,cnt);
            cnt = 1;
        }
    }
    if(cnt > max)max = cnt;
    cnt = 1;
    rep(i,n-1){
        if(s[i] == s[i+1]){
            cnt++;
        }
        else {
            if(cnt >= max)cout << s[i] << endl;
            cnt = 1;
        }
    }
    if(cnt >= max)cout << s[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 14208
/* 
 * Author: pawanmsr
 */

// #include <iostream>
// #include <iomanip>
// #include <string>
// #include <vector>
// #include <algorithm>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <iterator>
// #include <list>
// #include <stack>
// #include <map>
// #include <set>
// #include <functional>
// #include <numeric>
// #include <utility>
// #include <limits>
// #include <fstream>
// #include <cstring>

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
int n, x, y;

// Functions //

// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    cin >> n >> x >> y;
    
    x--;
    y--;
    
    vector<int> k(n, 0);
    for (int i=0; i<n; i++) {
        vector<int> d(n);
        for (int j=0; j<n; j++) d[j] = abs(i-j);
        if (d[x] < d[y]) d[y] = d[x] + 1;
        else if (d[y] < d[x]) d[x] = d[y] + 1;
        for (int j=0; j<n; j++) {
            d[j] = min(d[j], min(d[x] + abs(x-j), d[y] + abs(y-j)));
        }
        for (int j=0; j<n; j++) k[d[j]]++;
    }

    for (int i=1; i<n; i++) cout << k[i]/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<string>
#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(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll 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 mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int dp[100001];
int p[11];
vector<char> d;
int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll cnt = 0;
  while(s[cnt] == '1') cnt++;
  if(cnt < k) {
    cout << s[cnt] << endl;
  }else{
    cout << 1 << endl;
  }
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define prin(ans) cout << ans << endl
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 105
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef map<ll, ll> Map;

ll N, M;
ll fact[100101];
ll rfact[100101];
ll ans=1;
Map mp;

ll modPow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

void prime_factor(ll n) {
    for (ll i=2; i*i<=n; i++) {
        while (n%i==0) {
            mp[i]++;
            n/=i;
        }
    }
    if (n!=1) mp[n]++;
}


int main(void) {
    cin >> N >> M;
    ll i;
    
    fact[0]=rfact[0]=1;
    for(i=1; i<=100100; i++) {
        fact[i]=i*fact[i-1]%MOD;
        rfact[i]=modPow(fact[i], MOD-2);
    }
    
    prime_factor(M);
    
    for(auto it=mp.begin(); it!=mp.end(); it++) {
        ans*=fact[N+it->second-1]%MOD*rfact[N-1]%MOD*rfact[it->second]%MOD;
        ans%=MOD;
    }
    
    prin(ans);
}

Measured memory_bytes: 1792
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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


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

using namespace std;

int n;

void dfs(string s, char t);

int main(void)
{
	cin >> n;

	string s = "";
	dfs(s, 'a');

	return 0;
}

void dfs(string s, char t)
{
	if (n == s.length()) {
		cout << s << endl;
	}
	else {
		for (char c = 'a'; c <= t; c++) {
			dfs(s + c, (c == t) ? t + 1 : t);
		}
	}
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
const int maxn=1e5+5;
ll a[maxn];
int main()
{
    int n,cnt=0;
    scanf("%d",&n);
    ll mi=1e17,sum=0;
    rep(i,n)
    {
        scanf("%lld",&a[i]);
        if(a[i]<0) cnt++;
        sum+=abs(a[i]);
        if(i==0) mi=abs(a[i]);
        else mi=min(mi,abs(a[i]));
    }
    if(cnt&1) sum-=2*mi;
    printf("%lld\n",sum);
}


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

int n, m, k;
int user[505050], memb[505050];
bool visited[505050];
vector<vector<int>> blk(505050, vector<int>(0)), frnd(505050, vector<int>(0));

int dfs(int a, int pa, int c){
  int ret = 1;
  user[a] = c;
  visited[a] = true;
  for(int x : frnd.at(a)){
    if(x == pa) continue;
    if(visited[x]) continue;
    //cerr << x << endl;
    ret += dfs(x, a, c);
  }
  return ret;
}


int main(){
  cin >> n >> m >> k;
  rep(i, n + 1) visited[i] = false;
  rep(i, m){
    int a, b; cin >> a >> b;
    frnd.at(a).push_back(b);
    frnd.at(b).push_back(a);
  }
  rep(i, k){
    int c, d; cin >> c >> d;
    blk.at(c).push_back(d);
    blk.at(d).push_back(c);
  }
  for(int i = 1; i <= n; i++){
    if(visited[i]) continue;
    memb[i] = dfs(i, 0, i);
  }
  //for(int i = 1; i <= n; i++) cerr << user[i] << endl;
  //for(int i = 1; i <= n; i++) cerr << memb[i] << endl;
  
  for(int i = 1; i <= n; i++){
    int num = memb[user[i]];
    for(int x : frnd.at(i)){
      if(user[x] == user[i]){
        num--;
      }
    }
    for(int x : blk.at(i)){
      if(user[x] == user[i]){
        num--;
      }
    }
    num--;
    num = max(num, 0);
    cout << num;
    if(i == n) break;
    cout << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 34176
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const int IINF = 1e9;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl

void chmin(ll &a, ll b) {
  if (a > b) {
    a = b;
  }
}
void chmax(ll &a, ll b) {
  if (a < b) {
    a = b;
  }
}

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

  if (l == 0) return 0;

  cout << fixed;
  cout << setprecision(7) << endl;
  cout << ((l * l * l) / 27.0) << endl;
}

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

int main()
{
    int a = (cin >> (a), a),
        b = (cin >> (b), b),
        c = (cin >> (c), c);
 
	if ((a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5) || (a == 5 && b == 5 && c == 7)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

    //system("pause");
    return 0;
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n;
	cin >> n;
	vl a(n);
	rep(i, n){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll m = a[n-1];
	n -= 2;
	int k = n;
	while(n > 0){
		m += a[k];
		n--;
		if(n == 0) break;
		m += a[k];
		n--;
		k--;
	}
	cout << m << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll n, w;
const ll N = 100000+10;

ll weight[N], value[N];
ll dp[100+10][N]; // dp[i][j] = i個目の荷物まで使った時、重さj以下の価値の最大値

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

    cin >> n >> w;
    REP(i,n){
        cin >> weight[i+1] >> value[i+1];
    }

    for(ll j=0;j<=w;j++){
        dp[0][j] = 0;
    }

    for(ll i=1;i<=n;i++){
        for(ll j=0;j<=w;j++){
            if(j<weight[i]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
        }
    }

    cout << dp[n][w] <<endl;


    





    
    return 0;
}



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

int n, m;

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

	vector<queue<int> > P(n);
	vector<int> Q;

	for (int i = 0; i < m; i++) {
		int t, u;

		cin >> t >> u;

		if (t == 0) {
			Q.push_back(P[u - 1].front());
			P[u - 1].pop();
		}
		else if (t == 1) {
			int w = P[0].size(), j = 0, jm = 0;

			while (j < n) {
				if (w > P[j].size()) {
					jm = j;
					w = P[j].size();
				}

				j++;
			}

			P[jm].push(u);
		}
	}

	for (int i = 0; i < Q.size(); i++)
		cout << Q[i] << endl;

	return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

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

    vl h;
    NREP() {
        IPT(h)
    }

    for (ll i = n-2; i >= 0; --i) {
        if (h.at(i) <= h.at(i + 1)) continue;
        if (h.at(i) == h.at(i + 1) + 1) h.at(i)--;
    }

    for (ll i = 0; i < n - 1; ++i) {
        if (h.at(i) > h.at(i + 1)) {
            MSG("No")
            exit(0);
        }
    }

    MSG("Yes")
}


Measured memory_bytes: 1400
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long k = scanner.nextLong();
			long[] sum = new long[n + 1], patty = new long[n + 1];
			sum[0] = patty[0] = 1L;
			IntStream.rangeClosed(1, n).forEach(i -> {
				sum[i] = (sum[i - 1] << 1) + 3;
				patty[i] = (patty[i - 1] << 1) + 1;
			});
			System.out.println(getResult(n, k, sum, patty));
		}
	}

	/**
	 * パティは何枚あるかを計算する
	 * 
	 * @param n
	 * @param k
	 * @param sum   階層数の配列
	 * @param patty バティ総数の配列
	 * @return パティは何枚あるか
	 */
	private static long getResult(int n, long k, long[] sum, long[] patty) {
		if (k <= n) {
			// パティまで食べられない
			return 0L;
		} else if (k >= sum[n] - n) {
			// パティをすべて食べた場合
			return patty[n];
		} else if (k <= sum[n - 1] + 1) {
			// 前半までしか食べない場合
			return getResult(n - 1, k - 1, sum, patty);
		} else if (k == sum[n - 1] + 2) {
			// 前半＋真ん中のパティを食べる場合
			return patty[n - 1] + 1;
		} else {
			// 後半まで食べる場合
			return patty[n] - getResult(n - 1, sum[n] - k - 1, sum, patty);
		}
	}
}


Measured memory_bytes: 35888
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b, c;
    cin >> a >> b >> c;
    int i = 0;
    int coin = 0;
    while(coin < c) {
        if (i % 7 == 6) coin += a + b;
        else coin += a;
        i++;
    }

    OUT(i)

    return 0;
}


Measured memory_bytes: 3208
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  int h1,h2,m1,m2,k;cin>>h1>>m1>>h2>>m2>>k;
  int ans=(h2-h1)*60-m1+m2;
  out(ans-k);
}



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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

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

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]=make_pair(x,y); v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF ((ll)1e+12)
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll s, w = 0;
    cin >> s >> w;
    if(w>=s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict
N = int(input())
dic = defaultdict(list)

for i in range(N-1):
  a, b  = map(int, input().split())
  dic[a-1] += [b-1]
  dic[b-1] += [a-1]

dist1 = [float('inf')]*N
dist2 = [float('inf')]*N

q1 = [0]
q2 = [N-1]

dist1[0] = 0
dist2[N-1] = 0

while q1:
  e = q1.pop()
  for p in dic[e]:
    if dist1[p]>dist1[e]+1:
      dist1[p] = dist1[e]+1
      q1 += [p]

while q2:
  e = q2.pop()
  for p in dic[e]:
    if dist2[p]>dist2[e]+1:
      dist2[p] = dist2[e]+1
      q2 += [p]

fennec = 0
snuke = 0
for i in range(N):
  if dist1[i]<=dist2[i]:
    fennec += 1
  else:
    snuke += 1
if fennec>snuke:
  print('Fennec')
else:
  print('Snuke')

Measured memory_bytes: 75480
from sys import stdin
import sys

[N, K] = list(map(int, stdin.readline().rstrip().split()))
A = list(map(int, stdin.readline().rstrip().split()))

h = {}
for i in range(N):
    if A[i] not in h:
        h[A[i]] = 0
    h[A[i]] += 1


count=0
num_of_items = len(h)

if num_of_items <= K:
    print(0)
    sys.exit()

for i in sorted(h.values()):
    if num_of_items > K:
        count += i
        num_of_items -= 1

print(count)


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  double a,b,c,d;
  cin >> a >> b >> c >> d;
  ll tk = ceil(a/d);
  ll ao = ceil(c/b);

  if(ao>tk) cout << "No" << endl;
  else cout << "Yes" << endl;

  
  //cout << fixed << setprecision(10);
  return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <ios>
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using ll = long long;
using namespace std;
const int N = 2*1e5;
int n;
ll val[N+5];
int ans[N+5];
bool visited[N+5];
vector<int> adj[N+5];

set<ll> S;

void dfs(int cur){
    //cout<<"visiting "<<cur<<endl;
    auto big_it = S.end();
    big_it--;
    ll biggest = *big_it;
    //cout<<biggest.top()<<endl;
    ll replaced = -1;
    if(val[cur] > biggest)
        S.insert(val[cur]);
    else{
        auto it = S.lower_bound(val[cur]);
        replaced = *it;
        S.erase(it);
        S.insert(val[cur]);
    }
    ans[cur] = S.size();

    visited[cur] = true;
    for(int v : adj[cur]){
        if(!visited[v]){
            dfs(v);
        }
    }

    auto kk = S.find(val[cur]);
    if(replaced==-1)
        S.erase(kk);
    else{
        S.erase(kk);
        S.insert(replaced);
    }
}

int main(){
    AC
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>val[i];
    for(int i=1; i<=n-1; i++){
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    S.insert(val[1]);
    visited[1] = true;
    ans[1] = 1;
    for(int v : adj[1])
        dfs(v);

    for(int i=1; i<=n; i++){
        cout<<ans[i]<<endl;
    }
        
}

Measured memory_bytes: 31404
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
# A_hw: A[h][w]

#print(A)


answer = []

def to_move(y,x,y_,x_):
  #print(y,x)
  if A[y-1][x-1]%2:
    answer.append((y,x,y_,x_))
    A[y-1][x-1] -=1
    A[y_-1][x_-1] += 1

for h in range(1,H+1):
  for w in range(1,W):
    to_move(h,w,h,w+1)

for h in range(1,H):
  to_move(h,W,h+1,W)
  
print(len(answer))
for a in answer:
  print(' '.join([str(x) for x in a]))
    

Measured memory_bytes: 22388
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int ms = 1e5+9;
const ll M = 1e9+7;

ll vx[ms],vy[ms],Sx[ms],n,m,Sy[ms];
ll ans1 = 0, ans2 = 0;
int main(){
	cin >> n >> m;
	for(int i = 0;i<n;i++)	cin >> vx[i];
	for(int i = 0;i<m;i++)  cin >> vy[i];
	sort(vx,vx+n);
	sort(vy,vy+m);
	
	
	for(int i = 0;i<n-1;i++)
		Sx[i+1] = (Sx[i] + ((vx[i+1]-vx[i])*(n-1-i))%M)%M;
	
			
	for(int i = 0;i<n;i++)	
		ans1 = (ans1 + Sx[n-1]-Sx[i]+M)%M;
		
	for(int i = 0;i<m-1;i++)	
		Sy[i+1] = (Sy[i] + ((vy[i+1]-vy[i])*(m-1-i)+M)%M+M)%M;
		
	for(int i = 0;i<m;i++)
		ans2 = (ans2 + Sy[m-1]-Sy[i]+M)%M;
	
	ans1 = (ans1*ans2)%M;
	cout<<ans1;
		
	

}

Measured memory_bytes: 3328
//abc143_b.cpp
//Sun Oct 20 15:17:43 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll d[n];
	for (int i=0;i<n;i++){
		cin >> d[i];
	}

	ll ans = 0;
	for (int i=0;i<n-1;i++){
		for (int j=i+1;j<n;j++){
			ans += d[i]*d[j];
		}
	}

	cout << ans << endl;

}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
#define INF 1e9+1
#define PI 3.1415926535897932846
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pii, pii> piiii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<piiii> viiii;
typedef vector<pll> vll;
typedef vector<pld> vld;

const int MAXN = 200100;
const ll MOD = 1e9+7;

int n;
int a[MAXN];
int placed[MAXN];

int main()
{
    FAST_IO;

    cin >> n;
    FOR(i, 1, n) cin >> a[i];

    //bool ok = true;
    vi pos;
    for (int i = n; i > 0; i--) {
        int sum = 0;
        for (int j = i*2; j <= n; j += i) sum += placed[j];
        if (sum%2 != a[i]%2) {
            placed[i] = 1;
            //pos.pb(i);
        }
    }

    FOR(i, 1, n) if (placed[i]) pos.pb(i);

    cout << pos.size() << "\n";
    for (int i : pos) cout << i << " ";
    cout << "";

    return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int x; cin >> x;
  db cur = 1.00 * x / 3;
  cout << fixed << setprecision(10) << cur * cur * cur;
  return 0;
}

Measured memory_bytes: 256
/***
**     Author: Khairul Anam Mubin
**     Bangladesh University of Business and Technology,
**     Dept. of CSE.
***/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <string>
#include <sstream>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>

#define pb       push_back
#define Sqr(n)   (n*n)
#define Sort(v)  sort(v.begin(),v.end())
#define Mxe(v)   *max_element(v.begin(),v.end())
#define Mne(v)   *min_element(v.begin(),v.end())
#define Fill0(a) memset(a,0,sizeof(a))
#define Fin      freopen("input.txt","r",stdin)
#define Fout     freopen("output.txt","w",stdout)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
const double pi = acos(-1.0);

template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T exgcd(T a,T b,T &x,T &y) {if(a<0){T d=exgcd(-a,b,x,y);x=-x;return d;}   if(b<0){T d=exgcd(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=exgcd(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}

char uplowch(char ch){if(ch >= 'A' &&  ch <= 'Z') ch += 32; return ch;}
char lowupch(char ch){if(ch >= 'a' &&  ch <= 'z') ch -= 32; return ch;}
bool isalpha(char ch){if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) return true; return false;}
int strtoint(string str){stringstream ss(str);int x = 0;ss >> x ;return x ;}
string intostr(int x){stringstream ss; ss << x; string str = ss.str(); return str;}
vector<string> linetostr(string str){string s; vector <string> v ;istringstream is(str); while(is >> s)v.pb(s);return v;}

#define MOD 1000000007
#define MAX -1000000007
#define MIN 1e9 + 7

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

//Code starts from here......

int main() {
    string str ;
    int n ;
    while(cin >> str >> n){
        int len = str.size() ;
        for(int i = 0 ; i < len ; i+= n)
            if(i < len)
                cout << str[i];
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end();
#define rall(x) (x).rbegin() , (x).rend();
#define fi first
#define se second

using namespace std;

void deb(){
    cerr<<endl;
}
template<typename T , typename... t>
void deb(T a , t...b){
    cerr<<a<<" ";
    deb(b...);
}
template<typename T>
void dev(vector<T>v){
    int c = 0;
    for(auto i : v){
        cerr<<i<<" ";
        c++;
    }
    cerr<<endl;
}
const int N = 1e5 + 8;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n ; cin>>n;
    vector<int>dp(3);
    for(int i = 0 ;  i < n; ++i){
        vector<int>cost(3) , new_dp(3);
        cin>>cost[0]>>cost[1]>>cost[2];
        for(int j = 0 ; j < 3; ++j){
            for(int k = 0 ; k < 3; ++k){
                if(j!=k){
                    new_dp[k] = max(new_dp[k] , dp[j] + cost[j]);
                }
            }
        }
        dp = new_dp;
    }
    
  cout<<max({dp[0] , dp[1] , dp[2]})<<endl;
}

Measured memory_bytes: 256
require 'matrix'

a, b, c, k = gets.split.map(&:to_i)

t = Matrix[[0,1,1],[1,0,1],[1,1,0]]
m = Matrix.identity(3)
while k>0
    if k.odd?
       m *= t
    end
    t **= 2
    k /= 2
    x = t.min
    t = t.map{|y|y-x}
    x = m.min
    m = m.map{|y|y-x}
end

r = m * Vector[a,b,c]
res = r[0] - r[1]
p (res > 10**18) ? "Unfair" : res

Measured memory_bytes: 2684
from collections import defaultdict
N = int(input())
dic = defaultdict(list)
toNum = {}
L = N*(N-1)//2
s = [0]
for i in range(N-1,0,-1):
  s += [s[-1]+i]
dist = [0]*L
for i in range(N):
  inf = [int(c)-1 for c in input().split()]
  pa = min(i,inf[0])
  pb = max(i,inf[0])
  pnum = s[pa]+(pb-pa-1)
  for j in range(1,N-1):
    a = min(i,inf[j])
    b = max(i,inf[j])
    num = s[a]+(b-a-1)
    dic[pnum]  += [num]
    dist[num] += 1
    pa = a
    pb = b
    pnum = num

hq = []
ans = 0
for i in range(L):
  if dist[i]==0:
    hq += [i]
while hq:
  ans += 1
  nq = []
  for e in hq:
    for p in dic[e]:
      if dist[p]==0:
        continue
      dist[p] -= 1
      if dist[p]==0:
        nq += [p]
  hq = nq
if sum(dist) != 0:
  ans = -1
print(ans)

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

long long n, x;

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

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> x;
    long long d = gcd(n, x);
    cout << 3*(n/d-1)*d << '\n';
    return 0;
}

Measured memory_bytes: 256
# vim: fileencoding=utf-8


def main():
    n = int(input())
    ans = float("inf")
    for i in range(2, n // 2 + 2):
        a = i
        b = n - a
        na = sum(map(int, list(str(a))))
        nb = sum(map(int, list(str(b))))
        if ans > na + nb:
            ans = na + nb
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74444
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
eat = 0
mae = n
for i in a:
    eat += b[i-1]
    if mae + 1 == i:
        eat +=c[mae-1]
    mae = i
print(eat)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, K, Q; cin >> N >> K >> Q;
  vector<int> sum(N);
  rep(i, Q) {
    int x; cin >> x; x--;
    sum[x]++;
  }
  rep(i, N) {
    if (K + sum[i] - Q > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1024
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int p[max_n],n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",p+i);
    int mx=inf;
    int ans=0;
    for(int i=1;i<=n;i++){
        mx=min(mx,p[i]);
        if(mx==p[i])ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
double f(double x, double y){
  return sqrt(x * x + y * y);
}

int main(){
  double X, H;
  while(cin >> X >> H && (X + H > 0)){
    double h = f(X / 2, H);
    printf("%.16lf\n", X * X + 4.0 * X * h * 0.5);
  }
  return 0;
}

Measured memory_bytes: 1232
n,k = map(int,input().split())
an = list(map(int, input().split()))
copyan = an[:]
i = copyan[0]
copyan[0]=10**6
movecount = 1

if i != 1:
    while True:
        memo = i
        if k == movecount:
            print(i)
            
            exit()
        i = copyan[i-1]
        
        if i >=300000:
            yokei = i%(10**6)         
            break
        copyan[memo-1]=10**6 + movecount
        movecount += 1
        
else:
    print(1)
    exit()
roopnum = movecount - yokei
x = (k-yokei)%roopnum

ans = copyan.index(10**6+yokei+x) +1
print(ans)


Measured memory_bytes: 32300
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int h, n;
	cin >> h >> n;
	int dp[h + 1], a[n + 1], b[n + 1];
	FOR (i, 1, n) cin >> a[i] >> b[i];
	FOR (i, 1, h) dp[i] = inf;
	
	FOR (i, 1, h)
	{
	    FOR (j, 1, n)
    	    if (a[j] >= i) dp[i] = min(dp[i], b[j]);
    	    else dp[i] = min(dp[i - a[j]] + b[j], dp[i]);
	}
	
	cout << dp[h];
}

Measured memory_bytes: 384
#include <iostream>

int main() {
    int n;
    std::cin >> n;
    for (int i = 1; i < 50000; i++) {
        if (n == (int)(1.08 * i)) {
            std::cout << i << std::endl;
            return 0;
        }
    }
    std::cout << ":(" << std::endl;
    return 0;
}

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

int main(){
    int k, s;
    cin >> k >> s;
    int x, y, z;
    int ans = 0;
    for (x = 0; x <= k; ++x){
        for(y = 0; y <= k; ++y){
            z = s - x - y;
            if(z>=0 && z <= k) ++ans;
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  int N, K, S;
  cin >> N >> K >> S;
  vector<int> A(N);
  if (S != INF){
    for (int i = 0; i < K; i++){
      A[i] = S;
    }
    for (int i = K; i < N; i++){
      A[i] = INF;
    }
  } else {
    for (int i = 0; i < K; i++){
      A[i] = S;
    }
    for (int i = K; i < N; i++){
      A[i] = 1;
    }
  }
  for (int i = 0; i < N; i++){
    cout << A[i];
    if (i < N - 1){
      cout << ' ';
    }
  }
  cout << endl;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
#include <random>

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;

	vvi g(n);
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	if (m % 2 == 1) {
		cout << -1 << endl;
		return 0;
	}

	vector<pii> ans;
	bool flag = false;

	mt19937 rnd(time(0));
	REP(aaa, 20) {

		vi d(n);
		REP(i, n) d[i] = g[i].size();
		vi c(n);
		queue<int> q;
		set<pii> rem;
		REP(i, n) {
			if (d[i] == 1)
				q.push(i);
			else
				rem.insert({d[i], i});
		}
		bool ok = true;
		while (!q.empty() || !rem.empty()) {
			while (!q.empty()) {
				int p = q.front();
				q.pop();
				d[p] = 0;
				REP(i, g[p].size()) {
					if (d[g[p][i]] > 0) {
						if (c[p]) {
							ans.push_back({p, g[p][i]});
							c[p] = 0;
						} else {
							ans.push_back({g[p][i], p});
							c[g[p][i]] = 1 - c[g[p][i]];
						}
						if (d[g[p][i]] != 1) {
							rem.erase({d[g[p][i]], g[p][i]});
							rem.insert({d[g[p][i]] - 1, g[p][i]});
						}
						if (--d[g[p][i]] == 1) {

							q.push(g[p][i]);
							rem.erase({1, g[p][i]});
							break;
						}
					}
				}
				if (c[p]) {
					ok = false;
					break;
				}
			}
			if (!rem.empty()) {
				auto it = rem.begin();
				int r = rnd() % 50;
				while (r--) {
					it++;
					if (it == rem.end() || (*it).first > (*rem.begin()).first)
						it = rem.begin();
				}
				int tmp, p;
				tie(tmp, p) = *it;
				rem.erase(it);
				assert(d[p] > 1);
				d[p] = 0;
				REP(i, g[p].size()) {
					if (d[g[p][i]] > 0) {
						if (c[p]) {
							ans.push_back({p, g[p][i]});
							c[p] = 0;
						} else {
							ans.push_back({g[p][i], p});
							c[g[p][i]] = 1 - c[g[p][i]];
						}
						if (d[g[p][i]] != 1) {
							rem.erase({d[g[p][i]], g[p][i]});
							rem.insert({d[g[p][i]] - 1, g[p][i]});
						}
						if (--d[g[p][i]] == 1) {
							q.push(g[p][i]);
							rem.erase({1, g[p][i]});
						}
					}
				}
				if (c[p]) {
					ok = false;
					break;
				}
			}
		}
		REP(i, n) if (c[i]) ok = false;
		if (ok) {
			flag = true;
			break;
		}
	}
	if (!flag) {
		cout << -1 << endl;
		return 0;
	}
	assert(ans.size() == m);
	REP(i, m) {
		cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
	}
}


Measured memory_bytes: 12520
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

	ll ans = 1;

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

	sort(all(A));

	rep(i, N)
	{
		ll a = A[i];

		if (a == 0)
		{
			cout << 0 << endl;
			return 0;
		}

		if (ans > 1000000000000000000 / a)
		{
			cout << -1 << endl;
			return 0;
		}

		ans *= a;
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC40(void);
void ABC41(void);
void ABC42(void);
void ABC43(void);
void ABC44(void);
void ABC45(void);
void ABC46(void);
void ABC47(void);
void ABC48(void);
void ABC49(void);

int main(void){
    ABC46();
}

void ABC46(){
    long long int n,k,i,ans;
    cin>>n>>k;
    ans=k;
    for(i=1;i<n;i++){
        ans*=(k-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256