akhauriyash/Code-Regression huggingface dataset:
// AOJ ALDS1_5_B Merge Sort
// 2018.4.30 bal4u
 
#include <stdio.h>
#include <string.h>
 
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
char buf[20];
void mypr(int n)
{
    int w;
    if (!n) { pc('0'); return; }
    w = 0; while (n) buf[w++] = n%10 + '0', n/=10;
    while (w--) pc(buf[w]);
}
 
#define MAX_N 500002
#define INF   0x7f7f7f7f
 
int a[MAX_N];
int w[MAX_N/2+2];
int cnt;
 
void merge_sort(int low, int high) 
{ 
    int i, j, k, p, mid; 
 
    if (low < high) {
        mid = (low + high) >> 1;
        merge_sort(low,   mid);
        merge_sort(mid+1, high);
 
cnt += high-low+1;
 
        p = mid-low+1;
        memcpy(w, a+low, p << 2);
        i = mid+1, j = 0; k = low;
 
        w[p] = INF;
        while (i <= high) {
            if (w[j] <= a[i]) a[k++] = w[j++];
            else              a[k++] = a[i++];
        }
        memcpy(a+k, w+j, (p-j) << 2);
    }
}
 
int main()
{
    int n, i;
     
    n = in(); for (i = 0; i < n; i++) a[i] = in();
 
    cnt = 0;
    merge_sort(0, n-1);
 
    mypr(a[0]); for (i = 1; i < n; i++) pc(' '), mypr(a[i]); pc('\n');
    mypr(cnt); pc('\n');
    return 0;
}


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

int n,m,cnt;
int x[1010],y[1010];

inline int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0' || c>'9') {if (c=='-') f=0;c=getchar();}
	while (c>='0' && c<='9') x=x*10+(c^48),c=getchar();
	return f?x:-x;
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	{
		x[i]=read(),y[i]=read();
		if ((x[i]+y[i])&1) cnt--;
		else cnt++;
	}
	if (abs(cnt)!=n) {printf("-1\n");return 0;}
	m=31+(cnt>0);
	printf("%d\n",m);
	for (int i=0;i<=30;i++) printf("%d ",1<<i);
	if (cnt>0) printf("1 ");
	printf("\n");char s[40];
	for (int i=1;i<=n;i++)
	{
		memset(s,0,sizeof(s));
		int X=x[i],Y=y[i];
		bool flag=0;
		if (cnt>0) s[31]='R',X--;
		for (int j=30;j>=0;j--)
		{
			if (abs(X)<abs(Y)) swap(X,Y),flag^=1;
			if (X>0) X-=1<<j,s[j]=flag?'U':'R';
			else X+=1<<j,s[j]=flag?'D':'L';
		}
		printf("%s\n",s);
	}
}

Measured memory_bytes: 256
num = map(int, raw_input().split())
W = num[0]
H = num[1]
x = num[2]
y = num[3]
r = num[4]

if x-r >= 0 and x+r <= W:
    if y-r >= 0 and y+r <= H:
        print "Yes"
    else:
        print "No"
else:
    print "No"

Measured memory_bytes: 6460
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)

ll A,B,C,D;

int main(){
  std::cin >> A >> B >> C >> D;
  ll ans;
  ll sum = B - A + 1;

  if(C<D) swap(C,D);
  ll m = C,n = D;
  while(m%n!=0){
    ll tmp = m;
    m = n;
    n = tmp%n;
  }
  ll CD = C*D/n;
  ll lC = (A-1) / C;
  ll uC = B / C;
  ll nC = uC - lC;
  ll lD = (A-1) / D;
  ll uD = B / D;
  ll nD = uD - lD;
  ll lCD = (A-1) / CD;
  ll uCD = B / CD;
  ll nCD = uCD - lCD;
  //cout << nC << ' ' << nD << ' ' << nCD << endl;
  cout << sum - (nC + nD - nCD) << endl;
  
  return 0;
}


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

int main() {
  
  int A=0, B=0, C=0, D=0;
  
  cin >> A >> B >> C >> D;
  
  int sum1 = A + B;
  int sum2 = C + D;
  
  if( sum1 < sum2 ) {
    
    cout << "Right" << endl;
    
  } else if( sum2 < sum1 ) {
    
    cout << "Left" << endl;
    
  } else if( sum1 == sum2 ) {
    
    cout << "Balanced" << endl;
    
  }
  
  return 0;
  
}
  

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N;
    int sum = 0;
    int m = 0;
    cin >> N;
    for (size_t i = 0; i < N; i++) {
        int L;
        cin >> L;
        sum += L;
        m = max(m, L);
    }
    if (m < sum - m) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, ans=1;
	int A[100005];

	cin >> N;
	rep(i,N) cin >> A[i];

	int d = 0;
	rep(i,N-1){
		if( A[i] < A[i+1] ){
			if( d == -1 ){
				ans++;
				d = 0;
			}else{
				d = 1;
			}
		}
		if( A[i] > A[i+1] ){
			if( d == 1 ){
				ans++;
				d = 0;
			}else{
				d = -1;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
var
 i,n:longint;
 a:array[0..202] of string;
 procedure sort(l,r: longint);
      var
         i,j: longint;
         x,y:string;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
begin
 readln(n);
  for i:=1 to n do
     readln(a[i]);
      sort(1,n);
  for i:=1 to n do write(a[i]);
end.

Measured memory_bytes: 128
n,k=map(int,input().split())
m=(n-1)*(n-2)//2
if k>m:
    print(-1)
else:
    l=m-k
    lst=[]
    for i in range(1,n):
        lst.append([i,n])
    for i in range(1,n):
        for j in range(i+1,n):
            if l==0:
                break
            lst.append([i, j])
            l-=1
        else:
            continue
        break
    print(len(lst))
    for a,b in lst:
        print(a,b)

Measured memory_bytes: 45168
#include <bits/stdc++.h>
const int N=400005;
using namespace std;
typedef pair<int,int> pii;
int n,m,dp[N],cur;
vector<pii>g[N];
void add(int pos,int val){
    while(pos<N){
        dp[pos]+=val;
        pos+=pos&(-pos);
    }
}
int get(int pos){
    int ans=0;
    while(pos){
        ans+=dp[pos];
        pos-=pos&(-pos);
    }
    return ans;
}
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    cin>>n>>m;
    cur=n;
    for(int i=1;i<=n;i++){
        int l,r;cin>>l>>r;
        g[r-l+1].push_back({l,r});
    }
    for(int i=1;i<=m;i++){
        int v=cur;
        for(int j=0;j<N;j+=i)v+=get(j);
        cout<<v<<'\n';
        for(auto el:g[i]){
            cur--;
            add(el.first,1);
            add(el.second+1,-1);
        }
    }
    return 0;
}


Measured memory_bytes: 17872
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd_ll(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int fiv(int n){
  if(n==0){
    return 0;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}
int main(){
  ll n,k;
  cin>>n>>k;
  if(k%2 !=0) cout <<ll((n/k)*(n/k)*(n/k))<<endl;
  else if(k%2 ==0) cout<< (n/k)*(n/k)*(n/k)  +(-n/k+n/(k/2))*(-n/k+n/(k/2))*(-n/k+n/(k/2)) <<endl;
}





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

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;

ll r1, r2, c1, c2;
ll fac[2000005];
ll fiv[2000005];

ll C(ll p, ll q)
{
    return fac[p] * fiv[q] % M * fiv[p - q] % M;
}

int main()
{
    scanf("%lld%lld%lld%lld", &r1, &c1, &r2, &c2);
    r2++, c2++;
    fac[0] = 1;
    fiv[r2 + c2] = 1;
    for(ll i = 1; i <= r2 + c2; i++) fac[i] = fac[i - 1] * i % M;
    ll now = fac[r2 + c2];
    for(ll i = 0; (1 << i) <= (M - 2); i++)
    {
        if((1 << i) & (M - 2)) fiv[r2 + c2] *= now, fiv[r2 + c2] %= M;
        now *= now;
        now %= M;
    }
    for(ll i = r2 + c2 - 1; i >= 0; i--)
    {
        fiv[i] = fiv[i + 1] * (i + 1) % M;
    }
    ll ans = 0;
    ans += C(r2 + c2, r2);
    ans -= C(r2 + c1, r2);
    ans -= C(r1 + c2, r1);
    ans += C(r1 + c1, r1);
    ans += 2 * M;
    ans %= M;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 31488
import java.util.*

fun main(args:Array<String>){
    val (n,k) = readLine()!!.split(" ").map{it.toInt()}
    val a = readLine()!!.split(" ").map{it.toLong()}
    var b = LongArray(n * (n + 1) / 2)
    var it = 0
    for(i in 0 until n){
        var sum = 0L
        for(j in i until n){
            sum += a[j]
            b[it] = sum
            it++
        }
    }
    var ans = 0L
    var t = 1L shl 62
    var t1 = 62
    var c = BooleanArray(b.size){true}
    while(t > 0){
        var cnt = 0
        for(i in 0 until b.size){
            if(c[i] && (b[i] shr t1) and 1 == 1L) cnt++
        }
        if(cnt >= k){
            for(i in 0 until b.size){
                if(c[i] && (b[i] shr t1) and 1 == 0L) c[i] = false
            }
            ans += t
        }
        t /= 2
        t1--
    }
    println(ans)
}


Measured memory_bytes: 39136
/* ex4_3
  terakura */

#include <stdio.h>

int depth(int west_height, int east_height);

int main(void){
    int west_height, east_height;
    scanf("%d %d", &west_height, &east_height);

    printf("%d\n", depth(west_height, east_height));

    return 0;

}


int depth(int west_height, int east_height){
    int diff, ans, hei ;
    diff = east_height - west_height;   //高さの差
    int i;
    for(i=0; i < diff + 1; i++){
        hei = hei + i;      //east_heightの実際の高さ A(n)=A(n-1) + n
    }

    ans = hei - east_height;    //実際の高さから見えている高さをひく

    return ans;

}


Measured memory_bytes: 128
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=21,M=(1<<16)+5;
int f[N][M],a[N],sz[M],fac[M],ifac[M],n,m,lim,res;
inline void init(int n){
	fac[0]=ifac[0]=1,sz[0]=0;
	fp(i,1,n)fac[i]=1ll*fac[i-1]*i%P,sz[i]=sz[i>>1]+(i&1);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=1ll*ifac[i+1]*(i+1)%P;
}
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d",&n,&m),lim=(1<<n);
	init(lim);
	fp(i,1,m)scanf("%d",&a[i]);
	f[m+1][0]=1;
	fd(i,m,1)fp(s,0,lim-1)if(f[i+1][s]){
		upd(f[i][s],f[i+1][s]);
		R int p=lim-1-s,coef=f[i+1][s];
		fp(j,0,n-1)if(s>>j&1^1)upd(f[i][s|(1<<j)],1ll*coef*C(p-a[i]+1,(1<<j)-1)%P*fac[1<<j]%P);
	}
	fp(i,0,lim-1){
		R int ret=1ll*f[1][i]*fac[lim-1-i]%P;
		upd(res,sz[i]&1?P-ret:ret);
	}
	res=1ll*res*lim%P;
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 6144
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int flag = 1;
  int n;
  int *a;
  int i,j;
  int temp;
  int count = 0;
  
  scanf("%d",&n);
  a = (int *)malloc(sizeof(int) *n);
  
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }

  while(flag){
    flag = 0;
    for(j=(n-1); j>=1; j--){
      if(a[j] < a[j-1]){
	temp = a[j];
	a[j] = a[j-1];
	a[j-1] = temp;
	flag = 1;
	count ++;
      }
    }
  }

  for(i=0; i<n; i++){
    printf("%d",a[i]);
    if(i != (n-1)){
      printf(" ");
    }
  }
  printf("\n%d\n",count);

  free(a);
  
  return(0);
}

Measured memory_bytes: 604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong();
		long a = scanner.nextLong();
		long b = scanner.nextLong();
		if ((a - b) % 2 == 0) {
			System.out.println(Math.abs(a - b) / 2);
			return;
		}
		System.out.println(Math.min((a+b-1)/2,(2*n-a-b+1)/2));

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <map>
#include <queue>

using namespace std;


class Insect{
public:
  string body;
  int sec;
  Insect(string body, int sec): body(body), sec(sec) {}
};

bool isOneColor(string str) {
  char c = str[0];
  for(int i = 1; i < str.length(); i++) {
    if(str[i] != c) return false;
  }
  return true;
}

int main() {
  while(1) {
    string str;
    getline(cin, str);
    if(str == "0") break;

    map<string, bool> visited;
    queue<Insect> Q;
    Q.push(Insect(str, 0));
    visited[str] = true;

    int sec = -1;
    while(!Q.empty()) {
      Insect s = Q.front();
      Q.pop();
      
      if(isOneColor(s.body)) {
	sec = s.sec;
	break;
      }

      for(int i = 0; i+1 < s.body.length(); i++) {
	if(s.body[i] != s.body[i+1]) {
	  string temp = s.body;
	  if(s.body[i] != 'r' && s.body[i+1] != 'r')
	    temp[i] = temp[i+1] = 'r';
	  if(s.body[i] != 'g' && s.body[i+1] != 'g')
	    temp[i] = temp[i+1] = 'g';
	  if(s.body[i] != 'b' && s.body[i+1] != 'b')
	    temp[i] = temp[i+1] = 'b';

	  if(!visited[temp]) {
	    Q.push(Insect(temp, s.sec+1));
	    visited[temp] = true;
	  }
	}
      }
    }

    if(sec == -1) {
      cout << "NA" << endl;
    } else {
      cout << sec << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main() {
	int N, X, Y;

	cin >> N >> X >> Y;

	vector<int> count(N, 0);

	for (int i = 1; i < N; i++)
	{
		for (int j = i + 1; j <= N; j++) {
			//i,jの最短距離を求める
			if (i <= X) {
				if (j >= Y)
					count[j - Y + 1 + X - i]++;
				else
					count[min(j - i, Y - j + 1 + X - i)]++;
			}
			else if (i < Y) {
				count[min(j - i, (i - X) + 1 + abs(j - Y))]++;
			}
			else {
				count[j - i]++;
			}
		}
	}

	for (int i = 1; i < N; i++) {
		cout << count[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

N,S = MI()
A = LI()
dp = FILL2(0,N+1,S+1)
for i in range(N):
    for j in range(S+1):
        if j>0 and j+A[i]<=S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD
        elif j==0 and A[i]<=S:
            dp[i+1][A[i]] += i+1
            dp[i+1][A[i]] %= MOD
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
ans = 0
for i in range(N+1):
    ans += dp[i][S]
    ans %= MOD
print(ans)


Measured memory_bytes: 125016
#include<bits/stdc++.h>
typedef long long ll;
#define sz(x) int(x.size())
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MOD 1000000007

using namespace std;

int main() {
    int N,M;
    cin >> N >> M;
    int A[5];
    int s[10];
    int c[10];
    for (int i = 0; i < M; i++)
    {
        cin >> s[i] >> c[i];
    }
    
    for (int i = 0; i < N; i++)
    {
        A[i] = -1;
    }

    for (int i = 0; i < M; i++)
    {
        if(A[s[i]-1] == -1) A[s[i]-1] = c[i];
        else{
            if(A[s[i]-1] != c[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    if(N != 1 && A[0] == 0){
        cout << -1 << endl;
        return 0;
    }

    for (int i = 0; i < N; i++)
    {
        if(A[i] == -1){
            if(i == 0 && N != 1) A[i] = 1;
            else A[i] = 0;
        }
        cout << A[i];
    }
    cout << endl;
}

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

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	
	int max=0;//最大値maxの宣言。
	for(int i=1;i<n;i++){
		int cun=0;//区切り方それぞれの場合における、カウント数cunの宣言。
		for(int j=0;j<i;j++){
			int jud=0;
			for(int k=j-1;k>=0;k--){
				if(s[j]==s[k]){
					jud=1;
					break;
				}
			}
			if(jud) continue;//同じ文字のカウントは避ける。
			
			for(int k=i;k<n;k++){
				if(s[j]==s[k]){
					cun++;
					break;
				}
			}
		}
		
		if(max<cun) max=cun;
	}
	
	
	cout<<max<<endl;
	
	
	return 0;
}

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

using ll = long long int;
using P = std::pair<int, int>;

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

constexpr ll mod = 1e9 + 7;

class mint
{
    ll num = 0;

public:
    mint(ll x = 0) : num(x) {}

    mint operator+(const mint &rhs) const
    {
        return (num + rhs.num) % mod;
    }
    mint operator+=(const mint &rhs)
    {
        return num = (num + rhs.num) % mod;
    }
    mint operator*(const mint &rhs) const
    {
        return num * rhs.num % mod;
    }
    mint operator-(const mint &rhs) const
    {
        return (num + rhs.num + mod) % mod;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs)
{

    os << rhs.num;

    return os;
}

int main()
{
    int n;

    std::cin >> n;

    std::vector<char> cs(n + 1);

    rep(i, n)
    {
        std::cin >> cs[i];
    }

    std::vector<std::vector<std::vector<mint>>> cnt(n + 1, std::vector<std::vector<mint>>(n + 1, std::vector<mint>(n + 1)));

    if (cs[1] == '-')
        cnt[1][0][0] = 1;
    else if (cs[1] == 'U')
        cnt[1][1][1] = 1;

    for (int i = 2; i <= n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            for (int k = 0; k < n; ++k)
            {
                if (cs[i] == '-')
                    cnt[i][j][k] = cnt[i - 1][j][k];
                else if (cs[i] == 'U')
                {
                    cnt[i][j][k] = mint(k) * cnt[i - 1][j][k];
                    if (j >= 1 && k >= 1)
                        cnt[i][j][k] += cnt[i - 1][j - 1][k - 1];
                }
                else if (cs[i] == 'D')
                {
                    cnt[i][j][k] = mint((k + 1) * (j + 1)) * cnt[i - 1][j + 1][k + 1] + mint(j) * cnt[i - 1][j][k];
                }
            }
        }
    }

    std::cout << cnt[n][0][0] << std::endl;

    /*rep(i, n)
    {
        std::cerr << cnt[i][0][0] << ' ' << cnt[i][1][1] << ' ' << cnt[i][2][2] << std::endl;
    }*/

    return 0;
}


Measured memory_bytes: 67720
// 参考: oshiumi 様
#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int> > g[100000];
long long dist[100000];

void dfs (int index, int parent) {

    for (auto &e : g[index]) {
        if (e.first == parent) continue;

        dist[e.first] = dist[index] + e.second;
        dfs(e.first, index);
    }
}

int main () {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }

    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, -1);
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;

        cout << dist[x] + dist[y] << endl;
    }

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector<int> check(26,0);
    for(int i=0; i<s.length(); i++){
        check[s[i]-'a']++;
    }
    for(int i=0; i<26; i++){
        if(check[i]==0){
            cout << (char)('a'+i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl
int h, w, i, j, dp[1001][1001], M = (int) 1e9+7;
string s[1001];
int main ()
{
    cin >> h >> w;
    for(i = 0; i < h; i++) cin >> s[i];
    dp[0][0] = 1;
    for(i = 1; i < w; i++)
    {
        if(s[0][i] == '.') dp[0][i] = dp[0][i-1];
        else dp[0][i] = 0;
    }
    for(i = 1; i < h; i++)
    {
        if(s[i][0] == '.') dp[i][0] = dp[i-1][0];
        else dp[i][0] = 0;
    }
    for(i = 1; i < h; i++)
    {
        for(j = 1; j < w; j++)
        {
            if(s[i][j] == '.') dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % M;
            else dp[i][j] = 0;
        }
    }
    cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 5248
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
 
    private static final int BIG_NUM  = 2000000000;
    private static final int MOD  = 1000000007;
 
    private static Node nodes[];
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
 
        nodes = new Node[N];
        for(int i = 0; i < N; i++)nodes[i] = new Node();
 
        int id,num,child_id;
        for(int loop = 0; loop < N; loop++){
            id = scanner.nextInt();
            num = scanner.nextInt();
 
            for(int i = 0; i < num; i++){
                child_id = scanner.nextInt();
                nodes[id].children.add(child_id);
                nodes[child_id].setParent_id(id);
            }
        }
 
        for(int i = 0; i < N; i++){
            if(nodes[i].getParent_id() == -1){
                calcDepth(i,0);
            }
        }
 
        StringBuilder ans = new StringBuilder();
 
        for(int i = 0; i < N; i++){
            ans.append("node ").append(Integer.toString(i)).append(": parent = ").append(Integer.toString(nodes[i].getParent_id()))
            .append(", depth = ").append(Integer.toString(nodes[i].getDepth())).append(", ");
 
            if(nodes[i].getParent_id() == -1){
                ans.append("root, ");
            }else if(nodes[i].children.size() == 0){
                ans.append("leaf, ");
            }else{
                ans.append("internal node, ");
            }
 
            ans.append("[");
            if(nodes[i].children.size() > 0){
                ans.append(Integer.toString(nodes[i].children.get(0)));
                for(int k = 1; k < nodes[i].children.size(); k++){
                    ans.append(", ").append(Integer.toString(nodes[i].children.get(k)));
                }
            }
            ans.append("]\n");
        }
        System.out.print(ans.toString());
    }
 
    static void calcDepth(int id,int value){
        nodes[id].setDepth(value);
 
        for(int i = 0; i < nodes[id].children.size(); i++){
            calcDepth(nodes[id].children.get(i),value+1);
        }
    }
}
 
class Node{
    private int parent_id;
    private int depth;
    public ArrayList<Integer> children;
 
    Node(){
        children = new ArrayList<Integer>();
        parent_id = -1;
    }
 
    public int getParent_id() {
        return parent_id;
    }
 
    public void setParent_id(int parent_id) {
        this.parent_id = parent_id;
    }
 
    public int getDepth() {
        return depth;
    }
 
    public void setDepth(int depth) {
        this.depth = depth;
    }
}


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

//Card Game
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			boolean[] t = new boolean[2*n+1];
			boolean[] h = new boolean[2*n+1];
			int ct = n;
			int ht = n;
			Arrays.fill(h, true);
			for(int i=0;i<n;i++){
				int c = sc.nextInt();
				t[c] = true;
				h[c] = false;
			}
			int p = 0;
			int turn = 0;
			while(0<ct&&0<ht){
				boolean f = false;
				for(int i=1;i<=2*n;i++){
					if(turn==0){
						if(t[i]&&p<i){
							t[i] = false;
							ct--;
							p = i;
							f = true;
							break;
						}
					}
					else{
						if(h[i]&&p<i){
							h[i] = false;
							ht--;
							p = i;
							f = true;
							break;
						}
					}
				}
				if(!f)p = 0;
				turn = (turn+1)%2;
			}
			int pt = 0;
			int ph = 0;
			for(int i=1;i<=2*n;i++){
				pt+=h[i]?1:0;
				ph+=t[i]?1:0;
			}
			System.out.println(pt+"\n"+ph);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
n=int(input())
v=list(map(int,input().split()))
a=sorted(v)
if n==2:
    ans=(a[0]+a[1])/2
    print(ans)
    exit()
awase=(a[0]+a[1])/2
for i in range(2,n-1):
    awase=(awase+a[i])/2
awase=(awase+a[n-1])/2
print(awase)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
//#define ull unsigned  long  long
#define int long long int
#define lld long double
#define endl "\n"
#define S second
#define F first
#define pir      pair<int,int>
#define vtr      vector<int>
#define mpp      map<int,int>
#define pb       push_back
#define popb     pop_back()
#define mk       make_pair
#define stc      set<char>
#define st       set<int>
#define stk      stack<int>
#define ctn      continue
#define MOD      1000000007
#define fr(i,a,b)   for(int i=a;i<b;i++)
#define rfr(i,a,b)  for(int i=a-1;i>=b;i--)
#define must        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

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

int myfun(int x,int y)
{
    return x*y;
}
void primeFactors(int n)
{
    while (n%2 == 0)
    {
        cout<<2<<endl;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            cout<<i<<endl;
            n = n/i;
        }
    }
    if (n > 2)
        cout<<n<<endl;
}

void fillPrefixSum(int arr[], int N, int prefixSum[])
{
    prefixSum[0] = arr[0];

    for (int i = 1; i < N; i++)
        prefixSum[i] = prefixSum[i-1] + arr[i];
}

int factorial(int n)
{
    return (n==1 || n==0) ? 1: n * factorial(n - 1);
}

int power(int x,  int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1;
            x = (x*x) % p;
    }
    return res;
}




void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int sum=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            sum+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }
    cout<<sum<<endl;
}



signed main()
{
	must;
    int tt=1;
    //cin >> tt;
	while(tt--)solve();
	return 0;
}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n; cin>>n;
	string s; cin>>s;
	ll rcnt = 0;
	rep(i,0,n){
		if(s[i] == 'R') rcnt++;
	}
	ll ans = 0;
	rep(i,0,rcnt){
		if(s[i] == 'W') ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3744
let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)
let ( *^ ) x y = (x * y) mod m

let () = Scanf.scanf "%d %d" @@ fun n k ->
  let ds = Array.init k succ in
  for d = 1 to k do
    for i = 2 to k / d do
      ds.(d * i - 1) <- ds.(d * i - 1) -^ ds.(d - 1)
    done
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( +^ ) 0 @@
  Array.init k @@ fun d ->
    power ( *^ ) ds.(d) (k / (d + 1)) n

Measured memory_bytes: 5420
fn main() {
    proconio::input! {
        n: usize,
        s: [String; n],
    }

    let mut dic = std::collections::HashMap::new();
    dic.entry("AC").or_insert(0);
    dic.entry("WA").or_insert(0);
    dic.entry("TLE").or_insert(0);
    dic.entry("RE").or_insert(0);
    for si in &s {
        *dic.entry(si.as_str()).or_insert(0) += 1;
    }
    for si in vec!["AC", "WA", "TLE", "RE"] {
        println!("{} x {}", si, dic.get(&si).unwrap());
    }
}


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

int main() {
  int ans = 0;
  string s;
  
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == '1') {
      ans++;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
fn main(){
    let inp: Vec<usize> = read_vec();
    let v: Vec<char> = read::<String>().chars().collect();
    let mut dup = 0;
    for i in 0..inp[0]-1 {
        if v[i] == v[i+1] {dup += 1};
    }

    println!("{}", std::cmp::min(inp[0]-1, dup + 2*inp[1]));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int A = sc.nextInt();
		int B = sc.nextInt();
		String U = sc.next();
		sc.close();
		if(U.equals(S)){
			System.out.println((A-1) + " " + B);
		}else if(U.equals(T)){
			System.out.println(A + " " + (B-1));
		}

	}

}

Measured memory_bytes: 21716
H,W=map(int,input().split())
S=[list(input())for _ in range(H)]

from collections import deque
import math


def bfs(h,w,sy,sx,S):
    maze=[[10**9]*(W)for _ in range(H)]

    maze[sy-1][sx-1]=0
    que=deque([[sy-1,sx-1]])
    count=0
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+i,x+j
            if 0<=nexty<h and 0<=nextx<w:
                dist1=S[nexty][nextx]
                dist2=maze[nexty][nextx]
            else:
                continue
            if dist1!='#':
                if dist2>maze[y][x]+1:
                    maze[nexty][nextx]=maze[y][x]+1
                    count=max(count,maze[nexty][nextx])
                    que.append([nexty,nextx])
    return count

ans=0
for sy in range(H):
    for sx in range(W):
        if S[sy][sx]=='.':
            now=bfs(H,W,sy+1,sx+1,S)
            ans=max(ans,now)

print(ans)

Measured memory_bytes: 9348
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define MAX_N (110)

static ll heights[MAX_N], patties[MAX_N];

static ll f(int N, ll X)
{
	ll ret;
	if (N == 0)
		ret = 1;
	else if (X <= 1)
		ret = 0;
	else if (X <= 1 + heights[N - 1])
		ret = f(N - 1, X - 1);
	else if (X == 2 + heights[N - 1])
		ret = patties[N - 1] + 1;
	else if (X <= 2 + 2 * heights[N - 1])
		ret = f(N - 1, X - heights[N - 1] - 2) + patties[N - 1] + 1;
	else
		ret = patties[N];
	return ret;
}

int main()
{
	int N;
	ll X;
	scanf("%d%lld", &N, &X);

	heights[0] = 1;
	patties[0] = 1;
	for (int i = 1; i <= N; i++) {
		heights[i] = heights[i - 1] * 2 + 3;
		patties[i] = patties[i - 1] * 2 + 1;
	}
	printf("%lld\n", f(N, X));

	return 0;
}


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

using namespace std;

int hierarchy(string str) {
	int count = 0;
	while (str[count] == '[')count++;
	str = str.substr(1, str.length() - 2);//??????????????????????????????
	if (count == 1) {
		int res = stoi(str);
		//cout << res << endl;
		return res/2+1;
	}
	else {
		count--;
		vector<int>v;
		int s = 0, ms = count, cou = 0;
		while (str.length() > ms) {
			if (str[ms] == ']')cou++;
			else cou = 0;

			if (count == cou) {
				string b = str.substr(s, ms + 1 - s);
				v.push_back(hierarchy(b));
				s = ms + 1;
				cou = 0;
			}
			ms++;
		}
		sort(v.begin(), v.end());
		int sum = 0;
		for (int i = 0; i < v.size()/2+1; i++) {
			sum += v.at(i);
		}
		return sum;
	}
}

int main() {
	int n;
	cin >> n;
	vector<int>v;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		v.push_back(hierarchy(s));
	}
	for (int i = 0; i < n; i++) {
		cout << v[i] << endl;
	}
}

Measured memory_bytes: 3196
def roll(die, d):
    if d == "E":
        return [die[3], die[1], die[0], die[5], die[4], die[2]]
    if d == "N":
        return [die[1], die[5], die[2], die[3], die[0], die[4]]
    if d == "S":
        return [die[4], die[0], die[2], die[3], die[5], die[1]]
    if d == "W":
        return [die[2], die[1], die[5], die[0], die[4], die[3]]
    if d == "L":
        return [die[0], die[3], die[1], die[4], die[2], die[5]]
    if d == "R":
        return [die[0], die[2], die[4], die[1], die[3], die[5]]

def checkdice(die1, die2):
    ans = "No"
    for d in "RRRNRRRNRRRSRRRSRRRNRRRR":
        if die1 == die2:
            ans = "Yes"
            break
        die2 = roll(die2, d)
    return ans

die1 = list(map(int, input().split()))
die2 = list(map(int, input().split()))
print(checkdice(die1, die2))

Measured memory_bytes: 7800
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
mod = 7 + 10 ** 9
count = 1
if N % 2 == 0:
    for i, a in enumerate(A):
        if a != 2 * (i // 2) + 1: 
            count = 0
            break
        if i % 2 == 1:
            count *= 2
            count %= mod
else:
    for i, a in enumerate(A):
        if a != 2 * ((i + 1) // 2):
            count = 0
            break
        if i % 2 == 1:
            count *= 2
            count %= mod
print(count)


Measured memory_bytes: 13880
#include<stdio.h>

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

void insertionSort(int A[], int N){
    int j, i, v;
    for (i=1;i<N;i++){
        v = A[i];
        j = i-1;
        while (j >= 0 && A[j] > v){
            A[j+1]  =A[j];
            j--;    
        }
        A[j+1] = v;
        trace(A,N);
    }
}

int  main(){
    int N, i, j;
    int A[100];

    scanf("%d", &N);
    for (i=0;i<N;i++) scanf("%d", &A[i]);

    trace(A,N);
    insertionSort(A,N);

    return 0;
}


Measured memory_bytes: 2696
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef ll Weight;
void add_edge(vector<vector<Weight>>& g, Weight from, Weight to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

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

  int h, w, k; cin >> h >> w >> k;
	vector<vector<char>> c(h, vector<char>(w));
	int black = 0;
  rep(i,h) rep(j,w) { cin >> c[i][j]; if (c[i][j] == '#') black++;}

	ll ans = 0;
	rep(state1, 1 << h) rep(state2, 1 << w) {
		vector<int> ix1;
		rep(i, h) if (state1 >> i & 1) ix1.push_back(i);
		vector<int> ix2;
		rep(i, w) if (state2 >> i & 1) ix2.push_back(i);

		int cnt = 0;
		for (int i : ix1) rep(j,w) {
		  if (c[i][j] == '#') cnt++;
		}
		rep(i,h) for (int j : ix2) {
			if (c[i][j] == '#') cnt++;
		}
		for (int i : ix1)  for (int j : ix2) {
			if (c[i][j] == '#') cnt--;
		}

		if (black - cnt == k) { ans++; }
	}
	

	cout << ans << endl;
}

Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
int main(){
  long long int n;
  cin >> n;
  long long int h[n];
  for(auto i=0;i<n;i++){
    cin >> h[i];
  }
  long long int ans[n];
  ans[0]=0;
  ans[1]=abs(h[1]-h[0]);
  ans[2]=min(ans[0]+abs(h[2]-h[0]),ans[1]+abs(h[2]-h[1]));
  for(auto i=3;i<n;i++){
    ans[i]=min(ans[i-2]+abs(h[i]-h[i-2]),ans[i-1]+abs(h[i]-h[i-1]));
  }
  cout << ans[n-1];
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> p(n);
  vector<vector<int>> s(n);
  vector<int> r(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
    p.at(i)--;
    s.at(i)={i};
    r.at(i)=i;
  }
  for(int _=0;_<m;_++){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    if(r.at(x)==r.at(y))
      continue;
    int rn=(s.at(r.at(x)).size()>s.at(r.at(y)).size()?r.at(x):r.at(y));
    int ro=(rn==r.at(x)?r.at(y):r.at(x));
    for(int x:s.at(ro)){
      r.at(x)=rn;
      s.at(rn).push_back(x);
    }
  }
  int c=0;
  for(int i=0;i<n;i++){
    if(r.at(i)!=i)
      continue;
    set<int> q;
    for(int x:s.at(i))
      q.insert(p.at(x));
    for(int x:s.at(i))
      c+=(q.count(x)?1:0);
  }
  cout<<c<<endl;
}

Measured memory_bytes: 16952
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
typedef long long ll;
int n,m;
pair<int,int>dice;
int main(){
    cin>>n;
    int cnt=0;
    bool done=false;
    for(int i=0;i<n;++i){
        int a,b;
        cin>>a>>b;
        if(a==b) cnt++;
        if(cnt>=3) done=true;
        if(a!=b) cnt=0;
    }

    if(done) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 3592
let mcm p n =
  let m = Array.make_matrix (n + 1) (n + 1) max_int in
  for i = 1 to n do m.(i).(i) <- 0 done;
  for l = 2 to n do
    for i = 1 to n - l + 1 do
      let j = i + l - 1 in
      for k = i to j - 1 do
        m.(i).(j) <- min m.(i).(j) (m.(i).(k) + m.(k+1).(j) + p.(i-1)*p.(k)*p.(j))
      done
    done
  done;
  m.(1).(n)

let () =
  let n = read_int () in
  let p = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    let (r, c) = Scanf.scanf "%d %d\n" (fun r c -> (r, c)) in
    p.(i) <- r;
    p.(i+1) <- c;
  done;
  mcm p n |> Printf.printf "%d\n"

Measured memory_bytes: 2448
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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;
}
///////////////////////////////////////////////

/*（๑•﹏•๑｀) */
int main() {
    int N; cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    REP(i,N){
        cin >> V[i];
    }

    REP(i,N){
        cin >> C[i];
    }

    int ans = 0;
    REP(i,N){
        if (V[i] > C[i]) ans += V[i] - C[i];
    }

    cout << ans << "\n";



}


Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    X = LI()
    c = collections.Counter()
    for k in X:
        c[k] += 1

    ans = 0
    d = collections.Counter()
    ix = sorted(c.items(),key=lambda x:x[1])
    for k,v in ix:
        x = (-k) % M
        if d[x] > 0:
            z = min(d[x],v)
            ans += z
            d[k%M] += v - z
            d[x] -= z
        else:
            d[k%M] += v
    for k,v in ix:
        x = min(v//2,d[k%M]//2)
        if x:
            ans += x
            d[k%M] -= x * 2

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 99012
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
using namespace boost::multiprecision;  
using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
//inline int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
//inline int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    int h;
    cin >> h;

    int res = 0;

    for(int i = 0;h;++i){
        res += (1ll << i);
        h >>= 1;
    }

    cout << res << '\n';

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  set<int> dA;
  int A_tmp;
  for (int i=0;i<N;i++){
    cin >> A_tmp;
    if (dA.count(A_tmp)) dA.erase(A_tmp);
    else dA.insert(A_tmp);
  }

  cout << dA.size() << endl;

}
 

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

#define FOR(i, m, n) for (int i = m; i <= n; ++i)

int calc_digit_sum(int n) {
  int sum = 0;
  while ( n ) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  FOR(i,1,N) {
    int sum = calc_digit_sum(i);
    if ( sum >= A && sum <= B ) {
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
def main():
    from statistics import median

    n, *a, = map(int, open(0).read().split())
    a = [x - i for i, x in enumerate(a, 1)]
    a.sort()
    m = int(median(a))

    ans = sum([abs(x - m) for x in a])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27212
#include<stdio.h>
#include<math.h>

typedef struct{
  double x;
  double y;
}point;

void koch(int i, point p1, point p2){
  point a, b, c;
  double change;

  if(i == 0) return;

  change = M_PI * 60.0 / 180.0;
  a.x = (2.0 * p1.x + p2.x) / 3.0;
  a.y = (2.0 * p1.y + p2.y) / 3.0;
  b.x = (p1.x + 2.0 * p2.x) / 3.0;
  b.y = (p1.y + 2.0 * p2.y) / 3.0;
  c.x = (b.x - a.x) * cos(change) - (b.y - a.y) * sin(change) + a.x;
  c.y = (b.x - a.x) * sin(change) + (b.y - a.y) * cos(change) + a.y;

  koch(i-1, p1, a);
  printf("%f %f\n", a.x, a.y);
  koch(i-1, a, c);
  printf("%f %f\n", c.x, c.y);
  koch(i-1, c, b);
  printf("%f %f\n", b.x, b.y);
  koch(i-1, b, p2);
}

int main(){
  int i;
 point p1= {0.0,0.0};
 point p2= {100.0,0.0};

  scanf("%d",&i);

  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(i,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);

  return 0;
}
  



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

int main() {
  int N;
  cin >> N;
  
  int64_t leven = 2;
  int64_t lodd = 1;
  for (int i = 0; i < N + 1; i++) {
    if (i % 2 == 0 && i > 1) {
      leven += lodd;
    }
    if (i % 2 == 1 && i > 1) {
      lodd += leven;
    }
  }
  
  if (N % 2 == 0) {
   cout << leven << endl; 
  }
  if (N % 2 == 1) {
   cout << lodd << endl; 
  }
  
}

Measured memory_bytes: 256