akhauriyash/Code-Regression huggingface dataset:
def resolve():
    N = int(input())
    F = [int(input().replace(" ", ""), 2) for i in range(N)]
    P = [list(map(int, input().split(" "))) for i in range(N)]
    maxtotal = -1*float("inf")
    maxpattern = ""
    for bits in range(1, (1<<10)):
        total = 0
        for i in range(N):
            c = bin(bits & F[i]).count("1")
            total += P[i][c]
        if maxtotal < total:
            maxpattern = bits
            maxtotal = total
    print(maxtotal)




if '__main__' == __name__:
    resolve()

Measured memory_bytes: 41324
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;


      ll x;
      string str;

      cin>>n>>m;

      ll ara[n+2]={};

      for(i=0; i<m; i++)
      {
          cin>>a>>b;

          ara[a]++;

          ara[b+1]--;
      }

      for(i=1; i<=n; i++)
      {
          ara[i]+=ara[i-1];

     //     cout<<ara[i]<<endl;

          if(ara[i]==m)ans++;
      }

      cout<<ans<<endl;









}



Measured memory_bytes: 4452
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
double x[32],y[32];
double heron(int cn);
int main(){
    int cnt = 0;
    while(~scanf("%lf,%lf",&x[cnt],&y[cnt])){
        cnt++;
    }
    double ans = 0.0;
    for(int q = 0;q < cnt-2; q++){
        ans += heron(q+1);
    }
    printf("%.6lf\n",ans);
    return 0;
}
double heron(int cn){
    double ab,ac,bc;
    ab = sqrt((x[0]-x[cn])*(x[0]-x[cn]) + (y[0]-y[cn])*(y[0]-y[cn]));
    ac = sqrt((x[0]-x[cn+1])*(x[0]-x[cn+1]) + (y[0]-y[cn+1])*(y[0]-y[cn+1]));
    bc = sqrt((x[cn]-x[cn+1])*(x[cn]-x[cn+1]) + (y[cn]-y[cn+1])*(y[cn]-y[cn+1]));

    double s=0,S=0;
    s = (ab+ac+bc)/2.0;
    S = sqrt(s*(s-ab)*(s-ac)*(s-bc));
    return S;
}

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

int main(void){

  int n, q, C=0, i, j;
  int S[N], T[N];
  int left=0, right, mid, key;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }


  for(j=0;j<q;j++){

    key = T[j];
    right = n;
    left = 0;

    while(left<right){
      mid = (left+right)/2;

      if(S[mid] == key){ C++; break;}
      if(S[mid] != key && S[mid] < key){ left = mid+1;}
      if(S[mid] != key && S[mid] > key){ right = mid;}
      
    }
  }

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

  return 0;
}



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

int main() {
	int n;cin>>n;
	while(1){
		vector<P>v;
		rep(i,n){
			string s;int a,b,c;
			cin>>s>>a>>b>>c;
			v.push_back(P(a*3+c*1,s));
		}
		stable_sort(v.begin(),v.end(),[](P a,P b){return a.first>b.first;});
		for(P p:v){
			cout<<p.second<<','<<p.first<<endl;
		}
		cin>>n;
		if(!n)return 0;
		else cout<<endl;
	}
}

Measured memory_bytes: 3248
import itertools

def f(n):
    cnt = n // 4 + 1
    return 'Yes' if any(a * 4 + b * 7 == n for a, b in itertools.product(range(cnt), repeat=2)) else 'No'

if __name__ == '__main__':
    n = int(input())
    print(f(n))

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

bool vis[100005];
vector<int> adj[100005];

void dfs(int at) {
	if (vis[at]) return;
	vis[at] = 1;
	for (int c : adj[at]) {
		dfs(c);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		--a;--b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int cnt = 0;
	for (int i = 0; i < N; ++i) if (!vis[i]) {
		dfs(i);
		++cnt;
	}
	cout << cnt-1 << endl;
}

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

int main() {
  int N, M, X, Y;
  cin >> N >> M;
  vector V(N, 1), B(N, 0);
  B.at(0) = 1;
  while (cin >> X >> Y) {
    V.at(--X)--, V.at(--Y)++;
    if (B.at(X)) B.at(Y) = 1;
    if (!V.at(X)) B.at(X) = 0;
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) cnt += V.at(i) && B.at(i);
  cout << cnt << "\n";
}

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#include <atcoder/all>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	string ans;
	int N;
	cin >> N;
	rep(i, N)
		ans += "ACL";


	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3664
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
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;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース


*/

//main.cpp----------------------------
#define MAX 100000

int n;
int h[21];

int main() {
  cin >> n;
  rep(i, n) cin >> h[i];

  int max = h[0];
  int cnt = 1;
  for(int i=1; i<n; ++i) {
    if(max<=h[i]) {
      max = h[i];
      ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int maxn = 1e5 + 5;
const int mod = 1e9+7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll four = 1;
    f(n - 1) {
        four *= 4;
        four %= mod;
    }
    vector<ll>c(n);
    for (auto &i : c) {
        cin >> i;
    }
    sort(all(c));
    reverse(all(c));
    ll mul = 0;
    f(n) {
        mul += c[i] * (i + 2);
        mul %= mod;
    }
    cout << four * mul % mod << '\n';
}

Measured memory_bytes: 1792
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
#define int long long
using namespace std;
signed main() {
    int H, A;
    cin >> H >> A;
    if (H % A == 0) {
        cout << H / A << endl;
    }
    else {
        cout << H / A + 1 << endl;
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;

    int ans = 0;
    for(int i=1;;i++){
        int A, B;
        A = i;
        B = N - i;
        if(A >= B)
            break;
        ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

Ans = [[0] * W for _ in range(H)]

num = 1
cnt = A[0]
for i in range(H):
    for j in range(W):
        if cnt == 0:
            num += 1
            cnt = A[num-1]
        if i % 2 == 0:
            Ans[i][j] = num
            cnt -= 1
        else:
            k = W - j - 1
            Ans[i][k] = num
            cnt -= 1

for A in Ans:
    for i, a in enumerate(A):
        if i == W - 1:
            print(a)
        else:
            print(a, end=' ')





Measured memory_bytes: 74840
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[200010],b[200010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld%lld",a+i,b+i);
	sortup(a,n);
	sortup(b,n);
	if(n%2==1)printf("%lld\n",b[n/2]-a[n/2]+1);
	else printf("%lld\n",b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1);
}

Measured memory_bytes: 6328
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2+10;
#define fr(i,low,up,st) for(int i = low;i <= up;i += st)
#define nfr(i,low,up,st) for(int i = low;i >= up;i -= st)
#define sz(a) a.siz()
#define clr(a) memset(a,0,sizeof a)

vector<int> e[N];
int y[N],vis[N],a[N][N];

bool solve(int x){
   fr(i,0,e[x].size()-1,1){
      int w = e[x][i];
      if(!vis[w]){
         vis[w] = 1;
         if(!y[w] || solve(y[w])){
            y[w] = x;
            return true;
         }
      }
   }
   return false;
}

int n,m;
int mk[N][N];
int b[N][N];
int main(){
   scanf("%d%d",&n,&m);
   fr(i,1,n,1)
      fr(j,1,m,1)
         scanf("%d",&a[i][j]);

   fr(j,1,m,1){
      fr(i,1,n,1){
         e[i].clear();
         fr(k,1,m,1){
            if(!mk[i][k])e[i].push_back((a[i][k]-1)/m+1);
         }
      }
      memset(y,0,sizeof y);
      fr(i,1,n,1){
         memset(vis,0,sizeof vis);
         solve(i);
      }
      fr(i,1,n,1){
         fr(k,1,m,1){
            if(mk[i][k])continue ;
            int cl = (a[i][k]-1)/m+1;
            if(y[cl] == i){
               mk[i][k] = j;
               break;
            }
         }
      }
   }
   fr(i,1,n,1)
      fr(k,1,m,1)
         b[i][mk[i][k]] = a[i][k];
   memcpy(a,b,sizeof b);

   fr(i,1,n,1){
      fr(j,1,m,1)
         printf("%d ",a[i][j]);
      puts("");
   }
   fr(i,1,n,1){
      fr(j,1,m,1)
         mk[(a[i][j]-1)/m+1][j] = a[i][j];
   }
   fr(i,1,n,1){
      fr(j,1,m,1)
         printf("%d ",mk[i][j]);
      puts("");
   }
   return 0;
}


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

int main() {
  int N;
  cin >> N;
  string s; 
   
    for(int i; i < N; i++){
      cin >> s;
      
      if(s == "Y"){
        cout << "Four" << endl;
        break;
      }
          
      else if(i == N - 1){
        cout << "Three" << endl;
      }
    
    }

}

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

int main(){
  char A[] = "abcdefghijklmnopqrstuvwxyz";
  char C;
  cin >> C;
  for(int i = 0;i < 26;i++){
    if(A[i] == C)
      cout << A[i + 1] << endl;
  }
  return 0;
}


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

using namespace std;

int n,m,w[105],v[105];
long long f[105][100005];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n; i++) cin>>w[i]>>v[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            f[i][j]=f[i-1][j];
            if (j>=w[i] && f[i][j]<f[i-1][j-w[i]]+v[i])
                f[i][j]=f[i-1][j-w[i]]+v[i];
        }
    }
    cout<<f[n][m];
    return 0;
}


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << "" << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll x(n); x[i]=a;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

ll pow(ll n, ll r){
    ll ans = 1;
    REP(i,r) ans *= n;
    return ans;
}

int main(){
    ll n, m, ans=0;
    cin >> n >> m;
    vll a(n, 0);
    vll z(n, 0);
    vll s(m);
    vll c(m);

    REP(i,m){
        cin >> s[i] >> c[i];
        s[i]--;
    }

    REP(i,m){
        if(c[i] == 0){
            if(a[s[i]] > 0){
                cout << -1 << endl; return 0;
            }
            z[s[i]] = 1;
        }
        else{
            if(a[s[i]] == 0){
                if(z[s[i]] > 0){
                    cout << -1 << endl; return 0;
                }
                else{
                    a[s[i]] = c[i];
                }
            }
            else{
                if(a[s[i]] != c[i]){
                    cout << -1 << endl; return 0;
                }
            }
        }
    }

    if(n>1 && a[0] == 0){
        if(z[0] > 0){
            cout << -1 << endl; return 0;
        }
        else a[0] = 1;
    }

    cout << a << endl;
    // cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,A,B=map(int,input().split())
dom=0
foreign=0
for x in input():
  if x == "a":
    if dom+foreign<A+B:
      dom+=1
      print("Yes")
    else:
      print("No")
  elif x == "b":
    if dom+foreign<A+B and foreign<B:
      foreign+=1
      print("Yes")
    else:
      print("No")
  else:
    print("No")



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

using namespace std;

typedef long long llint;

int main() {
  int n;
  cin >> n;
  vector<llint> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  llint ans = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      ans += sum / 2;
      sum = 0;
    }
    sum += a[i];
  }
  ans += sum / 2;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<ll> primes;
void make_primes(){
    primes.pb(2);
    for(ll n = 3; n <= 2200; n++){ // 2200^3 > 10^10
        bool isPrime = true;
        for(ll i = 0; primes[i] * primes[i] <= n && i < primes.size(); i++){
            if(n % primes[i] == 0) {
                isPrime = false;
                break;
            }
        }
        if(isPrime) primes.pb(n);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    make_primes();
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        for(ll prime: primes){
            while(1){
                if(A[i] % (prime * prime * prime) == 0){
                    A[i] /= prime * prime * prime;
                }
                else{
                    break;
                }
            }
        }
    }
    sort(all(A));
    vector<pair<ll, int>> C;
    map<ll, int> M;
    ll num = -1;
    rep(i, N){
        if (num == A[i]){
            C.back().second++;
        }
        else{
            C.pb(mp(A[i], 1));
            M[A[i]] = (int)C.size(); // index + 1
        }
        num = A[i];
    }
    
    vector<int> vis(C.size(), 0); // チェックしたか
    int ret = 0;
    
    // a*b^2 and a^2*b
    rep(i, C.size()){
        if(C[i].first > 2200 * 2200) break;
        if(vis[i] > 0 || C[i].first == 1) continue;
        ll a = C[i].first;
        ll b = 1;
        for(ll prime: primes){
            if(a % (prime * prime) == 0){
                a /= (prime * prime);
                b *= prime;
            }
        }
        if(M[a * a * b] > 0){
            ret += max(C[i].second, C[M[a * a * b] - 1].second);
            vis[i] = 1, vis[M[a * a * b] - 1] = 1;
        }
        else{
            ret += C[i].second;
            vis[i] = 1;
        }
    }
    
    // a and a^2
    rep(i, C.size()){
        if(C[i].first > 100000) break; // (10^5)^2=10^10
        if(vis[i] > 0 || C[i].first == 1) continue;
        ll a = C[i].first;
        ll b = a * a;
        if(M[b] > 0){
            ret += max(C[i].second, C[M[b] - 1].second);
            vis[i] = 1, vis[M[b] - 1] = 1;
        }
        else{
            ret += C[i].second;
            vis[i] = 1;
        }
    }
    
    // 1だけ特別に処理
    rep(i, C.size()){
        if(vis[i] == 0){
            if(C[i].first == 1) ret++;
            else ret += C[i].second;
        }
    }
    
    output(ret, 0);
    
    return 0;
}

Measured memory_bytes: 12912
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int array[3];
    for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
    for(int i = 2; i > 0; i--){
        for(int j = 0; j < i; j++){
            if(array[j] > array[j+1])swap(array[j],array[j+1]);
        }
    }
    printf("%d %d %d\n",array[0],array[1],array[2]);
}


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

using namespace std;
#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__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  int x1, x2, y1, y2;

  x1 = 0;
  x2 = W;
  y1 = 0;
  y2 = H;

  int x, y, a;
  rep(i, N){
    cin >> x >> y >> a;
    if(a == 1){
      chmax(x1, x);
    }
    if(a == 2){
      chmin(x2, x);
    }
    if(a == 3){
      chmax(y1, y);
    }
    if(a == 4){
      chmin(y2, y);
    }

  }

  int x_white = max(x2 - x1, 0);
  int y_white = max(y2 - y1, 0);

  cout <<  x_white * y_white << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,f[100001],g[100001];
vector<int>v[100001];
int find(int x)
{
	if(f[x]==x)
	return x;
	return f[x]=find(f[x]);
}
void hb(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(fx!=fy)
	f[fx]=fy,g[fy]+=g[fx];
}
signed main()
{
	int x,y,ans,fx,fy;
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=n;i++)
	f[i]=i,g[i]=1;
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld",&x,&y);
		hb(x,y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=1;i<=k;i++)
	{
		scanf("%lld%lld",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
	{
		fx=find(i);
		ans=g[fx]-1;
		for(int j=0;j<v[i].size();j++)
		{
			x=v[i][j];
			if(find(x)==fx)
			ans--;
		}
		printf("%lld ",ans);
	}
	return 0;
}

Measured memory_bytes: 11508
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  float n;
  while(cin>>n,n>0){
    string s = "";
    for(int i = 0 ; i < 8 ; i ++){
      if(n >= (1<<(7-i))){
	n -= (1<<(7-i));
	s += '1';
      }else
	s += "0";
    }
    s += '.';
    
    for(int i = 0 ; i < 4 ; i ++){
      double miya = 1.0/(1<<(i+1));
      if(n >= miya){
	n -= miya;
	s += '1';
      }else
	s += '0';
    }
    if(n==0)cout<<s<<endl;
    else cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 1232
#include <iostream>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>
#include <algorithm>
#include <string.h>
using namespace std;
#define ll long long

int main () {
  ll n;
  cin >> n;
  long double x[8], y[8];
  for (ll i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  vector<ll> num;
  for (ll i = 0; i < n; i++) {
    num.push_back(i);
  }
  long double  sum = 0;
  long double number = 0;
  do {
    long double sub, subsub;
    for (ll p = 0; p < n; p++) {
      if (p == 0) {
        sub = x[num[p]];
        subsub = y[num[p]];
      }  
      else {
        sum += sqrt((sub - x[num[p]]) * (sub - x[num[p]]) + 
        (subsub - y[num[p]]) * (subsub - y[num[p]]));
      }
    }
    number++;
  } while (next_permutation(num.begin(), num.end()));
  cout << setprecision(15) << sum / number << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    while(true) {
        val i1 = sc.nextInt()
        val op = sc.next()
        val i2 = sc.nextInt()

        if (op == "?") break

        when (op) {
            "+" -> println(i1 + i2)
            "-" -> println(i1 - i2)
            "*" -> println(i1 * i2)
            "/" -> println(i1 / i2)
        }
    }
}



Measured memory_bytes: 25444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    rep(i,n-1){
        if(s[i]!=s[i+1]) ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A;
    bool flag=true;
    cin >> A;
    vector<int> N(A);
    for(int i=0;i<A;i++){
        cin >> N[i];
    }
    for(int i=0;i<A;i++){
        if(N[i]%2==0&&!(N[i]%3==0||N[i]%5==0)){
            flag=false;
            break;
        }
    }
    if(flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,x,y,i,j;
  scanf("%d %d %d",&n,&x,&y);
  int A[n];
  for(i=1;i<=n-1;i++){
    A[i]=0;
  }
  for(i=1;i<=n;i++){
    for(j=i+1;j<=n;j++){
      if(j<=x){
        A[j-i]++;
      }else if(y<=i){
        A[j-i]++;
      }else if(i<=x){
        if(y<=j){
          A[j-i+x-y+1]++;
        }else if(j-x<=y-j+1){
          A[j-i]++;
        }else{
          A[y-j+1+x-i]++;
        }
      }else if(y<=j){
        if(y-i<=i-x+1){
          A[j-i]++;
        }else{
          A[j-y+i-x+1]++;
        }
      }else{
        if(j-i<=y-j+i-x+1){
          A[j-i]++;
        }else{
          A[y-j+i-x+1]++;
        }
      }
    }
  }
  for(i=1;i<=n-1;i++){
    printf("%d\n",A[i]);
  }
  return 0;
}

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

using namespace std;

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

	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		cout << s << '\n' << s << '\n';
	}

	return 0;
}



Measured memory_bytes: 256
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"4
3 8 5 1
" => r"Yes",

r"4
3 8 4 1
" => r"No",

r"10
1 8 10 5 8 12 34 100 11 3
" => r"No"
}

use std::cmp;
use std::cmp::max;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: i32,
        l: [i32; n]
    }

    let mut ans = 0;
    let mut maxnum = 0;
    for i in 0..l.len() {
        ans += l[i];
        maxnum = cmp::max(l[i], maxnum);
    }

    if maxnum < ans - maxnum {
        "Yes".to_string()
    } else {
        "No".to_string()
    }
}


Measured memory_bytes: 4352
#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() {
    string s;
    cin >> s;
    int n = s.size();
    ll mod = 1e9+7;
    vector<vector<long>> dp(n+1, vector<long>(13));
    dp[0][0] = 1;
    rep(i,n) {
        rep(j,13) {
            if(s[i] == '?') {
                rep(k,10) {
                    dp[i+1][(j*10+k)%13] += dp[i][j];
                    dp[i+1][(j*10+k)%13] %= mod;
                }
            } else {
                ll k = s[i]-'0';
                dp[i+1][(j*10+k)%13] += dp[i][j];
                dp[i+1][(j*10+k)%13] %= mod;
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}


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

int main() {
	
    long long int num;
    cin>>num;
    string fin;
    while(num>0)
    {
        if(num%26!=0)
        {
            char c= (num%26)+96;
            fin.push_back(c);
            num=num/26;
        }
        else
    	 {
    	 	fin.push_back('z');
    	 	num=num/26;
    	 	num=num-1;
    	  
    	 }
    
    }
    for(long long int j=fin.size()-1;j>=0;j--)
    {
        cout<<fin[j];
    }
    
	return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	long long m=0,a=0,r=0,c=0,h=0;
	string s;
	cin>>n;
	while(cin>>s)
		switch(s[0]){
		case'M':
			m++;
			break;
		case'A':
			a++;
			break;
		case'R':
			r++;
			break;
		case'C':
			c++;
			break;
		case'H':
			h++;
		}
	cout<<m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,i,sum=0,x=1;
	cin>>n;
	int a[n+1];
	bool flag=true;
	for(i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==1)flag=false;
	}
	if(flag){
		cout<<"-1";
		return 0;
	}
	for(i=1;i<=n;i++)
	if(a[i]!=x){
		sum++;
		continue;
	}
	else
	x++;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

A, B, C, K = inpl()
xa = min(K, A)
K -= xa
xb = min(K, B)
K -= xb
xc = K
print(xa-xc)


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

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

int main(){
    ll n,cost=0;
    double avg=0;
    vector<ll> A;
    cin>>n;
    A = vector<ll>(n);
    for(int i=0;i<n;i++){
        cin>>A[i];
        avg += (double)A[i]/n;
    }
    avg = (ll)round(avg);
    for(int i=0;i<n;i++){
        cost += pow(A[i]-(ll)avg,2);
    }
    cout<<cost;
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }

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

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void solve() {
  string s, t;
  cin >> s >> t;
  t += s;
  cout << t << "\n";
  debug(s);
  debug(t);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 3596
using Yorukatsu048.Questions;
using Yorukatsu048.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu048.Questions
{
    /// <summary>
    /// ABC160 D
    /// </summary>
    public class QuestionD : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nxy = inputStream.ReadIntArray();
            var n = nxy[0];
            var x = nxy[1] - 1;
            var y = nxy[2] - 1;

            var count = new int[n];
            for (int i = 0; i + 1 < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    var normal = j - i;
                    var shortCut = Math.Abs(x - i) + 1 + Math.Abs(j - y);
                    count[Math.Min(normal, shortCut)]++;
                }
            }

            for (int i = 1; i <= n - 1; i++)
            {
                yield return count[i];
            }
        }
    }
}


namespace Yorukatsu048
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionD();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu048.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu048.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 N, X, Y, i, j;
  cin >> N >> X >> Y;
  X--;
  Y--;

  vi ans(N);
  i64 k = 0;
  REP(0, N, i) {
    REP(0, N, j) {
      if(i > j) {
	i64 d = min(i - j,
		    min(abs(X-i)+abs(Y-j)+1, abs(Y-i)+abs(X-j)+1)
		    );
	ans[d]++;
      }
    }
  }
  REP(1, N, k) {
    cout << ans[k] << endl;
  }

  return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  string s, t;
  cin >> s >> t;
  int dp[s.size() + 1][t.size() + 1];

  // 初期化
  for (int i = 0; i <= s.size(); i++) dp[i][0] = 0;
  for (int i = 0; i <= t.size(); i++) dp[0][i] = 0;

  // DPしていく
  for (int i = 1; i <= s.size(); i++) {
    for (int j = 1; j <= t.size(); j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }

  // ここで一旦確認用
  // for (int i = 0; i <= s.size(); i++) {
  //   for (int j = 0; j <= t.size(); j++) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  // 復元
  string ans = "";
  int i = s.size(), j = t.size();
  while (i > 0 || j > 0) {  // 左上に着くまで
    if (i > 0 && dp[i][j] == dp[i - 1][j])
      i--;  // 一つ上へ
    else if (j > 0 && dp[i][j] == dp[i][j - 1])
      j--;  // 一つ左へ
    else {
      ans = s[i - 1] + ans;
      i--;
      j--;
    }
    // cout << i << " " << j << endl;
  }

  cout << ans << endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n;
ll W, w, x;
vl v[4], s[4];
ll _search(ll _w, int i){
  if(i == 4) return 0;
  ll ret = 0;
  FOR(j, 0, sz(s[i])){
    if(_w < j*(w+i)) break;
    maxs(ret, s[i][j] + _search(_w - j*(w+i), i+1));
  }
  return ret;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> W >> w >> x;
  v[0].pb(x);
  FOR(i, 0, n-1){
    ll _w;
    cin >> _w >> x;
    v[_w-w].pb(x);
  }
  FOR(i, 0, 4){
    sort(rng(v[i]));
    reverse(rng(v[i]));
    ll su = 0;
    s[i].pb(0);
    each(itr, v[i]){
      su += *itr;
      s[i].pb(su);
    }
  }
  cout << _search(W, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
long double calc(int N){
    return N * (N + 1) / 2;
}

int main(){
    int N, K;
    cin >> N >> K;
    
    long double ans = 0.0;
    vector<ll> p(N);
    for (int i = 0; i < N;i++)
    {
        cin >> p[i];
    }
    vector<long double> calced(N);
    vector<long double> ruisekiwa(N+1);
    for (int i = 0; i < N; i++)
    {
        calced[i] = (double)calc(p[i]) / p[i];
        ruisekiwa[i + 1] = ruisekiwa[i] + calced[i];
    }
    for (int i = K; i <= N; i++)
    {
        long double sum = ruisekiwa[i] - ruisekiwa[i-K];
        ans = max(ans, sum);
    }
    cout << fixed << ans <<setprecision(10)<< endl;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    s += "X";
    const ll n = s.size();
    vector<vector<ll>> pos(26);
    rep(i, n-1) {
        pos[s[i]-'a'].pb(i);
    }
    vector<vector<ll>> G(n+1);
    rep(i, n) rep(j, 26) {
        ll idx = lower_bound(all(pos[j]), i) - pos[j].begin();
        ll nxt = idx >= pos[j].size() ? n : pos[j][idx]+1;
        G[nxt].pb(i);
    }
    vector<ll> dp(n+1, linf); dp[n] = 0;
    rrep(i, n+1) {
        assert(dp[i] < linf);
        each(j, G[i]) {
            chmin(dp[j], dp[i]+1);
        }
    }
    ll len = dp[0];
    string ans = "";
    ll now = 0;
    rep(t, len) {
        rep(c, 26) {
            ll idx = lower_bound(all(pos[c]), now) - pos[c].begin();
            ll nxt = idx >= pos[c].size() ? n : pos[c][idx]+1;
            if (dp[nxt] == len-t-1) {
                now = nxt;
                ans += char(c+'a');
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 70036
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

def mul(A):
    res = 1
    for a in A:
        res *= a
    return res

O = {'+': sum, '*': mul}


class Source():
    def __init__(self, S, i = 0):
        self.S = S
        self.pos = i

def peek(S):
    return S.S[S.pos] if S.pos < len(S.S) else 'a'

def next(S):
    S.pos += 1

def level_off(S):
    lv = 0
    while peek(S) == '.':
        lv += 1
        next(S)

    return lv

def level(S):
    i = S.pos
    lv = 0
    while peek(S) == '.':
        lv += 1
        next(S)

    S.pos = i
    return lv

def expr(S, lv, ope):
    A = []
    while peek(S) != 'a' and level(S) == lv:
        level_off(S)
        A.append(factor(S, lv))
    return ope(A)

def factor(S, lv):
    if peek(S) in O:
        ope = O[peek(S)]
        next(S)
        return expr(S, lv + 1, ope)
    return num(S)

def num(S):
    res = int(peek(S))
    next(S)

    return res


while True:
    n = int(input())
    if n == 0:
        break
    S = []
    for i in range(n):
        S.append(input())
    print(expr(Source(''.join(S)), 0, O['+']))


Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

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

  int result=2;
  for (int i = static_cast<int>(s.size() / 2) - 1; i > 1; --i) {
    bool flag = true;
    for (int j = 0; j < i; ++j) {
      if (s[j] != s[j + i]) {
        flag = false;
        break;
      }
    }

    if (flag) {
      result = i * 2;
      break;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
typedef long long ll;

ll x, y, a, b, c, ans, p[N], q[N], r[N], pq[2*N];
int main() {
	ll i, j;
	cin >> x >> y >> a >> b >> c;
	for(i=0; i<a; i++) scanf("%lld", &p[i]);
	for(i=0; i<b; i++) scanf("%lld", &q[i]);
	for(i=0; i<c; i++) scanf("%lld", &r[i]);
	sort(p, p+a, greater<int>());
	sort(q, q+b, greater<int>());
	sort(r, r+c, greater<int>());
	for(i=0; i<x; i++) pq[i] = p[i];
	for(i=0; i<y; i++) pq[i+x] = q[i];
	sort(pq, pq+x+y);
	for(i=j=0; i<c && j<x+y && r[i] > pq[j]; i++, j++) pq[j] = r[i];
	for(i=0; i<x+y; i++) ans += pq[i];
	cout << ans;
	return 0;
}

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

int main(){
  int input, h, m, s, hour, min;
  hour = 60*60;
  min = 60;
  cin >> input;
  h = input / hour;
  m = (input % hour) / min;
  s = (input % hour) % min;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
  
}


Measured memory_bytes: 3104