akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    long long N;
    cin >> N;
    vector< long long > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long Q;
    cin >> Q;
    vector< long long > B(Q), C(Q);
    for (long long i = 0; i < Q; i++) {
        cin >> B[i] >> C[i];
    }
    vector< long long > x(100010, 0);
    long long sum = 0;
    for (long long i = 0; i < N; i++) {
        sum += A[i];
        ++x[A[i]];
    }
    for (long long i = 0; i < Q; i++) {
        sum += x[B[i]] * (C[i] - B[i]);
        printf("%lld\n", sum);
        x[C[i]] += x[B[i]];
        x[B[i]] = 0;
    }

    return 0;
}


Measured memory_bytes: 6308
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for(int i = 0; i < N; i++){
            int a = sc.nextInt();
            while(true){
                if(a % 2 == 0){
                    ans++;
                    a /= 2;
                }else{
                    break;
                }
            }
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 33480
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;



int main()
{
	vector<string> word;
	string sent;
	int ss = 0;
	getline(cin, sent);
	//input word
	for(int i = 0; i < sent.size(); i++)
	{
		if(sent[i] == ' ' )
		{
			
			word.push_back(sent.substr(ss,i - ss));
			int inc = 1,tmp = i;
			while(1)
			{
				if(!(sent[tmp+1] == ' ') )	break;
				++inc; ++tmp;
			}
			ss = i + inc;
		}
		if(i == sent.size() - 1)
		{
			word.push_back(sent.substr(ss, (i+1) - ss));
		}
	}
	
	int leng = 0, p = 0;
	//length
	for(int i = 0;i < word.size(); i++)
	{
		if(word[i].size() > leng)
		{
			leng = word[i].size();
			p = i;
		}
	}
	//cout << word[p] << endl;
	//frequency
	/*
	int bucket[1024];
	for(int i = 0; i < 1024; i++) bucket[i] = 0;
	
	vector<string> list;

	for(int i = 0; i < word.size(); i++)
	{
		if( list.empty() || !( find(list.begin(), list.end(), word[i]) == list.end() ) )
		{
			list.push_back(word[i]);
		}
		for(int i = 0; i < list.size(); i++)
		{
			cout << list[i] << endl;
		}
	}
	*/
	
	map<string, int> freq;
	for(int i = 0;i < word.size(); i++)
	{
		bool judge = false;

		if(freq.find(word[i]) == freq.end())
		{
			freq.insert(make_pair<string,int>(word[i], 1));
		}
		else
		{
			freq[ word[i] ]++;
		}
	}
	map<string, int>::iterator it, high;
	leng = 0;
	for(it = freq.begin(); it != freq.end(); it++)
	{
		if( leng < (*it).second)
		{
			leng = (*it).second;
			high = it;
		}	
		//cout << (*it).first << (*it).second << endl;
	}
	cout << (*high).first << ' ' << word[p] << endl;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin >> p.at(i);
  int ans=0;
  for(int i=1;i<n-1;i++){
    int minimum=min(p.at(i-1),p.at(i+1));
    int maximum=max(p.at(i-1),p.at(i+1));
    if((minimum<p.at(i)&&p.at(i)<maximum)) ans++;
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define int long long
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ

signed main(){
    string s; cin >> s;
    cout << s.substr(0,3) << endl;
}


Measured memory_bytes: 3624
from collections import deque
N,M = map(int,input().split())
g = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)

q = deque([(1,0)])
ans = [-1]*(N+1)
while q:
    u,v = q.popleft()
    if ans[u] == -1:
        ans[u] = v
        for w in g[u]:
            if w==v:
                continue
            q.append((w,u))

print('Yes')
for i in range(N-1):
    print(ans[i+2])

Measured memory_bytes: 105800
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL gcd(LL m, LL n){
    LL temp;
    while(m%n!=0){
        temp=n;
        n=m%n;
        m=temp;
    }
    return n;
}
LL lcm(LL m, LL n){
    return m*n/gcd(m, n);
}

void solve(long long N, std::vector<long long> a){
    LL m = 0;
    REP(i, N){
        m = max(m, a[i]);
    }
    LL f = 0;
    LL idx = 0;
    LL LCM = 1;
    REP(i, N){
        LCM = lcm(a[i], LCM);
    }
    REP(i, N){
        f += (a[i])-1;
    }
    cout<<f<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 4500000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7772
#include <bits/stdc++.h>
#define int long long

using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
int a[maxn];
signed main(){
    int n;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    int ans=1;
    for(int i=1;i<n;i++){
        ans*=4;
        ans%=mod;
    }
    int ans2=0;
    for(int i=1;i<=n;i++){
        ans2+=a[i]*(i+1)%mod;
        ans2%=mod;
    }
    (ans*=ans2)%=mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  int n;
  while (scanf("%d", &n) == 1) {
    vector<int> b(n);
    for (int &x : b) {
      scanf("%d", &x);
      --x;
    }

    vector<int> ans;
    for (int i = 0; i < n; i++) {
      int t = -1;
      for (int j = 0; j < (int)b.size(); j++) {
        if (b[j] == j) {
          t = j;
        }
      }
      if (t == -1) {
        ans.clear();
        ans.push_back(-1);
        break;
      }
      ans.push_back(t + 1);
      b.erase(b.begin() + t);
    }
    reverse(ans.begin(), ans.end());
    for (int x : ans) {
      printf("%d\n", x);
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	
	int cards[4][13]={{0},{0}};/*2?¬??????????????????????*/
	int i, j,n;


	scanf("%d",&n);

	for(i=0;i<n;i++){
	char b;
	int c;
	scanf(" %c %d\n",&b, &c);
	if(b=='S'){		/*??\???????????????????????????????????????????´?*/
		cards[0][c-1]=1;
	}else if(b=='H'){
		cards[1][c-1]=1;
	}else if(b=='C'){
		cards[2][c-1]=1;
	}else if(b=='D'){
		cards[3][c-1]=1;
	}
	}
	char pattern[]={'S','H','C','D'};
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
		if(cards[i][j]==0){ /*???????????????????????????????????????*/
		printf("%c %d\n",pattern[i],j+1); 
		}
	}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	int x = n % 10;
	if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9){
		cout << "hon" << endl;
	}
	else if (x == 0 || x == 1 || x == 6 || x == 8){
		cout << "pon" << endl;
	}
	else if (x == 3){
		cout << "bon" << endl;
	}
	return 0;
}


Measured memory_bytes: 3636
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")


n,a,b=MI()


print(min(n*a,b))








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


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N;
    cin>>N;
    v a(N);
    rep(i,0,N)cin>>a[i];
    v sum_a(100005);
    rep(i,0,N){
        sum_a[a[i]]++;
    }
    ll three_max = 0;
    rep(i,0,100005){
        ll three = 0;
        three = sum_a[i] + sum_a[i+1] + sum_a[i+2];
        three_max = max(three_max,three);
    }
    cout<<three_max;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		int n = int.Parse(Console.ReadLine());
		var l = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		
		int longest = 0;
		int nanban = 0;
		
		for(int a=0; a!=n; a++){
			if(l[a] > longest){
				longest = l[a];
				nanban = a;
			}
		}
		
		int sum = 0;
		
		for(int b=0; b!=n; b++){
			if(b != nanban){
				sum = sum + l[b];
			}
		}
		
		if(sum > l[nanban]){
			Console.WriteLine("Yes");
		}else{
			Console.WriteLine("No");
		}
	}
}

Measured memory_bytes: 13396
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] x = new int[N];
    int[] y = new int[N];
    int[] t = new int[N];

    for (int i = 0; i < N; i++) {
      t[i] = sc.nextInt();
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }

    sc.close();

    String result = "Yes";

    for (int i = 0; i < N; i++) {
      if (t[i] < x[i] + y[i]) {
        result = "No";
        break;
      } else {
        if (t[i] % 2 == 1 && (x[i] + y[i]) % 2 == 0) {
          result = "No";
          break;
        } else if (t[i] % 2 == 1 && (x[i] + y[i]) % 2 == 0) {
          result = "No";
          break;
        }
      }
    }

    System.out.println(result);

  }

}

Measured memory_bytes: 90148
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};
const main=()=>{
  let s=ts(),n=s.length,ans=0
  for(let i=0;i<2**(n-1);i++){
    let ss=s.split('')
    for(let j=0;j<n-1;j++){
      if(i&1<<j)ss[j]+='+'
    }
    ans+=eval(ss.join(''))
  }
  to(ans)
}
main()


Measured memory_bytes: 8124
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    V<ll> plus, minus;
    for(ll i = 0; i < N; i++) {
        ll e;
        cin >> e;
        (e > 0 ? plus : minus).push_back(e);
    }

    if(minus.empty()) {
        sort(ALL(plus));
        ll sum = accumulate(ALL(plus), 0ll);
        cout << sum - plus[0] * 2 << endl;
        ll init = plus[0];
        for(ll i = 1; i < N - 1; i++) {
            cout << init << ' ' << plus[i] << endl;
            init -= plus[i];
        }
        cout << plus.back() << ' ' << init << endl;
    } else if(plus.empty()) {
        sort(ALL(minus));
        ll sum = accumulate(ALL(minus), 0ll);
        sum = minus.back() * 2 - sum;
        cout << sum << endl;
        ll init = minus.back();
        for(ll i = 0; i < N - 1; i++) {
            cout << init << ' ' << minus[i] << endl;
            init -= minus[i];
        }
    } else {
        ll p = plus[0], m = minus[0];
        ll sum = accumulate(ALL(plus), 0ll) - accumulate(ALL(minus), 0ll);
        cout << sum << endl;
        for(ll i = 1; i < minus.size(); i++) {
            cout << p << ' ' << minus[i] << endl;
            p -= minus[i];
        }
        for(ll i = 1; i < plus.size(); i++) {
            cout << m << ' ' << plus[i] << endl;
            m -= plus[i];
        }
        cout << p << ' ' << m << endl;
    }
    return 0;
}


Measured memory_bytes: 2804
from itertools import product
inpl = lambda: list(map(int,input().split()))
N, M, X = inpl()
A = []
C = []
for _ in range(N):
    H = inpl()
    C.append(H[0])
    A.append(H[1:])

ans = -1
for s in product(range(2), repeat=N):
    U = [ sum( A[n][m] for n in range(N) if s[n]) for m in range(M)]
    for m in range(M):
        if U[m] < X:
            break
    else:
        P = sum(C[n] for n in range(N) if s[n])
        if ans < 0 or P < ans:
            ans = P
print(ans)


Measured memory_bytes: 76224
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	stack<int> S1;
	stack<pair<int,int>> S2;
	int sum=0;
	char ch;
	for (int i = 0; cin>>ch; ++i)
	{
		if(ch=='\\')
		{
			S1.push(i);
		}
		else if(ch=='/'&&S1.size()>0)
		{
			int j=S1.top();
			S1.pop();
			int a=i-j;
			sum+=a;
			while(S2.size()>0&&S2.top().first>j)
			{
				a=S2.top().second+a;
				S2.pop();
			}
			S2.push(make_pair(j,a));
		}
	}

	vector<int> ans;
	while(S2.size()!=0)
	{
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	int s=ans.size();
	cout<<s;
	for (int i = 0; i < s; ++i)
	{
		cout<<" "<<ans[i];
	}
	cout<<endl;
}


Measured memory_bytes: 3220
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

int N;
char Buf[100];

int Q(int x)
{
	printf("%d\n", x);
	fflush(stdout);
	scanf("%s", Buf);
	if (Buf[0] == 'V')
		exit(0);
	else if (Buf[0] == 'M')
		return 1;
	else
		return 2;
}

void Work()
{
	scanf("%d", &N);
	int Left = 0, Right = N - 1, Mid = (Left + Right) / 2;
	
	int ql = Q(Left);
	int qm = Q(Mid);
	int qr;
	if ((Left % 2 == Mid % 2) != (ql == qm))
	{
		Right = Mid;
		qr = qm;
	}
	else
	{
		Left = Mid;
		Right = N - 1;
		ql = qm;
		qr = Q(Right);
	}
	if ((Left % 2 == Right % 2) == (ql == qr)) { for (int ii = 0; ii < 20; ii ++) Q(0); }

	while (Right - Left > 1)
	{
		int Mid = (Left + Right) / 2;
		qm = Q(Mid);

		if ((Left % 2 == Mid % 2) != (ql == qm))
		{
			Right = Mid;
			qr = qm;
		}
		else
		{
			Left = Mid;
			ql = qm;
		}
	}
	for (int i = Left + 1; i < Right; i ++)
		Q(i);
}

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

Measured memory_bytes: 852
#include <iostream>
#include <map>
#include <string>
using namespace std;
//north, west, south, east
int dice[7][4] = {
    {},
    {2, 4, 5, 3},
    {6, 4, 1, 3},
    {5, 6, 2, 1},
    {5, 1, 2, 6},
    {1, 4, 6, 3},
    {5, 4, 2, 3}
};
int vals[7] = {0, 6, 5, 4, 3, 2, 1};

map<string, int> createmap() {
    map<string, int> m;
    m.insert({"North", 0});
    m.insert({"West", 1});
    m.insert({"South", 2});
    m.insert({"East", 3});
    return m;
}
static map<string, int> dirs = createmap();
int dir, pos, currNum, prevNum, prevPos, sum;

void setDir(int pp) {

    int optPos = 0;
    for (int i = 0; i < 4; i++) {
        if (dice[currNum][i]== prevNum) {
            optPos = i;
            break;
        }
    }
    int res = 0;
    if (optPos != pp) {
        while (optPos != pp) {
            pp = (pp + 1) % 4;
            res++;
        }
    }
    dir = res;
}

int main() {
    int n;
    for (; ;) {
        cin >> n;
        if (n == 0) break;
        dir = 0, currNum = 6, sum=1;
        prevNum = 2, prevPos = 0;
        string str;
        for (int i = 0; i < n; i++) {
            cin >> str;
            if (str == "Left") {
                sum += vals[currNum];
                dir = (dir + 3) % 4;

            }
            else if (str == "Right") {
                sum += vals[currNum];
                dir = (dir + 1) % 4;
            }
            else {
                pos = (dir + dirs[str]) % 4;
                prevNum = currNum;
                currNum = dice[currNum][pos];
                prevPos = (dirs[str]+2)%4;
                sum += vals[currNum];
                setDir(prevPos);
            }
        }
        cout << sum << endl;
    }
    return 0;
}



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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	if ((n*100+a*10+b) % 4 == 0) puts("YES");
	else puts("NO");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long int arr[n],sum(0);
for(int i=0; i<n; ++i)
{
int a;
cin>>a;
sum+=a;
arr[i]=a;
}
long long int ans=sum,sum1(0);
if(ans>=0)
ans+=(n-1);
if(ans<0)
ans+=(1-n);
ans/=n;
for(int i=0; i<n; ++i)
sum1+=(long long)(arr[i]-ans)*(arr[i]-ans);
long long int ans1=sum,sum2(0);
ans1/=n;
for(int i=0; i<n; ++i)
sum2+=(long long)(arr[i]-ans1)*(arr[i]-ans1);
cout<<min(sum1,sum2);
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
bri = [0]*m
ans = [0]*m

class U:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1 for _ in range(n)]
        self.rank = [0] * (n)
        
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
          
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
            
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
      
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

uni = U(n)
ans[0] = n*(n-1)//2
for i in range(m):
  bri[i] = [int(i)-1 for i in input().split()]
for i in range(1,m):
  if uni.is_same(bri[-i][0],bri[-i][1]):
    ans[i] = ans[i-1]
  else:
    ans[i] = ans[i-1] - uni.get_size(bri[-i][0]) * uni.get_size(bri[-i][1])
    uni.union(bri[-i][0],bri[-i][1])
for i in range(1,m+1):
  print(ans[-i])

Measured memory_bytes: 28712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC123
{
    class Program
    {
        static void Main(string[] args)
        {
            // FiveAntennas(); // 25min 掛けたが解けず
            FiveDishes();
        }

        public static void FiveDishes()
        {
            int[] dishes = new int[5];
            for(int i = 0; i < 5; i++)
            {
                dishes[i] = ReadInt();
            }

            dishes = dishes.OrderByDescending(i => i % 10 == 0 ? 10 : i % 10).ToArray();

            int ans = 0;
            for(int i = 0; i < 4; i++)
            {
                ans += (int)Math.Ceiling(dishes[i] / 10m) * 10;
            }

            ans += dishes[4];

            Console.WriteLine(ans);
        }

        public static void FiveAntennas()
        {
            int[] antennas = new int[5];
            for(int i = 0; i < 5; i++)
            {
                antennas[i] = ReadInt();
            }

            int k = ReadInt();

            string ans = "Yey!";
            if (antennas[0] + k < antennas[4])
            {
                ans = ":(";
            }

            Console.WriteLine(ans);
        }

        public static int[] ReadBinaryString()
        {
            return Console.ReadLine().Select(c => int.Parse(c.ToString())).ToArray();
        }

        public static bool[] ReadBoolArray()
        {
            return Console.ReadLine().Select(c => c == '1').ToArray();
        }

        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
    }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i =0;i<n;i++){
        cin >> h.at(i);
    }
    int count = 1;
    int h_max = h.at(0);
    for (int i =1;i<n;i++){
        if (h.at(i) >= h_max){
            count++;
            h_max = h.at(i);
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void) {
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    int A,B,C;
    A=abs(a-b);
    B=abs(b-c);
    C=abs(a-c);

    if(A<=d&&B<=d||C<=d){
        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++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define so(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pa pair
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpl;
typedef vector<vector<pair<int,int>>> vvp;


const ll mod = 1000000007;


int main()
{
    int N;
    cin >> N;
    vl A(N);
    in(N,A);
    
    vl B(100009,0);
    ll ans = 1;
    
    rep(i,N){
        if(A[i] == 0){
            ans *= (3-B[A[i]]);
            ans %= mod;
            B[A[i]]++;
        }else{
            ans *= (B[A[i]-1]-B[A[i]]);
            ans %= mod;
            B[A[i]]++;
        }
        
    }
    out(ans);
    
    
    return 0;
}



Measured memory_bytes: 1792
from collections import deque
mod = 10**9+7
N,K = map(int,input().split())
e = [[] for _ in range(N)]
d = {}
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
    d[(min(a,b),max(a,b))] = 0
ans = K
parents = deque([0])

n = [0]*N
while parents:
    p = parents.popleft()
    for c in e[p]:
        if d[(min(p,c),max(p,c))] == 0:
            d[(min(p,c),max(p,c))] = 1
            n[p] += 1
            n[c] += 1
            parents.append(c)
            ans *= K-n[p]
            ans %= mod

print(ans)

Measured memory_bytes: 82464
S = input()

counter = 0
before_chr = ''
now_chr = ''


for chr in S:
    now_chr += chr
    
    if before_chr == now_chr:
        before_chr = now_chr
        continue
        
    elif now_chr != before_chr:
        counter += 1
        before_chr = now_chr
        now_chr = ''
        continue
    
    
print(counter)

Measured memory_bytes: 3500
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}

ll X;
ll N;
vl p;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> X;
    cin >> N;
    p = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> p[i];
    }
    solve();
}

// 1 <= X <= 100
// 0 <= N <= 100
// 1 <= p_i <= 100
// p_1, \ldots, p_N はすべて異なる。
// 入力中のすべての値は整数である。

// ll X, ll N, vl p
// 答えを出力せよ。
void solve(){
    set<ll> st;
    rep(i,N)st.insert(p[i]);
    
    ll ans=-1;
    ll val=INF;
    repe(i,101){
        if(abs(X-i)>=val)continue;
        if(st.count(i))continue;
        ans=i;
        val=abs(X-i);
    }
    cout<<ans<<endl;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C;
  for (int i = 1; i <= min(A, B); i++) {
    if (A % i == 0 && B % i == 0) {
      D = i;
    }
  }
  bool E = false;
  if (A < B) {
    if (B - A > C) {
      for (int i = 0; i <= B; i++) {
        if (B - A - D * i == C) {
          cout << "YES";
          E = true;
          break;
        }
      }
      if (!E) {
        cout << "NO";
      }
    }
    else {
      for (int i = 0; i <= B; i++) {
        if (B - A + D * i == C) {
          cout << "YES";
          E = true;
          break;
        }
      }
      if (!E) {
        cout << "NO";
      }
    }
  }
  else {
    if (A - B > C) {
      for (int i = 0; i <= A; i++) {
        if (A - B - D * i == C) {
          cout << "YES";
          E = true;
          break;
        }
      }
      if (!E) {
        cout << "NO";
      }
    }
    else {
      for (int i = 0; i <= A; i++) {
        if (A - B + D * i == C) {
          cout << "YES";
          E = true;
          break;
        }
      }
      if (!E) {
        cout << "NO";
      }
    }
  }
}

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

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

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

  vector<int> d(N);
  int64_t sum = 0;
  rep(i,N){
    cin >> d.at(i);
    sum += d.at(i);
  }

  int64_t ans=0;
  for(int i=0; i<N; i++){
    ans += d.at(i) * (sum - d.at(i));
  }
  cout << ans/2;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    long long K;
    cin >> N >> M >> K;
    vector<long long> A(N), B(M), sumA(N + 1), sumB(M + 1);
    sumA[0] = 0;
    sumB[0] = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sumA[i + 1] = sumA[i] + A[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> B[i];
        sumB[i + 1] = sumB[i] + B[i];
    }
    int ans = 0;
    for (int numA = N, numB = 0; numA >= 0; --numA) {
        while (numB < M && sumA[numA] + sumB[numB + 1] <= K) {
            ++numB;
        }
        if (sumA[numA] + sumB[numB] <= K) {
            ans = max(ans, numA + numB);
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
  ll n;
  cin >>n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  ll ans=0;
  ans += a[0];
  for(int i=2; i<n; i++){
    ans += a[i/2];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int a[52][52];
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int cnt[4];
/*  ??????.->0  ?????§??£??\B,W,B&W->1,2,3  ???B,W->10,20  ?£?->30  */

void paint(int y,int x,int color){
    if(a[y][x]>=3 || a[y][x]==color)return;
    cnt[a[y][x]]--;
    a[y][x] |= color;
    cnt[a[y][x]]++;
    rep(i,4)paint(y+dy[i],x+dx[i],a[y][x]);
}

int main(void){
    int h,w;
    char c;
    while(cin>>w>>h, w|h){
        rep(i,4)cnt[i]=0;
        rep1(y,h){
            rep1(x,w){
                cin>>c;
                if(c=='.')a[y][x] = 0;
                else a[y][x] = (c=='B' ? 10 : 20);
            }
        }
        rep(y,h+2) a[y][0] = a[y][w+1] = 30;
        rep(x,w+2) a[0][x] = a[h+1][x] = 30;

        rep1(y,h)rep1(x,w)if(a[y][x]>=10)rep(i,4)paint(y+dy[i],x+dx[i],a[y][x]/10);

        cout<<cnt[1]<<" "<<cnt[2]<<endl;
    }

    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define ll long long int 
#define RD(v,n) for(ll i =0;i<n;i++ ) cin>>v[i]
#define bolt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
	bolt;
    ll k,n;
    cin>>k>>n;
    vector<ll> v(n);
    RD(v,n);	
    ll maxpath = INT_MIN;
    for(ll i=1;i<n;i++){
        maxpath = max(maxpath,v[i]-v[i-1]);
    }
    maxpath = max(maxpath,k-v[n-1]+v[0]);
    cout<<k-maxpath<<"\n";
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int H, W, h, w;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> H >> W >> h >> w;

  if ((H % h) == 0 && (W % w) == 0) {
    cout << "No" << endl;
    return 0;
  } 

  cout << "Yes" << endl;
  bool rev = false;
  if ((H % h) == 0) {
    swap(W, H);
    swap(w, h);
    rev = true;
  }
  // assert(H % h > 0);

  int c1 = 1 + 300000;
  int c2 = -h + (1 - h) * 300000;


  if (rev) {
    for(int j  = 0; j < W; ++j) {
      for(int i = 0; i < H; ++i) {
        if ((i % h) == h - 1) {
          cout << c2 << ' ';
        } else {
          cout << c1 << ' ';
        }
      }

      cout << '\n';
    }

    return 0;
  }

  // else
  for(int i = 0; i < H; ++i) {
    if ((i % h) == h - 1) {
      for(int j = 0; j < W; ++j) {
        cout << c2 << ' ';
      }
    } else {
      for(int j = 0; j < W; ++j) {
        cout << c1 << ' ';
      }
    }

    cout << '\n';
  }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

void testcase() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a < b or d < b) {
		cout << "No" << endl;
		return;
	} 
	if (b - 1 <= c) {
		cout << "Yes" << endl;
		return;
	}
	a %= b;
	// if max((a + k * d) % b) > c then no else yes
	// (a + k * gcd(b, d)) < b 	=> 	k < (b - a) / gcd(b, d)
	int g = __gcd(b, d);
	int k = (b - a + g - 1) / g - 1;
	if ((a + k * g) % b > c) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}
				
int32_t main() {
	fast_cin();  
	int T; cin >> T;
	while (T--) {
		testcase();
	}
	return 0;
}

Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int l,r;
    cin >> l >> r;
    if(l/2019 != r/2019) cout << 0 << endl;
    else {
        int ans = inf;
        rep2(i,l,r) rep2(j,i+1,r+1) {
            chmin(ans,((i%2019)*(j%2019))%2019);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 2019;

long calc(long L, long R) {
    const mod = 2019;

    long ans = int.max;
    int[int] i_used;
    for (long i = L; i <= R; i++) {
        if (i_used[i % mod]++) continue;

        int[int] j_used;
        for (long j = i + 1; j <= R; j++) {
            if (j_used[j % mod]++) continue;

            ans = min(ans, (i % mod) * (j % mod) % mod);
        }
    }
    return ans;
}

long calc1(long L, long R) {
    long ans = int.max;
    for (long i = L; i <= R; i++) {
        for (long j = i + 1; j <= R; j++) {
            long m = i * j % MOD;
            ans = min(ans, m);
            if (ans == 0) goto END;
        }
    }
END:
    return ans;
}

void main() {
    int L, R; scan(L, R);
    writeln(calc1(L, R));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;

int par[N]; //親
int depth[N]; //木の深さ
int p[N];

//要素nで初期化
void init(int n){
  for(int i = 0; i < n; i++){
    par[i] = i;
    depth[i] = 0;
  }
}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }
  else {
    return par[x] = find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return;

  if(depth[x] < depth[y]) par[x] = y;
  else {
    par[y] = x;
    if(depth[x] == depth[y]) depth[x]++;
  }
}

signed main(){

  int n,m; cin >> n >> m;
  init(n);
  for(int i = 0; i < n; i++) cin >> p[i];
  for(int i = 0; i < m; i++){
    int x,y;
    cin >> x >> y;
    unite(x,y);
  }

  int cnt = 0;
  for(int i = 0; i < n; i++){
    if( find(i+1) == find(p[i]) ) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n, m, c,sum=0,ans=0;
	int i, j, k;
	cin >> n >> m >> c;
	vector<int> b(m);
	vector<vector<int>> a(n, vector<int>(m, 0));
	for(i = 0; i < m; ++i)
		cin >> b.at(i);
	for(i = 0; i < n; ++i) {
		for(j = 0; j < m; ++j) {
			cin >> a.at(i).at(j);
		}
	}
	for(i = 0; i < n; ++i) {
		for(j = 0; j < m; ++j) {
			sum+=a.at(i).at(j)* b.at(j);
		}
		sum += c;
		if(sum > 0)
			++ans;
		sum = 0;
	}
	cout << ans << endl;
}

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

int main(){
	int n, m;
  	cin >> n >> m;
  
  	vector<P> ans;
  
  	if(n % 2){
    	for(int l = 1, r = n-1; l < r; l++, r--){
    		ans.emplace_back(l, r);
        }
    } else {
      	bool flag = false;
    	for(int l = 1, r = n-1; l < r; l++, r--){
        	if(!flag && r-l <= n/2){
              	r--;
            	flag = true; 
            }
         	ans.emplace_back(l, r);
        }
    }
  
  	rep(i, m){
    	cout << ans[i].first << " " << ans[i].second << endl;
    }
}

Measured memory_bytes: 4228
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s; cin >> s;
    vector<int> cnt('z'-'a' + 1,0);
    for(int i = 0; i < s.size(); i++)
    {
        cnt[s[i]-'a'] = 1;
    }
    int flag = 0;
    char ans;
    for(int i = 0; i < 'z'-'a' + 1; i++)
    {
        if(cnt[i] == 0)
        {
            flag = 1;
            ans = 'a' + i;
          	break;
        }
    }
    if(flag == 0)
    {
        cout << "None" << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

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

int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a_list(A);
    vector<int> b_list(B);
    vector<vector<int>> discount_list(M, vector<int>(3));

    for(int &x: a_list) cin >> x;
    for(int &x: b_list) cin >> x;
    for(vector<int> &x_list: discount_list)
        for(int &x: x_list) cin >> x;

    int a_min = *min_element(a_list.begin(), a_list.end());
    int b_min = *min_element(b_list.begin(), b_list.end());

    vector<int> results(M + 1, a_min + b_min);
    for(int i = 1; i <= M; i++) results[i] = a_list[discount_list[i-1][0]-1] + b_list[discount_list[i-1][1]-1] - discount_list[i-1][2];
    cout << *min_element(results.begin(), results.end()) << endl;
    return 0;
}

Measured memory_bytes: 6912
n,m = map(int,input().split())
c = list(range(n+1)) #色
a = [] #色ごとのリスト
for i in range(n+1):
  a.append([i])
b = [1]*(n+1) #色ごとの頂点数
p = [0]*(n+1) #位置
#print(a)
for i in range(m):
  x,y,d = map(int,input().split())
  u = c[x]
  v = c[y]
  if b[u] < b[v]:
    x,y = y,x
    u,v = v,u
    d = -d
  if u != v:
    l = d + p[x] - p[y]
    for t in a[v]:
      c[t] = u
      p[t] += l
    a[u] += a[v]
    a[v] = []
    b[u] += b[v]
    b[v] = 0
  else:
    if not p[y]-p[x] == d:
      #print(p)
      print("No")
      quit()
print("Yes")
      



Measured memory_bytes: 23796
m=[int(input()) for i in range(5)]
k = []
j=[]
for i in range(5):
    j.append(-(-m[i]//10)*10)
    
    
    t=m[i] - (m[i]//10)*10
    if t>0:
        k.append(t)
if len(k)==0:
    print(sum(j))
else:
    print(sum(j)-(10-min(k)))

Measured memory_bytes: 3316
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  int A, B;
  vector<vector<int> > friends(N);
  for(int i=0;i<M;++i) {
    cin>>A>>B;
    A--;
    B--;
    friends[A].push_back(B);
    friends[B].push_back(A);
  }
  int groups[N];
  for(int i=0;i<N;++i) groups[i] = -1;
  int group = 0;
  queue<int> que;
  int state;
  for(int i=0;i<N;++i) {
    if(groups[i]>-1) continue;
    que.push(i);
    while(!que.empty()) {
      state = que.front();que.pop();
      if(groups[state]>-1) continue;
      groups[state] = group;
      for(int j=0;j<friends[state].size();++j) {
        if(groups[friends[state][j]]>-1) continue;
        que.push(friends[state][j]);
      }
    }
    group++;
  }
  int num[group];
  for(int i=0;i<group;++i) num[i] = 0;
  for(int i=0;i<N;++i) {
    num[groups[i]]++;
  }
  int ans = 0;
  for(int i=0;i<group;++i) ans = max(ans, num[i]);
  cout<<ans<<endl;
}



Measured memory_bytes: 15576
n,m=map(int,input().split())
l=list(map(int,input().split()))
count=[0 for i in range(n)]
for i in range(n):
  count1=0 
  if i==n-1:
    pass
  else:
    for j in range(i+1,n):
      if l[i]>l[j]:
        count1+=1
  count[i]=count1
l1=sorted(l)
count2=[0 for i in range(n)]
countsub=0
for i in range(1,1+n-1):
  if l1[i]==l1[i-1]:
    count2[i]=count2[i-1]
    countsub+=1
  else:
    count2[i]=count2[i-1]+countsub+1
    countsub=0
ans=0
for i in range(n):
  ans=ans+count2[i]*(m-1)*m//2
  ans=ans+(count[i])*m
  ans%=10**9+7
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    vector<int> u(N);
    int xsum = 0;
    for(int i=0; i<N; ++i) {
        cin >> v[i];
        u[i] = v[i] ^ (v[i] - 1);
        xsum ^= v[i];
    }
    sort(u.begin(), u.end());
    u.erase(unique(u.begin(), u.end()), u.end());
    int res = 0;
    for(int i=30; i>=0; --i) {
        if(xsum & (1 << i) && binary_search(u.begin(), u.end(), (1 << (i+1)) - 1)) {
            xsum ^= (1 << (i+1)) - 1;
            res++;
        }
    }
    if(xsum != 0) {
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }
}


Measured memory_bytes: 1024