akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int W, H, N;
    cin >> W >> H >> N;

    vvi xya(N, vi(3));
    REP(i, N)
    {
        cin >> xya[i][0] >> xya[i][1] >> xya[i][2];
    }

    int x1 = 0, x2 = W, y1 = 0, y2 = H;

    REP(i, N)
    {
        int x = xya[i][0], y = xya[i][1], a = xya[i][2];
        if (a == 1)
        {
            x1 = max(x, x1);
        }
        else if (a == 2)
        {
            x2 = min(x, x2);
        }
        else if (a == 3)
        {
            y1 = max(y, y1);
        }
        else
        {
            y2 = min(y, y2);
        }
    }
    int ans = max(0, x2 - x1) * max(0, y2 - y1);
    cout << ans << endl;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

char board[30][30];
bool visited[30][30];

int H, W;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

void dfs(int x, int y) {
   for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (board[nx][ny] == '#') continue;
      if (visited[nx][ny]) continue;
      visited[nx][ny] = true;
      dfs(nx, ny);
   }
}

int main() {
   while (cin >> W >> H, W || H) {
      memset(visited, false, sizeof(visited));

      int sx = 0, sy = 0; // 人の座標
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            cin >> board[i][j];
            if (board[i][j] == '@') {
               sx = i, sy = j;
            }
         }
      }

      visited[sx][sy] = true;
      dfs(sx, sy);

      int ans = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            if (visited[i][j]) ans++;
         }
      }
      cout << ans << endl;

   }

   return 0;
}


Measured memory_bytes: 3004
table = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
check = ->(field, type) {
  table.each do |pat|
    return true if pat.map {|i| field[i] == type}.all?
  end
  false
}
game = ->(field, left) {
  if check.(field, "o")
      "o"
  elsif check.(field, "x")
      "x"
  else
    nxt = (left.size % 2).zero? ? "x" : "o"
    try = proc {|f|
      left.each do |pos|
        table[pos] = nxt
        a = f.()
        return a if a
        table[pos] = "s"
      end
    }
    try.(->{ check.(table, left.reject {|i| i == pos}) })
    try.(->{ game .(table, left.reject {|i| i == pos}) })
    false
  end
}
         
$<.readlines.map(&:chomp).map(&:chars).each do |field|
  left = field.map {|i| i == "s" ? i : nil}.compact
  result = game.(field, left)
  puts result ? result : "d"
end


Measured memory_bytes: 8900
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 998244353
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll k, n;
		vector<pair<ll, ll>> len;
		cin >> n >> k;
		for (int i = 0; i < k; i++) {
			int a, b;
			cin >> a >> b;
			len.pb(mk(a, b));
		}
		ll arr[2 * n + 10] = {0}, ans = 0;
		arr[1] = 1;
		for (int i = 1; i <=  n; i++) {
			ans += arr[i];
			ans %= mod;
			for (int j = 0; j < k; j++) {
				arr[i + len[j].ff] += ans;
				arr[i + len[j].ss + 1] -= ans;
				if (arr[i + len[j].ss + 1] < 0) arr[i + len[j].ss + 1] += mod;
			}
		}
		ans = arr[n] % mod;
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 6752
/*input
1
2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b; cin >> a >> b;
    cout << 6 - a - b;

    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        Arrays.sort(s);
        String ss = new String(s);
        Arrays.sort(t);
        String tt = new String(t);
        tt = new StringBuilder(tt).reverse().toString();
        if(ss.compareTo(tt) < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35620
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int a,b;cin>>a>>b;
    string ans;
    if(a>0){
        ans="Positive";
    }
    else if(a==0){
        ans="Zero";
    }
    else{
        if(b>=0)ans="Zero";
        else{
            int kosuu=b-a+1;
            if(kosuu%2==1)ans="Negative";
            else ans="Positive";
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include<stdio.h>

int main(){
  int i, j, n, tmp, flug=1, cnt=0;
  int A[100];

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

  while(flug){
    flug = 0;
    for(j=n-1; j>0; j--){
      if(A[j] < A[j-1]){
	tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;
	cnt++;
	flug = 1;
      }
    }
  }
  
  for(i=0; i<n-1; i++){
    printf("%d ", A[i]);
  } printf("%d\n", A[i]);
  printf("%d\n", cnt);
  return 0;
}



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

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

ll n, in[114514], s[2] = { 1,-1 }, a[2] = {},x[2][114514];
int main() {
	cin >> n;
	REP(i, n) cin >> in[i];
	REP(k, 2) {
		REP(i, n) {
			if (s[k] > 0) {
				if (x[k][i] + in[i] < 1) {
					a[k] += 1 - (x[k][i] + in[i]);
					x[k][i + 1] = 1;
				}
				else x[k][i + 1] = x[k][i] + in[i];
			}
			else {
				if (x[k][i] + in[i] >= 0) {
					a[k] += 1 + (x[k][i] + in[i]);
					x[k][i + 1] = -1;
				}
				else x[k][i + 1] = x[k][i] + in[i];
			}
			s[k] *= -1;
		}
	}
	cout << min(a[0], a[1]) << endl;
}
	


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 200020
#define d_flag 0


char s[MAX+1];
char t[MAX+1];



int main(){

  scanf(" %s",s);
  int len=strlen(s);
  int i,j=0;
  for(i=0;i<len;){
    if(s[i]!='B'){
      t[j++]=s[i++];
      continue;
    }
    if(s[i+1]=='C'){
      t[j++]='D';
      i+=2;
      continue;
    }
    t[j++]=s[i++];
  }

  if(d_flag)printf("%s\n",t);
long int count=0,sum=0;
  for(i=0;i<j;i++){
    if(t[i]=='A')count++;
    else if(t[i]=='D') sum+=count;
    else count=0;
  }

  printf("%ld",sum);
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n;
int a[maxx];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	printf("%d\n", a[n / 2 + 1] - a[n / 2]);
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main() {
    int x, y;
    cin >> x >> y;
 
    if(x%y == 0) {
        cout << -1;
    }
    else {
        cout << x;
    }
 
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

long long a,b,c,d,e,i,j,k=0,l=0;
pair<long long,long long>p;
vector<pair<long long,long long> >v;
cin>>a>>b;
for(i=1;i<=a;i++)
{
 cin>>c>>d;
p.first=c;
p.second=d;
v.push_back(p);

}
sort(v.begin(),v.end());
for(i=0;i<v.size();i++)
{l+=v[i].second;
if(l>=b&&k==0){c=v[i].first;k=1;}

}
cout<<c<<endl;
}

Measured memory_bytes: 2420
n,k=map(int,input().split())
n_list = n
p = 0
c = 0
while k > 0.5 :
    num = max(int(n_list-k+1),0)
    if num:
        p += num * (0.5**c)
        n_list = int(k) - int(1 - ( k - int(k)))
    k /= 2
    c += 1
print( p / n )

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        for(;;){
                int a,b;
                char op;
                scanf("%d %c %d",&a,&op,&b);
                if(op=='?'){
                        break;
                }else{
                        if(op=='+'){
                                printf("%d\n",a+b);
                        }else if(op=='-'){
                                printf("%d\n",a-b);
                        }else if(op=='*'){
                                printf("%d\n",a*b);
                        }else{
                                printf("%d\n",a/b);
                        }
                }
        }
        return 0;
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          Console.WriteLine(a[1]%a[0]==0 ? a[0]+a[1]:a[1]-a[0]);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
#![allow(non_snake_case, unused_imports)]

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

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque,BinaryHeap};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        A: [usize; N],
        B: [usize; N],
        C: [usize; N-1],
    }
    let mut ans = 0;
    for i in 0..N{
        ans += B[i];
    }
    for i in 0..N-1{
        if A[i]+1 == A[i+1]{
            ans += C[A[i]-1];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring> 
#include <algorithm>
#include <map>
using namespace std;

namespace IO{
    const int insiz = 1 << 12, outsiz = 1 << 18;
    char in[insiz], *A(in), *B(in); char out[outsiz], *ptr(out);
    inline char getc(){
    	#ifndef LOCAL
        return (A == B) && (B = (A = in) + fread(in, 1, insiz, stdin), A == B) ? EOF : *A++;
        #endif
        return getchar();
    }
    template <typename T> inline T read(){
        T ret(0), p(1); char ch(getc());
        while(ch < '0' || ch > '9'){
            if(ch == '-') p = -1; ch = getc();
        }
        while(ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getc();
        return ret*p;
    }
    inline void flush(){ fwrite(out, 1, ptr - out, stdout); ptr = out; }
    template <typename T> inline void write(T x, char cmd = '\n'){
        if(x < 0) *ptr++ = '-', x = -x;
        if(x == 0) *ptr++ = '0';
        static char s[123]; int cnt = 0;
        for(; x; x /= 10) s[++cnt] = x % 10 + '0';
        for(; cnt; --cnt) *ptr++ = s[cnt];
        *ptr++ = cmd;
        if((outsiz >> 1) > ptr - out) flush();
    }
} using IO::getc; using IO::read; using IO::write; using IO::flush;

typedef long long ll; 

map<pair<ll, ll>, int> mp;
ll x[112], y[112], n;

bool asked[112];

inline int pd(ll lx, ll ly){
	memset(asked, 0, sizeof(asked));
	int ret(0);
	for(int i(1); i <= n; ++i){
		if(asked[i]) continue;
		++ret; asked[i] = true;
		ll nx = x[i] + lx, ny = y[i] + ly;
		while(mp.count(make_pair(nx, ny))){
			asked[mp[make_pair(nx, ny)]] = true;
			nx += lx, ny += ly;
		}
		nx = x[i] - lx, ny = y[i] - ly;
		while(mp.count(make_pair(nx, ny))){
			asked[mp[make_pair(nx, ny)]] = true;
			nx -= lx, ny -= ly;
		}
	}
	return ret;
}

int main(){
	n = read<int>();
	for(int i(1); i <= n; ++i){
		x[i] = read<ll>(), y[i] = read<ll>();
		mp[make_pair(x[i], y[i])] = i;
	}
	int ans(10000000);
	for(int i(1); i < n; ++i){
		for(int j(i + 1); j <= n; ++j){
			ans = min(ans, pd(x[i] - x[j], y[i] - y[j]));
		}
	}
	if(n == 1) ans = 1;
	write(ans);
	flush(); return 0;
}




Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res
 
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
 
    if n == 0:
        return 1
 
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
 
    return K * x
def main():  #startline-------------------------------------------
    print("ACL"*int(input()))

if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 38952
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    int cnt = 0;
    for ( int i = a; i <= b; i++ ) {
        if ( c % i == 0) cnt++;
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
int a[100001];

int main() {
	// 최대유량, 앳코더, (종만북(?) 생각) - 기하 잘하고 싶다!
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, k; cin >> n >> k;
	int cnt = 10000000;
	int idx = -1;
	rep(i, n) {
		int x;
		cin >> x;
		if (cnt > x) {
			cnt = x; idx = i;
		}
	}
	int left = idx;
	int right = n - idx - 1;
	k -= 1;

	if (left % k == 0 || right % k == 0) {
		cout << (int)ceil((double)left / k) + (int)ceil((double)right / k) << '\n';
	}
	else {
		int dist = right % k;
		right -= dist;
		left -= (k - dist);
		cout << (int)ceil((double)left / k) + (int)ceil((double)right / k) + 1 << '\n';
	}


}


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

vector<int> par;
vector<int> RA;

void Re(int a){
  par.resize(a);
  RA.resize(a);
  for(int i=0;i<a;i++){
    par[i]=i;
  }
}
int root(int a){
  if(a==par[a]){
    return a;
  }
  else{
    return par[a]=root(par[a]);
  }
}
void UN(int a,int b){
  a=root(a);
  b=root(b);
  if(a==b){
    return;
  }
  else if(RA[a]<RA[b]){
    par[a]=b;
  }
  else{
    par[b]=a;
  }
  if(RA[a]==RA[b]){
    RA[a]++;
  }
}
bool same(int a,int b){
  if(root(a)==root(b)){
    return true;
  }
  else{
    return false;
  }
}

int main() {
  int N,M;
  cin>>N>>M;
  int Z=N-1;
  Re(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    if(same(a,b)){
      continue;
    }
    Z--;
    UN(a,b);
  }
  cout<<Z<<endl;
}

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


int main()
{
    int n,W;
    cin>>n>>W;
    int val[n+5],wt[n+5];
    int sum=0;
    for(int i=0; i<n; i++){
        cin>>wt[i]>>val[i];
        sum+=val[i];
    }
    int dp[n+5][sum+5];
    for(int i=0;i<=n;i++) {
        for(int j=0;j<=sum;j++) {
            if(i==0 && j==0) dp[i][j]=0;
            else if(i==0) dp[i][j]=1e9;
            else if(val[i-1]<=j) dp[i][j]=min(wt[i-1]+dp[i-1][j-val[i-1]],dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];

        }
    }
    int idx=0;
    for(int i=0;i<=sum;i++) {
        if(dp[n][i]<=W)idx=i;
    }
    cout<<idx<<endl;





    return 0;
}


Measured memory_bytes: 42976
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool used[400][400] = {};
lli h,w;
void dfs(int y, int x, char bw, lli &bl, lli &wh, vector<string> &field){
	if(used[y][x]) return;
	used[y][x] = true;
	if(field[y][x] == '.') wh++;
	else bl++;
	for(int d=0; d<4; d++){
		int ny = y+dy[d];
		int nx = x+dx[d];
		if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
		if(field[y][x] == field[ny][nx]) continue;
		dfs(ny, nx, field[y][x], bl, wh, field);
	}
}

int main(){
	cin >> h >> w;
	vector<string> field(h);
	for(int i=0; i<h; i++){
		cin >> field[i];
	}
	lli ans = 0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			lli bl=0, wh=0;
			dfs(i, j, 0, bl, wh, field);
			ans += bl*wh;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 20608
n=gets.to_i
s=gets.chomp
maxCount = 0
(1..(n-1)).each do |index|
  xIndex = index
  xString = s.slice(0,xIndex).split("").uniq
  yString = s.slice(xIndex,s.length-xIndex).split("").uniq
  tempMaxCount = 0
  xString.each do |x|
  	tempMaxCount += 1 if yString.include?(x)
  end
  maxCount = tempMaxCount if tempMaxCount > maxCount
end
puts maxCount

Measured memory_bytes: 1788
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include <unistd.h>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Buffer{
    int idx;
    char buf[1025];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, 1024); }
    void check(){ if(idx == 1024){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};

ll cs[10][10];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    Buffer buf;
    int h = buf.next(), w = buf.next();
    // vector<vector<short>> cs(10, vector<short>(10));
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cs[i][j] = buf.next();
        }
    }
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                cs[j][k] = min((ll)cs[j][k], cs[j][i] + cs[i][k]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int a = buf.next();
            prints(a);
            if(a != -1){
                ans += cs[a][1];
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
S = input()
N= len(S)
S1=S[:(N-1)//2]
S2=S[(N+1)//2:]

def solve(s):
    if s == s[::-1]:
        return True
    return False

if solve(S) and solve(S1) and solve(S2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long d[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &d[i]);
  }
  long m;
  scanf("%ld", &m);
  long t[m];
  for (long i = 0; i < m; i++) {
    scanf("%ld", &t[i]);
  }
  qsort(d, n, sizeof(long), cmpnum);
  qsort(t, m, sizeof(long), cmpnum);
  int flag;
  long idea = 0;
  for (long i = 0; i < m; i++) {
    if (idea >= n) {
      flag = 0;
      break;
    }
    flag = 1;
    while (1) {
      if (idea >= n) {
        flag = 0;
        break;
      }
      if (d[idea] == t[i]) {
        idea++;
        break;
      } else if (d[idea] < t[i]) {
        idea++;
      } else {
        flag = 0;
        break;
      }
    }
    if (flag == 0) {
      break;
    }
  }
  if (flag == 1) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 4860
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pt = 0
for i in range(N):
    pt += B[A[i]-1]
    if i > 0 and (A[i]-1) == A[i-1]:
        pt += C[A[i-1]-1]
print(str(pt))

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 10000
#define NIL -1
 
struct Node { int p, l, r; };
struct Node T[MAX];
int n;
 
void preparse(int u) {
    if (u == NIL) {
        return;
    }
    printf(" %d", u);
    preparse(T[u].l);
    preparse(T[u].r);
}
 
void inparse(int u) {
    if (u == NIL) {
        return;
    }
    inparse(T[u].l);
    printf(" %d", u);
    inparse(T[u].r);
}
 
void postparse(int u) {
    if (u == NIL) {
        return;
    }
    postparse(T[u].l);
    postparse(T[u].r);
    printf(" %d", u);
}
 
int main(void)
{
    int i, s, l, r, root;
 
    scanf("%d", &n);
 
    for (i = 0;i < n;i++) {
        T[i].p = NIL;
    }
 
    for (i = 0; i < n;i++) {
        scanf("%d %d %d", &s, &l, &r);
        T[s].l = l;
        T[s].r = r;
        if (l != NIL) {
            T[l].p = s;
        }
        if (r != NIL) {
            T[r].p = s;
        }
    }
 
    for (i = 0;i < n;i++) {
        if (T[i].p == NIL) {
            root = i;
        }
    }
 
    printf("Preorder\n");
    preparse(root);
    printf("\n");
    printf("Inorder\n");
    inparse(root);
    printf("\n");
    printf("Postorder\n");
    postparse(root);
    printf("\n");
 
    return 0;
}


Measured memory_bytes: 2100
use std::cmp::{min,max};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        n:usize,
        an:[i64;n],
    }
    let mut left = vec![0;n+1];
    let mut right = vec![0;n+1];
    for j in 0..n { left[j+1] = gcd(left[j],an[j]);}
    for j in (0..n).rev() {  right[j] = gcd(right[j+1],an[j]);}

    let mut ans = 0;
    for j in 0..n{
        let l = left[j];
        let r = right[j+1];
        ans = max(ans,gcd(l,r));
    }
    println!("{}",ans);
}
fn gcd(a:i64,b:i64) -> i64{
    if b == 0 {
        return a;
    }
    if a % b == 0{
        b
    } else {
        gcd(b, a%b)
    }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i=0; i<n; i++)
 
using namespace std;
const double PI = acos(-1);
using Graph = vector<vector<int>>;
 
int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> h(n+1);
	vector<ll> highest(n+1, 1);
	for (int i = 1; i < n+1; i++)
	{
		cin >> h[i];
	}
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		if (h[a] <= h[b])
			highest[a] = 0;
		if (h[b] <= h[a])
			highest[b] = 0;
	}
	int count = 0;
	for (int i = 1; i < n+1; i++)
	{
		count += highest[i];
	}
	cout << count << endl;
}

Measured memory_bytes: 4844
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
	long long sum[200005];
	memset(sum, 0, sizeof(sum));
	int i, n;
	sum[0] = 0;
	scanf("%d", &n);
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	sort(sum , sum + 1  + n);
	long long count = 1;
	long long ans = 0;
	for(i = 1 ; i <= n ; i++)
	{
		if(sum[i] == sum[i - 1])
		{
			count++;
		}
		else
		{
			ans += count * (count - 1) / 2;
			count = 1;
		}
	}
	ans += count * (count - 1) / 2;
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
        cin >> p[i];
    sort(p.begin(), p.end());

    int res = 0;
    for (int i = 1; i <= 100000; i++) {
        int cnt = lower_bound(p.begin(), p.end(), i) - p.begin();
        if (cnt == N / 2) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
Total = []
mod = 10**9+7
c = 0
for i in range(N):
    c += A[i]
    Total.append(c)

ans = 0
for i in range(N):
    k = Total[-1] - Total[i]
    ans += A[i]*k % mod
    ans = ans % mod
print(ans % mod)

Measured memory_bytes: 101628
N = int(input())
ans = 0
count = []
for i in range(10):
    count.append([0] * 10)
for i in range(N+1):
    str_i = str(i)
    if str_i[-1] == "0":
        continue
    else:
        if str_i[-1] == str_i[0]:
            ans += 2*count[int(str_i[0])][int(str_i[-1])] +1
            count[int(str_i[0])][int(str_i[-1])] += 1
        else:
            ans += count[int(str_i[-1])][int(str_i[0])]*2
            count[int(str_i[0])][int(str_i[-1])] += 1
print(ans)

Measured memory_bytes: 41452
import java.util.*;
import java.io.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int n = s.length();
    int m = t.length();
    int[][] dp = new int[n+1][m+1];
    for(int i = 1; i<=n; i++) {
        for(int j = 1; j<=m; j++) {
            if(s.charAt(i-1)==t.charAt(j-1))
                dp[i][j] = dp[i-1][j-1]+1;
            else dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
        }
    }
    StringBuilder sb = new StringBuilder();
    int row = n;
    int col = m;
    while(row>0 && col>0) {
        if(s.charAt(row-1)==t.charAt(col-1)) {
            sb.append(s.charAt(row-1));
            row--;
            col--;
        }
        else {
            if(dp[row-1][col]>dp[row][col-1])
                row--;
            else col--;
        }
    }
    System.out.println(sb.reverse().toString());
  }
}

Measured memory_bytes: 81228
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int a[100000],ans = 0,K;
vi adjList[100000];
int doDFS(int u) {
    int i,m = 0;
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        int c = doDFS(v)+1;
        if ((c >= K) && (u != 0)) ans++;
        else m = max(m,c);
    }
    return m;
}
int main() {
    int i;
    int N;
    scanf("%d %d",&N,&K);
    for (i = 0; i < N; i++) scanf("%d",&a[i]),a[i]--;

    if (a[0] != 0) ans++,a[0] = 0;
    for (i = 1; i < N; i++) adjList[a[i]].pb(i);
    doDFS(0);
    printf("%d\n",ans);

    return 0;
}



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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(ll size) {
        size = max((int) sqrt(size) + 1, 101010);
        prime.resize(size, 1);
        prime[0] = 0;
        prime[1] = 0;
        for (size_t i = 2; i * i <= size; ++i)
            if (prime[i]) {
                for (size_t j = 2; i * j <= size; ++j)prime[i * j] = false;
            }
    }
};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

string s;
ll N, K;

int main() {
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N)cin >> A[i];
    sort(A.begin(), A.end());
    Combination c(2e5);
    ll ma = 0, mi = 0;
    REP(i, N) {
        ll k = c.comb(i, K - 1) % MOD;
        ma += A[i] * k % MOD;
        ma %= MOD;
    }
    reverse(A.begin(), A.end());
    REP(i, N) {
        ll k = c.comb(i, K - 1) % MOD;
        mi += A[i] * k % MOD;
        mi %= MOD;
    }
    cout << (ma - mi) % MOD << endl;
    return 0;
}


Measured memory_bytes: 4096
import sys
sys.setrecursionlimit(10**8)
n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a-=1; b-=1
    g[a].append(b)
    g[b].append(a)

dist = [float('inf')] * n
def dfs(s, p, depth):
    if depth>2: return
    dist[s] = min(dist[s], depth)
    for to in g[s]:
        if to==p: continue
        if dist[to] < dist[s]+1: continue
        dfs(to, s, depth+1)

dfs(0, -1, 0)

if dist[n-1] <= 2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 43364
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

using namespace std;

#define MOD 1000000007

typedef long long lli;

class e {
public:
	int u, v, w;
	e(int u, int v, int w)
		:u(u), v(v), w(w)
	{}
};

bool cmp(const e &i, const e &j) {
	return i.w < j.w;
}

vector<e> a;
vector<int> con[1001], cost[1001];
int n, m, up[1001];
lli x;
int par[11][1001], mx[11][1001], d[1001];
lli p2[2020];

void setlca() {
	for (int h = 1; h < 11; h++) {
		for (int i = 1; i <= n; i++) {
			mx[h][i] = max(mx[h - 1][i], mx[h - 1][par[h - 1][i]]);
			par[h][i] = par[h - 1][par[h - 1][i]];
		}
	}
}

int qry(int u, int v) {
	int ret = 0;
	if (d[u] < d[v]) swap(u, v);
	for (int i = 10; i >= 0; i--) {
		if (d[par[i][u]] >= d[v]) {
			ret = max(ret, mx[i][u]);
			u = par[i][u];
		}
	}
	if (u == v) return ret;
	for (int i = 10; i >= 0; i--) {
		if (par[i][u] != par[i][v]) {
			ret = max(ret, max(mx[i][u], mx[i][v]));
			u = par[i][u];
			v = par[i][v];
		}
	}
	return max(ret, max(mx[0][u], mx[0][v]));
}

void dfs(int pre, int u, int dis = 1) {
	d[u] = dis++;
	for (int i = 0; i < con[u].size(); i++) {
		int v = con[u][i];
		if (pre == v) continue;
		par[0][v] = u;
		mx[0][v] = cost[u][i];
		dfs(u, v, dis);
	}
}

int fd(int u) {
	if (up[u] == 0) return u;
	return up[u] = fd(up[u]);
}

void un(int u, int v) {
	int ru = fd(u), rv = fd(v);
	up[rv] = ru;
}

int main() {
	scanf("%d %d %lld", &n, &m, &x);
	p2[0] = 1;
	for (int i = 1; i < 2020; i++)
		p2[i] = p2[i - 1] * 2 % MOD;
	for (int i = 0; i < m; i++) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		a.push_back(e(u, v, w));
	}
	sort(a.begin(), a.end(), cmp);
	lli sum = 0;
	for (int i = 0; i < a.size(); i++) {
		int u = a[i].u, v = a[i].v, w = a[i].w;
		if (fd(u) != fd(v)) {
			un(u, v);
			con[u].push_back(v);
			cost[u].push_back(w);
			con[v].push_back(u);
			cost[v].push_back(w);
			sum += w;
		}
	}
	if (x < sum) {
		puts("0");
		return 0;
	}
	dfs(-1, 1);
	setlca();
	memset(up, 0, sizeof(up));
	vector<e> rem;
	int cur = 0;
	int c1 = 0, c2 = 0;
	while (cur < a.size()) {
		vector<e> cand;
		cand.push_back(a[cur]);
		while (cur + 1 < a.size() && a[cur + 1].w == a[cur].w) {
			cur++;
			cand.push_back(a[cur]);
		}
		for (int i = 0; i < cand.size(); i++) {
			int u = cand[i].u, v = cand[i].v, w = cand[i].w;
			if (fd(u) == fd(v)) {
				rem.push_back(cand[i]);
				c2++;
			}
			else c1++;
		}
		for (int i = 0; i < cand.size(); i++) {
			int u = cand[i].u, v = cand[i].v, w = cand[i].w;
			if (fd(u) != fd(v)) un(u, v);
		}
		cur++;
	}
	if (x == sum) {
		printf("%lld\n", (p2[m] - p2[c2 + 1] + MOD) % MOD);
		return 0;
	}
	lli res = 0;
	vector<int> added;
	for (int i = 0; i < rem.size(); i++) {
		int u = rem[i].u, v = rem[i].v, w = rem[i].w;
		int add = w - qry(u, v);
		added.push_back(add);
	}
	sort(added.begin(), added.end());
	for (int i = 0; i < added.size(); i++) {
		int w = added[i];
		if (sum + w == x) {
			res += 2 * p2[added.size() - i - 1];
			res %= MOD;
		}
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
 
int fx(int a, int b){
  if(b==0)
    return a;
  else
    return fx(b,a%b); 
}
 
int main(){
  int a, b;
  scanf("%d %d",&a,&b);
  if(a<b)
    printf("%d\n",fx(b,a));
  else
    printf("%d\n",fx(a,b));
  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#include<string.h>
int main(){
  char m[1000],b[2],g[1000][1000],c[2]="-";
  int n,a,i,j,d,f=0;
  while(1){
    scanf("%s",m);
    if(strcmp(m,c)==0){
      break;
    }
    int e=strlen(m);
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&a);
      for(j=0;j<a;j++){
    b[0]=m[0];
    d=1;
    while(d!=e){
      m[d-1]=m[d];
      d++;
    }
    m[e-1]=b[0];
      }
    }
    strcpy(g[f],m);
    f++;
  }
  for(i=0;i<f;i++){
    printf("%s\n",g[i]);
  }
}

Measured memory_bytes: 2612
read n m c
t=0
read s
b=($s)
for i in `seq $n` ; do
	read s
	a=($s)
	s=$c
	for j in `seq $m` ; do
		s=$[s+a[j-1]*b[j-1]]
	done
	t=$[t+(s>0)]
done
echo $t

Measured memory_bytes: 604
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	vi mx(n);
	rep(i, n) cin >> a[i];
	mx[0] = a[0];
	int ans = 0;
	repn(i, 1, n){
		if(a[i] >= mx[i - 1]){
			ans++;
		}
		mx[i] = max(a[i], mx[i - 1]);
	}
	cout << ans + 1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main() {
    int n;
    scanf("%d", &n);
    int s[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &s[i]);
    }

    int q, t, ans = 0;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &t);
        if (*lower_bound(s, s+n, t) == t) {
            ans++;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3092
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int sugar = 0, water = 0;
    double c = 0.0;
    for (int i = 0; i <= 30; ++i)
    {
        if (100 * A * i > F)
            break;
        for (int j = 0; j <= 30; ++j)
        {
            if (100 * A * i + 100 * B * j > F)
                break;

            for (int k = 0; k <= 100; ++k)
            {
                if (100 * A * i + 100 * B * j + C * k > F)
                    break;

                for (int l = 0; l <= 100; ++l)
                {
                    if (100 * A * i + 100 * B * j + C * k + D * l > F)
                        break;

                    if ((A * i + B * j) * E < C * k + D * l)
                        continue;

                    if (c <= (double)(C * k + D * l) * 100 / (C * k + D * l + 100 * A * i + 100 * B * j))
                    {
                        c = (double)(C * k + D * l) * 100 / (C * k + D * l + 100 * A * i + 100 * B * j);
                        sugar = C * k + D * l;
                        water = sugar + 100 * A * i + 100 * B * j;
                    }
                }
            }
        }
    }

    cout << water << " " << sugar << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b;
    cin >> a >> b;
    if(b==1)
    {
        cout << 0;
        return 0;
    }
    int tot=1;
    b-=a;
    while(b>0)
    {
        b-=(a-1);
        tot++;
    }
    cout << tot;

    return 0;
}


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

int main(){
  int A,B;
  cin>>A>>B;
  if(A<=5){
    cout<<0<<endl;
  }
  else if(6<=A&&A<=12){
    cout<<B/2<<endl;
  }
  else{
    cout<<B<<endl;
  }
}

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)

int main() {
    unsigned long long a; cin >> a;
    long double b; cin >> b;
    unsigned long long c;
    c = b * 1000;
    unsigned long long ans = a * c;
    int dig = ans % 1000;
    unsigned long long res = (ans - dig) / 1000;
    cout << res << endl;
}


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

main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    int dp[n+1];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }

    cout<<dp[n];

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  if(s=="Sunny") cout << "Cloudy" << endl;
  else if(s=="Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 256