akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

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

    vector <pair <int, int>> gusu(100000), kisu(100000);
    rep (i, 100000) gusu[i] = kisu[i] = make_pair(0, i + 1);

    rep (i, n) {
        int v;
        cin >> v;
        (i % 2 ? gusu[v - 1] : kisu[v - 1]).first += 1;
    }

    sort(gusu.rbegin(), gusu.rend());
    sort(kisu.rbegin(), kisu.rend());

    int ans = 1000000000;
    //cout << kisu.begin()->first << ", " << kisu.begin()->second << endl;
    //cout << gusu.begin()->first << ", " << gusu.begin()->second << endl;
    //cout << endl;
    for (auto pii : gusu) {
        //cout << pii.first << ", " << pii.second << endl;
        auto macs = kisu.begin();
        //cout << macs->first << ", " << macs->second << endl;
        while (pii.second == macs->second) macs += 1;
        //cout << macs->first << ", " << macs->second << endl;
        //cout << n - pii.first - macs->first << endl;
        //cout << endl;
        ans = min(ans, n - pii.first - macs->first);
    }
    //cout << ans << endl;
    for (auto pii : kisu) {
        auto macs = gusu.begin();
        while (pii.second == macs->second) macs += 1;
        ans = min(ans, n - pii.first - macs->first);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

#define int ll


const int N = 5e3 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string n;
int k, ans, dp[N][2][5];
int solve(int x, bool flag, int now) {
    if (now > k) return 0;
    int &res = dp[x][flag][now];
    if (~res) return res;
    if (x == n.size() + 1) return res = (now == k);
    res = 0;
    if (flag) {
        for (int i = 0; i < 10; ++i) res += solve(x + 1, 1, now + (i > 0));
    } else {
        for (int i = 0; i < 10; ++i) {
            int cur = n[x - 1] - '0';
            if (i < cur) {
                res += solve(x + 1, 1, now + (i > 0));
            } else {
                if (i == cur) res += solve(x + 1, 0, now + (i > 0));
                break;
            }
        }
    }
    return res;
}
main() {
    file("threesum");
    ios;
    cin >> n >> k;
    memset(dp, -1, sizeof dp);
    cout << solve(1, 0, 0);
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


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

int main() {
  string N;
  cin >> N;
  int count=0,maxc=0;
  for(int i=0;i<N.size();i++){
    if(N.at(i)=='R')count++;
    else count=0;
      maxc=max(maxc,count);
  }
  cout << maxc << endl;
  
}

Measured memory_bytes: 3624
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,q = get_nums_l()

lines = sys.stdin.readlines()
edges = list(map(lambda s:list(map(int, s.split(" "))), lines[:n-1]))
queries = list(map(lambda s:list(map(int, s.split(" "))), lines[n-1:]))

scores = [0] * (n+1)

for q in queries:
    scores[q[0]] += q[1]

queue = deque()
mark = [False] * (n+1)
mark[1] = True


childrens = [ [] for _ in range(n+1) ]
for e in edges:
    a = e[0]
    b = e[1]
    childrens[a].append(b)
    childrens[b].append(a)


queue.append(1)

while queue:
    a = queue.popleft()
    children = childrens[a]
    for b in children:
        if not mark[b]:
            scores[b] += scores[a]
            mark[b] = True
            queue.append(b)

print(" ".join(map(str,scores[1:])))


Measured memory_bytes: 172688
import sys
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M, K = map(int, rl().split())
    A = list(map(int, rl().split()))
    B = list(map(int, rl().split()))
    
    accA = [0] + list(accumulate(A))
    accB = list(accumulate(B))
    ans = 0
    for i, v in enumerate(accA):
        if K < v:
            break
        ans = max(ans, i + bisect_right(accB, K - v))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 125476
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
  double x1, y1, x2, y2;
  double dis;

  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

  dis = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));

  printf("%.8lf\n", dis);
  
  return 0;
}

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

int N;
double f[3000], p, ans;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	f[0] = 1.0;
	for(int i = 1; i <= N; ++i) {
		cin >> p;
		for(int j = i; j >= 1; --j)
			f[j] += f[j - 1] * p, f[j - 1] *= (1.0 - p);
	}
	for(int i = N / 2 + 1; i <= N; ++i)
		ans += f[i];
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 100000


int main(){
  int i,j=0,k,found=0,kosuu,A[N],a;
  scanf("%d",&kosuu);
  for(i=0;i<kosuu;i++)
    {
      scanf("%d",&A[i]);
    }
  
  for(i=0;i<kosuu;i++)
    {
      if(A[i]==4 || A[i]==6 || A[i]==8 || A[i]==1)j++;
      k=3;
      while(k<=sqrt(A[i]))
	{
	  if(A[i]%2==0){j++; break;}
	  else if(A[i]%k == 0) {j++; break;}
	  else k+=2;
	}
    }
	  
      
    


printf("%d\n",kosuu-j);
return 0;
}
  
  



Measured memory_bytes: 2148
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#include<climits>
#include<sstream>
using namespace std;
#define maxn 10010
struct Node{
    int x,y,val,pre;
};
Node g[100010];
int gh[maxn],du[maxn];
int n,m;
stack<int> s;

int main(){
    int i,j;
    cin>>n>>m;
    memset(gh,-1,sizeof gh);
    memset(du,0,sizeof du);
    for(i=0;i<m;i++){
        cin>>g[i].x>>g[i].y;
        g[i].pre=gh[g[i].x];
        gh[g[i].x]=i;

        du[g[i].y]++;
    }
    for(i=0;i<n;i++)
        if(du[i]==0)
            s.push(i);
    while(!s.empty()){
        int t=s.top();
        s.pop();
        cout<<t<<endl;
        j=gh[t];
        while(j!=-1){
            int yy=g[j].y;
            du[yy]--;
            if(!du[yy]) s.push(yy);
            j=g[j].pre;
        }
    }
    return 0;
}



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

int main(int argc, char *argv[])
{
  int n, q, i, j;
  int *S, *T;
  int found;
  int st, ed, center;

  scanf("%d", &n);
  S = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) scanf("%d", &S[i]);

  scanf("%d", &q);
  T = (int *)malloc(sizeof(int) * q);
  for (i = 0; i < q; i++) scanf("%d", &T[i]);

  found = 0;
  for (i = 0; i < q; i++) {
    st = 0;
    ed = n - 1;
    while (1) {
      center = st + (ed-st)/2;
      if (ed - st < 20) break;
      if (S[center] > T[i]) ed = center;
      else if (S[center] < T[i]) st = center;
      else break;
    }
    for (j = st; j <= ed; j++) {
      if (S[j] == T[i]) {
	found++;
	break;
      }
    }
  }

  printf("%d\n", found);

  free(S);
  free(T);

  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    vector<ll> sa(n+1),sb(m+1);
    rep(i,n) sa[i+1]=sa[i]+a[i];
    rep(i,m) sb[i+1]=sb[i]+b[i];

    ll ans = 0;
    rep(i,n+1){
        if(sa[i]>k) continue;
        ll ok = 0, ng = m+1;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(sa[i]+sb[mid]<=k) ok = mid;
            else ng = mid;
        }
        chmax(ans,i+ok);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9496
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}


long long power(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = 0;
	vector<int> C;
	
	cin>>N;
	
	C.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>C[i];
	}
	
	sort(C.begin(), C.end(), greater<int>());
	
	for(int i = 0, j = N * 2; i < N; i++){
		ans += C[i] % MOD * (i + 2) % MOD;
		ans %= MOD;
	}
	
	ans *= power(2, N-1);
	
	ans %= MOD;
	
	ans *= power(2, N-1);
	
	ans %= MOD;
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;

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

  int N; cin >> N;
  vector<long long> plus, minus;
  rep(i, N) {
    ll a; cin >> a;
    if (a >= 0) plus.push_back(a);
    else minus.push_back(a);
  }

  sort(plus.begin(), plus.end(), greater<long long>());
  sort(minus.begin(), minus.end());
  if (minus.empty()) minus.push_back(plus.back()), plus.pop_back();
  if (plus.empty()) plus.push_back(minus.back()), minus.pop_back();

  vector<pair<long long, long long> > res;
  long long cur = minus[0];
  for (int i = 0; i+1 < plus.size(); ++i) {
      res.push_back({cur, plus[i]});
      cur -= plus[i];
  }
  res.push_back({plus.back(), cur});
  cur = plus.back() - cur;

  for (int i = 1; i < minus.size(); ++i) {
      res.push_back({cur, minus[i]});
      cur -= minus[i];
  }

  cout << cur << endl;
  for (auto p : res) cout << p.first << " " << p.second << endl;
}


Measured memory_bytes: 5104
#include<stdio.h> 
int main(void) 
{ 
int a, b;
    scanf("%d %d", &a, &b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

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

int main(void) {
	vector<char> str;
	int num1, num2;
	char ope;
	int ans, flag = 0;
	while(1) {
		cin >> num1 >> ope >> num2;
		switch(ope) {
		case '+':
			cout << num1 + num2 << endl;
			break;
		case '-':
			cout << num1 - num2 << endl;
			break;
		case '*':
			cout << num1 * num2 << endl;
			break;
		case '/':
			cout << num1 / num2 << endl;
			break;
		case '?':
			flag = 1;
			break;
		}
		if(flag == 1) {
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

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

    sort(a, a+n);

    bool dp[k+1];
    fill(dp, dp+k+1, false);
    for (int i = a[0]; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (i - a[j] >= 0 && !dp[i - a[j]]) {
                dp[i] = true;
            }
        }
    }

    if (dp[k]) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }

    return 0;
}

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

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000 // array max range

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    int n;
    cin >> n;
    int d[n][2];
    R(i,n) cin >> d[i][0] >> d[i][1]; 
    int cnt = 0;
    R(i,n){
        if(d[i][0] == d[i][1]){
            cnt++;
        }else{
            cnt=0;
        }
        if(cnt == 3){
            break;
        }
    }
    if(cnt == 3){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_V=1000010;
unsigned int dp[MAX_V];
unsigned int dpodd[MAX_V];
set<int> tetras{-1};
set<int> oddtetras{-1};
int main(){ _;
  int n;
  REP(i,MAX_V)dp[i]=dpodd[i]=-1;
  dp[0]=dpodd[0]=0;
  for(int i=1;;i++){
    int k=i*(i+1)*(i+2)/6;
    tetras.insert(k);
    if((k>>1)<<1!=k)//odd
      oddtetras.insert(k);
    if(k>MAX_V)break;
  }
  for(int i=1;i<MAX_V;i++){
    auto tetra=tetras.upper_bound(i);
    auto oddtetra=oddtetras.upper_bound(i);
    for(int j=0;j<200;j++){
      int k=*(--tetra);
      if(k<0)break;
      dp[i]=min(dp[i],dp[i-k]+1);
    }
    for(int j=0;j<200;j++){
      int k=*(--oddtetra);
      if(k<0)break;
      dpodd[i]=min(dpodd[i],dpodd[i-k]+1);
    }
  }
  while(cin>>n,n!=0){
    cout<<dp[n]<<" "<<dpodd[n]<<endl;
  }
}

Measured memory_bytes: 9016
#include<stdio.h>
int main(void)
{
    int n,i,j,h,w[10],l[10],t,u[10];
    char q[11],g;
    while(1){
        for(i=0;i<10;i++){
            w[i]=0; l[i]=0;
        }   
        scanf("%d",&n);
        if(n==0) break;
            for(i=0;i<n;i++){
				u[i]=i;
                scanf(" %c",&q[i]);
                for(j=0;j<n-1;j++){
                    scanf("%d",&h);
                    if(h==0) w[i]++;
                    if(h==1) l[i]++;
                }
            }
            for(i=0;i<n-1;i++){
                for(j=i+1;j<n;j++){
                    if(w[i]<w[j]||(w[i]==w[j]&&l[i]>l[j])||(w[i]==w[j]&&l[i]==l[j]&&u[i]>u[j])){
                        t=w[i];
                        w[i]=w[j];
                        w[j]=t;
                         
                        t=l[i];
                        l[i]=l[j];
                        l[j]=t;
                         
                        t=u[i];
                        u[i]=u[j];
                        u[j]=t;
                     
                        g=q[i];
                        q[i]=q[j];
                        q[j]=g;
                    }               
                }   
            }       
            for(i=0;i<n;i++) printf("%c\n",q[i]);
    }
    return 0;
}

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

int main()
{
  int N, X, Y, tmp;
  vector<int> a(2000, 0);

  cin >> N >> X >> Y;
  for (int i = 1; i < N; i++)
  {
    for (int j = i + 1; j <= N; j++)
    {
      if (i <= X && X < j)
      {
        if (Y <= j)
          a[X - i + 1 + j - Y]++;
        else
        {
          tmp = min(j - i, X - i + 1 + Y - j);
          a[tmp]++;
        }
      }
      else if (X < i && i < Y - 1)
      {
        if (Y <= j)
        {
          tmp = min(j - i, i - X + 1 + j - Y);
          a[tmp]++;
        }
        else
        {
          tmp = min(j - i, i - X + 1 + Y - j);
          a[tmp]++;
        }
      }
      else
        a[j - i]++;
    }
  }
  for (int i = 1; i < N; i++)
  {
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var hen = Console.ReadLine().Split(' ');
            var a = int.Parse(hen[0]) * int.Parse(hen[1]);
            var b = int.Parse(hen[2]) * int.Parse(hen[3]);
            if(a>b) Console.WriteLine(a);
            else Console.WriteLine(b);
        }        
    }
}

Measured memory_bytes: 11092
N, L = input().split()
N = int(N)
L = int(L)
sum = 0
if(L >= 0):
  for i in range(L + 1 ,L + N):
    sum += i
else :
  if(L + N > 0):
    for i in range(L,L + N):
      sum += i
  else :
    for i in range(L ,L + N - 1):
      sum += i
      
print(sum)



Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
map<int,int>M;
int n,A[1<<18],ans;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>A[i];
		M[A[i]]++;
	}
	sort(A,A+n,greater<int>());
	for(int i=0;i<n;i++)
	{
		if(M[A[i]]==0)continue;
		M[A[i]]--;
		int now=-A[i];
		for(int j=32;j--;)
		{
			if(!(now&1LL<<j))continue;
			now-=1LL<<j;
			if(__builtin_popcount(now+A[i])==1&&M[now]>0)
			{
				M[now]--;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 39168
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func calc(a, b, c int) int {
	l := 0
	r := a
	for l+1 < r {
		// out(l, r)
		m := (l + r) / 2
		red := m
		blue := (a - m)
		// out("diff", red, blue)
		if red > blue {
			r = m
		} else {
			l = m
		}
	}
	diff := b * c * (l - a + l)
	// out(l, r, red-blue)
	return (abs(diff))
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c := getInt(), getInt(), getInt()

	ans := calc(a, b, c)
	ans = min(ans, calc(b, a, c))
	ans = min(ans, calc(c, a, b))
	out(ans)
}


Measured memory_bytes: 1772
#include<iomanip>
#include <iostream>
using namespace std;
     
int main()
{
    int a,b=0;
    cin>>a>>b;
    cout<<a/b<<" "<<a%b<<" ";
    double da,db=0;
    da=(double)a;
    db=(double)b;
    cout<<fixed<<setprecision(5);
    cout<<da/db<<endl;
    return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
pair<lld,pl> ee(lld a, lld b) {
    if (b == 0)
    	return mk(a,mk(1,0));
    lld g, x, y;
    pair<lld,pl> now = ee(b, a%b);
    return mk(now.x,mk(now.y.y, now.y.x-(a/b)*now.y.y));
}
lld calc(lld x,lld y,lld v){
	if(y%x==0) return 1e16;
	if(x%y==0) return 1e16;
	if(__gcd(x,y)!=1) return 1e16;
	lld nny = y;
	y %= x;
	pair<lld,pl> now = ee(y,x);
	lld nn = now.y.x;
	if(nn>0) return nn%x;
	return nn%x + x;
}
int main(void){
	lld n;
	cin >> n;
	n *= 2;
	if(n==2) return !printf("1");
	lld lim = sqrt(n),ans = 1e18;
	ans = n;
	for(lld e=1;e<=lim;e++){
		if(n%e==0){
			lld f1 = e;
			lld f2 = n/e;
			lld nn1 = calc(f1,f2,1);
			if(nn1*f2-1&&nn1!=1e16) ans = min(ans,nn1*f2-1);
			lld nn2 = calc(f2,f1,1);
			if(nn2!=1e16) ans = min(ans,nn2*f1-1);
		}
	}
	cout << ans;
	return 0;
}


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

const int mxN = 1e5 + 5;
long long a[mxN], dp[mxN];
int main() {
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	for(int i = 2; i <= n; ++i) {
		dp[i] = 2e9 + 5;
		for(int j = 1; j <= k; ++j) {
			if(i - j < 1)
				continue;
			dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j]);
		}
	}
	cout << dp[n];
}


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

using namespace std;

int main()
{
    int x, n, t;
    cin >> x >> n;
    vector<int> ps(100);

    for (int i = 0; i <= 100; ++i)
        ps[i] = i;

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

    int ans = 101;

    for (int i = 0; i <= 100; ++i)
    {
        if (abs(ps[i] - x) < abs(ans - x))
        {
            ans = ps[i];
        }
        else if (abs(ps[i] - x) == abs(ans - x))
        {
            if (ps[i] < ans)
                ans = ps[i];
        }
    }

    cout << ans << endl;

    return 0;
}

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

int M[501][501];

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

  int H,W;
  cin >> H >> W;

  vector<pair<pi, pi>> q;

  rep(h, H) {
    rep(w, W) {
      cin >> M[h][w];
    }
  }

  rep(h, H) {
    rep(w, W-1) {
      if(M[h][w] % 2 == 1) {
        q.push_back(make_pair(make_pair(h,w), make_pair(h,w+1)));
        M[h][w]--;
        M[h][w+1]++;
      }
    }
  }

  rep(h, H-1) {
    if(M[h][W-1] % 2 == 1) {
      q.push_back(make_pair(make_pair(h,W-1), make_pair(h+1,W-1)));
      M[h][W-1]--;
      M[h+1][W-1]++;
    }
  }

  cout << q.size() << endl;

  rep(i, q.size()) {
    cout << q[i].first.first + 1 << " " << q[i].first.second + 1 << " " << q[i].second.first + 1 << " " << q[i].second.second + 1 << endl;
  }
}


Measured memory_bytes: 5232
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    int B[100010];
    rep(i, N) cin >> A[i];
    int sum = 0;
    rep(i, N) sum += A[i];
    int num = 0;
    rep(i, N) num += i + 1;
    if(sum % num != 0) {
        cout << "NO" << endl;
        return 0;
    }
    rep(i, N) B[i] = A[(i + 1) % N] - A[i] - (sum / num);
    // rep(i, N) cout << B[i] << " ";
    // cout << endl;
    rep(i, N) {
        if(-B[i] % N != 0 || B[i] > 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}
// 1 -4 1 1 1

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

using namespace std;

int main() {
	char s[10],c[3]={'o','x','d'};
	int i,j,f;
	while(gets(s)!=NULL) {
		f=2;
		for (i=0;i<2;i++) {
			for (j=0;j<3;j++) {
				if ((s[j*3]==c[i] && s[j*3+1]==c[i] && s[j*3+2]==c[i]) || (s[j]==c[i] && s[j+3]==c[i] && s[j+6]==c[i]))  f=i;
               }
			if ((s[0]==c[i] && s[4]==c[i] && s[8]==c[i]) || (s[2]==c[i] && s[4]==c[i] && s[6]==c[i])) f=i;
		}
		cout << c[f] << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
typedef unordered_map<ll, ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ts ll t; in(t) while (t--) solve();
#define ks ll t; in(t) FOR(i, 1, t+1) out("Case #" << i << ": " << solve());
#define endl '\n'
#define ln cout << endl;
#define in(x) cin >> x;
#define out(x) cout << x << endl;
#define flush cout << flush;
#define reset(a, b) memset(a, b, sizeof(a));
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FORI(i, a, b, c) for (ll i = a; i < b; i += c)
#define FORD(i, a, b) for (ll i = a; i > b; --i)
#define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++)
#define FORALL(it, v) for (auto it : v)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vin(v, x) vll v(x); FOR(i, 0, x) in(v[i])
#define all(v) v.begin(), v.end()
#define allr(v, r) v.begin(), v.begin() + r
#define showv(v) FORALL(it, v) cout << it << ' '; ln
#define printv(v) FORALL(it, v) out(it)
#define show2d(v) FORALL(it, v) { FORALL(j, it) cout << j << ' '; ln}
#define showm(v) FORALL(it, v) cout << it.F << ": " << it.S << ' '; ln
#define sortv(v) sort(all(v));
#define revv(v) reverse(all(v));
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define gcd __gcd
#define checkbit(n, i) (n >> i) & 1               // check ith bit
#define bitcount __builtin_popcount               // count set bits
#define firstbitindex __builtin_ctz               // count trailing zeros
#define lastbitindex __builtin_clz                // count leading zeros
#define bitparity __builtin_parity                // check set bits are even or odd
#define findv(v, x) (find(all(v), x) != v.end())
#define findsm(u, x) (u.find(x) != u.end())
#define findstr(s, x) (s.find(x) != string::npos)
#define sz(a) a.size()
#define precise(x) cout << fixed << setprecision(x);

const ll MAXN = 2e5, MOD = 998244353, SIZE = 2e7, INF = 0x7f7f7f7f7f7f7f7f;
const double EPS = 1e-9, PI = acos(-1);
const int INFi = 0x7f7f7f7f;

//<<------Declare Variables Here----->>//
ll n;
char a[] = "abcdefghijklmnopqrstuvwxyz";
string s;

//<<-----Implement Functions Here---->>//
void solve()
{
    in(n)
    while(n) --n, s = a[n % 26] + s, n /= 26;
	out(s)
}

//<<----------Start of Main---------->>//
int main()
{
    fastio
    //ts
    solve();
    return 0;
}

Measured memory_bytes: 3680
#include<cmath>
#include<iostream>

int main(int, char**)
{
	double a, b, c, d, e, f = 0;
	while (std::cin >> a >> b >> c >> d >> e >> f)
	{
		double y = std::roundl((c * d - a * f) / (b * d - a * e) * 1000.0) / 1000.0;
		double x = std::roundl((c * e - b * f) / (a * e - b * d) * 1000.0) / 1000.0;
		printf("%.3f %.3f\n", x + 0, y + 0);
	}
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

using mint = modint998244353;

struct S {
  mint x, power;
  S(mint x=0, mint power=1):x(x),power(power) {}
};
S op(S l, S r) { return S{l.x * r.power + r.x, l.power * r.power}; }
S e() { return S{0, 1}; }

struct F { int d; };
S mapping(F f, S s) {
  if(f.d == 0) return s;
  return S{(s.power-1)/9 * f.d, s.power};
}
F composition(F f, F g) {
  if( f.d == 0) return g;
  else return f;
}
F id() { return F{0}; }

int main() {
  int n,q; cin >> n >> q;
  lazy_segtree<S, op, e, F, mapping, composition, id> t(n);
  rep(i,n) t.set(i, S(1,10));
  rep(i,q) {
    int l, r, d;
    cin >> l >> r >> d; --l;
    t.apply(l, r, F{d});
    S ans = t.prod(0,n);
    cout << ans.x.val() << endl;
  }
}


Measured memory_bytes: 9840
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int ar[n+1]={0};
	int arr[n+1]={0};
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	arr[2]=abs(ar[1]-ar[2]);
	for(int i=3;i<=n;i++){
		/*cout<<(abs(ar[i]-ar[i-1])+arr[i-1])<<" ";
		cout<<(abs(ar[i]-ar[i-2])+arr[i-2])<<endl;*/
		arr[i]=min((abs(ar[i]-ar[i-1])+arr[i-1]),(abs(ar[i]-ar[i-2])+arr[i-2]));
	}
	cout<<arr[n]<<endl;
}

Measured memory_bytes: 1024
#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 floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[200000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
int main()
{
	ll n,m,x;
	cin>>n>>m>>x;
	vec c(n);
	vector<pair<ll,vec> > a(n);
	floop(i,0,n)
	{
		cin>>a[i].fi;
		floop(j,0,m)
		{
			ll ran;
			cin>>ran;
			a[i].se.pb(ran);
		}
	}
//	ll req[m+1]={};
	sort(all(a));
	ll ans=1e18;
	//set<ll> done;
	floop(i,0,p(2,n))
	{
		ll req[m+1]={};
		floop(wow,0,m)
		req[wow]=x;
		set<ll> done;
		ll temp=0;
		floop(j,0,n)
		{
			if((i&(1<<j)))
			{
				temp+=a[j].fi;
				//floop(k,0,m)
				//ans+=a[i].fi;
				floop(k,0,m)
				{req[k]-=a[j].se[k]; if(req[k]<=0) done.insert(k);}
				if(sz(done)==m)
				break;
			}
		}
		if(sz(done)==m)
		ans=min(ans,temp);
	}
	if(ans==1e18)
	ans=-1;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>

int main()
{
    while (true) {
        int m, d;
        std::cin >> m >> d;
        if (m == 0) break;

        const char *weekdays[] = {
            "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"
        };
        const int total_days[] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
        std::cout << weekdays[(total_days[m - 1] + d - 1) % 7] << std::endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define mod 1000000007;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
using namespace std;
int main()
{
    fast_io;
  li n,i;
  cin>>n;
  li a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  double sum=a[0];
  for(i=1;i<n;i++)
  sum=((sum+a[i])/2);
  cout<<sum;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int d, t, s; cin >> d >> t >> s;
	if (d > t * s) cout << "No" << endl;
	else cout << "Yes" << endl;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a == 1) {
		a = 14;
	}
	if (b == 1) {
		b = 14;
	}
	if (a > b) {
		cout << "Alice" << endl;
	}
	else if (a < b) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Draw" << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = (int) 2e5 + 123;
const int A = 'z' - 'a' + 1;

int n;
string s;
int nxt[N][A];
int dp[N];

void run() {
    cin >> s;
    n = sz(s);
    rep(i, 0, A) {
        nxt[n][i] = n;
        dp[n] = 1;
    }
    per(i, n - 1, 0) {
        copy(nxt[i + 1], nxt[i + 1] + A, nxt[i]);
        nxt[i][s[i] - 'a'] = i;
        dp[i] = INF;
        rep(j, 0, A) {
            mini(dp[i], dp[nxt[i][j] + 1] + 1);
        }
    }
    string ans;
    int i = 0;
    while (i < n) {
        rep(j, 0, A) {
            if (dp[nxt[i][j] + 1] + 1 == dp[i]) {
                i = nxt[i][j] + 1;
                ans += (char) (j + 'a');
                break;
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 21652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3005;
int n,P,ans,f[N],C[N][N],S[N][N];
ll pw(ll a,ll b,ll m){ll r=1;for(;b;b>>=1,a=a*a%m)if(b&1)r=r*a%m;return r;}
int main()
{
	scanf("%d%d",&n,&P);S[1][1]=1;
	for(int i=2;i<N;i++)for(int j=1;j<=i;j++)S[i][j]=(S[i-1][j-1]+1ll*j*S[i-1][j])%P;
	for(int i=C[0][0]=1;i<=n;i++)for(int j=C[i][0]=1;j<=i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
	for(int i=0;i<=n;i++)
	{
		ll b=pw(2,n-i,P),c=1,s=0;
		for(int j=0;j<=i;j++,c=1ll*c*b%P)s=(s+1ll*S[i+1][j+1]*c)%P;
		s=1ll*s*C[n][i]%P*pw(2,pw(2,n-i,P-1),P)%P;
		if(i&1)ans=(ans+P-s)%P;else ans=(ans+s)%P;
	}
	printf("%d\n",ans);
	return 0;
}


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

ll go(ll n,vector<ll> &h,ll k,vector<ll> &dp,ll pos=0)
{
  	if(pos>=n)
      return INT_MAX;
  	if(pos==n-1)
      return 0;
     if(dp[pos]!=-1)
     return dp[pos];
	ll res=INT_MAX;
	for(int i=1;i<=k and pos+i<n;i++)
	{
		res=min(res,abs(h[pos+i]-h[pos])+go(n,h,k,dp,pos+i));
	}
	return dp[pos]=res;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;
  cin>>n>>k;
  vector<ll> h(n);
  for(auto &i:h)
    cin>>i;
  vector<ll> dp(n+1,-1);
  cout<<go(n,h,k,dp)<<endl;
  return 0;
  
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>> A(M);
  vector<int> B(100001,0);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[a%M].push_back(a);
    B[a]++;
  }
  int ans=A[0].size()/2;
  for(int i=1;i<(M+1)/2;i++){
    if(A[i].size()>A[M-i].size()){
      ans+=A[M-i].size();
      int cnt=0;
      for(int j=i;j<=100001;j+=M)
        cnt+=B[j]/2;
      ans+=min((int)(A[i].size()-A[M-i].size())/2,cnt);
    }else if(A[i].size()<A[M-i].size()){
      ans+=A[i].size();
      int cnt=0;
      for(int j=M-i;j<=100001;j+=M)
        cnt+=B[j]/2;
      ans+=min((int)(A[M-i].size()-A[i].size())/2,cnt);
    }else if(A[i].size()==A[M-i].size()){
      ans+=A[i].size();
    }
  }
  if(M%2==0)
    ans+=A[M/2].size()/2;
  cout<<ans<<endl;
}

Measured memory_bytes: 9608
s = input()

if (s[0] != 'A'):
   print('WA')
   exit()

t = s[2:-1]
if ('C' not in t or t.count('C') > 1):
   print('WA')
   exit()

s = s[1:]
s = s.replace('C', '')
for x in s:
   if (x.islower() == False):
      print('WA')
      exit()
print('AC')


Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    string R="",L="";
    bool state = true; //true = 正順序、false:逆順
    int Q;
    int query,F;
    int i;
    char C;
    bool temp;
    S = "";
    cin >> S;
    cin >> Q;
    for(i=0;i<Q;i++){
        cin >> query;
        if( query == 1){
            state ^= 0x01;
        }else{
            cin >> F >> C;
            temp = bool(F-1);
            if( temp ^ state == true){
                L = L + C;
            }else{
                R = R + C;
            }
        }
    }
    if(state == true){
        for(i=L.length()-1;i>=0;i--){
            cout << L[i];
        }
        cout << S << R;
    }else{
        for(i=R.length()-1;i>=0;i--){
            cout << R[i];
        }
        for(i=S.length()-1;i>=0;i--){
            cout << S[i];
        }
        cout << L << endl;
    }
}

Measured memory_bytes: 1456
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int a, b; cin >> a >> b;
	cout << a * b << endl;
}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int h,w,a,b;cin>>h>>w>>a>>b;
    vector<vector<int>> vec(h,vector<int>(w,0));
    vector<pair<int,int>> W(w,pair<int,int>(0,0)),H(h,pair<int,int>(0,0));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(min(W[j].first+1,W[j].second)>b||W[j].first+1>h-b){vec[i][j]=1;W[j].second++;H[i].second++;}
            else if(min(W[j].first,W[j].second+1)>b||W[j].second+1>h-b){vec[i][j]=0;W[j].first++;H[i].first++;}
            else if(min(H[i].first+1,H[i].second)>a||H[i].first+1>w-a){vec[i][j]=1;W[j].second++;H[i].second++;}
            else if(min(H[i].first,H[i].second+1)>a||H[i].second+1>w-a){vec[i][j]=0;W[j].first++;H[i].first++;}
            else{
                if(j%2==0){
                    vec[i][j]=1;W[j].second++;H[i].second++;
                }
                else{
                    vec[i][j]=0;W[j].first++;H[i].first++;
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<vec[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 7632
#include <iostream>
#include <tuple>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
void init();
#define REP(var, num) for(sll var = 0; var < num; var++)
typedef signed long long sll;
typedef unsigned long long ull;
/*
numeric_limits<sll>::max()
*/

int main() {
    init();
    sll a,b,k;
    cin >> a >> b >> k;

    for (sll i = min(a, b); i >= 1; i--) {
        if (a % i != 0 || b % i != 0)
            continue;

        k--;
        if (!k) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    int x = 0;
    rep(i, n) {
        if(s[i] == 'I') x++;
        else x--;
        chmax(ans, x);
    }


    cout << ans << endl;

}

Measured memory_bytes: 256