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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g)
{
    for( int i = g; i < n; i++ ){
        int v = A[i];
        int j = i - g;
        while( j >= 0 && A[j] > v ){
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n)
{
    //数列 G = { 1, 4, 13, 40, 121, 364, 1093, ... } を生成
    for( int h = 1; ; ){
        if( h > n ) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for( int i = G.size()-1; i >= 0; i-- ){ //逆順に G[i] = g を指定
        insertionSort(A, n, G[i]);
    }
}

int main()
{
    cin >> n;
    //より速い入力scanf関数を使用しない
    for( int i = 0; i < n; i++ ) cin >> A[i];
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for( int i = G.size() - 1; i >= 0; i-- ){
        cout << G[i];
        if( i ) cout << " ";
    }
    cout << endl << cnt << endl;
    for( int i = 0; i < n; i++ ) cout <<  A[i] << endl;

    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    srand(time(nullptr));
    int D; cin >> D;
    vector<int> c(26+1, 0);
    for(int i = 1; i <= 26; i++) cin >> c[i];
    vector<vector<int>> s(D+1, vector<int>(26+1, 0));
    for(int i = 1; i <= D; i++)for(int j = 1; j <= 26; j++) cin >> s[i][j];
    vector<int> t(D+1, 0);
    for(int i = 1; i <= D; i++) {
        t[i] = i % 26 + 1;
    }
    ll ans = 0;
    int mx = 0;
    int id = 0;
    for(int _ = 0; _ <= 100000; _++){
        vector<int> last(26+1, 0);
        auto f = [&](int d){
            int res = 0;
            for(int i = 1; i <= 26; i++){
                res += c[i] * (d - last[i]);
                if(mx < c[i] * (d - last[i])) id = i;
            }
            return res;
        };
        vector<int> old = t;
        srand(time(nullptr));
        //t[rand() % (D-1) + 1] = rand() % 25 + 1;
        ll tmp = 0;
        for(int day = 1; day <= D; day++){
            //mx = 0;
            //t[day] = id;
            int con = t[day];
            tmp += s[day][con];
            last[con] = day;
            tmp -= f(day); 
        }
        if(ans > tmp) {
            t = old;
            continue;
        }
        ans = max(ans, tmp);
    }
    for(int i = 1; i <= D; i++) cout << t[i] << endl;
}

Measured memory_bytes: 3688
#include <stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  int a[n],k=1,ans=0;
  for(int i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n;i++)
  {
    if(a[i] == k)
    {
      ans++;
      k++;
    }
  }
  if((n-ans) == n)
  {
    printf("-1\n");
    return 0;
  }
  printf("%d\n",n-ans);
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    int c;
    while((c=a%b)!=0){
        a=b;
        b=c;
    }
    return b;
}
vector<int> divisor(int n){
    vector<int> div;
    for(int i=1;i<=n;i++){
        if(n%i==0){
            div.push_back(n/i);
        }
    }
    sort(div.begin(),div.end());
    return div;
}
int main(void){
    int n,A[3],gcdA;
    vector<int> div;
    cin>>n;
    if(n==2){
        cin>>A[0]>>A[1];
        gcdA=gcd(A[0],A[1]);
        vector<int> div=divisor(gcdA);
        for(int i=0;i<div.size();i++){
            cout<<div[i]<<endl;
        }
    }else{
        cin>>A[0]>>A[1]>>A[2];
        gcdA=gcd(A[0],gcd(A[1],A[2]));
        vector<int> div=divisor(gcdA);
        for(int i=0;i<div.size();i++){
            cout<<div[i]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3152
def comb(n, a, p):
    x = y = 1
    for i in range(a):
        x *= n - i
        x %= p
        y *= i + 1
        y %= p
    return x * pow(y, p-2, p) % p

n,a,b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod)
ans -= 1
ans -= comb(n, a, mod)
ans -= comb(n, b, mod)
print(ans % mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  string s[n];
  int a=0,b=0,c=0,d=0;
  for(int i=0;i<n;i++){
  	cin>>s[i];
    if(s[i]=="AC") a++;
    else if(s[i]=="WA") b++;
    else if(s[i]=="TLE") c++;
    else d++;
  }  
  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<b<<endl;
  cout<<"TLE x "<<c<<endl;
  cout<<"RE x "<<d<<endl;
}

Measured memory_bytes: 6752
#include<stdio.h>

int main(void){
    int i,n,m;
    for(i=1;;i++){
        scanf("%d %d",&n,&m);
        if (n!=0 || m!=0){
            if(n<m)
                printf("%d %d\n",n,m);
            else
                printf("%d %d\n",m,n);
        }else
            break;
    }
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n,m;
  cin >> n >> m;
  ll edge[n][n], edgeF[n][n];
  REP(i, n){
    REP(j, n)
      edge[i][j] = edgeF[i][j] = INF;
  }

  REP(i, m){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[a][b] = edge[b][a] = c;
    edgeF[a][b] = edgeF[b][a] = c;
  }

  REP(k, n){
    REP(i, n){
      REP(j, n)
        edge[i][j] = min(edge[i][j], edge[i][k]+edge[k][j]);
    }
  }


  ll ans = 0;
  REP(i, n){
    for(ll j = i+1; j<n; j++){
      if(edge[i][j] != edgeF[i][j] && edgeF[i][j] != INF)
        ans++;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const MOD = 998244353

func powInt(x, y int) int {
	ret := 1
	for i := 0; i < y; i++ {
		ret *= x
		ret %= MOD
	}
	return ret
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	depth := make([]int, n)
	d := nextInt()
	if d != 0 {
		fmt.Println(0)
		return
	}
	depth[d]++
	for i := 1; i < n; i++ {
		d := nextInt()
		depth[d]++
	}
	if depth[0] > 1 {
		fmt.Println(0)
		return
	}
	ans := 1
	dPrev := 1
	for _, d := range depth {
		switch {
		case d == 0:
			dPrev = 0
			continue
		case dPrev == 0:
			fmt.Println(0)
			return
		default:
			ans *= powInt(dPrev, d)
			ans %= MOD
			dPrev = d
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1920
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;


#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}



int main() {
	IOS;
	int n, k;
	cin >> n >> k;
	vector<char> ch(k);
	REP(i, k)cin >> ch[i];
	while (1) {
		string s = to_string(n);
		bool ans = true;
		REP(i, s.size()) {
			REP(j, k)if (s[i] == ch[j])ans = false;
		}
		if (ans) {
			dump(n);
			return 0;
		}
		n++;
	}
}




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

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  string s;
  cin >> n >> s;

  string d = "L";
  for (int i = 1; i < 2 * n; i++) {
    if (s[i - 1] == s[i]) {
      if (d[i - 1] == 'L')
        d += "R";
      else
        d += "L";
    } else {
      if (d[i - 1] == 'L')
        d += "L";
      else
        d += "R";
    }
  }

  lint Lc = 0, Rc = 0, res = 1;
  for (int i = 0; i < 2 * n; i++) {
    if (d[i] == 'L') {
      Lc++;
    } else {
      res = res * (Lc - Rc) % MOD;
      Rc++;
    }
  }

  if (s[0] == 'W' || s[2 * n - 1] == 'W') res = 0;
  if (Rc != Lc) res = 0;

  for (lint i = 1; i <= n; i++) res = (res * i) % MOD;
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 916
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toInt)
    val k = Math.min(K, N-1)
    val combi = Combination(N)
    var sum = MInt(0)
    for (i in 0..k) {
        sum = sum + combi(N, i) * combi(N - 1, i)
    }
    println(sum)
}

class MInt {
    private val MOD = 1000000007L
    var v: Long

    constructor(v: Long) {
        this.v = v % MOD
    }

    constructor(v: Int) {
        this.v = v.toLong() % MOD
    }

    operator fun plus(b: MInt): MInt {
        val a = MInt(v)
        a += b
        return a
    }

    operator fun minus(b: MInt): MInt {
        val a = MInt(v)
        a -= b
        return a
    }

    operator fun times(b: MInt): MInt {
        val a = MInt(v)
        a *= b
        return a
    }

    operator fun div(b: MInt): MInt {
        val a = MInt(v)
        a /= b
        return a
    }

    operator fun plusAssign(b: MInt) {
        v += b.v
        if (v >= MOD) v -= MOD
    }

    operator fun minusAssign(b: MInt) {
        v -= b.v
        if (v < 0) v += MOD
    }

    operator fun timesAssign(b: MInt) {
        v *= b.v
        v %= MOD
    }

    operator fun divAssign(b: MInt) {
        this *= b.inv()
    }

    fun inv(): MInt {
        var a = v
        var b = MOD
        var u = 1L
        var w = 0L
        while (b != 0L) {
            val t = a / b
            a -= t * b
            u -= t * w
            var tmp = a
            a = b
            b = tmp
            tmp = u
            u = w
            w = tmp
        }
        u %= MOD
        if (u < 0) u += MOD
        return MInt(u)
    }

    fun pow(N: Long): MInt {
        var ans = MInt(1)
        var a = this
        var n = N
        while (n > 0) {
            if (n.and(1) == 1L) {
                ans = ans * a
            }
            a = a * a
            n = n.shr(1)
        }
        return ans
    }

    override fun toString(): String {
        return v.toString()
    }
}

class Combination(n: Int) {
    private val fact = arrayOfNulls<MInt>(n + 1)
    private val ifact = arrayOfNulls<MInt>(n + 1)

    init {
        fact[0] = MInt(1)
        (1..n).forEach { i -> fact[i] = fact[i - 1]!! * MInt(i) }
        ifact[n] = fact[n]!!.inv()
        (n downTo 1).forEach { i -> ifact[i - 1] = ifact[i]!! * MInt(i) }
    }

    operator fun invoke(n: Int, k: Int): MInt {
        if (k < 0 || n < k) return MInt(0)
        return (fact[n]!! * ifact[k]!! * ifact[n - k]!!)
    }
}

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

int main() {
    int n,m;
    cin >> n >> m;
    int l[m];
    int r[m];
    int max_l = 0;
    int min_r = 1000000;
    for(int i=0;i<m;i++){
        cin >> l[i] >> r[i];
    }
    for(int i=0;i<m;i++){
        max_l = max(max_l, l[i]);
        min_r = min(min_r, r[i]);
    }

    if((min_r - max_l) >= 0){
        cout << min_r - max_l + 1 << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#define scanf_s scanf
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 150
#define CONSTNUM 600
int main(void)
{
	int d, sum = 0;
	while(scanf_s("%d", &d) != EOF){
		for (int i = 1; i < CONSTNUM / d; ++i) {
			sum += ((d*i)*(d*i) * d);
		}
		printf("%d\n", sum);
		sum = 0;
	}
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int H,W; cin >> H >> W;
    char a[H][W];
    map<char,int> ma;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> a[i][j];
            ma[a[i][j]]++;
        }
    }
    map<char,int> ma2;
    for(auto it=ma.begin();it!=ma.end();it++){
        it->second%=4;
        if(it->second>0){
            ma2[it->first]+=it->second;
        }
    }
    int even=0;
    int odd=0;
    for(auto it=ma2.begin();it!=ma2.end();it++){
        it->second%=2;
        if(it->second==0) even++;
        else odd++;
    }
    bool flag1=false;
    if(H%2==1&&W%2==1) flag1=true;
    if(flag1){
        if(even<(H%2*W+W%2*H)/2){
            if(odd<=1){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }else{
        if(even<=(H%2*W+W%2*H)/2){
            if(odd==0){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s[1000], t[1000];
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    int m;
    cin >> m;
    for(int i=0; i<m; i++){
        cin >> t[i];
    }
    int ans=0;
    for(int i=0; i<n; i++){
        int count=0;
        for(int j=0; j<n; j++){
            if(s[i]==s[j]) count++;
        }
        for(int j=0; j<m; j++){
            if(s[i]==t[j]) count--;
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}

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

int n;
int fie[3][3]={
	{0,1,1,},
	{2,0,0,},
	{2,0,0,}
};
int fie2[4][4]={
	{1,1,4,5,},
	{3,3,4,5,},
	{6,7,8,8,},
	{6,7,9,9,}
};

int fie3[5][5]={
	{1,1,2,2,1,},
	{2,3,3,0,1,},
	{2,0,0,3,2,},
	{1,0,0,3,2,},
	{1,2,2,1,1,},
};

int fie4[6][6]={
	{1,1,2,3,0,0,},
	{4,4,2,3,0,0,},
	{0,0,1,1,2,3,},
	{0,0,4,4,2,3,},
	{2,3,0,0,1,1,},
	{2,3,0,0,4,4,},
};

int fie5[7][7]={
	{1,1,2,2,3,3,0,},
	{4,4,0,4,4,0,1,},
	{0,0,4,0,0,3,1,},
	{0,0,4,0,0,3,2,},
	{4,4,0,4,4,0,2,},
	{0,0,4,0,0,4,3,},
	{0,0,4,0,0,4,3,},
};


int ans[1001][1001];

string str=".abcdefghijk";

int main(void){
	scanf("%d",&n);
	if(n<=2){
		printf("-1\n");
		return 0;
	}else if(n==3){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				ans[i][j]=fie[i][j];
			}
		}
	}else if(n%4==0){
		for(int i=0;i<n;i+=4){
			for(int j=0;j<4;j++){
				for(int k=0;k<4;k++){
					ans[i+j][i+k]=fie2[j][k];
				}
			}
		}
	}else{
		int pos=0;
		if(n%4==1){
			for(int j=0;j<5;j++){
				for(int k=0;k<5;k++){
					ans[j][k]=fie3[j][k];
				}
			}
			pos=5;
		}else if(n%4==2){
			for(int j=0;j<6;j++){
				for(int k=0;k<6;k++){
					ans[j][k]=fie4[j][k];
				}
			}
			pos=6;
		}else if(n%4==3){
			for(int j=0;j<7;j++){
				for(int k=0;k<7;k++){
					ans[j][k]=fie5[j][k];
				}
			}
			pos=7;
		}
		for(int i=pos;i<n;i+=4){
			for(int j=0;j<4;j++){
				for(int k=0;k<4;k++){
					ans[i+j][i+k]=fie2[j][k];
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			printf("%c",str[ans[i][j]]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 2e5 + 5;

ll n, m, k;
ll a[N];

void Solve(){
    cin >> n >> m;
    if(n == m) cout << "Yes"; else cout << "No";
}

int main(){
    Speed;
    int query = 1;
//    cin >> query;
    while(query--) Solve();
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int a1,b1,a2,b2,a3,b3,a4,b4;
   
   scanf("%d %d %d %d",&a1,&b1,&a2,&b2);
   
   a3=a2-(b2-b1);
   b3=b2+(a2-a1);
   a4=a3-(a2-a1);
   b4=b3-(b2-b1);
   
   printf("%d %d %d %d\n",a3,b3,a4,b4);
   
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct a{
    int k ;
    string s;
    int score;
} city[101];
bool cmp(a x,a y)
{   if(x.s == y.s)
    {
        if(x.score>y.score)
            return true;
        else
            return false;
    }
    else if( x.s<y.s)
        return true;
    else
        return false;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>city[i].s>>city[i].score;
        city[i].k=i+1;
    }
    sort(city,city+n,cmp);
    for(int i=0;i<n;i++)
    {
        cout<<(city[i].k)<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int N, K;
  cin >> N >> K;
  int res = 0;
  rep(i, N)
  {
    int x;
    cin >> x;
    int d1 = x;
    int d2 = abs(K - x);
    if (d1 < d2) {
      res += 2 * d1;
    } else {
      res += 2 * d2;
    }
  }
  cout << res << endl;
}

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

int main(void){
  int n;
  string s;
  cin>>n>>s;
  int cnt=0,max=0;

  r(i,s.size()){
    if(s.at(i)=='I')cnt++;
    else cnt--;
    if(max<cnt)max=cnt;
  }
  cout<<max<<endl;





  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

vector<vector<pair<int, int>>> adj;
vector<int> vis;
vector<int> color;

void dfs(int src)
{
    if (vis[src])
        return;
    vis[src] = 1;

    for (auto x : adj[src])
    {
        if (!vis[x.first])
        {
            color[x.first] = x.second % 2 ? !color[src] : color[src];
            dfs(x.first);
        }
    }
}

int main()
{
    ll n;
    cin >> n;
    adj.assign(n, vector<pair<int, int>>());
    vis.assign(n, 0);
    color.assign(n, -1);

    for (int i = 0; i < n - 1; i++)
    {
        int p, q, r;
        cin >> p >> q >> r;
        --p;
        --q;
        adj[p].push_back({q, r});
        adj[q].push_back({p, r});
    }
    color[0] = 0;
    dfs(0);

    for (int x : color)
        cout << x << endl;
}

Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N,D,X,ans;
    scanf("%d%d%d",&N,&D,&X);
    int A;
    for(int i=0;i<N;i++){
        ans+=1;
        scanf("%d",&A);
        ans+=(D-1)/A;
    }
    ans+=X;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {

r#"11 2"# => r#"4"#,

r#"1010101 10"# => r#"7"#,


r#"314159265 3"# => r#"18"#,

}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        mut n: usize, k: usize,
    }

    let mut ans = 0;
    while 0 < n {
        n = n / k;
        ans += 1;
    }

    ans.to_string()
}

Measured memory_bytes: 4352
fun main(args: Array<String>) {
    val (x, n) = readLine()!!.split(" ").map { it.toInt() }
    val l = readLine()!!.split(" ").map { it.toInt() }.groupBy { it }.mapValues { it.value.count() }.values.sortedDescending()
    println(l.sum() - l.take(n).sum())
}

Measured memory_bytes: 116176
import sys
input = lambda: sys.stdin.readline().rstrip()
from itertools import accumulate

N, M = map(int, input().split())

def find(x):
    if parents[x] < 0:
        return x
    parents[x] = find(parents[x])
    return parents[x]    

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

    if x == y:
        return
    if x > y:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x    

def same(x,y):

    return find(x) == find(y)

def count_root(x):

    return parents[find(x)]

edges = []

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a,b))
parents = [-1] * N
ans = [0] * M
ans[-1] = N * (N-1) // 2

for i in range(M-1, 0, -1):
    c1, c2 = edges[i]

    if not same(c1, c2):
        ans[i-1] = ans[i] - count_root(c1) * count_root(c2)
        union(c1,c2)
    else:
        ans[i-1] = ans[i]     

for a in ans:
    print(a)

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    string s;
    cin >> s;

    string origin = s;
    reverse(s.begin(), s.end());

    int ans = 0;
    rep(i, s.length()){
        if(origin[i] == s[i]) continue;
        ans++;
    }
    if(ans > 0) ans /= 2;
    OP(ans);
}


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

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n, k, fact[MAXN], inv[MAXN], inverse[MAXN], ans = 1;
vector<ll> adj[MAXN];

void DFS(ll v, ll p = -1) {
    ll K = k - 2;
    if (p == -1) K++;

    ll deg = 0;
    for (ll u : adj[v]) {
        if (u == p) continue;
        deg++;
        DFS(u, v);
    }
    if (deg > K) {
        cout << 0 << endl;
        exit(0);
    }
    ans = ans * fact[K] % MOD * inv[K - deg] % MOD;
}

int main() {
    fast_io;

    fact[0] = 1;
    inv[0] = 1;
    inverse[1] = 1;
    for (ll i = 2; i < MAXN; i++) inverse[i] = (MOD - MOD / i) * inverse[MOD % i] % MOD;
    for (ll i = 1; i < MAXN; i++) fact[i] = fact[i - 1] * i % MOD, inv[i] = inv[i - 1] * inverse[i] % MOD;

    cin >> n >> k;
    for (ll i = 1; i < n; i++) {
        ll v, u;
        cin >> v >> u;
        adj[v].push_back(u);
        adj[u].push_back(v);
    }
    DFS(1);
    cout << ans * k % MOD << endl;


    return 0;
}
/*

*/


Measured memory_bytes: 56064
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: i64,
        b: i64,
        x: i64,
    }
    const MOD: i64 = 1_000_000_007;
    let tot;
    if x < a {
        tot = x % MOD;
    } else {
        let ex = (x - a) / (a - b) + 1;
        tot = (x + (ex % MOD) * (b % MOD) % MOD) % MOD;
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



Measured memory_bytes: 9068
N = int(input())
S = [0] * N
P = [0] * N

n = [i for i in range(N)]

for i in range(N):
    S[i], P[i] = input().split()
    P[i] = int(P[i])

items = zip(S, P, n)
items = sorted(items, key = lambda x:(x[0], -x[1]))

for S, P, n in items:
    print(n + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define N 100001
ll n,c,k,t[N],ans=0;
ll j=0;

int main(){
	cin>>n>>c>>k;
	FOR(i,0,n){
		cin>>t[i];
	}
	t[n]=1e9+3;
	sort(t,t+n+1);
	ll ti=t[0];
	ll p=0;
	FOR(i,0,n){
		if(t[i]<=ti+k){
			p++;
			if(p==c){
				ti=t[i+1];
				p=0;
				ans++;
			}
		}else{
			ans++;
			p=1;
			ti=t[i];
		}
	}
	if(p)ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class AAddtion
    {
        public static void Main(string[] args)
        {
            new AAddtion().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var n = cin.ReadInt;
            var aList = cin.ReadIntArray(n);
            var count =0;

            for(int i = 0; i<aList.Length; i++){
                count += aList[i]!=i+1 ? 1 : 0;
            }
            var ans = count <=2 ? "YES" : "NO";

            WriteLine(ans);
        }
    }
}
public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

Measured memory_bytes: 11220
import sys

K,T = map(int, sys.stdin.readline().split())
a = map(int, sys.stdin.readline().split())

limit = K/2 + K%2
am= max(a)

if am > limit:
    print (am-1) - (K - am)                                                                                                                                                                                                           
else:
    print 0

Measured memory_bytes: 2568
import numpy as np

N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.empty([N, M], dtype = int)
for n in range(N):
    A[n] = np.array(list(map(int, input().split())))

print ((((A * B).sum(1) + C) > 0).sum())


Measured memory_bytes: 12392
#include<cstdio>
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	long long int ans=1;
	if(n<m){
		int k=n;
		n=m;
		m=k;
	}
	if(n-m>=2){
		ans=0;
	}else if(n-m==1){
		for(int i=1;i<=n;i++){
			ans=(ans*i)%1000000007;
		}
		for(int i=1;i<=m;i++){
			ans=(ans*i)%1000000007;
		}
	}
	else{
		ans=2;
		for(int i=1;i<=n;i++){
			ans=(ans*i)%1000000007;
		}
		for(int i=1;i<=m;i++){
			ans=(ans*i)%1000000007;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    bool firstHand = (S[0] == '1');
    vector<int> vec;
    auto cur = S[0];
    int cnt = 0, cnt0 = (S[0] == '0' ? 1 : 0);
    for (auto c : S) {
        if (c == cur) {
            ++cnt;
        } else {
            if (c == '0') ++cnt0;
            vec.push_back(cnt);
            cnt = 1;
            cur = c;
        }
    }
    vec.push_back(cnt);
    if (cnt0 <= K) {
        cout << S.size() << endl;
        return 0;
    }
    int len = 2 * K + 1 - (S[0] == '1' ? 0 : 1) - (S.back() == '1' ? 0 : 1);
    if (vec.size() <= len) {
        cout << S.size() << endl;
        return 0;
    }

    for (int i = 1; i != vec.size(); ++i) {
        vec[i] += vec[i - 1];
    }
    int ret = 0;
    if (S[0] == '0') {
        len = 2 * K;
        ret = vec[len - 1];
        int idx = len + 1;
        ++len;
        while (idx < vec.size()) {
            ret = max(ret, vec[idx] - vec[idx - len]);
            idx += 2;
        }
    } else {
        len = 2 * K + 1;
        ret = vec[len - 1];
        int idx = len + 1;
        while (idx < vec.size()) {
            ret = max(ret, vec[idx] - vec[idx - len]);
            idx += 2;
        }
    }
    if (S.back() == '0') {
        ret = max(ret, vec.back() - vec[vec.size() - 1 - 2 * K]);
    } else {
        ret = max(ret, vec.back() - vec[vec.size() - 1 - 2 * K - 1]);
    }
    cout << ret << endl;
    return 0;
}

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

int main() {

    string s;
    cin>>s;
    int a=0;
    int b=0;
    int c=0;

    for(int i=0;i<3;i++){
        if(s[i] == 'a'){
            a++;
        }
        else if(s[i] == 'b'){
            b++;
        }
        else if(s[i] == 'c'){
            c++;
        }
    }

    if(a==1 && b==1 && c==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

vector<vector<pair<int, int>>> to(100000);
vector<int> ans(100000);

void dfs(int v = 0, int p = -1, int c = 0)
{
  ans.at(v) = c;
  for (auto n : to.at(v)) {
    if (n.first == p) continue;
    dfs(n.first, v, n.second xor c);
  }
}

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

  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--; w %= 2;
    to.at(u).emplace_back(v, w);
    to.at(v).emplace_back(u, w);
  }

  dfs();

  for (int i = 0; i < n; i++) {
    cout << ans.at(i) << endl;
  }
}


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

int main() {
   long long a, b;
   cin >> a >> b;
   for(long long i = 1; i <=b; i++){
		if((a*i)%b==0){
			cout<<a*i<<"\n";
			break;
		}	
	}

return 0;
}


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

namespace AGC012
{
    public class A
    {
        private void Run()
        {
            var N = int.Parse(Console.ReadLine().Trim());
            var A = Console.ReadLine().Trim().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();
            Console.WriteLine(A.Take(N * 2).Where((x, i) => i % 2 == 1).Sum());
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new A().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 55688
#include <iostream>
#define M 1000000007 
using namespace std;
long long int mod_pow(long long int x, long long int n, long long int mod) {
    long long int res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int main() { 
    int n,m; cin >> n >> m;
    cout << mod_pow(n, m, M) << endl;
}


Measured memory_bytes: 3100
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N;
	cin >> N;
	cout << N / 3;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair <char, int> P;

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

    int n;
    cin >> n;

    vector <P> vec(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        cin >> vec[i].first >> vec[i].second;
        vec[i].second--;
    }

    int white[n][n+1]; // 白iより前に、i+1以上の白とj以上の黒がいくつあるか
    int black[n][n+1]; // 黒iより前に、i+1以上の黒とj以上の白がいくつあるか

    vector <int> white_count(n, 0);
    vector <int> black_count(n, 0);

    for (int i = 0; i < 2 * n; i++) {
        char color = vec[i].first;
        int idx = vec[i].second;

        // 累積和
        vector <int> white_sum(n + 1, 0); // j以上の白がいくつあるか
        vector <int> black_sum(n + 1, 0); // j以上の黒がいくつあるか
        for (int j = n-1; j >= 0; j--) {
            white_sum[j] = white_count[j] + white_sum[j+1];
            black_sum[j] = black_count[j] + black_sum[j+1];
        }

        for (int j = 0; j <= n; j++) {
            if (color == 'W') white[idx][j] = black_sum[j] + white_sum[idx+1];
            if (color == 'B') black[idx][j] = white_sum[j] + black_sum[idx+1];
        }

        if (color == 'W') white_count[idx]++;
        if (color == 'B') black_count[idx]++;
    }

    int dp[n+1][n+1]; // 白をi個、黒をj個置いた時の転倒数の最小値
    fill(dp[0], dp[n+1], (1<<30));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (i < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + white[i][j]);
            if (j < n) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + black[j][i]);
        }
    }

    cout << dp[n][n] << "\n";
    return 0;
}

Measured memory_bytes: 47232
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

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

    int n, t;

    cin >> n >> t;

    vector<pair<int, int>> a(n);

    for (int i = 0; i < n; i++)
        cin >> a[i].first >> a[i].second;

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

    vector<int> d(t, INT_MIN);
    d[0] = 0;

    int ans = 0;

    for (int i = 0; i < n; i++)
        for (int j = t - 1; j >= 0; j--) {
            if (d[j] == INT_MIN)
                continue;

            int f = a[i].first;
            int s = a[i].second;

            ans = max(ans, d[j] + s);

            if (j + f < t)
                d[j + f] = max(d[j + f], d[j] + s);
        }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  int LMAX=1;
  int RMIN=1000000;
  for(int i;i<M;i++){
    int L,R;
    cin>>L>>R;
    if(LMAX<L){
      LMAX=L;
    }
    if(RMIN>R){
      RMIN=R;
    }
  }
  if(RMIN>N){
    if(N<LMAX){
      cout<<0<<endl;
    }else{
      cout<<N-(LMAX-1)<<endl;
    }
  }else{
    if(LMAX>RMIN){
      cout<<0<<endl;
    }else{
      cout<<RMIN-(LMAX-1)<<endl; 
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i]; 
    for (int i = 0; i < c; i++) cin >> r[i];
    sort(p.begin(), p.end(), greater<ll>()); 
    sort(q.begin(), q.end(), greater<ll>()); 
    sort(r.begin(), r.end(), greater<ll>());
    vector<ll> v;
    for (int i = 0; i < x; i++) v.push_back(p[i]);
    for (int i = 0; i < y; i++) v.push_back(q[i]);
    for (auto t: r) v.push_back(t);
    sort(v.begin(), v.end(), greater<ll>()); 
    ll ans = 0;
    for (int i = 0; i < x + y; i++) ans += v[i];
    cout << ans << endl;
    return 0;
}

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

int main() {
	int H, W;
	cin >> H >> W;

	int h, w;
	cin >> h >> w;

	cout << H * W - (h*W + w*H - h*w) << endl;
	return 0;
}

Measured memory_bytes: 256
fn read() -> Vec<i32> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let n = input
        .trim()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect();
    n
}

fn main() {
    let n = read()[0];
    let n = n as usize;
    let mut a = read();

    a.sort();
    a.reverse();

    let mut alice = 0;
    let mut bob = 0;

    for i in 0..n {
        if i % 2 == 0 {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    println!("{}", alice - bob)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define err(x) debug() << "[" << #x << ": " << x << "]\n"
template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);
struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator<<(pair<c,d> e){
    return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator<<(c a){
    cerr << boolalpha << a;
    return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator<<(c a){
    *this << "{";
    for (auto it = a.begin(); it != a.end(); it++)
        *this << ","[1 - (it != a.begin())] << *it;
    return *this << "}";
}
#else
template<class c>debug& operator<<(c){
    return *this;
}
#endif
};







int main() 
{
    
    ll r, d, x;
    cin >> r >> d >> x;
    
    for (int i = 0; i < 10; ++i)
    {
        x = r * x - d;
        
        cout << x << endl;
    }
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char s[101][101];
int dp[101][101];
int main()
{
	int h,w;
	cin>>h>>w;
	for(int i=0;i<101;i ++)dp[i][0] = dp[0][i] = 0x3f3f3f3f;
	for(int i=1;i<=h;i++)
	{
		getchar();
		for(int j=1;j<=w;j++)
		{
			scanf("%c",&s[i][j]);
		}
	}
	dp[1][0]=dp[0][1]=0;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(s[i][j]=='.')
			{
				dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
			}
			else
			{
				dp[i][j]=min(dp[i-1][j]+(s[i][j]==s[i-1][j]?0:1),dp[i][j-1]+(s[i][j]==s[i][j-1]?0:1));
			}
		}
	}
	cout<<dp[h][w]<<endl;
}

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


int main(){

    ll n ,t,i ;
    string r ,s ;
    cin >> n>>t ;
    if (n<t){
        for(i=0;i<t;i++)
            cout << n ;
    }
    else
    {
        for(i=0;i<n;i++)
            cout << t ;
    }

    return 0 ;
}


Measured memory_bytes: 256
YOUBI = input()
if YOUBI == "MON":
  print(6)
if YOUBI == "TUE":
  print(5)
if YOUBI == "WED":
  print(4)
if YOUBI == "THU":
  print(3)
if YOUBI == "FRI":
  print(2) 
if YOUBI == "SAT":
  print(1)
if YOUBI == "SUN":
   print(7)

Measured memory_bytes: 3060
def get_leap_years(from, to)
  res = []
  from.upto(to) do |i|
    if i%400 == 0
      res << i
    elsif i%100 == 0
      next
    elsif i%4 == 0
      res << i
    end
  end
  res
end

count = 0
while gets do
  a, b = $_.split(' ').map(&:to_i)
  break if a == 0 && b == 0
  puts '' if count >= 1
  
  res = get_leap_years(a, b)
  if res.count == 0
    puts 'NA'
  else
    puts res
  end
  count += 1
end

Measured memory_bytes: 6116