akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;
  cin >> S;
  
  bool A = true;
  
  int N = S.size();
  
  for(int i=0; i<N; i+=2){
    if(S[i]=='L'){
      A = false;
    }
  }
  
  for(int i=1; i<N; i+=2){
    if(S[i]=='R'){
      A = false;
    }
  }
  
  if(A==true){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,a,b;
    cin >>a>>b;
    cout <<(6-a-b)<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll X;
  cin>>X;
  rep(i,-200,200) {
    rep(j,-200,200) {
      if(pow(i,5)-pow(j,5)==X) {
        cout<<i<<" "<<j;
        return 0;
      }
    }
  }
  
       
}

Measured memory_bytes: 3988
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define N 100010
#define M 1010

using namespace std;
char s1[M], s2[M];
map<char, int> ma;

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	cin >> s1 >> s2;
	int len1 = strlen(s1), len2 = strlen(s2);
	int ans = 0x3f3f3f3f;
	for (int i = 0; i < len1 - len2 + 1; i++) {
		int sy = 0;
		for (int j = 0; j < len2; j++)
			if (s1[i + j] != s2[j]) sy++;
		ans = min(ans, sy);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;


int main(){
    int a, b, ans;
    cin >> a >> b;
    if (a <= 5)
        ans = 0;
    else if (a <= 12)
        ans = b / 2;
    else
        ans = b;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N;
	string S;

	cin >> N >> S;

	if (S.length() % 2 == 0)
	{
		if (S.substr(0, S.length() / 2) == S.substr(S.length() / 2, S.length() / 2))
		{
			cout << "Yes";
		}
		else
		{
			cout << "No";
		}
	}
	else
	{
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
def main():
    N, M = [int(x) for x in input().split()]
    H = [0] + [int(x) for x in input().split()]
    flag = [0] + [1] * N
    for _ in range(M):
        a, b = [int(x) for x in input().split()]
        if H[a] >= H[b]:
            flag[b] = 0
        if H[b] >= H[a]:
            flag[a] = 0
    
    print(sum(flag))

if __name__ == "__main__":
    main()


Measured memory_bytes: 20104
from math import factorial as ff
def cc(n,r):
  return ff(n)//ff(n-r)//ff(r)
n,a,b = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse = True)
ans = 0
x = l[:a]
ave = sum(x)/a
m = l.count(x[0-1])
if len(set(x)) == 1:
  for i in range(a,min(b,m)+1):
    ans += cc(m,i)
else:
  p = x.count(x[-1])
  ans = cc(m,p)
print(ave)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int main() {
    string s[3];
    for (int i = 0; i < 3; i++) {
        cin >> s[i];
    }

    int p[3] = {}, t = 0;
    while (p[t] < s[t].size()) {
        t = s[t][p[t]++] - 'a';
    }

    cout << (char)('A' + t) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, M, now=0, ans=0;
  std::cin >> N >> M;
  vvi ab = vv(M, 2, 0, int);
  for(int i=0;i<M;i++) scanf("%d %d", &ab[i][1], &ab[i][0]);
  sort(ab.begin(), ab.end());
  for(int i=0;i<M;i++){
    if(now <= ab[i][1]) ans++, now=ab[i][0];
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7808
#include <iostream>

using namespace std;

int main(){
    int n;
    string s;
    string t;
    cin >> n;
    cin >> s >> t;
    string result;
    for(int i = 0; i < n; i++){
        result = result + s[i] + t[i];
    }
    cout << result << endl;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
      

if n % 2 == 0:
    f = True
    for k in a.values():
        f &= k == 2
    if f:
        print(pow(2, n // 2, 10 ** 9 + 7))
    else:
        print(0)
else:
    f = True
    a[0] += 1
    for k in a.values():
        f &= k == 2
    if f:
        print(pow(2, n // 2, 10 ** 9 + 7))
    else:
        print(0)

Measured memory_bytes: 16624
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(v.begin(), v.end());
	cout << v[0] << " " << v[1] << " " << v[2] << endl;

	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i,sum=0,s1=0,sa;
  scanf("%d",&n);
  int w[n+2];
  for(i=0;i<n;i++){
    scanf("%d",&w[i]);
    sum+=w[i];
  }
  sa=sum;
  for(i=0;i<n;i++){
    s1+=w[i];
    sum-=w[i];
    if(sa>abs(s1-sum))
      sa=abs(s1-sum);
  }
  printf("%d\n",sa);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1e10;

signed main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    int cnt[1020];
    for(int i = 0;i < 1020;i++) {
        cnt[i] = 0;
    }
    for(int i = 0;i < N;i++) {
        cnt[vec.at(i)]++;
    }
    int ret = 0;
    for(int i = 1;i <= 1000;i++) {
        for(int j = i;j <= 1000;j++) {
            for(int k = j;k < i + j && k <= 1000;k++) {
                if(cnt[i] * cnt[j] * cnt[k] != 0) {
                    if(i == j && j == k) {
                        if(cnt[i] > 2) {
                            ret+= (cnt[i] * (cnt[i] - 1) * (cnt[i] - 2)) / 6;
                        }
                    }
                    else if(i == j) {
                        if(cnt[i] != 1) {
                            ret += cnt[i] * (cnt[i] - 1) / 2 * cnt[k];
                        }
                    }
                    else if(j == k){
                        if(cnt[j] != 1) {
                            ret += cnt[j] * (cnt[j] - 1) / 2 * cnt[i];
                        }
                    }
                    else {
                        ret += cnt[i] * cnt[j] * cnt[k];
                    }
                }
            }
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

int main() {
    string S;
    cin >> S;
    int N = S.size();

    cout << ((N+(S[0]==S[N-1]?1:0)) % 2 == 1 ? "First" : "Second") << endl;

    return 0;
}


Measured memory_bytes: 512
const txt = require('fs').readFileSync('/dev/stdin', 'utf8')

const [n, a, b, c, d, e, gomi] = txt.split('\n').map((i: string) => { return Number(i) })
const min = Math.min(a, b, c, d, e)
if (n % min === 0) {
  console.log(Math.floor(n / min) + 4)
}
else {
  console.log(Math.floor(n / min) + 5)
}

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

using namespace std;

struct team{
    int ac,time,num;
    team(int ac,int time,int num):
    ac(ac),time(time),num(num){}
};

auto operator < (const team &e,const team &f){
    if(e.ac!=f.ac)return e.ac>f.ac;
    else if(e.time!=f.time)return e.time<f.time;
    else return e.num>f.num;
}

int main(){
    int M,T,P,R;
    while(cin>>M>>T>>P>>R,M){
        vector<team>tm;
        int plus[100][100]={};
        for(int i=0;i<T;++i){
            tm.emplace_back(0,0,i);
        }
        for(int i=0;i<R;++i){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            --t;
            if(!j){
                tm[t].time+=m+plus[t][p];
                tm[t].ac++;
            }else{
                plus[t][p]+=20;
            }
        }
        sort(tm.begin(),tm.end());
        cout<<tm[0].num+1;
        for(int i=1;i<T;++i){
            if(tm[i-1].ac==tm[i].ac && tm[i-1].time==tm[i].time){
                cout<<"=";
            }else{
                cout<<",";
            }
            cout<<tm[i].num+1;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3012
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX/2;

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        int sy, sx, gy, gx;
        vector<vector<int> > py(5), px(5);

        for(int i=0; i<h; ++i){
            string s;
            cin >> s;
            for(int j=0; j<w; ++j){
                if(s[j] == 'S'){
                    sy = i;
                    sx = j;
                }else if(s[j] == 'G'){
                    gy = i;
                    gx = j;
                }else if(s[j] != '.'){
                    py[s[j]-'1'].push_back(i);
                    px[s[j]-'1'].push_back(j);
                }
            }
        }

        pair<int, int> ret(INF, INF);
        for(int i=0; i<5; ++i){
            int a = (i+1) % 5;
            int b = (i+2) % 5;

            int n = py[a].size();
            vector<int> cost(n);
            for(int j=0; j<n; ++j)
                cost[j] = abs(sy - py[a][j]) + abs(sx - px[a][j]);

            for(int j=0; j<3; ++j){
                int m = py[b].size();
                vector<int> nextCost(m, INF);
                for(int k=0; k<n; ++k){
                    for(int l=0; l<m; ++l){
                        nextCost[l] = min(nextCost[l], cost[k] + abs(py[a][k] - py[b][l]) + abs(px[a][k] - px[b][l]));
                    }
                }
                (++a) %= 5;
                (++b) %= 5;
                n = m;
                cost.swap(nextCost);
            }

            for(int j=0; j<n; ++j)
                ret = min(ret, make_pair(cost[j] + abs(gy - py[a][j]) + abs(gx - px[a][j]), i+1));
        }

        if(ret.first == INF)
            cout << "NA" << endl;
        else
            cout << ret.second << ' ' << ret.first << endl;
    }
}

Measured memory_bytes: 0
fun main(arr:Array<String>) {
    val total = readLine()!!.split(" ") .map { it.toInt() }
    val paint = readLine()!!.split(" ").map { it.toInt() }
    val ans = (0..1).map { total[it] - paint[it] }.let { it[0]*it[1] }
    println(ans)
}


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

const int inf = 1e9;
const ll linf = 1e18;

int main()
{
    int a, b, c; cin >> a >> b >> c;
    cout << ((a+b>=c) ? "Yes" : "No") << endl;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n, m;
int e[MAX_N][MAX_N];
int edge[MAX_N][MAX_N];

int main(){
	cin.sync_with_stdio(false);
	cin >> n >> m;

	rep(i, n + 1) {
		rep(j, n + 1) {
			edge[i][j] = (i == j) ? 0 : INF;
			e[i][j] = INF; 
		}
	}

	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		e[a][b] = e[b][a] = edge[a][b] = edge[b][a] = c; 
	}

	repl(i, 1, n + 1) {
		repl(j, 1, n + 1) {
			repl(k, 1, n + 1) {
				minch(edge[j][k], edge[j][i] + edge[i][k]);
			}
		}
	}

	int cnt = 0;
	rep(i, n + 1) {
		rep(j, n + 1) {
			if (e[i][j] != INF && edge[i][j] == e[i][j]) cnt++;
		}
	}

	cout << m - cnt / 2 << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

ll get_num753(ll v, ll n) {
  if (v > n) {
    return 0ll;
  }

  ll ans = 0;
  ans += get_num753(v * 10 + 7, n);
  ans += get_num753(v * 10 + 5, n);
  ans += get_num753(v * 10 + 3, n);

  bitset<10> flg;

  while (v) {
    flg[v % 10] = 1;
    v /= 10;
  }

  if (flg[3] && flg[5] && flg[7]) {
    ans += 1;
  }

  return ans;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  ll ans = 0;
  ans += get_num753(7, n);
  ans += get_num753(5, n);
  ans += get_num753(3, n);

  cout << ans << endl;

  return 0;
}


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

int main()
{
  char c;
  for (int i = 0; i < 3; i++)
  {
    cin >> c;
    if (c == '7')
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int t1 = (c - 1) / b;
    int t2 = (a - 1) / d;
    if (t2 < t1)
        cout << "No\n";
    else
        cout << "Yes\n";
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main()
{
  while (true)
  {
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0)
      return 0;

    int count = 0;
    for (int i = 1; i <= n; i++)
    {
      for (int j = i + 1; j <= n; j++)
      {
        for (int k = j + 1; k <= n; k++)
        {
          if (i != j && i != k && i + j + k == x)
            count++;
        }
      }
    }

    cout << count << endl;
  }
}

Measured memory_bytes: 3076
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(10**9)

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,m,l):
  edges = {i+1:[] for i in range(n)}
  for i in range(m):
    a,b = l[i]
    edges[a].append(b)
    edges[b].append(a)
  return any(1 in v and n in v for k,v in edges.items())



def main():
  N,M = map(int,input().split())
  l = [tuple(map(int,input().split())) for _ in range(M)]
  print("POSSIBLE" if solve(N,M,l) else "IMPOSSIBLE")
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 70760
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int N, X, sum = 0, min = 1001,tmp=0,ans=0;
	scanf("%d %d", &N, &X);
	int *M = (int *)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &M[i]);
		sum += M[i];
		if (min > M[i]) {
			min = M[i];
		}
	}
	tmp = (X - sum) / min;
	ans = N + tmp;
	printf("%d\n", ans);




#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

void showArray(int a[], int n);

int min(int a[], int n) {
  int tmpMin = a[0];
  for (int i=0; i<n; i++) {
    if (tmpMin > a[i] ) {
      tmpMin = a[i];
    }
  }
  return tmpMin;
}

int max(int a[], int n) {
  int tmpMax = a[0];
  for (int i=0; i<n; i++) {
    if (tmpMax < a[i]) {
      tmpMax = a[i];
    }
  }
  return tmpMax;
}

int main() {
  int n;
  int m;
  int X;
  int Y;
  int x[100];
  int y[100];
  int xmax, ymin;
  int warFlg = 1;
  cin >> n >> m >> X >> Y;
  for (int i=0; i<n; i++) {
    cin >> x[i];
  }
  for (int i=0; i<m; i++) {
    cin >> y[i];
  }
  xmax = max(x, n);
  ymin = min(y, m);

  for (int i=X+1; i<=Y; i++) {
    for (int j=xmax+1; j<=ymin; j++) {
      if (i == j) {
        warFlg = 0;
      }
    }
  }
  if (warFlg == 0) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }

  // if ( X > Y ) {
  //   cout << "War" << endl;
  // } else {
  //   xmax = max(x, n);
  //   ymin = min(y, m);
  //   cout << xmax << " " << ymin << endl;
  //   if (xmax < ymin) {
  //     cout << "No War" << endl;
  //   } else {
  //     cout << "War" << endl;
  //   }
  // }

  return 0;
}

void showArray(int a[], int n) {
  for(int i=0; i<n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 256
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = rils(n - 1)
temp = []
for a, b in ls:
    if a > b:
        a, b = b, a
    temp.append((a - 1, b - 1))
ls = temp

edges = collections.defaultdict(list)
for i, (a, b) in enumerate(ls):
    edges[a].append((b, i))

colors = [-1] * n
colors[0] = (0, 0)

q = collections.deque()
q.append((0, 0))
while q:
    node, i0 = q.popleft()
    c = 1
    for next_, i in edges[node]:
        if colors[next_] != -1:
            continue
        if colors[node][0] == c:
            c += 1
            colors[next_] = (c, i)
        else:
            colors[next_] = (c, i)
        c += 1
        q.append((next_, i))
colors = [c for c, i in sorted(colors, key=lambda x: x[1])]
print(max(colors))
for c in colors[1:]:
    print(c)

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int MAX = 3e2 + 5;
int n, m;
int a[MAX][MAX], ptr[MAX], chosen[MAX], app[MAX];

int main() {
	scanf("%d %d", &n, &m);
	fori(i, 1, n + 1) {
		fori(j, 1, m + 1) {
			scanf("%d", &a[i][j]);
		}
	}
	fori(i, 1, m + 1) {
		chosen[i] = 1;
	}
	fori(i, 1, n + 1) {
		ptr[i] = 1;
	}

	vector<int> seq;
	while(1) {
		memset(app, 0, sizeof app);
		bool bad = false;
		fori(i, 1, n + 1) {
			while(ptr[i] <= m && !chosen[a[i][ptr[i]]]) {
				ptr[i]++;
			}
			if(ptr[i] > m) {
				bad = true;
				break;
			}
			app[a[i][ptr[i]]]++;
		}
		if(bad) {
			seq.pop_back();
			break;
		}
		int most = -1, max_app = 0;
		fori(i, 1, m + 1) {
			if(app[i] > max_app) {
				max_app = app[i];
				most = i;
			}
		}
		seq.push_back(max_app);
		chosen[most] = 0;
	}
	printf("%d\n", *min_element(seq.begin(), seq.end()));

	return 0;
}



Measured memory_bytes: 640
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 0, mod = (int) 0;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a & 1) || (b & 1) || (c & 1)) {
		cout << 0 << endl;
		return 0;
	}
	if (a == b && b == c) {
		cout << -1 << endl;
		return 0;
	}
	for (int j = 0; j < 1000 * 1000 * 50; ++j) {
		int ap = (b + c) / 2, bp = (a + c) / 2, cp = (a + b) / 2;
		a = ap;
		b = bp;
		c = cp;
		if ((ap & 1) || (bp & 1) || (cp & 1)) {
			cout << j + 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

//ユークリッドの互除法
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x;}


int main()
{
	int N;
	cin >> N;
	bool can = false;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) {
				can = true;
				cout << "Yes" << endl;
				return 0;
			}
			else {
				can = false;
			}
		}
	}
	if (can) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main()
{
    int a[3];
    
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    
    for(int i = 0;i<3;i++)
    {
        for(int j = 2;j>0;j--)
        {
            if(a[j]<a[j-1])
            {
                int b = a[j];
                
                a[j] = a[j-1];
                a[j-1] = b;
            }
        }
    }
    
    printf("%d\n",(a[2]-a[1])+(a[1]-a[0]));
    
    
    
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

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

int main() {
  int64_t N;
  cin >> N;
  int64_t m = -1;
  int64_t j;
  
  for(int i = 1; i <= sqrt(N); i++){
    if(N % i != 0) continue;
    j = N / i;
    if(m == -1){
      m = (i-1) + (j-1);
    }else{
      if(m > (i-1) + (j-1)){
        m = (i-1) + (j-1);
      }
    }
  }
  cout << m << endl;

}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  ll N, K;
  cin >> N >> K;
  VI a(N);
  rep(i, N) {
    int ae;
    cin >> ae;
    ae--;
    a.at(i) = ae;
  }
  unordered_map<int, int> se;
  int ini = 0;
  int per = 0;
  int perstart = 0;
  se.emplace(0, -1);
  rep(i, N) {
    if (se.count(a.at(ini))) {
      int befi = se.at(a.at(ini));
      per = i - befi;
      perstart = befi;
      break;
    } else {
      se.emplace(a.at(ini), i);
      ini = a.at(ini);
    }
  }
  perstart += 1;
  if (K < perstart + 1) {
    K = K;
  } else {
    K = (K - perstart) % per + perstart;
  }
  // cout << per << " " << perstart << " " << K << endl;
  ini = 0;
  rep(i, K) { ini = a.at(ini); }
  cout << ini + 1 << endl;

  return 0;
}


Measured memory_bytes: 12076
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <deque>
#include <cstdio>
#include <queue>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
}

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

int main()
{
	string S;

	cin >> S;

	int s = S.size(),ans = 0;
	for (int i = 0; i < s; i++) {
		if (S[i] == 'A') {
			ans++;
			int z = 0;
			for (int j = i + 1,m = 0; j < s; j++) {
				m++;
				if (S[j] == 'Z') {
					z = m;
				}
			}
			ans += z;
			break;
		}
	}

	cout << ans;

	return 0;
}

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

int main(){
	int n, temp, ans;
	scanf("%d",&n);
	temp = n; ans = 0;
	while (temp > 0){
		ans += temp % 10;
		temp /= 10;
	}
	if (ans == 1) ans = 10;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys

a, b, c = map(int, input().split())

#print(a, b, c)
ab = a == b
ac = a == c
bc = b == c

if ab and bc:
  print('No')
  sys.exit()

if not ab and not ac and not bc:
  print('No')
  sys.exit()

print('Yes')

Measured memory_bytes: 38256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    std::string s;
    std::cin >> s;
    for (char& c: s) if (c==',') c = ' ';
    std::cout << s << '\n';
}


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

using namespace std;
using namespace __gnu_pbds;

const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int mod = 998244353;

int n;
int a[maxn];
long long ans;

int main(){
#ifndef ONLINE_JUDGE
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int k=1;k<=n-1;k++){
		cerr<<n-k/2<<" ";
		ans+=a[n-k/2];
	}
	cerr<<"\n"<<endl;
	printf("%lld\n",ans);
	return 0;
}

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

struct ModInt {
    using M = ModInt;

    static vector<M> fact, finv;
    static long long MOD;
    long long v;

    // normalize: [-MOD, MOD**2] -> [0, MOD)
    ModInt(const long long _v = 0) : v((_v < 0) ? _v % MOD + MOD : _v % MOD) {}

    M operator+(const M& x) const { return M(v + x.v); }
    M operator-(const M& x) const { return M(v - x.v); }
    M operator*(const M& x) const { return M(v * x.v); }
    M operator/(const M& x) const { return M(v * x.inv().v); }
    M& operator+=(const M& x) { return *this = *this + x; }
    M& operator-=(const M& x) { return *this = *this - x; }
    M& operator*=(const M& x) { return *this = *this * x; }
    M& operator/=(const M& x) { return *this = *this / x; }
    bool operator==(const M& x) const { return v == x.v; }
    bool operator!=(const M& x) const { return v != x.v; }
    friend istream& operator>>(istream& input, M& x) {
        return input >> x.v, x = M(x), input;
    }
    friend ostream& operator<<(ostream& output, const M& x) {
        return output << x.v;
    }
    inline M pow(long long n) const {
        M x(v), res(1);
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    inline M inv() const { return this->pow(MOD - 2); }
    static void build(int n) {
        fact.assign(n + 1, 1);
        for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
        finv.assign(n + 1, fact[n].inv());
        for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * M(i);
    }
    static M comb(int n, int k) {
        if (n < k || k < 0) return M(0);
        return fact[n] * finv[n - k] * finv[k];
    }
    static M extgcd(int a, int b, int& x, int& y) {
        M d(a);
        if (b) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
};
vector<ModInt> ModInt::fact = vector<ModInt>();
vector<ModInt> ModInt::finv = vector<ModInt>();
long long ModInt::MOD = 998244353;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    ModInt::build(1e6);
    ModInt ans = 0;
    for (int i = 0; i <= k; i++) {
        ans += ModInt(m - 1).pow(n - i - 1) * ModInt::comb(n - 1, i);
    }
    cout << ans * m << endl;
}

Measured memory_bytes: 18760
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long N;
void solve()
{
    vector < long > A;
    long i,num=0;
    for (i=0;i<N;i++)
    {
        long x;
        cin>>x;
        A.push_back(x);
    }
    sort(A.begin(),A.end());
    long long s=1;
    for (i=N-1;i>=1;i--)
    {
        if (num==2) break;
        if (A[i]==A[i-1])
        {
            s*=A[i];
            ++num;
            i--;
        }
    }
    if (num==2) cout<<s;
    else cout<<0;
    cout<<endl;
}
int main()
{
    while(cin>>N)
        solve();
}

Measured memory_bytes: 1400
n = int(input())
D = list(map(int, input().split()))
MOD = 998244353

cnt = [0] * n
for d in D:
    cnt[d] += 1

if D[0] == 0 and cnt[0] == 1:
    res = 1
else:
    res = 0

for i in range(1, n):
    res *= pow(cnt[i - 1], cnt[i], MOD)
    res %= MOD

print(res)

Measured memory_bytes: 84788
a,b = map(int,input().split())
def gcd(x,y):
    if y == 0:
        return x
    return gcd(y,x%y)

n = gcd(a,b)
ans = 0
i = 2
while i*i <= n:
    if n%i == 0:
        while n%i == 0:
            n /= i
        ans += 1
    i += 1
if n != 1:
    ans += 1
print(ans+1)


Measured memory_bytes: 9120
#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>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vs = vector<string>;
using ii = vector<vector<long long>>;
int main() {
	string a;
	cin >> a;
	ll x = 0;
	ll y = 0;
	for (int i = 0; i < a.size(); i++) {
		if (i % 2 == 0) {//最初が白パターン
			if (a[i] == '0') {
				x++;
			}
		}
		else {
			if (a[i] == '1') {
				x++;
			}
		}
	}
	for (int i = 0; i < a.size(); i++) {
		if (i % 2 == 0) {//最初が黒パターン
			if (a[i] == '1') {
				y++;
			}
		}
		else {
			if (a[i] == '0') {
				y++;
			}
		}
	}
	cout << min(x, y) << endl;
}

Measured memory_bytes: 3728
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
  int i,c=0;
  char s[5];
  scanf("%s",s );
  for(i=0;i<4;i++){
    if(s[i]=='+')
    c++;
    else
    c--;
  }
  printf("%d",c );
}


Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)    (x).begin(),(x).end()
# define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
# define mp        make_pair
# define eb        emplace_back
# define REP       (i, a) for (int i = 0; i < (a); i++)
# define INIT      std::ios::sync_with_stdio(false);std::cin.tie(0);

LL fact[222222];
const LL MOD = 1000000007;

LL power(LL x, LL n) {
	LL tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2);
		if (n % 2 == 0) tmp = (tmp*tmp) % MOD;
		else tmp = (((tmp*tmp) % MOD)*x) % MOD;
	}
	return tmp;
}

void f() {
	fact[0] = fact[1] = 1;
	for (LL i = 2; i < 222222; i++) fact[i] = (fact[i - 1] * i) % MOD;
}
//hCm%MOD
LL com(LL h, LL w) {
	return (fact[h + w] * power((fact[h] * fact[w]) % MOD, MOD - 2)) % MOD;
}

signed main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	f();

	LL ans = com(h - 1, w - 1);

	LL sub = 0;

	for (LL i = h - a; i < h; i++) {
		sub += (com(i, b - 1) * com(h - 1 - i, w - 1 - b)) % MOD;
		sub %= MOD;
	}

	ans -= sub;

	while (ans < 0) ans += MOD;

	cout << ans%MOD << endl;

}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<string, PII> PSI;
typedef pair<vector<int>, vector<int>> PVV;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

typedef struct {
	int leftx;	// 上にあといくつ進めるか
	int rightx;
	int upy;
	int downy;
}margin;

const int MAX_H = 2000, MAX_W = 2000;
int H, W;
string S[MAX_H];
margin mar[MAX_H][MAX_W];

int dfs(int y, int x, int dy, int dx, int count)
{
	int nx = x + dx;
	int ny = y + dy;

	if ((nx < 0) || (ny < 0) || (nx >= W) || (ny >= H) || (S[ny][nx] == '#')) {
		return count;
	}

	dfs(ny, nx, dx, dy, count + 1);
}

int dfs_old(int y, int x, int dy, int dx)
{
	int nx = x + dx;
	int ny = y + dy;

	if ((nx < 0) || (ny < 0) || (nx >= W) || (ny >= H)) {
		return 0;
	}

	if (S[ny][nx] == '#')
		return 0;

	return dfs_old(ny, nx, dy, dx) + 1;
}

void solve()
{

	cin >> H >> W;
	FOR(i, 0, H) {
		cin >> S[i];
	}

	FOR(i, 0, H) {
		FOR(j, 0, W) {
			mar[i][j].leftx = 0;
			mar[i][j].rightx = 0;
			mar[i][j].upy = 0;
			mar[i][j].downy = 0;
		}
	}

	FOR(i, 0, H) {
		int count;
		count = 0;
		FOR(j, 0, W) {
			if (S[i][j] == '#') {
				count = 0;
			}
			else {
				mar[i][j].leftx = count;
				count++;
			}
		}

		count = 0;
		for(int j = W - 1; j >= 0; j--) {
			if (S[i][j] == '#') {
				count = 0;
			}
			else {
				mar[i][j].rightx = count;
				count++;
			}
		}
	}

	FOR(j, 0, W) {
		int count;
		count = 0;
		FOR(i, 0, H) {
			if (S[i][j] == '#') {
				count = 0;
			}
			else {
				mar[i][j].upy = count;
				count++;
			}
		}

		count = 0;
		for (int i = H - 1; i >= 0; i--) {
			if (S[i][j] == '#') {
				count = 0;
			}
			else {
				mar[i][j].downy = count;
				count++;
			}
		}
	}

	int max = 0;
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			if (S[i][j] == '#')
				continue;
			int maths = 1;
			maths += mar[i][j].leftx;
			maths += mar[i][j].rightx;
			maths += mar[i][j].upy;
			maths += mar[i][j].downy;

			if (maths > max) {
				max = maths;
			}
		}
	}

	cout << max << endl;
}

int main(void)
{
	solve();

	return 0;
}


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

using namespace std;
int num[100005];
int dp[100005];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> num[i];
    }
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(num[2] - num[1]);
    for (int i = 3; i <= n; ++i) {

        dp[i]=min(dp[i-2]+abs(num[i]-num[i-2]),dp[i-1]+abs(num[i]-num[i-1]));
        //cout<<dp[i]<<endl;
    }
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define ll long long
using namespace std;
void max_self(ll &a, ll b){
    a = max(a, b);
}
int main(){
    int n, W; cin>>n>>W;
    vector<ll> dp(W + 1);
    for(int item = 0; item < n; item++){
        int weight, value;
        cin>>weight>>value;
        for(int weight_already = W-weight; weight_already >=0; weight_already--){
            max_self(dp[weight_already+weight], dp[weight_already] + value);
        }
    }
    ll ans = 0;
    for(int i =0; i<=W; i++){
        max_self(ans, dp[i]);
    }

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

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗  default_value:初期値
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)


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

	vector<uint32_t> v(n);

	for (size_t i = 0; i < n; i++) {
		cin >> v[i];
	}
	_sort(v, uint32_t, less);

	uint32_t result = 0;
	for (size_t i = 0; i < n; i++) {

		size_t j;
		for (j = i + 1; j < n; j++) {
			if (v[i] == v[j]) { continue; }
			break;
		}
		if (j - i != v[i]) {
			result += ((j - i) < v[i] ? (j - i) : ((j - i) - v[i]));
		}
		i = j - 1;
	}

	cout << result;

	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 768
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

int N;
ld dp[301][301][301];
int c[3];

ld rec(int x, int y, int z)
{
    if (x < 0) return 0;
    if (y < 0) return 0;
    if (z < 0) return 0;
    if (x + y + z <= 0) return 0;

    if (dp[x][y][z] != -1) return dp[x][y][z];

    dp[x][y][z] = 0;
    dp[x][y][z] += rec(x - 1, y    , z    ) * x;
    dp[x][y][z] += rec(x + 1, y - 1, z    ) * y;
    dp[x][y][z] += rec(x    , y + 1, z - 1) * z;
    dp[x][y][z] += N;
    dp[x][y][z] *= 1.0 / (x + y + z);

    return dp[x][y][z];
}

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

    cin >> N;

    rep(i, N)
    {
        int a;
        cin >> a;
        a--;
        c[a]++;
    }

    rep(x, N + 1)
    {
        rep(y, N + 1)
        {
            rep(z, N + 1)
            {
                dp[x][y][z] = -1;
            }
        }
    }

    cout << setprecision(10) << setiosflags(ios::fixed);
    cout << rec(c[0], c[1], c[2]) << endl;

    return 0;
}

Measured memory_bytes: 426368
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int n;
int ans,mx=-1;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	while(n--){
		int p;
		cin>>p;
		ans+=p;
		mx=max(mx,p);
	}
	ans-=mx/2;
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3636
#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>;
const int MOD=1000000007;
 
int main() {
  int n;
  cin >> n;
  map<int,int> a, b;
  rep(i,n/2) {
    int x, y;
    cin >> x >> y;
    a[x]++; b[y]++;
  }
  int maxa=0, maxb=0;
  int maxa2=0, maxb2=0;
  int A, B;
  for(auto p: a) {
    if(maxa<p.second) {
      maxa=p.second;
      A=p.first;
    }
  }
  for(auto p: a) {
    if(p.first==A) continue;
    maxa2=max(maxa2,p.second);
  }
  for(auto p: b) {
    if(maxb<p.second) {
      maxb=p.second;
      B=p.first;
    }
  }
  for(auto p: b) {
    if(p.first==B) continue;
    maxb2=max(maxb2,p.second);
  }
 
  int ans=n-maxa-maxb;
  if(A==B) ans=min(n-maxa-maxb2,n-maxa2-maxb);
  cout << ans << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,long double> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int n,a;
string s;

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

	cin>>n>>a;
	int tmp=n%500;
	if(tmp<=a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 892
from collections import deque
import math
masu = input()
n = len(masu)
result = [0 for i in range(n)]
d = deque()
p = "R"
count = 0
for el in masu:
    if el == p:
        count += 1
    else:
        d.append(count)
        count = 1
        if p == "R":
            p = "L"
        else:
            p = "R"
d.append(count)
pointer = 0
for i in range(len(d)//2):
    nR = d.popleft()
    nL = d.popleft()
    result[pointer+nR-1] = math.ceil(nR/2) + nL//2
    result[pointer+nR] = nR//2 + math.ceil(nL/2)
    pointer += nR + nL
result = list(map(str, result))
print(' '.join(result))


Measured memory_bytes: 11380