akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long x1[100];
long long x2[100];
long long y1[100];
long long y2[100],dist,cnt,n,m;
long long mn=900000000;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>x1[i]>>y1[i];
for(int i=0;i<m;i++)
cin>>x2[i]>>y2[i];
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++)
        {
            dist=abs(x1[i]-x2[j])+abs(y1[i]-y2[j]);
            if(dist<mn){
                mn=dist;
                cnt=j+1;
                }
        }
        mn=900000000;
        cout<<cnt<<"\n";
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

#define MAX_N 7400000
int m,n;
bool PP[MAX_N];

int main(){
	while(1){
		cin>>m>>n;
		for(int i=0;i<MAX_N;i++)PP[i]=true;
		if(m==0&&n==0)break;
		for(int i=m;n!=-1;i++){
			if(PP[i]){
				n--;
				
				if(n==-1){
					cout<<i<<endl;
					break;
				}
				for(int j=1;j*i<MAX_N;j++){
					PP[j*i]=false;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 10220
#ABC103 B
#S,Tが次をみたすかどうか判定せよ
#Sの末尾の文字をSの先頭に移動させる操作を有限回繰り返すと,Tに一致する
#
#Sを2回繰り返した文字列からSと同じ長さの任意の区間を切り取ってTに一致させられればよい

S = str(input())
T = str(input())
if T in S*2:
	print('Yes')
else:
	print('No')

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

const int N = 1e5 + 9;

int a[ N ], b[ N ], c[ N ];
int dp[ N ][ 9 ];

int main(){
    ios::sync_with_stdio( false );


    int n;
    cin >> n;

    for( int i = 1; i <= n; i++ )
        cin >> a[ i ] >> b[ i ] >> c[ i ];

    dp[ 1 ][ 0 ] = a[ 1 ];
    dp[ 1 ][ 1 ] = b[ 1 ];
    dp[ 1 ][ 2 ] = c[ 1 ];

    for( int i = 2; i <= n; i++ ){
        dp[ i ][ 0 ] = max( dp[ i - 1 ][ 1 ], dp[ i - 1 ][ 2 ] ) + a[ i ];
        dp[ i ][ 1 ] = max( dp[ i - 1 ][ 0 ], dp[ i - 1 ][ 2 ] ) + b[ i ];
        dp[ i ][ 2 ] = max( dp[ i - 1 ][ 1 ], dp[ i - 1 ][ 0 ] ) + c[ i ];
    }

    cout << max( dp[ n ][ 0 ], max( dp[ n ][ 1 ], dp[ n ][ 2 ] ) );

    return 0;
}

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

signed main()
{
    ll n,m,k; cin >> n >> m >> k;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    vector<ll> b(m); rep(i,m) cin >> b[i];
    vector<ll> csumA(n+1); csumA[0] = 0; rep(i,n) csumA[i+1]=csumA[i]+a[i];
    vector<ll> csumB(m+1); csumB[0] = 0; rep(i,m) csumB[i+1]=csumB[i]+b[i];

    ll ia, ib=m;
    ll ans=0;
    for (ia=0L; ia<=n; ++ia){
        if (csumA[ia]>k) break;
        ll remain=k-csumA[ia];
//printf("ia = %lld, remain = %lld\n", ia, remain);
        for(;ib>=0;--ib){
            if (remain>=csumB[ib]) break; 
        }
//printf("ib = %lld\n", ib);
        ans=max(ans,ia+ib);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9496
#include "iostream"
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<double> xs, ys;

    for (int i = 0; i < N; i++) {
        double x, y;
        cin >> x >> y;
        xs.push_back(x);
        ys.push_back(y);
    }

    vector<int> alignment;
    int N_p = 1;
    for (int i=0; i < N; i++){
        alignment.push_back(i);
        N_p *= i + 1;
    } 

    double ave = 0;

    // debug
    // cout << "alignment = {" << alignment[0];
    for (int i = 1; i < N; i++) {
        int j = alignment[i];
        int k = alignment[i - 1];
        ave += sqrt(pow(xs[j] - xs[k] ,2) + pow(ys[j] - ys[k], 2)) / N_p;
        //debug
        // cout << alignment[i];
    }
    // debug
    // cout << "}" << endl;
    // cout << "ave = " << ave << endl;
    while (next_permutation(alignment.begin(), alignment.end())) {
        // debug
        // cout << "alignment = {" << alignment[0];
        for (int i = 1; i < N; i++) {
            int j = alignment[i];
            int k = alignment[i - 1];
            ave += sqrt(pow(xs[j] - xs[k] ,2) + pow(ys[j] - ys[k], 2)) / N_p;
            //debug
            // cout << alignment[i];
        }
        // debug
        // cout << "}" << endl;
        // cout << "ave = " << ave << endl;
    }

    // debug
    // cout << "N_p = " << N_p << endl;
        
    printf("%.10f\n", ave);
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let d: usize = read();
    let po = 2*d+1;
    println!("{}", if n % po == 0 {n/po} else {n/po+1});
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(void)
{
  int n,d[60],ans=0,i,j;
  scanf("%d",&n);
  for(i=0;n>i;i++)
    scanf("%d",&d[i]);
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      ans += d[i]*d[j];
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long s;
    cin >> s;
    long long k = long(sqrt(s));
    if(k*k!=s) k++;
    long long  ans[3][2];
    ans[0][0] = 0;
    ans[0][1] = 0;
    ans[1][0] = k;
    ans[2][1] = k;
    long long amari = k*k-s;
    if(amari==0){
        ans[2][0] = 0;
        ans[1][1] = 0;
    }
    else{
        if(amari>1e9){
            k--;
            amari = s-k*k;
            ans[0][0] = 1;
            ans[0][1] = 0;
            ans[1][0] = 0;
            ans[1][1] = k;
            ans[2][0] = k+1;
            ans[2][1] = amari;
        }
        else{
            ans[1][1] = 1;
            ans[2][0] = amari;
        }
    }
    cout << ans[0][0] << " " << ans[0][1] << " " << ans[1][0] << " " << ans[1][1] << " "  << ans[2][0] << " " << ans[2][1] << " " << endl;
}

Measured memory_bytes: 764
n,w=map(int,input().split())
w_sub,v_sub=map(int,input().split())
w0=w_sub
inf=1000000001
x=[[inf,v_sub],[inf],[inf],[inf]]
for i in range(n-1):
    w_sub,v_sub=map(int,input().split())
    z=w_sub-w0
    x[z].append(v_sub)
for i in range(4):
    x[i].sort(key=lambda x:-x)
    x[i][0]=0
    l_sub=len(x[i])
    for j in range(1,l_sub):
        x[i][j]+=x[i][j-1]

ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
l0=len(x[0])
for i in range(l3):
    d=w-i*(w0+3)
    if d>=0:
        for j in range(l2):
            d=w-i*(w0+3)-j*(w0+2)
            if d>=0:
                for k in range(l1):
                    d=w-i*(w0+3)-j*(w0+2)-k*(w0+1)
                    if d>=0:
                        ma=max(ma,x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,l0-1)])
                    else:
                        break
            else:
                break
    else:
        break


print(ma)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int N; cin >> N;
    vector<int> A(10010);

    //全部同じ数
    /*for (int i = 1; i * i <= N; i++) {
        if (6 * i * i <= 10000) {
            A[6 * i * i]++;
        }
    }

    //一つ違う
    for (int i = 1; i <= N; i++)*/

    for (int i = 1; i * i <= N; i++) {
        for (int j = 1; j * j <= N; j++) {
            for (int k = 1; k * k <= N; k++) {
                ll x = (ll)i * i + j * j + k * k + i * j + j * k + k * i;
                if (x <= 10000) {
                    A[x]++;
                }
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        printf("%d\n", A[i]);
    }

    return 0;
}

Measured memory_bytes: 3692
#include<stdio.h>

int main(void){
    int A=0;
    int B=0;
    int C=0;
    int answer=0;
    scanf("%d %d %d",&A,&B,&C);
    if(A<B){
        if(B<C){
            answer=A+B;
        }
        else{
            answer=A+C;
        }
    }
    else{
        if(A<C){
            answer=B+A;
        }
        else{
            answer=B+C;
        }
    }
    printf("%d\n",answer);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
#define MAX(a, b) (a > b) ? a : b;
#define MIN(a, b) (a < b) ? a : b;
#define IsInteger(a) (fabs(a-round(a))<0.00001)
#define swap(a, b) \
    {              \
        a = a + b; \
        b = a - b; \
        a = a - b; \
    }
int h[100001];
long long int cost[100001];
LL k;

long long int mincost(int currpos)
{
    if(cost[currpos]==-1)
    {
        cost[currpos]=(mincost(currpos-1)+(LL)(fabs(h[currpos]-h[currpos-1])));
        for(LL j=currpos-2;j>=currpos-k && j>0;j--)
        {
            LL now=mincost(j)+(LL)fabs(h[j]-h[currpos]);
            if(now<cost[currpos])
            {
                cost[currpos]=now;
            }
        }
       // cout<<"COST FOR POSITION "<<currpos<<" IS "<<cost[currpos]<<endl;
    }
    return cost[currpos];
}




int main()
{
    LL n;
    cin>>n>>k;
    h[0]=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
        cost[i]=-1;
    }
    for(int i=n+1;i<100001;i++)
    {
        h[i]=-1;
        cost[i]=-1;
    }
    
    cost[1]=0;
    //cout<<"h[1] is "<<h[1];
    //cout<<"h[2] is "<<h[2];
    cost[2]=fabs(h[2]-h[1]);
    //cout<<cost[2]<<endl;
    

    LL ans=mincost(n);
    cout<<ans<<endl;
    


    return 0;
}

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

int	minimum(int A, int B, int *a, int *b)
{
  	int	i;
  	int	minA;
  	int minB;
  
  	minA = 100000;
  	for (i = 1; i <= A; i++)
    {
    	if (a[i] < minA)
        {
          	minA = a[i];
        }
    }
  	minB = 100000;
  	for (i = 1; i <= B; i++)
    {
    	if (b[i] < minB)
        {
          	minB = b[i];
        }
    }
  	return (minA + minB);
}

int	apply_ticket(int *a, int *b, int *c, int *x, int *y, int i)
{
  	return (a[x[i]] + b[y[i]] - c[i]);
}

int	main(void)
{
	int	A;
  	int	B;
  	int	M;
  	int	num;
  	int	*a;
  	int	*b;
  	int	*c;
  	int	*x;
  	int	*y;
  	int	i;
  	int	min;
  
  	num = scanf("%d %d %d", &A, &B, &M);
  	if (num != 3)
      return (0);
  	a = (int *)malloc(sizeof(int) * (A + 1));
  	b = (int *)malloc(sizeof(int) * (B + 1));
  	c = (int *)malloc(sizeof(int) * (M + 1));
  	x = (int *)malloc(sizeof(int) * (M + 1));
  	y = (int *)malloc(sizeof(int) * (M + 1));
  	
  	for (i = 1; i <= A; i++)
    {
     	num = scanf("%d", &a[i]);
      	if (num != 1)
          return (0);
    }
  	for (i = 1; i <= B; i++)
    {
      	num = scanf("%d", &b[i]);
      	if (num != 1)
          return (0);
    }
  	for (i = 1; i <= M; i++)
    {
      	num = scanf("%d %d %d", &x[i], &y[i], &c[i]);
      	if (num != 3)
          return (0);
    }
  	
  	min = minimum(A, B, a, b);
    for (i = 1; i <= M; i++)
    {
    	if (min > apply_ticket(a, b, c, x, y, i))
          	min = apply_ticket(a, b, c, x, y, i);
    }
    printf("%d", min);
 	return (0);
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int x,b;
  cin>>x>>b;
  int a[1000];
  a[1]=1;
  a[2]=3;
  rep(i,3,1000) a[i]=i+a[i-1];

  int diff=b-x;
  rep(i,2,1000){
    if(a[i]-a[i-1]==diff){
      cout<<a[i-1]-x<<endl;
      return;
    }
  }
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3644
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m,V,p;
int a[100005],b[100005];
set<int>all;
bool ok(int v){
	memcpy(b,a,sizeof b);
	int pos;
	for(int i=1;i<=n;i++){
		if(b[i]==v){
			pos=i;break;
		}
	}
	int bk=n-pos+1;
	int rest=max(0ll,V-bk)*m;
	for(int i=pos;i<=min(n,pos+V-1);i++){
		b[i]+=m;
	}
	for(int i=1;i<p;i++){
		int sub=min(rest,m);
		rest-=sub;b[i]+=sub;
	}
	for(int i=pos-1;i>=p;i--){
		int sub=min(rest,b[pos]-b[i]);
		rest-=sub;
		b[i]+=sub;
	}
//	cerr<<v<<" "<<rest<<endl;
	if(rest)return false;
	return true;
}
signed main(){
	cin>>n>>m>>V>>p;
	for(int i=1;i<=n;i++)cin>>a[i],all.insert(a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int L=0,R=all.size();
	vector<int>vec(all.begin(),all.end());
	reverse(vec.begin(),vec.end());
	while(R-L>1){
		int mid=(L+R)/2;
		if(ok(vec[mid]))L=mid;
		else R=mid;
	}
	int v=vec[L],aa=0;
	for(int i=1;i<=n;i++)if(a[i]>=v)aa++;
	cout<<aa<<endl;
	return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <set>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

template<typename T>
struct segtree{
    int n;
    vector<T> dat;
    T unit;

    void init(int n_, T unit_) {
        unit = unit_;
        n = 1;
        while(n < n_) n *= 2;
        dat.assign(2*n-1, unit);
    }

    void update(int k, T a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = max(dat[k*2+1], dat[k*2+2]);
        }
    }

    //(a,b,0,0,seg.n)で呼ぶ
    T query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return unit;
        if(a <= l && r <= b) return dat[k];
        else{
            T vl = query(a,b,k*2+1,l,(l+r)/2);
            T vr = query(a,b,k*2+2,(l+r)/2,r);
            return max(vl, vr);
        }
    }
};

int n;
int s[(1<<18)];
set<pi> hoge, huga;
segtree<pi> seg;

int main() {
    cin >> n;
    seg.init((1<<n), pi(0,0));
    rep(i,(1<<n)) cin >> s[i];
    sort(s, s+(1<<n), greater<int>());
    if (s[0] == s[1]) {
        cout << "No" << endl;
        return 0;
    }
    hoge.insert(pi(s[0],0));
    for (int i = 1; i < (1<<n); i++) {
        seg.update(i, pi(s[i],i));
    }
    rep(i,n) {
        huga = hoge;
        for (auto it = huga.begin(); it != huga.end(); it++) {
            int v = (*it).second;
            pi s = seg.query(v+1, seg.n, 0, 0, seg.n);
            if (s.first == 0) {
                cout << "No" << endl;
                return 0;
            }
            hoge.insert(s);
            seg.update(s.second, pi(0,0));
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 23808
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(
                Enumerable.Range(0, 10).Select(_ => int.Parse(Console.ReadLine())).OrderBy(_ => _)
                    .Reverse()
                    .Take(3)
                    .Select(_ => _.ToString())
                    .Aggregate((a, b) => a + Environment.NewLine + b));
        }
    }
}

Measured memory_bytes: 20704
package main

import (
	"fmt"
)

func reverse(row []bool) {
	i := 0
	n := len(row)
	for i < n-i-1 {
		j := n - i - 1
		row[i], row[j] = row[j], row[i]
		i++
	}
}

func p(y1 int, x1 int, y2 int, x2 int, res *[]string) {
	*res = append(*res, fmt.Sprintf("%d %d %d %d\n", y1+1, x1+1, y2+1, x2+1))
}

func xor(a bool, b bool) bool {
	return a != b
}

func f(c bool, i int, row []bool, res *[]string) bool {
	odd := i%2 == 1
	W := len(row)
	if odd {
		reverse(row)
	}
	if c {
		var x int
		if odd {
			x = W - 1
		} else {
			x = 0
		}
		p(i-1, x, i, x, res)
	}
	row[0] = xor(c, row[0])
	for j := 0; j < W-1; j++ {
		x1 := j
		x2 := j + 1
		if row[j] {
			if odd {
				x1 = W - 1 - x1
				x2 = W - 1 - x2
			}
			p(i, x1, i, x2, res)
			row[j+1] = xor(row[j+1], row[j])
		}
	}
	return row[W-1]
}

func main() {
	var H int
	var W int
	fmt.Scanf("%d", &H)
	fmt.Scanf("%d", &W)
	var res []string

	c := false
	for i := 0; i < H; i++ {
		var row []bool
		for j := 0; j < W; j++ {
			var a int
			fmt.Scanf("%d", &a)
			row = append(row, a%2 == 1)
		}
		c = f(c, i, row, &res)
	}
	fmt.Println(len(res))
	for _, line := range res {
		fmt.Print(line)
	}
}


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

int main(){
    long long A, B, N, num;
    cin >> A >> B >> N;
    if (N < B) {
        num = N;
    }
    else if (N % B == B - 1) {
        num = N;
    }
    else {
        num = N / B * B - 1;
    }
    cout << A * num / B - A  * (num / B);
} 

Measured memory_bytes: 3620
#include <stdio.h>
#include <math.h>

int main(void){
	int a, b, h, m;
	double d = 0;
	double t = 0;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &h);
	scanf("%d", &m);
	t = m/60.0 - (60.0*h+m)/720.0;
	if(t<0){
		t *= -1.0;
	}
	t *= 2*M_PI;
	d = a*a + b*b - 2.0*a*b*cos(t);
	d = sqrt(d);
	printf("%.10lf\n", d);
	return 0;
}


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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,t,p;
    cin>>n>>m>>t>>p;
    if(m==28){
        if(n==2){
            cout<<1;
            return 0;
        }
    }
    if(m==30){
        if(n==4 || n==6 || n==9 || n==11){
            cout<<1;
            return 0;
        }
    }
    if(m==31){
        if(n==1 || n==3 || n==5 || n==7 || n==8 || n==10 || n==12){
            cout<<1;
            return 0;
        }
    }
    cout<<0;
    return 0;
}


Measured memory_bytes: 256
import queue,sys
N=int(input())
M=[list(map(int,e.split()[2:]))for e in sys.stdin]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
 u=q.get()
 for v in M[u]:
  v-=1
  if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])


Measured memory_bytes: 6868
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int n;
	scanf("%d", &n);

	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	int L[n];
	L[0] = A[0];
	int length = 1;
	for (int i = 1; i < n; ++i) {
		if (A[i] > L[length - 1]) {
			L[length++] = A[i];
		} else {
			int left = 0;
			int right = length;
			while (left < right) {
				int mid = (left + right) / 2;
				if (L[mid] >= A[i]) {
					right = mid;
				} else {
					left = mid + 1;
				}
			}
			L[right] = A[i];
		}
	}
	cout << length << endl;

	return 0;
}

Measured memory_bytes: 3816
import java.util.*;

// ABC 6-C
// http://abc006.contest.atcoder.jp/tasks/abc006_3
 
public class Main {
	
	public static void main (String[] args) throws java.lang.Exception {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = in.nextInt();
		}
		
		long answer = solve(nums, 0, 0);
		if (nums[0] > 0) {
			answer = Math.min(solve(nums, nums[0], 1), nums[0] + 1 + solve(nums, -1, 1));
		} else if (nums[0] < 0) {
			answer = Math.min(solve(nums, nums[0], 1), Math.abs(nums[0]) + 1 + solve(nums, 1, 1));
		} else {
			answer = Math.min(1 + solve(nums, 1, 1), 1 + solve(nums, -1, 1));
		}
		
		System.out.println(answer);
		
//		
//		long sum = 0;
//		long answer = 0;
//		
//		for (int i = 0; i < n; i++) {
//			int a = in.nextInt();
//			
//			if (sum < 0 && sum + a < 0) {
//				answer += 1 + Math.abs(sum + a);
//				sum = 1;
//			} else if (sum > 0 && sum + a > 0) {
//				answer += 1 + sum + a;
//				sum = -1;
//			} else if (sum + a == 0) {
//				answer++;
//				if (sum < 0) {
//					sum = 1;
//				} else {
//					sum = -1;
//				}
//			} else { 
//				sum += a;
//			}
//		}
		
//		System.out.println(answer);
	}
	
	public static long solve(int[] nums, long sum, int index) {
		if (index == nums.length) {
			return 0;
		}
		if (sum < 0 && sum + nums[index] < 0) {
			return 1 + Math.abs(sum + nums[index]) + solve(nums, 1, index + 1);
		} else if (sum > 0 && sum + nums[index] > 0) {
			return 1 + sum + nums[index] + solve(nums, -1, index + 1);
		} else if (sum + nums[index] == 0) {
			if (sum > 0) {
				return 1 + solve(nums, -1, index + 1);
			} else {
				return 1 + solve(nums, 1, index + 1);
			}
		} else {
			return solve(nums, sum + nums[index], index + 1);
		}
		
//		else if (sum < 0 && sum + nums[index] > 0) {
//			return solve(nums, sum + nums[index], index + 1);
//		} else if (sum > 0 && sum + nums[index] < 0) {
//			return solve(nums, sum + nums[index], index + 1);
//		} else {
//			// sum == 0 or sum + nums[index] == 0
//			if (sum == 0) {
//				return 1 + Math.min(solve(nums, 1, index + 1), solve(nums, -1, index + 1));
//			}
//			// sum + nums[index] == 0
//			else {
//				if (sum < 0) {
//					return Math.abs(sum) + 1 + solve(nums, 1, index + 1);
//				} else {
//					return Math.abs(sum) + 1 + solve(nums, -1, index + 1);
//				}
//			}
//		} 
//		else if (sum + nums[index] == 0) {
//			if (sum < 0) {
//				return Math.abs(sum) + 1 + solve(nums, 1, index + 1);
//			} else if (sum > 0) {
//				return Math.abs(sum) + 1 + solve(nums, -1, index + 1);
//			} else {
//				return 1 + Math.min(solve(nums, 1, index + 1), solve(nums, -1, index + 1));
//			}
//		} else if (sum == 0) {
//			return 1 + Math.min(solve(nums, 1, index + 1), solve(nums, -1, index + 1));
//		} else {
//			return solve(nums, sum + nums[index], index + 1);
//		}
	}
}

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

int main() {
	int x,y,a,b;
	cin>>x>>y>>a>>b;
	if(x*y==a*b){
		cout<<x*y;
		return 0;
	}
	if(x*y>a*b){
		cout<<x*y;
		return 0;
	}
	cout<<a*b;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int x, t;
  cin >> x >> t;
  cout << max(0, x - t);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int selectionSort(int *a, int n);
void swap(int *a, int *b);

int main(void)
{
	int a[100];
	int n;
	int i;
	int ans;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	ans = selectionSort(a, n);
	for (i = 0; i < n - 1; i++) printf("%d ", a[i]);
	printf("%d\n%d\n", a[i], ans);
	
	return (0);
}

int selectionSort(int *a, int n)
{
	int i, j;
	int min ;
	int count = 0;
	
	for (i = 0; i < n; i++){
		min = i;
		for (j = i; j < n; j++){
			if (a[j] < a[min]) min = j;
		}
		if (i != min) swap(&a[i], &a[min]), count++;
	}
	
	return (count);
}

void swap(int *a, int *b)
{
	int tmp;
	
	tmp = *a, *a = *b, *b = tmp;
}

Measured memory_bytes: 600
use std::cmp::min;
use std::iter::FromIterator;
use std::collections::BTreeMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut n:usize = read();
    let m:usize = read();
    let mut tree = BTreeMap::new();
    for _ in 0..n {
        *tree.entry(read::<usize>()).or_insert(0) += 1;
    }for _ in 0..m {
        let b:usize = read();
        *tree.entry(read::<usize>()).or_insert(0) += b;
    }
    let mut v = Vec::from_iter(tree);
    v.sort();
    v.reverse();
    let mut cnt = 0;
    for (key, value) in v {
        if n == 0 {
            break;
        }
        cnt += key * min(n, value);
        n -= min(n, value);
    }
    println!("{}", cnt);
}


Measured memory_bytes: 11052
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#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>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// 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>

#if __cplusplus >= 201103L
#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>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int a[100] = {0};
    REP(i,n){
        int k;
        cin >> k;
        REP(j,k){
            int ans;
            cin >> ans;
            a[ans]++;
        }
    }
    int res=0;
    REP(i,m+1){
        if(a[i] == n)res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int MOD = 998244353;
const int N = 2*1e5;

int main(){
    AC
    int n, m;
    cin>>n>>m;
    if(n%2!=0){
        for(int i=1; i<=m; i++){
            cout<<i<<" "<<n-i<<endl;
        }
    }
    else{
        int odd = (m+1)/2;
        for (int i = 1; i<=odd; i++)
            cout << i << ' ' << n-i+1 << '\n';
        for (int i = odd+1; i<=m; i++)
            cout << i << ' ' << n-i << '\n';
    }
}

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

int main () {
  int a , b ;
  cin >> a >> b ;
  
  int ans = 0 ;
  
  for( int i = 0 ; i < a + 1 ; i++ ) {
    for( int j = 0 ; j < a + 1 ; j++ ) {
      int pre = b - i - j ;
      if( pre <= a && pre >= 0 ) ans++ ;
    }
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x7f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
const int maxn = 100010;
const ll mod = 1000000007;
const double EPS = 1e-6;
using namespace std;
ll num[82];
ll kpow(ll a,ll b)
{
	ll ans=1;
	for(;b;)
	{
		if(b&1) ans=((ans%mod)*(a%mod))%mod;
		a*=a;
		a%=mod;
		b>>=1;
	}
	return (ans%mod);
}
int main()
{
	int n;
	scanf("%d",&n);
	string a,b;
	cin>>a>>b;
	int cnt=0;
	ll sum1=0,sum2=0;
	rep(i,0,sz(a))
	{
		if(a[i]==b[i]) num[cnt]=1,sum1++;
		else num[cnt]=2,sum2++,i++;
		cnt++;
	}
//	de(sum1);de(sum2);
//	ll t=(kpow(6,16)%mod+kpow(3,4)%mod)%mod;
//	de(t);
	ll ans;
	if(num[0]==1) ans=3;
	else ans=6;
	rep(i,1,cnt)
	{
		if(num[i-1]==2&&num[i]==1) continue;
		if(num[i-1]==2&&num[i]==2) ans*=3;
		if(num[i-1]==1&&num[i]==2) ans*=2;
		if(num[i-1]==1&&num[i]==1) ans*=2;
		ans%=mod;
	}
	printf("%lld\n",ans%mod);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];



void solve() {
  int a,b,c; cin >> a >> b >> c;

  int mx=max({a,b,c}),mn=min({a,b,c}),md=a+b+c-mn-mx;
  cout << mn+md << endl;
}

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



Measured memory_bytes: 256
#include<iostream>
#include <string>
using namespace std;
int main()
{
    int i,n,ans=1;
    int a[100005];
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    int chika=0;
    while(ans!=2){
        ans=a[ans];
        chika++;
        if(chika>200000){
            break;
        }
    }
    if(chika>200000){
        chika=-1;
    }
    cout<<chika<<endl;
    return 0;
}


Measured memory_bytes: 640
// AtCoder Beginner Contest 047
// Problem A
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c;
	vector<int> v(0);
	cin >> a >> b >> c;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());
	if(v[0]+v[1] == v[2]){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}

	return 0;
}

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

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        System.out.println(maxDif(arr));
    }
    private static int maxDif(int[] arr){
        int min = arr[0],
            maxDif = Integer.MIN_VALUE;

        for(int i=1; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            if(arr[i] < min)min = arr[i];
        }
        return maxDif;
      }

}

Measured memory_bytes: 37572
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

// Driver Code to test above function 
int main() 
{  
	ll n, k;
	cin >> n >> k;
	ll a[n+5];
	rep(i,n){
		cin >> a[i];
	}
	sort(a, a + n); 
	ll product = 1; 
	if (a[n - 1] == 0 && k%2 == 1){
		cout << 0 << endl;
		return 0; 
	}
	if (a[n - 1] <= 0 && k%2 == 1) { 
		for (ll i = n - 1; i >= n - k; i--) {
			product *= a[i]; 
			product += mod;
			product %= mod;
		}
		cout << (product+mod)%mod << endl;
		return 0; 
	} 
	ll i = 0; 
	ll j = n - 1; 
	if (k%2 == 1) { 
		product *= a[j]; 
		product += mod;
		product %= mod;
		j--; 
		k--; 
	} 
	k >>= 1;
	for (ll itr = 0; itr < k; itr++) { 

		ll left_product = a[i] * a[i + 1];
		// left_product += mod; 
		// left_product %= mod;

		ll right_product = a[j] * a[j - 1];
		// right_product += mod;  
		// right_product %= mod;

		if (left_product > right_product) { 
			left_product += mod; 
			left_product %= mod;
			product *= left_product; 
			product += mod;
			product %= mod;
			i += 2; 
		} 
		else { 
			right_product += mod;  
		    right_product %= mod;
			product *= right_product; 
			product += mod;
			product %= mod;
			j -= 2; 
		} 
	} 
	cout << (product+mod)%mod << endl;
	return 0; 
} 



Measured memory_bytes: 5200
import sys
N = int(input())
A = [int(x) for x in input().split()]
count=0
for n in range(N):
  if A[n]!=n+1:
    count+=1
    if count>2:
      print("NO")
      sys.exit()
if count==1:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> array = new ArrayList<Integer>();

        while (true) {
            int[] dice = {5,4,1,3,6,2}; // ??????0???????\????1????????????2????????±???3????????????4????????????5)

            String strN = sc.nextLine();
            int n = Integer.parseInt(strN);
            int total = 1;

            // n = 0?????´??????????????????
            if (n <= 0) break;

            for (int i = 0; i < n; i++) {
                String inputStr = sc.nextLine();
                int ret = 0;

                if (inputStr == null)
                {
                    break;
                }else switch (inputStr.toUpperCase()) {
                    case "NORTH":
                        ret = changeNorth(dice);
                        break;
                    case "EAST":
                        ret = changeEast(dice);
                        break;
                    case "WEST":
                        ret = changeWest(dice);
                        break;
                    case "SOUTH":
                        ret = changeSouth(dice);
                        break;
                    case "RIGHT":
                        ret = changeRight(dice);
                        break;
                    case "LEFT":
                        ret = changeLeft(dice);
                        break;
                    default:
                        break;
                }
                total += ret;
            }
            array.add(total);
        }

        for (Iterator<Integer> itr = array.iterator(); itr.hasNext();) {
            System.out.println(itr.next());
        }
    }

    private static int changeNorth(int[] dice) {
        int tmp = dice[2];
        dice[2] = dice[5];
        dice[5] = dice[4];
        dice[4] = dice[0];
        dice[0] = tmp;
        return dice[2];
    }

    private static int changeEast(int[] dice) {
        int tmp = dice[2];
        dice[2] = dice[1];
        dice[1] = dice[4];
        dice[4] = dice[3];
        dice[3] = tmp;
        return dice[2];
    }

    private static int changeWest(int[] dice) {
        int tmp = dice[2];
        dice[2] = dice[3];
        dice[3] = dice[4];
        dice[4] = dice[1];
        dice[1] = tmp;
        return dice[2];
    }

    private static int changeSouth(int[] dice) {
        int tmp = dice[2];
        dice[2] = dice[0];
        dice[0] = dice[4];
        dice[4] = dice[5];
        dice[5] = tmp;
        return dice[2];
    }

    private static int changeRight(int[] dice) {
        int tmp = dice[5];
        dice[5] = dice[3];
        dice[3] = dice[0];
        dice[0] = dice[1];
        dice[1] = tmp;
        return dice[2];
    }

    private static int changeLeft(int[] dice) {
        int tmp = dice[5];
        dice[5] = dice[1];
        dice[1] = dice[0];
        dice[0] = dice[3];
        dice[3] = tmp;
        return dice[2];
    }
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int x, a, b;
  std::cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b)) {
    std::cout << "A" << std::endl;
  } else {
    std::cout << "B" << std::endl;
  }
}


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

ll dp[55][2];

int main(){
	ll n,p;
	cin >> n >> p;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	dp[0][a[0]%2] = 1;
	dp[0][0] += 1;
	REP(i,n-1){
		rep(j,2){
			dp[i][(j+a[i])%2] += dp[i-1][j];
			dp[i][j] += dp[i-1][j];
		}
	}
	ll ans = dp[n-1][p];
	cout << ans << endl;
    return 0;
}



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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s;

int main(){
	cin>>s;
  rep(i,s.size()-1){
    if(s.substr(i,2)=="AC"){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
	return 0;
}


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

typedef long long int ll;
using ii= pair<ll,ll>;
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001

class prioritize{
    public: bool operator() (ii &p1,ii &p2){
        return p1.F<p2.F;
    }
};

int main()
{
    
    #ifndef ONLINE_JUDGE
        freopen("input1.txt","r", stdin);
        freopen("output1.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll k;
    cin>>k;

    ll num=7;
    ll cc=1;
    ll x=k;
    num= (num+k)%k;
    while(num%k!=0&&cc<=k){

        num = (((num+k)%k)*((10+k)%k))%k + 7;
        //cout<<num<<" ";
        cc++;
    }

    if(num%k==0) cout<<cc<<"\n";
    else cout<<-1<<"\n";

}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;
using ll = long long;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];

    ll dp[41][2];
    for (int m = 0; m <= 40; ++m) {
        ll score[2] = {0, 0};
        for (int i = 0; i < n; ++i) {
            score[1 - ((a[i] >> m) & 1)] += (1LL << m);
        }

        dp[m][0] = max(score[0], score[1]) + (m == 0 ? 0 : dp[m - 1][0]);
        if ((k >> m) & 1) {
            dp[m][1] = max(score[0] + (m == 0 ? 0 : dp[m - 1][0]),
                           score[1] + (m == 0 ? 0 : dp[m - 1][1]));
        } else {
            dp[m][1] = score[0] + (m == 0 ? 0 : dp[m - 1][1]);
        }
    }

    cout << dp[40][1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

//最大公約数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

//素数判定(True/Falseを返却)
int IsPrime_tf(ll num){
    if (num < 2) return false; //0、1は素数でない
    else if (num == 2) return true; //2は素数
    else if (num%2==0) return false; // 偶数はあらかじめ除く
    for (ll i = 3; i*i <= num; i += 2){ //チェックは2～√nで十分
        if (num % i == 0) return false; //素数でない
    }
    return true; //素数である
}

//素数判定(割れる値を返却)
ll IsPrime_value(ll num){
    if (num < 2) return -1; //0、1は素数でない
    else if (num == 2) return 2; //2は素数
    for (ll i = 2; i*i <= num; i += 1){ //チェックは2～√nで十分
        if (num % i == 0) return i; //素数でない
    }
    return num; //素数である
}

int main(){
   int n;
   string s;
   cin >> n >> s;
   int a=0, b=0; 
   rep(i,n) if(s[i]=='R') ++a; //Rの数をカウント
   int ans = max(a,b); //境界を一番左においたとき=Rを全てwに変換する
   rep(i,n){ //境界を1つ左にずらす
       if(s[i]=='R') --a; //境界より左の石がRならRの数を減らすだけ(RRRWWWWWのような形を目指すので、左にあるRはスワップ、変換する必要無)
       else ++b; //境界より左の石がWならwの数を+1
       int now = max(a,b); //aとbの最大値が処理回数(a=4、b=2なら2回スワップして、2回変換の計4回の処理)
       ans = min(ans,now); //暫定で最小の解を保存しておく
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define INF -(1<<30)
typedef pair<int,int>P;
void update(int i,int x);
P query(int a,int b,int i,int l,int r);
int n=1;
P dat[400009];
int sum[100009];

int main(){
  int m,q,l;
  int t[1000009];
  cin>>m>>q>>l;
  t[q]=l;
  while(n<m)n*=2;
  for(int i=0;i<n*2-1;i++){
    dat[i].fi=0;
    dat[i].se=0;
  }
  for(int i=1;i<=n;i++){
    update(i,0);
  }
  for(int i=0;i<=q;i++){
    int d,x;
    if(i!=q)cin>>d>>t[i]>>x;
    int id=n-dat[0].se;
    int time;
    if(i)time=t[i]-t[i-1];
    else time=t[i];
    sum[id]+=time;
    if(i!=q)update(d,x);
  }

  int mx=-1,ans;
  for(int i=1;i<=m;i++){
    if(mx<sum[i]){
      mx=sum[i];
      ans=i;
    }
  }
  cout<<ans<<endl;
  return(0);
}

void update(int i,int x){
  i=n-i;
  int j=i+n-1;
  dat[j].fi+=x;
  dat[j].se=i;
  while(j>0){
    j=(j-1)/2;
    dat[j]=max(dat[j*2+1],dat[j*2+2]);
  }
}




Measured memory_bytes: 8744
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;
vector<int> tree[100001];
int dp[100001][2];

// 0 = white, 1 = black
int solve(int curr, int color, int pr) {
    if(!tree[curr].size()) {
        if(color == 0) return 2;
        else return 1;
    }

    if(dp[curr][color] != -1) return dp[curr][color];

    int ans = 0, w1 = 1;
    for(auto child: tree[curr]) {
        if(child != pr) w1 = (w1*solve(child, 0, curr))%mod;
    }
    ans+= w1;

    if(!color) {
        int w2 = 1;
        for(auto child: tree[curr]) {
            if(child != pr) w2 = (w2*solve(child, 1, curr))%mod;
        }
        ans+= w2;
    }
    return dp[curr][color] = ans%mod;
}

int32_t main() {
    int N; cin>>N;
    for(int i=0; i<N-1; i++) {
        int x, y; cin>>x>>y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    memset(dp, -1, sizeof dp);
    cout<<solve(1, 0, -1)<<endl;
    return 0;
}


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

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

    long long double_factor = 1;
    long long sum = 0;

    while(1){
        if(double_factor > h){
            break;
        }  
        sum += double_factor;
        double_factor = double_factor * 2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3560