akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
    int a,b; cin >> a >> b;
    int c,d; cin >> c >> d;
    while(a>0 && c>0){
        c -= b;
        a -= d;
    }
    if (a>0 || (a<=0 && c<=0)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ b.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
コード変えたらコンパイルする
不正解ならWAが出る
*/

Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
using namespace std;
int fd[55][55];
int x[8]={0,1,0,-1,1,-1,1,-1};
int y[8]={1,0,-1,0,1,-1,-1,1};
int a,b;
void ff(int n,int m)
{
     for(int i=0;i<=7;i++)
     {
         int q=n+x[i];
         int p=m+y[i];
         //cout<<n<<" "<<m<<endl;
         if(q<1||q>a||p<1||p>b) continue;
         if(fd[q][p]==-1)continue;
         fd[q][p]+=1;
     }
}
int main()
{
    //int a,b;
    memset(fd,0,sizeof(fd));
    cin>>a>>b;
    for(int i=1;i<=a;i++)
    {
        for(int j=1;j<=b;j++)
        {
            char s;
            cin>>s;
            if(s=='.')fd[i][j]=0;
            else fd[i][j]=-1;
        }
    }
    for(int i=1;i<=a;i++)
    {
        for(int j=1;j<=b;j++)
        {
            if(fd[i][j]==-1) ff(i,j);
        }
    }
    for(int i=1;i<=a;i++)
    {
        for(int j=1;j<b;j++)
        {
            if(fd[i][j]!=-1)cout<<fd[i][j];
            else cout<<"#";
        }
        if(fd[i][b]!=-1) cout<<fd[i][b]<<endl;
        else cout<<"#"<<endl;;
    }
}


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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	ll m, k;
	cin >> m >> k;

	if(k >= (1 << m)) {
		cout << -1 << endl;
		return 0;
	}

	if(k == 0) {
		for(int i = 0; i < (1 << m) - 1; i++) {
			cout << i << ' ' << i << ' ';
		}
		cout << (1 << m) - 1 << ' ' << (1 << m) - 1 << endl;
		return 0;
	}

	ll x = 0;
	for(int i = 0; i < (1 << m); i++) {
		if(i != k) {
			x ^= i;
		}
	}
	if(x != k) {
		cout << -1 << endl;
		return 0;
	}

	cout << k;
	for(int i = 0; i < (1 << m); i++) {
		if(i != k) {
			cout << ' ' << i;
		}
	}
	cout << ' ' << k;
	for(int i = (1 << m) - 1; i >= 0; i--) {
		if(i != k) {
			cout << ' ' << i;
		}
	}
	cout << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
int a[10000];
cin>>n>>m;
for (int i=0;i<n;i++)
cin>>a[i];

int sum=0;
for (int i=0;i<n;i++)sum+=a[i];
int l=0;
for (int i=0;i<n;i++)
{
if(a[i]*4*m>=sum)
l++;}

if(l>=m)cout <<"Yes";
else cout <<"No";
}

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

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

}


int main()
{

    textIO();
    fastIO();

    long long n, ans = 0;;
    cin >> n;

    vector<long long> arr(n);

    for(int i=0;i<n;i++){
        cin >> arr[i];
    }

    sort(arr.begin(), arr.end());

    ans+=arr[n-1];

    long long ind = n-2;

    n-=2;



    while(n-2 >= 0){


        n-=2;
        ans+=(arr[ind]*2);
        ind--;

    }

    if(n > 0){
        ans+=arr[ind];
    }

    cout << ans << '\n';


    return 0;
}


Measured memory_bytes: 4756
#include<stdio.h>
#include<string.h>
int main()
{
    char arr[11]; int a,b;
    gets(arr); arr[0]='2'; arr[1]='0'; arr[2]='1'; arr[3]='8';
    for(a=0;a<10;a++)
        printf("%c",arr[a]);
}


Measured memory_bytes: 128
//PDF解説
#include<iostream>
using namespace std;

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int mod;
  for (int i = 1; i <= B; i++) {
    mod = (A * i) % B;
    if (C == mod) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}

Measured memory_bytes: 256
X = int(input())
if X >= 400 and X <= 599:
    print(8)
elif X >= 600 and X <= 799:
    print(7)
elif X >= 800 and X <= 999:
    print(6)
elif X >= 1000 and X <= 1199:
    print(5)
elif X >= 1200 and X <= 1399:
    print(4)
elif X >= 1400 and X <= 1599:
    print(3)
elif X >= 1600 and X <= 1799:
    print(2)
elif X >= 1800 and X <= 1999:
    print(1)

Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
 
using namespace std;
 
int main(){
    int A, B, C, D;

    cin >> A >> B >> C >> D;
    
    if(A*B < C*D) cout << C*D << endl;
    else cout << A*B << endl;


    return 0;
}

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

 using namespace std;

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

   cin >> N >> M >> X >> Y;

   vector<int> x(N);
   vector<int> y(M);

   for (int i = 0; i < N; i++) cin >> x.at(i);
   for (int i = 0; i < M; i++) cin >> y.at(i);

   int max_x = X;
   for (int i = 0; i < N; i++) {
     max_x = max(max_x, x.at(i));
   }

   int min_y = Y;
   for (int i = 0; i < M; i++) {
     min_y = min(min_y, y.at(i));
   }

   if (max_x < min_y) cout << "No War" << endl;
   else cout << "War" << endl;

}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <memory.h>
#include <algorithm>
using namespace std;

const int N = 505;

void die() {
    puts("No");
    exit(0);
}

int X[N];

int pt = 0;
int A[N * N];
bool special[N * N];

vector<int> pool;
int ppt = 0;

int main() {
    int n;
    scanf("%d", &n);
    memset(A, -1, sizeof(int) * (n * n));
    for (int i = 0; i < n; i++) {
        scanf("%d", &X[i]);
        --X[i];
        A[X[i]] = i;
        special[X[i]] = true;
    }
    for (int i = 0; i < n * n; i++) {
        if (A[i] == -1) {
            pool.push_back(i);
        } else if (special[i]) {
            int v = A[i];
            for (int j = 0; j < v; j++) {
                if (ppt == (int)pool.size())
                    die();
                A[pool[ppt++]] = v;
            }
        }
    }
    pool.clear();
    ppt = 0;
    for (int i = n * n - 1; i >= 0; i--) {
        if (A[i] == -1) {
            pool.push_back(i);
        } else if (special[i]) {
            int v = A[i];
            for (int j = 0; j < n - v - 1; j++) {
                if (ppt == (int)pool.size())
                    die();
                A[pool[ppt++]] = v;
            }
        }
    }
    assert(ppt == pool.size());
    puts("Yes");
    for (int i = 0; i < n * n; i++) {
        printf("%d ", A[i] + 1);
    }
    printf("\n");
}


Measured memory_bytes: 3444
#include<stdio.h>
#include<string.h>
int main()
{
	int c=0,r=0,n=0,max=0,most=0,p,q;
	char str[1000][32],now;
	while(scanf("%c",&now)!=EOF)
	{
		if(now==' ')
		{
			str[r][c]='\0';
			r++;
			c=0;
			n++;
		}
		else
		{
			str[r][c++]=now;
		}
	}
	str[r][c]='\0';
	for(int i=0;i<=n;i++)
	{
		int same=0,temp=strlen(str[i]);
		if(temp>max)
		{
			max=temp;
			q=i;
		}
		for(int j=i+1;j<n;j++)
		{
			if(strcmp(str[i],str[j])==0)
				same++;
		}
		if(same>most)
		{
			most=same;
			p=i;
		}
	}
	printf("%s %s\n",str[p],str[q]);
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
typedef long long int ll;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  
  ll ans = 0,count = 0;
  
  rep(i,n-1){
    if(h[i]>=h[i+1] && i!=n-2){
      count++;
      if(i==n-2) {
		if(count > ans){
        	ans = count;
        }
      }
    }else if(i!=n-2){
      if(count > ans){
        ans = count;
      }
        count = 0;
      
    }else{
      if(h[n-2]>=h[n-1]){
        count++;
      }
  	   if(count > ans){
        	ans = count;
        }
    }
  }


  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ans=1;
  int ans_c=0;
  rep1(i,n){
    int c=0;
    int t=i;
    while(1){      
      if(t%2==1) break;
      t/=2;
      c++;      
    }
    if(c>ans_c){
      ans_c=c;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
    

}


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

using namespace std;

int main()
{
    int n, p;
    string s;
    long long ans;

    cin >> n >> p >> s;

    if (10 % p == 0) {  // 2, 5
        ans = 0;
        for (int r = 0; r < n; r++) {   // 左端から
            if ((s[r] - '0') % p == 0) {
                ans += r + 1;           // そこから左すべて
            }
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> d(n + 1);
    vector<int> cnt(p);
    int ten = 1;

    for (int i = n - 1; i >= 0; --i) {  // 右端から
        int a = (s[i] - '0') * ten % p;
        d[i] = (d[i+1] + a) % p;        // 累積和
        ten *= 10; ten %= p;
    }

    /* 同じ剰余で挟まれる区間の数を数える */
    ans = 0;
    for (int i = n; i >= 0; --i) {      // 右端から
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long int lli;

string s;

int main()
{
	cin >> s;

	int sz = s.size();

	lli ans = 0;

	for(int mask = 0 ; mask < (1 << (sz - 1)) ; mask++)
	{
		lli curSum = 0;
		lli curNumber = s[0] - '0';

		for(int i = 0 ; i < sz - 1 ; i++)
		{
			if( mask & (1 << i) )
			{
				curSum += curNumber;
				curNumber = 0;
			}
			else curNumber = 10*curNumber;

			curNumber += s[i + 1] - '0';
		}

		curSum += curNumber;
		ans += curSum;
	}

	printf("%lld\n",ans);
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> ia(n);
    rep(i, n){
        ia[i].first = i+1;
        cin >> ia[i].second;
    }

    sort(all(ia), [](pair<ll, ll> l, pair<ll, ll> r){ return l.second<r.second; });
    rep(i, n){
        cout << ia[i].first << " ";
    }
    cout << endl;
}


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

int main() {
  int N,K,dx=0;
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    int x,x0,kx;
    cin >> x;
    x0 = 2*x;
    kx = 2*(K-x);
    if (x0<=kx) {
      dx += x0;
    }
    else {
      dx += kx;
    }
  }
  cout << dx << endl;
}

Measured memory_bytes: 256
import math


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct


a, b = map(int, input().split())
c = gcd(a, b)
d = factorize(c)
print(len(set(d))+1)


Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
   int x1,x2,x3,x4,x5;
 


       
       scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);

      if(x1==0){
         printf("%d\n",1);
      }else if(x2==0){
         printf("%d\n",2);
      }else if(x3==0){
         printf("%d\n",3);
      }else if(x4==0){
         printf("%d\n",4);
      }else if(x5==0){
          printf("%d\n",5);
      }
   return 0;  
}

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

typedef long long ll;

ll ans, f[17][10], g[17], p[17];
int n, num[17];

int main() {
	cin>>n;
	for(int i = 0; i <= 9; i++) f[1][i] = 1;
	for(int i = 2; i <= 16; i++) 
	    for(int j = 0; j <= 9; j++) {
	    	f[i][j] = f[i - 1][j];
	        if(j != 9) f[i][j] += f[i - 1][j + 1];
	        if(j != 0) f[i][j] += f[i - 1][j - 1];
	    }
	for(int i = 1; i <= 16; i++)
	    for(int j = 1; j <= 9; j++) g[i] += f[i][j];
	int pos = 1, top = 1;
	while(n > g[pos]) {
		n -= g[pos];
		pos++;
	}
	while(n > f[pos][top]) {
		n -= f[pos][top];
		top++;
	}
	p[1] = 1;
	for(int i = 2; i <= 16; i++) 
		p[i] = p[i - 1]*10;
	ans = top*p[pos];
	num[pos] = top;
	for(int i = pos - 1; i; i--) {
		for(int j = max(0, num[i + 1] - 1); j <= min(9, num[i + 1] + 1); j++)
		    if(f[i][j] >= n) {
		    	num[i] = j;
		    	ans += j*p[i];
		    	break;
		    }
		    else {
		    	n -= f[i][j];
		    }
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)  
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (int (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pp printf("Case %d: \n",t)
const unsigned int mod = 1e9+7;
const int mx=1000005;
const int maxInt = 2147483647;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin >> n;
    ll a[n+5][5],dp[n+5][5];
    for(int i=0;i<n;++i)cin >> a[i][0] >> a[i][1] >> a[i][2];
    dp[n-1][0]=a[n-1][0];
	dp[n-1][1]=a[n-1][1];
	dp[n-1][2]=a[n-1][2];
	for(int i=n-2;i>=0;--i){
		dp[i][0]=max(dp[i+1][1],dp[i+1][2])+a[i][0];
		dp[i][1]=max(dp[i+1][0],dp[i+1][2])+a[i][1];
		dp[i][2]=max(dp[i+1][0],dp[i+1][1])+a[i][2];
	}
	cout << max(dp[0][0],max(dp[0][1],dp[0][2])) << endl;
    return 0;
}

























Measured memory_bytes: 8064
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=1000005;
const ll SQN=330;
const ll LG=31;
const double PI=atan(1)*4;
using namespace std;

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

    // ll k;
    // cin >> k;
    // ll rem=0;
    // rep(i,1,MAX) {
    // 	ll r=(10*rem+7)%k;
    // 	if(r==0) ret(i);
    // 	rem=r;
    // }
    // ret(-1);

    ll n;
    cin >> n;
    string s;
    cin >> s;
    vll r,w;
    for(ll i=0;i<n;i++) if(s[i]=='R') r.pb(i);
    for(ll i=0;i<n;i++) if(s[i]=='W') w.pb(i);


    ll ans=min(r.size(),w.size());
	ll ridx=r.size()-1,widx=0;

	ll cost=0;
	while(ridx>=0 && widx<w.size()) {
		// cout << r[ridx] << " " << w[widx] << endl;
		if(r[ridx]<w[widx]) break;
		ridx--;
		widx++;
		cost++;
	}
	ret(cost);


}


Measured memory_bytes: 5756
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt
    val as = in.readLine().split("\\s+").map(_.toLong)

    val absas = Array.ofDim[Long](n)

    var minAbsa = Long.MaxValue
    var nonPositiveCount = 0
    for (i <- as.indices) {
      val a = as(i)
      if (a <= 0) {
        nonPositiveCount += 1
      }
      val absa = Math.abs(a)
      absas(i) = absa
      minAbsa = Math.min(minAbsa, absa)
    }

    out.println(
      absas.sum - {
        if (nonPositiveCount % 2 == 0) {
          0
        } else {
          2 * minAbsa
        }
      }
    )

    out.flush()
  }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int x,t; cin>>x>>t;
        if(x>t)cout<<x-t<<endl;
        else cout<<0<<endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	int maximum;
	int minimum;
	for(int i = 0; i < N; i++){
		cin >> a.at(i);
		if(i == 0){
			maximum = a.at(i);
			minimum = a.at(i);
		}
		else{
			maximum = max(a.at(i), maximum);
			minimum = min(a.at(i), minimum);
		}
	}
	cout << maximum - minimum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
// head

signed main() {
	  int N,M;
    std::cin >> N>>M;
		vector <pair<int, int> >  g[100009];
		rep(i,0,M){
			int l,r,d;
			scanf("%d %d %d",&l,&r,&d);
			l--, r--;
			g[l].push_back(make_pair(r, d));
      g[r].push_back(make_pair(l, -d));
		}
    int a[100009];
    for(int i=0;i<(sizeof(a)/sizeof(a[0]));i++){
    a[i]=-1;
    }
    VI que;
    int ch[100009] = {};
    rep(i,0,N){
      if (a[i] != -1){
        continue;
      }
      a[i] = 0;
      que.push_back(i);
      while (que.empty() == false){
        int x = que.back();
        que.pop_back();
        
        for(auto q: g[x]){
          if(ch[x] == 1){ break;}
          
          if((a[q.first] != (a[x]+q.second)) && (a[q.first] != -1)){
            std::cout << "No" << '\n';
            exit(0);
          }
          a[q.first] = a[x] + q.second;
          que.push_back(q.first);
        }
        ch[x] = 1;
      }

    }
    std::cout << "Yes" << '\n';
}

Measured memory_bytes: 10748
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n
    
  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
        return

    if self.parents[x] > self.parents[y]:
        x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
P = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(M)]

uf = UnionFind(N)
for xy in XY:
  x, y = xy                       
  uf.union(x - 1, y - 1)
                         
ans = 0
for itr, val in enumerate(P):
  if itr == val - 1 or uf.same(itr, val - 1):
    ans+=1

print(ans)

Measured memory_bytes: 33760
<?php
fscanf(STDIN, "%s", $data);
$l = strlen($data);

for($i = 0; $i < $l; $i++) {
	$char = substr($data, $i, 1);
	if (substr_count($data, $char) % 2 == 0 ){
		$result = "Yes";
	}
	else{
		$result = "No";
		break;
	}
}

echo $result . "\n";
?>


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

const int MAX = 1e6;
const int MOD = 1e9 + 7;

long long f[MAX], finv[MAX], inv[MAX];

void CombInit() {
  f[0] = f[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    f[i] = f[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long Perm(int n, int k) {
  if (n < k || k < 0) return 0;
  return f[n] * finv[n - k] % MOD;
}

long long Comb(int n, int k) {
  if (n < k || k < 0) return 0;
  return f[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long int conb(long long int a,long long int b){
  if(b==1){
    return a;
  }else{
    return (((conb(a,b-1)*(a-b+1))%MOD)*inv[b])%MOD;
  }
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
  long long int n,a,b,kotae;
  cin>>n>>a>>b;
  CombInit();
  kotae=modpow(2,n,MOD);
  kotae=(kotae-conb(n,b)-conb(n,a)-1+MOD*2)%MOD;
  cout << kotae;
}

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

using Lint=long long;

bool isPrime(int N)
{
   if(N<2) return false;
   for(int i=2;i*i<=N;i++) if(N%i==0) return false;
   return true;
}
int main()
{
   int x; cin>>x;
   while(!isPrime(x)) x++;
   cout<<x<<endl;
   return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

const int IINF = 2002002002;
const ll LINF = 9009009009009009009L;

//===

int gcd(int a, int b) {
	if (a < b) swap(a, b);
	
	int r = a % b;
	while (r) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

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

	Vi A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}

	int ans = A[0];
	for (int i = 1; i < N; ++i) {
		ans = gcd(ans, A[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
s=input()
ss=set(s)
a=["N","W","S","E"]
flg=False
if all(a[i] in s for i in range(4)):
    flg=True
if a[0] in s and a[1] not in s and a[2] in s and a[3] not in s:
    flg=True
if a[0] not in s and a[1] in s and a[2] not in s and a[3] in s:
    flg=True
if flg:
    print("Yes")
else:
    print("No")

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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll N; cin >>N;

    ll cap;
    ll cap_min = LLONG_MAX;
    rep(i, 5) {
        cin >> cap;
        chmin(cap_min, cap);
    }

    ll ans = (N + cap_min - 1) / cap_min + 4;

    cout << ans << endl;
}


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

const int n = 4;

vector<pair<ll,ll>> prime_factorization(ll n) {
	vector<pair<ll,ll>> pf;

	for(ll i = 2; i*i <= n; i++) {

		if(n%i != 0) continue;

		ll ex = 0;

		while(n%i == 0) {
			ex++;
			n /= i;
		}
		pf.push_back({i,ex});
	}

	if(n != 1) pf.push_back({n,1}); 
	// nが素数のときprime_factorization(n) = < {n,1} >
	return pf;
}

int main() {

	ll n; cin >> n;

	vector<pair<ll,ll>> pf = prime_factorization(n);
	ll cnt = 0;
	bool z = false;
	int tmp = 0;
	for(pair<ll,ll> p: pf) {
		ll x = p.second
;		ll i = 1;
		while(i <= x) {
			 x -= i;
			 i++;
			 cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    vector<int> A(5);
    rep(i, 5) cin >> A[i];
      for (int i = 1; i <= 5; i++) {
          if (!count(A.begin(), A.end(), i)) {
              cout << i << '\n';
              break;
          }
      }
    return 0;
    // ll, 0, -, 1i, for s&g
}

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int main() {
    int n, m, x, y;
    cin >> n >> m;
    bool red[n + 5];
    red[1] = true;
    for(int i = 2; i <= n; i++) red[i] = false;
    int count[n + 5];
    for(int i = 1; i <= n; i++) count[i] = 1;
    for (int i = 1; i <= m; i++) {
        cin >> x >> y;
        count[x]--;
        count[y]++;
        if(red[x]) red[y] = true;
        if(count[x] == 0) red[x] = false;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(red[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
X[2001];
main(){
	int N,M,i,p,g;
	for(;scanf("%d%d",&N,&M),N;){
		for(i=1;i<=N+M;i++)
			scanf("%d",X+i);
		p=1;
		g=0;
		for(i=1;i<=M;i++){
			p+=X[N+i];
			if(p<N)
				p+=X[p];
			if(!g&&p>=N)
				g=i;
		}
		printf("%d\n",g);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+500;
ll n,a[maxn],sum[maxn],ans;

int main()
{
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        sum[a[i]]++;
    }
    for(int i = 1; i < maxn; ++i) sum[i]+=sum[i-1];
    for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j){
        if(i==j) continue;
        ll ll = abs(a[i]-a[j]),rr = a[i]+a[j]-1;
        ans += sum[rr]-sum[ll];
        if(a[i]>ll&&a[i]<=rr) ans--;
        if(a[j]>ll&&a[j]<=rr) ans--;
    }
    cout << ans/6LL << endl;
    return 0;
}


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

const ll MAXN = 200000;

ll N, ans=0, tmp=0;
vector<ll> A(MAXN, 0);
string T;
signed main(){
    cin >> T;
    for(int i=0;i<T.size();i++) {
        if(T[i]=='?') T[i]='D';
    }
    cout << T << endl;
    return 0;
}

Measured memory_bytes: 5144
#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 < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


int main(){
  int N;
  cin >> N;
  int currentX = 0, currentY = 0,currentTime = 0;
  rep(i,N){
    int t,x,y,dist,nextTime;
    cin >> t >> x >> y;
    nextTime = t - currentTime;
    dist = abs(x - currentX) + abs(y - currentY);
    //cout << "dist = " << nextTime - dist << endl;
    if(nextTime < dist){
      cout << "No" << endl;
      return 0;
    }else if(nextTime > dist){
      if((nextTime - dist) % 2 == 1){
        cout << "No" << endl;
        return 0;
      }
    }
    currentX = x;
    currentY = y;
    currentTime = t;
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, A, B, C = map(int, input().split())
L = []
for i in range(N):
    l = int(input())
    L.append(l)

def dfs(cur, a, b, c):
    if cur == N:
        # 竹を使ってないと駄目
        if min(a, b, c) == 0:
            return INF
        else:
            return abs(a-A) + abs(b-B) + abs(c-C)

    ret0 = dfs(cur+1, a, b, c)
    # 最初の一本目はカウント除外、２本めからMP10
    ret1 = dfs(cur+1, a + L[cur], b, c) + (10 if a > 0 else 0)
    ret2 = dfs(cur+1, a, b + L[cur], c) + (10 if b > 0 else 0)
    ret3 = dfs(cur+1, a, b, c + L[cur]) + (10 if c > 0 else 0)

    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    S = input()
    T = input()

    numdic = [0]*(100000)
    for i in range(len(S)+1-len(T)):
        small = S[i:i+len(T)]
        same = 0
        for s in range(len(T)):
            if small[s] == T[s]:
                same += 1
        numdic[i] = same

    ans = len(T) - max(numdic)
    print(ans)




if __name__ == '__main__':
    solve()

Measured memory_bytes: 73860
#include<stdio.h>
int main(){
double a,b,c,d,e,f,x,y;
while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
 y=(c*d-f*a)/(b*d-e*a);
 x=(c-b*y)/a;
 printf("%.3f %.3f\n",x,y);
 }
return 0;}

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

#define SENTINEL 1000000000
int count = 0;
void merge(long long int A[], int left, int mid, int right);
void mergeSort(long long int A[], int left, int right) {
	int i, mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}



void merge(long long int A[], int left, int mid, int right) {
	int n1, n2, i, j, k;
	long long int *L, *R;
	n1 = mid - left;
	n2 = right - mid;
	L = (long long int *)malloc(sizeof(long long int)*(n1 + 1));
	R = (long long int *)malloc(sizeof(long long int)*(n2 + 1));
	for (i = 0; i <= n1 - 1; i++) {
		L[i] = A[left + i];
	}
	for (j = 0; j <= n2 - 1; j++) {
		R[j] = A[mid + j];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	i = 0;
	j = 0;
	for (k = left; k <= right - 1; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
			count++;
		}
		else {
			A[k] = R[j];
			j++;
			count++;
		}
	}
	free(L);
	free(R);
}

int main() {
	long long int a, b, c, d, n, m, num[2000]= {}, result = 0;
	char str[200005];
	scanf("%lld%lld", &n,&m);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &num[i]);
	}
	mergeSort(num, 0, n);

	for (int i = n-1; i >=n-m; i--) {
		result += num[i];
	}
	printf("%lld", result);
}


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

int main(){
  int n,a,b,c,D[1000],cal;
  double res;

  cin>>n;
  cin>>a>>b;
  cin>>c;
  for(int i=0;i<n;i++){
    cin>>D[i];
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(D[i]<D[j]){
       int tmp=D[i];
       D[i]=D[j];
       D[j]=tmp;
      }
    }
  }
  for(int i=1;i<n+1;i++){
    if(i==1){
      cal=D[i-1]+c;
      res=(double)cal/(a+b*i);
    }
    if(i>=2){
      cal+=D[i-1];
      if(res<(double)cal/(a+b*i)){
       res=(double)cal/(a+b*i);
    }
    }
  }
  res=(int)res;
  cout<<res<<endl;
}

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

signed main(){
  int N,ans=0,i=0;
  cin>>N;
  while(pow(2,i)<=N){
    ans=i;
    i++;
  }
  cout<<pow(2,ans)<<endl;
  return 0;
}

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

using namespace std;

int w, h, ans;
int map[20][20];
int vx[4] = {-1,0,0,1};
int vy[4] = {0,-1,1,0};

int solve(int count, pair<int, int> pos){
	if(count > 10) return 999;
	for(int i=0; i<4; i++){
		if(pos.first+vy[i]<0 || h<=pos.first+vy[i] || pos.second+vx[i]<0 || w<=pos.second+vx[i]) continue;
		if(map[pos.first+vy[i]][pos.second+vx[i]] == 1) continue;
		pair<int, int> p = pos;
		while(1){
			p.first += vy[i];
			p.second += vx[i];
			//if(map[p.first][p.second] == 3)	return min(ans, count);
			if(p.first<0 || h<=p.first || p.second<0 || w<=p.second) break;
			else if(map[p.first][p.second] == 3) return count;
			else if(map[p.first][p.second] == 1){
				map[p.first][p.second] = 0;
				p.first -= vy[i];
				p.second -= vx[i];
				ans = min(ans, solve(count+1, p));
				map[p.first+vy[i]][p.second+vx[i]] = 1;
				break;
			}
		}
	}
	return ans;
}

int main(){
	while(1){
		cin >> w >> h;
		if(!w && !h) break;
		fill(map[0], map[20], 0);
		pair<int, int> pos;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				cin >> map[i][j];
				if(map[i][j] == 2){
					pos = make_pair(i, j);
					map[i][j] = 0;
				} 
			}
		}
		ans = 999;
		ans = solve(1, pos);
		if(ans == 999) ans =-1;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3000
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N; cin >> N;
	int _min = 100;
	int _max = -1;
	vector<int> a(N);
	REP(i,N) cin >> a[i];

	SORT(a);

	cout << a.back() - a.front() << endl;



	return 0;

}


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

int main() {
	int p = 0;
	int n = 0;
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'p') p++;
	}
	n = s.size() / 2;
	cout << (int) n - p << endl;
}

Measured memory_bytes: 512
using System;

public class Helloworld{
  public static void Main (){
  string moji = Console.ReadLine();
	if(moji[2] == moji[3]){
      if(moji[4] == moji[5]){
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }
    }else{
      Console.WriteLine("No");
    }
  }
}
      
  

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

int abcd;

int a, b, c, d;

void dev() {
	a = abcd / 1000;
	b = (abcd / 100) % 10;
	c = (abcd / 10) % 10;
	d = (abcd / 1) % 10;
}



void solve() {

	for (int i = 0; i < 8; i++) {
		int sum = a;
		string table = "";
		if (i & 1) {
			sum += b;
			table += '+';
		}
		else { sum -= b; table+='-'; }
		if ((i>>1) & 1) {
			sum += c;
			table += '+';
		}
		else { sum -= c;  table+='-'; }
		if ((i>>2) & 1) {
			sum += d;
			table += '+';
		}
		else { sum -= d;  table+='-'; }
		if (sum == 7) {
			cout << a << table[0] << b << table[1] << c << table[2] << d << "=7" << endl;
			return ;
		}
	}



}



int main() {
	string ipt;
	cin >> ipt;
	a = int(ipt[0] - 48);
	b = int(ipt[1] - 48);
	c = int(ipt[2] - 48);
	d = int(ipt[3] - 48);

	solve();


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define e endl
#define MAXN 2005
#define MOD 998244353
int main()
{
     int n,a,b;
     cin>>n;
     cin>>a>>b;
     int p=b%n;
     b-=p;
     if(a<=b)
          cout<<"OK"<<e;
     else
          cout<<"NG";



}


Measured memory_bytes: 3676
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        a = [1, 0, 0]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)

    def test_2(self):
        a = [0, 0, 0, 0, 0]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)

    def test_3(self):
        a = [1, 1, 1, 1, 1, 1, 1]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)

    def test_4(self):
        a = [1, 1, 1, 0, 1, 1, 0, 0]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)


def solve():
    a = read()
    b = think(a)
    write(b)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    b = [0 for x in range(len(a))]
    for i in range(len(a), 0, -1):
        # print(i)
        count = 0
        for j in range(i, len(a) + 1, i):
            # print(j, ' ', end='')
            count += b[j - 1]
        # print('', b, ',', count, ',', a[i - 1])
        if a[i - 1] % 2 == count % 2:
            b[i - 1] = 0
        else:
            b[i - 1] = 1
    result = []
    for i in range(len(b)):
        if b[i] == 1:
            result.append(i + 1)
    return result


def write(b):
    print(len(b))
    print(' '.join(list(map(str, b))))


def is_valid(a, b):
    buf = [0 for x in range(len(a))]
    for i in b:
        buf[i - 1] = 1
    for i in range(len(a)):
        mod = i + 1
        count = 0
        for j in range(len(a)):
            to_be_divided = j + 1
            if to_be_divided % mod == 0:
                if buf[j]:
                    count += 1
        if count % 2 == a[i]:
            continue
        return False
    return True


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 21728
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const ll inf = 100000000000000007LL;
using namespace std;
int n; ll f[2510][2510][2];
struct poi { int l, r; } a[5010];
bool cmp(poi a, poi b) { return a.l + a.r < b.l + b.r; }
void upd(ll &x, ll y) { x = min(x, y); }
int main() {
	scanf("%d", &n);
	rep(i, 0, n / 2) rep(j, 0, n / 2) f[i][j][0] = f[i][j][1] = inf;
	rep(i, 1, n) scanf("%d%d", &a[i].l, &a[i].r);
	sort(a + 1, a + n + 1, cmp), f[0][0][0] = 0;
	rep(i, 1, n) {
		ll x = a[i].l, y = a[i].r;
		rep(l, max(0, i - 2 - n / 2), min(i - 1, n / 2)) {
			int r = i - 1 - l;
			upd(f[l + 1][r][0], f[l][r][0] + (x + y) * (n / 2 - l - 1) + y);
			upd(f[l][r + 1][0], f[l][r][0] + (x + y) * (n / 2 - r - 1) + x);
			upd(f[l][r][1], f[l][r][0] + (x + y) * (n / 2));
			-- r; if (r < 0) continue;
			upd(f[l + 1][r][1], f[l][r][1] + (x + y) * (n / 2 - l - 1) + y);
			upd(f[l][r + 1][1], f[l][r][1] + (x + y) * (n / 2 - r - 1) + x);
		}
	}
	printf("%lld\n", f[n / 2][n / 2][n & 1]);
	return 0;
}

Measured memory_bytes: 98432
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = LI()
    s = S()
    ans = 0
    pre = 0
    for ss in s:
        if ss != pre:
            ans += 1
        pre = ss
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4724
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
ll fact(ll n)
{
ll    res=1;
    for(int i = 1; i <= n;i++){
    res = res * i ;
}
return res;
}



int main()
{   IOS;

    int n,l; cin >> n >>l;
    for(int i=l-(n-1);i<=l+(n-1);i++)
        cout << i << " " ;



    cout.precision(30);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,count=0,ans=0;
  cin>>a>>b>>c;
  int m[30];
  for(int i=0;i<b;i++){
    cin>>m[i];
  }
  for(int j=0;j<a;j++){
    for(int k=0;k<b;k++){
      int x;
      cin>>x;
      count+=x*m[k];
    }
    count+=c;
    if(count>0){
      ans++;
      count=0;
    }
    else{
      count=0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
#include <cmath>
#include <map>
std::map<long long, long long> primeFactorization(long long n) {
  // 素因数分解
  std::map<long long, long long> pf;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ++pf[i];
    }
  }
  if (n > 1) {
    ++pf[n];
  }
  return pf;
}

int main() {
  int n;
  cin >> n;
  int lim = 100;
  VEC<int> e(n + 1, 0);
  REP(i, 2, n + 1) {
    int cur = i;
    REP(j, 2, i + 1) {
      while (cur % j == 0) {
        // DUMP(cur, j, e);
        ++e[j];
        cur /= j;
      }
    }
  }
  // DUMP(e);
  map<int, int> count;
  VEC<int> num = {2, 4, 14, 24, 74};
  REP(i, 0, n + 1) {
    REP(j, 0, num.size()) {
      if (e[i] >= num[j]) ++count[num[j]];
    }
  }
  // DUMP(count);
  LL ans = count[74] + count[4] * (count[4] - 1) * (count[2] - 2)/2 +
           count[14] * (count[4] - 1) + count[24] * (count[2] - 1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
X = gets.split.map(&:to_i)
X_s = X.sort
X.each{|e|
    if e <= X_s[N / 2 - 1]
        puts X_s[ N / 2 ]
    else
        puts X_s[ N / 2 - 1 ]
    end
}


Measured memory_bytes: 23396
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll x,k,d;
		cin>>x>>k>>d;
		x=abs(x);
		ll posmoves = x/d;
		posmoves=min(posmoves,k);
		ll posfinal = x - posmoves*d;
		if((k-posmoves)>0){
			if((k-posmoves)%2==1)
			posfinal = abs(posfinal-d);
		}
		cout<<posfinal<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
    int k, s, a, b, c, cnt = 0;
    cin >> k >> s;
    for (a = 0; a <= k; a++)
    {
        for (b = 0; b <= k; b++)
        {
            if (s - a - b <= k && 0 <= s - a - b)cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a,b,check=0;
    char sym;
    do{
        scanf("%d %c %d", &a, &sym, &b);
        switch(sym){
            case '+':
                printf("%d\n", a + b);
                break;
            case '-':
                printf("%d\n", a - b);
                break;
            case '*':
                printf("%d\n", a * b);
                break;
            case '/':
                printf("%d\n", a / b);
                break;
            case '?':
                check = 1;
                break;
        }
    } while(check == 0);
    return 0;
}

Measured memory_bytes: 2660
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>

int count;
int R[250001], L[250001], S[500001];

void merge(int A[], size_t left, size_t mid, size_t right) {
	size_t n1 = mid - left;
	size_t n2 = right - mid;
	for (int i = 0; i < n1; i++) {
		R[i] = A[left + i];
	}
	for (int i = 0; i < n2; i++) {
		L[i] = A[mid + i];
	}
	R[n1] = 1000000001;
	L[n2] = 1000000001;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		if (R[i] < L[j]) {
			A[k] = R[i++];
		}
		else {
			A[k] = L[j++];
		}
		count++;
	}
}

void merge_sort(int A[], size_t left, size_t right) {

	if (left + 1 < right) {
		size_t mid = (left + right) / 2;
		merge_sort(A, left, mid);
		merge_sort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main() {
	count = 0;

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

	for (int i = 0; i < n; i++) {
		if (i != 0)printf(" ");
		printf("%d", S[i]);
	}
	printf("\n");
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 7064