akhauriyash/Code-Regression huggingface dataset:
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
Z=x[-1]+1
if Z<=y[0] and X<Z<=Y:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    p = [int(x) for x in input().split()]
    if p == sorted(p):
        print('YES')
        return
    for i in range(n):
        for j in range(i + 1, n):
            q = p[:]
            q[i], q[j] = q[j], q[i]
            if q == sorted(q):
                print('YES')
                return
    print('NO')


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 30700
use proconio::{input, fastout};
use std::{io::Read, collections::HashSet};

#[fastout]
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let mut set: HashSet<usize> = HashSet::new();
    for i in 0..n {
        let mut a = it.next().unwrap().parse::<usize>().unwrap();
        if set.contains(&a) {
            set.remove(&mut a);
        } else {
            set.insert(a);
        }
    }
    println!("{}", set.len())
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int r,g,b;cin>>r>>g>>b;
    if ((g*10+b)%4==0)cout<<"YES";
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
using namespace std;
vector<tuple<int,int,int,int>> vec;

int calAns(vector<int>& A){
    int ans = 0;
    for(auto it : vec){
        int a,b,c,d;
        tie(a,b,c,d) = it;
        if(A[b-1]-A[a-1] == c)
            ans += d;
    }
    return ans;
}

int sol(vector<int>& A, int cur, int end, int m){
    if(cur == end){
        return calAns(A);
    }
    int res = 0;
    int s = A.size() ? A[cur-1] : 1;

    for(int i = s; i <= m ; ++i){
        A.push_back(i);
        res = max(res,sol(A,cur+1, end,m));
        A.pop_back();
    }
    return res;
}

int main(){
    int n,m,q;
    cin >> n >> m >> q;
    for(int i = 0,a,b,c,d; i < q ; ++i){
        cin >> a >> b >> c >> d;
        vec.emplace_back(a,b,c,d);
    }
    vector<int> A;
    cout << sol(A,0,n,m);

    return 0;
}

Measured memory_bytes: 3192
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    cnt = 0
    for i in range(N):
        if a[a[i]-1] == i+1:
            cnt += 1

    print(cnt//2)

if __name__ == '__main__':
    main()


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

struct unionfind{
    vector<int> parent;
    vector<int> rank;
    vector<int> size;

    unionfind (int N) {
        parent = vector<int>(N);
        iota(parent.begin(), parent.end(), 0);
        rank = vector<int>(N, 0);
        size = vector<int>(N, 1);
    }
    int root(int x) {
        if (parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        }
        else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) rank[y] += 1;
        }
    }
};

int N, M;
int main() {
    cin >> N >> M;
    unionfind uf(N);
    vector<vector<int>> lang(M, vector<int>());
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int L;
            cin >> L;
            lang[L-1].push_back(i);
        }
    }
    for (int i = 0; i < M; i++) {
        if (lang[i].size() <= 1) continue;
        int p = lang[i][0];
        for (int j = 1; j < (int)lang[i].size(); j++) {
            if (!uf.same(p, lang[i][j])) uf.unite(p, lang[i][j]);
        }
    }
    if (uf.size[uf.root(0)] == N) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}


Measured memory_bytes: 4608
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
T, X, Y = [], [], []
pos_x, pos_y, now_t = 0, 0, 0
for i in range(N):
    t, x, y = zz()
    T.append(t)
    X.append(x)
    Y.append(y)
ok = 1
for t, x, y in zip(T, X, Y):
    if (abs(x - pos_x) + abs(y - pos_y) > (t - now_t)):
        ok = 0
        break
    if (((abs(x - pos_x) + abs(y - pos_y)) % 2) != ((t - now_t) % 2)):
        ok = 0
        break
    pos_x, pos_y, now_t = x, y, t
if(ok == 1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 50644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}

void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    go();
    return 0;
}
/****************ackun*********************/
void go(){
    string s;
    R(s);
    int len=s.length();
    int ans=0;
    int now=0;
    rep(i,0,len-1){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            now++;
        }else{
            now=0;
        }
        ans=max(ans,now);
    }
    W(ans);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			HashSet<Integer> S = new HashSet<Integer>();
			int q = sc.nextInt();
			for(int i = 0; i < q; i++) {
				int cmd = sc.nextInt();
				int x = sc.nextInt();
				if(cmd == 0) {
					S.add(x);
					System.out.println(S.size());
				}
				else {
					System.out.println(S.contains(x) ? "1" : "0");
				}
			}
		}
	}
}


Measured memory_bytes: 148044
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    UL SX[1401][1401] = {};
    UL SY[1401][1401] = {};

    void Solve() {
        UL H, W; scanf("%d%d", &H, &W);
        rep(y, H) rep(x, W) {
            UL c; scanf("%d", &c);
            if (c == 1) continue;
            SX[x + 1][y + 1] = SX[x][y + 1] + 1;
            SY[x + 1][y + 1] = SY[x + 1][y] + 1;
        }
        rep(y, H + 1) rep(x, W + 1) SX[x][y] = min(SX[x][y], SY[x][y]);
        UL ans = 0;
        rep(y, H) rep(x, W) {
            SX[x + 1][y + 1] = min(SX[x + 1][y + 1], SX[x][y] + 1);
            ans = max(ans, SX[x + 1][y + 1]);
        }
        printf("%d\n", ans * ans);
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



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


tuple<int, int, int, int> mt(int *cc)
{
    return make_tuple(cc[0], cc[1], cc[2], cc[3]);
}

void shift(int *cc, int k)
{
    int hj[4];
    for (int i = 0; i < 4; i++) hj[i] = cc[(i+k)%4];
    for (int i = 0; i < 4; i++) cc[i] = hj[i];
}

void normalize(int *cc)
{
    int minidx;
    ll maxhsh = -1;
    for (int i = 0; i < 4; i++)
    {
        ll hsh = (ll)cc[0] + (ll)cc[1]*(1e3) + (ll)cc[2]*(1e6) + (ll)cc[3]*(1e9);
        if (hsh > maxhsh)
        {
            maxhsh = hsh;
            minidx = i;
        }
        shift(cc, 1);
    }

    shift(cc, minidx);
}

const int MAXN = 500;
int c[MAXN][4];
map <tuple<int, int, int, int> , ll > m;
map <tuple<int, int, int, int> , ll > mult;

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 4; j++)
            cin >> c[i][j];

        normalize(c[i]);

        if (c[i][0] == c[i][1] && c[i][0] == c[i][2] && c[i][0] == c[i][3]) mult[mt(c[i])] = 4;
        else if (c[i][0] == c[i][2] && c[i][1] == c[i][3]) mult[mt(c[i])] = 2;
        else mult[mt(c[i])] = 1;

        m[mt(c[i])]++;
    }

    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            m[mt(c[i])]--;
            m[mt(c[j])]--;

            for (int k = 0; k < 4; k++)
            {
                ll res = 1;
                int tile[4][4];
                for (int l = 0; l < 4; l++)
                {
                    //cout << i << " " << j << " " << k << " " << l << " " << m[make_tuple(6, 4, 5, 7)] << endl;
                    tile[l][0] = c[i][l];
                    tile[l][1] = c[j][(-l+7)%4];
                    tile[l][2] = c[j][(-l+6)%4];
                    tile[l][3] = c[i][(l+1)%4];
                    normalize(tile[l]);

                    res *= m[mt(tile[l])]* mult[mt(tile[l])];
                    m[mt(tile[l])]--;
                }
                for (int l = 0; l < 4; l++)
                    m[mt(tile[l])]++;

                ans += res;
                shift(c[j], 1);
            }

            m[mt(c[i])]++;
            m[mt(c[j])]++;
        }
    }
    cout << ans/3;
}


Measured memory_bytes: 159872
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    int n; scanf("%d", &n);
    map <ll, int> mp;
    for (int i = 0; i < n; i++) {
        ll x; scanf("%lld", &x);
        mp[x]++;
    }

    vector <ll> vec;
    for (auto pp : mp) {
        int cnt = pp.second;
        cnt /= 2;
        while (cnt > 0) {
            vec.push_back(pp.first);
            cnt--;
        }
    }

    if (vec.size() < 2) {
        puts("0");
        return 0;
    }

    int sz = vec.size();
    printf("%lld\n", vec[sz - 1] * vec[sz - 2]);
}


Measured memory_bytes: 9980
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
using namespace std;

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

  int x = v[1];
  bool flag = true;
  for (int i = 2; i <= n; i++) {
    if (v[i] != x) {
      flag = false;
    }
  }
  if (flag) {
    cout << n/2 << endl;
    return 0;
  }

  map<int, int> e, o;
  for (int i = 1; i <= n; i++) {
    if (i%2 == 0) {
      e[v[i]]++;
    }
    else {
      o[v[i]]++;
    }
  }

  vector<tuple<int, int> > a, b;
  for (auto i = e.begin(); i != e.end(); i++) {
    int nele = i->first, cnt = i->second;
    a.push_back(make_tuple(cnt, nele));
  }
  for (auto i = o.begin(); i != o.end(); i++) {
    int nele = i->first, cnt = i->second;
    b.push_back(make_tuple(cnt, nele));
  }
  a.push_back(make_tuple(0, 100010));
  b.push_back(make_tuple(0, 100010));
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  int ans;
  if (get<1>(a[0]) != get<1>(b[0])) {
    ans = n - get<0>(a[0]) - get<0>(b[0]);
  }
  else {
    ans = min(n - get<0>(a[0]) - get<0>(b[1]), n - get<0>(a[1]) - get<0>(b[0]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6520
///
// File:  2600.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 24 03:06:16 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  int32_t N, W, H;
  cin >> N >> W >> H;

  vector<int32_t> h(W + 1);
  vector<int32_t> v(H + 1);
  for (int32_t i = 0; i < N; i++) {
    int32_t x, y, w;
    cin >> x >> y >> w;
    h[max(0, x - w)] += 1;
    h[min(x + w, W)] -= 1;
    v[max(0, y - w)] += 1;
    v[min(y + w, H)] -= 1;
  }

  bool coverage = true;
  for (int32_t i = 0; i < W; i++) {
    if (!(h[i] > 0)) {
      coverage = false;
    }
    h[i + 1] += h[i];
  }

  if (coverage) {
    cout << "Yes" << endl;
    return 0;
  }

  coverage = true;
  for (int32_t i = 0; i < H; i++) {
    if (!(v[i] > 0)) {
      coverage = false;
    }
    v[i + 1] += v[i];
  }

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

  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==25)
	cout<<"Christmas";
	if(n==24)
	cout<<"Christmas Eve";
	if(n==23)
	cout<<"Christmas Eve Eve";
	if(n==22)
	cout<<"Christmas Eve Eve Eve";
} 

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n = sc.read();
    let mut a: Vec<u32> = sc.vec(n);
    let mut flag = true;
    let mut cnt = 0;
    while flag {
        flag = false;
        for j in 1..n {
            if a[j] < a[j-1] {
                a.swap(j, j-1);
                cnt += 1;
                flag = true;
            }
        }
    }
    println!("{}", a.iter().join(" "));
    println!("{}", cnt);
}



Measured memory_bytes: 9076
// C++ program to find the longest
// path in the DAG

#include <bits/stdc++.h>
using namespace std;

// Function to traverse the DAG
// and apply Dynamic Programming
// to find the longest path
void dfs(int node, vector<int> adj[], int dp[], bool vis[])
{
	// Mark as visited
	vis[node] = true;

	// Traverse for all its children
	for (int i = 0; i < adj[node].size(); i++) {

		// If not visited
		if (!vis[adj[node][i]])
			dfs(adj[node][i], adj, dp, vis);

		// Store the max of the paths
		dp[node] = max(dp[node], 1 + dp[adj[node][i]]);
	}
}

// Function to add an edge
void addEdge(vector<int> adj[], int u, int v)
{
	adj[u].push_back(v);
}

// Function that returns the longest path
int findLongestPath(vector<int> adj[], int n)
{
	// Dp array
	int dp[n + 1];
	memset(dp, 0, sizeof dp);

	// Visited array to know if the node
	// has been visited previously or not
	bool vis[n + 1];
	memset(vis, false, sizeof vis);

	// Call DFS for every unvisited vertex
	for (int i = 1; i <= n; i++) {
		if (!vis[i])
			dfs(i, adj, dp, vis);
	}

	int ans = 0;

	// Traverse and find the maximum of all dp[i]
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
	}
	return ans;
}

// Driver Code
int main()
{
	//int n = 5;
  int n,m;
  cin>>n>>m;
	vector<int> adj[n + 1];
  
	for(int i=0;i<m;i++)
  {
    int u,v;
    cin>>u>>v;
    addEdge(adj, u, v);
  }

	cout << findLongestPath(adj, n);
	return 0;
}


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

bool factorize(ll n){
  for(ll i = 2; i <= sqrt(n) ; ++i){
    if (n%i == 0) return true;
  }
  return false;
}

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

  while (factorize(x)) {
    x += 1;
  }

  cout << x << endl;

  return 0;
}


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

constexpr int INF = 1e9;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> C(M), x(N);
        for(int i=0; i<M; ++i) {
            cin >> C[i];
        }
        for(int i=0; i<N; ++i) {
            cin >> x[i];
        }
        vector<vector<int>> dp(N+1, vector<int>(256, INF));
        dp[0][128] = 0;
        for(int i=0; i<N; ++i) {
            for(int j=0; j<256; ++j) {
                for(int k=0; k<M; ++k) {
                    int next = min(255, max(0, j+C[k]));
                    dp[i+1][next] = min(dp[i+1][next], dp[i][j] + (x[i] - next) * (x[i] - next));
                }
            }
        }
        cout << *min_element(dp[N].begin(), dp[N].end()) << endl;
    }
}


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

using namespace std;

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

int main() {
  int N;
  cin >> N;
  int g = 0;
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    if (i == 0) g = A;
    g = gcd(g, A);
  }
  int res = 0;
  while (g % 2 == 0) {
    res++;
    g /= 2;
  }
  cout << res << endl;
}

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

struct UnionFind {
    vector<int> p;
    UnionFind(ll n) : p(n, -1) {};
    bool unite(ll u, ll v) {
        if ((u = root(u)) == (v = root(v))) return false;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v]; p[v] = u;
        return true;
    }
    bool find(ll u, ll v) { return root(u) == root(v); }
    int root(ll u) { return p[u] < 0 ? u : p[u] = root(p[u]); }
    int size(ll u) { return -p[root(u)]; }
};

struct Edge {
    int from, to, cost;
    bool b;
    Edge(int a, int b, int c, bool d) : from(a), to(b), cost(c), b(d) {};
    bool operator<(Edge& e) {
        return cost < e.cost;
    }
};

int main() {
    int w, h; cin >> w >> h;
    vector<Edge> es;
    rep(i, w) {
        int p; cin >> p;
        es.emplace_back(i, i + 1, p, 0);
    }
    rep(i, h) {
        int q; cin >> q;
        es.emplace_back(i, i + 1, q, 1);
    }
    sort(es.begin(), es.end());

    UnionFind uf1(w + 1), uf2(h + 1);
    ll ans = 0;
    int X = w + 1, Y = h + 1;
    for (auto&& e : es) {
        if (e.b == 0) {
            if (uf1.unite(e.from, e.to)) {
                ans += 1LL * e.cost * Y;
                X--;
            }
        }
        else {
            if (uf2.unite(e.from, e.to)) {
                ans += 1LL * e.cost * X;
                Y--;
            }
        }
    }

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

Measured memory_bytes: 6384
#include<stdio.h>
int main()
{
    int X, A;
    scanf("%d %d", &X, &A);
    if (0<=X,A<=9)
    {
        if(X<A)
        {
            printf("0");
        }
        else
        {
            printf("10");
        }
    }
    else
    {
        printf("Wrong input");
    }
    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include<set>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    set<int>s;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        int a;
        for(int j=0;j<d;j++){
            cin>>a;
            s.insert(a);
        }
    }
    cout<<n-s.size();
}


Measured memory_bytes: 3152
S = input()
T = input()
a = len(S)
b = len(T)
Max = 0
for i in range(a - b + 1):
  count = 0
  for j in range(b):
    if S[j + i] == T[j]:
      count += 1
  if count > Max:
    Max = count
    
print(b - Max)

Measured memory_bytes: 9120
import bisect
import sys

sys.setrecursionlimit(1000000)

s=input()
t=input()
dic={}
for v in s:
    dic[v]=True

for u in t:
    if not u in dic:
        print(-1)
        exit()

nex={}
for i, v in enumerate(s+s):
    if not v in nex:
        nex[v]=[i]
    else:
        nex[v].append(i)
#print(s)
#print(t)
#print(nex)
sl=len(s)
tl=len(t)
def func(st, tn, su):
    if tn == tl:
        return su
    #print(st, tn, su, t[tn])
    ind=bisect.bisect_left(nex[t[tn]] ,st+1)
    nm=(nex[t[tn]][ind]-st)
    return func((st+nm)%sl, tn+1, su+nm)


res=func(-1, 0, 0)

print(res)

Measured memory_bytes: 107824
n = int(input())
cnt = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]

for _ in range(n):
  b, f, r, v = map(int, input().split())
  cnt[b-1][f-1][r-1] += v

for i in range(4):
  for j in range(3):
    print(' '+' '.join(map(str, cnt[i][j])))

  if i != 3:
    print('#'*20)

Measured memory_bytes: 7764
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readInt64()
	var ans int64
	for i := int64(1); i*i < n; i++ {
		if n%i != 0 {
			continue
		}
		m := n/i - 1
		if n/m > m {
			break
		}
		ans += m
	}
	println(ans)

}

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


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i = 0;i < n+1;++i) cin >> a[i];
    bool f = true;
    ll p = 1;
    for (int i = 0;i < n+1;++i) {
        p -= a[i];
        if (p < 0) {
            cout << -1 << endl;
            return 0;
        }
        p *= 2;
        p = min(p,1000000000LL);
    }
    ll sum = -1,ans = 0;
    for (int i = 0;i < n+1;++i) sum += a[i];
    p = 1;
    for (int i = 0;i < n+1;++i) {
        ans += p;
        p -= a[i];
        ll x = min(p,sum);
        p += x;
        sum -= x;
    }
    cout << ans << endl;
}

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

int main(){

  string A,B,C;
  cin >> A >> B >> C;

  if (A.at(A.size()-1)==B.at(0) && B.at(B.size()-1)==C.at(0)){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
int n,k,q,ans;
int a[2005];
vector<int>o;
bool x=true;
int main(void){
    cin>>n>>k>>q;
    for(int i=0;i<n;i++){
        cin>>a[i];
        o.push_back(a[i]);
    }
    sort(o.begin(),o.end());
    ans=o[q-1]-o[0];
    for(int i=0;i<n&&x;i++){
        vector<int>y,z;
        for(int j=0;j<n;j++){
            if(a[j]<=o[i]){
                if(z.size()>=k){
                    sort(z.begin(),z.end());
                    for(int l=0;l<=z.size()-k;l++)y.push_back(z[l]);
                }
                z.clear();
            }else z.push_back(a[j]);
        }
        if(z.size()>=k){
                    sort(z.begin(),z.end());
                    for(int l=0;l<=z.size()-k;l++)y.push_back(z[l]);
                }
                z.clear();
        if(y.size()<q)x=false;
        else{
            sort(y.begin(),y.end());
            ans=min(ans,y[q-1]-y[0]);
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#include <algorithm>
#include <string>
#include <vector>
#define ll long long
struct s
{
    int timu;
    int time;
};
int main()
{

    string s1,s2,s3,s4,s5;
    cin>>s1;
    s2="dream";
    s3="dreamer";
    s4="erase";
    s5="eraser";
    int flag=1;
    int p1,p2,p3,p4;
    int f1,f2,f3,f4;
    ll l;
    while(1)
    {
        flag=0;
        f1=0;f2=0;f3=0;f4=0;
        l=s1.length();
        p1=l-5;
        for(int i=0;i<5;i++)
        {
            if(s1[p1+i]!=s2[i])
            {
                f1=1;
            }
        }
        if(f1==0)
        {
            s1.erase(p1,5);flag=1;
        }

        l=s1.length();
        p2=l-7;
        for(int i=0;i<7;i++)
        {
            if(s1[p2+i]!=s3[i])
            {
                f2=1;
            }
        }
        if(f2==0)
        {
            s1.erase(p2,7);flag=1;
        }

        l=s1.length();
        p3=l-5;
        for(int i=0;i<5;i++)
        {
            if(s1[p3+i]!=s4[i])
            {
                f3=1;
            }
        }
        if(f3==0)
        {
            s1.erase(p3,5);
            flag=1;
        }

        l=s1.length();
        p4=l-6;
        for(int i=0;i<6;i++)
        {
            if(s1[p4+i]!=s5[i])
            {
                f4=1;
            }
        }
        if(f4==0)
        {
            s1.erase(p4,6);flag=1;
        }

        if(flag==0&&s1.size()!=0)
        {
            cout<<"NO"<<endl;
            return 0;
        }
        if(s1.size()==0)
        {
            cout<<"YES"<<endl;
            return 0;
        }

    }

}


Measured memory_bytes: 512
n=int(input())
#a=[0,a1,a2,a3,...,an]
a=[0]
b=[0]
c=[0]
#０日め　0,0,0
#1日目　a1,b1,c1
#2日目　a2=b1+a2 or c1+a2
dp=[[0 for i in range(3)] for j in range(n+1)]
for i in range(n):
    x,y,z=map(int,input().split())
    a.append(x)
    b.append(y)
    c.append(z)
for i in range(1,n+1):
    dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i])
    dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i])
    dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i])
print(max(dp[n]))

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

using namespace std;

int N;

vector<bool> a_ary;
vector<bool> b_ary;


int main()
{
	cin >> N;
	a_ary = vector<bool>(N+1);
	b_ary = vector<bool>(N+1);
	unsigned int count = 0;

	for (int i=1; i < N+1; i++) {
		int a;
		cin >> a;
		a_ary.at(i) = a == 1;
	}

	for (int i = N; i > 0; i--) {

		int lim = N / i;
		bool sum = a_ary.at(i);
		for (int j = 2; j <= lim; j++) {
			sum = sum ^ b_ary.at(i*j);
		}

		b_ary.at(i) = sum;

		if (b_ary.at(i)) {
			count++;

		}
	}

	cout << count << endl;
	for (int i = 1; i < N+1; i++) {
		if (b_ary.at(i)) {
			cout << i << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 1152
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int mod = 998244353;

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

void sub(int &a, int b)
{
	a -= b;
	if (a < 0)
		a += mod;
}

int mult(int a, int b)
{
	return ll(a) * b % mod;
}

void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	string s;
	int k;

	while (cin >> s >> k)
//	s = string(150, '0') + string(150, '1');
//	k = int(1e9);

	{
		vector<int> parts;

		{
			int cur_part = 0;
			for (int i = 0; i < int(s.size()); i++)
			{
				if (s[i] == '0')
				{
					parts.push_back(cur_part);
					cur_part = 0;
				}
				else
					cur_part++;
			}
			parts.push_back(cur_part);
		}

		vector<int> sums(parts.size() + 1);
		partial_sum(parts.begin(), parts.end(), sums.begin() + 1);

		vector<vector<vector<int>>> dp(int(parts.size()) + 1, vector<vector<int>>(sums.back() + 1,
		                                                                          vector<int>(sums.back() + 1)));
		dp[0][0][0] = 1;

		for (int i = 0; i + 1 < int(dp.size()); i++)
			for (int j = sums[i]; j < int(dp[i].size()); j++)
				for (int ops = 0; ops < int(dp[i][j].size()); ops++)
				{
					const int cur = dp[i][j][ops];
					const int debt = j - sums[i];

					if (cur && debt <= sums.back() - sums[i])
					{
						assert(debt >= 0);

						for (int pay = 1; pay <= min(debt, parts[i]) && ops + pay <= int(sums.back()); pay++)
						{
							if (j + parts[i] - pay <= int(sums.back()))
								add(dp[i + 1][j + parts[i] - pay][ops + pay], cur);
						}

						for (int borrow = 0; j + borrow + parts[i] <= sums.back(); borrow++)
						{
							assert(j + borrow + parts[i] <= sums.back());
							add(dp[i + 1][j + borrow + parts[i]][ops], cur);
						}
					}
				}

		int ans = 0;
		for (int i = 0; i < min(k + 1, int(dp.back()[sums.back()].size())); i++)
			add(ans, dp.back()[sums.back()][i]);
		cout << ans << endl;
	}
}

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

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");
	solve(fin);

	cout << "clock: " << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}

Measured memory_bytes: 19928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int h,w;cin>>h>>w;
  int a,b;cin>>a>>b;
  rep(i,b){
    rep(i,a)cout<<0;
    rep(i,w-a)cout<<1;
    cout<<endl;
  }
  rep(i,h-b){
    rep(i,a)cout<<1;
    rep(i,w-a)cout<<0;
    cout<<endl;
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin>>a>>b;
  string ei = to_string(a);
  string bi = to_string(b);
  string c = ei + bi;
  int s = stoi(c);
  bool end = true;
  for(int i=0; i<1000; i++){
    if(i*i==s){
      cout<<"Yes"<<endl;
      end = false;
      break;
    }
  }
  if(end){
    cout<<"No"<<endl;
  }
}


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

int n; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	for(int i = 1; i <= n; i++) if(1ll * i * (i + 1) / 2 >= n) { printf("%d\n", i); return 0; }
	return 0; 
}


Measured memory_bytes: 3136
n,m,r = map(int,input().split())
books = [[int(i) for i in input().split()] for _ in range(n)]
t = []

for x in range(2**n):
    p = [0]*(m+1)
    for y in range(n):
        if (x>>y)&1 :
            p = [a+b for (a,b) in zip(books[y],p)]
    t.append(p)




ans = []


c = True

for z in t:
    c = True
    for s in range(1,m+1):
        if z[s] < r:
            c = False
    if c:
        ans.append(z[0])

if ans != []:
    print(min(ans))

else:
    print(-1)

Measured memory_bytes: 11440
data class Satoumizu(val water:Int, val sugar:Int):Comparable<Satoumizu>{
    override fun compareTo(other: Satoumizu): Int {
        return (this.sugar * other.water).compareTo(this.water * other.sugar)
    }

}
fun main(args:Array<String>):Unit{
    val arg = readLine()!!.split(' ').map(String::toInt).toIntArray()
    val a = arg[0] * 100
    val b = arg[1] * 100
    val c = arg[2]
    val d = arg[3]
    val e = arg[4]
    val f = arg[5]
    var max = Satoumizu(1, 0)
    for (aNum in 0 .. (f / a)){
        for (bNum in 0 .. ((f - a * aNum) / b)){
            val sugarWeight = maxSugar(minOf(f - aNum * a - bNum * b, (aNum * a + bNum * b) * e / 100), c, d)
            if (max <= Satoumizu(aNum * a + bNum * b, sugarWeight)){
                max = Satoumizu(aNum * a + bNum * b, sugarWeight)
            }
        }
    }
    println("${max.water + max.sugar} ${max.sugar}")
}
fun maxSugar(rest:Int, c:Int, d:Int):Int{
    return (0 .. (rest / c)).map{cNum -> cNum * c + (rest - cNum * c) / d * d}.max() ?: 0
}
fun minOf(a:Int, b:Int):Int = if (a < b) a else b

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

namespace kozaiyApp
{
    public class TwoColorsCardGame
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            List<string> s = new List<string>();
            for (int i = 0; i < N; i++)
            {
                s.Add(Console.ReadLine());
            }
            s.Sort();

            int M = int.Parse(Console.ReadLine());
            List<string> t = new List<string>();
            for (int i = 0; i < M; i++)
            {
                t.Add(Console.ReadLine());
            }
            t.Sort();

            // 青カードそれぞれいくらになるか
            List<int> amount = new List<int>();
            while (s.Count > 0)
            {
                int count = 0;
                string l = s[0];

                // +
                int p = s.BinarySearch(l);
                while (0 <= p)
                {
                    s.RemoveAt(p);
                    count += 1;
                    p = s.BinarySearch(l); // 新しいsで再検索
                }

                // -
                int q = t.BinarySearch(l);
                while (0 <= q)
                {
                    t.RemoveAt(q);
                    count -= 1;
                    q = t.BinarySearch(l);
                }

                amount.Add(count);
            }

            int ans = amount.Max();
            if (0 > ans)
            {
                Console.WriteLine(0);
                return;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13408
import java.util.*;

class SwappingTwoNumbers {
    public static void main(String...args) {
        final Scanner sc = new Scanner(System.in);
        while(true) {
            final int a = sc.nextInt();
            final int b = sc.nextInt();
            if(a == 0 && b == 0)
                break;
            System.out.println(a < b ? a + " " + b : b + " " + a);
        }
    }
}
public class Main {
    public static void main(String... args) {
        SwappingTwoNumbers.main();
    }
}

Measured memory_bytes: 27116
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 1000000007;
// const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;
int a, b, c, d;

signed main(){
    cin >> a >>  b >>  c >>  d;

    int ans = min(b, d) - max(a,c);
    (ans<0)?cout<< 0<< endl:cout<< ans<< endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
char ch[2][2]={{'R','B'},{'G','Y'}};	
int n,m,d;
char calc (int x,int y)
{
	int a=(x+y),b=(x-y);
	a=a+1000;b=b+1000;
	a/=d;b/=d;
	return ch[a&1][b&1];
}
int main()
{
	scanf("%d%d%d",&n,&m,&d);
	for (int u=1;u<=n;u++)
	{
		for (int i=1;i<=m;i++)
		printf("%c",calc(u,i));
		printf("\n");
	}
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Cube cube = new Cube(br);
		//char[] act = br.readLine().toCharArray();
		//cube.roll(act);
		int count = Integer.parseInt(br.readLine());
		for(int i = 0; i < count; i++){
			cube.search(br);
		}
		//System.out.println(cube.top);
	}
}

class Cube {
	String[] num;
	String top;
	String center;
	String back;
	String bottom;
	String right;
	String left;
	String temp;

	Cube(BufferedReader br) throws IOException {
		num = br.readLine().split(" ");
		this.top = num[0];
		this.center = num[1];
		this.right = num[2];
		this.left = num[3];
		this.back = num[4];
		this.bottom = num[5];
	}

	void south() {
		temp = this.top;
		this.top = this.back;
		this.back = this.bottom;
		this.bottom = this.center;
		this.center = temp;
	}

	void north() {
		temp = this.top;
		this.top = this.center;
		this.center = this.bottom;
		this.bottom = this.back;
		this.back = temp;
	}

	void east() {
		temp = this.top;
		this.top = this.left;
		this.left = this.bottom;
		this.bottom = this.right;
		this.right = temp;
	}

	void west() {
		temp = this.top;
		this.top = this.right;
		this.right = this.bottom;
		this.bottom = this.left;
		this.left = temp;
	}

	void roll(char[] act) {
		for (int i = 0; i < act.length; i++) {
			switch (act[i]) {
			case 'S':
				south();
				break;
			case 'N':
				north();
				break;
			case 'E':
				east();
				break;
			case 'W':
				west();
				break;
			}
		}
	}

	void search(BufferedReader br) throws IOException {
		String[] numList = br.readLine().split(" ");
		for (int i = 0; i < 6; i++) {
			if (i == 3) {
				this.east();
				}
			if (numList[1].equals(this.center)){
				break;
				} else {
				this.north();
				}
		}
		while (true) 
			if (numList[0].equals(this.top)) {
				break;
				} else {
				this.west();
				}
		System.out.println(right);
	}
}

Measured memory_bytes: 24216
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n, 1); rank.resize(n, 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};

ll N,M;
int main(){
    cin>>N>>M;
    UnionFind uf;
    uf.init(N);
    for(ll i=0;i<M;i++){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        uf.merge(a,b);
    }
    ll ans=0;
    for(ll i=0;i<N;i++){
        ans=max(ans,uf.getSize(i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6368
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



LL snum[4001];
int main(){
	int N;
	cin>>N;
	vector<string>res;
	int cnt=0;
	cin.ignore();
	REP(i,N){
		
		string str;
		getline(cin,str);
		
		std::string::size_type index = str.find("Hoshino");
		while(index!=string::npos){
			str.replace(index,7,"Hoshina");
			index=str.find("Hoshino",index);
		}
		res.PB(str);
	}
	REP(i,N)cout<<res[i]<<endl;
	return 0;
}

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

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

    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=n-1;0<i;i=i-1){
        cout <<a[i]<< " ";
    }
        cout << a[0] << endl;
    return 0;
}


Measured memory_bytes: 3080
#include<iostream>
using namespace std;
const int MAX = 1000;
void insertionSort(int A[], int N);

int main(){
  int A[MAX],n;
  
  cin >> n;
  for(int i=0;i<n;i++)
    cin >> A[i];
  insertionSort(A, n);
  return 0;
}

void insertionSort (int A[], int N){
  int i,j,v;
  for (i = 0; i < N; i++){
    j = i;
    
    while (j > 0 && A[j] < A[j-1]){
      v = A[j];
      A[j] = A[j-1];
      A[j-1] = v;
      j--;
    }
    cout << A[0];
    for(int i=1;i<N;i++)cout << " " << A[i];
    cout << endl;
  }
}

Measured memory_bytes: 1164
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut a = a;
    let mut time = 0;
    loop {
        for i in 0..a.len() {
            if a[i] % 2 == 0 {
                a[i] = a[i] / 2;
            } else {
                println!("{}", time);
                return;
            }
        }
        time+=1;
    }
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, x;
    cin >> n >> x;
    ll a[n];
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum == x) {
        cout << n << endl;
        return 0;
    }

    sum = 0;
    sort(a, a + n);
    rep(i, n) {
        sum += a[i];
        if (sum > x) {
            cout << i << endl;
            return 0;
        }
    }
    cout << n - 1 << endl;
    return 0;
}



Measured memory_bytes: 256