akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define ll  long long
#define out(a) printf("%d",a)
#define writeln printf("\n")
using namespace std;
int n,t,x,sum,k;
int a[233333];
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read(); 
	for (int i=1;i<=55555;i++) {
	  
	  for (int j=2;j<=55555;j++) {
	    if (j*j>i) break;
	    if (i%j==0) {
		  a[i]=1; break;
	}
  }
}

  for (int i=2;i<=55555;i++) {
    if (a[i]==0&&i%10==1) out(i),cout<<' ',t++,sum+=i,x=i;
    if (t==n) break;
  }
	return 0;
}

Measured memory_bytes: 640
s = str(input())
t = str(input())
s_dic = {}
for i in range(len(s)):
    s_dic.setdefault(s[i],0)
    s_dic[s[i]] += 1
sort_s = sorted(s_dic.items())
#print(sort_s)
t_dic = {}
for i in range(len(t)):
    t_dic.setdefault(t[i],0)
    t_dic[t[i]] += 1
sort_t = sorted(t_dic.items())
#print(sort_t)
mk_s = ''
for i in range(len(sort_s)):
    for j in range(sort_s[i][1]):
        mk_s += sort_s[i][0]
#print(mk_s)
mk_t = ''
for i in range(len(sort_t)):
    for j in range(sort_t[-(i+1)][1]):
        mk_t += sort_t[-(i+1)][0]
#print(mk_t)

if mk_s<mk_t:
    print('Yes')
else:
    print('No')

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

struct segment_tree_max{
  int n;
  std::vector<int64_t> data;
  int64_t identity;

  int64_t max(int64_t a,int64_t b){return a<b?b:a;}

  segment_tree_max(){}
  segment_tree_max(int sz,int64_t id){
    n = 1;
    while(n<sz)n*=2;
    identity = id;
    data.resize(2*n,identity);
  }
  void set(int i,int64_t val){
    i += n;
    data[i] = val;
    i /= 2;
    while(i){
      data[i] = max(data[2*i],data[2*i+1]);
      i /= 2;
    }
  }
  int64_t get_max(int l,int r){
    l += n, r += n;
    int64_t res = identity;
    while(l<r){
      if(l&1) res = max(res,data[l++]);
      if(r&1) res = max(res,data[--r]);
      l /= 2, r /= 2;
    }
    return res;
  }
  int64_t operator[](int k)const{
    return data[k+n];
  }
};

int main(){

  int n;
  std::cin>>n;
  std::vector<int64_t> h(n),a(n);
  for(auto& hi:h)std::cin>>hi;
  for(auto& ai:a)std::cin>>ai;

/*
  dp[i][j] :=  i 番目まで見て、高さが j のときの美しさの最大値
  初期値は全部 0, 更新は
  for i = 1..n:
    dp[i] = dp[i-1]
    dp[i][hi] = max(dp[i-1][0..hi]) + ai
  i 番目で更新されるのは dp[i][hi] だけなので時系列の i は不必要とわかる
  dp[k] := 高さ k の時の美しさの最大値
  for i = 1..n:
    dp[hi] = max(dp[0..hi]) + ai
  max(dp[0..hi]) を愚直に求めると全体で O(NH) かかる(H = h_i_max)
  h_i_max <= N なので O(N^2)
  ここで segment tree を使うと max(dp[0..hi]) を高速に求められ、
  O(NlogH) = O(NlogN) で解くことが出来る
*/

  segment_tree_max dp(n+1,0);

  for(int i=0;i<n;++i){
    auto& hi = h[i];
    auto& ai = a[i];
    int64_t tmp = dp.get_max(0,hi);
    dp.set(hi,tmp+ai);
  }

  int64_t ans = dp.get_max(0,n+1);
  std::cout<<ans<<std::endl;

}

Measured memory_bytes: 10368
N=gets.to_i
as=gets.split.map(&:to_i)
bs=gets.split.map(&:to_i)

l = r = 0
as.zip(bs) do |a,b|
    if a < b
        r += (b-a)/2
    elsif a > b
        l += a-b
    end
end

puts (r>=l ? 'Yes' : 'No')



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

typedef long long ll;

int main() {
	ll N, C, K; cin >> N >> C >> K;
	vector<ll>T(N); for (auto& x : T)cin >> x;
	sort(T.begin(), T.begin() + N);

	ll cnt = 1, time = T[0] + K, bus = 1;
	for (int i = 1; i < T.size(); i++) {
		if (T[i] <= time && cnt < C) { cnt++; }
		else { time = T[i] + K; cnt = 1; bus++; }		
	}
	cout << bus << endl;

	return 0;
}

Measured memory_bytes: 1024
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define LL long long

int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long a,b;
	cin>>a>>b;
	cout<<a*b/__gcd(a,b)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};
 
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 mod=1000000007;
 
int X,Y,A,B,C;
int p[100005],q[100005],r[100005];
int sum_p[100005],sum_q[100005],sum_r[100005];
int ans;

signed main(){
    cin>>X>>Y>>A>>B>>C;
    for(int i=0;i<A;++i)cin>>p[i];
    for(int i=0;i<B;++i)cin>>q[i];
    for(int i=0;i<C;++i)cin>>r[i];
    sort(p,p+A,greater<int>());
    sort(q,q+B,greater<int>());
    sort(r,r+C,greater<int>());
    priority_queue<int,vector<int>,greater<int>> pq;
    int ph=0,qh=0,rh=0;
    while(pq.size()<X+Y){
        if(qh>=Y||(p[ph]>=q[qh]&&ph<X)){
            pq.push(p[ph]);
            ph++;
        }
        else {
            pq.push(q[qh]);
            qh++;
        }
    }
    while(pq.size()){
        int v=pq.top();
        if(v>r[rh])break;
        pq.pop();
        ans+=r[rh];
        rh++;
    }
    while(pq.size()){
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7652
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	if y >= 2*x && (y-2*x)%2 == 0 && 4*x >= y && (4*x-y)%2 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1756
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
using namespace std;
const int maxn=1e6+10;
int main()
{
    int a,b;scanf("%d %d",&a,&b);
    int mid=max(a,b)-min(a,b);
    if(mid%2)
    {
        puts("IMPOSSIBLE");
    }else printf("%d\n",min(a,b)+(mid>>1));
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	int x = max(max(n, m), k);
	int y = min(min(n, m), k);
	printf("%d", x-y);
}

Measured memory_bytes: 128
# import numpy as np
# import math
import sys
input = sys.stdin.readline

s = input()

gtime = 0
ptime = 0

N = len(s) - 1
# print(N)

res = 0

for i in range(N):
    temp = s[i]
    if ptime >= gtime:
        gtime += 1
        if temp == 'p':
            res -= 1
    else:
        if temp == 'p':
            ptime += 1
        elif temp == 'g':
            ptime += 1
            res += 1
    # print(i)
    # print(gtime,ptime)

print(res)


Measured memory_bytes: 3316
'''ika tako
選ぶ個数を固定して、それ毎に結果を足し合わせればよい。
k  個の数を選ぶとき、各項に含まれる  10^100  は除いて考えても
和の個数を求める上では問題ない。
最小値は小さい方から  k  個を足し合わせた数0+1+2+…+(k-1)
初項  0 、末項  k−1 、長さ  k  の等差数列の総和なので  
k(k−1)/2 
最大値は大きい方から  k  個を足し合わせた数(N-k+1)+…+(N-1)+N
初項  N−k+1 、末項N 、長さk  の等差数列の総和なので  
k(2N−k+1)/2 
数字は1刻みで、特に選び方に制約も無いので、最小値～最大値の間の整数は全て作れる。
'''
# 累積和解法
from itertools import accumulate
 
n, k = map(int, input().split())
MOD = 10 ** 9 + 7
f_acc = [0] + list(accumulate(list(range(n + 1))))
b_acc = [0] + list(accumulate(reversed(list(range(n + 1)))))
ans = 0
for i in range(k, n + 2):
    min_ = f_acc[i]
    max_ = b_acc[i]
    ans = (ans + max_ - min_ + 1) % MOD
print(ans)

Measured memory_bytes: 37728
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 2e3+17;
LL a[MAXN],b[MAXN],dp[MAXN][MAXN];
int main(int argc ,char const *argv[])
{
	#ifdef noob
	freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
	#endif		
	int n;
	LL x;
	cin>>n>>x;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		b[i] = 0x3fffffffffffffff;
	}
	int mx=0;
	for (int i = 0; i < n; ++i)
	{
		dp[i][0] = a[i];
		for (int j = 1; j < n; ++j)
		{
			dp[i][j] = dp[i][j-1];
			if(i-j<0)
				dp[i][j] = min(dp[i][j],a[i-j+n]);
			else
				dp[i][j] = min(dp[i][j],a[i-j]);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		// debug(i);
		for (int j = 1; j < n; ++j)
		{
			dp[i][j] = min(dp[i][j-1],dp[i][j]);
			// debug(j);
			// debug(dp[i][j]);
		}
	}
	LL ans = 0x3fffffffffffffff;
	for (int i = 0; i < n; ++i)
	{
		LL tmp = i*x;
		for (int j = 0; j < n; ++j)
		{
			tmp+=min(dp[j][i],a[j]);
		}
		ans = min(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;		
}

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

using namespace std;
const int N = 2e5 + 5;
int p[N] , w[N],cnt[N];
int f(int u){
    if(u == p[u])return u;
    return p[u] = f(p[u]);
}
void connect(int a , int b){
    a = f(a);
    b = f(b);
    if(a == b)return;
    if(w[a] < w[b])swap(a,b);
    w[a] += w[b];
    p[b] = a;
}
void init(){
    for(int i = 0 ; i < N ; i++)
        p[i] = i , w[i] = 1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    init();
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        cnt[u]++;
        cnt[v]++;
        connect(u,v);
    }
    for(int i=0;i<k;i++)
    {
        int u,v;
        cin>>u>>v;
        if(f(u)==f(v))
        {
            cnt[u]++;
            cnt[v]++;
        }
    }
    for(int i=1;i<=n;i++)
        cout<<w[f(i)]-cnt[i]-1<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2816
def main():
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    aa = 0
    for x in range(len(a)):
        aa += a[x]
    bb = 0
    for x in range(len(b)):
        bb += b[x]
    if aa >= bb:
        print(aa)
    else:
        print(bb)


if __name__ == "__main__":
    main()

Measured memory_bytes: 7696
<?php
  fscanf(STDIN, "%s", $a);
  fscanf(STDIN, "%s", $b);

$count = 0;
  for($i = 0; $i < strlen($a); $i++) {
    $aa = substr($a, $i,1);
    $bb = substr($b, $i,1);
    if($aa !== $bb) {
      $count++;
    }
  }
echo $count;

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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    // s[i][j] i:m j:ki
    vector<vector<int>> s(m);
    for(int i = 0; i < m; ++i) {
        int k = 0; cin >> k;
        for(int j = 0; j < k; ++j) {
            int swt = 0; cin >> swt;
            --swt;
            s[i].emplace_back(swt);
        }
    }

    // 0:偶数個 1:奇数個
    vector<int> p(m);
    rep(m) {
        cin >> p[i];
    }

    ll ans = 0;
    // スイッチのON/OFFの全パターン
    for(int bit = 0; bit < (1 << n); ++bit) {
        // パターンが条件を満たすか
        bool judge = true;
        // 電球iの時を考える
        for(int i = 0; i < m; ++i) {
            // cout << i << " Light Bulb simulated" << endl;
            int swt = 0;
            for(auto j : s[i]) {
                // cout << Cast(10, bit) << " & " << Cast(10, (1 << j)) << endl;
                if(bit & (1 << j)) {
                    // cout << "Switch " << j << " is ON" << endl;
                    ++swt;
                }
            }

            if((swt % 2 != p[i])) {
                judge = false;
                break;
            }else {
                // cout << i << " Light Bulb is POWERED!!" << endl;
            }
        }

        if(judge) {
            // cout << "ans_bit = " << Cast(10, bit) << endl;
            ++ans;
        }
        // cout << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
        static void Main(){
            char[] c = IChars();
            char[] a = new char[2];
            if(c[0]==c[1]&&c[2]==c[3]&&c[0]!=c[2]){
                Console.WriteLine("Yes");
                return;
            }if(c[0]==c[2]&&c[1]==c[3]&&c[0]!=c[1]){
                Console.WriteLine("Yes");
                return;
                //
            }if(c[0]==c[3]&&c[1]==c[2]&&c[0]!=c[1]){
                Console.WriteLine("Yes");
                return;
                //
            }
            Console.WriteLine("No");
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = Console.ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return Console.ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return Console.ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = Console.ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = Console.ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>

int H, A[2000001];

void maxHeapify(int i){
  int l, r, largest, temp;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A[i])         largest = l;
  else                              largest = i;

  if(r <= H && A[r] > A[largest])   largest = r;

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  int i;

  for(i = H / 2; i >= 1; i--){
    maxHeapify(i);
  }
}

int main(){
  int i;
  
  scanf("%d", &H);
  for(i = 1; i <= H; i++){
    scanf("%d", &A[i]);
  }

  buildMaxHeap();

  for(i = 1; i <= H; i++)
    printf(" %d", A[i]);
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 2556
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		int answer = 0;
		String s[] = new String[3];
		Scanner sc = new Scanner(System.in);
		
		while(true){//??\???????????£????????°?????????????§?-----------+
			for(int i = 0; i<s.length; i++){
				s[i] = sc.next();
			}
			int a = Integer.parseInt(s[0]);//?¨????????????¨????????°??????int????????????
			String op = s[1];			   //?????????????????????????????¨????????????String??§
			int b = Integer.parseInt(s[2]);//?¨????????????¨????????°??????int????????????
			if(op.equals("?")){//??????\???????????????????????°????????????
				break;
			}else if(op.equals("+")){//?????????????????????
				answer=a+b;System.out.println(answer);
			}else if(op.equals("-")){
				answer=a-b;System.out.println(answer);
			}else if(op.equals("*")){
				answer=a*b;System.out.println(answer);
			}else if(op.equals("/")){
				answer=a/b;System.out.println(answer);
			}
		}//------------------------------------while?????????sc.close();//Scanner????????????????????????
	}
}

Measured memory_bytes: 26124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 0;
    rep(i,n){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, count;
    cin >> a >> b;
    for (int i=a; i<=b; i++) {
        if (i/10000 == i%10 && i%10000/1000 == i%100/10) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18

int beki(int k){
    int ret = 1;
    REP(i,k) ret*=2;
    return ret; 
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int l;
    cin >> l;
    int n=2;
    int tmp=4;
    //cout << "poi" << endl;
    while(tmp<=l){
        tmp*=2;
        n++;
    }
    int m = 2*(n-1);
    tmp =1;
    for(int i=0;i<n-1;i++){
        if((l>>i)&1==1){
            m++;
        }
    }
    cout << n << " " << m << endl;
    int lx = l;
    int count =1;
    for(int i=0;i<n-1;i++){
        cout << i+1 << " " << i+2 << " "<<0 << endl;;
        cout << i+1 << " " << i+2 << " "<<tmp << endl;
        tmp*=2;
        if((l>>i)&1==1){
            lx-=beki(i);
            cout << i+1 << " " << n << " " << lx << endl;
            
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int MAX=1e9;
const int N=2005;
char ss[N];
struct qq
{
	int x,y,last;
}e[N*2];int num,last[N];
void init (int x,int y)
{
	e[++num].x=x;e[num].y=y;
	e[num].last=last[x];
	last[x]=num;
}
int sum=0;
int dep[N],siz[N],f[N],g[N];
void DP (int x,int fa)
{
	siz[x]=ss[x]-'0';g[x]=f[x]=0;int mx=0;
	for (int u=last[x];u!=-1;u=e[u].last)
	{
		int y=e[u].y;
		if (y==fa) continue;
		dep[y]=dep[x]+1;DP(y,x);
		g[y]=g[y]+siz[y];g[x]=g[x]+g[y];
		f[y]=f[y]+siz[y];f[x]=f[x]+f[y];
		siz[x]=siz[x]+siz[y];
		if (f[y]>f[mx]) mx=y;
	}
	if (g[x]-g[mx]>=f[mx]) f[x]=(g[x])&1;
	else 
	{
		f[x]=f[mx]-(g[x]-g[mx]);
	}
	//printf("x:%d %d %d %d %d\n",x,f[x],g[x],g[mx],f[mx]);
}
int main()
{
	num=0;memset(last,-1,sizeof(last));
	int n;
	scanf("%d",&n);
	scanf("%s",ss+1);
	for (int u=1;u<n;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		init(x,y);init(y,x);
	}
	DP(2,0);
	int ans=MAX;
	for (int u=1;u<=n;u++)
	{
		dep[u]=0;DP(u,0);
		if (f[u]!=0) continue;
		sum=0;
		for (int i=1;i<=n;i++) sum=sum+(ss[i]-'0')*dep[i];
		//printf("x:%d %d\n",u,sum);
		ans=min(ans,sum);	
	}
	if (ans==MAX) printf("-1\n");
	else printf("%d\n",ans/2);
	return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  map<int, int> mps[2];
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++mps[i & 1][x];
  }
  vector<pair<int, int>> vs[2];
  for (int i = 0; i < 2; ++i) {
    for (const auto& pr : mps[i]) {
      vs[i].emplace_back(pr.second, pr.first);
    }
    vs[i].emplace_back(0, 0);
    sort(vs[i].rbegin(), vs[i].rend());
  }
  auto& a = vs[0];
  auto& b = vs[1];
  int ans = 0;
  if (a[0].second == b[0].second) {
    ans = max(a[0].first + b[1].first, a[1].first + b[0].first);
  } else {
    ans = a[0].first + b[0].first;
  }
  printf("%d\n", n - ans);
  return 0;
}


Measured memory_bytes: 6136
#include<iostream>
using namespace std;
int main(void){
    long long n,a[10000],min=1000000,max=-1000000,sum=0;
     
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]<min){min=a[i];}
    if(a[i]>max){max=a[i];}
    sum=a[i]+sum;
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    
}


Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1;i<=b;i++){
        if(a*i%b==c){
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <typeinfo>

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define all(x) (x).begin(),(x).end()
*/

using namespace std;

int h, w;
char a[105][105];

void delRow(int r){
    for (int j = 0; j < w;j++)
        a[r][j] = 'D';
}

void delColumn(int c)
{
    for (int i = 0; i < h; i++)
        a[i][c] = 'D';
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    for (int i = 0; i < h;i++)
        for (int j = 0; j < w;j++)
            cin >> a[i][j];

    bool needendl[105];
    for (int i = 0; i < 105;i++){
        needendl[i] = true;
    }
        bool allwhite;
    for (int i = 0; i < h;i++){
            allwhite = true;
        for (int j = 0; j < w;j++)
        {
            if(a[i][j]=='#')
                allwhite = false;
        }
        if(allwhite){
            delRow(i);
            needendl[i] = false;
        }
    }
    for (int j = 0; j < w; j++)
    {
        allwhite = true;
        for (int i = 0; i < h; i++)
        {
            if (a[i][j] == '#')
                allwhite = false;
        }
        if (allwhite)
            delColumn(j);
    }
    for (int i = 0; i < h;i++){
        for (int j = 0; j < w;j++){
            if(a[i][j]!='D')
                cout << a[i][j];
        }
        if(needendl[i])
            cout << endl;
    }
}

Measured memory_bytes: 256
using System;

class Program{
    public static void Main(){
        var N=int.Parse(Console.ReadLine());
        var s=Console.ReadLine().Split(' ');
        var A=new int[N];
        for(var i=0; i<N; i++){
            A[i]=int.Parse(s[i]);
        }

        var cnt=0;
        for(var i=0; i<N; i++){
            for(var j=N-1; j>i; j--){
                if(A[j]<A[j-1]){
                    cnt++;
                    var tmp=A[j];
                    A[j]=A[j-1];
                    A[j-1]=tmp;
                }
            }
        }

        for(var i=0; i<N; i++){
            if(i>=N-1){
                Console.WriteLine(A[i]);
            } else{
                Console.Write(A[i]+" ");
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 9264
H, W = map(int, input().split())

# tatewari
minD = 10 ** 9
for w in range(1, W):
    s1 = w * H
    s2 = (W - w) * (H // 2)
    s3 = (W - w) * (H - H // 2)
    if s1 * s2 * s3 > 0:
        d = max(s1, s2, s3) - min(s1, s2, s3)
        if minD > d:
            minD = d
    s2 = ((W - w) // 2) * H
    s3 = (W - w - (W - w) // 2) * H
    if s1 * s2 * s3 > 0:
        d = max(s1, s2, s3) - min(s1, s2, s3)
        if minD > d:
            minD = d

# yokowari
for h in range(1, H):
    s1 = W * h
    s2 = (H - h) * (W // 2)
    s3 = (H - h) * (W - W // 2)
    if s1 * s2 * s3 > 0:
        d = max(s1, s2, s3) - min(s1, s2, s3)
        if minD > d:
            minD = d
    s2 = ((H - h) // 2) * W
    s3 = (H - h - (H - h) // 2) * W
    if s1 * s2 * s3 > 0:
        d = max(s1, s2, s3) - min(s1, s2, s3)
        if minD > d:
            minD = d

print(minD)

Measured memory_bytes: 49628
#include<bits/stdc++.h>
using namespace std;
int INF = 1e8;
struct edge{ int to,cap,rev; };
vector<edge> G[ 20005  ];
bool used[ 20005 ];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to]&&e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)break;
    flow+=f;
  }
  return flow;
}


int H,W,si,ti;
char t[200][200];
int di[4]={-1,0,1,0};
int dj[4]={0,1,0,-1};

int main(){
  cin>>H>>W;
  si=H*W*2;
  ti=si+1;
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      
      
      cin>>t[i][j];
      
      if(i==0||j==0||i==H-1||j==W-1){
        add_edge(i*W+j+H*W,ti,INF);
      }
      
      if(t[i][j]=='X'){
        add_edge(si,i*W+j,INF);
        if(i==0||j==0||i==H-1||j==W-1){
          cout<<-1<<endl;
          return 0;
        }
        add_edge( i*W+j , i*W+j+H*W , INF );
      }else{
        add_edge( i*W+j , i*W+j+H*W , 1 );
      }

      for(int dir=0;dir<4;dir++){
        int ni=i+di[dir];
        int nj=j+dj[dir];
        if(ni<0 || nj<0 || ni>=H || nj>=W)continue;
        
        add_edge(i*W+j+H*W,ni*W+nj,INF);
      }
    }
  }

  cout<< max_flow( si,ti) <<endl;
  return 0;
}



Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
using namespace std;

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

#define PI 3.14159265358479

typedef long long ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	double v;
	while (cin >> v){
		for (int i = 0;;i++){
			if (v < 9.8*sqrt((5 * i - 5) / 4.9)){
				cout << i << "\n";
				break;
			}
		}
	}
}

Measured memory_bytes: 1232
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)

int N, a[2000001], maxv = 0;
int  ret[2000001];
int cnt[10002] = {-1};
main()
{
   scanf("%d", &N);

   rep(i, N)
      scanf("%d", a+i),
      maxv = std::max( maxv, a[i] );

   rep(i, N) ++cnt[ a[i] ];
   reps(i, 1, maxv) cnt[i] += cnt[i-1];

   for(int i=N-1; i>=0; --i){
      int& p = cnt[ a[i] ];
      ret[p] = a[i];
      --p;
   }

   rep(i, N) printf("%d%c", ret[i], i+1 < N ? ' ' : '\n' );
}




Measured memory_bytes: 18412
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
    int x;
    cin >> x;

    if(x == 7 || x == 5 || x == 3){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int K, S;
    cin >> K >> S;
    ll ans = 0;
    for (int X = 0; X <= K; X++)
    {
        for (int Y = 0; Y <= K; Y++)
        {
            int Z = S - X - Y;
            if (Z >= 0 && Z <= K)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

vector<pair<int,int>> make_seica(string str){
	vector<pair<int,int>> ret;
	if(str[0] == '0')ret.EB(1,0);
	else ret.EB(0,0);
	REP(i,str.size()-1){
		if(str[i] != str[i+1])ret.EB(str[i] - '0',i+1);
	}
	if(str[str.size() - 1] == '0')ret.EB(0,str.size());
	else ret.EB(1,str.size());
	
	while(ret.size() < 5005)ret.EB(1-ret.back().FI,str.size());
	
	return ret;
}

int solve_seica(vector<pair<int,int>> a, vector<pair<int,int>> b){
	int ret = INF;
	REP(i,a.size()){
		int now = 0;
		if(a[i].FI != b[b.size() - 1].FI)continue;
		REV(j,b.size()){
			int tmp = i - ((int)b.size() - 1 - j);
			if(tmp >= 0){
				now += (abs(a[tmp].SE - b[j].SE));
			}
			else{
				now += b[j].SE;
			}
		}
		ret = min(ret, now);
	}
	return ret;
}

int main(){
	
	int n;cin >> n;
	string s,t;cin >> s >> t;
	auto a = make_seica(s);
	auto b = make_seica(t);
		
	cout << min(solve_seica(a,b),solve_seica(b,a)) << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef MY_DEBUG_FLAG
template<typename T> void debug(T a) { cerr << a << ' '; }
template<typename T, typename U> void debug(pair<T, U> a) { cerr << a.first << ' ' << a.second << ' '; }
template<typename T> void debug(vector<T> a) { for(auto it : a) debug(it);}
template<typename T> void debug(set<T> a) { for(auto it : a) debug(it);}
#define db(a) cerr << "DEBUG ( " << #a << " == "; debug(a); cerr << ")\n"
#else
#define db(...)
#endif

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr)
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define dec(i,n,a) for(int i=(n); i>=(a); i--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()

constexpr int inf = 0x3f3f3f3f;
constexpr int MAXN = 1e5 + 10;
constexpr int mod = 1000000007;

int main() {
	int n; scanf("%d", &n);
	vector<double> p(n);
	rep(i,0,n) scanf("%lf", &p[i]);
	vector<double> dp(n+1);
	dp[0] = 1;
	rep(i,0,n) {
		vector<double> new_dp(n+1);
		new_dp[0] = dp[0]*(1-p[i]);
		rep(k,1,n+1) {
			new_dp[k] = dp[k-1]*p[i] + dp[k]*(1-p[i]);
		}
		swap(new_dp, dp);
	}
	double ans = 0;
	rep(i,0,n+1) if(i > n-i) ans += dp[i];
	printf("%.10lf\n", ans);
}


Measured memory_bytes: 3864
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    B = LIST()
    rest = 0
    count = 0
    for i in range(N):
        if A[i] <= rest:
            count += A[i]
            tmp = 0
        else:
            count += rest
            tmp = A[i] - rest
        if tmp <= B[i]:
            count += tmp
            rest = B[i] - tmp
        else:
            count += B[i]
            rest = 0
    if A[-1] <= rest:
        count += A[-1]
    else:
        count += rest
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 76416
N,K=map(int,input().split())
a=0
for i in range(K,N+2):
  minn=0
  maxx=0
  minn=int((1/2)*(i-1)*i)
  maxx=int(((1/2)*N*(N+1))-((1/2)*(N-i)*(N-i+1)))
  
  a+=maxx-minn+1
  a=int(a%(pow(10,9)+7))
 
  
print(a)

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n, 0);
    for(int i=0; i<k; i++){
    	int d;
    	cin >> d;
    	for(int j=0; j<d; j++){
    		int b;
    		cin >> b;
    		a[b-1]++;
    	}
    }
    int ans = 0;
    for(int i=0; i<n; i++){
    	if(a[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
# あなたは、X円を持ってケーキとドーナツを買いに出かけました。
# あなたはまずケーキ屋で1個A円のケーキを1個買いました。 次に、ドーナツ屋で1個B円のドーナツをできるだけたくさん買いました。
# これらの買い物のあと手元に残っている金額は何円ですか。


X = int(input()) 
A = int(input())
B = int(input())

Y = X - A # Aを1個買って、残ったお金をY円とする。

print(Y % B)  

Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
ll dp[61][1<<14];
ll pows[1<<14];
vector<ll> vec;

bool C(ll v){
	while(v>0LL){
		if(v%10LL!=2 && v%10LL!=8)return false;
		v/=10LL;
	}
	return true;
}

int main(void){
	scanf("%lld",&n);
	int cnt=0;
	while(n%2LL==0){
		cnt++;
		n/=2LL;
	}
	for(ll i=3;i*i<=n;i++){
		while(n%i==0){
			n/=i;
			vec.push_back(i);
		}
	}
	if(n!=1LL){
		vec.push_back(n);
	}
	int m=vec.size();
	for(int i=0;i<(1<<m);i++){
		ll val=1;
		for(int j=0;j<m;j++){
			if(i>>j & 1){
				val*=vec[j];
			}
		}
		pows[i]=val;
	}
	memset(dp,-1,sizeof(dp));
	if(cnt>0)dp[cnt][(1<<m)-1]=0;
	for(int i=cnt;i>0;i--){
		for(int j=0;j<(1<<m);j++){
			if(dp[i][j]==-1)continue;
			int ubit=j;
			bool fu=true;
			while(ubit!=j || fu){
				fu=false;
				ll val=pows[ubit];
				for(int k=1;k<=i;k++){
					val*=2LL;
					if(C(val)){
						dp[i-k][j-ubit]=max(dp[i-k][j-ubit],dp[i][j]+1);
					}
				}
				ubit=(ubit-1)&j;
			}
		}
	}
	printf("%lld\n",dp[0][0]);
	return 0;
} 


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

#define LINE_BUF_SIZE 32

int main(){

    int N;
    int i,j,k;
    char line[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d", &N);

    int *r_x = (int *)malloc(sizeof(int) * (N+1));  /*動的確保してみる*/
    int *r_y = (int *)malloc(sizeof(int) * (N+1)); 
    int *b_x = (int *)malloc(sizeof(int) * (N+1)); 
    int *b_y = (int *)malloc(sizeof(int) * (N+1));

    //int r_x[N+1],r_y[N+1],b_x[N+1],b_y[N+1];

    int x,y;

    for(i=1;i<=N;i++){
        fgets(line,sizeof(line),stdin);
        sscanf(line,"%d %d", &x,&y);
        r_x[i] = x;
        r_y[i] = y;
    }

    for(i=1;i<=N;i++){
        fgets(line,sizeof(line),stdin);
        sscanf(line,"%d %d", &x,&y);
        b_x[i] = x;
        b_y[i] = y;
    }

    int b_x_max = 0,max_index = 0;
    int *sorted_b_x = (int *)malloc((sizeof(int)*N));
    int *sorted_b_y = (int *)malloc((sizeof(int)*N));

    for(i=1;i<=N;i++){          /*x座標が小さい青から探索しなければならないのでソート*/
        for(j=1;j<=N;j++){
            if(b_x_max <= b_x[j]){
                max_index = j;
                b_x_max = b_x[max_index];
            }
        }
        sorted_b_x[N-i+1] = b_x[max_index];
        sorted_b_y[N-i+1] = b_y[max_index];
        b_x[max_index] = -1;
        b_y[max_index] = -1;
        max_index = 0;
        b_x_max = 0;
    }

    int max_y = 0;
    int max = 0;
    int flag = 0;
    int count = 0;

    for(i=1;i<=N;i++){
        for(j=1;j<=N;j++){
            
            if(r_x[j] <= sorted_b_x[i] && r_y[j] <= sorted_b_y[i]){   /*まずペアになれるかどうか*/
                if(r_y[j] >= max){       /*ペアの中での最大のy座標を探索*/
                    max = r_y[j];
                    max_y = j;
                    flag = 1;
                }
            }
        }

        if(flag == 1){
            r_y[max_y] = 1000;     /*pairになった赤点を除外*/
            r_x[max_y] = 1000;
            count += 1;
            flag = 0;
        }
        max  = 0;
    }

    printf("%d",count);

/*
    free(r_x);
    free(r_y);
    free(b_x);
    free(b_y);
    free(sorted_b_x);
    free(sorted_b_y);
*/
    return 0;

}

Measured memory_bytes: 128
#include <cmath>
#include <iostream>
using namespace std;
long long extgcd(long long a, long long b, long long &x, long long &y) {
	long long g = a;
	x = 1, y = 0;
	if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}
int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		long long px, py, qx, qy;
		cin >> px >> py;
		long long g = extgcd(px, py, qy, qx);
		if (g <= 50000) {
			cout << 3 << endl;
			cout << 0 << ' ' << 0 << endl;
			cout << px << ' ' << py << endl;
			cout << abs(qx) << ' ' << abs(qy) << endl;
		}
		else {
			cout << 4 << endl;
			cout << 1 << ' ' << 0 << endl;
			cout << px << ' ' << py << endl;
			cout << 0 << ' ' << 1 << endl;
			cout << px / g * (g - 1) << ' ' << py / g * (g - 1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));		
		int n = Integer.parseInt(reader.readLine());
		String[] strArray = reader.readLine().split(" ");
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(strArray[i]);
		}
		int q = Integer.parseInt(reader.readLine());
		strArray = reader.readLine().split(" ");
		for (int i = 0; i < q; i++) {
			if (solve(arr, Integer.parseInt(strArray[i]))) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}

	private static boolean solve(int[] arr, int m) {
		Map<String, Boolean> memo = new HashMap<String, Boolean>();
		return solve(0, arr, m, memo);
	}

	private static boolean solve(int i, int[] arr, int m, Map<String, Boolean> memo) {		
		String key = i + "-" + m;
		boolean res = false;
		if (memo.containsKey(key)) {
			 res = memo.get(key);
		} else if (m == 0) {
			res = true;
		} else if (i >= arr.length) {
			res = false;
		} else {
			boolean res1 = solve(i + 1, arr, m, memo);
			boolean res2 = solve(i + 1, arr, m - arr[i], memo);
			res = res1 || res2;
		}		
		memo.put(key, res);		
		return res;
	}
}


Measured memory_bytes: 101008
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;


int main()
{
	vector<char> S;
	S.resize(6);

	for (int i = 0; i < 6; i++)
		cin >> S[i];
	

	bool flag1 = false, flag2 = false;

	if (S[2] == S[3])
		flag1 = true;

	if (S[4] == S[5])
		flag2 = true;

	if (flag1 && flag2)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - *e**** ********e* *e****e* ****e**
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

char s[16];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%s%d", &n, s, &k);

  char c = s[k - 1];
  for (int i = 0; i < n; i++) putchar((s[i] == c) ? c : '*');
  putchar('\n');
  return 0;
}


Measured memory_bytes: 380
#include <cstdio>
bool A[200001],B[200001];
inline int read(){
  int ans=0,c=getchar_unlocked();
  while(c<'0'||c>'9')c=getchar_unlocked();
  while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar_unlocked();}
  return ans;
}
int main(){
  int n,m,a,b;n=read();m=read();
  while(m--){a=read();b=read();
    if(a==1)A[b]=true;
    if(b==n)B[a]=true;
  }
  for(int i=1;i<=n;i++)if(A[i]&&B[i])return puts("POSSIBLE"),0;
  puts("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 512
//بسم الله الرحمن الرحيم
//اللہ کے نام سے شروع جو بڑا مہربان اور نہایت رحم والا ہے
//Allah in the name of The Most Affectionate, the Merciful
//अल्लाह के नाम से जो दयालु और कृपाशील है
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
#include<ctime>

using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0)
#define ll long long
#define ull unsigned ll 
#define pb push_back

#define endl '\n'
#define mod 1000000007

#define FOR(i,k,n) for(int i=k; i<n; i++)
#define ROF(i,k,n) for(int i=k; i>=n; i--)
#define MEMSET(t) memset(t,0,sizeof(t));
#define time clock_t tStart
#define Start clock()
#define Time printf("Time taken: %.3fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC)



ll minC(int ar[], int n,int k, ll dp[], int i)  
{
  if(i>=n) return 0;
  if(i==n-1) return 0;
  if(dp[i]!=-1) return dp[i]; 

  int t=n;
    ll mini=INT_MAX;
  for(int j=i+1; j<=i+k && j<n ; j++) 
  {
    mini= min( abs(ar[i]-ar[j])+minC(ar,n,k,dp,j), mini); 
  //  cout<<mini<<" "<<i<<" "<< j<<endl;
  }
   dp[i] = mini;
   return dp[i];
  //return 0;
}

int main()
{
  fastio; 
  int t=1;
  while(t--)
  {
    int n,k;
    cin>>n>>k;

    int ar[n];
    ll dp[n+1];
    FOR(i,0,n) cin>>ar[i];
    memset(dp,-1,sizeof(dp));
    cout<<minC(ar,n,k,dp,0);

  }
  return 0;
}   

Measured memory_bytes: 13616
#include<iostream>
#include<bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define lli long long int
#define all(v) (v.begin(),v.end())
#define fr first
#define sc second
#define mp make_pair
using namespace std;
int wt[100],val[100];
lli dp[105][100005];
lli rec(int n,int s)
{
    if(n==0||s==0) return dp[n][s]=0;
    if(dp[n][s]!=-1) return dp[n][s];
    if(wt[n-1]>s) return dp[n][s]=rec(n-1,s);
    return dp[n][s]=max(rec(n-1,s),
               val[n-1]+rec(n-1,s-wt[n-1]));
}
int main()
{
    int n,s,i;
    cin>>n>>s;
memset(dp,-1,sizeof(dp));
    rep(i,n) cin>>wt[i]>>val[i];
    cout<<rec(n,s);
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

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

  vector<vector<int>> graph (N+1);

  int a, b;
  rep(i, 0, N - 1) {
    cin >> a >> b;
    graph[a].pb(b);
    graph[b].pb(a);
  }

  vector<ll> cnts(N+1, 0ll);

  int p;
  ll x;
  rep(i, 0, Q) {
    cin >> p;
    cin >> x;
    cnts[p] += x;
  }

  int color[N+1];
  rep(i, 0, N) {
    color[i] = 0;
  }

  queue<int> q;
  q.push(1);
  color[1] = 1;

  while (!q.empty()) {
    int u = q.front();
    q.pop();
    color[u] = 2;

    rep(j, 0, graph[u].size()) {
      int v = graph[u][j];
      if (color[v] == 2) continue;
      cnts[v] += cnts[u];
      q.push(v);
      color[v] = 1;
    }
  }

  rep(i, 0, N) {
    int num = i+1;
    cout << cnts[num] << endl;
  }
};


Measured memory_bytes: 17140
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[300010];
    cin >> N;
    rep(i,0,3*N) cin >> A[i];
    sort(A, A+3*N, greater<ll>());
    ll ans = 0;
    rep(i,0,3*N){
        if(i % 2 == 1 && i < 2*N){
            ans += A[i];
        }
    }
    print(ans);
 }

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

int main()
{
	int n; cin >> n;
	
	vector<int> a(n);
	for(int i = 0;i < n;i++)
		cin >> a[i];
	
	int min = a[0], max = a[0];
	for(int i = 1;i < n;i++){
		if(min > a[i]){
			min = a[i];
        }else if(max < a[i]){
			max = a[i];
        }
    }
    cout << max - min << endl;
}


Measured memory_bytes: 256
NN = list(input())

for i in range(2**3):
    N = NN[:]
    for j in range(3):
        if i & (1 << j):
            if j == 0:
                N.insert(1, '+')
            elif j == 1:
                N.insert(3, '+')
            else:
                N.insert(5, '+')
        else:
            if j == 0:
                N.insert(1, '-')
            elif j == 1:
                N.insert(3, '-')
            else:
                N.insert(5, '-')
    if eval(''.join(N)) == 7:
        print(''.join(N)+'=7')
        break

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
int max,a,b,i,j,k,e;
  scanf("%d %d",&a,&b);
  e=0;
int ct[a];
  for(i=0;i<a;++i)
  {ct[i]=0;
  }
int c[b];
  
  for(i=0;i<b;++i)
  {scanf("%d",&c[i]);
  int d[c[i]];
   for(j=0;j<c[i];++j)
   {
   scanf("%d",&d[j]);
      for(k=1;k<a+1;++k)
      {
      if(k==d[j]) ct[k-1]++;
      }
   }
  }

  for(i=0;i<a;++i)
  {
  if(ct[i]==0) e++;
  }
  
  printf("%d",e);
  
return 0;
}

Measured memory_bytes: 1732
from functools import *
from itertools import *
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
 
M = 10**9+7
N = int(input())

@lru_cache(maxsize=None)
def mod_inv(x):
  return 1 if x == 1 else M // x * -mod_inv(M%x) % M

Weight = [0]*(N+1)
Size = [0]*(N+1)
def calc_subtree(v):
  W, S = 1, 1
  for child in Edge[v]:
    Edge[child].remove(v)
    w, s = calc_subtree(child)
    W = W * w % M
    S += s
  Weight[v] = W * mod_inv(S) % M
  Size[v] = S
  return Weight[v], Size[v]

Ans = [0]*(N+1)
def calc_ans(v, a):
  Ans[v] = a
  for child in Edge[v]:
    n = Size[child]
    calc_ans(child, a * n * mod_inv(N-n) % M)

Edge = [set() for i in range(N+1)]
fact = N
for i in range(1, N):
  fact = fact * i % M
  a, b = map(int, input().split())
  Edge[a].add(b)
  Edge[b].add(a)
  
calc_subtree(1)
calc_ans(1, Weight[1] * fact % M)

for a in islice(Ans, 1, None):
  print(a)


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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

typedef unsigned int uint;
typedef long long ll;
typedef pair<int,int> pii;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll a[100000];
int ans[99999];
bool pushed[99999];
	stack<int> s;

void Push(int x){
	if(!pushed[x])
		s.push(x);
	pushed[x]=true;
}

int main(){
	int n=read();
	ll l=read();
	set<int> v;
	REP(i,n)
		v.insert(i);
	REP(i,n)
		a[i]=read();
	int k=0;
	REP(i,n-1)
		if(a[i]+a[i+1]>=l)
			Push(i);
	while(!s.empty()){
		int x=s.top();
		s.pop();
		auto itr=v.find(x);
		int y=*(++itr);
		ans[k++]=x;
		a[y]+=a[x];
		itr=v.erase(--itr);
		auto pr=itr;
		if(pr!=v.begin()){
			--pr;
			if(a[*pr]+a[y]>=l)
				Push(*pr);
		}
		auto nx=itr;
		if(++nx!=v.end()){
			if(a[*nx]+a[y]>=l)
				Push(y);
		}
	}
	if(k!=n-1){
		printf("Impossible\n");
	}else{
		printf("Possible\n");
		for(int i=k-1;i>=0;i--){
			printf("%d\n",ans[i]+1);
		}
	}
}


Measured memory_bytes: 7116