akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
using namespace std;

int N, C[1010], dp[1010][2];
vector< pair<int, int> > G[1010];
const int INF = 1 << 28;

void solve(int cur, int par=-1) {
  dp[cur][ C[cur] > 0 ] = 0;
  for(auto e : G[cur]) {
    int to, cost; tie(to, cost) = e;
    if(to == par) continue;

    solve(to, cur);
    if(C[cur] == 0) {
      dp[cur][0] += min(dp[to][0], cost);
    }
    else {
      dp[cur][1] += min(dp[to][0], dp[to][1]);
    }
  }
}

int main() {
  cin >> N;
  fill(dp[0], dp[N+1], INF);
  for(int i=1; i<N; i++) {
    cin >> C[i];
  }
  for(int i=0; i<N-1; i++) {
    int u, v, cost; cin >> u >> v >> cost;
    G[u].emplace_back(v, cost);
    G[v].emplace_back(u, cost);
  }

  solve(0);
  /*
  for(int i=0; i<N; i++) {
    fprintf(stderr, "i = %d, dp[0] = %d, dp[1] = %d\n", i, dp[i][0], dp[i][1]);
  }
  */
  cout << dp[0][0] << endl;
  return 0;
}



Measured memory_bytes: 3168
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;


int main() {

    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	
	cout << ( (a * b > c * d) ? a * b : c * d ) << endl;

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









Measured memory_bytes: 256
#include <stdio.h>


int main(){
  int N,K;
  char S[20];
  scanf("%d\n%s\n%d",&N,S,&K);
  K--;
  for(int i=0;i<N;i++)
    if(S[i]!=S[K]) S[i]='*';
  
  printf("%s\n",S);
  return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


// |a-(sum-a)| = |2*a-sum|

int main(){
  ll N; cin>>N;
  ll cumu[N];
  REP(i,N){
    cin >> cumu[i];
    if(i>0){ cumu[i] += cumu[i-1];}
  }
  ll r;
  for(int i=0;i<=N-2;i++){
    if(i==0){ r = abs(2*cumu[i]-cumu[N-1]);}
    else{ r = min(abs(2*cumu[i]-cumu[N-1]),r);}
  }
  cout << r;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int a;
  N -= 1;
  K -= 1;
  a = N / K;
  if (N % K != 0){
    a += 1;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

template <ll mod>
struct modular {
    ll value;
    modular(ll x = 0) {
        value = x % mod;
        if (value < 0) value += mod;
    }

    modular& operator+=(modular other) {
        if ((value += other.value) >= mod) value -= mod;
        return *this;
    }
    modular& operator-=(modular other) {
        if ((value -= other.value) < 0) value += mod;
        return *this;
    }
    modular& operator*=(modular other) {
        value = value * other.value % mod;
        return *this;
    }
    modular& operator/=(modular other) {
        ll a = 0, b = 1, c = other.value, m = mod;
        while (c != 0) {
            ll t = m / c;
            m -= t * c;
            swap(c, m);
            a -= t * b;
            swap(a, b);
        }
        a %= mod;
        if (a < 0) a += mod;
        value = value * a % mod;
        return *this;
    }
    modular& operator^=(modular other) {
        ll r = 1, x = value, n = other.value;
        while (n > 0) {
            if (n & 1) r = r * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        value = r;
        return *this;
    }
    modular operator+(modular rhs) {
        return modular(*this) += rhs;
    }
    modular operator-(modular rhs) {
        return modular(*this) -= rhs;
    }
    modular operator*(modular rhs) {
        return modular(*this) *= rhs;
    }
    modular operator/(modular rhs) {
        return modular(*this) /= rhs;
    }
    modular operator^(modular rhs) {
        return modular(*this) ^= rhs;
    }
    bool operator==(modular rhs) {
        return value == rhs.value;
    };
    bool operator!=(modular rhs) {
        return value != rhs.value;
    };
    bool operator<(modular rhs) {
        return value < rhs.value;
    }
};
template <ll mod>
string to_string(modular<mod> x) {
    return to_string(x.value);
}
template <ll mod>
ostream& operator<<(ostream& stream, modular<mod> x) {
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream << x.value;
}
template <ll mod>
istream& operator>>(istream& stream, modular<mod>& x) {
    stream >> x.value;
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream;
}
const ll mod = 1e9 + 7;
using mint = modular<mod>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<vector<mint>> dp(61, vector<mint>(3));
    dp[60][0] = 1;
    for (int b = 59; b >= 0; b--) {
        int x = (n >> b) & 1;
        dp[b][2] = dp[b + 1][2] * 3 + dp[b + 1][1];
        dp[b][0] = dp[b + 1][0];
        dp[b][1] = dp[b + 1][1];
        if (x) {
            dp[b][2] += dp[b + 1][1];
            dp[b][1] += dp[b + 1][0];
        } else {
            dp[b][0] += dp[b + 1][1];
        }
    }
    debug(dp);
    cout << (dp[0][0] + dp[0][1] + dp[0][2]) << endl;
    return 0;
}


Measured memory_bytes: 256
m,n,t[100],i,L1,L2,L,h,w;C(){for(h=w=i=0;h<m&&i<n;w>L?(w=0,++h):i++)w+=t[i];return h<m;}main(){for(;scanf("%d%d",&m,&n),n;printf("%d\n",L1)){for(i=0;i<n;)scanf("%d",t+i++);for(L1=0,L2=1500000;L1<L2;C()?L2=L:(L1=L+1))L=(L1+L2)/2;}exit(0);}

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

const int INF = 1001001001;

int main(){
 string S;
 cin>>S;
 char a[26];
 set<char>t;
 for(int i=0;i<S.size();i++){
     t.insert(S[i]);
 }
 for(int i=0;i<26;i++){
    if(!t.count((char)(i+'a'))){cout<<char(i+'a')<<endl;return 0;}
 }
 cout<<"None"<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void) {
    int N, i;
    char S[10005];
    scanf("%d%s", &N, S);
    for (i=0; i<strlen(S); i++) {
        S[i]+=N;
        if (S[i]>'Z') S[i]-=26;
    }
    printf("%s", S);
}

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

int main() {
    string s;
    cin >> s;
    set<char> st;
    rep(i,s.size()) {
        if(st.count(s[i])==1) {cout << "no" << endl; return 0;}
        st.insert(s[i]);
    }
    cout << "yes" << endl;
    return 0;
}

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

int main()
{
    std::string a, b;
    std::cin >> a;
    std::cin >> b;

    if (a.size() == b.size())
    {
        bool flag = true;
        for (size_t i = 0; i < a.size(); ++i)
        {
            if (a[i] == b[i])
            {
                continue;
            }
            else if (a[i] > b[i])
            {
                std::cout << "GREATER";
            }
            else
            {
                std::cout << "LESS";
            }
            flag = false;
            break;
        }
        if (flag)
        {
            std::cout << "EQUAL";
        }
    }
    else if (a.size() > b.size())
    {
        std::cout << "GREATER";
    }
    else
    {
        std::cout << "LESS";
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define TC int tt; cin >> tt; for(int t=0; t<tt; t++)
#define ll long long
#define pb push_back
#define Mod 1000000007
#define limit 2000008
using namespace std;

void solve(int t)
{
    double i,j,n,m,k,d,ct=0;
    cin >> n >> d;
    for(i=0; i<n; i++)
    {
        double x,y,z;
        cin >> x >> y;
        z = sqrt(x*x+y*y);
        if(d>=z)
            ct++;
    }
    cout <<ct<<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int tt=1,t;
 ///   cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}



Measured memory_bytes: 3804
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;

#define pi 3.141592653589

int main(){
	int a, b;
	char op;
	
	while (cin >> a >> op >> b){
		if (op == '+')
		{
			cout << a + b << endl;
		}
		else if (op == '-'){
			cout << a - b << endl;
		}
		else if (op == '*'){
			cout << a*b << endl;
		}
		else if (op == '/'){
			cout << a / b << endl;
		}
		else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while ( scanner.hasNextInt() ) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            System.out.println( Integer.toString( a + b ).length() );
        }
    }
}

Measured memory_bytes: 20412
/**
 *  author:   TakeruOkuyama
 *  created:  2020-04-08 10:36:09
**/
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P =pair<int,int>;

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) {
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    /*rep(i,N) {
        cout << L[i];
    }*/
    int x = 0, y = 0;
    rep(i, N) {
        if(i == 0){
            x += L[i];
        }else{
            y += L[i];
        }
    }
    if(x < y){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
return 0;}

/**
 * compile: g++ code.cpp
 * run: ./a.out
 * insert date string: ctrl + shift + i
 * 
**/ 

Measured memory_bytes: 256
N,K=map(int, input().split())
hs=list(map(int, input().split()))

dp = [-100 for _ in range(N)]
dp[0] = 0
dp[1] = abs(hs[1]-hs[0])

for i in range(2,N):
    num = max(0, i-K)
    dp[i] = min([abs(hs[i]-hs[j])+dp[j]\
            for j in range(num, i)])

print(dp[-1])


Measured memory_bytes: 20484
#include <stdio.h>

int main(void)
{
	for(;;)
	{
		int x,y,h,w,z,n,m,ans=0;
		scanf("%d",&n);
		if(n==0)
		{
			break;
		}
		for(m=0;m<n;m++)
		{
			scanf("%d %d %d %d",&x,&y,&h,&w);
			z=x+y+h;
			if(z<=60&&w<=2)
			{
				ans+=600;
			}
			else if(z<=80&&w<=5)
			{
				ans+=800;
			}
			else if(z<=100&&w<=10)
			{
				ans+=1000;
			}
			else if(z<=120&&w<=15)
			{
				ans+=1200;
			}
			else if(z<=140&&w<=20)
			{
				ans+=1400;
			}
			else if(z<=160&&w<=25)
			{
				ans+=1600;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2692
<?php

fscanf(STDIN, "%d %d", $in_n, $in_m);
$in_h = trim(fgets(STDIN));
$h = explode(" ", $in_h);
//var_dump($h);
$ans = 0;
//$miti = array_fill(0, $in_n, array());
$aite_h = array_fill(0, $in_n, 0);


for($i = 0; $i < $in_m; $i++) {
    fscanf(STDIN, "%d %d", $in_a[$i], $in_b[$i]);
//    var_dump($in_b[$i]);
//    array_push($miti[$in_a[$i] - 1], $in_b[$i]);
    $aite_h[$in_a[$i] - 1] = max($aite_h[$in_a[$i] - 1] , $h[$in_b[$i] - 1]);
//    array_push($miti[$in_b[$i] - 1], $in_a[$i]);
    $aite_h[$in_b[$i] - 1] = max($aite_h[$in_b[$i] - 1] , $h[$in_a[$i] - 1]);
}


for($i = 0; $i < $in_n; $i++) {
//    var_dump($miti[$i]);
//    var_dump($aite_h[$i]);
//    $flag = true;
//    for ($j = 0; $j < count($miti[$i]); $j++) {
//        if($h[$i] < $h[$miti[$i][$j]]){
//            $flag = false;
//            break;
//        }
//    }
//    if(($flag == true) && (count($miti[$i]) > 0)){
//        $ans++;
//    }
    if($h[$i] > $aite_h[$i]){
//        var_dump($i);
        $ans++;
    }
}

echo "$ans\n";


Measured memory_bytes: 39524
import sys

sys.setrecursionlimit(10 ** 9)
N = int(input())
length = len(str(N)) + 1
result = []


def dfs(now):
    if len(now) <= length and now != "":
        result.append(now)
        if len(now) == length:
            return
    dfs("3" + now)
    dfs("5" + now)
    dfs("7" + now)


dfs("")
ans = 0
result = set(result)
for r in result:
    i = int(r)
    if i <= N and r.count("3") > 0 and r.count("5") > 0 and r.count("7") > 0:
        ans += 1
print(ans)


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

using namespace std;
using ll = long long;

const int nax = 3005;
ll dp[nax][nax];

int main(){  
    int n;
    scanf("%d",&n);
    vector<int> a(n);
    REP(i,n){
        scanf("%d",&a[i]);
    }
    //dp[0][n-1] 
    for(int L=n-1; L>= 0; L--){
        for(int R=L; R<n; R++){
            dp[L][R] = max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
        }
    }
    printf("%lld\n",dp[0][n-1]);
    return 0;
}


Measured memory_bytes: 70016
import string
from collections import OrderedDict

n = int(input())

d = OrderedDict()
for i in string.ascii_lowercase:
    d[i] = d.get(i, 0) - 1

for _ in range(n):
    s = input()
    for i in string.ascii_lowercase:
        if s.count(i) == 0:
            d[i] = 0
        elif s.count(i) > 0:
            if d[i] == -1:
                d[i] = s.count(i)
            else:
                d[i] = min(d[i], s.count(i))

ans = ""

for i in d.items():
    if i[1] != 0:
        ans += i[0] * i[1]

print(ans)

Measured memory_bytes: 3772
program papers_please
    integer(4):: n, i
    integer(4),allocatable:: a(:)
    logical:: is_denied = .false.

    read*, n
    allocate(a(n))
    read*, a(:)
    
    do i=1,n
        if (mod(a(i),2) /= 0) cycle
        if (mod(a(i),3)/=0 .and. mod(a(i),5)/=0) is_denied = .true.
    end do

    if (is_denied) then
        print*, "DENIED"
    else
        print*, "APPROVED"
    end if
end program papers_please

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto s = RD!string;
	auto t = RD!string;
	long[string] set1, set2;
	foreach (c; s)
		++set1[[c]];
	foreach (c; t)
		++set2[[c]];

	string ss;
	foreach (key; set1.keys.sort())
	{
		foreach (i; 0..set1[key])
			ss ~= key;
	}
	string tt;
	foreach (key; set2.keys.sort!"a > b"())
	{
		foreach (i; 0..set2[key])
			tt ~= key;
	}

	writeln(icmp(ss, tt) < 0 ? "Yes" : "No");
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
if a[0] > x:
    ans = a[0] - x
    a[0] = x

for i in range(1, N):
    if a[i - 1] + a[i] > x:
        ans += a[i - 1] + a[i] - x
        a[i] = x - a[i - 1]

print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	long long N, K;
	cin >> N >> K;

	auto sum = 0ll;
	vector<pair<int, long long>> list;
	for (auto i = 0ll; i < N; ++i)
	{
		long long a, b;
		cin >> a >> b;
		list.push_back(make_pair(a, b));
	}

	sort(list.begin(), list.end());

	auto result = 0;
	for (auto i = 0ll; i < N; ++i)
	{
		auto& p = list[i];
		sum += p.second;
		if (sum >= K)
		{
			result = p.first;
			break;
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
struct Node
{
    double x, y;
    Node(double xx = 0, double yy = 0){
        x = xx; y = yy;
    }

    Node operator + (Node b){
        return Node(x+b.x, y+b.y);
    }
    Node operator - (Node b){
        return Node(x-b.x, y-b.y);
    }
    Node operator * (double a){
        return Node(a*x, a*y);
    }
    Node operator / (double a){
        return Node(x/a, y/a);
    }

    double norm(){return x*x+y*y;}
    double len(){
        return sqrt(norm());
    }

    bool operator < (const Node &p) const{
        return x!=p.x ? x<p.x : y<p.y;
    }

    bool operator == (const Node &p) const {
        return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
    }
};

bool equals(double a, double b) {
    return fabs(a)-fabs(b) < eps;
}

typedef Node vtr;

struct line{
    Node a, b;
    line(Node x, Node y){
        a = x, b = y;
    }
};

//向量点积
double dot(vtr a, vtr b){
    return a.x*b.x+a.y*b.y;
}

//向量叉积
double cross(vtr a, vtr b){
    return a.x*b.y-a.y*b.x;
}

//判断向量a,b是否正交(垂直)
bool isOrthogonal(vtr a, vtr b){
    return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Node a1, Node a2, Node b1, Node b2){
    return isOrthogonal(a1-a2, b1-b2);
}

bool isOrthogonal(line s1, line s2){
    return equals(dot(s1.b-s1.a, s2.b-s2.a), 0.0);
}

//判断向量a,b是否平行
bool isParallel(vtr a, vtr b){
    return equals(cross(a, b), 0.0);
}

bool isParallel(Node a1, Node a2, Node b1, Node b2){
    return isParallel(a1-a2, b1-b2);
}

bool isParallel(line s1, line s2){
    return equals(cross(s1.b-s1.a, s2.b-s2.a), 0.0);
}

//投影 求垂足坐标
//点p在直线p1p2上的投影
Node project(line s, Node p)
{
    vtr base = s.b-s.a;
    //算出比例
    double r = dot(p-s.a, base)/base.norm();
    return s.a+base*r;
}

//映象 求p以直线s为对称轴的对称点
Node reflect(line s, Node p){
    return p+(project(s, p)-p)*2.0;
}

int ccw(Node p0, Node p1, Node p2)
{
    vtr a = p1-p0, b = p2-p0;
    //b在a的逆时针方向
    if(cross(a, b) > eps) return 1;
    //顺时针方向
    if(cross(a, b) < -eps) return -1;
    //共线但反向
    if(dot(a, b) < -eps) return 2;
    //共线同向
    //b更长一点
    if(a.norm() < b.norm()) return -2;
    //a更长一点
    return 0;
}

//判断两线段是否相交
bool intersect(Node p1, Node p2, Node p3, Node p4){
    bool t1 = ccw(p1, p2, p3)*ccw(p1, p2, p4)<=0;
    bool t2 = ccw(p3, p4, p1)*ccw(p3, p4, p2)<=0;
    return t1&&t2;
}
bool intersect(line s1, line s2){
    return intersect(s1.a, s1.b, s2.a, s2.b);
}


int main()
{
    Node p0, p1, p2, p3;
    int q; cin >> q;
    while(q--)
    {
        cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
        line s1 = line(p0, p1);
        line s2 = line(p2, p3);
        cout << intersect(s1, s2) << endl;
    }
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

/*FUNCs=================================================*/
ll GCD(ll a, ll b){
    return (b ? GCD(b, a%b) : a);
}
    //約数列挙配列生成
vll divisor(ll n){
    vll ret;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    long double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    ll a,b; cin >> a >> b;
    ll gcd = GCD(a,b);
    vll p = divisor(gcd);
    ll cnt = 0;
    for(int i = 0; i < p.size(); i++){
        if(IsPrime(p[i])) cnt++;
    }
    cout << cnt+1 << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main()
{
	int32_t x;
	cin >> x;

	cout << (x < 1200 ? "ABC" : "ARC") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    long long res = 0;

    vector<vector<bool>> c(h, vector<bool>(w, false));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (c[i][j]) {
                continue;
            }

            c[i][j] = true;

            long long cb = 0, cw = 0;
            queue<pair<int, int>> que;
            que.push(make_pair(i, j));
            while (!que.empty()) {
                pair<int, int> q = que.front();
                que.pop();

                int y = q.first;
                int x = q.second;

                if (s[y][x] == '#') {
                    cb++;
                } else {
                    cw++;
                }

                int dy[] = { -1, 0, 0, 1 };
                int dx[] = { 0, -1, 1, 0 };
                for (int k = 0; k < 4; k++) {
                    if (0 <= y + dy[k] && y + dy[k] < h
                            && 0 <= x + dx[k] && x + dx[k] < w
                            && s[y][x] != s[y + dy[k]][x + dx[k]] && !c[y + dy[k]][x + dx[k]]) {
                        c[y + dy[k]][x + dx[k]] = true;
                        que.push(make_pair(y + dy[k], x + dx[k]));
                    }
                }
            }

            res += cb * cw;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 512
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
vector<pair<int,int> > edge ;
int n , m ;
vector<int> rep ;
int Find(int x){
    if ( rep[x] == x ) return x ;
    return rep[x] = Find(rep[x]) ;
}
void Union(int x, int y){
    int X = Find(x) ;
    int Y = Find(y) ; 
    if ( X == Y ) return ;
    rep[X] = Y ;
}
bool build(int x){
    for(int i = 0; i < n; i++){
        rep[i] = i ;
    }
    for(int i = 0; i < m; i++){
        if ( i == x ) continue ;
        int a = edge[i].first , b = edge[i].second ;
        Union(a, b) ;
    }
    if ( Find(edge[x].first) == Find(edge[x].second) ) return false ;
    return true ;
}
signed main(){
    fastio
    cin >> n >> m ;
    rep = vector<int>(n) ;
    edge = vector<pair<int,int> > (m) ;
    for(int i = 0; i < m; i++){
        cin >> edge[i].first >> edge[i].second ;
        edge[i].first-- , edge[i].second-- ;
    }
    int ans = 0 ;
    for(int i = 0; i < m; i++){
        ans += build(i) ;
    }
    cout << ans << endl;
    return 0; 
}


Measured memory_bytes: 3648
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """要素xが属するグループの根を返す"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """要素xが属するグループと要素yが属するグループを併合"""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """要素xが属するグループのサイズを返す"""
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x, yが同じグループかどうか"""
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属するグループの要素をリストで返す"""
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """すべての根の要素をリストで返す"""
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """グループの数を返す"""
        return len(self.roots())

    def all_group_members(self):
        """{ルート要素: [そのグループの要素, ...], ...}を返す"""
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """print()での表示用"""
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    uf.union(a, b)

print(uf.group_count() - 1)

Measured memory_bytes: 12760
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define V vector<int>
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

P ps[100100];

int n, m;
int a[100100], b[100100];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int tmp = 0;
	int id = 0;
	for (int i = 1; i <= n; i++) {
		tmp += i;
		if (tmp >= n) {
			id = i; break;
		}
	}
	if (tmp == n) {
		for (int i = 1; i <= id; i++) {
			cout << i << endl;
		}
	}
	else {
		int tmp2 = 0;
		for (int i = 1; i <= id; i++) {
			if (tmp - i == n) {
				tmp2 = i; break;
			}
		}
		for (int i = 1; i <= id; i++) {
			if (i != tmp2)cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    vector<vector<int>> A(3, vector<int>(3, 0));
    map<int, int> b;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            int a; cin >> a;
            A[i][j] = a;
            b[a] = 0;
        }
    }
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        int x; cin >> x;
        b[x] = 1;
    }
    
    //horizontal
    for (int i = 0; i < 3; i++) {
        bool tmp_flag = true;
        for (int j = 0; j < 3; j++) {
            if (b[A[i][j]] != 1) {
                tmp_flag = false;
                break;
            }
        }
        if (tmp_flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    // vertical
    for (int i = 0; i < 3; i++) {
        bool tmp_flag = true;
        for (int j = 0; j < 3; j++) {
            if(b[A[j][i]] != 1) {
                tmp_flag = false;
                break;
            }
        }
        if (tmp_flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    bool tmp_flag = (b[A[0][0]] == 1 && b[A[1][1]] == 1 && b[A[2][2]] == 1);
    tmp_flag = tmp_flag || (b[A[2][0]] == 1 && b[A[1][1]] == 1 && b[A[2][0]] == 1);
    if (tmp_flag) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(string, S);
	bool r = true;
	r &= S[0] == 'A';
	int cnt = 0;
	for (int i = 2; i < S.size() - 1; ++i)
		if (S[i] == 'C')
			++cnt;
	r &= cnt == 1; cnt = 0;
	for (auto c : S)
		if (!('a' <= c && c <= 'z'))
			++cnt;
	out(r&&cnt == 2 ? "AC" : "WA");
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		// スペース区切りの整数の入力
		String str = sc.next();
		String[] strArray = str.split("");
		int len = strArray.length % 2;
		if(len == 0) {
			len = strArray.length / 2;			
		}else{
			len = (strArray.length - 1) / 2;
		}
		int ans = 0;
		 
		// Mapの宣言
        Map<String,Integer> map = new HashMap<>();
        int i = 0;
        int j = strArray.length - 1;
		while(i <= len - 1) {
		    // 1文字ずつ表示
	        if (strArray[i].equals(strArray[j] )){
	        }else {
	        	map.put(strArray[i],1);
	        	ans ++;
	        }
			
			i++;
			j--;
		}

//		System.out.println(map.size());
		System.out.println(ans);



   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 23252
mod = 998244353
N, M, K = map(int, input().split())

f = 1
f_list = [1]
for m in range(1, N + 1):
    f *= m
    f %= mod
    f_list.append(f)
inv = pow(f, mod - 2, mod)    
inv_list = [1] * (N + 1)
inv_list[N] = inv

for m in range(N, 1, -1):
    inv *= m
    inv %= mod
    inv_list[m - 1] = inv

ans = 0

for i in range(K + 1):
    color = pow(M - 1, N - 1 - i, mod)
    order = f_list[N - 1] * inv_list[i] * inv_list[N - i - 1] % mod
    ans += color * order * M % mod
    ans = ans % mod
print(ans % mod)

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

#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)

#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)

#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)

#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))

#define whileZ int T; getI(T); while(T--)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))

#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure

#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"

#define PRESENT(c,x) ((c).find(x) != (c).end())

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short

//for map, pair
#define mp make_pair
#define fi first
#define se second

// for debug
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)

//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
string s[55];
int a[55];
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);

    wez(n); F(i,0,n) {
        cin >> s[i] >> a[i];
    } string tt; cin >> tt; int ans=0;
    FFE(i,n-1,0) {
        if (s[i]==tt) break;
        ans+=a[i];
    } cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    ll K, N, A[200000], B[200000], min;
    cin >> K >> N;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    B[0] = A[N - 1] - A[0];
    min = B[0];
    for (ll i = 1; i < N; i++) {
        B[i] = K - (A[i] - A[i -1]);
        if (min > B[i]) {
            min = B[i];
        }
    }
    cout << min << endl;
    return 0;
}



Measured memory_bytes: 1792
in_str = raw_input()
q = int(raw_input())
for i in range(q):
    oper = raw_input().split()
    if oper[0] == 'print':
        print in_str[(int(oper[1])):(int(oper[2]))+1]
    elif oper[0] == 'reverse':
        buf = ''
        for i in range(int(oper[1])):
            buf += in_str[i]
        for i in reversed(range(int(oper[1]),int(oper[2])+1)):
            buf += in_str[i]
        buf += in_str[(int(oper[2]))+1:]
        in_str = buf
    elif oper[0] == 'replace':
        buf = in_str[:(int(oper[1]))]
        buf += oper[3]
        buf += in_str[(int(oper[2]))+1:]
        in_str = buf

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

using namespace std;

int main()
{
    int n;
    while(cin >> n)
    {
        int x=0;
        int sum[110],sum2[110];
        memset(sum,0,sizeof(sum));
        memset(sum2,0,sizeof(sum2));
        for(int i=1;i<=n;i++)
        {
            cin >> x;
            sum[i]=sum[i-1]+x;
        }
        for(int i=1;i<=n;i++)
        {
            cin >> x;
            sum2[i]=sum2[i-1]+x;
        }
        int MAX=0;
        int all;
        for(int i=1;i<=n;i++)
        {
            all=sum[i]+sum2[n]-sum2[i-1];
            MAX=max(MAX,all);
        }
        cout << MAX << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int main() {
	string s1, s;
	cin >> s1;
	for (register size_t i = 0; i < s1.length(); i++) {
		char c = s1[i];
		if (c == 'B' && i + 1 < s1.length() && s1[i + 1] == 'C') {
			s += string("K");
			i++;
		}
		else {
			s += c;
		}
	}
	ll ans = 0;
	ll acnt = 0;
	for (auto c : s) {
		if (c == 'A') acnt++;
		else if (c == 'K') {
			ans += acnt;
		}
		else {
			acnt = 0;
		}
	}
	cout << ans << endl;
	//cout << s << endl;
	
}

Measured memory_bytes: 776
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

int N,K,ans=0;

int main(){
    cin>>N>>K;
    while(N){
        N/=K;
        ans++;
    }
    out(ans);
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string decC(string s)
{
	string mess=s;
	mess[s.size()-1]=s[0];
	for(int i = 0; i < s.size()-1; ++i)
	{
		mess[i]=s[i+1];
	}
	return mess;
}

string decJ(string s)
{
	string mess=s;
	mess[0]=s[s.size()-1];
	for(int i = 1; i < s.size(); ++i)
	{
		mess[i]=s[i-1];
	}
	return mess;
}

string decE(string s)
{
	int n=s.size();
	string l=s.substr(0,n/2);
	string m=n%2==0?"":s.substr(n/2,1);
	string r=n%2==0?s.substr(n/2):s.substr(n/2+1);

	return r+m+l;
}

string decP(string s)
{
	for(int i = 0; i < s.size(); ++i)
	{
		if('0'<=s[i]&&s[i]<='9')
		{
			if(s[i]=='0') s[i]='9';
			else s[i]-=1;
		}
	}
	return s;
}

string decM(string s)
{
	for(int i = 0; i < s.size(); ++i)
	{
		if('0'<=s[i]&&s[i]<='9')
		{
			if(s[i]=='9') s[i]='0';
			else s[i]+=1;
		}
	}
	return s;
}

int main()
{
	int n; cin>>n;
	while(n--) 
	{
		string order,mess; cin>>order>>mess;

		for(int i = order.size()-1; 0 <= i; --i)
		{
			if(order[i]=='J') mess=decJ(mess);
			if(order[i]=='C') mess=decC(mess);
			if(order[i]=='E') mess=decE(mess);
			if(order[i]=='A') reverse(mess.begin(),mess.end());
			if(order[i]=='P') mess=decP(mess);
			if(order[i]=='M') mess=decM(mess);
		}
		cout<<mess<<endl;
	}
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans=0;
  cin >> n;
  vector<long> a(n),b(n),c(n),d(n);
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=0;i<n;i++) cin >> b[i];
  for(long x=1;x<=4294967296L;x*=2) {
    long y,aa=0,bb=0;
    for(long i=0;i<n;i++) if(a[i]&x) aa++;
    for(long i=0;i<n;i++) if(b[i]&x) bb++;
    y=aa*(n-bb)+(n-aa)*bb+n*n;
    for(long i=0;i<n;i++) c[i]=a[i]%x;
    for(long i=0;i<n;i++) d[i]=b[i]%x;
    sort(c.begin(),c.end());
    sort(d.begin(),d.end());
    long j=n-1;
    for(long i=0;i<n;i++) {
      while(c[i]+d[j]>=x) {
        j--;
        if(j==-1) break;
      }
      y-=(j+1);
      if(j==-1) break;
    }
    j=0;
    for(long i=n-1;i>=0;i--) {
      while(c[i]+d[j]<2*x) {
        j++;
        if(j==n) break;
      }
      y-=(n-j);
      if(j==n) break;
    }
    if(y%2==1) ans+=x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9424
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define t int t;scanf("%d",&t);for(int v=1;v<=t;v++)
#define loop_arr(i,a,b) for(int i=a;i<b;i++)
#define loop_norm(i,a,b) for(int i=a;i<=b;i++)
#define minheap priority_queue<int,vector<int>,greater<int> >
#define maaheap priority_queue<int>
#define pb push_back
#define pop pop_back
ll BIGMOD ( ll a, ll p, ll m )
{
    ll result = 1;
    ll x = a;

    while ( p )
    {
        if ( p & 1 ) //p is odd
        {
            result = ( result * x ) % m;
        }
        x = ( x * x ) % m;
        p = p >> 1;
    }

    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}

int main()
{
   //fastread;
   int n;
   cin>>n;
   int arr[n+5];
   loop_arr(i,0,n) cin>>arr[i];
   int res=1;
   loop_arr(i,0,n)
   {
       if(arr[i]%2!=0) continue;
       else if(arr[i]%2==0)
       {
           if(arr[i]%3==0 || arr[i]%5==0) continue;
           else
           {
               res=0;
               break;
           }
       }
   }
   if(res) cout<<"APPROVED"<<"\n";
   else cout<<"DENIED"<<"\n";

  return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

n = int(input())
l = deque()

for _ in range(n):
    op = input().strip().split()
    if op[0] == "insert":
        l.appendleft(op[1])
    elif op[0] == "delete":
        if op[1] in l:
            l.remove(op[1])
    elif op[0] == "deleteFirst":
        l.popleft()
    elif op[0] == "deleteLast":
        l.pop()
print(" ".join(l))



Measured memory_bytes: 69728
n= int(input())
s = input()

r = []
g = []
b = []

for i in range(n):
    if s[i]=='R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    else:
        b.append(i)

# print(r,g,b)
ans = 0

for i in range(n):
    for j in range(i+1,n):
        if 2*j - i < n and s[i] != s[j] and s[i] != s[2*j-i] and s[j]!= s[2*j-i]:
            ans += 1

print(len(r)*len(g)*len(b) -ans)

Measured memory_bytes: 73888
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;



int main() {
    ll n, a[105], max = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (abs(a[i]) > abs(a[max])) max = i;
    }
    
    cout << 2*n-2 << endl;
    for (int i = 1; i <= n; i++) {
        if (i == max+1) continue;
        else cout << max+1 << ' ' << i << endl;
    }
    if (a[max] >= 0) {
        for (int i = 1; i < n; i++) cout << i << ' ' << i + 1 << endl;
    }
    else {
        for (int i = n; i > 1; i--) cout << i << ' ' << i - 1 << endl;
    }
    return 0;
}

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

using namespace std;

typedef struct UnionFind {
    vector<int> vertex;
    UnionFind(int size) : vertex(size,-1) { }
    bool Union(int x, int y){
        x = root(x); y = root(y);
        if( x != y ) {
            if(vertex[y] < vertex[x]) swap(x,y);
            vertex[x] += vertex[y]; vertex[y] = x;
        }
        return x != y;
    }

    bool Find(int x, int y){
        return root(x) == root(y);
    }

    int root(int x){
        return vertex[x] < 0 ? x : vertex[x] = root(vertex[x]);
    }
    int size(int x){
        return -vertex[root(x)];
    }
} UnionFind;


int main() {
    int N,W,H;
    cin >> N >> W >> H;
    vector<int> vectx(W,-1),vecty(H,-1);;
    UnionFind uf(N);
    bool wall=false;
    int num = N;
    int x,y;
    for(int i=0 ; i<N ; i++){
        cin >> x >> y;
        if( x==1 || x==W || y==1 || y==H) wall = true;
        x--;y--;
        if(vectx[x]==-1){
            vectx[x]=i;
        }else{
            if(!uf.Find(i,vectx[x])){
                uf.Union(i,vectx[x]);
                num--;
            }
        }
        if(vecty[y]== -1){
            vecty[y]=i;
        }else{
            if(!uf.Find(i,vecty[y])){
                uf.Union(i,vecty[y]);
                num--;
            }
        }
    }

    if(num==1){
        cout << N-1 << endl;
    }else if(wall){
        cout << N-2+num << endl;
    }else {
        cout << N-1+num << endl;
    }
    return 0;
}



Measured memory_bytes: 3816
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
b.append(0)
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  if a[i]<b[i]:
    cnt+=a[i]
    cnt+=min(b[i]-a[i], a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
print(str(cnt))
  

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

int main() {
  int A, B, C;
  cin>> A >>B >>C;
  
  //A==B
  if(A==B)
  cout<< C;  
    
  //A==C
  else if(A==C)
  cout<< B;  
  
  //B==C
  else if(B==C)
  cout<< A;  
    
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<ll, ll> P;
     
    int L, N = 0;
    vector<vector<int>> edge;
     
    int main(void){
    	
    	scanf("%d", &L);
        while(1 << N <= L) ++N;
        
        for(int i = 1; i < N; ++i){
            edge.push_back({i, i + 1, 1 << (i - 1)});
            edge.push_back({i, i + 1, 0});
        }
    	
    	int corrent = (1 << (N - 1)) - 1;
    	
    	for(int i = N - 1; i >= 1 && corrent != L - 1; i--){
    	    
    	    int add = 1 << (i - 1);
    	    
    	    if(corrent + add <= L - 1){
    	        edge.push_back({i, N, corrent + 1});
    	        corrent += add;
    	    }
    	    
    	}
    	
    	printf("%d %d\n", N, (int)edge.size());
    	for(auto i : edge) printf("%d %d %d\n", i[0], i[1], i[2]);
    	//for(auto i : edge) if (i[0]==i[1]&&i[1]==i[2]){} 
        return 0;
    }

Measured memory_bytes: 256