akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	string s;
	cin >> s;
	int ans = 0 ;
	char c = 'R';
	if (s[0] == c && s[1] == c && s[2] == c) {
		cout << 3;
		return;
	}
	if (s[0] == c && s[1] == c ) {
		cout << 2;
		return;
	}
	if (s[1] == c && s[2] == c ) {
		cout << 2;
		return;
	}
	if (s[1] == c || s[2] == c || s[0] == c) {
		cout << 1;
		return;
	}
	cout << 0;

}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 10000000000000000
#define MOD 998244353
using namespace std;


int main(){
    int n;
    cin >> n;
    ll a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    cout<<abs(a[n-1]-a[0])<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.C
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();
			int n = cin.nextInt();
			int y = cin.nextInt();

			bool found = false;
			for (int i = Math.Min(y / 10000, n); i >= 0; i--)
			{
				for (int j = Math.Min((y - 10000 * i) / 5000, n - i); j >= 0 && !found; j--)
				{
					if (10000 * i + 5000 * j + 1000 * (n - i - j) == y)
					{
						Console.WriteLine(i + " " + j + " " + (n - i - j));
						found = true;
					}
				}
			}
			if (!found) Console.WriteLine("-1 -1 -1");

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13140
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    long double a, b, h, m;
    std::cin >> a >> b >> h >> m;

    const long double PI = acos(-1);

    long double cos_value = cos(fabsl((h + m / 60) / 6 - m / 30) * PI);

    long double ans_sq = a * a + b * b - 2 * a * b * cos_value;

    printf("%.12Lf\n", std::sqrt(ans_sq));
}


Measured memory_bytes: 4204
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i=0; i<N; i++)

// dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))

int main(int argc, char *argv[])
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    Rep(i, N) {
        cin >> h[i];
    }

    vector<LLI> dp(N);
    dp[0] = 0;
    for (int j=1; j<N; j++) {
        LLI c = dp[j-1] + abs(h[j] - h[j-1]);
        for (int k=2; k<=K && j-k>=0; k++) {
            c = min(c, dp[j-k] + abs(h[j] - h[j-k]));
        }
        dp[j] = c;
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    REP(i,N) cin >> A[i];
    REP(i,N) cin >> B[i];
    reverse(ALL(B));

    int changed = 0;
    REP(i,N) {
        if (A[i] == B[i]) {
            if (changed == i) changed++;
            while (changed != N && ( B[i] == A[changed] || B[i] == B[changed]) ) changed++;
            if (changed == N) {
                cout << "No" << endl;
                return;
            }
            auto tmp = B[i];
            B[i] = B[changed];
            B[changed] = tmp;
        }
    }
    cout << "Yes" << endl;
    REP(i,N) {
        if (i != 0) cout << " ";
        cout << B[i];
    }
    cout << endl;

}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4828
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n;
		n=sc.nextInt();
		int c=0;
		for(int i=1;i<=n;i++) {
			if(i%2==0)
				continue;
			if(div(i)==8)
				c++;
		}
		System.out.println(c);
	}
	
	public static int div(int n) {
		int cnt=0;
		for(int i=1;i<=n;i++) {
			if(n%i==0)
				cnt++;
		}
		return cnt;
	}
}

Measured memory_bytes: 23892
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += min(A[i],B[i])
    B[i] = B[i] - A[i]
    if 0 < B[i]:
        ans += min(A[i+1],B[i])
        if A[i+1] <= B[i]:
            A[i+1] = 0
        else:
            A[i+1] = A[i+1] - B[i]
print (ans)


Measured memory_bytes: 18476
import Control.Monad
main = do
  n <- readLn
  t <- map (map read . words) <$> replicateM n getLine
  let x = [0, 0, 0] : t
  let a = foldl (&&) True $ zipWith resolve x (tail x)
  putStrLn $ if a then "Yes" else "No"

resolve [t1, x1, y1] [t2, x2, y2]
  | t < d = False
  | even (d - t) = True
  | otherwise = False
  where
    d = abs (x1 - x2) + abs (y1 - y2)
    t = t2 - t1


Measured memory_bytes: 75132
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> P(N),Q(N);
    for(int i = 0;i < N;i++){
        cin >> P[i];
        Q[P[i]-1] = i;
    }
    int cnt = 1,maxi = 0;
    for(int i = 1;i < N;i++){
        if(Q[i-1] < Q[i])cnt++;
        else{
            maxi = max(maxi, cnt);
            cnt = 1;
        }
    }
    maxi = max(maxi,cnt);
    cout << N - maxi << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rt register int
#define all(it) it.begin(), it.end()
#define rep(it, f, e) for (rt it = f; it <= e; ++it)
#define per(it, f, e) for (rt it = f; it >= e; --it)
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 10;
int dp[3010][2];
int mul[MAXN], inv[MAXN];
pii poi[3010];
inline int qpow(int x, int y) {
	int ret = 1;
	while (y) {
		if (y & 1) ret = ret * 1ll * x % MOD;
		x = x * 1ll * x % MOD;
		y >>= 1;
	}
	return ret;
}
inline int C_count(int x, int y) {
	y += x;
	return mul[y] * 1ll * inv[y - x] % MOD * inv[x] % MOD;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	mul[0] = 1;
	rep (i, 1, MAXN - 1) {
		mul[i] = mul[i - 1] * 1ll * i % MOD;
	}
	inv[MAXN - 1] = qpow(mul[MAXN - 1], MOD - 2);
	inv[0] = 1;
	per (i, MAXN - 2, 1) {
		inv[i] = inv[i + 1] * 1ll * (i + 1) % MOD;
	}
	int n, m, k;
	cin >> n >> m >> k;
	rep (i, 1, k) {
		cin >> poi[i].fst >> poi[i].sed;
	}
	poi[k + 1] = mp(1, 1);
	poi[k + 2] = mp(n, m);
	k += 2;
	sort(poi + 1, poi + k + 1);
	dp[1][1] = 1;
	rep (i, 2, k) {
		rep (j, 1, i - 1) {
			int dx = poi[i].fst - poi[j].fst;
			int dy = poi[i].sed - poi[j].sed;
			if (dx >= 0 && dy >= 0) {
				ll t = C_count(dx, dy);
				dp[i][0] = (dp[i][0] + t * dp[j][1]) % MOD;
				dp[i][1] = (dp[i][1] + t * dp[j][0]) % MOD;
			}
		}
	}
	cout << (dp[k][0] - dp[k][1] + MOD) % MOD << endl;
	return 0;
}

Measured memory_bytes: 1920
func = []
A , B , N = map(int , input().split())
"""
for x in range(N+1):
    func.append((A*x) // B  - A * (x // B ))
print(max(func))
"""
if B - 1 > N:
    print((A*(N)) // B  - A * ((N) // B ))
else:
    print((A*(B-1)) // B  - A * ((B-1) // B ))


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

int main()
{
	int n;
	while( cin >> n ){
		long long int ans = 0;
		for( int a = max( n - 3000, 0 ); a <= min( n, 1000 ); ++a ){
			for( int b = max( n - a - 2000, 0 ); b <= min( n - a, 1000 ); ++b ){
				int clow = max( n - a - b - 1000, 0 );
				int chigh = min( n - a - b, 1000 );
				ans += ( chigh - clow + 1 );
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

priority_queue<long long int>pq;

int main(){
	long long int x;
	long long int a,b;
	cin>>a>>b;
	for(long long int i=0;i<a;i++){
		cin>>x;
		pq.push(x);
	}
	for(long long int i=0;i<b;i++){
		long long int as=pq.top();
		pq.pop();
		pq.push(as/2);
	}
	long long int toplam=0;
	while(pq.size()>0){
		long long int asa=pq.top();
		pq.pop();
		toplam=toplam+asa;
	}
	cout<<toplam;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main()
{
	int a,b,d,r;
	double f;
	
	scanf("%d %d",&a,&b);
	d = a / b;
	r = a % b;
	f = (double)a/b;
	printf("%d %d %f",d,r,f);
	return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

int ask(int n, const vector<int>& a)
{
    printf("? ");
    int i;
    for(i=0; i<n; i++) {
        printf("%d ", a[i]+1);
    }
    printf("\n");
    fflush(stdout);
    char str[20]={0};
    scanf("%s", str);
    if(strcmp(str, "Red")==0) {
        return 1;
    }
    else if(strcmp(str, "Blue")==0) {
        return 0;
    }
    else {
        return 99;
    }
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        a[i]=i;
    }
    int ret0=ask(n, a);
    if(ret0==99) {
        return 99;
    }

    int l=0, r=n;
    while(r-l>1) {
        int m=(l+r)/2;
        for(i=0; i<n; i++) {
            if(i<n-m) a[i]=i;
            else      a[i]=i+n;
        }
        int ret=ask(n, a);
        if(ret==99) {
            return 99;
        }
        if(ret==ret0) {
            l=m;
        }
        else {
            r=m;
        }
    }

    for(i=0; i<n; i++) {
        if(i<n-l) a[i]=i;
        else      a[i]=i+n;
    }
    int ss=n-l-1;

    vector<int> ans(n*2,-1);
    ans[n-l-1]=ret0;
    ans[n*2-l-1]=1-ret0;
    for(i=1; i<n; i++) {
        a[ss]=ss+i;
        int ret=ask(n, a);
        if(ret==99) {
            return 99;
        }
        if(ret==ret0) {
            ans[ss+i]=ret0;
        }
        else {
            ans[ss+i]=1-ret0;
        }
        a[ss]=ss;
    }

    for(i=0; i<n; i++) {
        a[i]=ss+i;
    }
    for(i=0; i<n*2; i++) {
        if(ans[i]<0) {
            a[0]=i;
            int ret=ask(n, a);
            if(ret==99) {
                return 99;
            }
            if(ret==ret0) {
                ans[i]=ret0;
            }
            else {
                ans[i]=1-ret0;
            }
        }
        a[0]=ss;
    }

    printf("! ");
    for(i=0; i<n*2; i++) {
        if(ans[i]==1) {
            printf("R");
        }
        else if(ans[i]==0) {
            printf("B");
        }
        else {
            printf("?");
        }
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 724
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll GCD = c*d/__gcd(c,d);
    ll befo=0,aft=0;
    int cnt=0;
    a--;
    aft -= b/c;
    aft -= b/d;
    aft += b/GCD;
    befo -= a/c;
    befo -= a/d;
    befo += a/GCD;
    cout << b-a+aft-befo<<endl;
    // if(a%c==0)
    // {
    //     ans += a/c;
    // }
    // else if(b%c==0)
    // {
    //     ans -= a/b;
    // }
    // else  if(a%d==0)
    // {
    //     ans += a/d;
    // }
    // else if(b%c==0)
    // {
    //     ans -= a/d;
    // }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<char,char> mp;
  string a="ATCG",b="TAGC";
  for(int i=0;i<4;++i){
    mp[a[i]] = b[i];
  }
  char c;
  cin >> c;
  cout << mp[c] << endl;
}

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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<ll, ll >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second > secondElof.second;
}
//---------------//

ll N;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;

    ll ans = 0;
    ll C[N];
    ll A, B;
    LREP(i, 0, N){
        cin >> A >> B;
        ans += - B;
        C[i] = A + B;
    }
    sort(C, C + N, greater<ll >());
    for(ll i = 0; i < N; i += 2) ans += C[i];
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x)
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0)
#define scan(x) scanf("%lld",&x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll dird = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] -= i + 1;
  sort(all(a));
  ll low = 0, up = n - 1, le, ri;
  while (up - low > 3) {
	le = (low * 2 + up) / 3;
	ri = (low + up * 2) / 3;
	ll l = 0, r = 0;
	rep(i, n) l += abs(a[i] - a[le]);
	rep(i, n) r += abs(a[i] - a[ri]);
	if (l > r) low = le;
	else up = ri;
  }
  
  ans = inf;
  FOR(i, low, up + 1) {
	tmp = 0;
	rep(j, n) tmp += abs(a[j] - a[i]);
	ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2005;

int n, m;
string s[maxn];

int a[maxn][maxn];
int h[maxn], l[maxn], r[maxn];

void read_input()
{
    cin >> n >> m;
    for(int i = 0; i < n; ++i)
        cin >> s[i];
}

void init()
{
    fill_n(&a[0][0], sizeof(a) / sizeof(a[0][0]), 1);
    for(int i = 0; i + 1 < n; ++i)
        for(int j = 0; j + 1 < m; ++j)
        {
            int cnt = 0;
            for(int ii = i; ii < i + 2; ++ii)
                for(int jj = j; jj < j + 2; ++jj)
                    cnt += (s[ii][jj] == '#');
            if(cnt & 1)
                a[i + 1][j + 1] = 0;
        }
    /*for(int i = 0; i <= n; ++i)
    {
        for(int j = 0; j <= m; ++j)
            cout << a[i][j] << ' ';
        cout << '\n';
    }*/
}

void solve()
{
    int ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j <= m; ++j)
            ++h[j];
        stack<int> stk;
        for(int j = 0; j <= m; ++j)
        {
            while(!stk.empty() && h[stk.top()] >= h[j])
                stk.pop();
            if(stk.empty()) l[j] = -1;
            else l[j] = stk.top();
            stk.push(j);
        }
        while(!stk.empty()) stk.pop();
        for(int j = m; j >= 0; --j)
        {
            while(!stk.empty() && h[stk.top()] >= h[j])
                stk.pop();
            if(stk.empty()) r[j] = m + 1;
            else r[j] = stk.top();
            stk.push(j);
        }
        for(int j = 0; j < m; ++j)
            ans = max(ans, h[j] * (min(r[j], m) - max(l[j], 0)));
        for(int j = 0; j < m; ++j)
            if(a[i][j] == 0) h[j] = 0;
    }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    init();
    solve();
}



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

// 連想配列
void answer1() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  map<int, bool> mp;
  int in;
  while (cin >> in) {
    auto itr = mp.find(in);
    if (itr == mp.end()) {
      mp[in] = true;
    } else {
      mp.erase(itr);
    }
  }
  cout << mp.size() << endl;
}

// バケット
void answer2() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<bool> bucket(pow(10, 9) + 1, false);
  for (int i = 0; i < N; i++) {
    int in;
    cin >> in;
    bucket.at(in) = ! bucket.at(in);
  }

  int count = 0;
  for (bool b: bucket) {
    if (b) {
      count++;
    }
  }
  cout << count << endl;
}

int main() {
  answer1();
  //answer2();
}


Measured memory_bytes: 4992
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    S=input()
    T=input()
    print(["No","Yes"][T[:-1]==S])
#%%submit!
resolve()

Measured memory_bytes: 61680
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n;
	cin >> n;
	if(n%2 == 0){
		long long int ans = 0;
		long long int m = n/2;
		while(m > 0){
			ans += m/5;
			m /= 5;
		}
		cout << ans << endl;
	}else{
		cout << 0 << endl;
	}
	return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
using Tu = tuple<int, int, int, int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vector<int> def(3); rep(i, 3) cin >> def[i];

  vector<int> ary(n); rep(i, n) cin >> ary[i];
  stack<pair<vector<int>, int> > s;
  vector<int> v(0);
  s.push(make_pair(v, 0));
  
  int ans = 1e9;
  while(!s.empty()) {
    pair<vector<int>, int> p = s.top(); s.pop();

    if(p.second == n) {
      vector<int> cnt(3, 0), tree = p.first;
      int cost = 0;
      int add_cnt = 0;
      rep(i, n) {
	if(tree[i] != 3) {
	  cnt[tree[i]] += ary[i];
	  cost += 10;
	  ++add_cnt;
	}
      }
      
      if(cnt[0] && cnt[1] && cnt[2]) {
	rep(i, 3) {
	  cost += abs(cnt[i] - def[i]);
	}
	
	cost = max(cost-30, 0);
	ans = min(ans, cost);
      }
    }

    if(p.second < n) {
      rep(i, 4) {
	vector<int> nv = p.first;
	nv.emplace_back(i);
	s.push(make_pair(nv, p.second+1));
      }
    }
  }
  cout << ans << endl;
}

    


Measured memory_bytes: 256
a = gets.to_i
x = []
for num in 0..a-1 do
  b = gets.chomp
  x << b
end

h = Hash.new(0)
x.each { | v | h.store(v, h[v]+1) }
h = h.sort_by { |_, v| v }.reverse
l = h.length
y =[]
for num in 0..l-1 do
  if h[num][1] == h[0][1]
    y << h[num][0]
  end
end
puts y.sort

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

int main(){
	using vc = vector<char> ;
	using vcc = vector<vc> ;
	int n,m ;
	cin >> n >> m ;
	vcc a(n,vc(n)) ;
	vcc b(m,vc(m)) ;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> a.at(i).at(j) ;
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			cin >> b.at(i).at(j) ;
		}
	}
	for(int i=0;i<n-m+1;i++){
		for(int j=0;j<n-m+1;j++){
			bool ok = true ;
			for(int k=0;k<m;k++){
				for(int l=0;l<m;l++){
					if(a.at(k+i).at(l+j)!=b.at(k).at(l)) ok =false ;
				}
			}
			if(ok){
				cout << "Yes" << endl ;
				return 0 ;
			}
		}
	}
	cout << "No" << endl ;
}

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

public class Hello{
    public static void Main(){
        //int [] str=Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int kosu=int.Parse(Console.ReadLine());
        int ans=0;
        int target;
        for(int j=0;j<kosu;j++)
        {
            target=int.Parse(Console.ReadLine());
            if(target==2)
            {
                ans++;
                continue;
            }
            if(target%2==0)continue;
            for(int i=3;i<=Math.Sqrt(target);i+=2)
            {
                if(target%i==0)goto Aiueo;
            }
            ans++;
            Aiueo: ;
        }
        Console.WriteLine(ans);
    }
}




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

const ll INF = 1LL<<60;
ll dp[20][100005];

int main(){
	int n;
	cin >> n;
	
	rep(i,11){
		rep(j,100005){
			dp[i][j] = INF;
		}
	}
	
	//dp初期条件
	rep(i,11){
		dp[i][0] = 0;
	}
	
	for (int i = 1; i <= 10 ; ++i) {
		for (int j = 1; j <= 100000 ; ++j) {
			ll one = 1;
			ll six = 1;
			ll nine = 1;
			rep(k,i){
				six *= 6;
				nine *= 9;
			}
			if(j>=one){
				dp[i][j] = min(dp[i][j], dp[i][j-one]+1);
			}
			if(j>=six){
				dp[i][j] = min(dp[i][j], dp[i][j-six]+1);
			}
			if(j>=nine){
				dp[i][j] = min(dp[i][j], dp[i][j-nine]+1);
			}
			dp[i][j] = min(dp[i][j], dp[i-1][j]);
		}
	}
	
	ll ans = dp[10][n];
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
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; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

signed main(void){
    const int MEM = 214514;
    int N;
    int A[MEM];
    int B[MEM]={},Ans[MEM]={};
    vector<int> G[MEM];
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    for(int i=1;i<=N;i++){
        for(int j=2*i;j<=N;j+=i){
            G[j-1].push_back(i-1);
        }
    }
    for(int i=N-1;i>=0;i--){
        
        Ans[i]=(A[i]+B[i])%2;
        if(Ans[i]==1){
            REP(j,G[i].size()){
                B[G[i][j]]++;
            }
        }
    }
    Ans[0]=(A[0]+B[0])%2;
    vector<int> E;
    REP(i,N){
        if(Ans[i]==1){
            E.push_back(i+1);
        }
    }
    cout << (int)E.size() << endl;
    REP(i,E.size()){
        cout << E[i] << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 40056
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

const int D = 60;
const int MAX_N = 200005;

int to[D][MAX_N];

int main() {

	ll n, k;
	cin >> n >> k;

	rep(i, n) {
		cin >> to[0][i];
		to[0][i]--;
	}

	rep(i, D-1) {
		rep(j, n) {
			to[i + 1][j] = to[i][to[i][j]];
		}
	}
	int v = 0;

	for (int i = D - 1; i >= 0; i--) {
		ll l = 1ll << i;
		if (l <= k) {
			v = to[i][v];
			k -= l;
		}
	}
	cout << v+1 << endl;
	return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;

bool check(string s)
{
   int k = s.size()/2;
   for(int i = 0; i <k; i++)
   {
      if(s[i] != s[i+k])
         return false;
   }
   return true;
}
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   string s; cin >> s;
   cout << s[0] << s.size() -2 << s[s.size()-1] << nl;
   return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
  
int main(){
  
  int n,m;
  cin>>n>>m;
  int a,b;
  vector<pair<int,int>> ab;
  REP(i,n){
    cin>>a>>b;
    ab.push_back(make_pair(a,b));
  }
  sort(ab.begin(),ab.end());
  
  priority_queue<int> q;
  int index=0;
  int ans=0;
  for(int i=m;i>=0;i--){
    while(index<n){
      if(i+ab[index].first>m){
        break;
      }else{
        q.push(ab[index].second);
        index++;
      }
    }
    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
  }
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 1908
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < n; ++i)
#define fore(i, a, b) for(int i = a; i < b; ++i)

#define endl '\n'

const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int sum = 0;
    vector<int> ar(n);
    for (int i = 0; i < n; ++i) {
        cin >> ar[i];
        sum += ar[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (abs(sum - n * ar[i]) < abs(sum - n * ar[ans])) ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import fractions
A, B, C, D = map(int, input().split())
total = B - A + 1
Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
 
print(total - Cdiv - Ddiv + CDdiv)

Measured memory_bytes: 5048
n,m = map(int,input().split())

H = [[0 for _ in range(n)] for _ in range(n) ]
edge_list = []

for _ in range(m):
    a, b = map(int,input().split())
    edge_list.append([a,b])
    H[a-1][b-1] = 1
    H[b-1][a-1] = 1
    
visited = [0 for _ in range(n)]

def dfs(node):
    visited[node] = 1
    for node_,edge_ in enumerate(H[node]):
        if edge_ == 1:
            if visited[node_] == 1:
                continue
            dfs(node_)
ans = 0
for _ in edge_list:
    H[_[0] -1][_[1] - 1] = 0
    H[_[1] -1][_[0] - 1] = 0
    
    dfs(1)
    if 0 in visited:
        ans += 1
    H[_[0] -1][_[1] - 1] = 1
    H[_[1] -1][_[0] - 1] = 1
    visited = [0 for _ in range(n)]
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int A, B, C;
	cin >> A;
	cin >> B;
	cin >> C;

	if (((A == B) && (B == C) || ((A != B))&& (B != C) && (C != A))) {
		cout<<"No";
	}
	else {
		cout << "Yes";
	}


}


Measured memory_bytes: 256
#! /usr/bin/python
# -*- coding: utf-8 -*-

N=int(input()) # 数列の長さ
A=list(map(int, input().split())) # 空白を区切文字として配列に格納

minj = 0
tmp = 0
cnt = 0

for i in range(0, N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:  #一番小さい要素よりも小さいものを記憶する
            minj = j
    if i != minj:
        cnt += 1
    tmp = A[i]  #18行目までで、一番小さい要素とi番目の要素を入れ替え
    A[i] = A[minj]
    A[minj] = tmp
    
print(*A)
print(cnt)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

void solve(){
	int h,w; cin >> h >> w;
	int l[h+2][w+2],r[h+2][w+2],u[h+2][w+2],d[h+2][w+2];
	
	// set everything to 0 
	FOR(i,0,h+2){
		FOR(j,0,w+2){
			l[i][j] = 0;
			r[i][j] = 0;
			u[i][j] = 0;
			d[i][j] = 0;
		}
	}
	
	
	
	FOR(i,1,h+1){
		FOR(j,1,w+1){
			char c; cin >> c;
			if(c == '#'){
				l[i][j] = -1;
		        r[i][j] = -1;
                u[i][j] = -1;
                d[i][j] = -1;
            }
		}
	}
	
	//debuga2(l,h+2,w+2);
	//debuga2(l,h+2,w+2);
	//debuga2(l,h+2,w+2);

    // now dp each of the grids e.g. l[i][j] indicates number of free cells to thr left of the cur cell
    FOR(i,1,h+1){
        FOR(j,2,w+1){
            if(!l[i][j]) l[i][j] += l[i][j-1]+1;
        }
    }

    FOR(i,1,h+1){
        for(int j = w-1; j>=1; --j){
            if(!r[i][j]) r[i][j] += r[i][j+1]+1;
        }
    }

	//debuga2(u,h+2,w+2);
    FOR(i,2,h+1){
        FOR(j,1,w+1){
            if(!u[i][j]) u[i][j] += u[i-1][j]+1;
        }
    }
    //debuga2(u,h+2,w+2);

    for(int i = h-1; i>=1; --i){
        FOR(j,1,w+1){
            if(!d[i][j]) d[i][j] += d[i+1][j]+1;
        }
    }
	
    int ans = 0;
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            if(u[i][j]!=-1){
                ans = max(ans,u[i][j] + d[i][j] + l[i][j] + r[i][j] + 1);
            }
        }
    }

    cout << ans;
}

 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 66284
#!/usr/bin/env python3
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = [1]
c = 1
for i in range(n):
    ans.append(a[ans[i] - 1])
b = ans.index(ans[n])
if k < b:
    for p in range(k):
        c = a[c - 1]
else:
    for p in range((k-b) % (n-b)+b):
        c = a[c - 1]
print(c)


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

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

const int N = 1e4+5;

int n, h;
int a[N],b[N];
int cache[N];

int dp(int curr)
{
      if(curr<=0) return 0;
      int &res = cache[curr];
      if(res!=-1) return res;

      res = 1e18;
      for(int i=1; i<=n; i++)
      {
            res = min(res , b[i] + dp(curr-a[i]));
      }
      return res;
}

int32_t main()
{
      IOS;
      cin>>h>>n;
      for(int i=1; i<=n; i++)
      {
            cin>>a[i]>>b[i];
      }
      memset(cache, -1, sizeof(cache));
      cout<<dp(h);


      return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

int D;
int c[26], s[365][26], t[26], last[26], ans[366];

void calc(int idx) {
    for (int i = idx; i < D; ++i) {
        ans[i + 1] = ans[i] + s[i][t[i]];
        last[t[i]] = i + 1;
        for (int j = 0; j < 26; ++j)
            ans[i + 1] -= c[j] * (i + 1 < last[j] ? i + 1 : i + 1 - last[j]);
    }
}

void greedy() {
    for (int i = 0; i < D; ++i) {
        ans[i + 1] = INT_MIN;
        int maidx = 0;
        for (int k = 0; k < 26; ++k) {
            int res = ans[i] + s[i][k], old = last[k];
            last[k] = i + 1;
            for (int j = 0; j < 26; ++j)
                res -= c[j] * (i + 1 - last[j]);

            if (ans[i + 1] < res) {
                ans[i + 1] = res;
                maidx = k;
            }
            last[k] = old;
        }
        t[i] = maidx;
        last[t[i]] = i + 1;
    }
}

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

    cin >> D;
    for (int i = 0; i < 26; ++i)
        cin >> c[i];
    for (int i = 0; i < D; ++i)
        for (int j = 0; j < 26; ++j)
            cin >> s[i][j];

    greedy();
    for (int i = 0; i < D; ++i)
        cout << t[i] + 1 << '\n';

    return 0;
}


Measured memory_bytes: 3696
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();

		int count = (int)IntStream.range(0, n - 2).filter(i -> s.substring(i, i + 3).equals("ABC")).count();
		System.out.println(count);
	}
}


Measured memory_bytes: 26448
#include <iostream>
using namespace std;
int n,m,a[20][20],c[20],X,now[20];
int ans=1e9;
inline void dfs(int x,int nw)
{
	if(x==n+1)
	{
		for(int i=1;i<=m;i++)
			if(now[i]<X) return ;
		ans=min(ans,nw);
		return ;
	}
	for(int i=1;i<=m;i++)
		now[i]+=a[x][i];
	dfs(x+1,nw+c[x]);
	for(int i=1;i<=m;i++)
		now[i]-=a[x][i];
	dfs(x+1,nw);
}
int main(int argc, char** argv) {
	cin >> n >> m >> X;
	for(int i=1;i<=n;i++)
	{
		cin >> c[i];
		for(int j=1;j<=m;j++)
			cin >> a[i][j];
	}
	dfs(1,0);
	if(ans<=5e8)
		cout << ans;
	else puts("-1");
	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    string S;cin>>S;
    bool kurisage=false;
    int dp[S.size()+1][2];
    //0はピッタリ払う
    //1は1多く払う
    REP(i,S.size()){
        int d=S[i]-'0';
      	if(i==0){
            dp[i+1][0]=d;
            dp[i+1][1]=9-d;
        }
        else{
            dp[i+1][0]=min(dp[i][0]+d,dp[i][1]+d+2);
            dp[i+1][1]=min(dp[i][0]+9-d,dp[i][1]+9-d);
        }
    }
    int ans=min(dp[S.size()][0],dp[S.size()][1]+2);
    cout<<ans<<endl;
}

Measured memory_bytes: 17028
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f(N, A) :- N mod 500 =< A.

main :-
    get_number(X, A, B),
    Y is (X - A) mod B,
    writeln(Y).


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

using namespace std;

const int MAX_N = 200000, MAX_M = 200000;
int n, m;
int a[MAX_N];
int ctr[MAX_N] = {};
int cover[MAX_N] = {};

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

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ctr[a[i]-1]++;
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < ctr[i]; ++j) {
      if (i - j >= 0) cover[i-j]++;
    }
  }

  int c = 0;
  for (int i = 0; i < n; ++i) {
    //cout << i << " " << cover[i] << endl;
    if (cover[i] == 0) c++;
  }
  //cout << c << endl;

  int x, y;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    int l = a[x-1] - ctr[a[x-1]-1];
    ctr[a[x-1]-1]--;
    if (l >= 0) {
      cover[l]--;
      if (cover[l] == 0) c++;
    }
    a[x-1] = y;
    ctr[y-1]++;
    l = y - ctr[y-1];
    if (l >= 0) {
      cover[l]++;
      if (cover[l] == 1) c--;
    }
    cout << c << endl;
  }

  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main(){
  string s;
  cin >> s;
  string S;
  S = s;
  int n = s.size();
  // if(s.size() < 7)
  // {
  //   cout << "No" << endl;
  //   return 0;
  // }
  reverse(s.begin(),s.end());
  // cout << s << endl;
  // cout << S << endl;
  if(S != s)
  {
    // cout << "1" << endl;
    cout << "No" << endl;
    return 0;
  }
  else
  {
    for(int i = 0;i < (n-1)/2-1;i++)
    {
      // cout << i << " " << (n-1)/2-i-1 << endl;
      if(s.at(i) != s.at( (n-1)/2-i-1))
      {
        // cout << "2" << endl;
        cout << "No" << endl;
        return 0;
      }
    }
    int j = 0;
    for(int i = (n+3)/2-1;i < n;i++)
    {
      // cout << i << " " << n-j-1 << endl;
      if(s.at(i) != s.at(n-j-1))
      {
        // cout << "3" << endl;
        cout << "No" << endl;
        return 0;
      }
      j++;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, first, second, third, out, point;
	char in[16];

	scanf("%d ", &n);

	while (n--) {
		first = second = third = out = point = 0;

		while (out < 3) {
			fgets(in, 15, stdin);

			if (in[1] == 'I') {
				point += third;
				third = second;
				second = first;
				first = 1;
			} else if (in[1] == 'U') {
				out++;
			} else {
				point += first + second + third + 1;
				first = second = third = 0;
			}
		}
		printf("%d\n", point);
	}
	return 0;
}

Measured memory_bytes: 600
#if !defined(ONLINE_JUDGE)
    #include "prettyprint.hpp" 
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 1729
    #define cer(x) 13
#endif
const bool testcase=0;
typedef long long int ll;
#define INF LONG_MAX
#define MINF LONG_MIN 
#define MAXR 111111
const ll mod1 = 1000000007;
const ll mod2 = 998244353;



//loop 
#define loop(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define loope(i,L,R) for (int i = L; i <= R; i++)
#define rloop(i,L,R) for (int i = L; i > R; i--)
#define rloope(i,L,R) for (int i = L; i >= R; i--)
#define nl cout<<'\n'



//misc
#define sz(x) ((int)((x).size()))
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL) 
#define checkbit(n,b) ( (n >> b) & 1)
#define test int _T_=1;if(testcase){cin>>_T_;}while(_T_--)



//vector
#define lastEle(vec) vec[vec.size()-1]
#define all(ve) ve.begin(),ve.end()
#define rall(x) x.rbegin(),x.rend()
#define fi first
#define se second



template<typename T>inline T mmod(T a,T b,T mod){return ((a%mod)*(b%mod))%mod;}
template<typename T>inline T smod(T a,T b,T mod){return ((a%mod)+(b%mod))%mod;}
template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a){in>>a.fi>>a.se;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a){for(auto &x : a)in>>x;return in;}

ll lcm(ll a,ll b){return (max(a,b)/__gcd(a,b))*min(a,b);} 

// MAIN
void solve();
int main(){
    std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
    start = std::chrono::high_resolution_clock::now();
    fast;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
        // for debug in error.txt
        freopen("error.txt", "w", stderr);
    #endif
    test {
        solve();
    }
    end = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    cerr << "\nElapsed Time: " << elapsed_time << "ms\n";
    return 0;
}


// SOLVE 
ll maxn = 111111111;
void solve() {
    ll n, k;
    cin >> n >> k;
    std::vector<ll> v(n), sum(n+1,0);
    cin >> v;
    for(int i = 0; i < n; i++) {
        sum[i+1] =  sum[i] + v[i];
    }
    for(int i = 0; i <= n; i++) {
        sum[i] = (sum[i] - i + (k * maxn))%k;
    }
    d(sum);
    ll ans = 0;
    map<ll,ll> cnt;
    for(int i = 0; i <= n; i++) {
        if(i >= k) {
            cnt[sum[i-k]]--;
        }
        ans += cnt[sum[i]];
        cnt[sum[i]]++;
    }
    cout << ans << '\n';
}



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

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

Measured memory_bytes: 256