akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

struct Card{
	char suit;
	int value;
};

Card Input, B[36], S[36];
int N;

void BubbleSort(Card C[]){
	for(int i = 0; i < N; i++){
		for(int j = N - 1; j > i; j--){
			if(C[j].value < C[j-1].value){
				swap(C[j], C[j-1]);
			}
		}
	}
}

void SelectionSort(Card C[]){
	for(int i = 0; i < N; i++){
		int mini = i;
		for(int j = i; j < N; j++){
			if(C[j].value < C[mini].value){
				mini = j;
			}
		}
		swap(C[i], C[mini]);
	}
}

bool CompareCards(Card A[], Card B[]){
	bool ok = true;
	for(int i = 0; i < N; i++){
		if(A[i].suit != B[i].suit){
			ok = false;
		}
	}
	return ok;
}


void PrintArray(Card C[]){
	for(int i = 0; i < N; i++){
		printf("%c%d", C[i].suit, C[i].value);
		if(i == N - 1) printf("\n");
		else printf(" ");
	}
}

int main(void){
	char str[3];
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%s", str);
		Input.suit = str[0];
		Input.value = str[1] - '0';
		//printf("%c%d", Input.suit, Input.value);
		B[i] = S[i] = Input;
	}
	//PrintArray(B);
	//PrintArray(S);
	BubbleSort(B);
	SelectionSort(S);

	PrintArray(B);
	printf("Stable\n");
	PrintArray(S);
	if(CompareCards(B, S) == true) printf("Stable\n");
	else printf("Not stable\n");

	return 0;
}

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

bool isMuseisiin(char c){
  return (c == 'k' || c == 's' || c == 't' || c == 'h' || c == 'p');
}

int main(){
  string str;
  while(cin >> str && str != "#"){
    bool f[100];
    int prev[100];
    fill(f,f+100,false);
    prev[0] = -1;

    for(int i=0;i<str.size();i++){
      if(i > 0) prev[i] = prev[i-1];
      if(str[i] == 'a' || str[i] == 'i' || str[i] == 'u' || str[i] == 'e' || str[i] == 'o') prev[i] = i;

      if(i > 0 && (str[i] == 'i' || str[i] == 'u')){
	if(i < str.size() - 1 && !isMuseisiin(str[i+1])) continue;
	f[i] = (i > 1 && str[i-1] == 'y' && isMuseisiin(str[i-2]) || isMuseisiin(str[i-1]));

      } else if(i > 0 && i < str.size() - 2 && (str[i] == 'a' || str[i] == 'o')){
	bool f2 = true;
	if(!(isMuseisiin(str[i-1]) || i > 1 && str[i-1] == 'y' && isMuseisiin(str[i-2]))) f2 = false;
	if(!(str[i] == str[i+2] && isMuseisiin(str[i+1]) || i < str.size() - 3 && str[i] == str[i+3] && isMuseisiin(str[i+1]) && str[i+2] == 'y')) f2 = false;

	f[i] = f2;

      }

      if(f[i] && i > 0 && prev[i-1] != -1 && f[prev[i-1]]) f[i] = false;
    }

    for(int i=0;i<str.size();i++){
      if(f[i]) cout << '(' << str[i] << ')';
      else cout << str[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1184
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define Max 100005
using namespace std;
struct node
{
	int x;
	int y;
}data[Max];
bool cmp(node a,node b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y<b.y;
}
int n,m,Min=Max;
int main()
{
		scanf("%d%d",&n,&m);
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&data[i].x,&data[i].y);
		}
		sort(data,data+m,cmp);
		int ans=1;
		Min=data[0].y;
		for(int i=1;i<m;i++)
		{
			if(data[i].x>=Min)
			{
				ans++;
				Min=data[i].y;
			}
		}
		printf("%d\n",ans);
    return 0;
}


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

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

int main(){
  vector<char> s(4);
  for(int i=0;i<4;i++){
    cin >> s[i];
    s[i]-= '0';
  }
 
     if(10*s[0]+s[1]<=12 && s[0]+s[1]!=0){
      if(10*s[2]+s[3]<=12 && s[2]+s[3]!=0){
        cout << "AMBIGUOUS" << endl;
      }else{
        cout << "MMYY" << endl;
      }}else if(10*s[2]+s[3]<=12 && s[2]+s[3]!=0){
        cout << "YYMM" << endl;
      }else{
      cout << "NA" << endl;
      }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define DS       pair<LL, LL>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    string s;
    cin >> s;
    puts(s[0] == s[1] && s[1] == s[2] ? "No" : "Yes");
    return 0;
}


Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Combination(object):
	def __init__(self, N, con):
		self.fac = [0] * (N + 1)
		self.inv = [0] * (N + 1)
		self.finv = [0] * (N + 1)
		self.fac[0], self.fac[1] = 1, 1
		self.inv[1] = 1
		self.finv[0], self.finv[1] = 1, 1

		# 前計算
		for i in range(2, N + 1):
			self.fac[i] = self.fac[i - 1] * i % con
			self.inv[i] = self.inv[con % i] * (con - (con // i)) % con
			self.finv[i] = self.finv[i - 1] * self.inv[i] % con

	def com(self, N, k):
		return (self.fac[N] * self.finv[k] * self.finv[N - k]) % con

#処理内容
def main():
	r1, c1, r2, c2 = getlist()
	Com1 = Combination(r1 + c2 + 1, con)
	Com2 = Combination(r1 + c1, con)
	ans = 0
	val1 = Com1.com(r1 + c2 + 1, r1 + 1)
	val2 = Com2.com(r1 + c1, r1 + 1)
	ans += val1 - val2
	for R in range(r1, r2):
		inv = pow(R + 2, con - 2, con)
		val1 = (val1 * (R + c2 + 2) * inv) % con
		val2 = (val2 * (R + c1 + 1) * inv) % con
		ans += val1 - val2
		ans %= con
	
	ans %= con
	print(ans)
	 #mod conにおける逆元


	


if __name__ == '__main__':
	main()

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

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);

    int[] x = new int[2];

      while(true){

        x[0] = sc.nextInt();
        x[1] = sc.nextInt();

        if( x[0] != 0 || x[1] != 0 ){
          Arrays.sort(x);
          System.out.println( x[0] + " " + x[1] );
        }else{
          break;
        }

      }

    } 
}


Measured memory_bytes: 34552
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009

using namespace std;
using ll=long long;

class APluralForm {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin>>s;
        int n=s.length();
        if (s[n-1]=='s')s+="es";
        else s+="s";
        cout<<s;
	}
};


int main() {
	APluralForm solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;
#define ll long long int
#define ed "\n"


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	char a[1000];
	ll p = 0;


	cin>>a;
ll n = strlen(a);

	for(ll i =0;i<n;i++)
	{
		if(a[i]=='7')
		{
			p=1;
			break;
		 } 
	}
	if(p==1)
	{
		cout<<"Yes"<<ed;
	}
	else
	{
		cout<<"No"<<ed;
	}
	
	return 0;


 } 

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f,g,h,n,m;
int main()
{
  cin>>a>>b>>c>>d;
  n=abs(a-c);m=abs(b-d);
  if(a<c){
    if(b>d)cout<<c+m<<" "<<d+n<<" "<<a+m<<" "<<b+n;
    else cout<<c-m<<" "<<d+n<<" "<<a-m<<" "<<b+n;
  }else{
    if(b>d)cout<<c+m<<" "<<d-n<<" "<<a+m<<" "<<b-n;
    else cout<<c-m<<" "<<d-n<<" "<<a-m<<" "<<b-n;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if((r*100+g*10+b) % 4 == 0) System.out.println("YES");
        else System.out.println("NO");
     }
}

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

int main(){

    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, int> > > graph(N + 1);
    for(int i = 0; i < M; i++){
        int L, R, D;
        cin >> L >> R >> D;
        graph[L].push_back(make_pair(R, D));
        graph[R].push_back(make_pair(L, -D));
    }

    vector<bool> used(N + 1, false);
    vector<int> node(N + 1, 0);
    for(int i = 1; i <= N; i++){
        if(used[i]) continue;
        queue<pair<int, int> > Q;
        Q.push(make_pair(i, 0));
        while(!Q.empty()){
            int id = Q.front().first;
            int cost = Q.front().second;
            Q.pop();
            if(!used[id]){
                node[id] = cost;
                used[id] = true;
                for(int j = 0; j < graph[id].size(); j++){
                    Q.push(make_pair(graph[id][j].first, cost + graph[id][j].second));
                }
            }else{
                if(node[id] != cost){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 11252
import sys
input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    H = [int(x) for x in input().split()]

    dp = [0] * (N + 1)
    dp[2] = abs(H[0] - H[1])



    for i in range(3, N + 1):
        mi = float("inf")
        for j in range(i - 1, i - K - 1, -1):
            if j == 0:
                break
            mi = min(mi, dp[j] + abs(H[j - 1] - H[i - 1]))
        dp[i] = mi

    print(dp[N])




if __name__ == '__main__':
    main()



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

void print_vec(const std::vector<int> vec, char sep) {
  for (int i = 0; i < vec.size(); i++) {
    std::cout << vec.at(i);
    if (i < vec.size() - 1) std::cout << sep;
  }
  std::cout << std::endl;
}

void insertion_sort(std::vector<int>* pVec) {
  std::vector<int>& vec(*pVec);

  int n = vec.size();
  for (int i = 1; i < n; i++) {
    print_vec(vec, ' ');
    int val = vec.at(i);

    int j = i - 1;
    for (; j >= 0; j--) {
      if (vec.at(j) > val) {
        vec.at(j + 1) = vec.at(j);
      }
      else {
        break;
      }
    }
    vec.at(j + 1) = val;
  }
  print_vec(vec, ' ');
}

int main(void) {

  int n;
  std::cin >> n;
  std::vector<int> vals;
  for (int i = 0; i < n; i++) {
    int val;
    std::cin >> val;
    vals.push_back(val);
  }

  insertion_sort(&vals);

  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

const int MAX=100001;

int main(){
  int Q;
  cin >> Q;
  vector<bool> p(MAX+1,false);

  p[1]=true;
  p[2]=true;

  int i = 2;
  set<int> p_set;
  while(i<=MAX){
    p_set.insert(i);
    FOR(j,1,MAX){
      if(j*i>MAX)break;
      p[j*i]=true;
    }
    while(p[i]==true){
      i++;
    }
  }

  vector<int> sum(MAX+1,0);
  for(int i = 1; i <= MAX; i+=2){
    if(p_set.find(i) != p_set.end() && p_set.find((i+1)/2) != p_set.end()){
      sum[i] = 1;
    }
  }
  REP(i,MAX){
    sum[i+1] = sum[i+1]+sum[i];
  }
  REP(i,Q){
    int l,r;
    cin >> l >> r;
    cout << sum[r] - sum[l-1] << endl;
  }


}



Measured memory_bytes: 1536
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N, M;
	cin >> N >> M;
	vector<vector<LL>>A(N,vector<LL>(3));
	for (int i = 0; i < N; ++i) {
		for (int k = 0; k < 3; ++k) {
			cin >> A[i][k];
		}
	}
	LL ans = 0;
	for (int k = 0; k < (1 << 3); ++k) {
		vector<LL> B(N, 0);
		for (int i = 0; i < N; ++i) {
			LL res = 0;
			int base = 1;
			for (int j = 0; j < 3; ++j,base<<=1) {
				if (k & base) {
					res -= A[i][j];
				}
				else {
					res += A[i][j];
				}
			}
			B[i] = res;
		}
		SO(B);
		LL res = 0;
		for (int i = 0; i < M; ++i) {
			res += B[N - 1 - i];
		}
		chmax(ans, res);
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    ll n,k;
    cin >> n >> k;
    if(n>k) n=n%k;
    cout << min(k-n,n) << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll h,w,m;
  cin>>h>>w>>m;
  map<ll,ll> row,col;
  map<pair<ll,ll>,bool> field;
  for (int i = 0; i < m; ++i)
  {
    ll x,y;
    cin>>x>>y;
    x--;y--;
    field[{x,y}]=true;
    row[x]++;
    col[y]++;
  }
  
  ll max_row=0;
  ll max_col=0;
  for(const auto& e: row) 
  {
    max_row=max(max_row,e.second);
  }
  for(const auto& e: col) 
  {
    max_col=max(max_col,e.second);
  }
  ll ans=max_row+max_col;

  vector<ll> row_kouho,col_kouho;
  for(const auto& e: row) 
  {
    if(e.second==max_row)
      row_kouho.push_back(e.first);
  }
  for(const auto& e: col) 
  {
    if(e.second==max_col)
      col_kouho.push_back(e.first);
  }
  for (int i = 0; i < row_kouho.size(); ++i)
  {
    for (int j = 0; j < col_kouho.size(); ++j)
    {
      if(!field[{row_kouho[i],col_kouho[j]}])
      {
        cout<<ans<<endl;
        return 0;
      }
    }
  }
  cout<<ans-1<<endl;
}

Measured memory_bytes: 67820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn for(int i=0;i<n;i++)
#define pb push_back
#define pob pop.back()
int main()
{
 
  int n;
  cin>>n;
  int arr[n];
  forn cin>>arr[i];
  int ans=0;
  vector<int> v;
  forn
  {
      if(i!=0 && i!=n-1){
      v.clear();
      v.pb(arr[i]);
      v.pb(arr[i-1]);
      v.pb(arr[i+1]);
      sort(v.begin(),v.end());
      if(v[1]==arr[i]) ans++;}
  }
  cout<<ans;
  return 0;
   
  
  
    
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 2000

int a[N], n, sum, q, m, i;

int check(int i,int m){
  if(sum < m)return 0;
  if(m == 0)return 1;
  if(i >= n)return 0;
  return check(i+1,m) || check(i+1,m-a[i]);
}

int main(){

  sum = 0;
  scanf("%d",&n);

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

  for(i=0;i<q;i++){
    scanf("%d",&m);
    if (check(0,m)){
      printf("yes\n");
    }else{
      printf("no\n");
    }

  }
  return 0;
}

Measured memory_bytes: 2620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n;
		int K;
		int res = 0;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		K = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int h = sc.nextInt();
			if (h >= K) {
				res++;
			}
		}
		sc.close();

		System.out.println(res);
	}
}


Measured memory_bytes: 48428
import math
A, B = map(int, input().split())
value = math.ceil(A / 0.08)
limit = math.ceil((A + 1) / 0.08)
while value < limit:
    if B == int(value * 0.1):
        print(value)
        break
    value += 1
else:
    print('-1')


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int a[1100000], deq[1100000];

int main(){
	
	int n, L;
	cin >> n >> L;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	int s = 0, t = 0; // 先頭と末尾
	
	for(int i = 0; i < n; i++){
		while(s < t && a[deq[t - 1]] >= a[i]){
			t--;
		}
		deq[t] = i;
		t++;
		if(i - L + 1 >= 0){
			//cout << deq[s] << " " << i - L + 1 << endl;
			printf("%d%c", a[deq[s]], i == n - 1 ? '\n' : ' ');
			if(deq[s] == i - L + 1){
				s++;
			}
		}else{
			continue;
		}
	}
	
	return 0;
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


auto solve() {
    string s;
    cin >> s;

    int n = s.size();

    REP(j, n) {
        FOR(k, j, n) {
            stringstream ss;
            REP(i, n) {
                if(j <= i && i < k) {
                    continue;
                }
                ss << s[i];
            }
            if (ss.str() == "keyence") return true;
        }
    }

    return false;
}


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

//    cout << solve() << endl;
    cout << (solve() ? "YES" : "NO") << endl;


    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = [int(i) for i in input().split()]

answer = 0
for i in range(len(p)-2):
	if p[i+1] > min(p[i], p[i+2]) and p[i+1] < max(p[i], p[i+2]):
		answer += 1

print(answer)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int N;  ll P;
    cin >> N >> P;
    vector<ll> prime;
    vector<ll> power;
    for(ll i=2; i*i<=P; i++){
        if(P%i==0){
            prime.push_back(i);
            power.push_back(0);
        }
        while(P%i==0){
            power.back()++;
            P/=i;
        }
    }
    if(P!=1){
        prime.push_back(P);
        power.push_back(1);
    }

    int n = prime.size();
    ll ans = 1;
    for(int i=0; i<n; i++){
        if(power[i]>=N){
            ans*=pow(prime[i], power[i]/N);
        }
    }
    cout << ans << endl;
}



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

int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<long long> P(A), Q(B), R(C);
  for(auto &e : P) cin >> e;
  for(auto &e : Q) cin >> e;
  for(auto &e : R) cin >> e;
  sort(P.rbegin(), P.rend());
  sort(Q.rbegin(), Q.rend());
  sort(R.rbegin(), R.rend());
  for(int i = 1; i < C; ++i)
    R[i] += R[i-1];
  vector<long long> PQ;
  PQ.insert(PQ.end(),P.begin(),P.begin()+X);
  PQ.insert(PQ.end(),Q.begin(),Q.begin()+Y);
  sort(PQ.rbegin(), PQ.rend());
  for(size_t i = 1; i < PQ.size(); ++i)
    PQ[i] += PQ[i-1];
  long long ans = PQ.back();
  for(int i = 0; i < X+Y; ++i){
    int c = X+Y-i-2;
    if(c >= C or c < 0) continue;
    ans = max(ans, PQ[i]+R[c]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000009
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=2e5+10;
const int N=2e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
int n,m,k,t,a[maxn],b[maxn],id[maxn],ama,bma,ami=1e9,bmi=1e9,dma,dmi=1e9;
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n)
    {
        scanf("%d%d",&a[i],&b[i]);
        if(a[i]>b[i])swap(a[i],b[i]);
        id[i]=i;
        ama=max(ama,a[i]);
        ami=min(ami,a[i]);
        bma=max(bma,b[i]);
        bmi=min(bmi,b[i]);
    }
    ll ret=(ll)(ama-ami)*(bma-bmi);
    sort(id+1,id+n+1,cmp);
    rep(i,1,n)
    {
        dma=max(dma,b[id[i]]);
        dmi=min(dmi,b[id[i]]);
        ret=min(ret,(ll)(max(dma,a[id[n]])-min(dmi,a[id[i+1]]))*(bma-ami));
    }
    printf("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 2560
S = input()
if len(S)==2 and S[0]==S[1]:
    print(1,2);exit()
for i in range(len(S)-2):
    if S[i] == S[i+1] or S[i] == S[i+2] or S[i+1] == S[i+2]:
        print(i+1,i+3);exit()
print("-1 -1")

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
using namespace std;
int ans;
int w, h;
//?§???????
const int mx[] = {-1, 0, 1, -1, 1, -1, 0, 1 };
const int my[] = { 1, 1, 1, 0, 0, -1, -1, -1};
vector<int> vx;
vector<int> vy;

vector<vector<int> > area;
int islands = 0;

//????±????????????¨????????¢?´¢
void dfs(int i,int j){
	for (int n = 0; n < vx.size(); n++){
		int x = j + vx[n];
		int y = i + vy[n];
		if (x >= 0 && x < w &&
			y >= 0 && y < h &&
			area[y][x] == 1){
			area[y][x] = 2;
			dfs(y,x);
		}
	}
}

int main(){
	for (int i = 0; i < 8; i++){
		vx.push_back(mx[i]);
		vy.push_back(my[i]);
	}
	while (1){
		cin >> w >> h;
		if (w == 0 && h == 0) break;
		//?????????
		islands = 0;
		area.clear();
		area = vector<vector<int> >(h, vector<int>(w));
		//??\???
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				cin >> area[i][j];
			}
		}
		//??¨??¢?´¢
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (area[i][j] == 1){
					islands++;
					area[i][j] = 2;
					dfs(i, j);
				}
			}
		}
		cout << islands << endl;
	}
	return 0;
}

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


	int main() {
		vector<vector<int>>a(3, vector<int>(3));
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				cin >> a[i][j];
			}
		}
		int n;
		vector<vector<bool>>flag(3, vector<bool>(3, false));
		cin >> n;
		for (int ni = 0; ni < n; ni++) {
			int x;
			cin >> x;
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					for (int k = 0; k < n; k++) {
						if (a[i][j] == x)flag[i][j] = true;
					}
				}
			}
		}
		
		bool ans = false;
		for (int i = 0; i < 3; i++) {
			if (flag[i][0] && flag[i][1] && flag[i][2]) ans = true;
			else if (flag[0][i] && flag[1][i] && flag[2][i])ans = true;
			else if (flag[0][0] && flag[1][1] && flag[2][2])ans = true;
			else if (flag[0][2] && flag[1][1] && flag[2][0])ans = true;

		}
		if (ans)cout << "Yes" << endl;
		else cout << "No" << endl;
	}


Measured memory_bytes: 256
from collections import deque


def bfs(start):
    Q = deque()
    child = deque()
    Q.append(start)
    dist[start[1] - 1][start[0] - 1] = 0
    r = 0

    while Q:
        x, y = Q.popleft()
        x = x - 1
        y = y - 1

        for i in range(4):
            child.clear()
            nx = x + dx[i]
            ny = y + dy[i]

            if nx < 0 or nx >= W or ny < 0 or ny >= H:
                continue
            if G[ny][nx] == "#":
                continue
            if dist[ny][nx] != -1:
                continue

            child.append((nx + 1, ny + 1))

            if len(child) > 0:
                for c in child:
                    dist[c[1] - 1][c[0] - 1] = dist[y][x] + 1
                    Q.append(c)

    for i in range(H):
        r = max(r, max(dist[i]))
        # print(dist[i])

    return r


H, W = map(int, input().split())
G = [[] for _ in range(H)]

for i in range(H):
    G[i] = list(input())

# dist = [[-1 for _ in range(W)] for _ in range(H)]
dx = [1, 0, -1, 0]  # 斜めも含むならその方向もプラス
dy = [0, 1, 0, -1]

res = 0
for i in range(H):
    for j in range(W):
        if G[i][j] != "#":
            # print("-----------(" + str(j + 1) + "," + str(i + 1) + ")")
            dist = [[-1 for _ in range(W)] for _ in range(H)]
            start = (j + 1, i + 1)
            res = max(res, bfs(start))

print(res)


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

const int MIN = 0;
const int MAX = 10000;
const int CMAX = 3000;

void koukan(int &a, int &b)
{
    int tmp = a;
    a = b;
    b = tmp;
}

bool isIN(int v)
{
    if ((MIN <= v) && (v <= MAX))
    {
        return true;
    }
    return false;
}

bool isZero(int v)
{
    if (v == 0)
    {
        return true;
    }
    return false;
}

int main()
{
    int x, y;
    int cnt = 0;
    while (cin >> x >> y)
    {
        if (!isIN(x) || !isIN(y))
        {
            continue;
        }
        if (isZero(x) && isZero(y))
        {
            return (0);
        }
        if (++cnt > CMAX)
        {
            return (0);
        }
        if (x > y)
        {
            koukan(x, y);
        }
        cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 3056
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

#define MAXNUM 128
int npow(int a, int n){
  if(n == 0) return 1;
  else return a * npow(a, n-1);
}

bool is_num(char c){
  if( c >= '0' && c <= '9') return true;
  else return false;
}
int main(void){
  int c = 0;

  while(true){
    string buf[3];

    if(c == EOF) break;
    for(int j = 0; j < 3; j++){
      for(int i = 0; i < MAXNUM; i++){
        c = getchar();
        if(c == EOF) goto END;
        if(c == '+' || c == '=' || c == '\n')
          break;
        buf[j].push_back(c);
      }
    }
    int x = 0;
    for(int j = 0; j < 3; j++){
      if(buf[j][0] == 'X' && buf[j][1] != '\0') {
        x = 1;
        break;
      }
    }
    for(; x <= 9; x++){
      int num[3] = {0, 0, 0};
      for(int j = 0; j < 3; j++){
        int lngth = buf[j].length();
        for(int i = 0; i < lngth; i++){
          if(buf[j][i] == 'X') num[j] += x * npow(10, lngth-1-i);
          else num[j] += (buf[j][i]-'0') * npow(10, lngth-1-i);
        }
      }
      if(num[0] + num[1] == num[2]){
        break;
      }
    }
    if(x == 10) cout << "NA" << endl;
    else cout << x << endl;
  }
END:
  return 0;
}

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

using namespace std;

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;
static const int MAX_N = 100005;

int n, m, c, d[MAX_N], cumu[MAX_N], visit[MAX_N];
vector<pii> G[MAX_N], res;

void dijkstra() {
  fill(d, d + MAX_N, INF);
  priority_queue<pii, vector<pii>, greater<pii> > q;
  d[1] = 0;
  q.push(pii(0, 1));

  while (q.size()) {
    pii p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    for (int i = 0; i < G[v].size(); ++i) {
      pii e = G[v][i];
      int to = e.first, cost = e.second;

      if (d[to] < cost + d[v]) continue;
      d[to] = cost + d[v];
      q.push(pii(d[to], to));
    }
  }
}

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

  cin >> n >> m >> c;
  for (int i = 0; i < m; ++i) {
    int a , b, d;
    cin >> a >> b >> d;
    G[a].PB(pii(b, d));
    G[b].PB(pii(a, d));
  }

  dijkstra();

  for (int i = 1; i <= n; ++i) {
    res.PB(pii(d[i], i));
  }
  sort(res.begin(), res.end());

  for (int i = res.size() - 1; 0 <= i; --i) {
    int v = res[i].second;
    visit[v] = true;
    cumu[i] += cumu[i + 1];
    for (int j = 0; j < G[v].size(); ++j) {
      int to = G[v][j].first;
      if (visit[to]) continue;
      cumu[i] += G[v][j].second;
    }
  }

  int ans = INF;
  for (int i = 0; i < res.size(); ++i) {
    int temp = res[i].first * c, v = res[i].second;

    temp += cumu[i + 1];
    ans = min(ans, temp);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 19720
n = int(input())
num = list(map(int,input().split()))
lis = [0]*(max(num)+4)
for i in num:
    if i == 0:
        lis[i] +=1
        lis[i+1] +=1
    else:
        lis[i-1] +=1
        lis[i] +=1
        lis[i+1] +=1
    
print(max(lis))


Measured memory_bytes: 20816
//include
//------------------------------------------
#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;




//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main() {
	char n[5];
	REP(i, 4) {
		cin >> n[i];
	}

	if ((n[0] == n[1] && n[1] == n[2]) ||( n[1] == n[2]&& n[2]== n[3])) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String n = sc.next();
        int len = n.length();

        String[] arr = new String[len];
        for (int i=0; i<len; i++) arr[i] = n.substring(i, i+1);

        long[][] dp = new long[len+1][2];
//        long[] dpPay = new long[len];
//        long[] dpChange = new long[len];
        dp[0][0] = 0;
        dp[0][1] = 1;

//        dp[0][0] = Integer.parseInt(arr[0]);
//        dp[0][1] = (Integer.parseInt(arr[0])+1)==10 ? 1 : Integer.parseInt(arr[0])+1;

//        System.out.println(dp[0][0]);
//        System.out.println(dp[0][1]);

//        if (Integer.parseInt(arr[0])<=5){
//            dpSum[0] = Integer.parseInt(arr[0]);
//        }else if (6<=Integer.parseInt(arr[0])){
//            dpSum[0] = 11 - Integer.parseInt(arr[0]);
//        }

//        System.out.println(dpSum[0]);

        for (int i=1; i<len+1; i++){
            int tmp = Integer.parseInt(arr[i-1]);

            dp[i][0] = Math.min(dp[i-1][0]+tmp, dp[i-1][1]+10-tmp);
            dp[i][1] = Math.min(dp[i-1][0]+tmp+1, dp[i-1][1]+9-tmp);
        }

        System.out.println(dp[len][0]);
//        System.out.println(dpSum[len-1]);
    }
}


Measured memory_bytes: 167016
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let _n = input::<usize>();
    let s = input::<String>()
        .chars()
        .map(|c| c as u8)
        .collect::<Vec<u8>>();

    let mut ans = 0;
    for i in 1..s.len() - 1 {
        let x = &s[..i];
        let y = &s[i..];
        let mut cnt = 0;
        for c in 'a' as u8..'z' as u8 + 1 {
            if x.contains(&c) && y.contains(&c) {
                cnt += 1;
            }
        }
        ans = std::cmp::max(ans, cnt);
    }
    println!("{}", ans);
}


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

int main() {
  string S;
  cin >> S;
  int ans = -1;
  for (int i = 0; i < S.size() - 2; i++) {
    if (ans == -1) ans = abs(753 - stoi(S.substr(i, 3)));
    ans = min(ans, abs(753 - stoi(S.substr(i, 3))));
  }
  cout << ans << endl;
}

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

int main() {
  int N, K, ret = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (K < ret) {
      ret += K;
    } else {
      ret *= 2;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 384
from itertools import groupby
def main():
    _=input()
    vv=list(map(int,input().split()))
    ve=sorted(vv[0::2])
    vo=sorted(vv[1::2])
    le=len(set(ve))
    lo=len(set(vo))
    if le==lo==1:
        if ve[0]!=vo[0]:
            print(0)
            return
        else:
            print(len(ve))
            return
    if le==1 or lo==1:
        if lo==1:
            ve,vo=vo,ve
        c=0
        for k,g in groupby(vo):
            if k!=ve[0]:
                lg=len(list(g))
                if lg>c:
                    c=lg
        print(len(vo)-c)
        return
    ce=0
    ke=None
    for k,g in groupby(ve):
        lg=len(list(g))
        if lg>ce:
            ke=k
            ce=lg
    co=0
    ko=None
    for k,g in groupby(vo):
        lg=len(list(g))
        if lg>co:
            ko=k
            co=lg
    if ke!=ko:
        print(len(vo)*2-ce-co)
        return
    if ce<co:
        ke,ko=ko,ke
        ve,vo=vo,ve
        ce,co=co,ce
    if ce > co:
        c=0
        for k,g in groupby(vo):
            if k!=ke:
                lg=len(list(g))
                if lg>c:
                   c=lg
        print(len(vo)*2-c-ce)
        return
    ce2=0
    for k,g in groupby(ve):
        if k!=ke:
            lg=len(list(g))
            if lg>ce2:
               ce2=lg
    co2=0
    for k,g in groupby(vo):
        if k!=ko:
            lg=len(list(g))
            if lg>co2:
               co2=lg
    print(len(vo)*2-ce-max(ce2,co2))

main()

Measured memory_bytes: 14008
#include <iostream>

using namespace std;

int main()
{
	int n;
	long long arr[55];
	long long sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> arr[i];
		for (int j = 1; j < i; j++) {
			sum += arr[i] * arr[j];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    int n;
    cin >> n;
    cout << (n+1)*n/2 << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define trace(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 sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
template <typename T, typename U>
T max(T x, U y)
{
    return x>y ? x : y;
}
template <typename T, typename U>
T min(T x, U y)
{
    return x<y ? x : y;
}
ll dp[3001][3001];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);string ans;
    string s,t;cin >> s >> t;ll n=s.size();ll m=t.size();
    for (int i = 0; i <=n; ++i)
    {
    	for (int j = 0; j <=m; ++j)
    	{
    		if(i==0 or j==0)dp[i][j]=0;
    		else if(s[i-1]==t[j-1])dp[i][j]=1+dp[i-1][j-1];
    		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    	}
    }
    ll i=n;ll j=m;
    while(i>=1 and j>=1)
    {
    	if(s[i-1]==t[j-1]){ans+=s[i-1];i--;j--;}
    	else if(dp[i][j-1]>dp[i-1][j])j--;
    		else i--;
    }
    reverse(ans.begin(),ans.end());cout<<ans;
    //cout << dp[n][m];
    }

Measured memory_bytes: 70656
s = input()

flg = 0
try:
	while flg == 0:
		if s[0] == "d":
			if s[:5] == "dream":
				if s[5] == "d":
					s = s[5:]
				elif s[5:7] == "er":
					if s[7] == "a": # erase(r)
						s = s[5:]
					elif len(s) == 7 or s[7] == "d" or s[7] == "e": #dreamer
						s = s[7:]
					else:
						flg = 1
				else:
					flg = 2
			else:
				flg = 3
		elif s[0] == "e":
			if s[:5] == "erase" and (len(s) == 5 or s[5] == "d" or s[5] == "e"):
				s = s[5:]
			elif s[:6] == "eraser" and (len(s) == 6 or s[6] == "d" or s[6] == "e"):
				s = s[6:]
			else:
				flg = 4
		else:
			flg = 7
	if flg != 0:
		#print(flg)
		print("NO")
except IndexError:
	if len(s) == 0:
		print("YES")
	elif s == "dream" or s == "dreamer" or s == "erase" or s == "eraser":
		print("YES")
	else:
		print("NO")



Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll a[n];
    ll sum[n];
    rep(i, 0, n){
        cin >> a[i];
    }

    ll ans = 0;
    map<ll, ll> num;
    sum[0] = a[0] % m;
    num[sum[0]]++;
    if(sum[0] == 0){
        ans += num[sum[0]];
    }
    rep(i, 0, n - 1){
        sum[i + 1] = (sum[i] + a[i + 1]) % m;
        num[sum[i + 1]]++;
        if(sum[i + 1] == 0){
            ans += num[sum[i + 1]];
        }else{
            ans += num[sum[i + 1]] - 1;
        }
    }

    cout << ans << endl;


}


Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

struct unionfind {
    vector<long long> par,_size;
    unionfind(long n) : par(n), _size(n,1) {
        for(long long i=0; i<n; i++) par[i]=i;
    }
    void init(long long n) {
        par = vector<long long>(n);
        _size = vector<long long>(n);
        for(long long i=0; i<n; i++) par[i]=i;
    }
    long long root(long long x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(long long x, long long y) {
        x = root(x);
        y = root(y);
        if (x==y) return false;
        if(_size[x]<_size[y]) swap(x,y);
        _size[x] += _size[y];
        par[y] = x;
        return true;
    }
    bool issame(long long x, long long y) { return root(x) == root(y); }
    long long size(long long x) { return _size[root(x)]; }
};

int main() {
    int n,m,k;
    cin >> n >> m >> k;
    unionfind friends(n+1);

    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(k);
    vector<int> d(k);

    for (int i=0; i<m; i++) cin >> a[i] >> b[i];
    for (int i=0; i<k; i++) cin >> c[i] >> d[i];

    for (int i=0; i<m; i++) friends.merge(a[i],b[i]);

    vector<int> ans(n+1, 0);
    for (int i=1; i<=n; i++) ans[i] = friends.size(i) - 1;

    for (int i=0; i<m; i++) {
        ans[a[i]]--;
        ans[b[i]]--;
    }

    for (int i=0; i<k; i++) {
        if (friends.issame(c[i], d[i])) {
            ans[c[i]]--;
            ans[d[i]]--;
        }
    }

    for (int i=1; i<=n; i++) {
        cout << ans[i] << (i!=n? ' ' : '\n');
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include<cmath>
#include<vector>
using namespace std;

int main(void) {
	int N,ans=0;
	cin >> N;

	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N-1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N-1; i++) {
		cin >>C[i];
	}

	int a;

	for (int i = 0; i < N; i++) {
		a = A[i] - 1;
		ans += B[a];
		if (i != 0 && A[i] -1 == A[i - 1]) {
			ans += C[A[i - 1]-1]; //1個まえの配列参照
		}

		//cout << ans<<endl;
	}

	cout << ans;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = {}
    for i in range(n):
        if a[i] in cnt.keys():
            cnt[a[i]] += 1
        else:
            cnt[a[i]] = 1
    q = int(input())
    s = sum(a)
    for i in range(q):
        b,c = map(int,input().split())
        if b in cnt.keys():
            if c in cnt.keys():
                cnt[c] += cnt[b]
            else:
                cnt[c] = cnt[b]
            s += cnt[b]*(c-b)
            cnt[b] = 0
            print(s)
        else:
            print(s)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20980
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k, q; cin >> n >> k >> q;
    int arr[q]; for(auto &i : arr) cin >> i;
    int cnt[n]{}; for(auto i : arr) ++cnt[i - 1];
    for(auto i : cnt) cout << (k + i - q > 0 ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>

typedef long long ll;

using namespace std;

int main(){
  string str;
  cin >> str;
  char moji[(int)str.size()-7];
  int count=0;
  for(int i = 0; i < (int)str.size()-8; ++i){
    moji[i] = str[i];
    count++;
  }
  for(int i = 0; i < count; ++i){
    cout << moji[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int r=0;
	rep(i,s.size()){
		r+=int(s[i]-'0');
		r%=9;
	}
	if(r==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

int main(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	Yes((a + d - 1)/ d >= (c + b - 1) / b);
}

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

using namespace std;

long long a, b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> a >> b;
    long long gc = __gcd(a, b);
    if(gc == 1){
        cout << gc << endl;
    } else {
        set<long long> st;
        while(gc % 2 == 0){
            st.insert(2);
            gc /= 2;
        }

        for(long long i = 3; i * i <= gc; i += 2){
            while(gc % i == 0){
                st.insert(i);
                gc /= i;
            }
        }

        if(gc > 2){
            st.insert(gc);
        }

        st.insert(1);
        cout << st.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int c=1;
    REP(i,n-1){
        if(s[i]!=s[i+1])++c;
    }
    cout<<c<<endl;
}


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

using namespace std;

int n,k,q[110];
int mem[110][5][5];
static const int mod = 10000;
int dfs(int day,int p,int pp){
    int ans=0;
    if(day==0)return 1;
    if(mem[day][p][pp]!=-1)return mem[day][p][pp];
    if(q[day]!=0){
        if(p==pp&&q[day]==p)return 0;
        ans=dfs(day-1,q[day],p);
        return mem[day][p][pp]=ans;
    }
    for(int i=1;i<=3;i++){
        if(p==pp&&p==i) continue;
        ans+=dfs(day-1,i,p);
    }
    ans=ans%mod;
    mem[day][p][pp]=ans;
    return ans;
}

signed main(){
    cin>>n>>k;
    memset(mem,-1,sizeof(mem));
    int a,b;
    for(int i=1;i<=k;++i){
        cin>>a>>b;
        q[a]=b;
    }
    cout<<dfs(n,0,0)<<endl;
}

Measured memory_bytes: 1188