akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 1200000
#define offset 50000
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
int n,x,y,z,m;
bool invalid[tam];
bool valid[tam];
ll p10[tam];
const ll MOD=1e9+7;
ll dp[42][262144];
ll dammask;
int go(int pos,int mask)
{
    //<<invalid[mask]<<" "<<mask<<" "<<valid[mask]<<endl;;
    if (mask>=(1<<m)|| invalid[mask])
        return 0;
    //<<dp[pos][mask]<<" aca"<<endl;
    if (pos>n)
        return 0;
    if (valid[mask])
        return p10[n-pos];
    //<<dp[pos][mask]<<" aca"<<endl;
    //<<dp[pos][mask]<<" aca"<<endl;
    if (dp[pos][mask]!=-1)
        return dp[pos][mask];
    int tot=0,auxmask;
    forr(i,1,11)
    {
        auxmask=(mask<<i)+(1<<(i-1));
        auxmask^=(auxmask&dammask);
        tot+=go(pos+1,auxmask);
        while(tot>=MOD)tot-=MOD;
    }
    return dp[pos][mask]=tot;
}

int main()
{
    cin>>n>>x>>y>>z;
    p10[0]=1;
    forr(i,1,n+10)
    {
        p10[i]=(p10[i-1]*10)%MOD;
        //<<p10[i]<<" ";
    }
    dammask=0;
    m=x+y+z;
    forr(i,m,30)
    dammask|=(1<<i);
    forr(mask,(1<<(m-1)),(1<<m))
    {
        int c=1,tot=0,tipo=1;
        bool nop=false;
        for(int bit=m-2;bit>=0;bit--)
        {
            if ((mask&(1<<bit)))
            {
                if (c>10)
                    nop=1;
                tot+=c;
                if (tipo==1&& tot==x)
                    tipo=2,tot=0;
                if (tipo==2&& tot==y)
                    tipo=3,tot=0;
                c=1;
            }
            else c++;
        }
        tot+=c;
        invalid[mask]=nop;
        if (tipo==3&& tot==z)
            tipo=4;
        if (tipo==4)
            valid[mask]=1;
        //<<mask<<" "<<valid[mask]<<" "<<invalid[mask]<<endl;
    }
    //<<m<<endl;
    memset(dp,-1,sizeof dp);
    cout<<go(0,0)<<endl;
}

Measured memory_bytes: 90368
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
string s;
ll dp[100001][3];
ll maxval(ll i,ll sum_p){
	if(i==s.length()){
		if(sum_p==1) return 0;
		else return 1;
	}
	if(dp[i][sum_p]!=-1){
		return dp[i][sum_p]%mod;
	}

	if(s[i]=='0'){
		return dp[i][sum_p]=(maxval(i+1,sum_p)%mod+2*maxval(i+1,1)%mod)%mod;
	}
	else {
		return dp[i][sum_p]=(2*maxval(i+1,sum_p)%mod+maxval(i+1,0)%mod)%mod;
	}
}
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>s;
	memset(dp,-1,sizeof(dp));
	reverse(all(s));

	k=maxval(0,0)%mod;
	cout<<k;
	return 0;
}


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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2) ans*=a, ans%=(mod);
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,_;
	ll n;
	cin >> n;
	ll x[n], y[n];
	rep(i,0,n) cin >> x[i] >> y[i];
	ll a[n], b[n];
	rep(i,0,n) a[i] = x[i] + y[i], b[i] = x[i] - y[i];
	sort(a, a + n);
	sort(b, b + n);
	cout << max(abs(a[n-1]-a[0]), abs(b[n-1]-b[0])) << endl;
}

int main()
{
	ios::sync_with_stdio(0);
 	cin.tie(0);
	ll T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




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

int main() {    
    /* Input */
    string S, T;
    cin >> S;
    cin >> T;
    /* Main Logic */
    int ans = 0;
    rep (i, S.length()) {
        if (S[i] != T[i]) ans++;
    }
    /* Output */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3924
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int n,p = 0,i;
  char buf[1000000];
  char *tok,ch;
  int min,max;
  long long sum;
  scanf("%d", &n);
  while((ch = fgetc(stdin)) != '\n') {};
  int a[n];
  fgets(buf, sizeof(buf), stdin);
  tok = strtok(buf, " ");
  while(tok != NULL) {
    a[p++] = atoi(tok);
    tok = strtok(NULL, " ");
  }
  min = a[0];
  max = a[0];
  sum = 0;
  for(i = 0; i < n; i++) {
    if(min > a[i])
      min = a[i];
    if(max < a[i])
      max = a[i];
    sum += a[i];
  }
  printf("%d %d %lld\n", min, max, sum);
  return 0;
}

Measured memory_bytes: 728
import math

n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]

x, y = ta[0]
for i in range(1, n):
    t, a = ta[i]
    k = max(-(-x // t), -(-y // a))
    x, y = k * t, k * a

print(x + y)


Measured memory_bytes: 3188
N=int(input())
X=input()
A=[0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1]

ppx=0

for i in range(N):
  if X[i]=="1":
    ppx+=1
if ppx<=1:
  ppxm1=1
else:
  ppxm1=ppx-1
Xmod=[0,0]
XmodP=[0]*N
XmodM=[0]*N
XmodP[0]=1%(ppx+1)
XmodM[0]=1%(ppxm1)
Xmod=[XmodP[0]*(X[-1]=="1"),XmodM[0]*(X[-1]=="1")]
for i in range(N-1):
  XmodP[i+1]=(XmodP[i]*2)%(ppx+1)
  XmodM[i+1]=(XmodM[i]*2)%(ppxm1)
  if X[-2-i]=="1":
    Xmod[0]=(Xmod[0]+XmodP[i+1])%(ppx+1)
    Xmod[1]=(Xmod[1]+XmodM[i+1])%(ppxm1)
for i in range(N):
  if X[i]=="0":
    Xm=(Xmod[0]+XmodP[-1-i])%(ppx+1)
  else:
    Xm=(Xmod[1]-XmodM[-1-i])%(ppxm1)
  if ppx==1 and X[i]=="1":
    print(0)
  elif Xm==0:
    print(1)
  else:
    px=0
    temp=Xm
    while temp>0:
      if temp%2==1:
        px+=1
        temp=(temp-1)/2
      else:
        temp=temp/2
    p=Xm%px
    print(A[p]+2)

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

int main()
{ 
 ll h1,m1,h2,m2;
 cin>>h1>>m1>>h2>>m2;
 ll k;
 cin>>k;
 ll ans=0;
 ans=abs(h2-h1)*60+(m2-m1)-k;
 cout<<ans;


    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long a, b;
	cin >> a >> b;
	
	long long ret = a * b / __gcd(a, b);
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int H, A;
    cin >> H >> A;

    cout << H/A+(H%A>0) << endl;
}

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

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

// (x, y) を始点とした BFS をして、(x, y) から最も遠いマスへの距離を答える
int bfs(const vector<string> &v, int x, int y) {
    int H = v.size(), W = v[0].size();
    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int,int>> que;

    int res = 0;
    que.push({x, y});
    dist[x][y] = 0;
    while (!que.empty()) {
        int x = que.front().first, y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = x+ dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (v[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    return res;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    for (int i = 0; i < H; ++i) cin >> v[i];

    int res = 0;
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            if (v[x][y] == '#') continue;
            res = max(res, bfs(v, x, y));
        }
    }
    cout << res << endl;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pb push_back
using namespace std;

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

Measured memory_bytes: 256
#!/usr/bin/env pypy3
# -*- coding: UTF-8 -*-

n,t=map(int,input().split())
a=[int(i) for i in input().split()]
ans=chk=0
for i in a:
    if chk<=i:
        ans=ans+t
        chk=i+t
    else:
        ans=ans+((i+t)-chk)
        chk=chk+((i+t)-chk)

print(ans)

Measured memory_bytes: 86224
package main

import (
	"bufio"
	"fmt"
	"os"
	_ "sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func convertToInt(s []string, len int) []int {
	ret := make([]int, len)
	for i := 0; i < len; i++ {
		ret[i], _ = strconv.Atoi(s[i])
	}
	return ret
}

func main() {
	line := nextLine()
	cols := strings.Split(line, " ")
	A, _ := strconv.Atoi(cols[0])
	B, _ := strconv.Atoi(cols[1])
	K, _ := strconv.Atoi(cols[2])
	isTakahashiTurn := true

	for i := 0; i < K; i++ {
		if isTakahashiTurn {
			if A%2 == 1 {
				A = A - 1
			}
			B = B + A/2
			A = A / 2
			isTakahashiTurn = false
		} else {
			if B%2 == 1 {
				B = B - 1
			}
			A = A + B/2
			B = B / 2
			isTakahashiTurn = true
		}
	}
	fmt.Printf("%d %d\n", A, B)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
int main(){
    int e,d;
    scanf("%d %d",&d,&e);
    if (e==d){
        printf("%d",d+d);
    }
    else if (d>e){
        printf("%d",d+d-1);
    }
    else{
        printf("%d",e+e-1);
    }
    
    
    return 0;
}


Measured memory_bytes: 1684
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;



int main(){
    long long A,B,C,K;
    cin>>A>>B>>C>>K;
    
    long long ans=A-B;
    ans*= (K%2)?(-1):1;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
memo = [[0 for _ in range(w)] for _ in range(h)]
step = [[1, 0], [-1, 0], [0, 1], [0, -1]]

memo[0][0] = 1
white = 0
for row in maze:
    white += row.count('.')

q = [[0, 0, 0]]

while q:
    x, y, c = q.pop(0)
    for a, b in step:
        next_x = x + a
        next_y = y + b
        if next_x == h - 1 and next_y == w - 1:
            print(white - (c + 2))
            exit()
        if next_x >= h or next_x < 0:
            continue
        if next_y >= w or next_y < 0:
            continue
        if memo[next_x][next_y] == 1:
            continue
        if maze[next_x][next_y] == '#':
            continue
        memo[next_x][next_y] = 1
        q.append([next_x, next_y, c + 1])
print(-1)


Measured memory_bytes: 3064
use std::cmp::*;
use std::io::{self, Read};
use std::iter::FromIterator;

#[allow(dead_code)]
struct Source {
    chars: Box<Iterator<Item = char>>,
}

#[allow(dead_code)]
impl Source {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }

    fn from_stdin() -> Self {
        let mut data = String::new();
        io::stdin().read_to_string(&mut data).expect("Input error");
        Self::from_str(&data)
    }

    fn from_str(s: &str) -> Self {
        let data = String::from(s);
        let chars = data.chars().collect::<Vec<char>>().into_iter();
        Source {
            chars: Box::new(chars),
        }
    }
}

#[allow(unused_macros)]
macro_rules! input {
    ($src:expr; $($elem:tt)*) => {
        input_inner!($src, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

fn main() {
    let mut src = Source::from_stdin();
    input! { src;
             n: usize, m: usize, x: mut [i32; m],
    }

    x.sort();

    let mut y = vec![];
    for i in 0..m - 1 {
        y.push(x[i + 1] - x[i] - 1)
    }

    y.sort();

    let mut res = 0;
    for i in 0..max(0, m as i32 - n as i32) {
        res += y[i as usize];
    }

    //println!("{}", res);

    println!("{}", max(0, res + m as i32 - n as i32))
}


Measured memory_bytes: 10492
#include<iostream>
using namespace std;
int main(){
  unsigned long A, B, C, D;
  cin >> A >> B >> C >> D;
  unsigned long a_c=0, a_d=0, a_cd=0, b_c=0, b_d=0, b_cd=0;
  unsigned long c, d, r;
  if(C<D){
    d=D;
    c=C;
    r=d%c;
  }else{
    d=C;
    c=D;
    r=d%c;
  }
  while(r!=0){
    d=c;
    c=r;
    r=d%c;
  }
  a_c = (A-1)/C;
  a_d = (A-1)/D;
  a_cd = (A-1)/(C*D/c);
  b_c = B/C;
  b_d = B/D;
  b_cd = B/(C*D/c);
  unsigned long ans;
  ans = (B - (b_c + b_d - b_cd)) - (A - (a_c + a_d - a_cd) - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  for(int i=0; i<s.size(); ++i)
  {
    int id = s[i]-'A';
    id +=n;
    id %=26;
    cout << char(id+'A');
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int64_t GCD(int64_t a, int64_t b) {
	if (!b) return a;
	else return GCD(b, a % b);
}

int main() {
	int64_t N, X;
	cin >> N >> X;

	vector<int64_t> d(N);
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		d[i] = abs(n - X);
	}

	int64_t ans = d[0];
	for (int i = 1; i < d.size(); i++) {
		ans = GCD(ans, d[i]);
	}

	cout << ans << endl;
}

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

int main()
{
  int n;
  cin>>n;
  bool bad = false;
  int arr[4];
  int i=0;
  while(n!=0)
  {
    arr[i] = n%10;
    n/=10;
    i++;
  }
  for(int i=0;i<3;i++)
    if(arr[i] == arr[i+1])
      bad = true;
  if(bad)
    cout<<"Bad";
  else
    cout<<"Good";
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max() - 1;
constexpr auto llinf = numeric_limits<ll>().max() - 1LL;

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << *it << " ";
	}
	cout << endl;
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << (*it).first << ":" << (*it).second << " ";
	}
	cout << endl;
}
template<typename T>
void debug(initializer_list<T> list) {
  for (auto el : list) {
    cout << el << " ";
  }
  cout << endl;
}

constexpr ll mod = ll(1e9 + 7);

ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll power(ll a, ll b) {
	ll result = 1LL;
	while (b) {
		if (b % 2LL) result = mult(result, a);
		a = mult(a, a);
		b /= 2LL;
	}
	return result;
}

ll divide(ll a, ll b) { return mult(a, power(b, mod - 2)); }

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }

ll subtract(ll a, ll b) { return ((a - b) % mod + mod) % mod; }

int n, m, x;
int c[15];
int a[15][15];

void solve() {
	cin >> n >> m >> x;
	rep(i, n) {
		cin >> c[i];
		rep(j, m) cin >> a[i][j];
	}
	int mnm = inf;
	rep (bits, 1 << n) {
		vi books(m, 0);
		int cost = 0;
		rep(i, n) {
			if (bits & (1 << i)) {
				cost += c[i];
				rep(j, m) books[j] += a[i][j];
			}
		}
		bool done = true;
		rep(i, m) {
			if (books[i] < x) {
				done = false;
				break;
			}
		}
		if (done) mnm = min(mnm, cost);
	}
	if (mnm == inf) cout << "-1";
	else cout << mnm;
	cout << "\n";
}

#define REPEAT 0
#define CASE 0

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#if REPEAT
		int t;
		cin >> t;
		repa(i, 1, t) {
			#if CASE
				cout << "Case #" << i << ": ";
			#endif
			solve();
		}
	#else
		solve();
	#endif
	return 0;
}


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

const int INF = 1<<28;

class SegmentTree {
private:
  int n;
  vector<int> dat1, dat2, lazy;

public:
  SegmentTree() {}

  SegmentTree(int _n) {
    n = 1;
    while (n < _n) n *= 2;
    dat1 = dat2 = lazy = vector<int>(n*2-1, 0);
  }

  inline void evaluation(int k, int l, int r) {
    dat1[k] += (r - l) * lazy[k];
    dat2[k] += lazy[k];
    if (k < n-1) {
      lazy[k*2+1] += lazy[k];
      lazy[k*2+2] += lazy[k];
    }
    lazy[k] = 0;
  }

  void add(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    evaluation(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] += x;
      evaluation(k, l, r);
      return;
    }
    add(a, b, x, k*2+1, l, (l+r)/2);
    add(a, b, x, k*2+2, (l+r)/2, r);
    dat1[k] += dat1[k*2+1] + dat1[k*2+2];
    dat2[k] = min(dat2[k*2+1], dat2[k*2+2]);
  }

  int sum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    evaluation(k, l, r);
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return dat1[k];
    int v1 = sum(a, b, k*2+1, l, (l+r)/2);
    int v2 = sum(a, b, k*2+2, (l+r)/2, r);
    return v1 + v2;
  }

  int mini(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    evaluation(k, l, r);
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return dat2[k];
    int v1 = mini(a, b, k*2+1, l, (l+r)/2);
    int v2 = mini(a, b, k*2+2, (l+r)/2, r);
    return min(v1, v2);
  }
};

int N, Q;
string s;
set<int> cs;
SegmentTree seg;

void init() {
  cs = set<int>();
  seg = SegmentTree(N);
  for (int i = 0; i < N; ++i) {
    if (s[i] == ')') cs.insert(i);
    seg.add(i, N, s[i] == '(' ? +1 : -1);
  }
}

void change(int index) {
  if (s[index] == '(') {
    s[index] = ')';
    seg.add(index, N, -2);
    cs.insert(index);
  } else {
    s[index] = '(';
    seg.add(index, N, +2);
    cs.erase(index);
  }
}

int main() {
  while (cin >> N >> Q) {
    cin >> s;
    init();
    while (Q--) {
      int q; cin >> q; --q;
      if (s[q] == '(') { // '(' => ')'
        change(q);
        int p = *cs.begin();
        cout << p + 1 << endl;
        change(p);
      } else { // ')' => '('
        change(q);
        int l = 0, r = N;
        while (r-l) {
          int m = (l + r) / 2;
          if (seg.mini(m, N) > 1) {
            r = m;
          } else {
            l = m+1;
          }
        }
        cout << r + 1 << endl;
        change(r);
      }
    }
  }
  return 0;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N,K;
list<int> edge [2001];
const int INF = 1e9;

void dfs(int curr,int prev,int cost,vector<int>& min_cost)
{
	chmin(min_cost [curr],cost);
	for(auto&& it : edge [curr]) if(it != prev){
		dfs(it,curr,cost + 1,min_cost);
	}
}

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

	cin >> N >> K;
	FOR(i,0,N - 1){
		int A,B;
		cin >> A >> B;
		edge [A].push_back(B);
		edge [B].push_back(A);
	}

	int ans = INF;
	if(K % 2 == 0){
		for(int i = 1;i <= N;i++){
			int cnt = 0;
			vector<int> min_cost(N + 1,INF);
			dfs(i,-1,0,min_cost);
			for(int i = 1;i <= N;i++){
				if(min_cost [i] > K / 2) cnt++;
			}
			chmin(ans,cnt);
		}
	}
	else{
		vector<int> min_cost(N + 1,INF);
		for(int i = 1;i <= N;i++){
			for(auto&& it : edge [i]) if(it > i){
				int cnt = 0;
				vector<int> min_cost(N + 1,INF);
				dfs(i,-1,0,min_cost); dfs(it,-1,0,min_cost);
				for(int i = 1;i <= N;i++){
					if(min_cost [i] > K / 2) cnt++;
				}
				chmin(ans,cnt);
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>
using namespace std;

int main(){
  int n,q,counter = 0;
  queue<string> name;
  queue<int> time;
  cin >> n >> q;
  string str;
  int buf;
  for(int i=0; i<n; i++){
    cin >> str >> buf;
    name.push(str);
    time.push(buf);
  }

  //RR???????£?
  while(!time.empty()){
    buf = time.front();
    str = name.front();
    time.pop();
    name.pop();
    if(buf > q){
      buf -= q;
      name.push(str);
      time.push(buf);
      counter += q;
    }
    else{
        counter += buf;
      cout << str << " " << counter << endl;
    }
  }
}

Measured memory_bytes: 4176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int A,B,C,K; cin>>A>>B>>C>>K;

    int ans=0;
    while(B<=A){
        ans++;
        B*=2;
    }
    while(C<=B){
        ans++;
        C*=2;
    }

    string sans="No";
    if(ans<=K) sans="Yes";
    cout<<sans<<endl;
}

Measured memory_bytes: 3620
N = int(input())
A = list(map(int,input().split()))
money = 1000
i = 0
while i < N-1:
    k = i
    while A[i]<=A[i+1]:
        i += 1
        if i >= N-1:
            break
    money += (A[i]-A[k])*(money//A[k])
    if i >= N-1:
        break
    while A[i]>A[i+1]:
        i += 1
        if i >= N-1:
            break
print(money)

Measured memory_bytes: 9168
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
using Graph = vector<VE>;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k; cin >> n >> k;
	int cnt = 0;
	string s; cin >> s;
	rep(i, n-1)if (s[i] == s[i + 1])cnt++;
	cout << min(cnt + 2 * k, n - 1);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
    int X = 0,w = 0 ;
    char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}
vector<int> edg[100005];
int dp[100005];
bool vis[100005];
int in[100005];
int n,m;

int dfs(int x)
{
    if(dp[x]>0)
    {
        return dp[x];
    }
    for(int i=0;i<edg[x].size();i++)
    {
        dp[x]=max(dp[x],dfs(edg[x][i])+1);
    }
    return dp[x];
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        edg[x].push_back(y);
        in[y]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(in[i]==0)
        {
            dfs(i);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(dp[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
int gx,gy,sx,sy;
int map[102][102];
bool flag[102][102];
int xx[]={3,1};
int yy[]={1,3};
int xv[]={0,1,0,-1};
int yv[]={1,0,-1,0};
void cal(int X,int Y){
	flag[X][Y]=1;
	for(int i=0;i<4;i++){
		if(map[X][Y]==map[X+xv[i]][Y+yv[i]]&&!flag[X+xv[i]][Y+yv[i]]){
			cal(X+xv[i],Y+yv[i]);
		}
	}
}

int main(){
	for(int w,h,n;cin>>w>>h,w;){
		memset(map,0,sizeof(map));
		memset(flag,0,sizeof(flag));
		cin>>sx>>sy;
		cin>>gx>>gy;
		for(cin>>n;n>0;n--){
			int c,d,x,y;
			cin>>c>>d>>x>>y;
			for(int X=x;X<=x+xx[d];X++){
				for(int Y=y;Y<=y+yy[d];Y++){
					map[X][Y]=c;
				}
			}
		}
		if(map[sx][sy])cal(sx,sy);
		if(flag[gx][gy])cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1216
fn main() {
    let vs = read_vec::<usize>();
    let n = vs[0];
    let k = vs[1];
    let q = vs[2];
    let mut a_vec = Vec::new();
    for i in 0..q {
        a_vec.push(read::<usize>())
    }
    solve(n, k as isize, q as isize, a_vec);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn solve(n: usize, k: isize, q: isize, a_vec: Vec<usize>) {
    let mut points: Vec<isize> = vec![k - q; n];
    for i in a_vec {
        points[i - 1] += 1;
    }
    for p in points {
        if p > 0 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

Measured memory_bytes: 6780
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  double a,b,x;
  cin >> a >> b >> x;
  double ans;
  if(a*a*b/2 < x){
    double h = 2*(a*a*b-x)/(a*a);
    ans = atan2(h,a);
  }else{
    double w = 2.0*x/(a*b);
    ans = atan2(b,w);
  }
  ans = ans * 180.0 / PI;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  int n = (int)s.size();
  bool f = false;
  for(int i = 0; i < n - 1; ++i){
    f |= s[i] == 'A' && s[i+1] == 'C';
  }
  cout << (f?"Yes":"No") << endl;
}

Measured memory_bytes: 3636
n = gets.to_i
i = 1
while true
  x = i
  if x % 3 == 0
    print " ",i
  else
    loop do
      if x % 10 == 3
         print " ",i
         break
      end
      x /= 10
      break if x == 0
    end
  end
  i += 1
  break if (i > n)
end
print "\n"


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

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

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int64_t N, K, A[2000];
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> A[i];
    BIT<int> bit(2001);
    int64_t inv = 0;
    for(int i=0; i<N; i++){
        inv += bit.sum_between(A[i]+1, 2000);
        bit.plus(A[i], 1);
    }
    int64_t ans = inv * K % MOD;
    int64_t C = K*(K-1)/2 % MOD;
    for(int i=0; i<N; i++){
        int64_t res = bit.sum_between(0, A[i]-1);
        add(ans, res*C);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
         
        int a,b;
 
        while(cin.hasNext())
        {
            a=cin.nextInt();
            b=cin.nextInt();
         
            String s = ((Integer)(a+b)).toString();
            System.out.println(s.length());
        }
    }
}

Measured memory_bytes: 20436
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int a, b;
int main(void){
    cin >> a >> b;
    if (a > b) cout << a - 1 << '\n';
    else cout << a << '\n';
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  String po[]=sc.next().split("",0);
  int x=0,y=0;
  for(int i=0;i<n;i++){
    y+=(po[i].equals("I"))?1:-1;
    x=Math.max(x,y);
  }
    System.out.println(x);
}
}


Measured memory_bytes: 22996
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *NOIP 2019 RP++                                           *
 ***********************************************************/
//#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
    char *pp = (char*)malloc(size) + size;  \
    __asm__("movl %0, %%esp\n" :: "r"(pp))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) ((x>y)?x:y)
#define Min(x,y) ((x<y)?x:y)
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register int a=b;a<=c;++a)
#define FORD(a,b,c) for (register int a=b;a>=c;--a)
using namespace std;
//char buf[1<<20],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline ll read(){
    ll x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}
template<typename T>
inline void write(T a){
    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//

signed main(){
	#ifdef _WIN32
        freopen("0.in","r",stdin);
//        freopen("0.out","w",stdout);
//        ADD_STACK;
        long double be=clock();
    #endif
	ll w=read(),h=read(),x=read(),y=read();
	printf("%.10Lf ",(long double)(w*h)/2.000000000000000000000000000000);
	if(2ll*x==w&&2ll*y==h)puts("1");else puts("0");
	#ifdef _WIN32
        long double en=clock();
        printf("Time: %.0Lfms\n",en-be);
        fclose(stdin);fclose(stdout);
    #endif
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        boolean flag = true;
        int count = 0;
        while (flag) {
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 == 0) {
                    a[i] = a[i] / 2;
                } else {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 24276
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){

    string S;
    cin >> S;

    int s = 0, ans = 0;
    for (int i = 0; i < S.length(); i++){
        if (S[i] == 'T'){
            if (s == 0){
                ans ++;
            }else{
                s--;
            }
        }else{
            s ++;
        }
    }
    
    cout << ans * 2 << endl;

    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = input()

if n == "SUN":
    print(7)
elif n == "MON":
    print(6)
elif n == "TUE":
    print(5)
elif n == "WED":
    print(4)
elif n == "THU":
    print(3)
elif n == "FRI":
    print(2)
elif n == "SAT":
    print(1)

Measured memory_bytes: 3060
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b== c || b + c == a || c + a == b)  cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String N=scan.nextLine();
        if(N.charAt(0)=='7'||N.charAt(1)=='7'||N.charAt(2)=='7'){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26944
A, B, C = map(int, input().split())
K = int(input())

c = 0
while B <= A:
    B *= 2
    c += 1
    if K < c:
        print("No")
        exit()

while C <= B:
    C *= 2
    c += 1
    if K < c:
        print("No")
        exit()

print("Yes")



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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

vector< vector<int> > to = {
  {2},
  {2, 5},
  {0, 1, 3, 6},
  {2, 7},
  {5},
  {1, 4, 6, 9},
  {2, 5, 7, 10},
  {3, 6, 8, 11},
  {7},
  {5, 10},
  {6, 9, 11, 12},
  {7, 10},
  {10}
};

vector<int> ans = {0,1,2,3,4,5,6,7,8,9,10,11,0};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  map<vector<int>, int> D;  
  queue< vector<int> > que;
  que.push(ans);
  D[ans] = 0;
  while(!que.empty()) {
    auto v = que.front(); que.pop();
    if(D[v] >= 10) break;
    rep(i, v.size()) {
      if(v[i]) continue;
      rep(j, to[i].size()) {
	int c = D[v];
	swap(v[i], v[to[i][j]]);
	if(!D.count(v)) {
	  que.push(v);
	  D[v] = c + 1;
	}
	swap(v[i], v[to[i][j]]);
      }
    }
  }
  
  int p;
  while(cin >> p, ~p) {
    vector<int> pzl; pzl.push_back(p);
    rep(i, 12) cin >> p, pzl.push_back(p);
    if(D.count(pzl)) {
      cout << D[pzl] << endl;
      continue;
    }
    map<vector<int>, int> d;
    queue< vector<int> > que;
    que.push(pzl);
    d[pzl] = 0;
    bool flag = false;
    while(!que.empty() && !flag) {
      auto v = que.front(); que.pop();
      if(d[v] >= 10) break;      
      rep(i, v.size()) {
	if(v[i]) continue;
	rep(j, to[i].size()) {
	  int c = d[v];
	  swap(v[i], v[to[i][j]]);
	  if(D.count(v)) {
	    cout << D[v] + c + 1 << endl;
	    flag = true;
	    break;
	  } else if(!d.count(v)) {
	    que.push(v);
	    d[v] = c + 1;
	  }
	  swap(v[i], v[to[i][j]]);
	}
	if(flag) break;
      }
    }
    if(!flag) cout << "NA" << endl;
  }
  return 0;
}

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

int head[100005],cnt,vis[100005],color[100005],col,n,m;

ll ans,sum[3],ttot,ltot;

struct edge{
	int to,nxt,w;
}e[200005];

void add(int u,int v,int w){
	e[++cnt]=(edge){v,head[u],w};
	head[u]=cnt;
}

void dfs(int u){
	vis[u]=1;ttot++;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to,w=e[i].w;
		if(w>0) ltot++;
		if(vis[v]){
			if(color[v]!=(color[u]+w+3)%3) col=-1;
			continue;
		}
		color[v]=(color[u]+w+3)%3;
		if(col!=-1&&sum[color[v]]==0) col++;
		sum[color[v]]++;
		dfs(v);
	}
}

signed main(){
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		add(u,v,1);add(v,u,-1);
	}
	for(int i=1;i<=n;i++) if(!vis[i]){
		ttot=ltot=0;col=1;
		sum[0]=1;sum[1]=sum[2]=0;
		color[i]=0;
		dfs(i);
		if(col==-1) ans+=ttot*ttot;
		else if(col==3) ans+=sum[0]*sum[1]+sum[1]*sum[2]+sum[2]*sum[0];
		else ans+=ltot;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 6912
#include <iostream>

using namespace std;

typedef long long ll;


int l, k;
ll dp[200];

ll dfs(int h){
	if (dp[h]>=0) return dp[h];
	//printf("h: %d\n", h);
	ll ret=1;
	if (h>l) return dp[h] = 0;
	if (h>l-2) return dp[h] = ret;
	ret += dfs(h+2);
	if (h<=l-(k+1)) ret += dfs(h+k+1);
	//printf("h: %d, ret: %lld\n", h, ret);
	return dp[h] = ret;
}

int main(){
	cin >> l >> k;
	for (int i=0; i<200; i++){
		dp[i] = -1;
	}
	cout << dfs(1) + dfs(k) << endl;
	return 0;
}


Measured memory_bytes: 3120
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def doubling(MAX, A):
    """ ダブリング """

    N = len(A)
    nxt = list2d(MAX, N, -1)
    for i, a in enumerate(A):
        nxt[0][i] = a
    for k in range(1, MAX):
        for i in range(N):
            nxt[k][i] = nxt[k-1][nxt[k-1][i]]
    return nxt

N, K = MAP()
A = [a-1 for a in LIST()]
MAX = 64

nxt = doubling(MAX, A)

ans = 0
for k in range(MAX-1, -1, -1):
    if K >> k & 1:
        ans = nxt[k][ans]
print(ans+1)


Measured memory_bytes: 176660
N = int(input())

lists = [0]*4
for i in range(N):
  s = input()
  if "AC"==s:
    lists[0] += 1
  elif "WA"==s:
    lists[1] += 1
  elif "TLE"==s:
    lists[2] += 1
  else:
    lists[3] += 1

print("AC x {}".format(lists[0]))
print("WA x {}".format(lists[1]))
print("TLE x {}".format(lists[2]))
print("RE x {}".format(lists[3]))

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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B==C+D){
    cout<<"Balanced"<<endl;
    return 0;
  }else{
    cout<<(A+B<C+D ? "Right" : "Left")<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
P = []
for _ in range(N):
  P.append(list(map(int, input().split())))
X = sorted(set([p[0] for p in P]))
Y = sorted(set([p[1] for p in P]))

res = (X[-1] - X[0]) * (Y[-1] - Y[0])
cs = [[0] * (len(Y)) for _ in range(len(X))]

for i in range(len(X)):
  for j in range(len(Y)):
    for p in P:
      if X[0] <= p[0] <= X[i] and Y[0] <= p[1] <= Y[j]:
        cs[i][j] += 1
for l in range(len(X) - 1):
  for r in range(l + 1, len(X)):
    for d in range(len(Y) - 1):
      for u in range(d + 1, len(Y)):
        a = cs[r][u]
        if l > 0:
          a -= cs[l - 1][u]
        if d > 0:
          a -= cs[r][d - 1]
        if l > 0 and d > 0:
          a += cs[l - 1][d - 1]
        if a >= M:
          #print(X[l], X[r], Y[d], Y[u], abs(X[r] - X[l]) * abs(Y[u] - Y[d]), a, l, r, d, u)
          res = min(res, abs(X[r] - X[l]) * abs(Y[u] - Y[d]))
print(res)

Measured memory_bytes: 46956