akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];
    long long ans = 0;

    for(int i=0; i<=60; i++){
        long long one = 0;
        long long zero = 0;
        REP(j, N){
            if(A[j]&(1LL<<i)){
                one++;
            }else{
                zero++;
            }
        }
        long long tmp = ((1LL<<i) % MOD * one) % MOD;
        tmp = (tmp * zero) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#define SIZE 100005
#define MX 20
#define BT (1<<16)+5

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int A[SIZE];
int dp[BT],rv[MX];
int nw[BT];
int nm[MX];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int x,y,a;
		scanf("%d %d %d",&x,&y,&a);
		A[x]^=a;
		A[y]^=a;
	}
	for(int i=0;i<n;i++)
	{
		nm[A[i]]++;
	}
	int ret=nm[0];
	for(int i=1;i<MX;i++)
	{
		ret+=nm[i]/2;
		nm[i]%=2;
	}
	vector <int> vt;
	for(int i=1;i<MX;i++) if(nm[i]==1) vt.push_back(i);
	memset(dp,-1,sizeof(dp));
	memset(rv,-1,sizeof(rv));
	for(int i=0;i<vt.size();i++) rv[vt[i]]=i;
	dp[0]=0;
	for(int i=0;i<vt.size();i++)
	{
		memset(nw,-1,sizeof(nw));
		for(int S=0;S<1<<i;S++)
		{
			if(dp[S]==-1) continue;
			nw[S|1<<i]=max(nw[S|1<<i],dp[S]);
			for(int a=0;a<i;a++)
			{
				if(!(S>>a&1)) continue;
				for(int b=a+1;b<i;b++)
				{
					if(!(S>>b&1)) continue;
					if(vt[a]^vt[b]^vt[i]==0)
					{
						int T=S-(1<<a)-(1<<b);
						nw[T]=max(nw[T],dp[S]+1);
					}
					for(int c=b+1;c<i;c++)
					{
						if(!(S>>c&1)) continue;
						int t=vt[a]^vt[b]^vt[c]^vt[i];
						int T=S-(1<<a)-(1<<b)-(1<<c);
						if(t==0) nw[T]=max(nw[T],dp[S]+1);
						else if(rv[t]!=-1&&(T>>rv[t]&1))
						{
							int K=T-(1<<rv[t]);
							nw[K]=max(nw[K],dp[S]+1);
						}
					}
				}
			}
		}
		for(int S=0;S<1<<(i+1);S++) dp[S]=nw[S];
	}
	int mx=0;
	for(int i=0;i<BT;i++) mx=max(mx,dp[i]);
	printf("%d\n",n-ret-mx);
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;


int main(){

    int n,tmp;
    scanf("%d",&n);

    int L[n],length = 0,left,right,m;

    for(int i=0; i < n; i++){
        scanf("%d",&tmp);

        if(i == 0){
            L[0] = tmp;
        }else{
            if(L[length] < tmp){
                length++;
                L[length] = tmp;
            }else{
            	left = 0,right = length+1;
            	m = left;
            	while(true){
            		if(L[m] >= tmp){
            			for(;m >= 0 && L[m] >= tmp; m--);
            			L[m+1] = tmp;
            			break;
            		}else{
            			left = m;
            			m = (left+right)/2;
            		}
            	}
            }
        }
    }

    printf("%d\n",length+1);

    return 0;
}

Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		  Scanner sc = new Scanner(System.in);
		  int a = sc.nextInt();
		  int b = sc.nextInt();
		 
		  if (b % a == 0) {
			  System.out.println(a + b);
		  }
		  else {
			  System.out.println(b - a);
		  }
	}		
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int a, p;
  cin >> a >> p;
  int P =3*a + p;
  cout << P/2 << endl;
}

Measured memory_bytes: 256
/**
 *    Author:  Oak_limy
 *    Created: 2020-09-13 21:37:44
**/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define up upper_bound
using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
       if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
    char c = getchar(); int w = 1; int x = 0;
    while (!isdigit(c))
        (c == '-') && (w = -w), c = getchar();
    while (isdigit(c))
        x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
    x *= w;
    return x;
}
inline ll readll() {
    char c = getchar(); ll w = 1; ll x = 0;
    while (!isdigit(c))
        (c == '-') && (w = -w), c = getchar();
    while (isdigit(c))
        x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
    x *= w;
    return x;
}
void fl(string name){
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
          dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll n;
const ll mod=1e9+7;
int main(){
    cin>>n;
    if(n<3){
        cout<<0<<endl;
        return 0;
    }
    vector<ll>dp(n+1,0);
    dp[3]=1;
    rp(i,4,n){
        rb(j,i-3,3){
            dp[i]+=dp[j];
        }
        dp[i]++;
        dp[i]%=mod;
    }cout<<dp[n]<<endl;return 0;
}
/* stuff to remember
    * int overflow, array bounds
    * special cases (n=1? n=0?)
    * do something instead of nothing and stay organized
    * USE STATIC ARRAYS
    * DEFINING ARRAYS BEFORE main()
    * DO NOT DEFINE ARRAYS IN main()
    * USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 3676
#include <stdio.h>

int main()
{
  int x,y,r,tmp;

  scanf("%d",&x);
  scanf("%d",&y);

  if(x<y){
    tmp = x;
    x=y;
    y=tmp;
  }

  r = x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }

  printf("%d\n",y);

  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;//絵柄
    int value;//数字
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card Merge[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i=0; i<n1; i++){
        L[i] = Merge[left+i];
    }
    for(i=0; i<n2; i++){
        R[i] = Merge[mid+i];
    }
    L[n1].value = R[n2].value = SENTINEL;
    i=j=0;
    for(k = left; k< right; k++){
        if (L[i].value <= R[j].value){
            Merge[k] = L[i++];
        } else{
            Merge[k] = R[j++];
        }
    }
}

void mergeSort(struct Card Merge[], int n, int left, int right){
    int middle;
    if(left + 1 < right){
        middle = (left + right) / 2;
        mergeSort(Merge, n, left, middle);
        mergeSort(Merge, n, middle, right);
        merge(Merge, n, left, middle, right);
    }
}

int partition(struct Card Quick[], int n, int p,int r){
    int i,j;
    struct Card t, x;
    x = Quick[r];
    i = p-1;
    for(j=p; j<r; j++){
        if(Quick[j].value <= x.value){//基準の値より小さい場合は大きいと分類された先頭の値を入れ替える
            i++;
            t = Quick[i];
            Quick[i] = Quick[j];
            Quick[j] = t;
        }
    }
    //基準の値と大きいと分類された先頭の値を入れ替える
    t = Quick[i+1];
    Quick[i+1] = Quick[r];
    Quick[r] = t;
    return i+1;
}

void quickSort(struct Card Quick[], int n, int p, int r){//パーティションを繰り返してソートを行う
    int q;
    if(p < r){
        q = partition(Quick, n, p, r);
        quickSort(Quick, n, p, q-1);
        quickSort(Quick, n, q+1, r);
    }
}

int main(){
    int num,i,v;
    struct Card Merge[MAX], Quick[MAX];
    char design[10];
    int stable = 1;
    scanf("%d", &num);

    for(i=0; i<num; i++){
        scanf("%s %d", design, &v);//入力された絵柄と数字を入れていく
        Merge[i].suit = Quick[i].suit = design[0];
        Merge[i].value = Quick[i].value = v;
    }

    mergeSort(Merge, num, 0, num);
    quickSort(Quick, num, 0, num-1);

    for(i=0; i<num; i++){
        //マージソートは同じ数字の場合,絵柄は入力された順序で並ぶためマージソートと一致するときは,安定な出力となる
        if(Merge[i].suit != Quick[i].suit){
            stable = 0;
        }
    }
    if(stable ==1){
        printf("Stable\n");
    }
    else{
        printf("Not stable\n");
    }
    for(i=0; i<num; i++){
        printf("%c %d\n", Quick[i].suit, Quick[i].value);
    }
    return 0;
}


Measured memory_bytes: 4084
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read(); //N面ダイス
    let k: usize = read();
    let mut ans = 0.0;

    for i in 1..n+1{
        let mut probability = 1.0/n as f64;
        let mut tokuten = i;
        while tokuten < k {
            tokuten *= 2;
            probability /= 2.0;
        }
        ans += probability;
    }
    println!("{}",ans);

}


Measured memory_bytes: 4352
import qualified Data.ByteString.Lazy.Char8 as BSL
import qualified Data.Vector.Unboxed as VU
import Control.Applicative ((<$>))
import Data.Char (isSpace)

main :: IO ()
main = do
  [n,k,q] <- map read . words <$> getLine
  as <- VU.map (subtract 1)
    . VU.unfoldrN q (BSL.readInt . BSL.dropWhile isSpace)
    <$> BSL.getContents
  let additiveScoreBoard
        = VU.accumulate_ (+) (VU.replicate n 0) as (VU.replicate q 1)
      subtractiveScoreBoard
        = VU.map (+(k-q)) additiveScoreBoard
      survivorChecks
        = VU.map (>0) subtractiveScoreBoard
  VU.forM_ survivorChecks $ \b ->
    putStrLn $ if b then "Yes" else "No"



Measured memory_bytes: 4348
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;

ll n, k;
string s;

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

  for (ll i = 0; i < s.length(); i += 2)
  {
    ans += s[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}

int main(){
	int x;
	cin>>x;
	if(x<1200) cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x=0;
  int s, a, b, c;
  cin >> s;
  a=s/100;
  b=s/10%10;
  c=s%10;
  
  x=a+b+c;
  cout <<x <<endl;
}

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

using namespace std;

int N,K;
vector<int> d;
vector<vector<int> > A;

void input(){
    cin >> N >> K;
    d.resize(K);
    A.resize(K,vector<int>());
    for(int i = 0;i < K;i++){
        cin >> d[i];
        A[i].resize(d[i]);
        for(int j = 0;j < d[i];j++){
            cin >> A[i][j];
        }
    }
}

void output(){
    int ans = 0;
    for(int i = 1;i <= N;i++){
        bool have = false;
        for(int j = 0;j < K;j++){
            for(int k = 0;k < d[j];k++){
                if(A[j][k] == i) have = true;
            }
        }
        if(!have) ans++;
    }
    cout << ans << endl;
}

int main(void){
    input();
    output();
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int H, A;
    cin >> H >> A;
    int ans = H / A;
    if(H % A != 0) { ans++; }
    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int u=0;
    long long  ans=0;
    int biggest=0;
    while(u<n){
        biggest=max(a[u],biggest);
        int b1=biggest;
            ans+=b1-a[u];
        u++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  map<char, int> m;
  for (int i = 0; i < 3; i++) {
    m[s[i]]++;
  }
  if (!m['A'] or !m['B']) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n, d;
    cin >> n >> d;
    vector<vector<int>> X(n, vector<int>(d));
    rep(i, n)rep(j, d) cin >> X[i][j];

    int ans = 0;
    rep(i, n)REP(j, i+1, n){
        LL tmp = 0;
        rep(k, d) tmp += abs(X[i][k]-X[j][k]) * abs(X[i][k]-X[j][k]);
        rep(k, 10000) if(k*k == tmp){
            ans++;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

P dp[105][500*55];

int main(){
  
  int n;
  
  while(cin>>n, n){
    
    memset(dp,-1,sizeof(dp));
    
    dp[0][0]=P(0,0);

    P ans=P(0,0);
    
    for(int i=0;i<n;i++){
      
      int p;
      cin>>p;
      
      for(int j=0;j<500*55;j++){
	if(dp[i][j]==P(-1,-1)) continue;
	dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
	if(p%1000){
	  int rest=1000-p%1000, add500=0;
	  if(rest>=500) add500++, rest-=500;
	  int idx=min(j+rest,500*55-1);
	  dp[i+1][idx]=max(dp[i+1][idx],P(dp[i][j].first+add500,-(-dp[i][j].second+p)));
	  ans=max(ans,dp[i+1][idx]);
	}
	int rest=p+500;
	rest%=1000;
	if(j-rest<0) continue;
	dp[i+1][j-rest]=max(dp[i+1][j-rest],P(dp[i][j].first+1,-(-dp[i][j].second+p)));
	ans=max(ans,dp[i+1][j-rest]);
      }
      
    }

    cout<<ans.first<<' '<<-ans.second<<endl;
    
  }
  
  return 0;
}

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

using namespace std;

bool acgt(string &ss) {
  for (auto &s : ss) if (s == 'A' || s == 'C' || s == 'G' || s == 'T') {
    return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s; 
  cin >> s;
  int n = s.size();
  int res = 0, tmp;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      tmp = 1;
      for (int j = i+1; j < n; ++j) {
        if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') 
          ++tmp;
        else break;
      }
      res = max(res, tmp);
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);


struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> P(N),num(N);
    for(int i=0;i<N;i++) {
        cin >> P[i];
        P[i]--;
        num[P[i]]=i;
    }

    UnionFind uf(N);

    for(int i=0;i<M;i++){
        ll x,y;
        cin >> x >> y;
        x--;y--;
        uf.merge(x,y);
    }

    ll tmp=0;
    for(int i=0;i<N;i++){
        if(uf.issame(P[i],num[P[i]])) tmp++;
    }

    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int ans=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='-')
            ans--;
        else
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll k, a, b;
  cin >> k >> a >> b;
  if (b-a <= 2) {
    cout << k+1 << '\n';
    return 0;
  }
  k -= a-1;
  ll ans = k%2 + k/2 * (b-a) + a;
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>

using namespace std;

const int kMaxN = 100000;

int main() {
    int n;
    int A[kMaxN];

    cin >> n;

    int sum = 0;
    int x = 0, y, ans;

    for (int i = 0; i < n; i++) {
        cin >> A[i];
        sum += abs(A[i] - x);
        x = A[i];
    }

    sum += abs(0 - A[n - 1]);

    for (int i = 0; i < n; i++) {
        if (i == 0) {
            x = 0;
            y = A[i + 1];
        }
        else if (i == n - 1) {
            x = A[i - 1];
            y = 0;
        }
        else {
            x = A[i - 1];
            y = A[i + 1];
        }

        ans = sum + abs(y - x) - (abs(A[i] - x) + abs(y - A[i]));
        cout << ans << endl;
    }
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>

#define MAX 2000000
#define INFTY 500000000

int P,A[MAX+1];

void maxHeap(int a){
  int l,r,lgest;
  l = 2*a;
  r = 2*a+1;

  if(l<=P && A[l]>A[a])
    lgest = l;
  else lgest = a;
  if(r<=P && A[r]> A[lgest]) lgest = r;

  if(lgest != a){
    int z;
    z = A[a];
    A[a] = A[lgest];
    A[lgest] = z;
    maxHeap(lgest);
  }
}


int ext(){
  int mv;
  if(P<1) return -INFTY;
  mv = A[1];
  A[1] = A[P--];
  maxHeap(1);
  return mv;
}

void incK(int a,int k){

  int w;
  if(k<A[a])return;
  A[a] = k;
  while(a>1&&A[a/2]<A[a]){
    w = A[a];
    A[a] = A[a/2];
    A[a/2] = w;
    a = a/2;
  }
}



void ins(int k){
  P++;
  A[P] = -INFTY;
  incK(P,k);
}



int main(){
  int k;
  char c[10];

  while(1){
    scanf("%s",c);
    if(c[0] == 'e'&&c[1]=='n') break;
    if(c[0] == 'i'){
      scanf("%d",&k);
      ins(k);
    }else{
      printf("%d\n",ext());
    }
  }

  return 0;
}



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

#define fast                     ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int                      long long 
#define pb                       push_back
#define pii                      pair<int,int>
#define vi                       vector<int>
#define vii                      vector<pii>
#define mi                       map<int,int>
#define mii                      map<pii,int>
#define all(a)                   (a).begin(),(a).end()
#define l                        first
#define r                        second
#define sz(x)                    (int)x.size()
#define endl                     '\n'
#define MOD                      1000000007
#define loop(i,a,b)              for(int (i)=(a);(i)<(b);(i)++)
#define rloop(i,a,b)             for(int (i)=(a);(i)>=(b);(i)--)
#define Unique(A)                (A).resize(distance((A).begin(),unique(all((A)))))
#define MXe(A)                   *max_element(all(A))
#define MNe(A)                   *min_element(all(A))
#define SP(val,precision)        fixed << setprecision((precision)) << (val)
#define setBits(x)               __builtin_popcountll(x)
#define zroBits(x)               __builtin_ctzll(x)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define mem(name,val)            memset(name,val,sizeof(name))
#define traceA(A,x)              cerr<<#A<<": ";loop(i,0,x)cerr<<A[i]<<' ';cerr<<endl
#define traceV(A)                cerr<<#A<<": ";for(auto i:A)cerr<<i<<' ';cerr<<endl
#define maxheap                  priority_queue<int>
#define minheap                  priority_queue<int,vector<int>,greater<int>>

using namespace std;

const int N = 2e6+77;
int A[N];


int32_t main(){
    int n ; cin >> n ;
    int v = 7%n;
    loop(i,1,N){
        if(v==0){
            cout << i << endl;
            return 0;
        }
        v = v*10 + 7;
        v %= n;
    }
    cout << -1 << endl;
    return 0;
}

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

int A[200010];

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    int _max=-1;
    long long sum=0;
    for (int i = 0; i < N; i++)
    {
        if (_max < A[i]) _max = A[i];
        else {
            sum += _max - A[i];
            A[i] = _max;
        }
    }
    
    cout << sum << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = stoi(s);
  vector<int> s_i(4);
  s_i.at(0)=n/1000;
  s_i.at(1)=n/100-(n/1000)*10;
  s_i.at(2)=n/10-(n/100)*10;
  s_i.at(3)=n-(n/10)*10;
  
  // int a = s.at(0), b = s.at(1), c = s.at(2), d = s.at(3);

  for(int bit = 0; bit < (1<<3); bit++){
    int sum = s_i.at(0);
    for(int i=0; i<3; i++){
      if(bit&(1<<i)){
        sum+=s_i.at(i+1);
      }else sum-=s_i.at(i+1);
    }
    if(sum==7){
      for(int i=0; i<3; i++){
        cout << s_i.at(i);
        if(bit&(1<<i)){
          cout << '+';
        }else cout <<'-';
      }
      cout << s_i.at(3) << '=' << 7 <<endl;
      break;
    }
  }
}

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

int main() {
	int N;
	cin >> N;
	vector<int> X(N);
	double sum = 0;
	for (int i = 0;i < N;++i) {
		cin >> X[i];
		sum += X[i];
	}
	int ave = round(sum / N);
	int ene = 0;
	for (int i = 0;i < N;++i) {
		ene += (X[i] - ave) * (X[i] - ave);
	}
	cout << ene << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 100005;

int suf[N][3];
int a[N];
int main() {
    int n;
    string s;
    cin >> n >> s;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'R') a[i] = 0;
        if (s[i] == 'G') a[i] = 1;
        if (s[i] == 'B') a[i] = 2;
        suf[i][0] = suf[i + 1][0] + (a[i] == 0);
        suf[i][1] = suf[i + 1][1] + (a[i] == 1);
        suf[i][2] = suf[i + 1][2] + (a[i] == 2);
    }
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[j] == a[i]) continue;
            int t = 0;
            while (t < 3) {
                if (a[i] != t && a[j] != t) break;
                t++;
            }
            ans += suf[j + 1][t];
            int k = j + j - i;
            if (k < n && a[k] == t) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
import math
import collections

def trial_division(n):
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    factor.append(n)
    return factor

n = int(input())
c = collections.Counter([])
for num in range(2, n+1):
  prime_list = trial_division(num)
  c.update(prime_list)
res = 1
for prime, count in c.most_common():
  if(prime > 1):
    res = res * (count + 1)
print(res % (pow(10,9) + 7))

Measured memory_bytes: 40176
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//

        string S;
        cin >> S;
        if (S[0]==S[2])
        {
                cout << "Yes" << endl;
        }
        else
        {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
/*Author : Yuvraj Singh
 * Patience is Power
 * 
 * */
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
#define ar array
/*
ll power(ll x,ll y) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return ((temp%mod)*(temp%mod))%mod; 
    else
        return ((x%mod)*(temp%mod)*(temp%mod))%mod; 
}

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}

bool cmp(pair<int,int>a,pair<int,int>b){
	return a.second<b.second;
}
*/
void solve(){
	ll a,b,c,d; cin>>a>>b>>c>>d;
	ll mx = max(a*c,max(a*d,max(b*c,b*d)));
	cout<<mx;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	//int t; cin>>t;
	//while(t--)
		solve();
		
    return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

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

Measured memory_bytes: 256
n, m, x, y = map(int,input().split())
xs = map(int,input().split())
ys = map(int,input().split())
xs = sorted(xs)
ys = sorted(ys)
z = (xs[-1] + ys[0])/2

if x < z <= y and xs[-1] < z and ys[0] >= z:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
const int N=2*1e3+5;
int main(){
	int n,m,x,temp;
	cin>>n>>m>>x;
	for (int i = 0; i < m; ++i)
		cout<<x<<" ";
	if(x+1<=1e9)temp=x+1;
	else temp=x-1;
	for (int i = 0; i < n-m; ++i)
		cout<<temp<<" ";
}

Measured memory_bytes: 1280
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	ll X,Y,Z;
	cin >> X >> Y >> Z;
	
	ll ma = 0;
	for(int i=1;i<X;i++){
		ll tot = i * Y + (i + 1) * Z;
		if(X >= tot) ma = i;
	}
	
	cout << ma << endl;
	
	
	
    return 0;
}

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

int main() {
  int sum=0;
  int N,n;
  cin>>N;
  n=N;
  for(int i=8; i>=0;i--){
    int x=std::pow(10,i);
    sum=sum+n/x;
    n=n-(n/x)*x;
  }
  if(N%sum==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}  



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

int main() {
  int count=0;
  int N;
  cin>>N;
  if(N>194){
    cout<<5;
    return 0;
  }
  if(N>188){
    cout<<4;
    return 0;
  }
  if(N>164){
    cout<<3;
    return 0;
  }
  if(N>134){
    cout<<2;
    return 0;
  }
  if(N>104){
    cout<<1;
    return 0;
  }
  cout<<0;
}


Measured memory_bytes: 256
n, x = map(int,input().split())
lm = []
for s in range(n):
    m = int(input())
    if s == 0:
        lm.append(m)
    else:
        if lm[0] > m:
            lm[0] = m
    x -= m
print(n+ x//lm[0])

Measured memory_bytes: 3060
#include<cstdio>
#define ll long long
int h[100000],n,a,b;
bool check(int t) {
	int c=0;
	for(int i = 1; i <= n && c <= t; i++ )
		c+=h[i]<=(ll)t*b?0:(h[i]-t*b+a-1)/a;
	return c<=t;
}
int main() {
	scanf("%d%d%d",&n,&a,&b),a-=b;
	for(int i = 1; i <= n; i ++ )scanf("%d", &h[i]);
	int l=1, r=1e9;
	while(l<r) {
		int mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	printf("%d\n",r);
}

Measured memory_bytes: 512
#include <iostream>
#include <ctype.h>
 
using namespace std;
 
int main() {
int i;
char ch;
int alpha[26];
 
 
//?????????
for(i=0;i<26;i++){
alpha[i]=0;
}
 
 
//??\??????EOF?????\????????則
while ( cin >> ch ){
    // ????????則 ch ?????蔵?????????????????????????????属??????
 
if( isalpha(ch) != 0 ){
 
//??????????属????????????卒???????????????
alpha[tolower(ch)-'a']++;
}
  
}
 
for(i=0;i<26;i++){
//printf("%c : %d\n", (char)(i+'a'), alpha[i]);
cout << (char)(i+'a') << " : " << alpha[i] << endl;
}
 
        return 0;
}

Measured memory_bytes: 1140
#include<iostream> //cinなど
#include<string> //文字列
#include<algorithm> //sort など
#include<math.h> //paw(冪乗など)
#include<set> // 集合
#include<map> //写像
#include<stdio.h> //printf
#include<stack>

using namespace std;
int main(){
  int a,b;
  char o;

  cin>>a>>o>>b;

  if(o=='+'){
    cout<<a+b<<endl;
  }else{
    cout<<a-b<<endl;
  }

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,k,n,m,c,s,t;
    char ch;
    cin>>ch;
    if(ch=='A') printf("T\n");
    else if(ch=='T') printf("A\n");
    else if(ch=='C') printf("G\n");
    else if(ch=='G') printf("C\n");
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

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

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = a[0];
  for (int i = 1; i < n; i++) {
    ans = gcd(ans, a[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int N = 0;
    int K = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &N, &K);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    ans = N - K;
    
    if(ans == 0){
      /* 真の場合の処理 */
      printf("Yes");
    }else{
      /* 偽の場合の処理 */
       printf("No");
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
   ; // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}






Measured memory_bytes: 128
#include<stdio.h>
#define N 100
int main(){
  int i,j,n,x;
  int count=0,a;
  int A[N];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a);
    A[i] = a;
  }
  for( j = 0; j < n; j++){
    for( i = n-1; i > 0; i--){
      x = A[i];
      if(A[i] < A[i-1]){
	A[i] = A[i-1];
	A[i-1] = x;
	count++;
      }
    }
  }

  for(i = 0; i < n; i++){
    if(i > 0)
      printf(" ");
    printf("%d", A[i]);
  }
  printf("\n%d\n", count);

  return 0;
}





Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
ll a[N] = {};

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%lld", a+i+1);
	REP(i, n) a[i+1] *= 2;
	REP(i, n) a[i+1] += a[i];
	ll mid = a[n] / 2;
	int k = 0;
	while(a[k+1] <= mid) k++;
	printf("%lld\n", min(a[k+1]-mid, mid-a[k]));
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
	static int[]c;
	static int n, m;
	static final int MAX = 50000;
	static final int INF = (1<<21);
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		m = scan.nextInt();
		c = new int[m + 1];
		for(int i = 0; i < m; i++) {
			c[i + 1] = scan.nextInt();
		}
		scan.close();
		solve();
	}
	static void solve() {
		int[]T = new int[n + 1];
		for(int i = 0; i <= n; i++) {
			T[i] = INF;
		}
		T[0] = 0;
		for(int i = 1; i <= m; i++) {
			for(int j = 0; j + c[i] <= n; j++) {
				T[j + c[i]] = Math.min(T[j + c[i]], T[j] + 1);
			}
		}
		System.out.println(T[n]);
	}
}


Measured memory_bytes: 26620
package main

import "fmt"

func main() {
	var n int
	var x int
	var l int

	fmt.Scan(&n)
	fmt.Scan(&x)

	count := 1
	before := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&l)
		t := before + l
		//fmt.Println(t)
		if t <= x {
			count++
		} else {
			break
		}
		before = t
	}

	fmt.Println(count)
}


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

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

    int m = 10000;
    int g = 5000;
    int s = 1000;
    rep(a, 0, y / m + 1)
    rep(b, 0, (y - a * m)/g + 1) 
    {
        int c = (y - a * m - b * g) / s;
        if (a + b + c == n)
        {
            cout << a << ' ' << b << ' ' << c << endl;
            return 0;
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
    return 0;
}

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

int h,w;
string s[1000];
char k;

void solve(int x,int y){

  if(s[x][y] != k) return;
  s[x][y] = '.';

  if(x+1 < h) solve(x+1,y);
  if(y+1 < w) solve(x,y+1);
  if(x-1 >= 0) solve(x-1,y);
  if(y-1 >= 0) solve(x,y-1);

}

int main(){

  while(true){
    cin >> h >> w;
    if(!(h+w)) break;

    for(int i=0;i<h;i++) cin >> s[i];

    int ans = 0;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(s[i][j] != '.'){
	  k = s[i][j];
	  solve(i,j);
	  ans++;
	}
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1848
# ABC 094: B – Toll Gates
n, m, x = map(int, input().split())
a = [int(s) for s in input().split()]

if x < a[0] or x > a[m - 1]:
    print(0)
else:
    print(min(len([p for p in a if p < x]), len([q for q in a if q > x])))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vc vector<char> 
#define vvc vector<vector<char> > 
#define vpi vector<pair<int,int> >
#define ll long long 
#define sz(a) int(a.size())
#define forn(i,n) for(int i = 0 ; i < int(n) ; i++)
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define len(s) s.length()
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
#define modulo 998244353ll
#define mod 1000000007ll
#define MAXN  1000001 
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll gcd(ll a,ll b){if(a==0 || b == 0) return max(a,b);if(a == 1 || b == 1)return 1;return gcd(max(a,b)%min(a,b),min(a,b));}



void solve()
{
    ll a,b,c,d;
    ll ans;
    cin>>a>>b>>c>>d;
    ans = max(d*b,max(a*c,max(a*d,b*c)));
    cout<<ans<<endl;
}


int main()
{
    fast();
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<ll,ll>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):0;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}
        return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

	char str[N];int num[N];
	void main()
	{
		int n=qread(),k=qread();scanf("%s",str+1);
		int cnt=1;for(int i=2;i<=n;i++) if(str[i-1]!=str[i]) cnt++,num[cnt]=1^num[cnt-1];
		
		int fl=1,fr=cnt;
		while(k--)
		{
			if(cnt<=1) break;
			if(fl>fr) puts("error");
			
			if(num[fl]==num[fr])
			{
				fl++;fr--;
				if(fl==fr) cnt=1; else cnt-=2;
			}
			else cnt-=2,fl++,fr--;
		}
		chmax(cnt,1);
		write(n-cnt);
	}
};
int main()
{
	srand(time(0));
	mine::main();
}

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

const int inf = 1000000000000000LL;

signed main() {
	string a;
	cin >> a;
	vector<int> c(26, 0);
	for(auto i: a) {
		c[i - 'a']++;
	}
	int ans = 0;
	rep(i, 26) {
		ans += (a.size() - c[i]) * c[i];
	}
	cout << ans / 2 + 1 << endl;
}


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

int main() {
    int n; cin >> n;
    int a[105];
    for(int i=1;i<=n;i++) cin >> a[i];
    int ans = 0;
    for(int i=1;i<=n-1;i++) {
        int tag = 0;
        for(int j=1;j<=n-i;j++) {
            if(a[j] > a[j+1]) {
                swap(a[j],a[j+1]);
                tag = 1;
                ans++;
            }
        }
        if(tag == 0) break;
    }
    cout << a[1] ;
    for(int i=2;i<=n;i++) cout << " " << a[i];
    cout << endl << ans <<endl;
    return 0;
}



Measured memory_bytes: 3076
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
d={}
for i in range(n-1):
  d[(l[i][0]-1,l[i][1]-1)]=l[i][2]
  d[(l[i][1]-1,l[i][0]-1)]=l[i][2]

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=[v]
  next2=set()
  visited=[-1]*n
  visitct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            distance[connection[next[i]][j]]=distance[next[i]]+d[(next[i],connection[next[i]][j])]
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

ans=bfs(0)
for i in range(n):
  print(ans[i]%2)

Measured memory_bytes: 105432
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mp make_pair
    #define mod 1e9+7
    #define sz 100000
    #define f(i,n) for(ll i=0;i<n;i++)
    #define fab(i,a,b) for(ll i=a;i<b;i++)
    #define fr(i,n) for(ll i=n-1;i>=0;i--)
    #define fba(i,b,a) for(ll i=b-1;i>=a;i--)
    #define tc(t) ll t;cin>>t;while(t--)
     
    ll pw(ll x,unsigned ll y) 
    { 
        if (y==0) 
            return 1; 
        else if (y%2==0) 
            return pw(x,y/2)*pw(x,y/2); 
        else
            return x*pw(x,y/2)*pw(x,y/2);
    }
     
    int main() 
    {
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        string s, t, u;
        ll a, b;
        cin >> s >> t;
        cin >> a >> b;
        cin >> u;
        if(s == u)
            a -= 1;
        else b -= 1;
        cout << a << ' ' << b;
        return 0;
    }

Measured memory_bytes: 256