akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    map<string, bool> used;
    string last = s[0];
    used[last] = true;
    rep(i, 1, n)
    {
        if (last.back() != s[i].front() || used[s[i]])
        {
            cout << "No" << endl;
            return 0;
        }
        last = s[i];
        used[last] = true;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> divisor(T n) {
	vector<T> res;
	for (T i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.emplace_back(i);
			if (i * i != n) res.emplace_back(n / i);
		}
	}
	sort(res.begin(), res.end());
	return res;
}


int main() {

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

	int N, K;
	cin >> N >> K;

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

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

	auto div = divisor(sum);

	for (int i = (int)div.size() - 1; i >= 0; i--) {

		vector<int> rem;
		for (int j = 0; j < N; j++) {
			int tmp = A[j] % div[i];
			if (tmp) rem.emplace_back(tmp);
		}
		sort(rem.begin(), rem.end());

		int cnt = 0, ptr1 = 0, ptr2 = (int)rem.size() - 1;
		while (ptr2 - ptr1 > 0) {

			int k = div[i] - rem[ptr2];
			ptr2--;
			cnt += k;

			while (k) {
				if (k >= rem[ptr1]) {
					k -= rem[ptr1];
					ptr1++;
				}
				else {
					rem[ptr1] -= k;
					k = 0;
				}
			}
			
		}

		if (cnt <= K) {
			cout << div[i] << "\n";
			break;
		}

	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int A, B, C, D; cin >> A >> B >> C >> D;
  while(1){
    C-= B;
    if(C<=0){
      cout << "Yes" << endl;
      break;
    }
    A-= D;
    if(A<=0){
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> a(A);
    for(int i = 0;i < A;i++) {
        cin >> a.at(i);
    }
    vector<ll> b(B);
    for(int i = 0;i < B;i++) {
        cin >> b.at(i);
    }
    vector<ll> c(C);
    for(int i = 0;i < C;i++) {
        cin >> c.at(i);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    reverse(c.begin(),c.end());
    int cnta = X - 1;
    int cntb = Y - 1;
    ll ret = 0;
    for(int i = 0;i < X;i++) {
        ret += a.at(i);
    }
    for(int i = 0;i < Y;i++) {
        ret += b.at(i);
    }
    for(int i = 0;i < C;i++) {
        ll aa = -1;
        ll bb = -1;
        if(cnta != -1) {
            aa = c.at(i) - a.at(cnta);
        }
        if(cntb != -1) {
            bb = c.at(i) - b.at(cntb);
        }
        if(aa > 0 || bb > 0) {
            if(aa > bb) {
                ret += aa;
                cnta--;
            }
            else {
                ret += bb;
                cntb--;
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(a,b)+min(c,d)<<endl;
  
  

}
return 0;
}


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

using namespace std;

int a[211111], b[211111];

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    for(int i = 0; i < n; i++) scanf("%d", &b[i]);
    int ans = 0;
    for(int i = 28; i >= 0; i--){
        int v = (1 << (i + 1)) - 1;
        for(int j = 0; j < n; j++){
            a[j] &= v;
            b[j] &= v;
        }
        sort(b, b + n);
        v = (1 << i);
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += lower_bound(b, b + n, 2 * v - a[j]) - lower_bound(b, b + n, v - a[j]);
            sum += lower_bound(b, b + n, 4 * v - a[j]) - lower_bound(b, b + n, 3 * v - a[j]);
        }
        ans += ((sum & 1) << i);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int read() {
	int f = 1, x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -f;
		ch = getchar();
	} while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return f * x;
}
int main() {
	long long t = 100;
	int cnt = 0;
	long long x; cin >> x; 
	while (t < x) {
		++cnt;
		t += t / 100;
	}
	cout << cnt << endl;
	return 0;
}






Measured memory_bytes: 3596
program ABC149B
    implicit none
    integer(16) A,B,K
    read*,A,B,K
    if(A>=K)then
        A=A-K
    else
        B=max(B-(K-A),0_16)
        A=0
    endif
    print"(i0,A,i0)",A," ",B
end program ABC149B

Measured memory_bytes: 768
class Main{public static void main(String[]z){java.util.Scanner s=new java.util.Scanner(System.in);for (int n,p,i,t,a[];(n=s.nextInt())>0;System.out.println(i))for(a=new int[n],t=p=s.nextInt(),i=-1;a[i=(i+1)%n]<p;)a[i]=t-->0?a[i]+1:0&(t=a[i]);}}

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

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

Measured memory_bytes: 256
import math

eight, ten = map(int, input().split())

eight_price = eight / 0.08
ten_price = ten / 0.1

if eight_price >= ten_price:
    bigger = eight_price
    if (bigger // 10) != ten:
        print("-1")
    else:
        print(math.ceil(bigger))
else:
    bigger = ten_price
    if (bigger * 8 // 100) != eight:
        print("-1")
    else:
        print(math.ceil(bigger))

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

int main(){
    int n;
    cin >> n;
    int cnt=0,ans=0;
    for(int i=1; i<=n; i++){
        if(i%2==0)continue;
        cnt=0;
        for(int j=1; j<=i; j++){
            int tmp=i/j;
            if(tmp*j==i)cnt++;
        }
        if(cnt==8)ans++;
    }
    cout << ans << endl;
}

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

#define WA {puts("No");return 0;}
#define MAXN 501

struct Data
{
	int id,v;
	bool operator<(const Data &d)const
	{
		return v<d.v;
	}
}data[MAXN];

int num[MAXN*MAXN],pos=1,n;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&data[i].v);
		num[data[i].v]=i;
		data[i].id=i;
	}
	sort(data+1,data+n+1);
	for(int i=1;i<=n;++i)
	{
		int cnt=1;
		while(cnt<data[i].id)
		{
			while(num[pos]!=0)++pos;
			num[pos]=data[i].id;
			++cnt;
		}
		if(pos>data[i].v)WA
	}
	pos=n*n;
	for(int i=n;i>=1;--i)
	{
		int cnt=0;
		while(cnt<n-data[i].id)
		{
			while(num[pos]!=0)--pos;
			num[pos]=data[i].id;
			++cnt;
		}
		if(pos<data[i].v)WA
	}
	puts("Yes");
	for(int i=1;i<=n*n;++i)printf("%d ",num[i]);
	puts("");
}

Measured memory_bytes: 2176
fun main(args: Array<String>) {
    val n = readInt()

    var ac = 0
    var wa = 0
    var tle = 0
    var re = 0
    repeat(n) {
        val s = readString()
        when(s) {
            "AC" -> ac++
            "WA" -> wa++
            "TLE" ->tle++
            "RE" -> re++
        }
    }
    println("AC x $ac")
    println("WA x $wa")
    println("TLE x $tle")
    println("RE x $re")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 56704
let popcnt x =
  let x = (x land 0x5555555555555555) + ((x lsr 1) land 0x5555555555555555) in
  let x = (x land 0x3333333333333333) + ((x lsr 2) land 0x3333333333333333) in
  let x = (x land 0x0f0f0f0f0f0f0f0f) + ((x lsr 4) land 0x0f0f0f0f0f0f0f0f) in
  let x = (x land 0x00ff00ff00ff00ff) + ((x lsr 8) land 0x00ff00ff00ff00ff) in
  let x = (x land 0x0000ffff0000ffff) + ((x lsr 16) land 0x0000ffff0000ffff) in
  (x land 0x00000000ffffffff) + ((x lsr 32) land 0x00000000ffffffff)


let () = Scanf.scanf "%d\n" @@ fun n ->
  let xyss =
    Array.init n @@ fun _ ->
      Scanf.scanf "%d\n" @@ fun a ->
        Array.to_list @@ Array.init a @@ fun _ ->
          Scanf.scanf "%d %d\n" @@ fun x y -> x, y in
  Printf.printf "%d\n" @@
  Array.fold_left max min_int @@
  Array.init (1 lsl n) @@ fun ans ->
    if
      Array.fold_left ( && ) true @@
      Array.init n @@ fun i ->
        if ans land (1 lsl i) = 0
        then true
        else
          List.for_all (fun (x, y) ->
            ans land (1 lsl (x - 1)) = y lsl (x - 1)) xyss.(i)
    then popcnt ans
    else 0



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

int min_value = 999999;

int main() {
    int ans = 0;
    int n;
    int l;
    std::cin >> n >> l;
    int taste = 0;
    std::vector<int> apples;
    for (int i = 0; i < n; i++) {
        int k = l + (i+1) - 1;
        taste += k;
        apples.push_back(k);
    }
    for (int i = 0; i < n; i++) {
        int w = std::abs(taste-(taste - apples[i]));
        if (min_value > w) {
            min_value = w;
            ans = i;
        }
    }
    
    std::cout << taste - apples[ans] << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll dp[200010];

int main(){
	int n,k; cin >> n >> k;
	vector<Pi> lr(k);
	rep(i,k) cin >> lr[i].first >> lr[i].second;
	sort(lr.begin(),lr.end());
	dp[1] = 1;
	repr(i,1,n){
		dp[i] += dp[i-1];
		dp[i] %= MOD;
		rep(j,k){
			if(i+lr[j].first > n+1) continue;
			dp[i+lr[j].first] += dp[i];
			dp[i+lr[j].first] %= MOD;
			dp[min(n+1,i+lr[j].second+1)] -= dp[i];
			if(dp[min(n+1,i+lr[j].second+1)] < 0) dp[min(n+1,i+lr[j].second+1)] += MOD;
		}
	}
	cout << dp[n] << endl;
}



Measured memory_bytes: 5188
#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>;

int main()
{
    int n;
    cin >> n;
    vector<vector<vector<int>>> a(4);
    rep(i, 4)
    {
        a[i] = vector<vector<int>>(3);
        rep(j, 3)
        {
            a[i][j] = vector<int>(10, 0);
        }
    }
    rep(i, n)
    {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        a[b - 1][f - 1][r - 1] += v;
    }

    rep(i, 4)
    {
        rep(j, 3)
        {
            rep(k, 10)
            {
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }
        if (i < 3)
        {
            cout << "####################" << endl;
        }
    }

    return 0;
}


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


int main()
{
   //ios_base::sync_with_stdio(false);

   int n,a,b;
   cin>>n;
   getchar();
   string s;
   getline(cin,s);
   a=0;
   int f=0;
   if(n%2!=0)
      cout<<"No\n";
   else
   {
       b=(n/2);
       while(b<n)
       {
           if(s[a]!=s[b])
           {
               f=1;
               break;
           }
           a++;
           b++;
       }
       if(f==0)
        cout<<"Yes\n";
       else
        cout<<"No\n";
   }

   return 0;
}


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

int main() {
  string str;
  cin >> str;
  int start = str.length(), end = str.length();
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == 'A' && start == str.length()) {
      start = i;
    }
    if (str[i] == 'Z') {
      end = i;
    }
  }
  cout << (end - start + 1) << endl;
}


Measured memory_bytes: 640
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

ll vs[100000+10];
ll dp[100000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &vs[i]);
    dp[i] = 1e18;
  }
  dp[0] = 0;
  REP(i, n) {
    if(i+1 < n) {
      dp[i+1] = min(dp[i+1], dp[i] + abs(vs[i+1]-vs[i]));
    }
    if(i+2 < n) {
      dp[i+2] = min(dp[i+2], dp[i] + abs(vs[i+2]-vs[i]));
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
char s[200005],t[200005];
ll dp[1005][1005];
bool flag,dame;

int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> s;
		m = strlen(s);
		for(j=0;j<m-1;j++){
			if(s[j] == 'A' && s[j+1] == 'B')ans++;
		}
		if(s[0] == 'B' && s[m-1] == 'A'){
			c++;
		}else if(s[0] == 'B'){
			b++;
		}else if(s[m-1] == 'A'){
			a++;
		}
	}
	if(a == 0 && b == 0){
		if(c == 0){
			ans += 0;
		}else{
			ans += c - 1;
		}
	}else if(a == 0 && b != 0){
		ans += c;
	}else if(a != 0 && b == 0){
		ans += c;
	}else{
		ans += (c + 1);
		a--;
		b--;
		ans += min(a,b);
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 27264
// https://atcoder.jp/contests/abc160/tasks/abc160_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  VL ps(A);
  rep(i, A) cin >> ps[i];
  sort(all(ps), [](ll a, ll b) { return a > b; });

  VL qs(B);
  rep(i, B) cin >> qs[i];
  sort(all(qs), [](ll a, ll b) { return a > b; });

  VL rs(C);
  rep(i, C) cin >> rs[i];
  sort(all(rs), [](ll a, ll b) { return a > b; });

  VL vals(0);

  rep(i, X) vals.push_back(ps[i]);
  rep(i, Y) vals.push_back(qs[i]);
  rep(i, C) vals.push_back(rs[i]);

  sort(all(vals), [](ll a, ll b) { return a > b; });

  ll sum = 0;
  rep(i, X + Y) sum += vals[i];

  cout << sum << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int n;
int arr[100][2];

int main()
{
	cin >> n;
	int maxx = 0;
	int left = 0;
	int right = 0;
	for(int j = 0;j<n;j++) cin >> arr[j][0];
	for(int j = 0;j<n;j++)
	{
		cin >> arr[j][1];
		right += arr[j][1];
	}
	if(n>=2)
	{
		for(int j = 0;j<n;j++)
		{
			left += arr[j][0];
			if(j>=1) right -= arr[j-1][1];
			if(right + left > maxx) maxx = right + left;
		}
	}
	else maxx = arr[0][0] + arr[0][1];
	cout << maxx;
	
	return 0;
}

Measured memory_bytes: 3568
s = input()
cnt = 0
if len(s) % 2 == 0:
    for i in range(int(len(s)/2)):
        if s[i] != s[len(s)-1-i]:
            cnt += 1

else:
    for i in range(int((len(s)-1)/2)):
        if s[i] != s[len(s)-1-i]:
            cnt += 1

print(cnt)


        


    







        



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

int dp[10][10],arr[210][210];

int main()
{
	long long i,j,k,h,w,ans=0;
	cin >> h >> w;
	for(i=0;i<10;i++)
		for(j=0;j<10;j++)
			cin >> dp[i][j];
	for(k=0;k<10;k++)
		for(i=0;i<10;i++)
			for(j=0;j<10;j++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	for(i=0;i<h;i++)
		for(j=0;j<w;j++)
		{
			cin >> arr[i][j];
			if(arr[i][j]!=-1) ans+=dp[arr[i][j]][1];
		}
	cout << ans << "\n";
}

Measured memory_bytes: 384
import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  def del(a:Array[Array[Int]],i:Int,j:Int):Unit  = {
    if(i<0 || j < 0 || i > 11 || j > 11 || a(i)(j) == 0) return
    else {
      a(i)(j) = 0
      del(a,i,j+1);del(a,i,j-1);del(a,i+1,j);del(a,i-1,j)
    }
  }

  Iterator.continually(readLine).takeWhile( _ != null ).foreach { s=>
    val b = new ArrayBuffer[Array[Int]]

    if(s=="") b+= readLine.map(_.asDigit).toArray else b+= s.map(_.asDigit).toArray
    for( i<- 1 to 11)
      b += readLine.map(_.asDigit).toArray

    val a = b.toArray
    for(i <- 0 until 12;j<- 0 until 12)  {
      if(a(i)(j) == 1) {
        del(a,i,j)
        a(i)(j) = 1
      }
    }
    println(a.map{ _.count{_==1} }.sum)
  }
}

Measured memory_bytes: 44372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  int s; cin >> s;
  vector<int> cnt(1000006, 0);
  cnt[s]++;

  int c = s;
  for (int i = 2; i < 1000010; i++) {
    if (c % 2 == 0) c = c / 2;
    else c = 3 * c + 1;
    if (cnt[c] == 1) {
      cout << i << '\n';
      return 0;
    } else {
      cnt[c]++;
    }
  }
  return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair

// random generator
// mt19937 rndm(time(0));

// ll gcd(ll a, ll b)
// {
//     while (b>0)
//     {
//         ll tmp = a;
//         a = b;
//         b = tmp%b;
//     }
//     return a;
// }


// long long gcd(long long a, long long b) {
//  return a? gcd(b % a, a) : b;
// }


const int M=998244353;
ll powmod(ll a,ll b, ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}/* a^b%mod */
const ll N=1e5+10;


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

    int deg[5]={0};
    for(int i=0;i<3;++i) {
    	int a, b;
    	cin>>a>>b;
    	deg[a]++, deg[b]++;
    }
    bool ok=1;
    for(int i=1;i<5;++i) {
    	if(deg[i]>2 || deg[i]==0) {
    		// cout<<i<<endl;
    		ok=0;
    	}
    }
    if(ok)cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}







Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,p,q,a,n,b[1000],f[1000],r[1000],v[1000],o[4][11]={0},t[4][11]={0},s[4][11]={0},y[4][11]={0};
    int tou,kai,room,human;
    scanf("%d",&n);
    for(i=1;i<=n;i+=1){
        scanf("%d %d %d %d",&b[i],&f[i],&r[i],&v[i]);
        tou=b[i];
        kai=f[i];
        room=r[i];
        human=v[i];
        if(tou==1){
            if(kai==1){
                o[1][room]=o[1][room]+human;
                continue;
            }
            else if(kai==2){
                o[2][room]=o[2][room]+human;
                continue;
            }
            else if(kai==3){
                o[3][room]=o[3][room]+human;
                continue;
            }
        }
        else if(tou==2){
            if(kai==1){
                t[1][room]=t[1][room]+human;
                continue;
            }
            else if(kai==2){
                t[2][room]=t[2][room]+human;
                continue;
            }
            else if(kai==3){
                t[3][room]=t[3][room]+human;
                continue;
            } 
        }
        else if(tou==3){
            if(kai==1){
                s[1][room]=s[1][room]+human;
                continue;
            }
            else if(kai==2){
                s[2][room]=s[2][room]+human;
                continue;
            }
            else if(kai==3){
                s[3][room]=s[3][room]+human;
                continue;
            }
        }
        else if(tou==4){
            if(kai==1){
                y[1][room]=y[1][room]+human;
                continue;
            }
            else if(kai==2){
                y[2][room]=y[2][room]+human;
                continue;
            }
            else if(kai==3){
                y[3][room]=y[3][room]+human;
                continue;
            }
        }
    }
    for(a=1;a<=3;a+=1){
        for(p=1;p<=10;p+=1){
            if(p==10){
                printf(" %d\n",o[a][10]);
            }
            else{
                printf(" %d",o[a][p]);
            }
        }
    }
    printf("####################\n");
    for(a=1;a<=3;a+=1){
        for(p=1;p<=10;p+=1){
            if(p==10){
                printf(" %d\n",t[a][10]);
            }
            else{
                printf(" %d",t[a][p]);
            }
        }
    }
    printf("####################\n");
    for(a=1;a<=3;a+=1){
        for(p=1;p<=10;p+=1){
            if(p==10){
                printf(" %d\n",s[a][10]);
            }
            else{
                printf(" %d",s[a][p]);
            }
        }
    }
    printf("####################\n");
    for(a=1;a<=3;a+=1){
        for(p=1;p<=10;p+=1){
            if(p==10){
                printf(" %d\n",y[a][10]);
            }
            else{
                printf(" %d",y[a][p]);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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 vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<60
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17 -I .
//push_back -> emplace_back

string solve(ll n){
   string str="";
   while(n!=0){
      int x=n/(-2);
      int y=n%(-2);
      if(y<0){
         y+=2;
         x++;
      }
      str+=char(y+'0');
      n=x;
   }
   if(str=="")str="0";
   reverse(ALL(str));
   return str;

}
int main(){
   ll n;cin>>n;
   cout<<solve(n)<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[555][555];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int k; cin>>k;
	if(k==1){cout<<1<<'\n'<<1<<'\n'; return 0;}
	int n = (k+3)/4; n*=2; int extra = 2*n-k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			a[i][j]=(i+j)%n;
			if(j%2==0) a[i][j]+=n;
			if(a[i][j]>=2*n-extra) a[i][j]-=n;
		}
	}
	cout<<n<<'\n';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<a[i][j]+1;
			if(j+1<n) cout<<' ';
		}
		cout<<'\n';
	}
}


Measured memory_bytes: 2304
int main(void) {
	int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
//  printf("%d %d %d", a,b,c);
    if(a < b){
    	printf("%d\n", c);  
    }else if(a%b==0){
    	printf("%d\n", (int)(a/b)*c);  
    }else{
        printf("%d\n", ((int)(a/b)+1)*c);
    }
    return 0;
}

Measured memory_bytes: 1704
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC opatimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }


int main() {
//    freopen("in.txt","r", stdin);
//    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n,r;
    cin >> n >> r;
    cout << r + (n >= 10? 0 :  100 * (10 -  n)) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var a = io.Is(n);

        var t2 = a.Count(x => x % 2 == 0 && x % 4 != 0);
        var t4 = a.Count(x => x % 4 == 0);
        var t0 = a.Count(x => x % 2 != 0);
        var m = n - t2;

        var t = m / 2;
        if (m % 2 != 0 && t2 > 0) t++;

        if (t4 >= t) io.Write("Yes");
        else io.Write("No");
    }
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int K;

int main()
{
    cin >> N >> K;
    int cnt = 0;
    rep(i, N)
    {
        int h;
        cin >> h;
        if (h >= K)
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;

typedef long long ll;
const int maxn=1e5+5;

vector<int> E[maxn];
int n,col[maxn];
bool vis[maxn];
void bfs(){
	mem(col,0),mem(vis,0);
	queue<int> q;
	q.push(1);vis[1]=1;col[1]=1;
	q.push(n);vis[n]=1;col[n]=2;
	while(!q.empty()){
		int f=q.front();
		q.pop();
		for(auto i:E[f]){
			if(vis[i]) continue;
			col[i]=col[f];
			vis[i]=1;
			q.push(i);
		}
	}
	int t1=0,t2=0;
	for(int i=1;i<=n;i++){
		if(col[i]==1) t1++;
		else if(col[i]==2) t2++;
	}
	if(t1<=t2) puts("Snuke");
	else puts("Fennec");
}
int main(){
	int u,v;
	while(~scanf("%d",&n)){
		for(int i=1;i<=n;i++) E[i].clear();
		for(int i=1;i<n;i++){
			scanf("%d%d",&u,&v);
			E[u].push_back(v);
			E[v].push_back(u);
		}
		bfs();
	}
	return 0;
}


Measured memory_bytes: 6400
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    static void Main()
    {
        var HWK = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int H = HWK[0];
        int W = HWK[1];
        int K = HWK[2];

        var map = new bool[H, W];
        for (int i = 0; i < H; i++)
        {
            var line = Console.ReadLine();
            for (int j = 0; j < W; j++)
            {
                map[i, j] = line[j] == '#';
            }
        }

        int ans = 0;
        for (int i = 0; i < (1<<H); i++)
        {
            for (int j = 0; j < (1<<W); j++)
            {
                int count = 0;
                for (int a = 0; a < H; a++)
                {
                    for (int b = 0; b < W; b++)
                    {
                        if ((i & (1 << a)) > 0 || (j & (1 << b)) > 0) continue;

                        if (map[a, b]) count++;
                    }
                }
                if (count == K) ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27972
//https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_a
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
// clang-format on
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    cout << (A < C && B > C || A > C && B < C ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self._size = [1 for _ in range(n)]
        self._edges = 0

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self._size[y] += self._size[x]
            self._edges += 1
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self._size[x] += self._size[y]
            self._edges += 1

    def size(self, x):
        x = self.find(x)
        return self._size[x]

    def trees(self):
        return self.n - self._edges

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

n, m = na()
ab = nan(m)
ab.reverse()

uf = UnionFind(n)
cur = n * (n - 1) // 2
ans = [cur]
for i in range(m - 1):
    a, b = ab[i]
    a -= 1
    b -= 1
    p = uf.size(a)
    q = uf.size(b)
    if uf.same(a, b):
        p = 0
    uf.unite(a, b)
    cur -= p * q
    ans.append(cur)

ans.reverse()
print(*ans, sep="\n")

Measured memory_bytes: 36488
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, K = map(int, readline().split())
    ans = K

    for i in range(N - 1):
        ans *= (K - 1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61272
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = br.readLine();
		int n  = Integer.parseInt(line);

		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		long total = 0L;

		String[] numline  = br.readLine().split(" ");

		for (int i = 0; i < numline.length; i++) {
			int input = Integer.parseInt(numline[i]);

			if (min > input) min = input;
			if (max < input) max = input;
			total += input;
		}

		System.out.println(min + " " + max + " " + total);
	}
}

Measured memory_bytes: 28740
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    double size_ = W / 2 * H;
    cout << std::fixed << std::setprecision(15) << size_ << " ";
    if (x * 2 == W && 2 * y == H) {
        cout << "1";
    } else {
        cout << "0";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 3776
h,w = map(int, input().split())
n = int(input())
a = map(int, input().split())

l = []

for i,x in enumerate(a):
	for j in range(x):
		l.append(i+1)

for i in range(h):
	t = l[i*w:(i+1)*w]
	if i % 2 == 1:
		t.reverse()
	print(' '.join(map(str, t)))

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll a[n+3];
    cin>>a[0]>>a[1];
    ll kq[n+99];
    kq[1]=abs(a[0]-a[1]);
    kq[0]=0;
    F(i,2,n-1)
    {
        cin>>a[i];
        kq[i]=min(abs(a[i]-a[i-1])+kq[i-1],abs(a[i]-a[i-2])+kq[i-2]);
    }
    cout<<kq[n-1];
}



Measured memory_bytes: 1792
#include <stdio.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
typedef long long lint;
const int mod=1000000007;
int k,n=-1,cnt=13;
char c[15];
lint fact[2000010],inv[2000010];
int main(){
	while(1){
		*c=getchar_unlocked();
		if(*c=='\n')break;
		k*=10;
		k+=*c-'0';
	}
	while(getchar_unlocked()!=-1)n++;
	fact[0]=1;
	for(int i=1;i<=n+k;i++)fact[i]=fact[i-1]*i%mod;
	inv[n+k]=1;
	lint now=fact[n+k];
	int b=mod-2;
	while(b){
		if(b&1){
			inv[n+k]*=now;
			inv[n+k]%=mod;
		}
		b>>=1;
		now*=now;
		now%=mod;
	}
	for(int i=n+k-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	lint ans=1;now=1;
	for(int i=1;i<=k;i++){
		now*=25;
		now%=mod;
		ans+=fact[n+k]*inv[n+k-i]%mod*inv[i]%mod*now;
		ans%=mod;
	}
	*(c+14)='\n';
	while(ans){
		*(c+cnt)=ans%10+'0';
		ans/=10;
		cnt--;
	}
	fwrite(c+cnt+1,1,14-cnt,stdout);
	return 0;
}

Measured memory_bytes: 32724
read n
a=(`dd`)
s=0
for b in ${a[@]};do
 s=$[s+b]
done
t=0
u=0
for b in ${a[@]};do
 u=$[u+b]
 t=$[(s-t-t)*(s-t-t)>(s-u-u)*(s-u-u)?u:t]
done
t=$[t*2]
echo $[s>t?s-t:t-s]

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

/* {{{ */
#define PI(N) M_PI * N / 180 //?§???????????????¢??????????????????
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */

int main()
{
    int n, sco[2] = {0};

    cin >> n;

    REP(i, n){
        string s1, s2;
        cin >> s1 >> s2;

        if (s1 > s2){
            sco[0] += 3;
        }
        else if (s1 < s2){
            sco[1] += 3;
        }
        else if (s1 == s2){
            sco[0]++;
            sco[1]++;
        }
    }

    cout << sco[0] << " " << sco[1] << endl;

    return (0);
}

Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,x,y;
    cin >> n >> x >> y;
    graph g(n);
    rep(i,n-1){
        g[i].emplace_back(i+1);
        g[i+1].emplace_back(i);
    }
    x--;
    y--;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
    vector<vector<int>> c(n,vector<int>(n,INF));
    rep(i,n){
        queue<int> que;
        que.push(i);
        c[i][i] = 0;
        while(!que.empty()){
            auto t = que.front();
            que.pop();
            for(auto nt: g[t]){
                if(c[i][nt]>c[i][t]+1){
                    que.push(nt);
                    c[i][nt] = c[i][t] +1;
                }
            }
        }
    }
    vector<int> ans(n,0);
    rep(i,n){
        rep(j,n){
            if(c[i][j]==0) continue;
            else{
                ans[c[i][j]]++;
            }
        }
    }
    rep(i,n-1){
        cout << ans[i+1]/2 << endl;
    }
}

Measured memory_bytes: 16128
N=int(input())
wordList={}
tmpWord=""
for i in range(N):
    tmpWord=input()
    if tmpWord in wordList:
        wordList[tmpWord]+=1
    else:
        wordList[tmpWord]=1
M=int(input())
for i in range(M):
    tmpWord=input()
    if tmpWord in wordList:
        wordList[tmpWord]-=1
if max(wordList.values())<=0:
    print("0")
else:
    print(max(wordList.values()))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int a[26];
char ct[110];

int main(){
	while(1){
		cin>>n;
		for(int i=0;i<26;i++){
			a[i]=0;
		}
		
		for(int i=0;i<n;i++)
			cin>>ct[i];
		if(n==0)break;
		int ma1=0,ma2=0;
		char cma1='a',cmb2='a';
		for(int i=0;i<n;i++){
			char t;
			t=ct[i];
			a[t-'A']++;
			if(cma1==t){
				ma1=a[t-'A'];
			}else if(cmb2==t){
				if(a[t-'A']>ma1){
					ma2=ma1;
					ma1=a[t-'A'];
					swap(cma1,cmb2);
				}else{
					ma2=a[t-'A'];
				}
			}else if(a[t-'A']>ma1){
				ma2=ma1;
				cmb2=cma1;
				ma1=a[t-'A'];
				cma1=t;
			}else if(a[t-'A']>ma2){
				ma2=a[t-'A'];
				cmb2=t;
			}
			if(ma1>ma2+(n-i-1)){
				cout<<cma1<<" "<<i+1<<endl;
				break;
			}
			if(i==n-1){
				cout<<"TIE"<<endl;
			}
			//cout<<ma1<<" "<<ma2<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3120
ary = []
3.times do |i|
    ary[i] = gets.split.map(&:to_i)
end
a1 = 0
b1 = ary[0][0] - a1
b2 = ary[0][1] - a1
b3 = ary[0][2] - a1
a2 = ary[1][0] - b1
a3 = ary[2][0] - b1
if (a1 + b1 == ary[0][0] &&
    a1 + b2 == ary[0][1] &&
    a1 + b3 == ary[0][2] &&
    a2 + b1 == ary[1][0] &&
    a2 + b2 == ary[1][1] &&
    a2 + b3 == ary[1][2] &&
    a3 + b1 == ary[2][0] &&
    a3 + b2 == ary[2][1] &&
    a3 + b3 == ary[2][2])
    puts 'Yes'
else
    puts 'No'
end

Measured memory_bytes: 1788
#全パターン試す

input = Array.new(5){gets.to_i}

ans = []

def calc(time)
  tmp = time%10
  return tmp == 0 ? time : (time + 10 - tmp)
end

input.permutation(5) do |a, b, c, d, e|
  time = 0

  time += a
  time = calc(time)
  time += b
  time = calc(time)
  time += c
  time = calc(time)
  time += d
  time = calc(time)
  time += e

  ans.push(time)
end

p ans.min

Measured memory_bytes: 1788