akhauriyash/Code-Regression huggingface dataset:
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextInt64() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}


func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func (io *Io) PrintBool(b bool, trueS, falseS string) {
	if b {
		io.PrintLn(trueS)
	} else {
		io.PrintLn(falseS)
	}
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func absi(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

type Int64s []int64
func (f Int64s) Len() int {
	return len(f)
}
func (f Int64s) Less(i, j int) bool {
	return f[i] < f[j]
}

func (f Int64s) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}


func abcInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func gcdInt(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

var (
	io *Io
)

type P struct {
	s string
	p int
	id int
}

type PS []P
func (f PS) Len() int {
	return len(f)
}
func (f PS) Less(i, j int) bool {
	if f[i].s != f[j].s {
		return f[i].s< f[j].s
	}
	return f[i].p > f[j].p
}

func (f PS) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func solve() {
	n,k := io.NextInt(), io.NextInt()
	v := make([]int, n)
	for i := range v {
		v[i] = io.NextInt()
	}

	ans := 0
	for l := 0; l <= n; l++ {
		for r := 0; r <= n; r++ {
			if l+r > n {
				break
			}
			if l+r > k {
				break
			}
			rem := k-l-r
			gots := make([]int, 0)
			for i := 0; i < l; i++ {
				gots = append(gots, v[i])
			}
			for i := 0; i < r; i++ {
				gots = append(gots, v[len(v) - 1 - i])
			}
			sort.Ints(gots)
			for len(gots) > 0 && rem > 0 && gots[0] < 0 {
				gots = gots[1:]
				rem--
			}
			sum := 0
			for _,v := range gots {
				sum += v
			}

			if ans < sum {
				ans = sum
			}
		}
	}

	io.PrintLn(ans)
}


func main() {
	io = NewIo()
	f, err := os.Open("src/input")
	if err == nil {
		io.reader = bufio.NewReader(f)
	}
	defer io.Flush()

	solve()
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  cout<<(n*a<b?n*a:b)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
void solve();
 
clock_t start_time;
double get_current_time() {
	return (double)(clock() - start_time) / CLOCKS_PER_SEC;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	solve();
}
 
/* ========== actual code starts here ========== */
 
#define fi first
#define re return
#define se second
#define in insert
#define pb push_back
#define eb emplace_back
#define y1 y123123123123
#define all(x) x.begin(), x.end()
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repx(i, x, n) for (int i = x; i < (n); i++)
#define repd(i, n, d) for (int i = 0; i < (n); i += d)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepd(i, n, d) for (int i = (n) - 1; i >= 0; i -= d)
 
#ifdef artem
	#define debug(x) x
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(x)
#endif
 
void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[ i ];
	}
	ll ans = 0;
	rep(i, n) {
		ans += a[ i ] / 2;
		if(i + 1 < n && a[ i + 1 ] != 0 && a[ i ] % 2 != 0) {
			++ans;
			a[ i ]--;
			a[ i + 1 ]--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3732
s = input()

a = s.split('eraser')

for i in a:
    b = i.split('erase')
    for j in b:
        c = j.split('dreamer')
        for k in c:
            d = k.split('dream')
            for l in d:
                if l != '':
                    print('NO')
                    exit()
print('YES')

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

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

int main(){
	int n,k,tmp;
	cin>>n>>k;
	int MAX=0,G=0;
	for(int i=1;i<=n;i++){
		cin>>tmp;
		G=gcd(G,tmp);
		MAX=max(MAX,tmp);
	} 	
	if(k<=MAX&&k%G==0) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   100007
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/




int main()
{

    ll q=0,i,j,a,b,k;
    cin>>a>>b;
    if(a==0)
	{
		if(b==100)
			cout<<b+1<<endl;
		else
			cout<<b<<endl;
	}
    else if(a==1)
	{
		if(b==100)
			cout<<100*b+100<<endl;
		else
			cout<<100*b<<endl;
	}
    else
	{
		if(b==100)
			cout<<1010000<<endl;
		else
        cout<<10000*b<<endl;
	}
    return 0;

}



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

int x[100005];
int t[100005];
typedef long long ll;
int main() {
  int n,m;
  cin >> n >> m;
  for(int i = 0; i < m; i++) cin >> x[i];
  sort(x,x+m);
  for(int i = 1; i < m; i++) t[i-1] = x[i] - x[i-1];
  sort(t,t+m-1);

  ll ans = 0;

  for(int i = 0; i < m - n; i++) {
    ans += t[i];
    //  cout << t[i] << endl;
  }

  cout << ans << endl;
}
  


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

void solve(long long A, long long B)
{
    //cout << ((A + B >= A - B) ? ((A + B >= A * B) ? (A + B) : (A * B)) : A - B) << endl;
    long long maxa = -1000000000;
    long long add = A + B;
    long long mn = A - B;
    long long ab = A * B;

    maxa = max(add, mn);
    maxa = max(maxa, ab);

    cout << maxa << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int crd[];
	static int num[];
	static int n;
	static int x;
	
	public static int f(int sum, int preIndex, int k) {
		if (x < sum) {
			return 0;
		} else if (sum == x) {
			return 1;
		}
		
		int count = 0;
		for (int i = preIndex; 0 <= i; i--) {
			if (i == preIndex && k < num[i]) {
				count += f(sum + crd[i], i, k + 1);
			} else if (i != preIndex) {
				count += f(sum + crd[i], i, 1);
			}
		}
		
		return count;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			crd = new int[n];
			num = new int[n];
			for (int i = 0; i < n; i++) {
				crd[i] = sc.nextInt();
				num[i] = sc.nextInt();
			}
			int m = sc.nextInt();
			for (int i = 0; i < m; i++) {
				x = sc.nextInt();
				System.out.println(f(0, n - 1, 0));
			}
		}
	}
}

Measured memory_bytes: 20884
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

typedef long long ll;

const int MAXN = 100005;
const ll INF = (1ll << 60) - 1;

int n;
int a[MAXN];

ll f[MAXN][2];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	f[0][1] = -INF;
	for (int i = 1;i <= n;i++)
	{
		f[i][~a[i] & 1] = (a[i] ? f[i - 1][1] + 1 + ((a[i] - 1) >> 1) : -INF);
		f[i][a[i] & 1] = max(f[i - 1][0],f[i - 1][1]) + (a[i] >> 1);
	}
	cout << max(f[n][0],f[n][1]) << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int sum = 0, ma = 0;
  for (int i = 0; i < N; ++i) {
    int p; cin >> p;
    sum += p;
    ma = max(ma, p);
  }
  cout << sum - ma/2 << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const string D_blue    = "\x1b[36m";
const string D_green   = "\x1b[32m";
const string D_red     = "\x1b[31m";
const string D_yellow  = "\x1b[33m";
const string Db_red    = "\x1b[41m";
const string Db_yellow = "\x1b[43m";
const string D_end     = "\x1b[39m";
const string Db_end    = "\x1b[49m";

int main (){
  int A,B,K;
  while (cin >> A >> B >> K){
    REP(i,K){
      int ans = A + i;
      if(ans > B)break;
      cout << ans << endl;
    }
    REP(i,K){
      int ans = B - K + i + 1;
      if(ans > B) break;
      if(ans > A + K - 1)
      cout << ans << endl;
    }
  }
  return 0;
}


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

int main(){
        int in,h,m,s;
        cin >> in;
        h = in / 3600;
        in = in - h*3600;
        m = in / 60;
        in = in - m* 60;
        s = in;
        cout << h << ":" << m << ":" << s << endl;
        return 0;
}

Measured memory_bytes: 3112
#include<stdio.h>
int main(void)
{
  int x,y,a,b,i,num[30],t;
  
  scanf("%d",&y);
  scanf("%d",&x);
  
  for(i=0;i<y;i++)
    {
      num[i]=i+1;
    }
  
  for(i=0;i<x;i++)
    {
      scanf("%d,%d",&a,&b);
      t=num[a-1];
      num[a-1]=num[b-1];
      num[b-1]=t;
    }
  
  for(i=0;i<y;i++)
    {
      printf("%d\n",num[i]);
    }
  
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    ll sum=0;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        sum+=(tmp-1);
    }
    printf("%lld\n", sum);

    return 0;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) (x).begin(),(x).end()
#define Ceil(x, n) (((((x))+((n)-1))/n))
#define CeilN(x, n) (((((x))+((n)-1))/n)*n)

#define INF 2e7
#define INF_LL 1LL<<60
#define ll long long
typedef pair<ll, ll>    P;

int main(){
    ll h, w, m;
    cin >> h >> w >> m;
    vector<ll> yoko(h), tate(w);
    vector<P> bomb(m);

    REP(i, h) yoko[i] = 0;
    REP(i, w) tate[i] = 0;

    REP(i, m) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        yoko[x]++, tate[y]++;
        bomb[i].first = x, bomb[i].second = y;
    }

    ll yoko_max = 0, tate_max = 0, yoko_max_num = 0, tate_max_num = 0;
    REP(i, h) yoko_max = max(yoko_max, yoko[i]);
    REP(i, w) tate_max = max(tate_max, tate[i]);

    REP(i, h) if(yoko_max == yoko[i]) yoko_max_num++;
    REP(i, w) if(tate_max == tate[i]) tate_max_num++;

    ll num = yoko_max_num * tate_max_num;

    REP(i, m) {
        int x = bomb[i].first;
        int y = bomb[i].second;
        if(yoko[x] == yoko_max && tate[y] == tate_max) {
            num--;
        }
    }

    ll ans = 0;

    if(num > 0) {
        ans = yoko_max + tate_max;
    } else {
        ans = yoko_max + tate_max - 1; 
    }

    cout << ans << endl;

    return 0;
}


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

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}


#define incID(i, l, r) for(int i = (l); i < (r); i++)
#define inc(i, n) incID(i, 0, n)
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }


// ---- ----

int n, k;
vector<int> vec[100000];
bool has[100000];
int mi[100000];
int ma[100000];

void prod(int x, int y) {
	if(has[y]) {
		bool flag = true;
		if(has[x] && (mi[x] - mi[y]) % 2 == 0) { flag = false; }
		setmax(mi[x], mi[y] - 1);
		setmin(ma[x], ma[y] + 1);
		has[x] = true;
		if(mi[x] > ma[x]) { flag = false; }
		if(! flag) {
			puts("No");
			exit(0);
		}
	}
}

bool dfs(int node, int pre) {
	if(pre != -1) { prod(node, pre); }
	for(auto && i : vec[node]) {
		if(i != pre) {
			dfs(i, node);
			prod(node, i);
		}
	}
}

int main() {
	reader(&n);
	inc(i, n - 1) {
		int a, b;
		reader(&a, &b);
		a--; b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	fill(mi, mi + n, -1000000);
	fill(ma, ma + n,  2000000);
	reader(&k);
	inc(j, k) {
		int v, p;
		reader(&v, &p);
		v--;
		mi[v] = p;
		ma[v] = p;
		has[v] = true;
	}
	
	dfs(12345 % n, -1);
	dfs(12345 % n, -1);
	
	puts("Yes");
	inc(i, n) { writerLn(mi[i]); }
	
	return 0;
}


Measured memory_bytes: 11392
import sys
a,b,c,d=map(int,input().split())
e=max(a//d+1,c//b+1)
for i in range(2*(e+1)):
    if i%2!=0:
        a-=d
        if a<=0:
            print('No')
            sys.exit()
    else:
        c-=b
        if c<=0:
            print('Yes')
            sys.exit()

Measured memory_bytes: 9216
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{   ll n,k;
    cin>>n>>k;
    ll a[n+1],dp[n+1];
    a[0]=0;
    for(ll i=1;i<=n;i++){
            cin>>a[i];
    dp[i]=1e9+7;}
    //memset(dp,1e5,sizeof(dp));
    dp[0]=0;
    dp[1]=0;
    for(ll i=1;i<=n;i++){

          for(ll j=i+1;j<=i+k;j++){
            if(j<=n)dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
            //cout<<dp[j]<<endl;
            }

    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=input()
    print(N.replace('1','X').replace('9','1').replace('X','9'))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
/*
 * Fast UNION(サイズによるUNION) + 経路圧縮
 * (入門データ構造とアルゴリズム(オライリー)8章)
 */
#include <stdio.h>

#define N 100000

/* 互いに素な集合を木で表す配列: */
/* 負の値: この要素は根であり、値はその木の要素数*(-1) */
/* 正の値: 親要素のインデックス */
int S[N+1];

/* 各場所に置いてある数字 */
int P[N+1];

void makeset(int size) {
    int i;
    /* 自身のみを含む1要素の集合に属するように初期化 */
    for (i = 1; i <= size; i++) {
        S[i] = -1; /* 根であり要素数は1 */
    }
}

int find(int x) {
    if (S[x] < 0) {
        return x;
    }


    return S[x] = find(S[x]);
}

void merge(int x, int y) {
    int root1 = find(x);
    int root2 = find(y);

    if (root1 == root2) {
        return;
    }

    /* 要素数が少ない方を子にする。*/
    /* 要素数を-1倍して格納しているので不等号の向きに注意 */
    if (S[root2] < S[root1]) {
        /** root1をroot2の子にする */
        S[root2] += S[root1];
        S[root1] = root2;
    } else {
        /** root2をroot1の子にする */
        S[root1] += S[root2];
        S[root2] = root1;
    }
}

int main()
{
    int i;
    int n, m;
    int x, y;
    int r;

    scanf("%d %d", &n, &m);

    makeset(n);

    for (i = 1; i <= n; i++) {
        scanf("%d", &P[i]);
    }

    for (i = 1; i <= m; i++) {
        scanf("%d %d", &x, &y);
        merge(x, y);
    }

    r = 0;
    for (i = 1; i <= n; i++) {
        if (find(i) == find(P[i])) {
            r++;
        }
    }

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


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

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

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

const long long INF = 1LL << 60;

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

    vector<ll> A(N);
    vector<ll> S;

    ll sum = 0;

    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    rep(i, N) {
        ll tmp = A[i];
        ll cnt = 2;
        while (tmp > 0) {
            ll res = A[i] / cnt;
            S.push_back(tmp - res);
            tmp = res;
            cnt *= 2;
        }
    }

    sort(all(S));
    reverse(all(S));

    rep(i, min((int)S.size(), M)) {
        sum -= S[i];
    }

    cout << sum << endl;
    return 0;
}

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

void fnInput(string& rsColor)
{
  int nColorSiz;
  cin >> nColorSiz >> rsColor;
}

int fnColorCount(string sColor)
{
  int nColorCnt = 0;
  int nBgn = 0;

  while (nBgn < sColor.size())
  {
    char cColor = sColor[nBgn];
    nColorCnt++;

    int nPos = nBgn + 1;
    while (nPos < sColor.size() &&
           cColor == sColor[nPos] )
      nPos++;

    nBgn = nPos;
  }

  return nColorCnt;
}

int main()
{
  string sColor;

  fnInput(sColor);
  cout << fnColorCount(sColor) << endl;

  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<string> ans;
int rep(char c){
	int sum,k;
	for(int i=0;i<3;i++){
		sum=0;k=0;
		for(int j=0;j<3;j++){
			if(ans[i][j]==c)
				sum++;
			if(ans[j][i]==c)
				k++;
		}
		if(sum==3||k==3)
			return 1;
	}
	if(ans[0][0]==c&&ans[1][1]==c&&ans[2][2]==c)
		return 1;
	if(ans[0][2]==c&&ans[1][1]==c&&ans[2][0]==c)
		return 1;
	return 0;
}
int main(){
	string s;
	while(cin>>s,s[0]!='0'){
		ans.push_back(s);
		for(int i=0;i<2;i++){
			cin>>s;
			ans.push_back(s);
		}
		if(rep('w'))
		cout<<'w'<<endl;
		else if(rep('b'))
		cout<<'b'<<endl;
		else cout<<"NA"<<endl;
		ans.clear();
	}
	return 0;
}

Measured memory_bytes: 0
// 2020-09-19 21:01:42
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
void answer() {
  int n;
  cin >> n;
  vector<int> d1(n), d2(n);
  rep(i, n) cin >> d1[i] >> d2[i];
  bool ok = false;
  rep(i, n - 2) {
    if (d1[i] == d2[i] && d1[i + 1] == d2[i + 1] && d1[i + 2] == d2[i + 2])
      ok = true;
  }
  if (ok) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
using namespace std;
long long i[10000000];
long long u[11111110];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=140,h=170,now=1;
  cin >>a>>b;
  if(b%a==0) cout <<a+b<<'\n';
  else cout<<b-a<<'\n';
  return (0);
}


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

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

  bool flg = true;

  REP(i, s.size()){
    if(i%2 == 1){
      if( s[i] == 'R') flg = false;
    }
    if(i%2 == 0){
      if( s[i] == 'L') flg = false;
    }
  }

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


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==f && (f==r && r==-1)){
			break;
		}
		if(m==-1 || f==-1){
			printf("F");
		}else if(m+f>=80){
			printf("A");
		}else if(m+f>=65){
			printf("B");
		}else if(m+f>=50){
			printf("C");
		}else if(m+f>=30){
			if(r>=50){
				printf("C");
			}else{
				printf("D");
			}
		}else{
			printf("F");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

double d[20][20], a[20][20][20], dp[10000][20][20];

int main() {
	int n; double r, th;
	cin >> n >> r >> th;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			d[i][j] = hypot(x[i] - x[j], y[i] - y[j]);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++) {
				if (i == j || j == k) continue;
				int x1 = x[i] - x[j], y1 = y[i] - y[j];
				int x2 = x[j] - x[k], y2 = y[j] - y[k];
				double c = (x1 * x2 + y1 * y2) / d[i][j] / d[j][k];
				a[i][j][k] = (c >= cos(th / 180 * M_PI));
			}
	fill(dp[0][0], dp[0][0] + 10000 * 20 * 20, FLT_MAX);
	for (int i = 1; i < n; i++)
		dp[1][i][0] = d[i][0];
	for (int l = 2; l < 10000; l++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				for (int k = 0; k < n; k++)
					if (i != j && j != k && a[i][j][k])
						dp[l][i][j] = min(dp[l][i][j], dp[l - 1][j][k] + d[i][j]);
	int maxi = 0;
	for (int l = 1; l < 10000; l++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (dp[l][i][j] <= r) maxi = l;
	cout << maxi << endl;
}

Measured memory_bytes: 32588
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	final static String[] C = {"a","b","c","d","e","f","g","h","i","j"};
	static BufferedReader reader;
	final static boolean MODE_DEBUG = true;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		int N = readLineInt()[0];
		
		String[] ss = get(N,N,1);
		
		for(String s : ss) {
			print(s);
		}
		
		//String[] s = readLine();
		//print(num);
	}
	
	public static String[] get(int N, int left, int max) {
		if(left==1) {
			String[] ss = new String[max];
			for(int i=0;i<max;i++) {
				ss[i] = C[i];
			}
			return ss;
		}else {
			String[][] sss = new String[max][];
			int rsl = 0;
			for(int j=0;j<max-1&&j<N-left+1;j++) {
				sss[j] = get(N,left-1,max);
				rsl+=sss[j].length;
			}
			sss[max-1] = get(N,left-1,max+1);
			rsl+=sss[max-1].length;
			String[] rs = new String[rsl];
			int rsi = 0;
			for(int j=0;j<max-1&&j<N-left+1;j++) {
				for(int i=0;i<sss[j].length;i++) {
					rs[rsi] = C[j]+sss[j][i];
					rsi++;
				}
			}
			for(int i=0;i<sss[max-1].length;i++) {
				rs[rsi] = C[max-1]+sss[max-1][i];
				rsi++;
			}
			return rs;
		}
	}
	
	//functions here
	//note that all methods should be STATIC

	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}


Measured memory_bytes: 101868
#include <stdio.h>
int main(void) {
    int i, n, k, h;
    int ans=0;

    scanf("%d", &n);
    scanf("%d", &k);
    for (i=0; i<n; i++) {
        scanf("%d", &h);
        if (h >= k) {
            ans++;
        }
    }

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int a,int b)
{
    int t;
    if(a<b)
    {
        t = a;
        a = b;
        b = t;
    }
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    int m,n;
    cin>>m>>n;
    cout<<gcd(m,n)<<endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1LL<<61);

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if ((a&1) == (b&1)) {
    cout << (b-a)/2 << endl;
  } else {
    ll ans = min(a+(b-a)/2, (n-b+1)+(n-a-(n-b+1))/2);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;
const int MX = 1e5+5;
int dp[MX][105];
vector <int> v,w;
int n,W;

int solve(int weight,int ind){
    if(weight > W) return -1e17;
    if(ind == n+1) return 0;
    if(dp[weight][ind] != -1) return dp[weight][ind];
    long long ans = -1e17;
    ans = max(ans, solve(weight + w[ind],ind + 1) + v[ind]);
    ans = max(ans, solve(weight ,ind + 1));
    return dp[weight][ind] = ans;
}

int32_t main()
{
    memset(dp,-1,sizeof dp);
    cin>>n>>W;
    v.resize(n+1);
    w.resize(n+1);
    for(int i=1 ; i<=n ; i++) cin>>w[i]>>v[i];
    cout<<solve(0,1);
    return 0;
}


Measured memory_bytes: 82432
#include<bits/stdc++.h>
int A,B,a,b;
int main(){
	scanf("%d%d%d%d",&A,&B,&a,&b);
	if(A%a==0&&B%b==0)return puts("No"),0;
	puts("Yes");
	for(int i=0;i<A;++i){
		for(int j=0;j<B;++j){
			printf("%d ",i%a||j%b?-1237:1237*(a*b-1)-1);
		}puts("");
	}
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

mat mul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++){
        for (int k = 0; k < B.size(); k++){
            for (int j = 0; j < B[0].size(); j++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n){
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int main(){
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
    int a, b, s;
    scanf("%d", &s);
    a = s/100;
    b = s%100;
    
    if (1<=a && a<=12){
        if (1<=b && b<=12){
            printf("%s\n", "AMBIGUOUS");
        }else{
            printf("%s\n", "MMYY");
        }
    }else{
        if (1<=b && b<=12){
            printf("%s\n", "YYMM");
        }else{
            printf("%s\n", "NA");
        }
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    ll ans = 1;
    for(int i = 1; i <= n; i++)
    {
        ans = (ans * i) % MOD;
    }
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 0x3FFFFFFF
using namespace std;
typedef long long ll;
int siz[MAXN];
ll ans;
int siz1,d1,d2;
ll dep[MAXN];
vector<int> a[MAXN],w[MAXN];
int n;
void dfs(int x,int fa){
	for(int i=0;i<a[x].size();i++){
		int u=a[x][i];
		if(u==fa)
			continue;
		dfs(u,x);
		siz[x]+=siz[u];	
	}
	siz[x]++;
	int siz2=n-siz[x];
	for(int i=0;i<a[x].size();i++)
		if(a[x][i]!=fa)
			siz2=max(siz2,siz[a[x][i]]);
	if(siz2<siz1||siz1==-1){
		siz1=siz2;
		d1=x;
		d2=0;
	}
	else if(siz1==siz2)
		d2=x;
}
void solve(int x,int fa){
	for(int i=0;i<a[x].size();i++){
		int u=a[x][i];
		if(u==fa)
			continue;
		dep[u]=dep[x]+w[x][i];
		solve(u,x);
	}	
	ans+=dep[x]*2;
}
int main(){
	SF("%d",&n);
	int u,v,val;
	for(int i=1;i<n;i++){
		SF("%d%d%d",&u,&v,&val);
		a[u].push_back(v);
		a[v].push_back(u);	
		w[u].push_back(val);
		w[v].push_back(val);
	}
	siz1=-1;
	dfs(1,0);
	solve(d1,0);
	ll add=-1;
	if(d2==0){
		for(int i=1;i<=n;i++)
			if(i!=d1){
				if(add==-1)
					add=dep[i];
				add=min(add,1ll*dep[i]);	
			}
	}
	else
		add=dep[d2];
	ans-=add;
	PF("%lld",ans);
}

Measured memory_bytes: 19072
//Yazar: Mehmet Kutay Bozkurt
//Auther: Mehmet Kutay bozkurt
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long int lo;
lo a,b,c,d,e,n,y,k,m,x,p,q,t,a1[500005],a2[200005],v[105],r;
char c1,c2,c3,c4;
bool check=false;
string s1,s2,s3,s4,cikti="NO";
vector <pair<int,int> > vect;
int main() {
    cin>>a>>s1;
    if(a<3200){
        cout<<"red\n";
    }
    else{
        cout<<s1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);


int main() {
	int n, k;
	cin >> n >> k;
	string s; cin >> s;

	VI a;
	if (s[0] == '0')a.pb(0);

	int i = 0;
	while (i < n) {
		char elem = s[i];
		int cnt = 0;
		while (i < n && s[i] == elem) { cnt++; i++; }
		a.pb(cnt);
	}
	if (s.back() == '0')a.pb(0);

	int sum = 0;
	rep(i, min(k * 2 + 1, sz(a))) {
		sum += a[i];
	}

	int ans = sum;
	int be = 0, en = k * 2;
	while (en <= sz(a)) {
		sum = sum + a[en + 1] + a[en + 2] - a[be] - a[be + 1];
		be += 2; en += 2;
		ans = max(sum, ans);
		if (en >= sz(a) - 1)break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1020
n, k = map(int, input().split())
teleporter = list(map(lambda x: int(x) - 1, input().split()))

before_loop_idx = 0
curr_city = 0
des_set = {0}
while before_loop_idx < k:
    curr_city = teleporter[curr_city]
    if curr_city in des_set:
        break
    des_set.add(curr_city)
    before_loop_idx += 1

if before_loop_idx == k:
    print(curr_city + 1)
else:
    cycle_cities = [curr_city]
    while True:
        curr_city = teleporter[cycle_cities[-1]]
        if curr_city == cycle_cities[0]:
            break
        cycle_cities.append(curr_city)

    print(cycle_cities[(k - before_loop_idx - 1) % len(cycle_cities)] + 1)


Measured memory_bytes: 32324
#include<iostream>
#include <vector>
#include <list>
#include<set>
#include<algorithm>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
ll n,m;
vector<ll>g[200005],v;
bool visit[200005];
set<ll>s;
void dfs(ll node)
{
    visit[node]=1;
    s.insert(node);
    for(auto child:g[node])
    {
        if(!visit[child])
            dfs(child);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,t,b,c,d,a,l,r;
    cin>>n>>m;
    for(i=1; i<=m; i++)
    {
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    for(i=1; i<=n; i++)
    {

        if(!visit[i])
        {
            dfs(i);
            v.pb(s.size());
            s.clear();
        }
    }
    sort(v.rbegin(),v.rend());
    if(v.size()==1)
        cout<<v[0]<<'\n';
    else
        cout<<(v[0]-v[1])+v[1]<<'\n';
}














Measured memory_bytes: 33468
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] checkPoints = new int[n][3];
		int startPoint[] = {0, 0, 0};

		for (int i = 0; i < n; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			checkPoints[i][0] = t;
			checkPoints[i][1] = x;
			checkPoints[i][2] = y;
			if (isAbleToGo(startPoint, checkPoints[i])) {
				startPoint = checkPoints[i];
			} else {
				System.out.println("No");
				break;
			}
			if (i == n - 1) {
				System.out.println("Yes");
			}
		}
	}
	public static boolean isAbleToGo(int fromPoint[], int toPoint[]) {
		int timeRemained = toPoint[0] - fromPoint[0];
		int differOfX = Math.abs(toPoint[1] - fromPoint[1]);
		int differOfY = Math.abs(toPoint[2] - fromPoint[2]);
		int differ = differOfX + differOfY;
		int amariTime = timeRemained - differ;

		return amariTime >= 0 && amariTime % 2 == 0;//2の倍数ターン分余ったら行ったり来たりすればOK
	}

}


Measured memory_bytes: 94008
import sys
a,b,c,k = list(map(int,input().split()))

ans = 0
if a <= k:
    ans += a
    k -= a
else:
    print(k)
    sys.exit()
if b <= k:
    k -= b
else:
    print(ans)
    sys.exit()
ans -= k
print(ans)

Measured memory_bytes: 61652
#include <iostream>

using namespace std;

int main() {
  int K;
  int array[] = {
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  };
  
  cin >> K;
  
  cout << array[K - 1];
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int h, w, d;
    cin >> h >> w >> d;
    vector<P> a(h*w+1);
    rep(i, h){
        rep(j, w){
            int x;
            cin >> x;
            a[x] = make_pair(i, j);
        }
    }
    vector<int> rui(h*w+1);
    rep(i, d){
        rui[i] = 0;
    }
    rep2(i, d, h*w+1){
        P pre = a[i - d], now = a[i];
        rui[i] += rui[i - d] + abs(pre.first - now.first) + abs(pre.second - now.second);
    }
    int q;
    cin >> q;
    rep(i, q){
        int res = 0;
        int l, r;
        cin >> l >> r;
        res = rui[r] - rui[l];
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 4192
fun main(args:Array<String>){
    val numOfpole = readLine()!!.toInt()
    val poleLength = readLine()!!.split(" ").map(String::toInt)
    var ans = 0
    var counter = 1
    for(i in 0..numOfpole-3){
        for(j in counter..numOfpole-2){
            for(k in j+1..numOfpole-1){
                if(poleLength[i] + poleLength[j] > poleLength[k] &&
                   poleLength[j] + poleLength[k] > poleLength[i] &&
                   poleLength[k] + poleLength[i] > poleLength[j] &&
                   poleLength[i] != poleLength[j] &&
                   poleLength[i] != poleLength[k] &&
                   poleLength[j] != poleLength[k]) {
                    ans++
                }
            }
        }
        counter++
    }
    println(ans)
}

Measured memory_bytes: 38976
#include<stdio.h>
#include<string.h>
int flag;
char s[101];
int main()
{
	scanf("%s",s);
	int l=strlen(s);
	for(int i=0;i<l;i++)
	{
		if(s[i]=='C')
			flag=1;
		if(s[i]=='F'&&flag==1)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(b < a)
        swap(a, b);

    if(a < c && c < b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

#define MAX 1000000
vector<int> p;
vector<bool> p_table(MAX+1,true);
void prime(){
  p_table.at(0)=false,p_table.at(1)=false;
  for(int i=2;i<=MAX;i++){
    if(p_table.at(i)){
      p.push_back(i);
      for(int j=2;i*j<=MAX;j++){
        p_table.at(i*j)=false;
      }
    }
  }
}

int main(){
  int N;
  cin>>N;
  int ans=0;
  for(int i=1;i<N;i++){
    ans+=(N-1)/i;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3752
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs = list(map(lambda x: x-X, xs))
#print(xs)
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = abs(xs[0])
for x in xs:
  r = calcgcd(r, abs(x))
print(r)


Measured memory_bytes: 14252
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H, W;
        while (true) {
            H = sc.nextInt();
            W = sc.nextInt();
            int i, k;
            for (i = 0; i < H; i++) {
                for (k = 0; k < W; k++) {
                    if ((k+i)%2==0) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
            if (H == 0 && W == 0)
                break;
            System.out.println("");
        }
    }
}


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

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

using namespace std;

int main(){
	for(int n,m,q;scanf("%d%d%d",&n,&m,&q),n;){
		bool solved[50][10]={};
		int pena[50]={},wa[50][10]={};
		while(q--){
			int id1,id2,time;
			char msg[16]; scanf("%d%d%d%s",&id1,&id2,&time,msg); id1--; id2--;
			if(msg[0]=='C'){ // CORRECT
				solved[id1][id2]=true;
				pena[id1]+=1200*wa[id1][id2]+time;
			}
			else{ // WRONG
				if(solved[id1][id2]) continue;
				wa[id1][id2]++;
			}
		}

		pair<pair<int,int>,int> res[50];
		rep(i,n){
			res[i].first.first=-count(solved[i],solved[i]+m,true);
			res[i].first.second=pena[i];
			res[i].second=i;
		}
		sort(res,res+n);

		rep(i,n) printf("%d %d %d\n",res[i].second+1,-res[i].first.first,res[i].first.second);
	}

	return 0;
}

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

const long long mod=1000000007;
long long n, a[300002];
unsigned long long ans=0;

int main(){
	cin >> n;
	for (int i=0;i<n;i++) cin >> a[i];
	for (long long j=0;j<60;j++){
		long long cnt0=0, cnt1=0;
		for (int i=0;i<n;i++){
			if (a[i]&((unsigned long long)1<<j)) cnt1++;
			else cnt0++;
		}
		unsigned long long tmp1=((unsigned long long)1<<j)%mod, tmp2=(cnt1*cnt0)%mod;
		ans+=tmp2*tmp1;
		ans%=mod;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll unsigned long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
vector<int>g[200005];
ll ans[200005];
ll sz[200005];
ll pre[maxn];
ll inv[maxn];
ll prei[maxn];
int n;
void build(int n){
    pre[1] = pre[0] = 1, inv[1] = inv[0] = 1, prei[1] = prei[0] = 1;
    for(int i = 2 ; i <= n ; i++){
        pre[i] = pre[i-1] * i % mod;
        inv[i] = (mod - mod / i * inv[mod % i] % mod) % mod;
        prei[i] = prei[i-1] * inv[i] % mod;
    }
}
void dfs(int now, int pre) {
    sz[now] = 1;
    for (auto i:g[now]) {
        if (i == pre) continue;
        dfs(i,now);
        sz[now] += sz[i];
    }
}
void dfs2(int now,int pre, ll a) {
    ans[now] = a;
    for (auto i:g[now]) {
        if (i == pre)continue;
        ll ca = a;
        ca *= sz[i];
        ca %= mod;
        ca *= inv[n-sz[i]];
        ca %= mod;
        dfs2(i,now,ca);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    f(n - 1) {
        int x ,y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1,1);
    build(n);
    ll a = 1;
    f1(n) {
        a *= i;
        a %= mod;
    }
    f1(n) {
        a *= inv[sz[i]];
        a %= mod;
    }
    dfs2(1,1,a);
    f1(n) {
        cout << ans[i] << '\n';
    }
}


Measured memory_bytes: 28276
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>

#define ll long long

using namespace std;

ll f(ll x) {

	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) {
			return i;
		}
	}

	return x;
}

int main() {

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

	int t;

	ll n, k;

	ll Q, b, c;

	cin >> n;

	ll sum = 0;
	vector<ll> a(n);
	map<ll, int> occur;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		occur[a[i]]++;
		sum += a[i];
	}

	cin >> Q;

	while (Q--) {
		cin >> b >> c;


		sum += (c - b) * occur[b];
		cout << sum << endl;
		occur[c] += occur[b];
		occur[b] = 0;
	}
	return 0;
}

Measured memory_bytes: 10036
N,Y = map(int,input().split())

for x in range(N+1):
  for y in range(N+1):
    z = N-x-y
    if 0<=z and 10000*x+5000*y+1000*z==Y:
      print(x,y,z)
      exit()

print(-1,-1,-1)

Measured memory_bytes: 9184