akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  int ans=inf;
  int subans=0;
  rep(i,s.size()){
    if(i%2==0){
      if(s[i]=='0')subans++;
    }
    else{
      if(s[i]=='1')subans++;
    }
  }
  ans=min(ans,subans);
  subans=0;
    rep(i,s.size()){
    if(i%2==0){
      if(s[i]=='1')subans++;
    }
    else{
      if(s[i]=='0')subans++;
    }
  }
  ans=min(ans,subans);
  cout << ans << endl;
return 0;}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<=i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;
typedef pair<ll,ll> P;

int main(){
  int N,M,ans=0;cin>>N>>M;
  vector<int> X(M),diff(M-1);
  REP(i,0,M){cin>>X[i];}
  sort(all(X));
  REP(i,0,M-1){diff[i]=X[i+1]-X[i];}
  sort(all(diff),greater<>());
  REP(i,N-1,M-1){ans+=diff[i];}
  print(ans)
  
}


Measured memory_bytes: 1024
from networkx import Graph,predecessor
G = Graph()

N,M = map(int,input().split())
rows = [list(map(int,input().split())) for _ in range(M)]

G.add_edges_from(rows)

preds = predecessor(G,source=1)

if len(preds) != N:
    print("No")
    exit()

print("Yes")
for i in range(2,N+1):
    print(preds[i][0])

Measured memory_bytes: 222300
fn main() {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut s: Vec<&str> = buf.split_whitespace().collect();

  let x: i32 = s[0].parse().unwrap();
  let y: i32 = s[1].parse().unwrap();
  let z: i32 = s[2].parse().unwrap();

  let res = (x - z) / (y + z);

  println!("{}",res);

}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=a;i>b;i--)
#define mkp(a,b) make_pair(a,b)
#define all(v) v.begin(),v.end()
using namespace std;
bool compare(pair<int,int>& p1,pair<int,int>& p2)
{
    return p1.second<p2.second;
}
int main()
{
    fastio
    ll n;
    cin>>n;
    vector<ll> v(n);
    ll sum=0;
    REP(i,0,n)
    {
        cin>>v[i];
        if(i!=0)
        {
            sum=sum^v[i];
        }
    }
    vector<ll> ans(n);
    ans[0]=sum;
    ll sumxor=sum^v[0];
    REP(i,1,n)
    {
        ans[i]=sumxor^v[i];
    }
    REP(i,0,n)
        cout<<ans[i]<<" ";
    cout<<"\n";
}

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

char tolow(char s){
    return(s+0x20);
  }

int main(){
  int N,K;
  string S;
  cin >> N;
  cin >> K;
  cin >> S;
  
  S[K-1]=tolow(S[K-1]);
  cout << S;
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s.length() ==2){
        cout << s << endl;
    }else{
        cout << s[2] << s[1] << s[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
int C[1000005];
int G[1000005][26];
int p[1000005];
int cnt[1000005][26];;
int ct = 1;
string st[200005];
ll ans;
bool cmp(string a, string b){
    return a.size() > b.size();
}
int main(){
    int n;
    scanf("%d",&n);
    for (int T = 0; T <n; T++){
        cin >> st[T];
    }
    sort(st,st+n,cmp);
    for (int T = 0; T < n; T++){
        string S = st[T];
        int s = S.size();
        int cur = 1;
        for (int j = s-1; j >= 1; j--){
            int ch = S[j]-'a';
            if (G[cur][ch] == 0){
                G[cur][ch] = ++ct;
                C[ct] = ch;
                p[ct] = cur;
                cur = ct;
            }
            else cur = G[cur][ch];
        }
        int CH = S[0] - 'a';
        ans += cnt[cur][CH];
        int mask = 0;
        cnt[cur][CH]++;
        if (G[cur][CH] == 0){
            G[cur][CH] = ++ct;
            C[ct] = CH;
            p[ct] = cur;
            cur = ct;
        }
        else cur = G[cur][CH];
        for (int i = 0; i < s; i++){
            for (int j = 0; j < 26; j++){
                if (mask & (1<<j)){
                    cnt[cur][j]++;
                }
            }
            mask |= (1<<C[cur]);
            cur = p[cur];
        }
        assert(cur == 1);
        for (int j = 0; j < 26; j++){
            if (mask & (1<<j)){
                cnt[cur][j]++;
            }
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 222100
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define eps 1e-8
//#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod = 998244353;
long double PI = acosl(-1);
const ll infl = 3e18+10;
const int inf = 1e9+10;
const int nmax = 1e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;


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

    map<int,int>mp;
    int n;
    cin>>n;
    ll ans = 0;
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        ans += mp[i-x];
        mp[x+i]++;
    }

    cout<<ans<<endl;
}
/*
3
1 1 0
AB
AC
BC
*/


Measured memory_bytes: 20708
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;

int sum(int s,int e,int a[])
{
    int ans=0;
    for(int i=s;i<=e;i++)
        ans+=a[i];
    return ans;
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[n][n];
    memset(dp,0,sizeof dp);
    for(int i=1;i<n;i++)
    {
        int r=0,c=i;
        while(c<n)
        {
                dp[r][c]=1000000000000000;
                for(int k=r;k<c;k++)
                {
                    dp[r][c]=min(dp[r][c],dp[r][k]+dp[k+1][c]+sum(r,k,a)+sum(k+1,c,a));
                }
            c++;r++;
        }
    }
    cout<<dp[0][n-1];
}



Measured memory_bytes: 1536
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ac=0
bc=0
for i in range(N):
  a,b=A[i],B[i]
  if a>b:
    bc+=a-b
  elif a<b:
    if (b-a)%2==0:
      ac+=(b-a)//2
    else:
      ac+=(b-a)//2+1
      bc+=1
      
if ac>=bc:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 4596
n=int(input())
i=0;j=n-1;ans=0
s=list(input())
while j > i:
    if (s[i]=="W" and s[j]=="R"):
        s[i],s[j]=s[j],s[i]
        j-=1
        i+=1
        ans+=1
    elif s[i]=="W" and s[j]=="W":
        j-=1
    elif s[i]=="R" and s[j]=="R":
        i+=1
    elif s[i]=="R" and s[j]=="W":
        j-=1
        i+=1
print(ans)
        
        


Measured memory_bytes: 82532
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int M,K;
   cin >> M >> K;
   if( M == 1 ){
      if(K==0){
         cout << "0 0 1 1"<<endl;
      }
      else{
         cout <<-1 << endl;
      }
   }
   else{
      if(K==0){
         for(int i=0; i<(1<<M); i++){
            cout <<i <<" " << i <<" " ;
         }
         cout << endl;
      }
      else if( K < (1<<M) ){
         cout << 0 <<" " << K << " " << 0<< " ";
         for(int i = 1 ; i < (1<<M); i++){
            if(i==K) continue;
            else cout <<i << " ";
         }
         cout << K << " ";
         for(int i = (1<<M)-1 ; i >=1 ; i--){
            if(i==K) continue;
            else cout <<i << " ";
         }
         cout << endl;
      }
      else{
         cout <<-1 << endl;
      }
   }
}


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

using ll = long long int;

int main() {
    #ifdef LU_SERIOUS
        freopen( "in.txt", "r", stdin );
    #endif // LU_SERIOUS
    string s1, s2, s3;
    while( cin >> s1 >> s2 >> s3 ) {
        cout << s1[0] << s2[0] << s3[0] << "\n";
    }
    return 0;
}


Measured memory_bytes: 764
n = int(input())

count = 0
m1, m2 = 0, 1
n1, n2 = 0, 0
for i in range(n):
    if i > 0:
        m1, m2 = n1, n2

    n1, n2 = map(int, tuple(input().split()))

    if n1 == n2 and m1 == m2:
        count += 1
    else:
        count = 0

    if count == 2:
        print("Yes")
        exit()


print("No")



Measured memory_bytes: 9180
n=int(input())
h=list(map(int,input().split()))


dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[-1])

Measured memory_bytes: 13928
from collections import deque
S=deque(list(input()))
Q=int(input())
ju=True
for _ in range(Q):
  l=list(input().split())
  if l[0]=="1":
    if ju:
      ju=False
    else:
      ju=True
  else:
    if ju:
      if l[1]=="1":
        S.appendleft(l[2])
      else:
        S.append(l[2])
    else:
      if l[1]=="1":
        S.append(l[2])
      else:
        S.appendleft(l[2])
if ju:
  while S:
    t=S.popleft()
    print(t,end="")
else:
  while S:
    t=S.pop()
    print(t,end="")

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

struct Problem {

    void Solve() {
        string S, P; cin >> S >> P;
        S += S;
        if (S.find(P) != string::npos) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1e9+7;
const int INF=1001001001;

int64_t dp[100005][5][105];
int main() {
  string S;
  int D;
  cin>>S>>D;
  int N=S.size();
  dp[0][0][0]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<D;k++){
        if(dp[i][j][k]==0){continue;}
        int lim=j?9:S[i]-'0';
        for(int d=0;d<lim+1;d++){
          (dp[i+1][j||(d<lim)][(d+k)%D]+=dp[i][j][k])%=mod;
        }
      }
    }
  }
  cout<<(dp[N][0][0]+dp[N][1][0]-1+mod)%mod<<endl;
  return 0;  
}

Measured memory_bytes: 44596
#include <bits/stdc++.h>
using namespace std;
#define lli long long
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    int n=s.size(),i,j;
    i=(n-1)/2;
    string ss=s;
    reverse(ss.begin(),ss.end());
    if(ss!=s)
    {
        cout<<"No"<<endl;
        return 0;
    }
    ss=s.substr(0,i);
    string sss=ss;
    reverse(ss.begin(),ss.end());
    if(ss!=sss)
    {
        cout<<"No"<<endl;
        return 0;
    }
    i = (n+3)/2-1;
    j = n-i;
    ss=s.substr(i,j);
    sss=ss;
    reverse(ss.begin(),ss.end());
    if(ss==sss)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;




}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

template<class T>
class segtree {
	int n;
	vector<T> data;
	T def;
	function<T(T, T)> operation;
	function<T(T, T)> update;
	T _query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return def;
		if (a <= l && r <= b) return data[k];
		T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
		T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
		return operation(c1, c2);
	}
public:
	segtree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
		:def(_def), operation(_operation), update(_update) {
		n = 1;
		while (n < _n) {
			n *= 2;
		}
		data = vector<T>(2 * n - 1, def);
	}
	void change(int i, T x) {
		i += n - 1;
		data[i] = update(data[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
		}
	}
	T query(int a, int b) {
		return _query(a, b, 0, 0, n);
	}
	T operator[](int i) {
		return data[i + n - 1];
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int check = n * (n + 1) / 4 + 1;
	int ng = 0, ok = 1000000001;
	while (ok - ng > 1) {
		int mid = (ng + ok) / 2;
		segtree<int> seg(2 * n + 5, 0, [](int a, int b) {return a + b; }, [](int a, int b) {return a + b; });
		int cnt = 0;
		int p = n + 1;
		seg.change(p, 1);
		rep(i, n) {
			if (a[i] <= mid) p++;
			else p--;
			int c = seg.query(0, p);
			cnt += c;
			seg.change(p, 1);
		}
		if (cnt >= check) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
} 

Measured memory_bytes: 5120
#include <iostream>

using namespace std;
int main()
{
	int n, dig, sum = 0;
	cin >> n;
	int num = n;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	if (num % sum == 0) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
// Volume0-0003	Is it a Right Triangle?
// 2018.3.13

#include <stdio.h>

int main(void){
  int a, b, c;
  int N;

  scanf ("%d\n", &N);
  while(N--){
    scanf("%d %d %d\n", &a, &b, &c);
    if(
       a * a == b * b + c * c ||
       b * b == a * a + c * c ||
       c * c == b * b + a * a
       ) {printf("YES\n");}
    else {printf("NO\n");}
  }
  return 0;
}



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

#define int long long

using namespace std;

int a[100001];
int b[100001];

 main () {
	int n, ans = 0;
	cin >> n;
	int k, t;
	cin >> k >> t;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
	}
	sort (a + 1, a + n + 1);
	int l = 1;
	while (l <= n) {
		int ll = l;
		while (a[l] + t >= a[ll] && ll - l + 1 <= k && ll <= n) {
			ll ++;
		} 
		l = ll;
		ans ++;
	}
	cout << ans;
    return 0;           		
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/
const int N = 128;
int a[N][N];
int b[N][N];
int n, m;

void dfs(int x, int y, int t, int val) {
  if (x > n or y > m or b[x][y] != t) return;
  if (!uin(a[x][y], val)) return;
  dfs(x + 1, y, t, val);
  dfs(x, y + 1, t, val);
}
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  fill_n(a[0], N * N, MOD);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    string s; cin >> s;
    for (int j = 1; j <= m; ++j) {
      b[i][j] = s[j - 1] == '#';
    }
  }
  a[1][0] = a[0][1] = 0;
  for (int x = 1; x <= n; ++x) {
    for (int y = 1; y <= m; ++y) {
      dfs(x, y, b[x][y], b[x][y] + min(a[x - 1][y], a[x][y - 1]));
    }
  }
  kek(a[n][m]);
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

void solve() {
  int a, b, k;
  scan(k, a, b);
  FOR (i, a, b+1) {
    if (i % k == 0) {
      print("OK");
      return;
    }
  }
  print("NG");
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 3172
from bisect import bisect_left

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

if X*Y*Z <= 50000:
  D = sorted([A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z)],reverse=True)
  for i in range(K):
    print(D[i])
  
else:
  A = sorted(A)
  D = sorted([B[i]+C[j] for i in range(Y) for j in range(Z)])

  thr = K
  s = A[-1]+D[max(0,len(D)-thr)]
  prev_idx=0
  selected = [A[-1] + D[i] for i in range(max(0,len(D)-thr),len(D))]
  
  for i in range(1,X):
    r = s - A[-1-i]
    if r<=0:break
    idx = bisect_left(D,r,prev_idx,len(D)-1)
    if idx == len(D):break
    selected.extend([A[-1-i] + D[j] for j in range(idx,len(D))])
    prec_idx = idx

  selected = sorted(selected,reverse=True)

  for i in range(K):
    print(selected[i])

Measured memory_bytes: 340876
#include <iostream>
#include <vector>
#include <cstdio>
float data[8];
const char* noYes[] = {"NO", "YES"};

int intersect (float *a)
{
    int result = 0;
    result += a[0] <= a[6];
    result += a[2] >= a[4];
    result += a[1] <= a[7];
    result += a[3] >= a[5];
    
    return result == 4;
}

int main(int argc, const char * argv[]) {

    std::string line;
    std::vector<std::string> output;
    
    while (std::getline(std::cin, line))
    {
        
        sscanf(line.c_str(), "%f %f %f %f %f %f %f %f",
               &data[0], &data[1], &data[2], &data[3],
               &data[4], &data[5], &data[6], &data[7]);

        output.push_back( noYes[ intersect(data) & 0x01]);

        
    }
    
    std::vector<std::string>::iterator it = output.begin();
   
    do {
        
        std::cout << *it << std::endl;
    } while (++it < output.end());
    
    
    
    return 0;
}

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

using namespace std;


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

	
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}

}


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

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) cin >> b[i];

    ll ans = 0;
    for (int i = 30;i >= 0;--i) {
        ll T = 1 << i;
        for (int j = 0;j < n;++j) b[j] %= T << 1;
        for (int j = 0;j < n;++j) a[j] %= T << 1;
        sort(b.begin(),b.end());
        ll cnt = 0;
        for (int j = 0;j < n;++j) {
            cnt += lower_bound(b.begin(),b.end(),2*T-a[j])-lower_bound(b.begin(),b.end(),T-a[j]);
            cnt += lower_bound(b.begin(),b.end(),4*T-a[j])-lower_bound(b.begin(),b.end(),3*T-a[j]);
        }
        if (cnt%2) ans ^= T;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  long long N,A,B;
  cin >> N >> A >> B;
  
  if (A == 0 && B == 0) {
    cout << 0 << endl;
    return 0;
  }
  
  long long x = N / (A + B);
  long long y = N % (A + B);
  
  if (y >= A) {
    cout << (x + 1) * A << endl;
  } else if (y < A) {
    cout << x * A + y << endl;
  }
}


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

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

Measured memory_bytes: 1408
def getCross point, prepre, pre, current
  (point[pre][0] - point[prepre][0]) * (point[current][1] - point[prepre][1]) - (point[pre][1] - point[prepre][1]) * (point[current][0] - point[prepre][0])
end

#３点の作る折れ線の回転方向を判定する
def areLeft point, upper
  cross = getCross(point, upper[upper.size - 3], upper[upper.size - 2], upper[upper.size - 1])
  (cross >= 0)? true : false 
end

#凸包生成
def convexHull point
  return point if point.size == 3

  #上側は左端から
  upper = [0, 1]
  2.upto(point.size - 1) do |i|
    upper << i
    while upper.size >= 3 && areLeft(point, upper)
      upper.delete_at(upper.size - 2)
    end
  end

  #下側は右端から
  lower = [point.size - 1, point.size - 2]
  (point.size - 3).downto(0) do |i|
    lower << i
    while lower.size >= 3 && areLeft(point, lower)
      lower.delete_at(lower.size - 2)
    end
  end

  #左端と右端の重複を排除
  upper.pop
  lower.pop

  hull = upper + lower
end

until (n = $stdin.gets.to_i) == 0
  point = Array.new
  n.times do
    point << $stdin.gets.chomp.split(",").map(&:to_f)
  end
  #事前準備としてx軸について座標をソート。x同軸についてはy軸ソート
  point.sort!{|a,b| 
    if a[0] == b[0]
      a[1] <=> b[1]
    else
      a[0] <=> b[0]
  end}

  p point.size - convexHull(point).size
end

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    int N, count4 = 0, count2 = 0, count1 = 0;
    cin >> N;
    vint a(N);
    rep(i, N)
    {
        cin >> a[i];
        if (a[i] % 4 == 0)
            count4++;
        else if (a[i] % 2 == 0)
        {
            count2++;
        }
        else
        {
            count1++;
        }
    }
    string ans;
    if(count4>=count1 or (count1 == count4+1 and N%2 == 1))
    {
        ans = "Yes";

    }
    else
    {
        ans = "No";

    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;



int main(){
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    int now = q.top();
    q.pop();
    q.push(now/2);
  }
  ll ans = 0;
  rep(i, n) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 892
from scipy.optimize import fmin
I=input
n=int(I())
L=[list(map(int,I().split()))for i in range(n)]
def C(t):i,j=t;return max((x-i)**2+(y-j)**2for x,y in L)
x,y=fmin(C,(500,500),disp=0)
print(C((x,y))**.5)

Measured memory_bytes: 49644
package main

import (
	"fmt"
)

func main() {
	const t string = "keyence"
	var s string
	fmt.Scan(&s)
	ans := "NO"
	n := len(s) - len(t)            // n文字取り除く必要がある
	for i := 0; i+n < len(s); i++ { // i文字目から連続してn文字取り除いた文字列を作り、"keyence"と比較する
		ts := s[0:i] + s[i+n:len(s)]
		if ts == t {
			ans = "YES"
			break
		}
	}
	fmt.Println(ans)
}


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

struct info{
	string name;
	int score,id;
}a[105];


int n;

bool cmp(const info &x, const info &y) 
{
	if(x.name < y.name) return true;
		else if(x.name==y.name && x.score > y.score) return true;
		else return false;
}
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i].name >> a[i].score;
		a[i].id = i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i = 1; i <= n; i++) cout << a[i].id << endl;
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  int cnt = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'o') {
      cnt++;
    }
  }
  cout << 700 + 100 * cnt;
}

Measured memory_bytes: 256
import re

S = input()
Sa = S.replace("?", "a")
Sd = S.replace("?", ".")
T = input()

word_L = []
for i in range(len(S)-len(T)+1):
  if re.match(Sd[i:i+len(T)], T) is not None:
    s = Sa[:i] + T + Sa[i+len(T):]
    word_L.append(s)

ans = "UNRESTORABLE"
if word_L:
  ans = sorted(word_L)[0]
print(ans)  
  

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
int a, b;

int main(){
	IOS
	cin >> a >> b;
	cout << a*b << '\n';
}


Measured memory_bytes: 3560
#include <stdio.h>
int main(){
char Stat1, Stat2, Stat3;
scanf("%c %c %c",&Stat1, &Stat2, &Stat3);
if((Stat1 == Stat2 && Stat1 == Stat3 && Stat2 == Stat3)||(Stat1 != Stat2 && Stat1!= Stat3 && Stat2 != Stat3)){
	printf("No");
}
else{
	printf("Yes");
}
return 0;
}

Measured memory_bytes: 1684
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define lint long long
#define ll long long
static const int INF = 1 << 22;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/*******source code below********/
int main(void) {

	int N;
	cin >> N;
	vector<int> b(N);
	for (int i = 0; i < N; i++) {
		cin >> b.at(i);
	}
	vector<int> ans;
	while (!b.empty()) {
		bool check = false;
		for (int i = b.size() - 1; i >= 0; i--) {
			if (b[i] == i + 1) {
				ans.push_back(i + 1);
				b.erase(b.begin() + i);
				check = true;
				break;
			}
		}
		if (!check) {
			cout << "-1" << endl;
			return 0;
		}
	}
	reverse(all(ans));
	for (int i = 0; i < N; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
ans=float("INF")
s=list(input())
t=list(input())
s_len=len(s)
t_len=len(t)

for i in range(s_len-t_len+1):
  cnt=0
  for j in range(t_len):
    if t[j]!=s[i+j]:
      cnt+=1
  ans=min(ans,cnt)
print(ans)
   
  
  
  

Measured memory_bytes: 9116
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <numeric>
#include <queue>
#include <stack>

using namespace std;
using ll = long long;

int main() {

	ll ans = 1, eng[27] = {0};
	string s;

	cin >> s;

	for(int i = 0;i<s.length();i++){
		eng[s[i] - 'a']++;
	}


	for (int i = 0; i < 26; i++) {
		for (int j = i + 1; j < 27; j++) {
			ans += eng[i] * eng[j];
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define ALL(v) (v).begin(), (v).end()
//cout << std::fixed << std::setprecision(15) << y << endl;
ll INF=1e18+5;

ll gcd(ll a, ll b){
// 結合法則も成り立つ
  if(a < b) return gcd(b, a);
  ll r = a % b;
  while(r != 0){
      a = b;
      b = r;
      r = a % b;
  }
  return b;
}

int main(){
  ll N, X;  cin >> N >> X;
  VL x(N);  
  rep(i,0,N){
    cin >> x[i];
    x[i] = abs(X - x[i]);
  }
  sort(ALL(x));

  ll ans = INF;
  if(N == 1) ans = x[0];
  else{
    rep(i,1,N){
      ans = min(ans, gcd(x[i-1], x[i]));   
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4008
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	vector<ll> v(k);
	rep(i, k) cin >> v[i];
	while (1) {
		vector<ll> v2;
		ll n2 = n;
		while (n2 > 0) {
			v2.emplace_back(n2 % 10);
			n2 /= 10;
		}
		bool flag = true;
		for(auto a:v)
			for (auto b : v2)
				if (a == b) {
					flag = false;
					break;
				}
		if (flag) break;
		n++;
	}
	cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 2019
typedef long long ll;

using namespace std;

string s;

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

    ll ans = 0;
    int suf = 0;
    int pot = 1;
    cin >> s;
    int n = s.length();
    vector<ll> suf_count(MOD);
    suf_count[0]++;

    for(int i=n-1; i>=0; i--)
    {
        int digit = s[i] - '0';
        suf = (suf + digit*pot) % MOD;
        pot = (pot*10) % MOD;
        ans += suf_count[suf];
        suf_count[suf]++;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3744
from collections import Counter

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    exit()
c=Counter(d)
c=sorted(c.items(),key=lambda x:x[0])
if c[0]!=(0,1):
    print(0)
    exit()
ans=1
check=1
for i in range(1,len(c)):
    if c[i][0]!=check:
        print(0)
        exit()
    check+=1
    ans*=c[i-1][1]**c[i][1]
    ans%=998244353
print(ans%998244353)

Measured memory_bytes: 21980
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



template <class T>
class BIT
{
    std::vector<T> array;
    const long long n;

public:
    BIT(long long n)
        : array(n+1, 0), n(n) {}

    T sum(long long i)
    {
        T sm = 0;
        while(i) {
            sm += array[i];
            i -= i & -i;
        }
        return sm;
    }

    T sum(long long i, long long j)
    {
        return sum(j) - sum(i-1);
    }

    void add(long long i, T new_el)
    {
        while (i <= n) {
            array[i] += new_el;
            i += i & -i;
        }
    }
};


int main()
{
    ll n, q;
    cin >> n >> q;
    BIT<ll> bit(n);
    rep(i, 0, q) {
        ll com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            bit.add(x, y);
        } else {
            cout << bit.sum(x, y) << endl;
        }
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    string S;
    while (cin >> S) {
        bool ok = false;
        for (int i = 0; i+1 < S.size(); ++i) {
            if (S.substr(i, 2) == "AC") ok = true;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


















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

int main() {
  int n;
  cin >> n;
  set<int> a;
  rep(i,n) {
    int x;
    cin >> x;
    if(a.count(x)) {
      cout << "NO" << endl;
      return 0;
    }
    a.insert(x);
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){

    int o[32];
    for( int i = 0 ; i < n ; i++ ){
      cin >> o[i];
    }

    int num = 32;
    int I = 0;

    while(num){
      num -= (num - 1) % 5;
      cout << num << endl;
      num -= o[(I++) % n];
      if(num < 0) num = 0;
      cout << num << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
table1 = {" ":"101", "'":"000000", ",":"000011", "-":"10010001", ".":"010001", "?":"000001",
        "A":"100101", "B":"10011010", "C":"0101", "D":"0001", "E":"110",
        "F":"01001", "G":"10011011", "H":"010000", "I":"0111", "J":"10011000",
        "K":"0110", "L":"00100", "M":"10011001", "N":"10011110", "O":"00101",
        "P":"111", "Q":"10011111", "R":"1000", "S":"00110", "T":"00111",
        "U":"10011100", "V":"10011101", "W":"000010", "X":"10010010", "Y":"10010011", "Z":"10010000"}

table2 = {"00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E",
        "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J",
        "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O",
        "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T",
        "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y",
        "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-",
        "11110":"'", "11111":"?"}

def convert1(str):
  convert = ""
  for s in str:
    convert += table1[s]
  return convert

def convert2(str):
  convert = ""
  index = 0
  
  while index + 5 < len(str):
    convert += table2[str[index:index + 5]]
    index += 5
  # 末尾は0で埋めてある
  if str[index:]:
    convert += table2[str[index:] + "0" * (5 - len(str) + index)]
  
  return convert

while True:
  try:
    s = input()
    c1 = convert1(s)
    c2 = convert2(c1)
    print(c2)
  except:
    break


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

int main(){
  int i, n;
  cin >> n;
  int count = -1;
  for(i = 0; i < n; i++){
    int a;
    cin >> a;
    int x = 0;
    while(a%2 == 0){
      x++;
      a /= 2;
    }
    if(count < 0 || count > x){count = x;}
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[123456];
vector<int>g[123456];
int n,e;
int ans=0;
void make()
{
    cin >> n >>e;
    for(int i=0;i<e;i++)
    {
        int x,y;
        cin >> x >> y;
        --x;--y;
        g[x].push_back(y);
    }
}

int ok(int v)
{
    if(!dp[v])
    {
        for(auto it:g[v])
            dp[v] = max(dp[v],ok(it));
        dp[v]++;
    }
    return dp[v];
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
   make();
   for(int i=0;i<n;i++)
   {
       if(dp[i]==0)
       {
           ans= max(ans,ok(i));
       }
   }
   cout<<ans-1<<"\n";

}

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

class union_find {
public:
  vector<unsigned int> par, rank;
  union_find(unsigned int n) {
    for(unsigned int i = 0; i < n; i++){
      par.push_back(i);
      rank.push_back(0);
    }
  }
  unsigned int root(unsigned int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }
  bool same(unsigned int x, unsigned int y){
    return root(x) == root(y);
  }
  void unite(unsigned int x, unsigned int y){
    x = root(x);
    y = root(y);
    if (x == y){return;}
    if (rank[x] < rank[y]){
      par[x] = y;
    }
    else {
      par[y] = x;
      if (rank[x] < rank[y]){
        rank[x]++;
      }
    }
  }
};

int main(){
  int ans = 0;
  INT(n); INT(m); VI(ps, n);
  union_find uf(n + 1);
  REP(m){
    INT(x); INT(y);
    uf.unite(x, y);
  }
  map<int, int> mp0;
  map<int, set<int>> mp1;
  REP(i, 1, n + 1){
    int r = uf.root(i);
    if (mp0.count(r)){
      mp0[r]++;
    } else {
      mp0[r] = 1;
    }
    mp1[r].insert(i);
    mp1[r].insert(ps[i - 1]);
  }
  FOR(it, mp0){
    int r = it->first;
    ans += 2 * it->second - SZ(mp1[r]);
  }
  printf("%d\n", ans);
  return 0;
}

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

int main()
{
	long long int a, b, c,d,p,q,r,s;
	cin>>a>>b>>c>>d;
  
  p= a*c;
  q=a*d;
  r=b*c;
  s=b*d;
  
  
  long long int maxi =0;
  maxi= max(p,q);
  maxi= max(maxi,r);
  maxi= max(maxi,s);
  
  cout<<maxi;
  
  
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()


int main()
{

    int r;
    cin >> r;
    cout << 3.14159 * 2 *r << endl;




    return 0;
}


Measured memory_bytes: 3788
object Main extends App {
	val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val A = temp(0)
	val B = temp(1)
	val C = temp(2)
	val D = temp(3)

	def max(x: Int, y: Int): Int = {
		if(x < y) return y
		else x
	}

	def min(x: Int, y: Int): Int = {
		if(x < y) return x
		else y
	}

	val re = min(B,D) - max(A,C)

	if(re<0) println(0)
	else println(re)
}


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

int main() {
    int N;
    cin >> N;
    vector <int> A(N);
    for (int i=0; i<N; i++) cin >> A.at(i);
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    int Alice=0, Bob=0;
    for (int i=0; i<N; i++){
        if (i%2==0) Alice+=A.at(i);
        else Bob+=A.at(i);
    }
    cout << Alice-Bob << endl;
}


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

int main() {
  int N, T, A;
  cin >> N;
  cin >> T >> A;

  double min_h = -1;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    double diff = abs(A - (T - h * 0.006));
    if (min_h == -1) {
      min_h = diff;
    } else {
      if (diff < min_h) {
        min_h = diff;
        ans = i;
      }
    }
  }

  cout << ans + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair
typedef long long ll;
typedef string str;


// 文字列sをランレングス圧縮し, 結果のpair-vectorを返す;
// pair : pair.first = 文字 : char, pair.second = 出現回数 : int
// 計算量 O(|S|)
vector<pair<char, int>> run_length(const str &s) {
    vector<pair<char, int>> res;

    // 前の文字列と比較するため, 1からスタートする.
    REP(i, s.length()) {
        int cnt = 1;

        // 前の文字と等しかったら等しい間だけカウントを続け, iも進める.
        // ※ s[i] == s[i + 1] としている理由は, s[i - 1] == s[i] とすると,
        //   sの末尾1文字のみが長さ位置のランレングスだった場合に,
        //   独立してif文で処理を書く必要が出てくるため, こちらの比較を採用.
        while(i + 1 < s.length() && s[i] == s[i + 1]) {
            cnt++;
            i++;
        }
        res.push_back(MP(s[i], cnt));
    }
    return res;
}


#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
// AtCoder ABC 143 C Slimes
// URL: https://atcoder.jp/contests/abc143/tasks/abc143_c
int main() {
    int n;
    cin >> n;
    str s;
    cin >> s;
    auto v = run_length(s);
    
    for(auto i : v) {
        DBG(i.first);
        DBG(i.second);
    }

    cout << v.size() << "\n";
    return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()


int main(){
  ll n,m; cin >> n >> m;
  vector<vector<ll>> x(3, vector<ll>(n));
  REP(i,n) REP(j,3) cin >> x[j][i]; 

  ll ans = -1e18;
  REP(i,8){
    vector<ll> s(3);
    REP(j,3) s[j] = (i & (1<<j)) ? 1 : -1;
    vector<ll> v(n,0);
    REP(j, n) REP(k,3) v[j] += s[k] * x[k][j];  
    sort(ALL(v));
    reverse(ALL(v));
    ll sum = 0;
    REP(j,m) sum += v[j];
    ans = max(ans,sum);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256