akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 56;

vector<int> g[N];
int tin[N], low[N];
bool bio[N];
int timer, ans;

void dfs(int u, int p=-1) {
	bio[u] = true;
	tin[u] = low[u] = timer++;
	for (int v: g[u]) {
		if (v == p) continue;
		if (bio[v]) {
			low[u] = min(low[u], low[v]);
			continue;
		}
		dfs(v, u);
		low[u] = min(low[u], low[v]);
		if (low[v] > tin[u]) ++ans;
	}
}

void solve() {
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) tin[i] = low[i] = -1;
	for (int i = 0; i < m; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		g[--u].push_back(--v);
		g[v].push_back(u);
	}
	dfs(0);
	printf("%d", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

// Input
#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
#[allow(unused_imports)]
use std::cmp::{min,max};

// Main
fn main(){
    input!{
        n: usize,
        _l: u64,
        s: [String; n]
    }
    let mut s = s;
    s.sort();
    for ss in s{
        print!("{}", ss);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	if (a.back() == b.front() && b.back() == c.front()) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
K = int(input())
res = 0
surplus = 1

if K % 2 == 0 or K % 5 == 0:
    res = -1
else:
    if K % 7 == 0:
        K /= 7
    while True:
        res += 1
        surplus = (10 * surplus) % (9*K)
        if surplus == 1:
            break
print(res)


Measured memory_bytes: 9160
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
const int MAX=100,INF=1<<30,WHI=0,GRA=1,BLA=2;
int n,m[MAX][MAX];
int prim(){
    int u,minv;
    int d[MAX],p[MAX],color[MAX];
    fill(d,d+n+1,INF);
    fill(p,p+n+1,-1);
    fill(color,color+n+1,WHI);
    d[0]=0;
    while(1){
        minv=INF;
        u=-1;
        REP(i,n){
            if(minv>d[i]&&color[i]!=BLA){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLA;
        REP(v,n){
            if(color[v]!=BLA&&m[u][v]!=INF){
                if(m[u][v]<d[v]){
                    d[v]=m[u][v];
                    p[v]=u;
                    color[v]=GRA;
                }
            }
        }
    }
    int sum=0;
    REP(i,n){
        if(p[i]!=-1) sum+=m[i][p[i]];
    }
    return sum;
}
int main(){
    scanf("%d",&n);
    REP(i,n){
        REP(j,n){
            int e;
            scanf("%d",&e);
            m[i][j]=(e==-1)?INF:e;
        }
    }
    printf("%d\n",prim());
    return 0;
}




Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int dp[3009][3009];
int main()
{
    string x,y;
    cin>>x>>y;
    int n=x.size();
    int m=y.size();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(x[i-1]==y[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    //cout<<dp[n][m]<<"\n";
    string ans="";
    int i=n,j=m;
    while(1)
    {
            if(dp[i][j]>max(dp[i-1][j],dp[i][j-1]))
            {
                ans+=x[i-1];
                j--;i--;
            }
            else if(dp[i][j]==dp[i-1][j])
            {
                i--;
            }
            else j--;
            if(i==0||j==0||dp[i][j]==0)break;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";
}


Measured memory_bytes: 35584
#include <iostream>

using namespace std;

int main()
{
    int n, c[5];
    cin >> n;
    c[1] = n % 10;
    c[2] = n / 10 % 10;
    c[3] = n / 100 % 10;
    c[4] = n / 1000 % 10;
    int cnt;
    for (int i = 1; i <= 2; ++i) {
        cnt = 1;
        for (int j = i + 1; j <= 4; ++j) {
            if (c[j] == c[i])
                ++cnt;
            else
                j = 5;
            if (cnt >= 3) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException, Exception{
		BufferedReader st = new BufferedReader(new InputStreamReader(System.in));
		int n = getInt(st);
		String[] data = getStrArry(st);
		int[] ans = new int[n];
		for(int i=0;i<n;i++) {
			ans[Integer.parseInt(data[i]) - 1] = i + 1;
		}
		anser(ans);
	}

	private static int getInt(BufferedReader st) throws Exception, IOException {
		int num = Integer.parseInt(st.readLine());
		return num;
	}

	private static String[] getStrArry(BufferedReader st) throws Exception, IOException {
		String line = st.readLine();
		String[] strData = line.split(" ");
		return strData;
	}

	private static void anser(int[] numData) {
		for (int i = 0; i < numData.length; i++) {
			System.out.print(numData[i]);
			System.out.print(" ");
		}
		System.out.println();
	}
}

Measured memory_bytes: 42080
#include <cstdio>
#include <stack>
#include <algorithm>

using namespace std;

stack <int> st;
int ap[4096];

int main ()
{
    int a, b;
    scanf ("%d %d", &a, &b);

    if (a <= b)
    {
        printf ("Impossible\n");
        fflush (stdout);

        return 0;
    }

    for (int i = 1; i <= a + b; ++i)
    {
        if (st.size () == 0) st.push (i);
        else
        {
            printf ("? %d %d\n", st.top () - 1, i - 1);
            fflush (stdout);

            char c;
            scanf (" %c", &c);

            if (c == 'N') st.pop ();
            else st.push (i);
        }
    }

    int x = st.top ();
    ap[x] = 1;

    for (int i = 1; i <= a + b; ++i)
    {
        if (i != x)
        {
            printf ("? %d %d\n", x - 1, i - 1);
            fflush (stdout);

            char c;
            scanf (" %c", &c);

            if (c == 'Y') ap[i] = 1;
        }
    }

    printf ("! ");
    for (int i = 1; i <= a + b; ++i)
        printf ("%d", ap[i]);

    printf ("\n");
    fflush (stdout);

    return 0;
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long int ll;
int main()
{
	ll n, sum=0;
	cin>>n;
	std::vector<ll> a(n+1);
	std::vector<ll> b(n);
	for (int i = 0; i < n+1; ++i)
	{
		/* code */cin>>a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		/* code */cin>>b[i];
	}
	for (int i = 0; i < n; ++i)
	{
		if(a[i]<=b[i])
		{
			b[i]-=a[i];
			sum+=a[i];
			if(a[i+1]<=b[i]){
				sum+=a[i+1];
				a[i+1]=0;
			}
			else{
				sum+=b[i];
				a[i+1]-=b[i];
			}
		}
		else
			sum+=b[i];
	}
	cout<<sum<<"\n";
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<cstdio>
#include<string>  
#include<algorithm>
#include<cmath>  
#include<iostream>
#include<queue>
#include<cstdlib>
#include<cstring>
#define maxn 200000
#define ll long long
using namespace std;
ll a[maxn]={0}; 
int main()
{
	int n,i;
	ll x;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		a[i]=a[i-1]+x;
	}
	ll sum=10000000000000;
	for(i=1;i<n;i++)
	{
		sum=min(sum,abs(a[i]-(a[n]-a[i])));
	}
	printf("%lld",sum);	
	//freopen("名字.in","r",stdin);
	//freopen("名字.out","w",stdout);
	return 0;
 }


Measured memory_bytes: 1792
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let c=read::<i32>();
    println!("{}",(a-b)%c)
}

Measured memory_bytes: 4352
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    
    print("#" * W)
    
    for _ in range(H - 2):
        print("#{}#".format("." * (W - 2)))
    
    print("#" * W)
    print()
    


Measured memory_bytes: 5612
import java.util.*;
import java.lang.*;



public class Main {
    static boolean isGoodDance(String dance){
        for(int i=0; i<dance.length(); i++){
            if(i%2==0 && dance.charAt(i)=='L') return false;
            if(i%2==1 && dance.charAt(i)=='R') return false;
        }
        return true;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String dance = sc.next();
        System.out.println(isGoodDance(dance) ? "Yes" : "No");

    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <cstring>


using namespace std;

int main(){
    int N,K,i,j,lr,rl,happy;
    string q;
    while(cin >> N >> K){
        cin >> q;
        happy = 0;
        rl = 0;
        lr = 0;
        for(i = 1; i < q.length(); i++){
            if(q[i - 1] == q[i]) happy++;
            else if(q[i - 1] == 'R') rl++;
            else lr++;
        }
        for(j = 0; j < K; j++){
            if(lr && rl){
                lr--;
                rl--;
                happy += 2;
            }else if((lr == 0 && rl != 0) || (lr != 0 && rl == 0)){
                happy++;
                break;
            }else break;
        }
        cout << happy << endl;
    }
    return 0;
}

Measured memory_bytes: 3752
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int X; std::cin >> X;
    int a(X);
    for(int i(1); i <= 361; ++i){
        if(!(a % 360)){
            std::cout << i << std::endl;
            return 0;
        }
        a += X;
    }
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	int* data = new int[n];
	for (int i=0; i<n; i++){
		cin >> data[i];
	}
	int mini;
	int swapCount = 0;
	int temp;
	for (int i=0; i<n; i++){
		mini = i;
		for (int j=i; j<n; j++){
			if (data[j] < data[mini]){
				mini = j;
			}
		}
		if (mini != i) {
			temp = data[i];
			data[i] = data[mini];
			data[mini] = temp;
			swapCount++;
		}
	}
	for (int i=0; i<n-1; i++) {
		cout << data[i] << " ";
	}
	cout << data[n-1] << endl;
	cout << swapCount << endl;
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge{ int from, to, cost; };

int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		vector<P> v;
		REP(i, n)
		{
			int a, b;
			cin >> a >> b; v.push_back(P(b, a));
		}
		sort(ALL(v));
		for (int i = n-1; i>=0&&m>0; i--)
		{
			if (v[i].second <= m)
			{
				m -= v[i].second;
				v[i].second = 0;
			}
			else
			{
				v[i].second -= m;
				m = 0;
			}
		}
		int sum = 0;
		REP(i, n) sum += v[i].first*v[i].second;
		cout << sum << endl;
	}
	return 0;
}

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

int main() {

	string S, T;

	cin >> S >> T;

	size_t size = S.length();

	if (T.compare(0, size, S) == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 3596
#include<iostream>

using namespace std;
int main()

{

char s[4];
int x=0;

for( int i=0;i<4;i++){
    cin>>s[i];
}
for(int i=0;i<4;i++){
    if(s[i]=='-'){
    x--;
}
else if(s[i]=='+'){
    x++;
}
}

cout<<x<<endl;

return 0;

}

Measured memory_bytes: 256
N = int(input())
r = []
for i in range(N):
    s, p = input().split()
    r.append([s, int(p), i + 1])
r = sorted(r, key=lambda x: x[1], reverse=True)
r = sorted(r, key=lambda x: x[0])
for i in r:
    print(i[2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

using namespace std;

const int N = 2777;
int n, m;
int fac[N];
vector <int> a(10);
vector <int> b(10);
set <int> st;
int s = 0;

int solve(vector <int> v){
    for (int i = 1; i <= n; i++){
        st.insert(i);
    }
    int ans = 1;
    for (int i = 1; i <= n; i++){
        int cnt = 0;
        for (auto it = st.begin(); it != st.end(); it++){
            int k = *it;
            if (k != v[i]){
                cnt++;
            }
            else {
                break;
            }
        }
        st.erase(v[i]);
        ans = ans + fac[n - i] * cnt;
    }
    while (!st.empty()){
        st.erase(st.begin());
    }
    return ans;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    fac[0] = 1;
    for (int i = 1; i < n; i++){
        fac[i] = fac[i - 1] * i;
    }
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++){
        cin >> b[i];
    }

    int s1 = solve(a);
    int s2 = solve(b);

    //cout << s1 << " " << s2 << endl;
    cout << abs(s1 - s2) << endl;


    return 0;
}


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

typedef long long ll;

int x, y, a, b, c;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> x >> y >> a >> b >> c;
    int p[a], q[b], r[c];

    ll sum = 0;
    for (int i = 0; i < a; ++i) {
        cin >> p[i];
    }
    for (int i = 0; i < b; ++i) {
        cin >> q[i];
    }
    for (int i = 0; i < c; ++i) {
        cin >> r[i];
    }
    sort(p, p + a, greater<int>());
    sort(q, q + b, greater<int>());
    vector<int> g(r, r + c);
    for (int i = 0; i < x; ++i) {
        g.push_back(p[i]);
    }
    for (int i = 0; i < y; ++i) {
        g.push_back(q[i]);
    }
    sort(g.begin(), g.end(), greater<int>());
    for (int i = 0; i < x + y; ++i) {
        sum += g[i];
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG



int main() {
  string S;
  cin >> S;
  if(S[0] == '7' | S[1] == '7' | S[2] == '7'){
    cout << "Yes" << endl;
    return 0;

  }
  
  
  cout << "No" << endl;

  return 0;
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int beki[110];
int dp[110][110000];
signed main() {
    cin >> N;
    for (int i = 2; i <= N; i++) {
        int x = i;
        while (x != 1) {
            for (int j = 2; j <= sqrt(x); j++) {
                if (x % j == 0) {beki[j]++; x /= j; goto nene;}
            }
            beki[x]++; x = 1;
nene:;
        }
    }
    dp[0][1] = 1;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 110; j++) {
            for (int k = 0; k <= beki[i]; k++) {
                dp[i + 1][j * (k + 1)] += dp[i][j];
            }
        }
    }
    cout << dp[100][75] << endl;
}

Measured memory_bytes: 84352
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    int n;
    char s[51];
    scanf("%d %s", &n, s);

    int cnt = 0;
    for (int i = 0; i < strlen(s) - 3 + 1; i++) {
        //printf("%c %c %c\n", s[i], s[i + 1], s[i + 2]);
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            cnt++;
        }
    }

    printf("%d", cnt);

    return 0;

}


Measured memory_bytes: 128
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
   
    int ans = 1;
    while (ans <= N) ans <<= 1;

    ans >>= 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#define F first
#define S second 
using namespace std;
typedef pair<int,int> P;
int w,h,sx,sy,gx,gy,fc;
int imap[110][110];
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
bool found;
void Init(){
  for(int i=0;i<110;i++){
    for(int j=0;j<110;j++){
      imap[i][j] = -1;
    }
  }
}

void display(){
 for(int i=0;i<=h;i++){
      for(int j=0;j<=w;j++){
	printf("%3d ",imap[i][j]);
      }
      cout << endl;
    }
}

void draw(int c,int d,int x,int y){
  int limy,limx;
  limy = d==1?4:2;
  limx = d==1?2:4;
  for(int i=0;i<limy && i<=h;i++){
    for(int j=0;j<limx && j<=w;j++){
      imap[y+i][x+j] = c;
    }
  }
}

void rec(int px,int py){
  if(px == gx && py == gy){
    found = true;
    return;
  }
  for(int i=0;i<4;i++){
    int nx = px+dx[i], ny = py+dy[i];
    if(!found && 0<=nx && nx <=w && 0<=ny && ny<=h && imap[ny][nx] == fc){
      imap[ny][nx] = -1;
      rec(nx,ny);
    }
  }
}


bool isMaze(){
  rec(sx,sy);
  if(found)return true;
  return false;
}

int main(){
  int n,c,d,x,y;
  while(cin >> w >> h  && w && h){
    found = false;
    cin >> sx >> sy;
    cin >> gx >> gy;
    cin >> n;
    Init();
    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;
      draw(c,d,x,y);
    }

    
    fc = imap[sy][sx];
    if(fc == -1)cout << "NG" << endl;
    else{
      if(isMaze())cout << "OK" << endl;
      else cout << "NG" << endl;
    }

  }
  return 0;
}

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

int main() {
  int min;
  int max;
  cin >> min >> max;
  int diff;
  diff = max - min + 1;
  
  int A;
  int p, q, r, s;
  int N=0;
  for (int i=0; i<diff; i++) {
    A = min + i;
    p = A / 10000;
    s = A % 10;
    q = (A - p*10000) / 1000;
    r = (A % 100 - s)/10;
    //cout << p<<q<<r<<s<< endl;
    if (p==s&&q==r) {
        N++;
      }
    }
    cout << N << endl;
}


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

int main() {
    int n;
    cin >> n;
    int a[n + 1] = {};
    for(int i = 1; i <= n; i++) cin >> a[i];

    int left[n] = {};
    int right[n + 2] = {};

    for(int i = 0; i < n - 1; i++) {
        left[i + 1] = max(left[i], a[i + 1]);
        right[n - i] = max(right[n - i + 1], a[n - i]);
    }

    for(int i = 1; i <= n; i++) cout << max(left[i - 1], right[i + 1]) << endl;

    return 0;
}

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

int main(){
	int n,a,ans;
	int f=0;
	while(1){
		cin>>n;
		if(n==0) break;
		f=0;
		ans=n;
		for(int i=0;i<n;i++){
			cin>>a;
			if(a>=2) f=1;
			else if(a==0) ans--;
		}
		if(f==0) cout<<"NA"<<endl;
		else cout<<ans+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#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 repl(i,list) for(int i : list)
using namespace std;

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

    cout << (A - 2 * B  >= 0 ? A - 2 * B : 0) << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
L = []
R = []

mod = 998244353

for i in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r + 1)

diff = [0] + [1] + [-1] + [0] * (10 ** 5 * 5)
ans = [0] * (10 ** 5 * 5)

for i in range(1, N + 1):
    ans[i] = ans[i-1] + diff[i]
    ans[i] %= mod
    for j in range(K):
        diff[i + L[j]] += ans[i]
        diff[i + R[j]] -= ans[i]
        diff[i + L[j]] %= mod
        diff[i + R[j]] %= mod

print(ans[N])

Measured memory_bytes: 35360
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int A=0;
  for (int c=1; c<10; c++) {
    for (int d=0; d<10; d++) {
      for (int e=0; e<10; e++) {
        int f = c*10001+d*1010+e*100;
        if (f<=b && f>=a) {
          A += 1;
        }
      }
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include <string>

using namespace std;

int main(){
  int n; cin>>n;
  
  string s = to_string(n);
  
  int sn=0;
  for(int i=0;i<s.length();i++){
    sn+=stoi(s.substr(i,1));
  }
  //cout<<sn<<endl;
  if(n%sn==0) cout<<"Yes";
  else cout<<"No";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> key(m);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        ll bit = 0;
        rep(j, b) {
            ll c;
            cin >> c;
            bit |= (1 << (c - 1));
        }
        key[i] = make_pair(a, bit);
    }
    vector<vector<ll>> dp(m + 1, vector<ll>(1 << n, inf));
    dp[0][0] = 0;
    rep(i, m) {
        rep(j, 1 << n) dp[i + 1][j] = dp[i][j];
        rep(j, 1 << n) {
            if (dp[i][j] == inf) continue;
            ll next = j | key[i].second;
            dp[i + 1][next] = min(dp[i + 1][next], dp[i][j] + key[i].first);
        }
    }
    ll all = (1 << n) - 1;
    if (dp[m][all] == inf) cout << -1 << endl;
    else cout << dp[m][all] << endl;
    return 0;
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    if A==B==C:
        print(NO)
        return
    print(YES if A==B or B==C or A==C else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;i--)
#define PI 3.1415926535897932384626433832795
#define fi first
#define se second
#define mp(x,y) make_pair
#define BIN(n,x) bitset<>  
using namespace std;

//BITSET
//bitset< ##no of digits required in binary## > x( ##integral string value## )   // bitset< ##no of digits required in binary## > x( ##number## ) 
//stores binary value of the string in x // constructor sets all values to 0 by default // x.set() sets all value to 1 //x.none() checks for 0{gives bool}
//-->x.count() gives no of 1's //--> x.size() gives total bits //--> x.test(i) returns binary value of i'th bit

//SETPRECISION
//cout<<fixed<<setprecision(#n#)<<x;  --> sets the no of digits of x after decimal to n

//SET STL
//insert();*** count() returns 1 if element is present or 0  **** ;find() {returns iterator pointing to element else returns end iterator}; ---> O(log(N))
//begin();end(){next to last};---->O(1)
//See sorting

//VECTOR STL
//begin(); back();-->O(1)
//sort(v.begin(),v.end()); -->{O(Nlog(N))}

//MAP STL map<U,V> mp; U=key val  V = mapped val
//count(k) (returns 1 if element with key value k is found}-->O(log(N))
//See sorting



long long BERem(long long a, long long b, long long m){
    a%=m;
    long long res =1;
    while(b>0){
        if(b&1){
            res = (res * a)%m;
        }
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}


int main(){

    int x;
    cin>>x;
    int happy;
    int v=x%500;
    happy = (v/5)*5+(x/500)*1000;
    cout<<happy<<endl;
    
    
    


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
int main() {
    int N,K; cin >> N >> K;
    vector<ll> a(N),b(N);
    for (int i=0;i<N;i++) cin >> a[i];
    ll res = 1e11;
    for (int bit=0;bit<(1<<N);bit++){
        // フラグ立っているところが見えるように.
        if(__builtin_popcount(bit) < K) continue;
        ll cost = 0, max_h = 0;
        for (int i=0;i<N;i++){
            if ((bit & (1<<i)) && (a[i]<= max_h)){
                cost += (max_h + 1) - a[i]; 
                max_h++;
            }
            chmax(max_h, a[i]);
        }
        chmin(res,cost);
    }
    cout << res << endl;
    return 0;
}


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




void solve()
{
       string a,b;
       cin >> a >> b;
       int n = a.size(), m = b.size();

       vector< vector<int> > memo( n+1, vector<int> (m+1,0));


       for(int i = 1 ; i <= n ; i ++)
       	  for(int j = 1 ; j <= m ; j++ )
       	  {
       	  	 memo[i][j] = ( a[i-1] == b[j-1] ) ? 1 + memo[i-1][j-1] : max(memo[i-1][j],memo[i][j-1]) ; 
       	  }
       	
        
        int i = n, j = m ;
        string ans = "" ;
        
        while( i > 0 and j > 0 )
          if ( a[i-1] == b[j-1] ) i--,j--, ans.push_back(a[i]);
          else if(memo[i-1][j] > memo[i][j-1]) i--;
          else j--;
        
        reverse(begin(ans),end(ans)); 
       	cout << ans ; 
       


}

int main()
{

	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);

	
	 int test = 0, t = 1;
	 if(test) cin >> t;
	 for(int i = 0 ; i < t ; i ++)
	 {
         solve(); 
	 }

	return 0;
}


Measured memory_bytes: 38544
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    ll k = (n + 1) / 2;
    for(ll i=0;i<k;++i){
        cout<<a[n-i*2-1]<<' ';
    }
    ll t = n / 2;
    for(ll i=0;i<t;++i){
        if(i == t-1){
            cout<<a[i*2+n%2];
        }else{
            cout<<a[i*2+n%2]<<' ';
        }
    }    
    cout<<endl;

    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#define maxn 1000005
#define LL long long
#define mod 1000000007

using namespace std;

int k,n,a[maxn];

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int n, c[N], cnt[N], siz[N];
inline ll cal(int x) {
	return 1ll * x*(x+1)/2;
}
ll ans[N];
vector<int>G[N];
	void dfs(int v, int fa) {
		int tmp = cnt[c[v]];
		siz[v] = 1;
		for(int u:G[v]) {
			if(u==fa) continue;
			cnt[c[v]] = 0;
			dfs(u, v);
			siz[v] += siz[u];
			ans[c[v]]+=cal(siz[u]-cnt[c[v]]);
		}
		cnt[c[v]] = tmp + siz[v];
	}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &c[i]);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", cal(n) - ans[i] - cal(n - cnt[i]));
	}
	return 0;
}


Measured memory_bytes: 37184
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int q;
    cin >> q;
    priority_queue<LL, vector<LL>, greater<LL>> sr;
    priority_queue<LL> sl;
    LL tl = 0, tr = 0, tB = 0;
    int ct = 0;
    rep(i, q){
        int n;
        cin >> n;
        if(n == 1){
            LL a, b;
            cin >> a >> b;
            tB += b;
            if(ct % 2 == 1){
                sl.push(a); tl += a;
                sr.push(sl.top()); tr += sl.top();
                tl -= sl.top(); sl.pop();
            }else{
                sr.push(a); tr += a;
                sl.push(sr.top()); tl += sr.top();
                tr -= sr.top(); sr.pop();
            }
            ct++;
        }else{
            LL A = sl.top();
            LL B = A*sl.size()-tl + tr-(A*(LL)sr.size()) + tB;
            cout << A << " " << B << endl;
        }
    }


}

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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}


 
int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;

  int time1 = 60 * H1 + M1;
  int time2 = 60 * H2 + M2;

  int diff = time2 - time1;

  int ans = diff - K;

  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const long long Maxn=110;
const long long inf=(1ll<<60);
long long x,k,d,ans=inf;
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	x=read(),k=read(),d=read();
	long long tmp=k-abs(x)/d;
	if(!(tmp & 1) && tmp>=0)
	ans=min(ans,abs(x)%d);
	--tmp;
	if(!(tmp & 1) && tmp>=0)
	ans=min(ans,d-abs(x)%d);
	ans=min(ans,min(abs(x-k*d),abs(x+k*d)));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vector<string> S(N);
    readv(S);
    int ans = 0;
    REP(i, N){
        REP(j, SZ(S[i]) - 1) if(S[i][j] == 'A' && S[i][j + 1] == 'B') ans++;
    }
    int hB = 0, tA = 0;
    int w = 0;
    REP(i, N){
        if(S[i][0] == 'B') hB++;
        if(S[i][SZ(S[i]) - 1] == 'A') tA++;
        if(S[i][0] == 'B' && S[i][SZ(S[i]) - 1] == 'A') w++;
    }
    int tmp = min(tA, hB);
    if(tA == w && hB == w && tmp >= 1) tmp--;
    ans += tmp;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> input = new ArrayList<Integer>();
        for(int i = 0; i<3; i++)
        {
            input.add(sc.nextInt());
        }

        Collections.sort(input);

        System.out.println(input.get(0)+input.get(1));
    }
}

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

int N;
vector<P> xi, yi;
vector<T> edges;

struct Unionfind {
    vector<int> par, rank;
    
    Unionfind(int n) {
        par.resize(n);
        fill(par.begin(), par.end(), -1);
        rank.resize(n);
    }
    
    int root(int x) {
        int r = x;
        while (!(par[r]<0)) r = par[r];
        int t = x;
        
        while (t!=r) {
            int tmp = t;
            t = par[t];
            par[tmp] = r;
        }
        
        return r;
    }
    
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        
        if (rx==ry) return;
        
        if (rank[rx]<=rank[ry]) {
            par[ry] += par[rx];
            par[rx] = ry;
            
            if (rank[rx]==rank[ry]) rank[ry]++;
        }
        else {
            par[rx] += par[ry];
            par[ry] = rx;
        }
    }
    
    bool is_same(int x, int y) {
        return root(x)==root(y);
    }
    
    int count(int x) {
        return -par[root(x)];
    }
};
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) {
        int x, y; cin >> x >> y;
        xi.pb(P(x, i));
        yi.pb(P(y, i));
    }
    sort(xi.begin(), xi.end());
    sort(yi.begin(), yi.end());
    
    rep(i, N-1) {
        int s = xi[i].second;
        int t = xi[i+1].second;
        int cost = xi[i+1].first-xi[i].first;
        edges.pb(make_tuple(cost, s, t));
    }
    rep(i, N-1) {
        int s = yi[i].second;
        int t = yi[i+1].second;
        int cost = yi[i+1].first-yi[i].first;
        edges.pb(make_tuple(cost, s, t));
    }
    sort(edges.begin(), edges.end());
    
    Unionfind uf(N);
    int ans = 0;
    rep(i, 2*(N-1)) {
        int s = get<1>(edges[i]);
        int t = get<2>(edges[i]);
        int cost = get<0>(edges[i]);
        if (!uf.is_same(s, t)) {
            uf.unite(s, t);
            ans += cost;
        }
    }
    cout << ans << endl;
}

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


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

    int diff = 0;
    if(B <= C) diff = 0;
    else if(D <= A) diff = 0;
    else if(A <= C && B <= D) diff = B - C;
    else if(C <= A && D <= B) diff = D - A;
    else if(C <= A && B <= D) diff = B - A;
    else if(A <= C && D <= B) diff = D - C; 

    cout << diff << endl;
}

Measured memory_bytes: 256
from heapq import heapify, heappush, heappop

def main():
    N = int(input())
    A = list(map(int, input().split()))
    heapify(A)
    while len(A) > 1:
        m = heappop(A)
        A = [a % m for a in A if a % m != 0]
        A.append((m))

    print(m)


if __name__ == "__main__":
    main()

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

left = 0
right = N
if A > B:
    A, B = B, A


def solve(n):
    minimum = A + C * n - (N - 1 - n) * D
    maximum = A + D * n - (N - 1 - n) * C
    if minimum <= B <= maximum:
        print('YES')
        exit()
    elif B < minimum:
        return False
    else:
        return True


while right - left > 1:
    mid = (right + left) // 2
    if solve(mid):
        left = mid
    else:
        right = mid
else:
    print('NO')


Measured memory_bytes: 3064
//---------- begin union_find ----------
#[allow(dead_code)]
mod union_find {
    pub struct UF {
        p: Vec<i32>,
    }
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {p: vec![-1; n] }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&mut self, mut x: usize) -> usize {
            while self.p[x] >= 0 {
                let p = self.p[x] as usize;
                if self.p[p] >= 0 {
                    let q = self.p[p];
                    self.p[x] = q;
                    x = q as usize;
                } else {
                    return p;
                }
            }
            x
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> {
            let mut x = self.root(x);
            let mut y = self.root(y);
            if x == y {
                return None;
            }
            if self.p[x] > self.p[y] {
                std::mem::swap(&mut x, &mut y);
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
            Some((x, y))
        }
        pub fn parent(&self, x: usize) -> Option<usize> {
            let p = self.p[x];
            if p >= 0 {
                Some(p as usize)
            } else {
                None
            }
        }
        pub fn get_size(&mut self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------

use proconio::*;
use proconio::marker::*;

fn run() {
    input! {
        n: usize,
        p: [(Usize1, Usize1); n],
    }
    let w = 100_000;
    let mut dp = vec![(0usize, 1usize); 2 * w];
    for p in dp.iter_mut().take(w) {
        *p = (1, 0);
    }
    let mut u = union_find::UF::new(2 * w);
    for (x, y) in p {
        if let Some((a, b)) = u.unite(x, y + w) {
            dp[a].0 += dp[b].0;
            dp[a].1 += dp[b].1;
            dp[b] = (0, 0);
        }
    }
    let ans = dp.into_iter().map(|p| p.0 * p.1).sum::<usize>() - n;
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8676
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

int main(){
  while(1){
  int n;
  cin >> n;
  if(n==0) break;
  vector<int> a;
  int tmp=0;
  for(int i=0;i<n;i++) {
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(),a.end());
  int ave=0;
  for(int i=1;i<n-1;i++){
    ave+=a[i];
  }
  ave=ave/(n-2);

  cout << ave << endl;
  }
  return 0;

}

Measured memory_bytes: 1220
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let l = read_t_in_line::<i32>();
    let (a, b, c, d) = (l[0], l[1], l[2], l[3]);
    println!("{}", cmp::max(0, cmp::min(b, d) - cmp::max(a, c)));
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
)

func chmax(a *int, b int) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func main() {
	var N, W int
	fmt.Scan(&N, &W)
	weight := make([]int, N)
	value := make([]int, W)
	for i := 0; i < N; i++ {
		fmt.Scan(&weight[i], &value[i])
	}

	dp := make([][]int, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = make([]int, W+1)
	}

	for i := 0; i < N; i++ {
		for w := 0; w <= W; w++ {
			chmax(&dp[i+1][w], dp[i][w])
			if w+weight[i] <= W {
				chmax(&dp[i+1][w+weight[i]], dp[i][w]+value[i])
			}
		}
	}

	fmt.Println(dp[N][W])
}


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

int main() {
	int N, R = 0, B = 0;
	string S;
	cin >> N >> S;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') {
			R++;
		}
		else B++;
	}
	if (R > B) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,M = MI()
	print(int((N+M)*(N+M-1)/2 - N*M))

if __name__ == '__main__':
	main()

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

int main() {
  string S;
  cin >> S;
  
  int N = S.size();
  
  string  S2, S3, tmp1, tmp2, tmp3;
  for (int i = 0; i < (N-1)/2; i++) {
    char tmp = S.at(i);
    S2 = S2 + tmp;
  }
  for (int i = (N+3)/2 - 1; i < N; i++) {
    char tmp = S.at(i);
    S3 = S3 + tmp;
  }
 
  
  
  bool ans = false;
  tmp1 = S;
  tmp2 = S2;
  tmp3 = S3;
  reverse(S.begin(), S.end());
  reverse(S2.begin(), S2.end());
  reverse(S3.begin(), S3.end());
  
  if (S == tmp1 && S2 == tmp2 && S3 == tmp3) {
   ans = true;
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
  
  
  

Measured memory_bytes: 256