akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	string s;
	cin >> s;
	if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int w = s.nextInt();
		int n = s.nextInt();
		String[] in = new String[2];
		int[] out = new int[w+1];
		int temp;
		for(int i=0 ; i<=w ; i++)
			out[i] = i;
		for(int i=0 ; i<n ; i++){
			in = s.next().split(",");
			temp = out[Integer.parseInt(in[0])];
			out[Integer.parseInt(in[0])] = out[Integer.parseInt(in[1])];
			out[Integer.parseInt(in[1])] = temp;
		}
		for(int i=1 ; i<=w ; i++)
			System.out.println(out[i]);
    }
}

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

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

	string result;

	for( int i = 0; i < s.size(); ++i ) {
		char ch = s.at( i );

		if( ch == 'B' ) {
			if( !result.empty() ) {
				result.pop_back();
			}
		}
		else {
			result += ch;
		}
	}

	cout << result << endl;
}


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

int main(){ 
    int n;
    int b=0;
    cin >>n;
    vector<int> a(n);
for (int i = 0; i < n; i++) {
  cin >> a.at(i);
}
for(int i=0;i<n;i++){
    if(a.at(i)!=i+1){
        b++;
    }
}
if(b==0||b==2){
    cout <<"YES";
}else{
    cout <<"NO";
}
    return 0;
}


Measured memory_bytes: 256
buf = input()
d = {}
for s in buf:
    if (s in d) == False:
        d[s] = 1
    else:
        d[s] += 1
nums = d.values()
oddExist = False
for num in nums:
    if num % 2 != 0:
        oddExist = True
if oddExist == False:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
using namespace std;

template <typename T>
T power(T x, T p, T mod) {
    T y = 1;
    T tmp = x;
    while (p > 0) {
        if (p % 2 == 1) {
            y = y * tmp % mod;
        }
        tmp = tmp * tmp % mod;
        p >>= 1;
    }
    return y;
}

#include <iostream>
int main() {
    unsigned long long m, n;
    cin >> m >> n;
    cout << power<unsigned long long>(m, n, 1000000007) << endl;
    return 0;
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-
def solve():
    d = dict()
    for _ in range(int(input())):
        s = input()
        d[s] = d.get(s,0)+1
    m = max(d.values())
    return '\n'.join(sorted([k for k,v in d.items() if v == m]))

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 32220
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
int N,K;

int dfs(int n, double depth){
  if(n >= K){
    return depth;
  }else{
    return dfs(n*2, depth + 1);
  }
}

int main(){
  cin >> N >> K;
  int i;
  double ans = 0;
  for(i=0; i<N; i++){
    if(i+1 >= K){
      ans += 1;
    }else{
      ans += (1 / pow(2, dfs(i+1, 0)));
    }
  }
  cout << setprecision(10) << ans / N << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int b[n],c[n];
    for(int i=0;i<n;i++)
    {
        b[i]=(i+1)+a[i];
    //    cout<<b[i]<<" ";
        c[i]=(-a[i]+(i+1));
      //  cout<<c[i]<<endl;
    }

    sort(c,c+n);
    long long ans=0;
    for(int i=0;i<n;i++)
    {
        int l=lower_bound(c,c+n,b[i])-c;
        if(l==n) continue;
        int h=upper_bound(c,c+n,b[i])-c;
        h--;
        ans+=(h-l+1);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5960
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long 
#define int long long 
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define MAX 1e18
#define PI 3.14159265
const int mod = 1e9 + 7;

int power(int x, int y) 
{ 
   int res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  
 
        y = y>>1; 
 
        if (x<=100000000)
        x = (long long)(x*x);
 
        //cout<<x<<'\n'; 
    } 
    return res; 
} 


void solve()
{
    char mx;
    cin>>mx;
    if(mx>=65 and mx<97){
        cout<<"A"<<endl;

    }
    else if(mx>=97 and mx<=122){
        cout<<"a"<<endl;
    }
    return;

}


int32_t main()
{
    IOS;
    solve();
    return 0;
}

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

int main(){
  string O, E;
  cin >> O >> E;
  int o=O.size();
  int e=E.size();
  for(int i=0; i<e; i++){
    cout << O.at(i) << E.at(i);
  }
  if(o!=e){
    cout << O.at(o-1) << endl;
  }
  else{
    cout << endl;
  }
}


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

int main(){
    ll n;
    cin>>n;
    ll minv=1000000000005;
    for(ll i=1;i<=sqrt(n);i++){
        ll j=n/i;
        if(j*i==n) minv=min(minv,i+j-2);
    }
    cout<<minv<<"\n";
    return 0;
}

Measured memory_bytes: 3684
n, m = map(int, input().split())
ans = 1
for i in range(1, int(m ** 0.5) + 1):
    if m % i == 0:
        if i >= n:
            ans = max(ans, m // i)
        elif (m // i) >= n:
            ans = max(ans, i)
print(ans)

Measured memory_bytes: 9368
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a = input()
    b = input()

    if a == b[::-1] and a[::-1] == b:
        print("YES")
    else:
        print("NO")

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

int main()
{
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int ans=0;
	for (int i=0;i<=a;i++)
	 for (int j=0;j<=b;j++)
	  for (int k=0;k<=c;k++)
	  {
	  	ans+=(((i*500)+(j*100)+(k*50))==x);
	  }
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
from itertools import permutations

brackets = [((0, "("), (3, ")")), ((2, "("), (5, ")")), ((4, "("), (7, ")")), 
            ((0, "("), (3, ")"), (4, "("), (7, ")")), ((0, "("), (0, "("), (3, ")"), (5, ")")),
            ((0, "("), (2, "("), (5, ")"), (5, ")")), ((2, "("), (2, "("), (5, ")"), (7, ")")),
            ((2, "("), (4, "("), (7, ")"), (7, ")"))]
ops = []
for op1 in ("+", "-", "*"):
  for op2 in ("+", "-", "*"):
    for op3 in ("+", "-", "*"):
      ops.append((op1, op2, op3))

def check(lst):
  for num_lst in permutations(lst, 4):
    for op_lst in ops:
      for br_lst in brackets:
        new = list(num_lst)
        for i, op in enumerate(reversed(op_lst)):
          new.insert(3 - i, op)
        for ind, br in reversed(br_lst):
          new.insert(ind, br)
        exp = "".join(new)
        if eval(exp) == 10:
          return exp
  return 0
while True:
  lst = list(input().split())
  if lst == ["0", "0", "0", "0"]:
    break
  print(check(lst))



Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  int K, S, count;
  cin>>K>>S;
  
  for(int i = 0; i<=K; i++){
    for(int j = 0; j<=K; j++){
      if(S-(i+j)<=K && S-(i+j)>=0) count ++;
    }
  }
  
  
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start:i64,end:i64,step:i64) -> Vec<i64>{
    let mut ret = Vec::new();
    let mut i = start;

    while i < end{
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS : [i64; 4] = [0,0,1,-1];
#[allow(dead_code)]
const DYS : [i64; 4]  = [1,-1,0,0];
#[allow(dead_code)]
const INF : i64 = 999999999;
#[allow(dead_code)]
const N_PRIME : i64 = 1000000007;

////////////////////////////////////////////////

fn main(){
    let xs = read_ints();
    let (n,l) = (xs[0],xs[1]);

    let xs = (l..l+n).collect::<Vec<i64>>();
    let mut n = xs[0];
    let mut sum = 0;
    for x in xs{
        sum += x;

        //println!("{}",x);
        if x.abs()<n.abs(){
            n=x;
        }
    }
    //println!("{}",n);

    println!("{}",sum-n);
}

Measured memory_bytes: 4352
MOD = 10**9 + 7
N = int(input())
S1 = input().rstrip()
S2 = input().rstrip()
L = len(S1)

if L==1:
    print(3)
    exit()

if S1[0] == S1[1]:
    dp = 6
    start = 2
    state = 0
else:
    dp = 3
    start = 1
    state = 1

i = start
while i<L-1:
    if S1[i] == S1[i+1]:
        if state == 0:
            dp *= 3
            dp %= MOD
        else:
            dp *= 2
            dp %= MOD
        state = 0
        i += 2
    else:
        if state == 1:
            dp *= 2
            dp %= MOD
        state = 1
        i += 1
if state == 1:
    dp *= 2
    dp %= MOD
print(dp)


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

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

    bool G[n][n] = {};
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a][b] = true;
        G[b][a] = true;          
    }

    int A[n - 1];
    for(int i = 1; i < n; i++){
        A[i - 1] = i;
    }

    int cnt = 0;
    do{
        int s = 0, e, f = 1;
        for(int i = 0; i < n - 1; i++){
            e = A[i];
            if(G[s][e]);
            else{
                f = 0;
                break;
            }
            s = A[i];
        }
        if(f) cnt++;
    }while(next_permutation(A, A + n - 1));

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//

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

        int onee = 0, zero = 0;
        for(int i = 0; i < s.size(); i++){
                if(s[i] == '1') onee++;
                if(s[i] == '0') zero++;
        }

        cout << min({onee, zero}) * 2 << endl;
        return 0;
}




























Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
using namespace std;

int findABNum(const string source) {
	int count = 0;
	for (auto pos = source.find("AB"); pos != string::npos;
		pos = source.find("AB", pos + 2)) {
		++count;
	}
	return count;
}

int main()
{
	int n;
	cin >> n;
	vector<string> sls(n);
	for (auto& s : sls)cin >> s;
	
	int res = 0, ba = 0, bTop = 0, aLast = 0; //  B...A, B..., ...A
	for (auto s: sls) {
		res += findABNum(s);
		if (s[0] == 'B') {
			if (s[s.length() - 1] == 'A') {
				ba += 1;
			} else {
				bTop += 1;
			}
		}
		else {
			if (s[s.length() - 1] == 'A') {
				aLast += 1;
			}
		}
	}

	if (ba > 0) {
		if (bTop == 0 && aLast == 0) {
			cout << res + (ba - 1) << endl;
			return 0;
		}
		if (bTop > 0) {
			++res;
			--bTop;
		}
		if (aLast > 0) {
			++res;
			--aLast;
		}
	}
	res += max(0, (ba - 1));
	res += min(bTop, aLast);

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
    string s;
    int ans=10000000,ans2;
    cin >> s;
    for(int i=0;i<s.size()-1;i++){
        
        ans2 = abs( 753 - stoi(( s.substr(i,3)))); //stoiでintに変換substrで
        ans = min(ans,ans2);
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e12;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

const ll mod = 1e9 + 7;

int main(){
    ll N, K; cin >> N >> K;
    vl a(N); REP(i, N) cin >> a[i];
    
    vvl dp(N+1, vl(K+1, 0));
    REP(i, K+1) if(i <= a[0]) dp[1][i] = 1;
    FOR(i, 1, N){
        vl sum(K+2, 0);
        REP(j, K+1) sum[j+1] = (sum[j] + dp[i][j]) % mod;
        REP(l, K+1){
            dp[i+1][l] = (sum[l+1] - sum[max(l-a[i], 0ll)] + mod) % mod;
        }
    }
    cout << dp[N][K] % mod << endl;
    return 0;
}


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

long maximum(long a, long b);

int main(){
	long a, b, c, d;
    long p1,p2,p3,p4;
    long sp1,sp2;
    long p;
	scanf("%ld %ld %ld %ld", &a,&b,&c,&d);

    p1 = a*c;
    p2 = a*d;
    p3 = b*c;
    p4 = b*d;
    //printf("%ld %ld %ld %ld\n",p1,p2,p3,p4);

    sp1=maximum(p1,p2);
    //printf("sp1 %ld\n",sp1);
    sp2=maximum(p3,p4);
    //printf("sp2 %ld\n",sp2);
    p=maximum(sp1,sp2);
    printf("%ld\n",p);

	return 0;
}

long maximum(long a, long b){
    if(a>b) return a ;
    else return b;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end();
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

int N;
int x[8], y[8];

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

  CIN(N);

  vector< int > v;

  for (int i = 0; i < N; i++) {
    CIN(x[i] >> y[i]);
    v.push_back(i);
  }

  double count = 0;
  int pattern = 0;
  do {
    for (int i = 0; i < N - 1; i++) {
      // COUT(x[v[i]] << " " << x[v[i + 1]] << " " << y[v[i]] << " " << y[v[i + 1]] << " r: " << sqrt(pow(x[v[i]] - x[v[i + 1]], 2) + pow(y[v[i]] - y[v[i + 1]], 2)));
      count += sqrt(pow(x[v[i]] - x[v[i + 1]], 2) + pow(y[v[i]] - y[v[i + 1]], 2));
    }
    pattern++;
  } while (next_permutation(v.begin(), v.end()));

  PS(count / pattern);

  return 0;
}


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

int main() {
    ll N; cin >> N;
    ll sum = 0;
    for(ll i=1; i<N; i++){
        sum += i;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;
const int BN = 18;
const int TN = 1<<BN;
ll N, K, A[200000], S[200001], T[TN];
vector<ll> v;
map<ll, ll> mi;
ll getter(int i){
  ll ret = 0, j = i + 1;
  FOR(k, 0, BN + 1){
    if(j & (1 << k)){
      ret += T[((j >> k) << k) - 1];
    }
  }
  return ret;
}
void setter(int i){
  FOR(k, 0, BN){
    if(!(i & (1 << k))){
      T[(((i >> k) + 1) << k) - 1] += 1;
    }
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll d, s = 0, ans = 0;
  cin >> N >> K;
  S[0] = 0;
  v.pb(0);
  FOR(i, 0, N){
    cin >> d;
    d -= K;
    A[i] = d;
    s += d;
    S[i + 1] = s;
    v.pb(s);
  }
  unique(v.begin(), v.end());
  sort(v.begin(), v.end());
  d = 0;
  for(vector<ll>::iterator itr = v.begin(); itr != v.end(); itr++){
    mi[*itr] = d;
    d++;
  }
  FOR(i, 0, N + 1){
    d = mi[S[i]];
    ans += getter(d);
    setter(d);
  }
  cout << ans << endl;
}


Measured memory_bytes: 19056
#define onlycc ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

typedef long long ll;

int n, m;

int main()
{
    onlycc;
    cin >> n >> m;
    dsu d(n+1);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        d.merge(a, b);
    }

    vector<vector<int>> ret = d.groups();
    cout << ret.size()-2;

    return 0;
}


Measured memory_bytes: 8936
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,int> P;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<ll>> dp(2,vector<ll>(n+4));
    dp[0][0] = a[0];
    dp[1][0] = -1*a[0];
    rrep(i,n-1){
        dp[0][i]=max(dp[0][i-1] + a[i], dp[1][i-1]-a[i]);
        dp[1][i]=max(dp[0][i-1] - a[i], dp[1][i-1]+a[i]);
    }
    ll ans = dp[0][n-1];
    // rep(i,n){
    //     cout << dp[0][i] << " ";
    // }cout << endl;
    // rep(i,n){
    //     cout << dp[1][i] << " ";
    // }cout << endl;
    cout << ans <<endl;
    return 0;
}

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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int a, b, n;
	cin >> a >> b >> n;
	cout << (a * min(n, b - 1)) / b - a * (min(n, b - 1) / b) << endl;	
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B;
    cin >> A >> B;

    cout << 98 << " " << 99 << endl;
    for(ll h=1; h<=49; h++){
        for(ll w=1; w<=99; w++){
            if((h%2==0) && (w%2==0) && (A!=1)){
                cout << '.';
                A--;
            }
            else{
                cout << '#';
            }
        }
        cout << endl;
    }

    B--;
    // cout << B << endl;

    for(ll h=1; h<=49; h++){
        for(ll w=1; w<=99; w++){
            if((h%2==0) && (w%2==0) && (B>0)){
                cout << '#';
                B--;
            }
            else{
                cout << '.';
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
typedef long double ld;
  
mt19937 rnd(time(0));
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
// #define int __int128
 
void solve() {
	int n;
	cin >> n;
	pair<ld, ld> a[n];
	for (int i = 0; i < n; ++i)
		cin >> a[i].f >> a[i].s;
	ld dist[n][n];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			dist[i][j] = sqrt((a[i].f - a[j].f) * (a[i].f - a[j].f) + (a[i].s - a[j].s) * (a[i].s - a[j].s));
		}
	}
	// cout << dist[1][2] << endl;
	int b[n];
	ld sum = 0;
	int k = 0;
	for (int i = 0; i < n; ++i)
		b[i] = i;
	do {
		ld sum2 = 0;
		for (int i = 0; i < n - 1; ++i) {
			// cout << b[i] << ' ' << b[(i + n - 1) % n] << endl;
			sum2 += (dist[b[i]][b[(i + n - 1) % n]]);
			sum += (dist[b[i]][b[(i + n - 1) % n]]);
		}
		++k;
		// for (auto &i : b)
			// cout << i << ' ';
		// cout << sum2 << endl;
		// cout << endl;
	} while (next_permutation(b, b + n));
	cout << fixed << setprecision(12) << sum / k << endl;
}
    
signed main() {
    // freopen("cbarn2.in", "r", stdin);
    // freopen("cbarn2.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 256
#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;
typedef pair<int, int> P;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N), c(M), d(M);

    rep(i, N) cin >> a[i] >> b[i];
    rep(i, M) cin >> c[i] >> d[i];

    rep(i, N) {
        int min = 1e9;
        int index;
        rep(j, M) {
            int dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dis < min) {
                min = dis;
                index = j;
            }
        }

        cout << index + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <stack>
#include <tuple>

using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        int in;
        cin >> in;
        a[i] = in - 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) if (a[a[i]] == i) ans++;
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll t1,t2,a1,a2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    ll a=t1*a1;
    ll b=t2*a2;
    ll c=t1*b1;
    ll d=t2*b2;
    ll ans;
    if(a+b>c+d){
        if(c>a){
            ans=2*((c-a)/(a+b-c-d))+1;
            if((c-a)%(a+b-c-d)==0) ans--;
            cout<<ans<<endl;
            return 0;
        }else{
            cout<<0<<endl;
            return 0;
        }
    }else if(a+b<c+d){
        if(a>c){
            ans=2*((a-c)/(c+d-a-b))+1;
            if((a-c)%(c+d-a-b)==0) ans--;
            cout<<ans<<endl;
            return 0;
        }else{
            cout<<0<<endl;
            return 0;
        }
    }else{
        cout<<"infinity"<<endl;
        return 0;
    }

}

Measured memory_bytes: 256
#include <stdio.h>

#include <iostream>
#include <string>
using namespace std;

int main() {
    int A, B, C;

    cin >> A >> B >> C;

    if (A == B) {
        if (B != C) {
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    } else if (B == C) {
        if (A != B) {
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    } else if (C == A) {
        if (B != C) {
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    } else{
            cout << "No" << endl;
            return 0;
    }
}


Measured memory_bytes: 256
N = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
cnt = 1
for i in range(1,N):
    if cnt < 2:
        ans += arr[-1]
        cnt += 1
        if cnt == 2:
            cnt = 0
            arr.pop()
print(ans)

Measured memory_bytes: 94024
void main() {
  problem();
}

void problem() {
  auto H = scan!int;
  auto W = scan!int;
  auto K = scan!int;
  auto MAP = H.iota.map!(x => scan).array;

  long solve() {
    long ans;

    foreach(wx; 0..2^^(W)) {
      auto w = (W+1).iota.map!(b => wx >> b & 1).array;
      foreach(hx; 0..2^^(H)) {
        auto h = (H+1).iota.map!(b => hx >> b & 1).array;

        w.deb;
        h.deb;

        int count;
        foreach(x; 0..W) {
          foreach(y; 0..H) {
            if (w[x] == 0 && h[y] == 0) {
              if (MAP[y][x] == '#') count++;
            }
          }
        }

        if (count == K) ans++;
        count.deb;
      }
      "----".deb;
    }

    return ans;
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 2772
import math
n, h = map(int,input().split())
a,b=0,[]
for i in range(n):
    k,l = map(int,input().split())
    a = max(a,k)
    b.append(l)
b.sort(reverse=True)
cnt=0
idx = 0
while(h>0):
    if idx<len(b) and b[idx]>a:
        h -= b[idx]
        idx += 1
        cnt += 1
    else:
        cnt += math.ceil(h/a)
        h=0
print(cnt)

Measured memory_bytes: 7512
A = int(input())
B = int(input())
C = int(input())
X = int(input())
res = 0
for i in range(A + 1):
  for j in range(B + 1):
    for k in range(C + 1):
      if X == i * 500 + j * 100 + k * 50: res += 1
print(res)

Measured memory_bytes: 39536
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

/*
 * an implementation of https://qiita.com/hamko/items/92660ac5aed9df4d346d
 */
#[derive(Debug, Copy, Clone)]
struct DM {
    d: i64,
    m: i64,
    dm: i64
}

use std::ops;
impl ops::Add<DM> for DM {
    type Output = DM;
    fn add(self, rhs: DM) -> DM {
        DM {
            d: self.d + rhs.d,
            m: self.m + rhs.m,
            dm: self.dm + rhs.dm + self.d * rhs.m
        }
    }
}

impl DM {
    fn from_char(c: char) -> DM {
        match c {
            'D' => DM { d: 1, m: 0, dm: 0 },
            'M' => DM { d: 0, m: 1, dm: 0 },
            _ => DM { d: 0, m: 0, dm: 0 },
        }
    }

    fn inverse(self) -> DM {
        DM {
            d: -self.d,
            m: -self.m,
            dm: -self.dm + self.d * self.m
        }
    }

    fn e() -> DM {
        DM { d: 0, m: 0, dm: 0 }
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let s: String = sc.cin();
    let cs: Vec<_> = s.chars().collect();

    let mut memo = vec![];
    {
        let mut ac = DM::e();
        memo.push(ac);
        for &c in cs.iter() {
            let x = DM::from_char(c);
            ac = ac + x;
            memo.push(ac);
        }
        // trace!(memo);
    }

    let q: usize = sc.cin();
    for _ in 0..q {
        let k: usize = sc.cin();
        let mut ans: u64 = 0;
        for c in 2..n {
            if cs[c] == 'C' {
                if c+1 >= k {
                    let y = memo[c+1-k].inverse() + memo[c];
                    // trace!(c+1-k, c);
                    ans += y.dm as u64;
                } else {
                    let y = memo[c];
                    // trace!(c, y);
                    ans += y.dm as u64;
                }
            }
        }
        put!(ans);
    }
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

int n, m;
int maxl, minr;

int main() {
  cin >> n >> m;
  minr = n;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    maxl = max(maxl, l);
    minr = min(minr, r);
  }
  cout << max(minr - maxl + 1, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	bool flag = true;
	ll ans = 0, tot = 0;
	rep(i, n){
		int ina, inb;
		cin >> ina >> inb;
		if(ina > inb){
			if(ans == 0 || ans > inb){
				ans = inb;
			}
		}
		if(ina != inb) flag = false;
		tot = tot + (ll)ina;
	}
	if(flag == true){
		cout << 0 << endl;
		return 0;
	}
	
	ans = tot - ans;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  int sum = 0;
  cin >> N >> K;
  int x;
  for(int i = 0;i<N;i++){
    cin >> x;
    if(x < K - x){
     sum += 2*x; 
    }else{
     sum +=  2*(K-x);
    }
  }
  
  cout << sum << endl;
}

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

int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(a>b)
    {
        swap(a,b);
    }
    long long mn1=0,mn2=0,mn3=0;
    if(abs(a-b)%2==0)
    {
        mn1=abs(a-b)/2;
        cout<<mn1<<endl;
    }
    else
    {
        mn2=(a-1)+(b-1);
        mn3=(n-a)+(n-b);
        //cout<<mn2<<" "<<mn3<<endl;

        long long mn=min(mn2,mn3);
        if(mn%2==0)
        {
            cout<<mn/2<<endl;
        }
        else
        {
            cout<<(mn/2)+1<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
a, b, c, d = gets.chomp.split(" ").map(&:to_i)
alice_ary = []
bob_ary = []
count = 0
0.upto(99) do |num|
  if num >= a && num <b
    alice_ary[num] = 1
  else
    alice_ary[num] = 0
  end
  if num >= c && num <d
    bob_ary[num] = 1
  else
    bob_ary[num] = 0
  end
  if alice_ary[num] == 1 && bob_ary[num] == 1
    count += 1
  end
end
puts count

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

class Main {
	int n;
	int[] a;
	int[] b;
	final long MOD = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n];
		b = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
		}
		for (int i = 0; i < n; ++i) {
			b[i] = sc.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		long[] c = new long[2 * n];
		for (int i = 0; i < n; ++i) {
			c[2 * i] = 2 * a[i];
			c[2 * i + 1] = 2 * b[i] + 1;
		}
		Arrays.sort(c);
		int out = 0, in = 0;
		long ans = 1;
		for (int i = 0; i < 2 * n; ++i) {
			if (c[i] % 2 == 1) {// outlet
				++out;
			} else {// pc
				++in;
			}
			while (out > 0 && in > 0) {
				ans = ans * Math.max(out, in) % MOD;
				--out;
				--in;
			}
		}
		if (out != 0 || in != 0)
			throw new AssertionError();
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 66660
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;


signed main() {
	int n,k,q;
	cin >> n >> k >> q;
	vector<int> a(n+1,0);
	REP(i,q){
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}
	REP(i,n){
		if(q-a[i+1]>=k){
			cout << "No" << endl;
		}
		else{
			cout << "Yes" << endl;
		}
	}
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL a, b, c, k;

int main() {
	cin >> a >> b >> c >> k;
	
	inc(q, k % 2) {
		LL aa = b + c;
		LL bb = a + c;
		LL cc = a + b;
		a = aa;
		b = bb;
		c = cc;
	}
	
	cout << a - b << endl;
	
	return 0;
}


Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
cnt = 0
sum_ = sum(a)
for ai in a:
  if ai >= 1 / (4 * m) * sum_:
    cnt += 1
if cnt >= m:
  print('Yes')
else:
  print('No')

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

const int mod = 1e9 + 7;


int M[63][maxn][maxn] = {};
int n, k;

void mul(int A[maxn][maxn], int B[maxn][maxn], int C[maxn][maxn]) {
    int ret[maxn][maxn] = {};
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                ret[i][j] += A[i][k] * B[k][j] % mod;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            C[i][j] = ret[i][j] % mod;
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> M[0][i][j];
        }
    }
    for(int i = 1; i < 63; i++) {
        mul(M[i - 1], M[i - 1], M[i]);
    }
    int tmp[maxn][maxn] = {};
    for(int i = 0; i < maxn; i++) {
        tmp[i][i] = 1;
    }
    for(int i = 0; i < 63; i++) {
        if(k & (1LL << i)) {
            mul(tmp, M[i], tmp);
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans = ans + tmp[i][j];
        }
    }
    cout << ans % mod << '\n';
    return 0;
}


Measured memory_bytes: 4912
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    char c;
    cin >> c;

    string vowels = "aiueo";
    if (vowels.find(c) == string::npos) {
        cout << "consonant" << endl;
    } else {
        cout << "vowel" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int n,b=1,j;
    bool flag=false;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(j=0;j<n;j++){
        b=a[b-1];
        if(b==2) {
            flag=true;
            break;
        }
    }
    if(flag==true) cout << j+1 <<endl;
    else cout<< "-1" <<endl;
}


Measured memory_bytes: 768
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{	

public static void main(String[] args) {
		Queue<Integer> time = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quantum = sc.nextInt();
		int timestamp = 0;
		sc.nextLine();
		String p = "";
		int t = 0;
		for (int i =0; i< input; i++) { //////  p1 = p,    500 = t
		  p = sc.next();
		  name.add(p);
		  t = sc.nextInt();
		  time.add(t);

		}
		
		while(!name.isEmpty()) {
			String a = name.poll();
			int ti = time.poll();
			if( ti <= quantum) {
				timestamp += ti;
				System.out.println(a + " " + timestamp);
			
				
			}
			else {
				ti = ti - quantum;
				name.add(a);
				time.add(ti);
				timestamp += quantum;
			}
			
		}
	}
}


Measured memory_bytes: 75944