akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pii Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};
class Graph {
public:
	int vn;
	int sumcost = 0;
	vector<vector<pii>> g;

	Graph(int n) {
		vn = n;
		g.resize(n);
	}
	virtual void con(int a, int b, int w) = 0;
	int getWeight(int f, int t) {
		auto itr = lower_bound(ALL(g[f]), make_pair(t, INT_MIN));
		if (itr != g[f].end())
			return itr->second;
		return INT_MIN;
	}
	int Costsum() {
		return sumcost;
	}
};

class BiDGraph : public Graph {//無向
public:
	BiDGraph(int n) : Graph(n) {}

	void con(int a, int b, int w = 1) {
		g[a].push_back({ b,w });
		g[b].push_back({ a, w });
		sumcost++;
	}
};
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) { //ｘの入ってる集合と yの入ってる集合を併合
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { //xとyが同じ集合に入っているかどうかを判定
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	bool isroot(int x) {
		return data[x] < 0;
	}
	int size(int x) {
		return -data[root(x)];
	}
};

vector<int> g[100001];
pii col[100001];

void dfs(int cp, int dis, int c) {
	if (!col[cp].first) col[cp].first = c;
	if (col[cp].second >= dis || dis == 0) return;
	col[cp].second = dis;
	for (auto itr : g[cp])
		dfs(itr, dis - 1, c);
};

signed main() {

	int n, m,q;
	pair<pii, int> que[100001];
	scnaf("%d %d", &n, &m);
	REP(i, m) {
		int a, b;
		scanf("%d %d", &a, &b);
		g[--a].push_back(--b);
		g[b].push_back(a);
	}
	scanf("%d", &q);
	REP(i, q) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		que[q-i-1] = { {--a,b}, c };
	}
	
	REP(i, q) {
		dfs(que[i].first.first,que[i].first.second,que[i].second);
	}

	REP(i, n) {
		printf("%d\n", col[i].first);
	}
	return 0;
}

Measured memory_bytes: 8440
//Solution for aoj:0042 A Thief
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
using namespace std;
#define int  long long unsigned int
int w, n, c;
char a;
int trs[1001][2];
int dp[1001][1001];
signed main(){
	while (cin >> w){
		if (!w)
			return 0;
		c++;
		cin >> n;
		for (int i = 1; i <= n; i++){
			cin >> trs[i][0] >> a >> trs[i][1];
		}
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= w; j++){
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				if (j >= trs[i][1])
					dp[i][j] = max(dp[i][j], dp[i - 1][j - trs[i][1]] + trs[i][0]);
			}
		}
		for (int i = 1; i <= w; i++){
			if (dp[n][i] == dp[n][w]){
				cout << "Case " << c << ':' << endl << dp[n][i] << endl << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 9000
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 10000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,e,t;
int dp[301];
int g[1001],c[1001],s[1001][1001];
int cost[11];
int main(void){
	scanf("%d%d%d",&n,&e,&t);
	t--;
	for(int i=0;i<n;i++){
		scanf("%d",&dp[i]);
		if(dp[i]==0){
			dp[i]=INF;
		}
	}
	for(int i=0;i<e;i++){
		scanf("%d%d",&g[i],&c[i]);
		g[i]--;
		for(int j=0;j<c[i];j++){
			scanf("%d",&s[i][j]);
			s[i][j]--;
		}
	}
	bool flag=true;
	while(flag){
		flag=false;
		for(int i=0;i<e;i++){
			for(int j=0;j<c[i];j++){
				cost[j]=dp[s[i][j]];
			}
			sort(cost,cost+c[i]);
			int maxi=0;
			for(int j=0;j<c[i];j++){
				maxi=max(maxi,cost[c[i]-j-1]+j);				
			}
			if(dp[g[i]]>maxi){
				dp[g[i]]=maxi;
				flag=true;
			}
		}
	}
	printf("%d\n",dp[t]==INF?-1:dp[t]);
	return 0;
}

Measured memory_bytes: 7168
I=lambda:list(map(int,input().split()))[::-1];m,n=I();c=[0]*-~n;a=[0]*m
for y,p,i in sorted(I()+[i]for i in range(m)):c[p]+=1;a[i]='%06d'%p+'%06d'%c[p]
for t in a:print(t)

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=0;i<=(n);i++)

int main(){
	string s, hoge;
	cin >> hoge >> s >> hoge;

	cout << "A" << s[0] << "C" << endl;
	
	return 0;
}


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

#define debug(x) cout << #x" = " << x;

#define st first
#define nd second

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

const int MAXN = 2E5 + 10, MAXD = 19;

int n, V;
int a[MAXN];
int pre[MAXD][MAXN], nex[MAXD][MAXN];
int prem[1 << MAXD], sufm[1 << MAXD];

int cnt[MAXN];

int main(){
	scanf("%d%d", &n, &V);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	
	int D = 32 - __builtin_clz(V);
	for (int k = 0; k <= D; ++k){
		int len = V >> D - k;
		pre[k][0] = 1;
		for (int j, i = 1; i <= n; i = j){
			pre[k][i] = i;
			for (j = i + 1; j <= n && a[j] - a[j - 1] <= len; ++j)
				pre[k][j] = i;
		}
		nex[k][n + 1] = n;
		for (int j, i = n; i >= 1; i = j){
			nex[k][i] = i;
			for (j = i - 1; j >= 1 && a[j + 1] - a[j] <= len; --j)
				nex[k][j] = i;
		}
	}

	int n0 = 1 << D;
	prem[0] = 0, sufm[0] = n + 1;
	for (int i = 1; i < n0; ++i){
		prem[i] = 0;
		for (int j = 0; j < D; ++j)
			if (i >> j & 1)
				prem[i] = max(prem[i], nex[j][prem[i ^ 1 << j] + 1]);
	}
	for (int i = 1; i < n0; ++i){
		sufm[i] = n + 1;
		for (int j = 0; j < D; ++j)
			if (i >> j & 1)
				sufm[i] = min(sufm[i], pre[j][sufm[i ^ 1 << j] - 1]);
	}

	for (int i = 0; i < n0; ++i){
		int l = prem[i] + 1, r = sufm[n0 - 1 ^ i] - 1;
		if (l > r){
			++cnt[1], --cnt[n + 1];
			break;
		}
		else{
			if (nex[D][l] >= r)
				++cnt[l], --cnt[nex[D][l] + 1];
			if (pre[D][r] <= l)
				++cnt[pre[D][r]], --cnt[r + 1];
		}
	}

	partial_sum(cnt + 1, cnt + n + 1, cnt + 1);
	for (int i = 1; i <= n; ++i)
		puts(cnt[i] ? "Possible" : "Impossible");

	return 0;
}


Measured memory_bytes: 37504
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report
            int n = int.Parse(Console.ReadLine());
            long t = 0;
            long a = 0;

            for(int i = 0; i < n; i++)
            {
                var line = ReadLine();
                long ti = line[0];
                long ai = line[1];

                if (ti >= t && ai >= a)
                {
                    t = ti;
                    a = ai;
                }
                else
                {
                    long mag1 = GetMagnification(t, ti);
                    long mag2 = GetMagnification(a, ai);

                    if (mag1 > mag2)
                    {
                        t = ti * mag1;
                        a = ai * mag1;
                    }
                    else
                    {
                        t = ti * mag2;
                        a = ai * mag2;
                    }
                }
            }

            Console.WriteLine(t + a);
        }

        static long GetMagnification(long a, long ai)
        {
            if (ai >= a)
            {
                return 1;
            }
            else
            {
                if (a % ai == 0)
                {
                    return a / ai;
                }
                else
                {
                    return a / ai + 1;
                }
            }
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => long.Parse(x)).ToList();
        }
    }
}


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

int main(){
    
    int a,b;
    cin>>a;
    cout<<endl;
    cin>>b;
    
    switch (a){
    case 1:
        if (b == 2) cout<<3;
            else cout<<2;
        break;
    case 2:
        if (b == 1) cout<<3;
            else cout<<1;
        break;
    default:
        if (b == 1) cout<<2;
            else cout<<1;
        break; 
    }
    
    return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

class ST {
    static constexpr auto C = 1L << 18;
    static constexpr auto S = 2 * C;
    static constexpr auto I = -1L;

   public:
    ST() : values_(S, I) {}

    void set(int64_t idx, int64_t value) {
        idx += C - 1;

        values_[idx] = value;
        while (idx > 0) {
            idx = (idx - 1) / 2;
            values_[idx] = max(values_[2 * idx + 1], values_[2 * idx + 2]);
        }
    }

    int64_t query(int64_t b, int64_t e) { return query(b, e, 0L, 0L, C); }

    int64_t query(int64_t b, int64_t e, int64_t idx, int64_t l,
                  int64_t r) const {
        if (e <= l || r <= b) {
            return I;
        }

        if (b <= l && r <= e) {
            return values_[idx];
        }

        return max(query(b, e, 2 * idx + 1, l, (l + r) / 2),
                   query(b, e, 2 * idx + 2, (l + r) / 2, r));
    }

   private:
    vector<int64_t> values_;
};

int main() {
    int64_t n;
    cin >> n;

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    vector<int64_t> l(n);
    ST st;
    for (auto i : irange(0L, n)) {
        l[i] = st.query(0L, a[i]);
        st.set(a[i], i);
    }

    vector<int64_t> r(n);
    st = ST();
    for (auto i : irange(0L, n) | reversed) {
        r[i] = n - 1 - st.query(0L, a[i]);
        st.set(a[i], n - 1 - i);
    }

    int64_t ans = 0;
    for (auto i : irange(0L, n)) {
        cerr << l[i] << " " << r[i] << endl;
        ans += a[i] * (r[i] - i) * (i - l[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 13184
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	int a;
	string s1,s2;
	cin>>s1>>s2;
	int cnt=0;
	for(int i=0;i<s1.length();i++) {
		if(s1[i]!=s2[i]) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3800
n = int(input())
l = list(map(int, input().split()))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for h in range(j+1,n):
            if l[i] != l[j] and l[i] != l[h] and l[j] != l[h]:
                mnum = max(l[i],l[j],l[h])
                if mnum < l[i] + l[j] + l[h] - mnum:
                    ans+=1
print(ans)

Measured memory_bytes: 74052
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (a,b,t) = get!(usize, usize, usize);
    println!("{}", b*(t/a));
}


Measured memory_bytes: 8572
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()

	if a == b {
		for i := 0; i < a; i++ {
			fmt.Printf("%d", a)
		}
		return
	}
	if a > b {
		for i := 0; i < a; i++ {
			fmt.Printf("%d", b)
		}
	} else {
		for i := 0; i < b; i++ {
			fmt.Printf("%d", a)
		}
	}

}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> vector0(W+2);
  int i;
  for (i=0;i<W+2;i++) {
    vector0.at(i) = "#";
    cout << vector0.at(i);
  }
  cout <<endl;
 int j;
  for (j=0;j<H;j++) {
    string A;
    cout << "#";
    cin >> A;
    cout << A;
    cout << "#";
    cout <<endl;
  }
  vector<string> vector1(W+2);
  int l;
  for (l=0;l<W+2;l++) {
    vector1.at(l) = "#";
    cout << vector1.at(l);
  }
  
}

Measured memory_bytes: 3620
import           Control.Monad
import           Data.Bool
import           Data.List
import qualified Data.Vector   as V

readInt = readLn :: IO Int

readInts = map read . words <$> getLine :: IO [Int]

readNInts = flip replicateM readInts

main :: IO ()
main = do
  ae <- replicateM 6 readLn :: IO [Int]
  if all (<= last ae) $ map distance $ combination 2 (init ae)
    then putStrLn "Yay!"
    else putStrLn ":("

combination :: Int -> [a] -> [[a]]
combination 0 xs = [[]]
combination _ [] = []
combination n (x:xs) = [x : y | y <- combination (n - 1) xs] ++ combination n xs

distance :: [Int] -> Int
distance [a, b] = abs $ a - b

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

struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};

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

    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
        A[i]--;
    }

    UnionFind uf(n);

    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(uf.same(i, A[i])) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main (){
  char N[3];
  int n;
  cin >> N;
  
  if(N[0] == N[1] & N[0] == N[2]){
    cout << "Yes";
  }
  else if(N[1] == N[2] && N[1] == N[3]){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <limits.h>
#include <iostream>
#include <numeric>
#define REP(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
const int inf=1<<30;
const int INF=INT_MAX;

int main(void) {
  int a, b, k;
  cin >> a >> b >> k;
  int ans, n;
  n = 0;
  for(ans = __gcd(a, b); ans > 0; --ans) {
    if((a % ans == 0) && (b % ans == 0)) {
        ++n;
        if(n == k) {
            break;
        }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
S = input()
agct = ["A", "G", "C", "T"]

cnt = 0
tmp = 0
for s in S:
  if s in agct:
    tmp = tmp + 1
  else:
    if tmp > cnt:
      cnt = tmp
      tmp = 0
  
if tmp > cnt:
  cnt = tmp

print(cnt)


Measured memory_bytes: 2940
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j,ans,ii,jj
    integer(int64), allocatable:: a(:), ia(:), ja(:)

    read*, n
    allocate(a(n),ia(n),ja(n))
    read*, a(:)
    do i=1,n
        ia(i) = a(i)+i
        ja(i) = -a(i)+i
    end do
    ans=0
    call merge_sort(ia,1_8,n)
    call merge_sort(ja,1_8,n)

    i=1
    j=1

    do while(i <= n .and. j<=n)
        if (ia(i) == ja(j))then
            ii=0
            do while(ia(i) == ia(i+ii))
                ii=ii+1
                if (i+ii > n) exit
            end do
            jj=0
            do while(ja(j)==ja(j+jj))
                jj=jj+1
                if (j+jj > n)exit
            end do
            ans=ans+ii*jj
            i=i+ii
            j=j+jj
        else if (ia(i) > ja(j)) then
            j=j+1
        else
            i=i+1
        end if
    end do
    print'(i0)', ans


contains
recursive subroutine merge_sort(ar, fst, lst)
    integer(int64),intent(inout):: ar(:)
    integer(int64),intent(in):: fst,lst
    integer(int64):: mdl

    if (lst-fst < 2) then
        if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
        return
    end if

    mdl = (fst+lst)/2
    call merge_sort(ar, fst, mdl)
    call merge_sort(ar, mdl+1, lst)
    call merge_(ar, fst, mdl, lst)
end subroutine

subroutine merge_(ar, fst, mdl, lst)
    integer(int64),intent(inout):: ar(:)
    integer(int64),intent(in):: fst, mdl, lst
    integer(int64),allocatable:: tmp(:)
    integer(int64):: li, ri, ti

    allocate(tmp(lst-fst+1))

    li=fst
    ri=mdl+1   
    ti=1

    do while (li <= mdl .and. ri <= lst)
        if (ar(li) <= ar(ri)) then
            tmp(ti) = ar(li)
            li=li+1
        else
            tmp(ti) = ar(ri)
            ri=ri+1
        end if
        ti=ti+1
    end do

    if (li <= mdl) then
        tmp(ti:) = ar(li:mdl)
    else
        tmp(ti:) = ar(ri:lst)
    end if

    ar(fst:lst) = tmp(:)
    deallocate(tmp)
end subroutine

subroutine swap(x,y)
    integer(int64),intent(inout):: x,y
    integer(int64):: tmp
    tmp = x
    x = y
    y = tmp
end subroutine
    

end program name

Measured memory_bytes: 10056
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define sqr(x) (x) * (x)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define rALL(a) a.rbegin(), a.rend()
#define SORT(a) sort(ALL(a))
#define sc scanf
#define pr printf
#define xatop(a) cerr << #a << " = " << a << endl;
#define jsatr debug(__LINE__)
#define INF 1000000000
#define mod 1000000007

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

	int jv;
	jv += min(a, k);
	k -= min(a, k);

	if (k)
		k -= min(b, k);

	if (k)
		jv -= min(c, k), k -= min(c, k);

	cout << jv << endl;

	return 0;
}


Measured memory_bytes: 3568
#include <cstdio>
#include <algorithm>

#define ff(i,a,b) for (int i=(a);i<=(b);i++)
using namespace std;
const int N=1010, inf=2e9+9;
int n,m;
int a[N][N], sa[N][N];
bool ready[N][N][2]; int memo[N][N][2];
int sum (int r1, int c1, int r2, int c2) {
    if (r1>r2 || c1>c2) return 0;
    return sa[r2][c2] - sa[r2][c1-1] - sa[r1-1][c2] + sa[r1-1][c1-1];
}
int game (int r, int c, int p) {
    if (r==n+1 && c==m+1) return 0;
    if (ready[r][c][p]) return memo[r][c][p];
    int ans=(p==0)?-inf:inf; ///Đang muốn làm max/làm min miệu.
    ///Người cmơi miện tại: Nam tiến
    if (r<n+1) {
        int tmp = game(r+1, c, 1-p) + sum(r,c,r,m) - sum(r,1,r,c-1); ///Hiệu (Nobuo-Shizuo) mới.
        if (p==0) { ///Đây là Nobuo, ăn pmía đông
            if (tmp > ans)
                ans = tmp;
        }
        else { ///Đây là Shizuo, sẽ ăn phần phía tây.
            if (tmp<ans)
                ans = tmp;
        }
    }
    ///Người chơi hiện tại: Đông tiến.
    if (c<m+1) {
        ///Nobuo ăn Bắc, Shizuo ăn nam
        int tmp = game(r, c+1, 1-p) + sum(1,c,r-1,c) - sum(r,c,n,c);
        if (p==0) {
            if (tmp>ans)
                ans=tmp;
        }
        else {
            if (tmp<ans)
                ans=tmp;
        }
    }
    ready[r][c][p]=1;
    return memo[r][c][p]=ans;
}
int main() {/*
    freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); //*/
    scanf("%d%d",&n,&m); swap(n,m);
    ff(i,1,n)
    ff(j,1,m) {
        scanf("%d",&a[i][j]);
        sa[i][j] = sa[i-1][j] + sa[i][j-1] - sa[i-1][j-1] + a[i][j];
    }
    printf("%d\n",abs(game (1,1,0))/2);
    return 0;
}



Measured memory_bytes: 20632
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a+b>a-b){
        if(a*b>a+b) printf("%d\n",a*b);
        else printf("%d\n",a+b);
    }
    else{
        if(a-b<a*b) printf("%d\n",a*b);
        else printf("%d\n",a-b);
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
s=[input() for i in range(N)]
ans=0
for st in s:
    ans+= st.count("AB")

a_cnt=0
b_cnt=0
ab_cnt=0
for i in range(N):
    if s[i][-1]=="A":
        a_cnt+=1
    if s[i][0]=="B":
        b_cnt+=1
    if s[i][-1]=="A" and s[i][0]=="B":
        ab_cnt+=1
ans+=min(a_cnt,b_cnt)
if ab_cnt==b_cnt==a_cnt:
    if ab_cnt!=0:
        ans-=1

print(ans)





Measured memory_bytes: 45912
import math
import sys
readline = sys.stdin.readline


def main():
    x = int(readline().rstrip())
    ans = x // 100
    if ans == 0:
        print(0)
        return

    sur = x - ans * 100
    print(1 if sur / ans <= 5 else 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9084
#include <bits/stdc++.h>
std::vector<int> A['   '];
int N, M, S['   '], B, L, R, I, X;
void U(int z, int u) {
  while (z <= N)
    S[z] += u, z += z & -z;
}
main() {
  std::cin >> M >> N;
  for (I = 1; I <= M; I++)
    std::cin >> L >> R, A[R - L + 1].push_back(L);
  for (L = 1; L <= N; L++) {
    B = M;
    for (I = L; I <= N; I += L) {
      X = I;
      while (X)
        B += S[X], X -= X & -X;
    }
    for (int u : A[L])
      U(u, 1), U(u + L, -1), M--;
    std::cout << B << "\n";
  }
}

Measured memory_bytes: 53760
#include<stdio.h>

int selectionSort(int A[], int N){
  int i,j,t,count=0,minj;
  for(i = 0 ; i < N ; i++){
    minj = i;
    for(j = i ; j < N ; j++){
      if(A[j] < A[minj]) minj = j;
    }
    t = A[i];
    A[i] = A[minj];
    A[minj] = t;
    if(i != minj) count++;
  }
  return count;
}

int main(){
  int A[100], N, i, count;

  scanf("%d",&N);
  for(i = 0 ; i < N ; i++) scanf("%d", &A[i]);

  count = selectionSort(A, N);

  for(i = 0 ; i < N ; i++){
    if(i > 0) printf(" ");
    printf("%d",A[i]);
  }

  printf("\n");
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2140
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();

        if(a%2==1 || b%2 == 1 || c%2 == 1){
            System.out.print("0");
            return;
        }

        if(a==b && b== c){
            System.out.print("-1");
            return;
        }

        for(int i=1; i>0; i++){
            int ta = b/2 + c/2;
            int tb = a/2 + c/2;
            int tc = a/2 + b/2;
            a = ta;
            b = tb;
            c = tc;
            if(a%2==1 || b%2 == 1 || c%2 == 1){
                System.out.print(i);
                break;
            }
        }
	}
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<vector<int>> a(n, vector<int>(n - 1));
  rep(i, n) rep(j, n - 1) cin >> a[i][j];

  set<pair<int, int>> s1;
  set<pair<int, int>> s2;
  vector<int> indice(n);
  auto advance = [&](int x) {
    int y = a[x][indice[x]] - 1;
    ++indice[x];
    if (x > y) swap(x, y);
    const auto it = s1.insert({x, y});
    if (!it.second) {
      s2.insert({x, y});
    }
  };
  rep(i, n) advance(i);
  int ans = 0;
  int completed = 0;
  while (true) {
    vector<pair<int, int>> v;
    for (const auto p : s2) {
      v.push_back(p);
    }
    dbg(v.size());
    if (v.empty()) {
      out(-1);
      return 0;
    }
    for (const auto p : v) {
      advance(p.first);
      advance(p.second);
      s2.erase(p);
      ++completed;
    }
    ++ans;
    dbg(completed);
    if (completed == n * (n - 1) / 2) break;
  }
  out(ans);
}


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

const ll MOD = ll(1e9) + 7;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll i, ll mod){
    return modpow(i, mod-2, mod);
}

int main()
{
    // int N, K;
    // cin >> N >> K;
    // ll ans = 0;
    // repSE(i,K,N+2) {
    //     ll ci = i*(N-i+1) + 1;
    //     ans = (ans + ci) % MOD;
    //     // cout << "i: " << i << ", ans: " << ans << endl;
    // }
    // cout << ans << endl;
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    ll tmp = (N+2)*(N+1) % MOD;
    tmp = (tmp * N) % MOD;
    tmp = tmp * modinv(3, MOD) % MOD;
    ans = (ans - tmp) % MOD;
    //
    tmp = (K * (K-1)) % MOD;
    tmp = (tmp * (K-2)) % MOD;
    tmp = (tmp * modinv(3, MOD)) % MOD;
    ans = (ans + tmp) % MOD;
    //
    tmp = (N * (N+1+K)) % MOD;
    tmp = (tmp * (N+2-K)) % MOD;
    tmp = tmp * modinv(2, MOD) % MOD;
    ans = (ans + tmp) % MOD;
    //
    ans = (ans + N + 2 - K) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define Graph vector<vector<int>>
#define MOD 1000000007 
typedef pair<int, int> PII;
typedef long long ll;

int main(){
  ll a,b,X;
  cin >> a >> b >> X;

  ll a_no = a / X;
  ll b_no = b / X;

  ll ans = 0;
  if((a % X) != 0){
    ans = (b_no - a_no);
  }else{
    ans = (b_no - a_no) + 1;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[101];
int main(){
  int  n;
  cin>>n;
  for(int i=0;i<n;i++){
	cin>>a[i];
   }
   ll ans=1e9;
	 for(int i=1;i<=100;i++){
		ll tmp=0;
		 for(int j=0;j<n;j++){
         tmp+=(a[j]-i)*(a[j]-i);
       }
			 ans=min(tmp,ans);
		}
		cout<<ans<<'\n';
}
	

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

using std::cin;
using std::cout;



int main(int argc, char* argv[])
{
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  int res = 0;
  for (int i = 0; i < n; ++i)
  {
    int ai; cin >> ai;
    res |= (ai & 1);
  }

  cout << (res ? "first\n" : "second\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <array>

using namespace std;


int main(){
	int r,n;

	cout.precision(4);
	cout.setf(ios::fixed);

	while(cin >> r >> n ,r){
		array<pair<int,int>,41> height;
		for(int i=0;i<41;i++) height[i] = make_pair(0,0);
		int xl,xr,h;
		for(int i=0;i<n;i++){
			cin >> xl >> xr >> h;
			for(int i=xl;i<xr;i++){
				height[i+20].second = max(height[i+20].second,h);
				height[i+21].first = max(height[i+21].first,h);
			}
		}
		double ret = 20.0;
		for(int i=-r+1;i<=r-1;i++){
			ret = min(ret,(double)min(height[20+i].first,height[20+i].second) - sqrt(pow(r,2) - pow(i,2)) + r);
			//cout << i << ":" << (double)min(height[20+i].first,height[20+i].second) - sqrt(pow(r,2) - pow(i,2)) + r << endl;
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll h,w,x,y;
    cin>>h>>w>>x>>y;
    h*=w;
    x+=y;
    if((h&1) && (x&1)){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	if(k>=n){
	cout<<v[n-1]-v[0];
	}
	else{
	vector<int> ans(n);
	ans[0]=0;
	for(int i=1;i<=k;i++){
		ans[i]=abs(v[i]-v[0]);
	}
	for(int i=k+1;i<n;i++){
		ans[i]=INT_MAX;
		for(int j=1;j<=k;j++){
			int y=abs(v[i]-v[i-j])+ans[i-j];
			ans[i]=min(ans[i],y);
		}
	}
	cout<<ans[n-1];
	}
}

Measured memory_bytes: 4024
using System;

namespace ITP1_3_C
{
    class Program
    {
        static void Main()
        {
            for (; ; )
            {
                string[] str = Console.ReadLine().Split(' ');
                int x = int.Parse(str[0]);
                int y = int.Parse(str[1]);

                if (x == 0 && y == 0) break;

                else if (x > y) Console.WriteLine(y + " " + x);

                else Console.WriteLine(x + " " + y);
            }
        }
    }
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double 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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const int nmax = 40, abmax = 10, inf = 1e6;

int n, ma, mb;
int a[nmax], b[nmax], c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

void solve() {
   for (int i = 0; i < n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            if (dp[i][ca][cb] == inf) continue;
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
            chmin(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
         }
      }
   }

   int ans = inf;
   for (int ca = 1; ca <= nmax*abmax; ca++) {
      for (int cb = 1; cb <= nmax*abmax; cb++) {
         if (ca*mb==cb*ma) {
            chmin(ans, dp[n][ca][cb]);
         }
      }
   }

   if (ans == inf) ans = -1;
   cout << ans << endl;
}

int main() {
   cin >> n >> ma >> mb;
   rep (i, n) cin >> a[i] >> b[i] >> c[i];

   for (int i = 0; i <= n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            dp[i][ca][cb] = inf;
         }
      }
   }
   dp[0][0][0] = 0;

   solve();

   return 0;
}

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

int main() {
  int a, b, x;
  cin>>a>>b>>x;
  if (x <= 1.0 * a * a * b / 2.0) {
    double c = sqrt(1.0*b*b + 4.0 * x * x/ (a*a*b*b));
    printf("%.9lf\n", 90 - acos(1.0*b/c) / M_PI * 180);
  } else {
    double c = sqrt(pow(2*b - 2.0*x/(a*a), 2) + a * a);
    printf("%.9lf\n", 90 - asin(1.0*a/c) / M_PI * 180);
  }
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC, key=lambda x:x[1], reverse=True)
D = [0] * N
idx = 0
for b,c in BC:
    for i in range(b):
        D[idx] = c
        idx += 1
        if idx >= N:
            break
    if idx >= N:
        break
# print(D)


# print(D)
# print(sorted(A))
# print(len(D), len(A))
for i in range(N):
    if A[i] < D[i]:
        A[i] = D[i]
    else:
        break
print(sum(A))

Measured memory_bytes: 83736
using System;
using System.Web;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static System.Math;
 

class P
{
    static void Main()
    {
        int[] nab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine($"{Min(nab[1], nab[2])} {Max(0, (nab[1] + nab[2]) - nab[0])}");
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include <iomanip>

using namespace std;

typedef long long ll;

double dp[3010][3010], p[3010];

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

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) {
            dp[i + 1][j] = dp[i][j] * (1 - p[i]);
            if (j - 1 >= 0) dp[i + 1][j] += dp[i][j - 1] * p[i];
        }
    }

    double ans = 0.0;
    for (int j = (n + 1) / 2; j <= n; ++j) {
        ans += dp[n][j];
    }

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70784
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,c[105][105];
ll b[1000005];
double a[1000005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&a[i]);
		b[i]=a[i]*1e9+0.5;
	}
	for(int i=1;i<=n;i++)
	{
		int ct0=0,ct1=0;
		while(b[i]%2==0) b[i]/=2,ct0++;
		while(b[i]%5==0) b[i]/=5,ct1++;
		c[min(ct0,18)][min(ct1,18)]++;
	//	printf("i=%d,ct=%d,%d\n",i,ct0,ct1);
	}
	ll ans=0;
	for(int i=0;i<=18;i++)
		for(int j=0;j<=18;j++)
			for(int k=0;k<=18;k++)
				for(int l=0;l<=18;l++)
				{
					if(i+k>=18&&j+l>=18)
					{
						int u=c[i][j],v=c[k][l],las=ans;
						if(i==k&&j==l) ans+=(1ll*u*(u-1));
						else ans+=1ll*u*v;
					//	if(las!=ans) printf("i=%d,j=%d,k=%d,l=%d,u=%d,v=%d\n",i,j,k,l,u,v);
					}
				}
	ans/=2;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4872
import java.util.*;

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

        int[] edgeCount = new int[5];
        for (int i = 0; i < 3; i++) {
            String[] ab = scanner.nextLine().split(" ", 2);
            int a = Integer.parseInt(ab[0]);
            int b = Integer.parseInt(ab[1]);
            edgeCount[a]++;
            edgeCount[b]++;
        }

        boolean all2 = true;
        for (int i = 1; i <= 4; i++) {
            if (edgeCount[i] == 0 || edgeCount[i] >= 3) {
                all2 = false;
                break;
            }
        }
        if (all2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


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

template <typename T>
class node {
public:
	node<T> *l, *r;
	T val, add;
	node(T val_ = 0, node<T>* l_ = nullptr, node<T>* r_ = nullptr)
		: l(l_), r(r_), val(val_), add(0) {}
};

template <typename T>
class RARS {
	const ll n;
	node<T> *root;
	ll size(ll n) {
		ll res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	T sub(ll l, ll r, node<T>* n, ll lb, ll ub) {
		if (!n || ub <= l || r <= lb) return 0;
		if (l <= lb && ub <= r) return n->val + n->add * (ub - lb);
		return sub(l, r, n->l, lb, (lb + ub) / 2) + sub(l, r, n->r, (lb + ub) / 2, ub) + n->add * (min(r, ub) - max(l, lb));
	}
	node<T>* suc(ll l, ll r, node<T>* n, ll lb, ll ub, T val) {
		if (ub <= l || r <= lb) return n;
		if (!n) n = new node<T>;
		if (l <= lb && ub <= r) {
			n->add += val;
			return n;
		}
		n->val += val * (min(r, ub) - max(l, lb));
		n->l = suc(l, r, n->l, lb, (lb + ub) / 2, val);
		n->r = suc(l, r, n->r, (lb + ub) / 2, ub, val);
		return n;
	}
public:
	RARS(ll n_) : n(size(n_)), root(nullptr) {}
	void add(ll l, ll r, T val) {
		root = suc(l, r + 1, root, 0, n, val);
	}
	T getSum(ll l, ll r) {
		return sub(l, r + 1, root, 0, n);
	}
};

template <typename T>
class node2 {
public:
	RARS<T> val, add;
	node2<T> *l, *r;
	node2(ll size) : val(size), add(size), l(nullptr), r(nullptr) {}
};

template <typename T>
class RARS2 {
	const ll h, w;
	node2<T> *root;
	ll size(ll n) {
		ll res = 1;
		while (res < n) res <<= 1ll;
		return res;
	}
	T sub(ll li, ll lj, ll ri, ll rj, node2<T>* n, ll lb, ll ub) {
		if (!n || ub <= li || ri <= lb) return 0;
		if (li <= lb && ub <= ri) return n->val.getSum(lj, rj) + n->add.getSum(lj, rj) * (ub - lb);
		return sub(li, lj, ri, rj, n->l, lb, (lb + ub) / 2) + sub(li, lj, ri, rj, n->r, (lb + ub) / 2, ub) + n->add.getSum(lj, rj) * (min(ri, ub) - max(li, lb));
	}
	node2<T>* suc(ll li, ll lj, ll ri, ll rj, node2<T>* n, ll lb, ll ub, T val) {
		if (ub <= li || ri <= lb) return n;
		if (!n) n = new node2<T>(w);
		if (li <= lb && ub <= ri) {
			n->add.add(lj, rj, val);
			return n;
		}
		n->val.add(lj, rj, val * (min(ri, ub) - max(li, lb)));
		n->l = suc(li, lj, ri, rj, n->l, lb, (lb + ub) / 2, val);
		n->r = suc(li, lj, ri, rj, n->r, (lb + ub) / 2, ub, val);
		return n;
	}
public:
	RARS2(ll h_, ll w_) : h(size(h_)), w(w_), root(nullptr) {}
	void add(ll li, ll lj, ll ri, ll rj, T val) {
		root = suc(li, lj, ri + 1, rj, root, 0, h, val);
	}
	T getSum(ll li, ll lj, ll ri, ll rj) {
		return sub(li, lj, ri + 1, rj, root, 0, h);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	RARS2<ll> lst(1, n);
	for (int i = 0, type, s, t, x; i < q; i++) {
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", lst.getSum(0, s, 0, t));
		}
		else {
			cin >> x;
			lst.add(0, s, 0, t, x);
		}
	}
	return 0;
}

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

qd = {}
for _ in range(m):
  a, b = map(int, input().split())
  if a not in qd:
    qd[a] = 1
  else:
    qd[a] += 1
  if b not in qd:
    qd[b] = 1
  else:
    qd[b] += 1

if all(v % 2 == 0 for v in qd.values()):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 9064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strNum = "";
		ArrayList<String> numList = new ArrayList<String>();
		while (true) {
			strNum = br.readLine();
			if ("0 0".equals(strNum)) {
				break;
			}
			String[] numArrays = strNum.split(" ");
			if (Integer.parseInt(numArrays[0]) > Integer.parseInt(numArrays[1])) {
				numList.add(numArrays[1] + " " + numArrays[0]);
			} else {
				numList.add(numArrays[0] + " " + numArrays[1]);
			}
		}
		for (int i = 0; i < numList.size(); i++) {
			System.out.println(numList.get(i));
		}
	}

}

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

using namespace std;

int main() {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    if (t[i] == 'r') a[i] = p;
    if (t[i] == 's') a[i] = r;
    if (t[i] == 'p') a[i] = s;
  }
  int total = 0;
  for (int i = 0; i < n; i++) {
    if (i - k >= 0) {
      if (t[i] == t[i - k]) {
        if (t[i] == 'r') total += p;
        if (t[i] == 's') total += r;
        if (t[i] == 'p') total += s;
        t[i] = 'z';
      }
    }
  }
  int total2 = 0;
  for (int i = 0; i < n; i++) {
    total2 += a[i];
  }
  cout << total2 - total << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    int dp[500][500];
    int x;
    int y;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            x = min(i, j);
            y = min(n - i - 1, n - j - 1);
            dp[j][i] = min(x,y);
        }
        
    }

    int c[500][500];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            c[j][i] = 1;
        }
    }
    int ans;
    ans = 0;
    struct aa{
        int x,y;
    };

    queue<aa> que;
    aa yx;
    int score;
    int my[4] = {0, 1, 0, -1};
    int mx[4] = {1, 0, -1, 0};
    int ym;
    int xm;
    int pi;
    for (int i = 0; i < n * n; i++)
    {
        cin >> pi;
        pi--;
        y = pi  / n;
        x = pi % n;
        ans += dp[y][x];
        c[y][x] = 0;
        yx.y = y;
        yx.x = x;
        que.push(yx);
        while (que.size())
        {
            yx = que.front();
            y = yx.y;
            x = yx.x;
            que.pop();
            score = dp[y][x] + c[y][x];
            for (int i = 0; i < 4; i++)
            {
                ym = my[i] + y;
                xm = mx[i] + x;
                if(0 < ym &&ym < n - 1 && 0 < xm &&xm < n - 1)
                {
                    if(dp[ym][xm] > score)
                    {
                        dp[ym][xm] = score;
                        yx.y = ym;
                        yx.x = xm;
                        que.push(yx);
                    }
                }
            }
            
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 5584
import itertools
N = int(input())
L = list(map(int,input().split()))
count = 0
for l in itertools.combinations(L,3):
    l = sorted(l)
    if l[1] == l[2] or l[0] == l[1]:
        continue
    if l[2] < l[1]+l[0]:
        count+=1
print(count)

Measured memory_bytes: 9188