akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll res = 0;
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.*;


public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        String pat = "\\b(\\z*"+sc.nextLine()+"\\z*)\\b";
        Pattern r = Pattern.compile(pat);
        
    
        
        
        int count = 0;
        while(true){
            String words = sc.next();
            String lowCase;
            if (words.equals("END_OF_TEXT")) {
                break;
            }else{
                lowCase = words.toLowerCase();
            }
            Matcher m = r.matcher(lowCase);
    
            if (m.find()) {
                count++;
            }
        }
        System.out.println(count);
        
    }
}



Measured memory_bytes: 26024
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    p=parseMap(split(readline()))
    flg=true
    ans=0
    for i in 1:n
        if p[i]==i && flg
            ans+=1
            flg=false
        else
            flg=true
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 118632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    cin >> N;
    VVL G(N);
    VL A(N-1), B(N-1);
    rep(i, 0, N-1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        A[i] = a; B[i] = b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    map<PL,ll> mp;
    queue<PL> que;
    que.push({0, -1});
    VB seen(N, false);
    while(!que.empty()){
        auto q = que.front();
        que.pop();
        seen[q.first] = true;
        ll cl = 1;
        for(auto g : G[q.first]){
            if(seen[g]) continue;
            if(cl == q.second) cl++;
            seen[g] = true;
            que.push({g,cl});
            mp[{q.first,g}] = cl;
            mp[{g,q.first}] = cl;
            cl++;
        }
    }

    ll mx = 0;
    rep(i, 0, N-1) mx = max(mx, mp[{A[i],B[i]}]);
    cout << mx << endl;
    rep(i, 0, N-1) cout << mp[{A[i],B[i]}] << endl;
    return 0;
}

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

vector <int> adj[100001];
int n,m,x,y;
int indegree[100001];
int dp[100001];

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

	cin >> n >> m;

	for(int i=0;i<m;i++)
	{
		cin >> x >> y;
		adj[x].push_back(y);
		indegree[y]++;
	}

	queue <int> que;
	for(int i=1;i<=n;i++)
	{
		if(indegree[i]==0)
		{
			que.push(i);
		}
	}

	int res = 0;

	while(!que.empty())
	{
		int now = que.front();
		que.pop();

		for(auto next : adj[now])
		{
			dp[next] = max(dp[next],dp[now] + 1);
			res = max(res,dp[next]);
			indegree[next]--;
			if(indegree[next]==0)
			{
				que.push(next);
			}
		}
	}

	cout << res << '\n';
	
	return 0;
}


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

// ?¨±?????????????????
#define EPS (1e-10)
// 2??????????????????????????????????????????
#define EQ(a,b) (abs((a)-(b)) < EPS)

typedef complex<double> P;

// ?????? (cross product) : a??b = |a||b|sin??
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

// 2??´?????????????????? : a//b <=> cross(a, b) = 0
int is_parallel(P a1, P a2, P b1, P b2) {
  return EQ( cross(a1-a2, b1-b2), 0.0 );
}
 
int main(){
	int n;
	cin >> n;
	double x1,y1,x2,y2,x3,y3,x4,y4;
	for(int i = 0; i < n; ++i){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		P a(x1,y1), b(x2,y2), c(x3,y3), d(x4,y4);
        if ( is_parallel(a,b,c,d) ) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
	}
    return 0;
}

Measured memory_bytes: 1224
# ABC082C
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = Counter(A)
ans = 0

for x in B:
    if x < C[x]:
        ans += C[x]-x
    elif x > C[x]:
        ans += C[x]

print(ans)

Measured memory_bytes: 24308
#include <bits/stdc++.h>
#define MAXN 100005
#define ll long long

using namespace std;
 
ll a[MAXN][3];
ll dp[MAXN][3];
int n;

ll solve(int day, int flag)
{
	
	if(day >= n)
		return 0;

	if(dp[day][flag] >= 0)
		return dp[day][flag];


	ll max1 = -1;
	if(day == 0)
	{
		max1 = max(max1, a[day][0] + solve(day+1, 0));
		max1 = max(max1, a[day][1] + solve(day+1, 1));
		max1 = max(max1, a[day][2] + solve(day+1, 2));

	}
	else if(flag == 0)
	{
		max1 = max(max1, a[day][1] + solve(day+1, 1));
		max1 = max(max1, a[day][2] + solve(day+1, 2));

	}
	else if(flag == 1)
	{
		max1 = max(max1, a[day][0] + solve(day+1, 0));
		max1 = max(max1, a[day][2] + solve(day+1, 2));
		
	}
	else if(flag = 2)
	{
		max1 = max(max1, a[day][0] + solve(day+1, 0));
		max1 = max(max1, a[day][1] + solve(day+1, 1));
	}

	return dp[day][flag] = max1;

}





int main()
{

	cin >> n;  
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> a[i][j];		
		}
	}
	
	memset(dp, -1, sizeof(dp));


	cout << solve(0, 0) << endl;

 
 
 
    return 0;
}

Measured memory_bytes: 14540
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()



int main()
{
  int x;
  cin >> x;
  long long a = x / 500;
  long long b = (x % 500)  / 5;
  cout << a * 1000 + b * 5 << endl;
  return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    ll a[n+1];
    fill(a, a+n+1, 0);
    a[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i-1];
    }
    
    vector <ll> sa;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j <= n; j++) {
            sa.push_back(a[j] - a[i]);
        }
    }

    ll ans = 0;

    for (int i = 39; i >= 0; i--) {
        vector <ll> tmp;
        for (int j = 0; j < sa.size(); j++) {
            if (sa.at(j) & (1LL<<i)) {
                tmp.push_back(sa.at(j));
            }
            sa.at(j) %= (1LL<<i);
        }

        if (tmp.size() >= k) {
            sa = tmp;
            ans += (1LL<<i);
        }
    }

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

Measured memory_bytes: 6256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int r,g,b;cin>>r>>g>>b;
    int n=r*100+g*10+b;
    if(n%4==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

const long long MOD = 5;
const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long B, long long C){
    for(long long i = 1; i <= B; ++i){
        if(A*i % B == C){
            cout << YES << endl;
            exit(0);
        }
    }
    cout << NO << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        double n = sc.nextInt();
        int d = sc.nextInt();

        System.out.println((int)Math.ceil(n / (2 * d + 1)));
    }
}


Measured memory_bytes: 21972
n = input()
p = [map(int, raw_input().split()) for i in xrange(n)]
for i in xrange(n):
    x1 = p[i-1][0] - p[i-2][0]
    y1 = p[i-1][1] - p[i-2][1]
    x2 = p[i][0] - p[i-2][0]
    y2 = p[i][1] - p[i-2][1]
    if x1*y2 - y1*x2 < 0:
        print 0
        break
else:
    print 1

Measured memory_bytes: 6436
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<cstring>
#include<math.h>
#include<map>
using namespace std;
int main()
{
    char a[4][4];
    while(cin>>a[1][1])
    {


        for(int i=1; i<=2; i++)
            for(int j=1; j<=3; j++)
            {
                if(i==1&&j==1)
                    continue;
                cin>>a[i][j];
            }
        int flag=0;
        if(a[1][1]!=a[2][3]||a[1][2]!=a[2][2]||a[1][3]!=a[2][1])
            flag=1;
        if(flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#define maxn 1000000
using namespace std;
int n,k;
int m=1;
	string s;
struct t{
	int num,dir;
}a[maxn];

void work1(){
	int ans=-1,sum=0;
	for (int i=1;i<=2*k+1;i++) sum+=a[i].num;
		//cout << sum << endl;
	ans=sum;
	for (int i=2*k+2;i<=m;i+=2){
		sum+=a[i].num+a[i+1].num-a[i-k*2-1].num-a[i-k*2].num;
		if (sum>ans) ans=sum;
		//cout << sum << endl;
	}
	cout << ans;
}

void work2(){
	int ans=-1,sum=0;
	for (int i=1;i<=2*k;i++) sum+=a[i].num;
		//cout << sum << endl;
	ans=sum;

	sum+=a[2*k+1].num+a[2*k+2].num-a[1].num;
	if (sum>ans) ans=sum;	

	for (int i=2*k+3;i<=m;i+=2){
		sum+=a[i].num+a[i+1].num-a[i-k*2-1].num-a[i-k*2].num;
		if (sum>ans) ans=sum;
		//cout << sum << endl;
	}
	cout << ans;
}
// 11 2
// 01010110011
void work3(){
	int ans=-1,sum=0;
	for (int i=1;i<=2*k+1;i++) sum+=a[i].num;
		//cout << sum << endl;
	ans=sum;
	for (int i=2*k+2;i<m;i+=2){
		sum+=a[i].num+a[i+1].num-a[i-k*2-1].num-a[i-k*2].num;
		if (sum>ans) ans=sum;
		//cout << sum << endl;
	}
	sum+=a[m].num-a[m-k*2-1].num-a[m-k*2].num;
	if (sum>ans) ans=sum;
	cout << ans;
}
// 15 2
// 111010101100000
void work4(){
	t b[maxn];
	b[1].num=0;b[1].dir=1;
	for (int i=1;i<=m;i++) {
		b[i+1].num=a[i].num;
		b[i+1].dir=a[i].dir;
	}
	b[m+2].num=0;b[m+2].dir=1;
	for (int i=1;i<=m+2;i++) 
	{
		a[i].num=b[i].num;
		a[i].dir=b[i].dir;
	}
	m+=2;
	work1();
}
int main(){
	cin >> n >> k;
	cin >> s;
	
	a[1].num=1;a[1].dir=s[0]-'0';

	for (int i=1;i<n;i++)
		if (s[i]-'0' == a[m].dir) a[m].num++;
			else {
				a[++m].dir=s[i]-'0';
				a[m].num=1;
			}

	if (a[1].dir == 1 && a[m].dir == 1) work1();
	if (a[1].dir == 0 && a[m].dir == 1) work2();
	if (a[1].dir == 1 && a[m].dir == 0) work3();
	if (a[1].dir == 0 && a[m].dir == 0) work4();

}

Measured memory_bytes: 3840
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD

using namespace std;

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

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

  cout << min((2*N + M) / 4, M / 2) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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


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

int main(void){
    int a,b,t,res[101];
	cin >> t;
	for(a=0;a<t;a++){
		int n,b,nn,up=0,down=0;
		cin >> n;
		for(b=0;b<n;b++){
			cin >> res[b];
		}
		for(b=0;b<n-1;b++){
			if(res[b+1]-res[b]>0)up=max(up,res[b+1]-res[b]);
			if(res[b+1]-res[b]<0)down=max(down,res[b]-res[b+1]);
		}
		cout << up << " " << down << endl;
	}
    return 0;
}

Measured memory_bytes: 0
#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 = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
ll A, B, C, D;
/* function */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x;}
ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
ll f (ll x) {
    ll ret = B / x - (A-1) / x;
    return ret;
}
/* main */
int main(){
    cin >> A >> B >> C >> D;
    ll divCorD = f(C) + f(D) - f(lcm(C, D));
    cout << (B - A + 1) - divCorD << '\n';
}


Measured memory_bytes: 3624
#include <cstdio>
#include <set>
#include <cstdlib>
#define LL long long
#define F(i, a, b) for (int i = a; i <= b; ++i)

using namespace std;

const int MS = 1e6 + 5, maxn = 1e6;
int n, a[MS], prim[MS], lowp[MS], low[MS], pcnt = 0;
bool isp[MS];
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
set<int> prims;

int main()
{
	scanf("%d", &n);
	F(i, 1, n) scanf("%d", &a[i]);
	F(i, 2, maxn) isp[i] = true;
	low[1] = 1;
	F(i, 2, maxn)
	{
		if (isp[i]) prim[pcnt++] = i, low[i] = lowp[i] = i;
		for (int j = 0; j < pcnt && (LL)i * prim[j] <= maxn; ++j)
		{
			isp[i * prim[j]] = false;
			lowp[i * prim[j]] = prim[j];
			if (i % prim[j]) low[i * prim[j]] = prim[j];
			else {
				low[i * prim[j]] = low[i] * low[prim[j]];
				break;
			}
		}
	}
	bool flag = false;
	int cgcd = a[1];
	F(i, 2, n) cgcd = gcd(cgcd, a[i]);
	if (cgcd > 1) printf("not coprime"), exit(0);
	F(i, 1, n)
	{
		while (low[a[i]] > 1) 
		{
			if (prims.count(lowp[a[i]]))
			{
				flag = true;
				break;
			}
			prims.insert(lowp[a[i]]);
			a[i] /= low[a[i]];
		}
	}
	if (flag) printf("setwise coprime");
	else printf("pairwise coprime");
	return 0;
}

Measured memory_bytes: 19880
from math import sqrt
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

d = 0
for i in range(n):
    for j in range(i):
        x = a[i] - a[j]
        y = b[i] - b[j]
        d += sqrt(x**2 + y**2)
d *= 2
d /= n
print(d)


Measured memory_bytes: 3064
#include <cstdio>           // printf(), scanf()
#include <cctype>           // isdigit()
#include <set>
#include <iterator>         // distance()
#include <algorithm>        // swap(), sort(), lower_bound(), upper_bound()

using namespace std;
static const int MAX_N = 100000;
enum { BOTTOM = 0, LEFT, RIGHT, TOP };

struct Point
{
	int x;
	int y;
};

struct Segment
{
	Point p1, p2;
};

class EndPoint
{
public:
	Point p;
	int seg; // ??\????????????ID
	int st;  // ??????????¨????

	EndPoint() {}
	EndPoint(Point p, int seg, int st): p(p), seg(seg), st(st) {}
	bool operator < (const EndPoint &ep) const
	{
		// y ??§?¨?????°???????????????´???
		if (p.y != ep.p.y)
			return p.y < ep.p.y;
		else
			return st < ep.st; // y ??????????????´????????????????????????????????????????????????????????????????????????
	}
};

Segment S[MAX_N];
EndPoint EP[2 * MAX_N]; // ??????????????????
int n;

// ??????????????????: ????????????????????????
int
manhattanIntersection()
{
	int k = 0;
	for (int i = 0; i < n; ++i)
	{
		// ?????? p1,p2 ??????????????????????????¶??????????????´
		if (S[i].p1.y == S[i].p2.y)
		{
			if (S[i].p1.x > S[i].p2.x)
				swap(S[i].p1, S[i].p2);
		}

		else if (S[i].p1.y > S[i].p2.y)
			swap(S[i].p1, S[i].p2);

		if (S[i].p1.y == S[i].p2.y) // ?°´????????????????????????????????????
			EP[k++] = EndPoint(S[i].p1, i, LEFT);

		else // ?????´?????????????????????????????????
		{
			EP[k++] = EndPoint(S[i].p1, i, BOTTOM);
			EP[k++] = EndPoint(S[i].p2, i, TOP);
		}
	}

	sort(EP, EP + k); // ????????? y ??§?¨??????¢?????????????????´???

	set<int> BT; // ????????¢?????¨
	BT.insert(1000000001); // ??????????¨????

	int cnt = 0;
	for (int i = 0; i < k; ++i)
	{
		if (EP[i].st == TOP)
			BT.erase(EP[i].p.x); // ??????????????????
		else if (EP[i].st == BOTTOM)
			BT.insert(EP[i].p.x); // ??????????????????
		else if (EP[i].st == LEFT)
		{
			set<int>::iterator b = BT.lower_bound(S[EP[i].seg].p1.x); // O(log n)
			set<int>::iterator e = BT.upper_bound(S[EP[i].seg].p2.x); // O(log n)
			cnt += distance(b, e); // b ??¨ e ????????¢(????????°)????????????O(k)
		}
	}

	return cnt;
}

int
get_int(int* bc)
{
	int n;
	int s;
	int c = *bc;

	while (c == ' ' || c == '\n')
		c = getchar();

	if (c == '-')
	{
		s = -1;
		c = getchar();
	}
	else
		s = 1;

	n = 0;
	while (isdigit(c))
	{
		n = n * 10 + c - '0';
		c = getchar();
	}

	*bc = c;
	n *= s;
	return n;
}

int
main(int argc, char** argv)
{
	int c;

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		// scanf("%d %d %d %d", &S[i].p1.x, &S[i].p1.y, &S[i].p2.x, &S[i].p2.y);
		c = getchar();
		S[i].p1.x = get_int(&c);
		S[i].p1.y = get_int(&c);
		S[i].p2.x = get_int(&c);
		S[i].p2.y = get_int(&c);
	}

	printf("%d\n", manhattanIntersection());
	return 0;
}

Measured memory_bytes: 10160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

#define REP(i,n) for(i=0;i<n;i++)

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i; 
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void sout(char *s) {
    printf("%s\n", s);
}

int main() {
    int A = iin(), B = iin();
    if (B % A == 0) {
        iout(A + B);
    } else {
        iout(B - A);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

#define MAX 100005
 
typedef long long ll;
typedef pair<int, int> P;

struct CARD {
    char sort;
    int num;
    bool operator==(const CARD &c) const { return sort == c.sort && num == c.num; };
    bool operator!=(const CARD &c) const { return sort != c.sort || num != c.num; };
    bool operator<(const CARD &c) const { return num < c.num; };
    bool operator<=(const CARD &c) const { return num <= c.num; };
    CARD(char sort, int num) { this->sort = sort; this->num = num; };
};

template <class T>
int partition(vector<T> &a, int p, int r)
{
    T x = a[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (a[j] <= x) {
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[r], a[i+1]);
    return i+1;
}

template <class T>
void QuickSort(vector<T> &a, int p, int r)
{
    if (p >= r) return;
    int q = partition(a, p, r);
    QuickSort(a, p, q-1);
    QuickSort(a, q+1, r); 
}

int main(int, char**)
{
    int n;
    cin >> n;

    vector<CARD> a;
    char s;
    int t;
    rep(i,n) {
        cin >> s >> t;
        a.emplace_back(s, t);
    }
    vector<CARD> a2 = a;
    QuickSort(a, 0, n-1);
    stable_sort(a2.begin(), a2.end());

    bool stb = true;
    rep(i,n) if (a[i] != a2[i]) stb = false;
    cout << (stb ? "Stable" : "Not stable") << endl;
    rep(i,n) cout << a[i].sort << " " << a[i].num << endl;

    return 0;
}


Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[101];
    for (int i=1; i<=100; i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    cout<<a[n]-a[1];
    return 0;
}

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

fn main() {
    let n = read::<usize>();
    let vec = read_vec::<i64>();
    let mut results: Vec<String> = Vec::new();
    let mut v = vec.iter().enumerate()
        .fold(0 as i64, |acc, (idx, value)| if idx % 2 == 0 {acc + value} else {acc - value});
    results.push(format!("{}", v));
    for i in 0..(n - 1) {
        v = 2 * (vec[i] - (v / 2));
        results.push(format!("{}", v));
    }
    println!("{}", results.join(" "));
}

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

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 12024
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

int main() {
	int h, w;
	cin >> h >> w;
	VI highsum(h+1);
	VI weisum(w+1);
	VS a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '.')highsum[i]++;
			else if (a[i][j] == '#')highsum[i] += 2;
		}
	}
	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h; i++) {
			if (a[i][j] == '.')weisum[j]++;
			else if (a[i][j] == '#')weisum[j] +=2 ;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (highsum[i] == w) continue;
			if (weisum[j] == h) continue;
			cout << a[i][j];
		}
		if(highsum[i]!=w) cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
//const int mod = 1000000007;
const int mod = 998244353;

int calc(int a, int b)
{
    int res = 1;
    int num = a;
    int cnt = 1;
    while (b >= cnt)
    {
        if (b & cnt)
            (res *= num) %= mod;
        num = (num * num) % mod;
        cnt *= 2;
    }
    return res;
}

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

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    if (d[0] != 0)
    {
        cout << 0 << endl;
        return 0;
    }
    bool f = false;
    Rep(i, 1, n) if (d[i] == 0) f = true;
    if (f)
    {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1;
    vector<int> cnt(n, 0);
    rep(i, n) cnt[d[i]]++;
    bool g = true;
    Rep(i, 1, n)
    {
        if (cnt[i - 1] == 0)
        {
            if (g)
            {
                g = false;
                continue;
            }
        }
        if (cnt[i - 1] != 0 && !g)
        {
            cout << 0 << endl;
            return 0;
        }
        int tmp = calc(cnt[i - 1], cnt[i]);
        tmp = max(tmp, 1LL);
        (ans *= tmp) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
# 下方向に移動するのは１回だけなので横のぶん<=100回繰り返せばよい
n = int(input())
m = []
for _ in range(2):
    m.append(list(map(int, input().split())))

ans = 0

for h in range(2):
    for w in range(n):
        ans = max(ans, sum(m[0][:w+1]+m[1][w:]))
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// stringの要素を検索
bool string_exist(string s, char c) {
  auto itr = find(s.begin(), s.end(), c);
  size_t index = distance(s.begin(), itr);
  if (index!=s.size()) {
    return true;
  }
  else {
    return false;
  }
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> memo(N-1, 0); // S[i]とS[i+1]の間でSを切断した時の，題意の種類数
  for (int i=1; i<=N; i++) {
    string S1 = S.substr(0, i), S2 = S.substr(i, N-i);
    sort(S1.begin(), S1.end());
    S1.erase(unique(S1.begin(), S1.end()), S1.end());
    for (int j=0; j<S1.size(); j++) {
      if (string_exist(S2, S1[j])) memo[i-1]++;
    }
  }
  sort(memo.begin(), memo.end());
  cout << memo[N-2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
ll ans = 0;
for (ll sho = 0; sho < n; sho++) {
    for (ll mid = sho + 1; mid < n;mid++){
        auto itr = lower_bound(a, a + n, a[mid] + a[sho]);
        ll minu = distance(itr, a + n);
        ans += (n - minu - mid -1);
    }
}
cout << ans << endl;
}


Measured memory_bytes: 256
n,m,q = map(int,input().split())

def conb(l,m):#   自作itertools.combinations_with_replacement(l, n)
    ls = l.copy()
    if ls[len(ls)-1] < m:
            ls[len(ls)-1] += 1
            return ls
    for i in range(len(ls)-2,-1,-1):
        if ls[i] < m:
            ls[i] += 1
            for j in range(len(ls)-1,i,-1):
                ls[j] = ls[i]
            return ls
    return None
ls = [[1]*n]
i = 0
while(1):
    x = conb(ls[i],m)
    if x != None:
        ls.append(x)
    else:
        break
    i += 1
abcd = []
l = [i for i in range(1,m+1)]

ans = 0

for j in range(q):
    abcd.append(list(map(int,input().split())))
for v in ls:
    #print(v)
    sum = 0
    for j in range(q):
        if v[abcd[j][1]-1] - v[abcd[j][0]-1] == abcd[j][2]:
            sum += abcd[j][3]
    ans = max(ans,sum)
print(ans)

Measured memory_bytes: 90080
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
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;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll 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] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////
bool is_prime(int n) {
	for (int i = 2; i*i <= n; ++i) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


int main() {
	int x, y; cin >> x >> y;
	bool ok = false;
	for (int i = 0; i <= x; ++i) {
		if (2 * i + 4 * (x - i) == y) {
			ok = true;
		}
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
  int N, i, j;
  cin >> N;
  pair<pair<string, int>, int> p[N];
  for (i = 0; i < N; i++) {
    cin >> p[i].first.first >> j;
    p[i].first.second = j * (- 1);
    p[i].second = i + 1;
  }
  sort(p, p + N);
  for (i = 0; i < N; i++)
    cout << p[i].second << endl;
  
  return 0;
}

Measured memory_bytes: 256
L=input()
mod=10**9+7
l=len(L)
a0=[1]+[0]*(l-1)
a1=[2]+[0]*(l-1)
for i in range(1,l):
    if L[i]=='1':
        a0[i]=(a0[i-1]*3+a1[i-1])%mod
        a1[i]=(a1[i-1]*2)%mod
    else:
        a0[i]=(a0[i-1]*3)%mod
        a1[i]=a1[i-1]
print((a0[-1]+a1[-1])%mod)

Measured memory_bytes: 11748
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int dp[1001][8];
main(){
	string s;
	int n,ans=0;
	cin>>n>>s;
	r(i,n)if(s[i]=='J')s[i]=0;
	 else if(s[i]=='O')s[i]=1;
	 else s[i]=2;
	if(s[0]==0)dp[0][1]=dp[0][3]=dp[0][5]=dp[0][7]=1;
	else if(s[0]==1)dp[0][3]=dp[0][7]=1;
	else dp[0][5]=dp[0][7]=1;
	r(i,n-1)r(j,8)if(dp[i][j])
	  r(k,8)if((j&k)&&(k&(1<<s[i+1])))
	    dp[i+1][k]+=dp[i][j]%10007;
	r(i,8)ans+=dp[n-1][i];
	cout<<ans%10007<<endl;
}

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

using namespace std;

int main(void) {
    string a,b;
    cin >> a >> b;
    int an = a.size();
    int bn = b.size();

    if (a == b)
        cout << "EQUAL" << endl;
    else if (an < bn || (an == bn && a < b))
        cout << "LESS" << endl;
    else
        cout << "GREATER" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  ll N, D;
  cin >> N >> D;
  vector <ll> x(N);
  vector <ll> y(N);
  rep(i,N) cin >> x[i] >> y[i];

  int ans = 0;
  rep(i,N){
    if (x[i] * x[i] + y[i] * y[i] <= D * D){
      ans ++;
    }
  }

  cout << ans << endl;

}


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

#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second

const int N = 1e4 + 5;
const int p = 1e9 + 7;
const int D = 105;

int dp[N][10][D];
int total[N][D];
int a[N];

void add(int &a, int b) {
	a += b;
	if (a >= p) a -= p;
	if (a < 0) a += p;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
	string s;
	int d;
	cin >> s >> d;
	int n = s.length();
	for (int i=0; i<N; i++) {
		for (int j=0; j<10; j++) {
			for (int k=0; k<D; k++) {
				dp[i][j][k] = 0;
				total[i][k] = 0;
			}
		}
	}
	for (int i=0; i<10; i++) {
		dp[1][i][i % d]++;
		total[1][i % d]++;
	}
	for (int i=2; i<=n; i++) {
		for (int j=0; j<10; j++) {
			for (int k=0; k<d; k++) {
				dp[i][j][k] = total[i-1][((k-j)%d + d)%d];
                add(total[i][k], dp[i][j][k]);
			}
		}
	}
	reverse(s.begin(), s.end());
	s = '$' + s;
	for (int i=1; i<=n; i++) a[i] = s[i] - '0';
	int ans = total[n][0];
	int cur = 0;
	for (int i=n; i>=1; i--) {
		for (int j=a[i]+1; j<10; j++) {
			add(ans, -dp[i][j][(d - cur) % d]);
		}
		cur = (cur + a[i]) % d;
	}
	add(ans, -1);
	cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 45440
#include <stdio.h>

const long long mod = 1000000007;
int N,K; long long D[2002][2002],inv[4004004]={0,1},fact[4004004]={1,1},ifact[4004004]={1,1};

long long comb(int n, int k)
{
	return fact[n] * ifact[k] % mod * ifact[n-k] % mod;
}

int main()
{
	scanf ("%d %d",&N,&K);
	if (K == 1){
		puts("1");
		return 0;
	}

	for (int i=2;i<N*K;i++){
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fact[i] = fact[i-1] * i % mod;
		ifact[i] = ifact[i-1] * inv[i] % mod;
	}

	D[0][0] = 1;
	for (int i=0;i<=N;i++) for (int j=0;j<=i;j++){
		if (i + 1 <= N) D[i+1][j] = (D[i+1][j] + D[i][j]) % mod;
		if (j + 1 <= N) D[i][j+1] = (D[i][j+1] + D[i][j] * comb(N*K-i-j*(K-1)-1,K-2)) % mod;
	}

	printf ("%lld\n",D[N][N]*fact[N]%mod);

	return 0;
}

Measured memory_bytes: 124928
#include"bits/stdc++.h"
using namespace std;

int main() {
    long long N;
    cin >> N;
    vector<long long> a(N), b(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }

    long long ans = 0;
    for (int i = 0; i < 29; i++) {
        //i桁目に1が立つ数を数える
        long long num_1 = 0;

        //i桁より大きい部分は影響しないのでマスクする
        vector<long long> aa = a, bb = b;
        for (int j = 0; j < N; j++) {
            aa[j] &= (1 << (i + 1)) - 1;
            bb[j] &= (1 << (i + 1)) - 1;
        }

        //aa[j] + bb[k] が 2^i ~ 2^(i + 1) - 1, 2^(i + 1) + (2^i ~ 2^(i + 1) - 1)の範囲にあれば1がi桁目に立つ
        //つまりaa[j]を決めるとbb[k]が取れる範囲が定まる
        sort(bb.begin(), bb.end());

        for (int j = 0; j < N; j++) {
            auto left1 = lower_bound(bb.begin(), bb.end(), (1LL << i) - aa[j]);
            auto right1 = upper_bound(bb.begin(), bb.end(), (1LL << (i + 1)) - 1 - aa[j]);

            auto left2 = lower_bound(bb.begin(), bb.end(), (3LL << i) - aa[j]);
            auto right2 = upper_bound(bb.begin(), bb.end(), (3LL << (i + 1)) - 1 - aa[j]);

            num_1 += right1 - left1;
            num_1 += right2 - left2;
        }

        ans |= ((num_1 % 2) << i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 8588
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using LL = long long;

using P = pair<pair<int, bool>, int>;

pair<pair<int, int>, int>f(vector<P>vec, int l)
{
	vector<P>las = vec;
	if (vec.size() == 0)
	{
		return make_pair(make_pair(-1, -1), -1);
	}
	for (P& p : vec)
	{
		if (!p.first.second)
		{
			p.first.first = l - p.first.first;
		}
	}
	sort(vec.begin(), vec.end());
	int lef = 0, rht = vec.size() - 1;
	for (int i = 0; i < (int)vec.size() - 1; ++i)
	{
		if (vec[i].first.second)
		{
			lef++;
		}
		else
		{
			rht--;
		}
	}
	int ans1 = vec[vec.size() - 1].first.first;
	int ans2 = las[lef].second;
	bool dir = vec[vec.size() - 1].first.second;
	return make_pair(make_pair(ans1, dir), ans2);
}

int main(void)
{
	for (;;)
	{
		int n, l;
		cin >> n >> l;
		if (!n)break;
		vector<P>odd, evn;
		for (int i = 0; i < n; ++i)
		{
			char c; int v;
			cin >> c >> v;
			if (v % 2)
			{
				odd.push_back({ { v,c == 'L' } ,i + 1 });
			}
			else
			{
				evn.push_back({ { v,c == 'L' },i + 1 });
			}
		}
		auto p1 = f(odd, l);
		auto p2 = f(evn, l);
		if (p1.first > p2.first)
		{
			cout << p1.first.first << " " << p1.second << endl;
		}
		else
		{
			cout << p2.first.first << " " << p2.second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << "0" << endl;
            return 0;
        }
    }
    long long ans = 1;
    for (int i = 0; i < n; i++)
    {
        if (a[i] <= 1000000000000000000 / ans)
        {
            ans *= a[i];
        }
        else
        {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n,bmin=0;cin>>n;
    vector<ll> sumi(n),a(n,0),b(n,0);

    rep(i,n){
        ll x;cin>>x;
        sumi.at(x-1)=i;
    }

    ll A=0,B=0,mnb=0;
    rep(i,n){
        if(A+B>=sumi[i]){
            A++;
            B=sumi[i]-A;
        }else{
            B--;
            A=sumi[i]-B;
        }
        a[i]=A;b[i]=B;
        mnb=min(mnb,B);
    }
    mnb--;

    rep(i,n){
        cout<<a[i]-mnb<< (i==n-1 ? '\n':' ');
    }

    rep(i,n){
        cout<<b[i]-mnb<< (i==n-1 ? '\n':' ');
    }


}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n, p; cin >> n >> p;
	int cntO = 0;
	int cntE = 0;
	REP(i, n) {
		int tmp; cin >> tmp;
		if (tmp % 2) cntO++;
		else cntE++;
	}

	ll res = 0;
	if (cntO > 0)
		res = pow(2, n - 1);
	else if (cntO == 0) {
		if (p == 1)
			res = 0;
		else if (p == 0)
			res = pow(2, n);
	}

	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+10;
typedef long long ll;

int sum[N << 2];

void pushup(int rt){
	sum[rt] = sum[rt << 1]|sum[rt << 1|1];
	return ;
}

void build(int rt,int l,int r){
	if(l == r){
		char ch;
		cin >> ch;
		sum[rt] = (1 << (ch-'a'));
		return ;
	}
	int m = (l+r) >> 1;
	build(rt << 1,l,m);
	build(rt << 1|1,m+1,r);
	pushup(rt);
	return ;
}

void update(int rt,int pos,int l,int r,int val){
	if(l == r){
		sum[rt] = val;
		return ;
	}
	int m = (l+r) >> 1;
	if(pos <= m) update(rt << 1,pos,l,m,val);
	else update(rt << 1|1,pos,m+1,r,val);
	pushup(rt);
	return ;
}

inline int query(int rt,int L,int R,int l,int r){
	if(L <= l && r <= R) return sum[rt];
	int ans = 0;
	int m = (l+r) >> 1;
	if(L <= m) ans |= query(rt << 1,L,R,l,m);
	if(R > m) ans |= query(rt << 1|1,L,R,m+1,r);
	return ans;
}

inline int cal(int k){
	int ans = 0;
	while(k){
		k -= k&(-k);
		ans++;
	}
	return ans;
} 

int main()
{
	char ch;
	int n,m,op,l,r;
	scanf("%d",&n);
	build(1,1,n);
	scanf("%d",&m);
	while(m--){
		scanf("%d",&op);
		if(op == 1) scanf("%d %c",&l,&ch),update(1,l,1,n,(1 << (ch-'a')));
		else scanf("%d%d",&l,&r),printf("%d\n",cal(query(1,l,r,1,n)));
	}
	return 0;
}


Measured memory_bytes: 6400
from collections import deque
que = deque()
s = input()
n = len(s)
for i in range(n):
    if s[i] == '0':
        que.append('0')
    if s[i] == '1':
        que.append('1')
    if s[i] == 'B':
        if len(que)==0:
            continue
        k = que.pop()
li = list(que)
print(''.join(li))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;

int ans,r,l;
int main(){
  int N;

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


Measured memory_bytes: 256
#include <stdio.h>
 #include <string.h>
 #define mxz 2e5+10
 char a[(int)mxz], b[(int)mxz];
  
 int main(void) {
 	int d = 0;
  
 	scanf("%s", a);
 	scanf("%s", b);
  	

 	if(strcmp(a, b) != 0){
 		for(int c = 0; c <strlen(a); c++){
 			if(a[c] != b[c]){
 				//a[c] = b[c];
 				d++;
 			}
 		}
 		printf("%d", d);
 	}else{
 		printf("0");
 	}
  
 	return 0;
 }

Measured memory_bytes: 2124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    vector<vector<int> > graph(n);
    rep (i, n - 1) {
        int a, b; cin >> a >> b; a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<ll> sum(n);
    rep (i, q) {
        ll p, x; cin >> p >> x; p--;
        sum[p] += x;
    }
    vector<bool> used(n); used[0] = true;
    priority_queue<int> que; que.push(0);
    while (!que.empty()) {
        int p = que.top(); que.pop();
        for (int i : graph[p]) {
            if (used[i]) continue;
            used[i] = true;
            sum[i] += sum[p];
            que.push(i);
        }
    }
    rep (i, n) cout << sum[i] << (i != i_len - 1 ? ' ' : '\n');
    return 0;
}

Measured memory_bytes: 16500
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  long long int a[n+1];
  for(int i=0;i<n+1;i++)
    a[i]=1;
  for(int i=0;i<m;i++)
  {
    int x;
    cin>>x;
    a[x]=0;
    if(a[x-1]==0 || a[x+1]==0)
      return cout<<"0",0;
  }
  for(int i=n-2;i>=0;i--)
  {
    if(a[i]==1)
      a[i]=(a[i+1]+a[i+2])%1000000007;
  }
  cout<<a[0];
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char a[3];
  cin>>a;
  if(strcmp(a,"MON")==0)
  {
    cout<<6;
  }
  else if(strcmp(a,"TUE")==0)
  {
    cout<<5;
  }
  else if(strcmp(a,"WED")==0)
  {
    cout<<4;
  }
  else if(strcmp(a,"THU")==0)
  {
    cout<<3;
  }
  else if(strcmp(a,"FRI")==0)
  {
    cout<<2;
  }
  else if(strcmp(a,"SAT")==0)
  {
    cout<<1;
  }
  else if(strcmp(a,"SUN")==0)
  {
    cout<<7;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = sum(a)
l = 0
r = 0
x = 0
ans = 0
for i in a:
  l += i
  r = b - l
  if l==r:
    break;
  elif l>r:
    ans = min(l-r,y-x)
    break;
  x = l
  y = r
print(ans)

Measured memory_bytes: 26396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
#define PI 3.14159265358979323846264338327950

int main() {
	ll a, b, h, m;
	long double minute, hour, rad, ans=0;

	cin >> a >> b >> h >> m;

	minute = (long double)m/60.0;
	hour = (long double)m /720.0 + (long double)h /12.0;
	rad = 2 * PI*(minute-hour);
	ans = sqrt(a*a + b*b - 2*a*b*cos(rad));
  
	printf("%20.20Lf\n", ans);

	return 0;
}

Measured memory_bytes: 4084
#include<stdio.h>
#define N 100
#define W 0
#define T 2
#define UN 1

int n,S[N][N];
int c[N],d[N],f[N],ts;

void visit(int u){
  int v;
  c[u]= UN;
  d[u]= ++ts; //fast contact
  for(v=0;v<n;v++){
    if(S[u][v]==0)continue;
    if(c[v]==W){
      visit(v);
    }
  }
  c[u]=T;
  f[u]=++ts;
}

void dfs(){
  int s;
  int i;
  for(s=0;s<n;s++){
    c[s]=W;
  }
    ts =0;

    for(s=0;s<n;s++){
      if(c[s]==W)visit(s);
    }

}

int main(){

  int i,j,x,y,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      S[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&y,&c);
    y--;
    for(j=0;j<c;j++){
      scanf("%d",&x);
      x--;
      S[y][x]=1;
    }
  }

dfs();
for(i=0;i<n;i++){
  printf("%d %d %d\n",i+1,d[i],f[i]);
}

  return 0;
}

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

using namespace std;

int main() {
  string str;
  cin >> str;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    string command;
    int a, b;
    cin >> command >> a >> b;
    if (0 == command.compare("print")) {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (0 == command.compare("reverse")) {
      for (int j = a, k = b; j < k; ++j, --k) {
        swap(str[j], str[k]);
      }
    } else if (0 == command.compare("replace")) {
      string p;
      cin >> p;
      str.replace(a, b - a + 1, p);
    }
  }
  return 0;
}



Measured memory_bytes: 3180