akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  string S;
  ll K;
  cin >> S >> K;
  vector<ll> N(100, 0L);
  int count = 0;
  while(count < (int)S.size()) {
    if(S[count] == '1')
      count++;
    else
      break;
  }
  if(K <= count || count == (int)S.size())
    cout << '1' << endl;
  else
    cout << S[count] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Max 100005
int N;
struct Node{int p ,l,r;};
Node T[Max];
int D[Max];

void setDepth(int u, int p){
  D[u] = p;
  if(T[u].r != -1)setDepth(T[u].r, p);
  if(T[u].l != -1)setDepth(T[u].l, p+1);
}

void print(int u){
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);
  if(T[u].p == -1)printf("root, ");
  else if(T[u].l == -1)printf("leaf, ");
  else printf("internal node, ");
  printf("[");

  for(int i=0, c = T[u].l; c != -1; ++i, c = T[c].r){
    if(i)printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

main()
{
  int id, k, c, l;
  scanf("%d", &N);
  for(int i=0; i<N; ++i)T[i].p = T[i].l = T[i].r = -1;

  for(int i=0; i<N; ++i){
    scanf("%d%d", &id, &k);

    for(int j=0; j<k; ++j){
      scanf("%d", &c);
      if(j == 0)T[id].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = id;
    }

  }

  for(int i=0; i<N; ++i){
    if(T[i].p == -1){
      setDepth(i, 0);
      break;
    }
  }

  for(int i=0; i<N; ++i)print(i);

}

Measured memory_bytes: 7888
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 100005;
int N, M, a[maxn];
ll s1[maxn], s2[maxn];
void mark(int l, int r) {
    int t;
    if(l < r) {
	t = r - l;
	s1[1] += t;
	s1[r + 1] += t;
	s2[l + 2] -= 1;
	s2[r + 2] += 1;
    } else {
	t = r - l + M;
	s1[1] += r;
	s1[r + 1] += t;
	s2[2] -= 1;
	s2[r + 2] += 1;
	s2[l + 2] -= 1;
    }
}
int main() {
    scanf("%d %d", &N, &M);
    scanf("%d", a + 1);
    for(int i = 2; i <= N; ++i) {
	scanf("%d", a + i);
	mark(a[i - 1], a[i]);
    }
    ll ans = ~0ULL>>1;
    for(int i = 1; i <= M; ++i) {
	s1[i] += s1[i - 1];
	s2[i] += s2[i - 1];
	s1[i] += s2[i];
	ans = min(ans, s1[i]);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb emplace_back
#define pii pair<int,int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}
int main()
{
    int l=read(),r=read(),d=read();
    int ans=r/d-(l-1)/d;
    cout<<ans<<endl;
}


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

#define ll unsigned long long

using namespace std;

int main()
{
    int n,k,res = 0,x;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        if(x >= k) res++;
    }
    cout << res;
}


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

int main() {
    int a, n, h_max, cnt = 1;

    cin >> n >> h_max;

    for (int i = 0; i < n - 1; i++) {
        cin >> a;

        if (a >= h_max) {
            h_max = a;
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        
        String N = stdIn.next();
        if (N.charAt(0) == N.charAt(1) || N.charAt(1) == N.charAt(2) || N.charAt(2) == N.charAt(3))
            System.out.print("Bad");
        else
            System.out.print("Good");
    }
}

Measured memory_bytes: 23380
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <ctime>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;
 
#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define bug cout<<88888888<<endl;
#define MIN(x,y) (x<y?x:y)
#define MAX(x,y) (x>y?x:y)
 
LL N;
LL A[MaxN];
//a2-a1 - num / N
int main()
{
    LL sum = 0;
    scanf("%lld", &N);
    for(int i=0;i<N;i++)
    {
        scanf("%lld", &A[i]);
        sum+=A[i];
    }
    LL tmp = (1+N)*N/2;
    if(sum%tmp) printf("NO\n");
    else
    {
        int flag = 0;
        LL num = sum/tmp;
        LL x=0;
        LL y=0;
        for(int i=0;i<N;i++)
        {
            LL d;
            if(i==0) d = A[0]-A[N-1];
            else d = A[i] - A[i-1];
            d = d + num*(N-1);
            
            if( d % N !=0  )
            {
                flag = 1;
                break;
            }
            else
            {
                d = d/N;
                if(d<0 || d>num)
                {
                    flag = 1;
                    break;
                }
                else
                {
                    x+=d;
                    y+=(num-d);
                }
            }
 
        }
        if(flag) printf("NO\n");
        else
        {
            //cout << x << " " << y << endl;
            if( (x - y*(N-1)) == 0) printf("YES\n");
            else printf("NO\n");
        }
    }
   // system("pause");
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int l, i=0, a[5];
    while(cin>>l){
        a[i] = l;
        i++;
    }
  if(a[0]+a[1]>a[2]+a[3]){
  	printf("Left");
  }else if(a[0]+a[1]<a[2]+a[3]){
  	printf("Right");
  }else{
    printf("Balanced");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	string a,b;
	cin >> a >> b;
	cout << "A" << b[0] << "C" << endl;
}

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

public class Main {
    public static void main(String args[]) throws IOException  {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String strArr[] = br.readLine().split(" ");
        int intArr[] = new int[strArr.length];

        for (int i = 0; i < intArr.length; i++) {
            intArr[i] = Integer.parseInt(strArr[i]);
        }

        if (intArr[0] > intArr[1]) {
            // [0]と[1]を並び替え
            int tmp = intArr[0];
            intArr[0] = intArr[1];
            intArr[1] = tmp;
        }
        if (intArr[1] > intArr[2]) {
            // [1]と[2]を並び替え
            int tmp = intArr[1];
            intArr[1] = intArr[2];
            intArr[2] = tmp;
        }
        if (intArr[0] > intArr[1]) {
            // [0]と[1]を並び替え
            int tmp = intArr[0];
            intArr[0] = intArr[1];
            intArr[1] = tmp;
        }
        System.out.println(intArr[0] + " " + intArr[1] + " " + intArr[2]);
    }
}



Measured memory_bytes: 24380
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 1e6 + 5;
const int M = N * 2;

bool win[N] , vis[N];

int fir[N], ne[M] , to[M] , cnt, a[N] , n;

void add(int x , int y) {
	ne[++ cnt] = fir[x]; fir[x] = cnt; to[cnt] = y;
}

void link(int x, int y) {
	add(x , y); add(y , x);
}

vector<int>Vec;

#define Foreachson(i , x) for(int i = fir[x];i;i = ne[i])

void get(int x) {
	if(vis[x]) return;
	vis[x] = 1;
	win[x] = 0;
	Foreachson(i , x) {
		int V = to[i];
		if(a[V] < a[x]) {
			win[x] = 1;
		}
	}
	if(!win[x]) return;
	bool flag = 0;
	Foreachson(i , x) {
		int V = to[i];
		if(a[V] < a[x]) {
			get(V);
			if(!win[V]) flag = 1;
		}
	} 
	win[x] = flag;
}

int main(void) {
//	freopen("C.in" , "r" , stdin);
//	freopen("C.out" , "w" , stdout);
	scanf("%d" , &n);
	for(int i = 1;i <= n;i ++) scanf("%d" , &a[i]);
	int x , y;
	for(int i = 1;i <n;i ++) {
		scanf("%d%d" , &x , &y);
		link(x , y);
	}
	for(int i = 1;i <= n;i ++) {
		get(i);
		if(win[i]) Vec.push_back(i);
	}
	sort(Vec.begin() , Vec.end());
	for(int i = 0;i < (int) Vec.size();i ++) printf("%d " , Vec[i]);
	puts("");
}

Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

int gcd(int m, int n){
    if(m < n){
        return gcd(n, m);
    } else if (n == 0){
        return m;
    } 
    return gcd(n, m % n);
}

long long lcm(int m, int n){
    return (long long) m * (long long) n / gcd(m, n);
}

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

    string S;
    string T;
    cin >> S;
    cin >> T;

    long long length = lcm(N, M);
    long long s_step = length / N;
    long long t_step = length / M;

    bool good = true;
    for(int i = 0; i < N; i++){
        if(i * s_step % t_step == 0){
            if(S[i] != T[(long long)i * s_step / t_step]){
                good = false;
                break;
            }
        }
    }
    for(int i = 0; i < M; i++){
        if(i * t_step % s_step == 0){
            if(T[i] != S[(long long)i * t_step / s_step]){
                good = false;
                break;
            }
        }
    }

    if(good){
        cout << length << endl;
    } else {
        cout << - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 512
var data = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  data += chunk;
} )

readable.on( 'end', function() {
  var x = parseInt( data );
  console.log( '%d', Math.pow( x, 3 ) );
} )

Measured memory_bytes: 7644
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	}

	public static void bubble(int A[], int n)
	{
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	}

	public static void trace(int A[], int n)
	{
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 26220
#include<iostream>
#include<vector>
using namespace std;
int main() {
	long n;
	cin >> n;
	vector <long long> x;
	for (long i = 0; i < n; i++)
	{
		int y;
		cin >> y;
		if (y == 0)
		{
			long long m;
			cin >> m;
			x.push_back(m);
		}
		else if (y == 1)
		{
			long p;
			cin >> p;
			cout << x[p] << endl;
		}
		else if (y == 2)
		{
			x.pop_back();
		}
	}
	return 0;
}


Measured memory_bytes: 4928
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    int f = 0;
    for(int i=1;i<=3;i++)
        if((a*b*i)%2!=0)
            f = 1;
    if(f)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a, b ,n;
    cin >> a >> b >> n;
    ll ans;
    if(n < b)
    {
        ans = a * n / b - a *(n  /b);
    }
    else
    {
        n = b - 1;
        ans = a * n / b - a *(n  / b);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 100005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
int K, N;
/* function */
/* main */
int main(){
    cin >> N >> K;
    ll ans = 0;
    for (int x = 1; x <= N; x++) {
        int r = N % x;
        int p = N / x;
        ans += p * max(0, x - K) + max(0, r - K + 1);
    }
    if (K == 0) {
        ans -= N;
    }
    cout << ans << '\n';
}


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

int main(){
    int k;
    cin >> k;
    int num[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << num[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,n;
	char op;
	scanf("%d %c %d",&a,&op,&b);
	if(op=='+'){
		n=a+b;
	}
	else{
		n=a-b;
	}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 128
m = 998244353
def main():
    n,k = map(int,input().split())
    l,r = [],[]
    for _ in range(k):
        l_, r_ = map(int,input().split())
        l.append(l_)
        r.append(r_)

    dp = [0]*(n+1)
    dp[1] = 1
    dpsum = [0]*(n+1)
    dpsum[1] = 1

    for i in range(2,n+1):
        for j in range(k):
            li = i - r[j]
            ri = i - l[j]
            if ri < 0:
                continue
            li = max(li,1)
            dp[i] += dpsum[ri] - dpsum[li-1]
        dpsum[i] = (dpsum[i-1]+dp[i])%m

    print(dp[n]%m)
main()

Measured memory_bytes: 24784
#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int n; cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1];
    
}

Measured memory_bytes: 1024
#############<------------  Xorcestor_X ---------------->############

from math import *


def is_even(p):
    n=len(p)
    count=0
    for i in range(n):
        index=p.index(i,i,n)
        if i==index:
            pass
        else:
            count+=1
            temp=p[i]
            p[i]=p[index]
            p[index]=temp
    # print(p)
    if count%2==0:
        return True
    else:
        return False



prime=[]

def SieveOfEratosthenes():
    global prime
    prime=[1]*2000010
    prime[1]=0
    p=2
    while p*p<=2000001:
        if prime[p]:
            for i in range(p*p,2000002,p):
                prime[i]=0

lpf=[]

def precompute():
    global lpf
    lpf=[0]*1000001
    for i in range(2,1000001):
        if not lpf[i]:
            for j in range(i,1000001,i):
                if not lpf[j]:
                    lpf[j]=i


def binpow(a,b):
    res=1
    while b>0:
        if b&1:
            res*=a
        a*=a
        b>>=1
    return res


def modpow(a,b,x):
    res=1
    while b>0:
        if b&1:
            res*=a
            res%=x
        a*=a
        a%=x
        b>>=1
    return res

cont=[]

def f(x):
    global cont
    total=0
    for i in cont:
        total+=abs(i-x)
    return total


def bs(low,high,target):
    while low+3<high:
        mid=(low+high)/2
        if arr[mid]<target:
            low=mid
        else:
            high=mid-1
    for i in range(high,low-1,-1):
        if arr[o]<target:
            return i
    return -1


def ternary_search(l,r):
    while r-l>10:
        m1=l+(r-l)/3
        m2=r-(r-l)/3
        f1=f(m1)
        f2=f(m2)
        if f1>f2:
            l=m1
        else:
            r=m2

    mino=f(l)

    for i in range(l,r+1):
        mino=min(mino,f(i))

    return mino

a,b,c=[int(i) for i in input().split()]
k=int(input())

arr=[c,b,a]
count=0
while arr[1]<=arr[2]:
    arr[1]*=2
    count+=1

while arr[0]<=arr[1]:
    arr[0]*=2
    count+=1

if count<=k:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9332
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

int main(){
	string s;
	cin>>s;
	bool ok=true;
	rep(i,s.size()){
		if(i%2==0){
			if(s.at(i)=='L'){
				ok=false;
				break;
			}
		}else{
			if(s.at(i)=='R'){
				ok=false;
				break;
			}
		}
	}
	if(ok){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

int main()
{
    string s;
    long long k;
    cin>>s>>k;
    for(long long i=0;i<s.size();i++)
    {
        if(i==k-1 && s[i]=='1')
        {
            cout<<"1";return 0;
        }
        if(s[i]!='1')
        {cout<<s[i];return 0;}
    }
    cout<<"1";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;
string st,st1;
int main()
{
    cin>>st;
    st1=st.substr(1,st.size()-2);
    cout<<st[0]<<st1.size()<<st[st.size()-1];

    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int x;
	cin>>x;
	cout<<(x<1200?"ABC":"ARC")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,k,ans;
int main(){
	scanf("%d%d",&n,&k);
	ans=1;
	fo(i,1,n){
		if (ans<=k) ans<<=1;else ans+=k;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std; 
 
int main() 
{ 

    int n;
    cin>>n;

    int cnt=0,continuous=0;
    for(int i=0;i<n;i++){
        int p;
        cin>>p;

        bool flg,flg_n,flg_cnt;
        if(p==i+1){
            cnt++;
            flg=true;
        }else
            flg=false;

        if(flg&&flg_n&&i>0)
            flg_cnt=true;
        else
            flg_cnt=false;
        
        if(flg_cnt)
            continuous++;
        else{
            if(continuous%2==0)
                cnt-=continuous/2;
            else
                cnt-=(continuous+1)/2;
            continuous=0;
        }

        flg_n=flg;
    }

    if(continuous%2==0)
        cnt-=continuous/2;
    else
        cnt-=(continuous+1)/2;

    cout<<cnt<<endl;

    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
ll gcd(ll a, ll b) {
    if (a < b) gcd(b, a);
    ll r = 1;
    while (r != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}
int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll M = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        M = max(M, a[i]);
    }
    ll g = 0;
    g = a[0];
    for (int i = 1; i < n; i++) {
        g = gcd(g, a[i]);
    }
    if (k >= g && k % g == 0 && k <= M) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 1024
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.21 02:54:47
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

constexpr int MOD = 1e9 + 7;
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((MOD+x)%MOD) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= MOD;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = MOD - 2;
        mint u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

struct Combination {
private:
    int N;
    vector< mint > FACT, IFACT;
    
    mint pow(mint k, ll n) {
        mint res = 1;
        while (n > 0) {
            if (n & 1) {
                res *= k;
            }
            k *= k;
            n >>= 1;
        }
        return res;
    }
public:
    
    Combination(int n) : N(n) {
        FACT.resize(n + 1);
        IFACT.resize(n + 1);
        FACT[0] = 1;
        IFACT[0] = 1;
        for (int i = 1; i <= n; i++) {
            FACT[i] = FACT[i - 1] * i;
            IFACT[i] = pow(FACT[i], MOD - 2);
        }
    }
    mint comb(int n, int r) {
        if (n < 0 || r < 0 || r > n) return 0;
        if (r > n / 2) r = n - r;
        return FACT[n] * IFACT[n - r] * IFACT[r];
    }
};
int main() {
    int r1,r2,c1,c2;cin >> r1 >> c1 >> r2 >> c2;
    Combination cb(r2 + c2 + 2);
    mint ans = 0;
    for (int i = r1; i <= r2; i++) {
        ans += cb.comb(c2 + i + 1,c2) - cb.comb(c1 + i,c1 - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34260
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};



int main(){
    LL n;cin >> n;
    vector<int> a(n);
    map<int,int> ma;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ma[a[i]]++;
    }
    vector<bool> p(1000001,0);
    for (int i = 1; i <= 1000000; i++) {
        if(ma[i]){
            for (int j = 2; j * i <= 1000000; j++) {
                p[i * j] = true;
            }
        }
    }
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        if(ma[a[i]] != 1 || p[a[i]]) continue;
        else ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 50984
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int a[30];

void show(int n){
  for(int i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[n-1]);
}

void dfs(int x,int n,int ma){
  if(x==0) show(n);
  else{
    for(int i=min(x,ma);i>=1;i--){
      a[n] = i;
      dfs(x-i,n+1,i);
    }
  }
}

bool solve(){
  int n;
  scanf("%d",&n);
  if(n==0) return false;
  dfs(n,0,n);
  return true;
}

int main(){
  while(1) if(!solve()) return 0;
}

Measured memory_bytes: 2680
#include <stdio.h>
#define MAX 10000
#define nil -1

struct node{
	int p,l,r;
};

struct node T[MAX];
int n;

void preparse(int u){
	if(u==nil){
		return;
	}
	printf(" %d",u);
	preparse(T[u].l);
	preparse(T[u].r);
}

void inparse(int u){
	if(u==nil){
		return;
	}
	inparse(T[u].l);
	printf(" %d",u);
	inparse(T[u].r);
}

void postparse(int u){
	if(u==nil){
		return;
	}
	postparse(T[u].l);
	postparse(T[u].r);
	printf(" %d",u);
}

int main(void){
	int i,v,l,r,root;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		T[i].p=nil;
	}
	for(i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
	T[v].l=l;
	T[v].r=r;
		if(l!=nil){
			T[l].p=v;
		}
		if(r!=nil){
			T[r].p=v;
		}
	}
	for(i=0;i<n;i++){
		if(T[i].p==nil){
			root=i;
		}
	}
	
	printf("Preorder\n");
	preparse(root);
	printf("\n");
	printf("Inorder\n");
	inparse(root);
	printf("\n");
	printf("Postorder\n");
	postparse(root);
	printf("\n");
	
	return 0;
	
}


Measured memory_bytes: 2104
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;

string func(stack<int>,stack<int>,stack<int>);

int main(){
		  stack<int> s,st,right,left;
		  int loop,num;

		  cin>>loop;
		  for(int i=0;i<loop;i++){

					 while(!s.empty()) s.pop();
					 while(!st.empty()) st.pop();
					 while(!right.empty()) right.pop();
					 while(!left.empty()) left.pop();
					 right.push(0);left.push(0);

					 for(int l=0;l<10;l++){
								cin>>num;
								s.push(num);
					 }
					 while(!s.empty()){
								st.push(s.top());
								s.pop();
					 }

					 cout<<func(st,right,left)<<endl;
		  }
		  return 0;
}

string func(stack<int> st,stack<int> right, stack<int> left){
		  if(st.empty()) return "YES";

		  if(right.top()<st.top()){
					 right.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(right.top());
								right.pop();
					 }
		  }
		  if( left.top()<st.top()){
					 left.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(left.top());
								left.pop();
					 }
		  }

		  return "NO";
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

vector<pair<int,int>> aaa(0);
int main()
{
    cin >> N;

    for (ll i = (2); i*i <= N; i++)
    {
        if(N % i != 0) continue;
        B=0;

        while(N%i==0)
        {
            N /= i;
            B++;
        }
        if(B != 0)aaa.push_back(pair<int,int>(i,B));
    }
    if(N != 1)aaa.push_back(pair<int,int>(N,1));

    int sum;
    rep(i,aaa.size())
    {
        sum = 0;

        E = aaa[i].second;
        rep2(i,1,20)
        {
            if(E>=i)
            {
                E -= i;
                sum++;
            }
            else 
            {
                break;
            }

        }
        D += sum;
    }

    cout << D;

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
long val[105];
long weight[105];
long d[105][100005];
long dp(int i, int w, int n);

int main()
{
  memset(d,-1,sizeof d);
  int n, w;
  cin >> n >> w;
  for(int i = 1; i <= n; i++)
  {
    cin >> weight[i] >> val[i];
  }
  // for(int i = 1; i <= n; i++) cout << weight[i] << ' ';
  // cout << endl;
  // for(int i = 1; i <= n; i++) cout << val[i] << ' ';
  // cout << endl;
  cout << dp(1, w, n) << endl;
  // for(int i = 1; i <= n; i++) cout << d[i] << ' ';
  // cout << endl;
}

long dp(int i, int w, int n)
{
  //cout << w << endl;
  if(i > n || w == 0) return 0;
  if(d[i][w] != -1) return d[i][w]; 
  if(weight[i] > w)
  {
    return dp(i + 1, w, n);
  }
  else
  {
    long a = dp(i + 1, w - weight[i], n) + val[i];
    long b = dp(i + 1, w, n);
    //cout << a << ' ' << b << endl;
    d[i][w] = max(a,b);
    return d[i][w];
  }
}

Measured memory_bytes: 82304
#include <iostream>
#define REP(i, a, n) for(int (i) = (a); (i) <= (n); (i)++)
using namespace std;

int main(void) {
  long N, M;
  cin >> N >> M;

  long cnt = 0;

  if(N * 2 <= M) {
    cnt += N;
    M -= N * 2;
    cnt += M / 4;
  } else {
    cnt += M / 2;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

d = defaultdict(int)
c = 0

for _ in range(int(input())):
    s = list(input())
    s.sort()
    s1 = ''
    for i in s:
        s1 += i
    s = s1

    if s in d:
        c += d[s]
        d[s] += 1
    else:
        d[s] += 1

print(c)

Measured memory_bytes: 18184
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
// セグメントツリー
template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat; 
    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }                                                                                                              
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};


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

int main(){
        int n;cin>>n;
        SegTree<ll> T(n,[](ll a,ll b){return gcd(a,b);},0);
        for(int i=0;i<n;i++){
            ll tmp;cin>>tmp;
            T.set(i,tmp);
        }
        T.build();
        ll res=0;
        for(int i=0;i<n;i++){
            ll left=T.get(0,i);
            ll right=T.get(i+1,n);
            res=max(res,gcd(left,right));
        }
        cout<<res<<endl;
}



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

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 1e9+7;

// code begins here

int main(){
    fast;
    
    ll n, k;
    cin>>n>>k;
    
    vector<ll> arr(n);
    for(auto &u: arr)
        cin>>u;
    
    vector<ll> dp(k+1);
    
    for(ll i=0;i<=k;i++){
        for(auto u: arr){
            if( i>=u && !dp[i-u] )
                dp[i] = 1;
        }
    }
    
    cout<< ( dp[k] ? "First" : "Second" ) <<endl;
    
    return 0;
}

Measured memory_bytes: 3996
unittest
{
	assert( [ "6", "abcabc" ].parse.expand.solve == "Yes" );
	assert( [ "6", "abcadc" ].parse.expand.solve == "No" );
	assert( [ "1", "z" ].parse.expand.solve == "No" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	return ( s[ 0 .. $ / 2 ] == s[ $ / 2 .. $ ] ) ? "Yes" : "No";
}


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

using ll = long long;
using pii = pair<int, int>;

template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> A(H);
    for(int i = 0; i < H; ++i) {
        cin >> A[i];
    }
    
    queue<pii> que;
    vector<vector<int>> d(H, vector<int>(W, inf<int>));
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(A[i][j] == 'S') {
                que.emplace(i, j);
                d[i][j] = 0;
            }
        }
    }
    while(!que.empty()) {
        int y = que.front().first, x = que.front().second;
        que.pop();
        for(int i = 0; i < 4; ++i) {
            int ny = y + dy[i], nx = x + dx[i];
            if(ny < 0 || H <= ny || nx < 0 || W <= nx || d[ny][nx] != inf<int> || A[ny][nx] == '#') {
                continue;
            }
            d[ny][nx] = d[y][x] + 1;
            if(d[ny][nx] < K) {
                que.emplace(ny, nx);
            }
        }
    }

    int res = inf<int>;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(d[i][j] == inf<int>) {
                continue;
            }
            int dist_y = min(H - i - 1, i);
            int dist_x = min(j, W - j - 1);
            int dist = min(dist_y, dist_x);
            res = min(res, (dist + K - 1) / K + 1);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define endl '\n'
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;


int32_t main(){
    vaibhavv06;
	int n,k; cin>>n>>k;
    // int dp[k+1]={0};
    vector<int> dp(k+1);
    dp[0]=1;
    for(int child = 0;child<n;child++){
        int upto; cin>>upto;
        // int fake[k+1]={0};
        vector<int> fake(k+1);
        for(int used=k;used>=0;used--){
            int temp = dp[used];
            int l = used+1;
            int r = used + min(upto,k-used);
            if(l<=r){
                fake[l]+=temp;
                fake[l]%=MOD;
                if(r+1<=k){
                    fake[r+1]-=temp;
                    if(fake[r+1]<0) fake[r+1]+=MOD;
                }
            }
        }
        int prefix = 0;
        for(int i=0;i<=k;i++){
            prefix+=fake[i];
            prefix%=MOD;
            dp[i]+=prefix;
            dp[i]%=MOD;
        }
    }
    cout<<dp[k]<<endl;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll a;
    double b;

    cin >> a >> b;
    ll c = (b+0.001)*100;

    printf ("%lld\n", a*c/100 );

    return 0;
}



Measured memory_bytes: 3788
#input template
from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda: list(map(int, cin().split()))

def chars(): #function for taking string input as character array since string in python is immutable
    s = cin()
    return(list(s[:len(s) - 1]))

#print list	
def pl(a):	
	for val in a:
		cout(val)
		
#main

s = chars()
s[3] = '8'
pl(s)

Measured memory_bytes: 8932
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	long long ans = 0;
	for (int i = 0; i <= n; ++i) {
		if ((i % 3) != 0 && (i % 5) != 0) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = acos(-1) ;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"


int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0;
	int arr[3];
	for(auto &i:arr)
		cin>>i;
	
	while(arr[0]%2==0&&arr[1]%2==0&&arr[2]%2==0)
	{
		x=arr[0],y=arr[1],z=arr[2];
		arr[0]=y/2+z/2;
		arr[1]=x/2+z/2;
		arr[2]=x/2+y/2;
		sum++;
		if(arr[0]==arr[1] && arr[1]==arr[2] &&arr[0]%2==0&&arr[1]%2==0&&arr[2]%2==0 )
		return cout<<-1<<nw,0;
	}
	cout<<sum<<nw;
}


Measured memory_bytes: 3648
n,k = map(int,input().split())

s = list(input())

if s[k-1] == "A" :
    s[k-1] = "a"
    print("".join(s))
elif s[k-1] == "B":
    s[k-1] = "b"
    print("".join(s))
elif s[k-1] == "C":
    s[k-1] = "c"
    print("".join(s))


Measured memory_bytes: 8940
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);

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

  double th = double(H * 60 + M) / 720 * 2 * pi;
  double tm = double(M) / 60 * 2 * pi;
  double xh = A * cos(th), yh = A * sin(th);
  double xm = B * cos(tm), ym = B * sin(tm);
  double dx = xh - xm, dy = yh - ym;
  double ans = sqrt(dx * dx + dy * dy);
  printf("%.10f\n", ans);
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin>>n;
    bool aprov = true;
    while (n--) {
        int x;
        cin>>x;
        if (x%2 == 0 && x%3 != 0 && x%5 != 0) aprov = false;
    }
    if (aprov) cout<<"APPROVED\n";
    else cout<<"DENIED\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))
int main(void){
	char s[5];
	scanf("%s",s);
	bool mmyy=false,yymm=false;
	if(s[0]=='0' && s[1]!='0')mmyy=true;
	else if(s[0]=='1' && (s[1]=='0' ||s[1]=='1'||s[1]=='2'))mmyy=true;
	if(s[2]=='0' && s[3]!='0')yymm=true;
	else if(s[2]=='1' && (s[3]=='0' ||s[3]=='1'||s[3]=='2'))yymm=true;
	
	
	if(mmyy && yymm)printf("AMBIGUOUS");
	else if(mmyy)printf("MMYY");
	else if(yymm)printf("YYMM");
	else printf("NA");
	return 0;
}

Measured memory_bytes: 128
N,A,B,C,D = map(int,input().split())
S = input()

if "##" in S[A-1:max(C,D)-1]:
  print("No")
  exit()
if C < D:
  print("Yes")
  exit()

count = 0
for i in range(B-1,D):
  if D != len(S): 
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
      print("Yes")
      exit()
print("No")

Measured memory_bytes: 9384
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

class robot{
	public:
		bool l[2]={false};
		bool r[2]={false};
		bool ghost=false;
};

int main(void) {
	int n; cin >> n;
	vector<pair<int,int>> xl(n); rep(i,n) cin >> xl[i].first >> xl[i].second;
	rep(i,n) xl[i].first+=xl[i].second;
	SORT(xl);
	rep(i,n) xl[i].first-=xl[i].second;
	int ans = 0;
	int x = -INF;
	rep(i,n){
		if(x<=xl[i].first-xl[i].second){
			ans++;
			x = xl[i].first+xl[i].second;
		}
	}
	out(ans);
}




Measured memory_bytes: 1024
# 入力
n, m = map(int, input().split())
s = [[] for i in range(m)]
for i in range(m):
    lines = [int(k) for k in input().split()]
    for j in range(1, len(lines)):
        s[i].append(lines[j] - 1)
p = [int(i) for i in input().split()]

# 処理
ans = 0
for i in range(1 << n):  # 2 ** n でも同じ
    switches = [0] * n  #
    flag = True
    for j in range(n):  # switchesリストの作成(全てのスイッチの状態を列挙)
        if (i >> j) & 1:  # iをj回右にシフトして1と論理積をとる(最下位の桁が1かcheck)
            switches[j] = 1
    for k in range(m):  # 行
        cnt = 0  # ついているスイッチの数
        for t in range(len(s[k])):  # 列
            if switches[s[k][t]] == 1:
                cnt += 1
        if cnt % 2 != p[k]:  # 等しいときにTrue
            flag = False
            break  # p_iの条件を満たさないので次の行へ
    if flag:  # 全ての電球が点灯する
        ans += 1

# 出力
print(ans)


Measured memory_bytes: 41072
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int cop; int dat1[400000]; int dat2[400000];
void init(int cop_) {
	cop = 1;
	while (cop < cop_)cop *= 2;
	rep(i, 2*cop-1) {
		dat1[i] = (int)MOD;
		dat2[i] = (int)MOD;
	}
}
void update1(int k, int a) {
	k += cop - 1;
	dat1[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat1[k] = min(dat1[k * 2 + 1], dat1[k * 2 + 2]);
	}
}
void update2(int k, int a) {
	k += cop - 1;
	dat2[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat2[k] = min(dat2[k * 2 + 1], dat2[k * 2 + 2]);
	}
}
int query1(int a,int b,int k,int l,int r) {
	if (r <= a || b <= l)return (int)MOD;
	if (a <= l && r <= b)return dat1[k];
	else {
		int vl = query1(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query1(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}
int query2(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return (int)MOD;
	if (a <= l && r <= b)return dat2[k];
	else {
		int vl = query2(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query2(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}
int main() {
	int n; cin >> n;
	cop = n;
	init(cop);
	int a[100000]; int exr[100000]; int exl[100000];
	vector<int>ex; vector<int> ex2;
	int len = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] == 0) {
			ex.push_back(i);
			ex2.push_back(-i);
			len++;
		}
	}
	sort(ex2.begin(), ex2.end());
	if (len == 0) {
		cout << 0 << endl; return 0;
	}
	rep(i, n) {
		if(a[i]<0) {
			update1(i, -i - a[i]);
			update2(i, i - a[i]);
		}
		int r = lower_bound(ex.begin(), ex.end(), i) - ex.begin();
		int l = lower_bound(ex2.begin(), ex2.end(), -i) - ex2.begin();
		if (r < len) {
			exr[i] = ex[r];
		}
		else {
			exr[i] = -1;
		}
		if (l < len) {
			exl[i] = -ex2[l];
		}
		else {
			exl[i] = -1;
		}
	}
	int cnt = 0;
	rep(i, n) {
		if (a[i] <= 0)continue;
		int ma = 0;
		int lr;
		if (exr[i] != -1) {
			lr = query1(i, exr[i], 0, 0, cop)+i;
			if (lr >= 0) {
				ma = max(ma, min(lr,a[i]));
			}
		}
		if (exl[i] != -1) {
			lr = query2(exl[i], i, 0, 0, cop)-i;
			if (lr >= 0) {
				ma = max(ma, min(lr, a[i]));
			}
		}
		cnt += ma;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 7144
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

vector<vector<LL>> graph;
vector<bool> check;
vector<LL> sum;
vector<LL> ans;

void dfs(int x, LL sumv) {
  check[x] = true;
  ans[x] = sumv;
  for (int i = 0; i < graph[x].size(); i ++) {
    int y = graph[x][i];
    if (!check[y]) {
      dfs(y, sumv + sum[y]);
    }
  }
}

int main() {
  LL n, q;
  cin >> n >> q;
  graph = vector<vector<LL>>(n);
  rep(i, n - 1) {
    LL a, b; cin >> a >> b;
    a --, b --;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  check = vector<bool>(n, false);
  sum = vector<LL>(n, 0);
  ans = vector<LL>(n);
  rep(i, q) {
    LL p, x;
    cin >> p >> x;
    p --;
    sum[p] += x;
  }

  dfs(0, sum[0]);

  rep(i, n) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 25856