akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

int main() {
    int N, W;
    cin >> N >> W;
    //vector<int> v(N, 0), w(N, 0);
    
    vector<vector<LL>> dp(N+1, vector<LL> (W+10, 0));
    for(int i=1; i<=N; i++) {
        LL w, v;
        cin >> w >> v;
        for(int j=0; j<=W; j++)
            dp[i][j] = dp[i-1][j];
        for(int j=0; j<=W; j++) {
            if(j+w > W) continue;
            dp[i][j+w] = max(dp[i-1][j] + v, dp[i][j+w]);
        }

    }
    LL maxim = 0;
    for(int j=0; j<=W; j++)
        maxim = max(dp[N][j], maxim);
    cout << maxim << endl;
    return 0;
}

Measured memory_bytes: 80256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int H = Integer.parseInt(S[0]);
    int W = Integer.parseInt(S[1]);
    
    boolean[] h = new boolean[H];
    boolean[] w = new boolean[W];
    char[][] field = new char[H][W];
    for(int i = 0; i < H; i++){
      String T = sc.nextLine();
      for(int j = 0; j < W; j++){
        field[i][j] = T.charAt(j);
        if(field[i][j] == '#'){
          h[i] = true;
          w[j] = true;
        }
      }
    }
    
    for(int i = 0; i < H; i++){
      boolean f = false;
      for(int j = 0; j < W; j++){
        if(h[i] && w[j]){
          f = true;
          System.out.print(field[i][j]);
        }
      }
      if(f){
        System.out.println("");
      }
    }
  }
}

Measured memory_bytes: 24144
#include <bits/stdc++.h>
#include <set>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;

const int INF = 1e9 + 5;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vi a(N); vi b(N); vi c(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  vi dp(3, INF);
  dp[0] = a[0];
  dp[1] = b[0];
  dp[2] = c[0];
  for (int i = 1; i < N; i++) {
    int aa = max(dp[1] + a[i], dp[2] + a[i]);
    int bb = max(dp[0] + b[i], dp[2] + b[i]);
    int cc = max(dp[0] + c[i], dp[1] + c[i]);
    dp[0] = aa; dp[1] = bb; dp[2] = cc;
  }
  cout << max(dp[0], max(dp[1], dp[2])) << "\n";


  return 0;
}

Measured memory_bytes: 1408
function main(lines) {
  const N = n();
  const S = s();

  let ans = 0;
  for (let i = 0; i < N-2; i++) {
    if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')
      ans++;
  }
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

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

#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define endl "\n"

#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a > b) ? b : a)

#define forn(i, a, n) for (int i = a; i < n; i++)
#define forns(i, a, n, step) for (int i = a; i < n; i += step)
#define fornr(i, a, n) for (int i = n; i > a; --i)
#define fornrs(i, a, n, step) for (int i = n; i > a; i -= step)
#define forlimits(i, l, r) for (int i = l; i <= r; i++)

// Choose auto x when you want to work with copies.
#define foritc(i, v) for (auto i = v)
// Choose auto &x when you want to work with original items and may modify them.
#define foritm(i, v) for (auto &i = v)
// Choose auto const &x when you want to work with original items and will not modify them.
#define forit(i, v) for (auto const &i = v)

#define all(v) (v).begin(), (v).end()

#define fill(arr, n, k) \
    forn(i, 0, n) { arr[i] = k; }

#define print(arr, n)                        \
    forn(i, 0, n) { cout << arr[i] << " "; } \
    cout << endl;

#define intersection(a, b, out) set_intersection(all(a), all(b), out.begin())

#define sum_n(n) (n * (n + 1) / 2)
typedef long long ll;
void solve();

int main() {
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
    return 0;
}

void solve() {
    ll n;
    string s;
    cin >> n;
    ll arr[4];
    fill(arr, 4, 0);
    forn(i, 0, n) {
        cin >> s;
        if (s == "AC") {
            ++arr[0];
        } else if (s == "WA") {
            ++arr[1];
        } else if (s == "TLE") {
            ++arr[2];
        } else if (s == "RE") {
            ++arr[3];
        }
    }
    cout << "AC x " << arr[0] << endl;
    cout << "WA x " << arr[1] << endl;
    cout << "TLE x " << arr[2] << endl;
    cout << "RE x " << arr[3] << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cstring>
#include<cstdio>
#define N 200010
using namespace std;
int minv[(1<<26)+10],bv[N],dp[N];
bool vis[(1<<26)+10];
inline int updv(int x,int p)
{
	return x^(1<<p);
}
char s[N];
inline int getv(int x,int p)
{
	return (x&(1<<p))>>p;
}
inline int out(int x)
{
	for(int i=0;i<26;i++)
		printf("%d",getv(x,i));
	cout<<endl;return 0;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),v=0;
	for(int i=0;i<26;i++)
		bv[i]=updv(0,i);
	vis[0]=true;
	for(int i=1;i<=n;i++)
	{
		v=updv(v,s[i]-'a'),dp[i]=i;
		if(vis[v]) dp[i]=minv[v]+1;
		for(int j=0;j<26;j++)
		{
			int x=v^bv[j];
			if(vis[x]) dp[i]=min(dp[i],minv[x]+1);
		}
		if(!vis[v]) minv[v]=dp[i];
		else minv[v]=min(minv[v],dp[i]);
		vis[v]=true;
	}
	return !printf("%d\n",dp[n]);
}

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


int main(){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    int x = c-b;
    if(abs(c-a)<=d) cout<<"Yes";
    else if(abs(b-a)<=d && abs(x)<=d){
        if(abs(c-a)<=2*d) cout<<"Yes";
        else cout<<"No";
    }
    else cout<<"No";
}


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

int A, B, C, K;

int main(){
  cin >> A >> B >> C >> K;
  if (K < A) cout << K << endl;
  else if (K - A < B) cout << A << endl;
  // K <= A + B + C なので残りのケースではCからK-A-B枚選ぶことになる
  else cout << A - (K - A - B) << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

    void yes(bool fl = true){
            if(fl) cout << "YES\n";
            else cout << "Yes\n";
    }
    void no(bool fl = true){
        if(fl) cout << "NO\n";
        else cout << "No\n";
    }  

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q;
        ll mod = 1e9 + 7;
        


        void solve(){
            cin >> n;
            set<string> st;
            FOR(i,0,n){
                string str; cin >> str;
                st.insert(str);
            }
            cout << st.size();
        }  
            
        int main(){
        ios_base::sync_with_stdio(false);
       
        int cases = 1;
        //cin >> cases;
    
        while(cases--){ 
            solve();
        }

        return 0;

        }

Measured memory_bytes: 19244
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

int n, m;
int a[50], b[50];
bool g[50][50] = {false};
bool visited[50];

void search(int x){
    visited[x] = true;
    rep(i, n){
        if(!g[x][i])continue;
        if(visited[i])continue;
        search(i);
    }
}
int main(){
    cin >> n >> m;
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }

    int ans = 0;
    rep(i, m){
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        rep(j, n)visited[j] = false;

        search(0);
        
        bool flag = false;
        rep(j, n)if(!visited[j])flag = true;
        if(flag)ans++;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector> //*max_element(all(変数))で最大値を獲得
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  ll k,a,b; cin >> k >> a >> b;
  if(b-a <= 2){
    cout << k+1;
  }else{
    k -= a-1;  ll biscuit = a;
    biscuit += (k/2)*(b-a) + k%2;
    cout << biscuit;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
	return k*base;
}
inline void write(int x)
{
	static char cnt,num[15];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=3e5+100;
ll n,a,b;
int c[maxn],s,cnt,k,id;
int main()
{
#ifdef ylx
	freopen("arc91c.in","r",stdin);
	freopen("arc91c.out","w",stdout);
#endif
	n=read();a=read();b=read();
	if (a+b>n+1)
	{
		printf("-1");
		return 0;
	}
	if (a*b<n)
	{
		printf("-1");
		return 0;
	}
	if (a==1)
	{
		for (int i=n;i>=1;i--) printf("%d ",i);
		return 0;
	}
	if (b==1)
	{
		for (int i=1;i<=n;i++) printf("%d ",i);
		return 0;
	}
	int aa=0;
	for (int i=1;i<=a;i++)
	{
		{
			k=b*i+1;
			while (k>b*(i-1)+1)
			{
				k--;
				id++;
				c[id]=k;
			}
			aa++;
			s++;
		}
		if (id+b>n||((n-(id+b))<a-aa))
		{
			aa=(int)a-aa;
			int ID=id;
			for (int j=ID+1;j<=min((int)n,ID+aa-1);j++)
			{
				id++;
				c[id]=j;
			}
			int Id=id;
			for (int j=n;j>=Id+1;j--)
			{
				id++;
				c[id]=j;
			}
			break;
		}
	}
	for (int i=1;i<=n;i++) printf("%d ",c[i]);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>

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

typedef long long ll;

using namespace std;

int main() {
    
    int n,k;
    cin >> n >> k;
    
    ll cnt=0;
    
    FOR(b, 1, n+1){
            /*
             if(b-1<k){
             cnt += 0;
             }else{
             cnt += (n/b) * (b-k);
             cnt += max(0,n%b-k+1);
             }
             */
            
            cnt += max(0,b-k)*(n/b);
            cnt += max(0,n%b-k+1);
            if(k==0){
                cnt--;
            }
        }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#pragma warning( disable:4996 )
using namespace std;

#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	/*char s[5];
	scanf("%s", s);
	if ((s[0] == s[1] && s[2] == s[3]) ||
		(s[0] == s[2] && s[1] == s[3]) ||
		(s[0] == s[3] && s[1] == s[2])) {
		if (s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
			printf("No\n");
		}
		else {
			printf("Yes\n");
		}
		
	}
	else {
		printf("No\n");
	}*/

	/*int n;
	int p[21];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	int count = 0;
	for (int i = 1; i < n - 1; i++) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
			(p[i + 1] < p[i] && p[i] < p[i - 1])) {
			count++;
		}
	}
	printf("%d\n", count);*/

	int n;
	int d[100001];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &d[i]);

	}
	if (n % 2 == 1) {
		printf("0\n");
	}
	else {
		sort(d, d + n);
		int mid = d[n / 2];
		int midm = d[n / 2 - 1];
		printf("%d\n", mid - midm);
	}
	
	
	return 0;
}

Measured memory_bytes: 512
import bisect
n=int(input())
a=list(map(int,input().split()))
suma=[]
sumans=0
for i in range(n):
	sumans += a[i]
	suma.append(sumans)
u=bisect.bisect_right(suma, sumans//2)
print(min(abs(2*suma[u-1]-sumans), abs(2*suma[u]-sumans)))

Measured memory_bytes: 26152
int G(x,y){return y?G(y,x%y):x;}
#define L(x,y)((long long)x/G(x,y)*y)
n[3],a[3],m[3];main(i,x){for(;scanf("%d%d%d%d%d%d",a,m,a+1,m+1,a+2,m+2),*m;n[0]*=n[1]/G(n[0],n[1]),printf("%lld\n",(long long)n[2]/G(n[0],n[2])*n[0]))for(i=3;i--;)for(x=n[i]=1;(x=a[i]*x%m[i])>1;n[i]++);}

Measured memory_bytes: 596
defmodule Main do
  def main do
    [a, b, c, d] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    a = String.to_integer(a)
    b = String.to_integer(b)
    c = String.to_integer(c)
    d = String.to_integer(d)
    cond do
    	a + b > c + d -> IO.puts("Left")
        a + b < c + d -> IO.puts("Right")
        a + b == c + d -> IO.puts("Balanced")
    end
  end
end


Measured memory_bytes: 30816
from sys import setrecursionlimit

class UnionFind:
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n

    def union(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        x, y = self.find(a), self.find(b)
        if x == y: return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        return self.find(a) == self.find(b)

    def find(self, a):
        assert 0 <= a < self._n
        if self.parent_or_size[a] < 0: return a
        self.parent_or_size[a] = self.find(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a):
        assert 0 <= a < self._n
        return -self.parent_or_size[self.find(a)]

    def groups(self):
        find_buf = [self.find(i) for i in range(self._n)]
        result = [[] for _ in range(self._n)]
        for i in range(self._n): result[find_buf[i]].append(i)
        return [r for r in result if r != []]

N, M = map(int,input().split())
uf = UnionFind(N)
setrecursionlimit(10**9+7)

for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    uf.union(a,b)

print(len(uf.groups())-1)

Measured memory_bytes: 95924
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
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;
}

template <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;

   public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

using mint = modint<MOD>;

int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N), vec(N);
    REP(i, N) { cin >> P[i]; }
    REP(i, N) { cin >> Q[i]; }
    REP(i, N) { vec[i] = i + 1; }
    int cnt = 0, a = 0, b = 0;
    while (next_permutation(ALL(vec))) {
        cnt += 1;
        if (P == vec) {
            a = cnt;
        }
        if (Q == vec) {
            b = cnt;
        }
    }
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
const int MaxN=19,MaxM=20,mod=1000000007;
int N,M,K,req[MaxM][MaxN];
int f[1<<MaxN];
int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
int main(){
	scanf("%d%d%d",&N,&M,&K);--N;
	while(K--){
		int A,B,C;scanf("%d%d%d",&A,&B,&C);
		req[A-1][B-1]=1<<C;
	}
	f[0]=1;
	for(int i=0;i<M;i++)
	for(int j=0;j<N;j++)
	for(int r=req[i][j],s=1<<N;(s-=1<<N-j)>=0;){
		int ss=s|1<<N-j-1;
		if(r==1)
			for(int k=1<<N-j-1,t=k<<1;t-->k;)f[s|t]=0;
		else{
			for(int k=1<<N-j-1;k>>=1;){
				if(r)for(int sk=s|k,t=k;t--;)f[ss|t]=add(f[ss|t],f[sk|t]),f[sk|t]=0;
				else for(int sk=s|k,t=k;t--;)f[ss|t]=add(f[ss|t],f[sk|t]);
			}
			f[ss]=add(f[ss],f[s]);r?f[s]=0:1;
		}
	}
	int sum=0;
	for(int i=0;i<1<<N;i++)(sum+=f[i])%=mod;
	printf("%d\n",sum);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

int main(){
	ll r,g,b,n;
	cin >> r >> g >> b >> n;
	vector<ll> dp(3000*2+6,0);
	dp[0] = 1;
	FOR(i,0,n)dp[i+r] += dp[i];
	FOR(i,0,n)dp[i+g] += dp[i];
	FOR(i,0,n)dp[i+b] += dp[i];
	cout << dp[n] << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[m];
        int count = 0;
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            if (a[i] < x) {
                count++;
            }
        }
        if (count <= m / 2) {
            System.out.println(count);
        } else {
            System.out.println(m - count);
        }
    }
}

Measured memory_bytes: 21844
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
hikitugi = 0

for ind,i in enumerate(B):
    if A[ind] <= i:
        ans += A[ind]
        hikitugi = i - A[ind]
        if A[ind+1] <= hikitugi:
            ans += A[ind+1]
            A[ind+1] = 0
        else:
            ans += hikitugi
            A[ind+1] = A[ind+1] - hikitugi
    else:
        A[ind] = A[ind] - i
        ans += i
print(ans)

Measured memory_bytes: 19256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    vector<ll> dp(n + 1, 0);
    rep(i, n) {
        ll ok = n - (upper_bound(all(c), b[i]) - c.begin());
        dp[i + 1] = dp[i] + ok;
    }
    ll ans = 0;
    rep(i, n) {
        ll idx = upper_bound(all(b), a[i]) - b.begin();
        ans += dp[n] - dp[idx];
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	cout << n/(a+b)*a+min(a,(n%(a+b))) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 1000000007
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        if(p1.first!=p2.first)return p1.first<p2.first;
        else return p1.second<p2.second;
    }
}; 

int main()
{
    fio;
    string s,t;
    cin>>s>>t;
    ll n=s.length(),m=t.length();
    vvl dp(n+1,vl(m+1,0));
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            dp[i][j]=max({dp[i][j],dp[i-1][j],dp[i][j-1]});
        }
    }
    ll i=n,j=m;
    string ans="";
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            ans.push_back(s[i-1]);
            i=i-1;j=j-1;
        }else{
            if(dp[i-1][j]>dp[i][j-1]){
                i=i-1;
            }else{
                j=j-1;
            }
        }
    }
    reverse(all(ans));
    cout<<ans<<endl;
}

Measured memory_bytes: 73692
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#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 Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  int count = 0;
  Cinint(n);
  vector<string> s(n);
  rep(i, n) {
    string num;
    cin >> num;
    s.at(i) = num;
  }
  map<string, int> s_map;
  rep(i, n) {
    if (!s_map.count(s.at(i))) {
      count++;
      s_map[s.at(i)] = 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 25156
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;
void solve()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	forn(i,n)cin>>arr[i];
	fora(i,k,n-1)
	{
		if(arr[i]>arr[i-k])
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
	solve();
    return 0;
}

Measured memory_bytes: 4428
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s == "a" || s == "e" || s == "i" || s == "o" || s == "u")
    {
        cout << "vowel" << endl;
    }
    else
    {
        cout << "consonant" <<endl;
    }
}


Measured memory_bytes: 256
A = gets.strip.to_i
B = gets.strip.to_i
C = gets.strip.to_i
X = gets.strip.to_i
count = 0

(0..A).each do |i|
  (0..B).each do |j|
    (0..C).each do |k|
      count += 1 if i * 500 + j * 100 + k * 50 == X
    end
  end
end
puts count

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

int main(){
  int N;
  cin>>N;
  long *A=new long[N];
  for(int i=0;i<N;i++) cin>>A[i];
  int count=1;
  bool flag_u=false;
  bool flag_d=false;
  for(int i=1;i<N;i++){
  	if(A[i]-A[i-1]>0){
      flag_u=true;
      if(flag_d){
        flag_d=false;
        flag_u=false;
        count++;
      }
    }else if(A[i]-A[i-1]<0){
      flag_d=true;
      if(flag_u){
        flag_d=false;
        flag_u=false;
        count++;
      }
    }
  }
  cout << count <<endl;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 1e5+7;
const ll inf = 1e18+5;


ll n,h[MAX];
ll dp[MAX];

ll DP(ll u){
  ll &ans = dp[u];
  if(u==1) return 0;
  if(u==2) return abs(h[u]-h[u-1]);
  if(ans!=-1) return ans; 
  ans = min(DP(u-1)+abs(h[u]-h[u-1]),DP(u-2)+ abs(h[u]-h[u-2]));
  return ans;
}
int main() {
  fastio;
  cin>>n;
  f(i,0,n+3)dp[i]=-1;
  f(i,1,n+1){
    cin>>h[i];
  }
  cout<<DP(n)<<endl;
  return 0;
}


Measured memory_bytes: 7512
#include<bits/stdc++.h>
using namespace std;
int n,x;
int main(){
    cin>>n>>x;
    int l[n];for(int i=0;i<n;i++)cin>>l[i];
    int cnt =0,d=0;
    while(d<=x){
        d+=l[cnt];cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int data;
	int a,b,c,d;
	int pair = 0;

	while( scanf("%d",&data) != EOF ){
		pair = 0;
		
		for(a=0; a<=9; a++){
			for(b=0; b<=9; b++){
				for(c=0; c<=9; c++){
					for(d=0; d<=9; d++){
						if( data == a + b + c + d){
							pair++;
						}
					}
				}
			}
		}

		printf("%d\n",pair);
	}

	return 0;
}

Measured memory_bytes: 596
/* Quick Sort */
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000;

struct Card
{
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i=0; i< n1; i++){
        L[i] = A[left + i];
    }
    for(i=0; i<n2; i++){
        R[i] = A[mid + i];
    }
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for(k=left; k<right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        } else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right)
{
    int mid;
    if(left+1 < right){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r)
{
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for(j=p; j<r; j++){
        if(A[j].value <= x.value){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    } 
    t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;
    return i+1;
}

void quickSort(struct Card A[], int n, int p, int r)
{
    int q;
    if(p < r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main()
{
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for(i=0; i<n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);

    for(i=0; i<n; i++){
        if(A[i].suit != B[i].suit){ stable = 0; }
    }

    if( stable == 1){ printf("Stable\n"); }
    else{ printf("Not stable\n"); }
    for(i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    return 0;
}


Measured memory_bytes: 4036
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;
#define inf 0x3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mp make_pair
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
const int N=1e6+7;
int n,m,k,t,a[N],l[N],r[N];
ll ans;

int main(){
    fast;
    cin>>n>>m>>k;
    forn(i,n){
        cin>>t;
        if(t<m||t>=k) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>

int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

  
    ll t;
    t=1;
    // cin>>t;
    while(t--){
      ll n;
      cin>>n;
      mmap mpp;
      set<ll>s;
      fori(0,n){
        ll x;
        cin>>x;
        s.insert(x);
        mpp[x]++;
      }
      ll ans =0;

      for(auto it = s.begin();it!=s.end();it++){
          auto ita=it;
          ita++;
        for(;ita!=s.end();ita++){
           auto itb=ita;
          itb++;
          for(;itb!=s.end();itb++)
          {
            ll a=*it,b=*ita,c=*itb;
            // cout<<a<<" "<<b<<" "<<c<<"\n";
            if(a+b>c)ans += (mpp[a]*mpp[b]*mpp[c]);
          }
      }}
          cout<<ans;
    }



  






return 0;
}     



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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    set<ll> x;
    ll tmp;
    cin >> tmp;
    x.insert(tmp);

    cin >> tmp;
    x.insert(tmp);

    if (x.find(1) == x.end()) {
        cout << 1 << endl;
    } else if (x.find(2) == x.end()) {
        cout << 2 << endl;

    } else {
        cout << 3 << endl;

    }
}


Measured memory_bytes: 256
n,m=map(int,input().split())
o,p,q,r=[],[],[],[]
def kyori(a,b,c,d):return abs(a-c)+abs(b-d)
for i in range(n):
  a,b=map(int,input().split())
  o.append(a)
  p.append(b)
for i in range(m):
  a,b=map(int,input().split())
  q.append(a)
  r.append(b)
for i in range(n):
  mind=kyori(o[i],p[i],q[0],r[0])
  minn=1
  for j in range(m-1):
    a=kyori(o[i],p[i],q[j+1],r[j+1])
    if a<mind:
      mind=a
      minn=j+2
  print(minn)

Measured memory_bytes: 3064
import collections

s=input()
t=input()

ans=True
sa=collections.Counter(s)
ta=collections.Counter(t)
for i in range(len(s)):
    if(ta.get(t[i])!=sa.get(s[i])):
        ans=False
        break
if(ans):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4016
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int uf[100001];
int kz[100001];
P hs[100001];
vector<int> ans;

int find(int x) {
  return x == uf[x] ? x : uf[x] = find(uf[x]);
}

int merge(int x, int y) {
  x = find(x);
  y = find(y);
  if(x == y) return 0;
  else {
    int tx = kz[x], ty = kz[y];
    kz[y] += kz[x];
    kz[x] = 0;
    uf[x] = y;
    return tx * ty;
  }
}

signed main() {
  int n, m;
  cin >> n >> m;

  rep(i, 0, n + 1) uf[i] = i, kz[i] = 1;
  rep(i, 0, m) cin >> hs[i].first >> hs[i].second;

  int hb = 0;
  dep(i, n - 1, 0) hb += i;
  ans.pb(hb);
  dep(i, m - 1, 1) {
    int kz = merge(hs[i].first, hs[i].second);
    hb -= kz;
    ans.pb(hb);
  }
  dep(i, ans.size() - 1, 0) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 5364
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000005

ll n, a[M], l[M], r[M], ans, res;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    l[1] = a[1], r[n] = a[n];
    for (int i = 2; i <= n; i++) l[i] = __gcd(l[i - 1], a[i]);
    for (int i = n - 1; i > 0; i--) r[i] = __gcd(r[i + 1], a[i]);
    ans = max(l[n - 1], r[2]);
    if (n >= 3){
        for (int i = 2; i < n; i++) ans = max(ans, __gcd(l[i - 1], r[i + 1]));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;
ll n,m;
vll val(N);
vector<vll>mp(N);

void solve()
{
   cin>>n>>m;
   for(int i=1;i<=n;i++)
   cin>>val[i];
   
   for(int i=0;i<m;i++)
   {
           ll a,b;
           cin>>a>>b;
           mp[a].pb(b);
           mp[b].pb(a);
   }
   
   bool marked[n+1];
   ll count = 0;
   memset(marked,0,sizeof(marked));
   for(int i =1 ; i<=n;i++)
   {
        bool done = 1;   
        if(marked[i]==0)
        {
          for(int j=0;j<mp[i].size();j++)
          {
                if(val[mp[i][j]]<val[i])
                {
                        marked[mp[i][j]] = 1; 
                }
                else
                {
                        done = 0;
                        break;
                }
          }
          
          if(done==1)
          count++;
        }
        marked[i] = 1;
   }
   cout<<count;
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

Measured memory_bytes: 10060
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

struct UnionFind{
  vector<int> par;
  UnionFind(int n) : par(n, -1){}
  int root(int x){ return (par[x] < 0) ? x : par[x] = root(par[x]); }
  int size(int x){ return -par[root(x)]; }
  bool issame(int x, int y){ return root(x) == root(y); }
  void marge(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(x > y) swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }
};

int main(void){
  int x, y;
  cin >> x >> y;
  UnionFind uf(13);
  int a[] = {1, 3, 5, 7, 8, 10, 12};
  int b[] = {4, 6, 9, 11};
  REP(i, 6) uf.marge(a[i], a[i+1]);
  REP(i, 3) uf.marge(b[i], b[i+1]);
  if(uf.issame(x, y)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);
    int m1 = -2;
    int m2 = -1;
    repi(i, a){
        if(m1 < *i){
            m2 = m1;
            m1 = *i;
        } else if(m2 < *i){
            m2 = *i;
        }
    }
    repi(i, a){
        if(*i == m1){
            cout << m2 << endl;
        } else {
            cout << m1 << endl;;
        }
    }
    return 0;
}


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

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

   vector<int> V(N);
   for (int i = 0; i < N; i++)
      cin >> V.at(i);

   vector<int> C(N);
   for (int i = 0; i < N; i++)
      cin >> C.at(i);
   
   int value = 0;
   for (int i = 0; i < N; i++)
   {
      if (V.at(i) > C.at(i))
         value += V.at(i) - C.at(i);
   }

   cout << value << endl;
}


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



int main (){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin>>A.at(i);
    }
    sort(A.begin(), A.end());
    cout<<A.at(N/2)-A.at(N/2-1);
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b;
  cin>>a>>b;
  int n[a];
  long long int s=0;
  if(a>b)
  {
  	for(int i=0;i<a;i++)
  	{
    	cin>>n[i];
  	}
    sort(n,n+a);
    for(int j=0;j<a-b;j++)
    {
      s=s+n[j];
    }
    cout<<s;
  }
  else
  {
    cout<<0;
  }
}

Measured memory_bytes: 1024
n = int(input())
A = list(map(int,input().split()))

p = sum(A)//n
q = p+1
r = p-1

ans = float("inf")
for x in [p,q,r]:
    tmp = 0
    for a in A:
        tmp += (a-x)**2
    ans = min(ans, tmp)
    
print(ans)

Measured memory_bytes: 61940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		long m = n;

		for (int i = n - 1; i > 1; i--) {
			m *= i;
		}
		System.out.println(m);

	}

}

Measured memory_bytes: 17024
#include <iostream>
#define ll long long
#define f(i, n) for (int i=0; i < n; i++)
// sort(bb, bb+n);

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    ll n,m,a,b;
    cin >> n >> m;
    a=n*(n-1)/2;
    b=m*(m-1)/2;
    cout << a+b;
    return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int MAX = 100005;
int P[MAX], Y[MAX];
vector<int> yd[MAX];
int main()
{
  int N, M;
  cin >> N >> M;
  rep(i, M)
  {
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }
  rep(i, N)
      sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, M)
  {
    printf("%06d", P[i]);
    printf("%06d\n", lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin() + 1);
  }
  return 0;
}


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

typedef long long ll;
using namespace std;

int main(){
	int n;
	cin>>n;
	n=n*3;
	ll a[n],ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(int i=1;i<n/3*2;i+=2){
		ans+=a[i];
	}
	cout <<ans<<endl;
  return 0; 
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int inf = 100005;
int s[100000];
int main()
{ll n,t1,p,d;p=0;
cin>>n;d=n;
    while (n){
        if (n < 0){
            n = -n;
            if (n % 2 == 1){
                s[++p] = 1;
                n = n / 2 + 1;
            }
            else{
                s[++p] = 0;
                n = n / 2;
            }
        }else{
            if (n % 2 == 1) s[++p] = 1;
            else s[++p] = 0;
            n = - (n / 2);
        }
    }
  for(int i=p;i>0;i--)
  cout<<s[i];
  if(d==0)cout<<0<<endl;
}

Measured memory_bytes: 256
# 2K * 2Kの正方形で一周するので、
# (X,Y) -> (X % 2K, Y % 2K)に言い換えることが出来る
# Wの表とBの表を別々で持つ
# それぞれの表で二次元累積和を持ち、範囲に対する得点を求められるようにする
# K * Kの正方形の左下隅を1000 * 1000通り全探索して最大値を求める
# 効率化のため、上記K * Kの正方形が黒である場合と白である場合を同時に計算する
# その領域で見つけた白の個数は、黒を計算するときは「白の総数 - 見つけた白の個数」とすることで白の得点として加算できるえ

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
white = [[0] * (2 * K + 1) for i in range(2 * K + 1)]
black = [[0] * (2 * K + 1) for i in range(2 * K + 1)]
# 黒を数えるときは、同時に白を数えて、白全体の数から引く
white_all = 0
black_all = 0
for i in range(N):
  x,y,c = readline().split()
  x,y = int(x) % (2 * K),int(y) % (2 * K)
  if c == "W":
    white[x + 1][y + 1] += 1
    white_all += 1
  else:
    black[x + 1][y + 1] += 1
    black_all += 1
  
for i in range(1, len(white)):
  for j in range(1, len(white[i])):
    white[i][j] += white[i][j - 1]
    
for j in range(1, len(white)):
  for i in range(1, len(white[j])):
    white[i][j] += white[i - 1][j]

for i in range(1, len(black)):
  for j in range(1, len(black[i])):
    black[i][j] += black[i][j - 1]
    
for j in range(1, len(black)):
  for i in range(1, len(black[j])):
    black[i][j] += black[i - 1][j]

cases = ((0,0),(K,K),(-K,-K),(K,-K),(-K,K))
ans = 0
  
for i in range(1, K + 1):
  for j in range(1, K + 1):
    # 基本となる黒の正方形の左下隅・右上は以下の通り
    # (i,j),(i + K - 1, j + K - 1)
    # これに対して、
    # i,jともに +Kしたもの
    # i,jともに -Kしたもの
    # iは+K,jは-Kしたもの
    # iは-K,jは+Kしたもの
    # が考えられる範囲となる
    # なお、最小値は1,1、最大値は2 * K,2 * Kとなる
    black_cnt = 0
    white_cnt = 0
    for c in cases:
      x1 = i + c[0]
      y1 = j + c[1]
      x2 = x1 + K - 1
      y2 = y1 + K - 1
        
      x1 = max(1, x1)
      y1 = max(1, y1)
      x2 = min(2 * K, x2)
      y2 = min(2 * K, y2)
      if x1 > x2 or y1 > y2:
        continue
        
      # その領域の黒と白の数を数える
      black_cnt += black[x2][y2] - black[x2][y1 - 1] - black[x1 - 1][y2] + black[x1 - 1][y1 - 1]
      white_cnt += white[x2][y2] - white[x2][y1 - 1] - white[x1 - 1][y2] + white[x1 - 1][y1 - 1]
      
    # その正方形が黒の場合と白の場合を両方足し合わせる
    point = max(black_cnt + (white_all - white_cnt),white_cnt + (black_all - black_cnt))
    if ans < point:
      ans = point
    
print(ans)

Measured memory_bytes: 138420