akhauriyash/Code-Regression huggingface dataset:
a = list(map(int, input().split()))
N = a[0]
K = a[1]
P = list(map(int, input().split()))

for i in range(len(P)):
    P[i] = (float)(P[i]+1)/2

S = []
for i in range(len(P)):
    if(i > 0):
        S.append(P[i]+S[i-1])
    else:
        S.append(P[0])
# print(S)

max = S[K-1]
for i in range(len(S)-K):
    a = S[i+K]-S[i]
    # print(a)

    if(a > max):
        max = a

# max = 0

# for i in range(len(P)-K+1):
#     num = 0
#     for j in range(K):
#         num += P[i+j]
#         # print(P[i+j],end=" ")
#     # print(num)
#     if(max < num):
#         max = num

print("{0:6f}".format(max))


Measured memory_bytes: 24804
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
// const int MOD = 1e9 + 7;
const int MOD = 10007;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

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<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

char s[N * 2], t[N * 2];
int buca[26], bucb[26], n;

int main() {
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    memset(buca, -1, sizeof(buca));
    memset(bucb, -1, sizeof(bucb));
    n = strlen(s + 1);
    bool flag = true;
    for (int i = 1; i <= n; i++) {
        if (!~buca[s[i] - 'a']) buca[s[i] - 'a'] = t[i] - 'a';
        else if (buca[s[i] - 'a'] != t[i] - 'a') flag = false;
        if (!~bucb[t[i] - 'a']) bucb[t[i] - 'a'] = s[i] - 'a';
        else if (bucb[t[i] - 'a'] != s[i] - 'a') flag = false;
    }
    if (flag) puts("Yes");
    else puts("No");
    return 0;
}

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

int main(){
	int n,t;
  	cin >> n;
  	vector<int> a(100002);
  	for(int i =0 ; i<n;i++) {
    	cin >> t;
      	a[t]++;a[t+1]++;a[t+2]++;
    }
  	sort(a.begin(),a.end());
  	cout << a[100001] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){

	string s;
	cin >> s;
	int ma = 0;
	int cnt = 0;
	rep(i,(int)s.size()) {
		if (s[i]!='A'&&s[i]!='C'&&s[i]!='G'&&s[i]!='T') {
			ma = max(ma, cnt);
			cnt = 0;
		} else {
			cnt++;
		}
	}
	ma = max(ma, cnt);
	cout << ma << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
int constexpr N = 1e9 + 1;
using namespace std;
using ll = long long;
void max_self(ll& x,ll& y ) {
	x = max(x, y);
}
void min_self(ll& x, ll& y) {
	x = min(x, y);
}
ll n, V = 0;
ll W;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> W;
	vector<ll> w(n);
	vector<ll> v(n);

	for (ll i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
		V += v[i];
	}
	vector<ll> dp(V + 1, N); 
	dp[0] = 0;                //dp[i] min weight of knapsack with value i
	for (int item = 0; item < n; ++item) {
		for (int value_already = V - v[item]; value_already >= 0; --value_already) {
			 dp[value_already + v[item]]=min(dp[value_already + v[item]], ll(dp[value_already] + w[item]));
		}
	}
	ll ans=0;
	for (ll j = 0; j <= V; ++j) {
		if (dp[j] <= W) {
			 max_self(ans,j);
		}
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mk make_pair
#define pb push_back
int main()
{
ios_base ::sync_with_stdio(0);cin.tie(0);cout.tie(0);
double r;
cin>>r;
cout<<2*3.14159265*r;

}

Measured memory_bytes: 3736
#include<string>
#include <iostream>
#include<vector>
#include <algorithm>
#include<queue>
#define T long long

struct S{
	int kx;
	int ky;
	int cx;
	int cy;
	int depth;
};



int main(void){
	int s,w;
	std::cin >> s >> w;
	if(s<=w){
		std::cout << "unsafe"<<std::endl;
	}else{
		std::cout << "safe"<<std::endl;
	}
}


Measured memory_bytes: 3624
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <bitset>
#include <cmath>
#include <tuple>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 型
#define ll long long

// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// for文
#define forn(i, size) for (long long(i) = 0; (i) < (size); (i)++)
#define for0(size) for (long(i) = 0; (i) < (size); (i)++)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length, type_name) sort(array, array + length, std::greater<type_name>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#define println(str) cout << str << endl;

#pragma endregion

#pragma region Utility
#pragma region 最大公約数
ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}
#pragma endregion

#pragma region 最小公倍数
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
#pragma endregion

#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion

#pragma region 連想配列のkeyが存在するか
template <typename T>
bool containsKey(map<string, T> map, string key)
{
    if (map.count(key) == 0)
    {
        return false;
    }
    return true;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    ll H, N;
    cin >> H >> N;

    // 入力数がN個の場合
    int A[N];
    forn (i, N)
    {
        cin >> A[i];
    }

    ll sum_val = getSum(A, N);

    if (sum_val >= H)
    {
        Yes
    }
    No
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

#define mod 1000000007

int main()
{
    int v, e, r;
    cin >> v >> e >> r;
    vector<vector<pair<int, int> > > graph(100001);
    for(int i = 0; i < e; i++){
        int s, t, d;
        cin >> s >> t >> d;
        graph[s].push_back(make_pair(t, d));
    }
    priority_queue<pair<long long int, int> > qu;
    vector<long long int> result(100001, -mod);
    result[r] = 0;
    qu.push(make_pair(0, r));
    while(!qu.empty()){
        int nowplace = (qu.top()).second;
        long long int nowcost = (qu.top()).first;
        qu.pop();
        if(result[nowplace] > nowcost) continue;
        result[nowplace] = nowcost;
        for(int i = 0; i < graph[nowplace].size(); i++){
            int next = graph[nowplace][i].first;
            long long int cost = graph[nowplace][i].second;
            if(result[next] < nowcost - cost) qu.push(make_pair(nowcost - cost, next));
        }
    }
    for(int i = 0; i < v; i++){
        if(result[i] == -mod) cout << "INF" << endl;
        else cout << -result[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 16568
#include <stdio.h>
#include <string.h>

int main(){
    int idx, len;
    char str[21];
    scanf("%s", str);
    len = strlen(str);
    for(idx = 0; idx < len / 2; ++idx){
        str[idx          ] = str[idx] ^ str[len - idx - 1];
        str[len - idx - 1] = str[idx] ^ str[len - idx - 1];
        str[idx          ] = str[idx] ^ str[len - idx - 1];
    }
    printf("%s\n", str);
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
#include<stdlib.h>
#include<stdio.h>
int main(){
    int n;
    cin>>n;
    int ar[n];
    int mn=10000,mx=0;
    for(int i=0;i<n;i++){
        cin>>ar[i];
        if(mn>ar[i])mn=ar[i];
        
        if(mx<ar[i])mx=ar[i];
    }
    long long ans=100000000000000,s=0;
    for(int i=mn;i<=mx;i++){
        s=0;
        for(int j=0;j<n;j++){
            s+=(ar[j]-i)*(ar[j]-i);
        }
        if(ans>s)ans=s;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int A, B;
	cin >> A >> B;
	int count = 0;
	for (int i = A; i <= B; i++) {
		if (to_string(i)[0] == to_string(i)[4] && to_string(i)[1] == to_string(i)[3]) {
			count++;
		}
	}

	cout << count;;
	return 0;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

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

	if (A + B < C + D)cout << "Right" << endl;
	else if (A + B > C + D) cout << "Left" << endl;
	else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int> b(N),ans(N);
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  for(int i=0;i<N;i++){
    for(int j=b.size()-1;j>=0;j--){
      if(b[j]==j+1){
        ans[i]=b[j];
        b.erase(b.begin()+j);
        break;
      }
    }
  }
  if(ans[N-1]==0){
    cout<<-1<<endl;
  }else{
    for(int i=N-1;i>=0;i--){
      cout<<ans[i]<<endl;
    }
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll pw(ll a, ll b) {
    if (b == 0) return 1;
    ll t = pw(a, b / 2);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
int main()
{
	double n,D;cin>>n>>D;
	ll cnt=0;
	while(n--)
	{
		double x,y;cin>>x>>y;
		double d=sqrt(x*x+y*y);
		if(d<=D)cnt++;
	}
	cout<<cnt;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const ll MOD = 1000000007, MAX = 2000000007, MAXN = 100005;
ll ans[MAXN];

ll fast_exp(ll base, ll exp)
{
    if(exp==1)
        return base;
    else
    {
        if(exp%2 == 0)
        {
            ll x = fast_exp(base,exp/2);
            ll base1 = (x*x)%MOD;
            if(base1 >= MOD)
                return base1%MOD;
            else
                return base1;
        }
        else
        {
            ll x = fast_exp(base,(exp-1)/2);
            ll ans = (base*x)%MOD;
            ans = (ans*x)%MOD;
            if(ans >= MOD)
                return ans%MOD;
            else
                return ans;
        }
    }
}

ll solve(ll n, ll k)
{
    for(ll i=k; i>=1; i--)
    {
        ll muls = k/i;
        ans[i] = fast_exp(muls,n);
        ans[i]%=MOD;
        ll to_subtract = 0;
        for(ll j=i+i; j<=k; j+=i)
        {
            to_subtract+=ans[j];
            to_subtract%=MOD;
        }
        ans[i] = (ans[i] - to_subtract + MOD)%MOD;
    }
    ll finalans = 0;
    for(ll i=1; i<=k; i++)
    {
        ll temp = (ans[i]*i)%MOD;
        finalans+=temp;
        finalans%=MOD;
    }
    return finalans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    ll n,k;
    n = 3;
    cin>>k;       
    cout<<solve(n,k)<<endl;
	return 0;
}

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

int main() {
  ll n;
  ll a[5];
  cin >> n;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }

  ll mn = *min_element(a, a + 5);
  ll ans = (n + mn - 1) / mn + 4LL;

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


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;


bool isprime(long long n)
{
	if (n<=2) return true;
	
	for (long long  i = 2; i*i<=n; i++)
	{
		if (n%i == 0) return false;
		else continue;
	}
	
	return true;
}

int main()
{
	
	long long  x;
	cin >> x;
	
	while(isprime(x)!=true) x++;
	
	cout << x <<endl;
	
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)))
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
struct Q
{
	int d;
	int x;
	int co;
	Q(int x,int d,int co):x(x),d(d),co(co){};
};
int n,m,q;
int c[100005];
int dis[100005];
vector<int> E[100005];
vector<Q> qs;
/*---main code---*/
 
void DFS(int x,int d,int co)
{
//	cout<<x<<' ';
	if(d<=dis[x])
	{
		return ;
	}
	dis[x]=d;
	if(c[x]==0)
	{
		c[x]=co;
	}
	EACH(E[x],it)
	{
		int nx=*it;
		if(nx>0&&nx<=n)
		{
			DFS(nx,d-1,co);
		}
	}
}
 
int main()
{
	FIO;
	cin>>n>>m;
//	cout<<c[7]<<'\n';
	for(int i=1;i<=n;i++)
	{
		dis[i]=-1;
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	cin>>q;
	for(int i=0;i<q;i++)
	{
		int d,x,co;
		cin>>x>>d>>co;
		qs.push_back(Q(x,d,co));
	}
	for(int i=qs.size()-1;i>=0;i--)
	{
//		cout<<qs[i].x<<' '<<qs[i].d<<' '<<qs[i].co<<'\n';
		DFS(qs[i].x,qs[i].d,qs[i].co);
//		cout<<"\n\n";
	}
	for(int i=1;i<=n;i++)
	{
		cout<<c[i]<<'\n';
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;

  queue<pair<string,ll>> base;
  queue<pair<string,ll>> add;
  ll cnt=1;
  base.push(make_pair("",0));
  while(cnt<=n){
    while(!base.empty()){
      string s = base.front().FI;
      ll lim = base.front().SE;
      base.pop();

      REP(i,lim+1){
        string t=s+char('a'+i);
        if(i==lim)
          add.push(make_pair(t,lim+1));
        else
          add.push(make_pair(t,lim));
      }
    }

    swap(base, add);
    cnt++;
  }

  while(!base.empty()){
    string s = base.front().FI;
    base.pop();
    cout<<s<<endl;
  }
}



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

int a[5000];

int main()
{
	int n, i, j, s, max;

	while (cin >> n)
	{
		if (n == 0) break;

		for (i = 0; i < n; i++)
			cin >> a[i];

		max = -2147483647;
		for (i = 0; i < n; i++)
		{
			s = 0;
			for (j = i; j < n; j++)
			{
				s += a[j];
				if (s > max)
					max = s;
			}
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int D,N;
int main(){
  cin >> D >> N;
  if(N==100){
    if(D==0) cout << 101 << endl;
    else if(D==1) cout << 10100 << endl;
    else if(D==2) cout << 1010000 << endl;
  }
  else{
  if(D==0) cout << N << endl;
  else if(D==1) cout << N*100 << endl;
  else cout << N*10000 << endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int r;
    cin>>r;
    if(r<1200){
        cout<<"ABC";
    }else if(r<2800){
        cout<<"ARC";
    }else{
        cout<<"AGC";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        String s=sc.next();
      if(a>=3200){
      		System.out.println(s);
      }else{
      		System.out.println("red");
      }
    }
}

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

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

    vector<ll> a(n);
    vector<ll> cnt(100010,0);
    cnt[0]=3;
    ll ans=1;
    rep(i,n){
        cin>>a[i];
        ans=(ans*cnt[a[i]])%MOD;
        cnt[a[i]]--;
        cnt[a[i]+1]++;
    }

    cout<<ans<<endl;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }

    sort(a.begin(),a.end());
    a.push_back(0);

    int cnt=0,ans=0;
    rep(i,n){
        cnt++;
        if(a[i]!=a[i+1]){
            if(cnt-a[i]<0){
                ans+=cnt;
            }
            else {
                ans+=cnt-a[i];
            }
            cnt=0;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stack>
using namespace std;
int main() {
	int n, r;
	while (cin >> n >> r, n || r){
		stack<int> st;
		for (int i = 1; i <= n; i++)st.push(i);
		for (int i = 0; i < r; i++) {
			int p, c; cin >> p >> c;
			stack<int>st1, st2;
			for (int i = 0; i < p - 1; i++) { st1.push(st.top()); st.pop(); }
			for (int i = 0; i < c; i++) { st2.push(st.top()); st.pop(); }
			for (int i = 0; i < p - 1; i++) { st.push(st1.top()); st1.pop(); }
			for (int i = 0; i < c; i++) { st.push(st2.top()); st2.pop(); }
		}
		cout << st.top() << endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;

int main(){
	int n, q;
	cin>>n>>q;
	fenwick_tree<ll> fw(n);
	rep(i, n){
		int a; cin>>a;
		fw.add(i, a);
	}
	rep(_, q){
		int t; cin>>t;
		if(t==0){
			int p, x; cin>>p>>x;
			fw.add(p, x);
		}
		else{
			int l, r; cin>>l>>r;
			cout<<fw.sum(l, r)<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 8228
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   string s;
   cin >> s;
   int cnt1 = 0, cnt2 = 0;
   for (int i = 0; i < (int)s.length(); i++){
	   if (i % 2 == 0){
		   if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') cnt1++; 
		 }
	   else {
		   if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') cnt2++;  
		 }
	 }
	if (cnt1 + cnt2 == (int)s.length()) cout << "Yes" << endl;
	else cout << "No" << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
const int oo = 1000000000;
int n, k, v[N], dp[N];
int f(int pos) {
	if(dp[pos] != -1)
		return dp[pos];
	if (pos == (n - 1))
		return 0;
	if (pos > n)
		return oo;
	int answer = oo;
	for(int i = 1; i <= k; i++)
		answer = min(answer, f(pos + i) + abs(v[pos] - v[pos + i]));
	return dp[pos] = answer;
}
int main(){
	cin >> n >> k;
	memset(dp, -1, sizeof dp);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	cout << f(0) << "\n";
    return 0;
}


Measured memory_bytes: 12176
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
using namespace std;
int main()
{
    int n, m, k;
    string s;
    cin>>n;
    cin>>s;
    if(n>=3200)
        cout<<s<<endl;
    else
        cout<<"red"<<endl;
    return 0;
}


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

int main()
{
    int a, b;
    int cnt = 0;
    cin >> a >> b;
    for (int i = a; i <= b; i++)
    {
        int w = i % 10;
        int x = (i % 100) / 10;
        int y = (i % 10000) / 1000;
        int z = i / 10000;
        //cout << w << " " << x << " " << y << " " << z << endl;
        if (w == z && x == y)
        {

            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
def degToRad(deg)
  return deg * Math::PI/ 180.0
end

currX, currY = [0.0, 0.0]
currAngle = 0
while true
  hosuu, deg = gets().split(',').map{|i| i.to_i}
  if hosuu == 0 && deg == 0
    break
  end
  currX += hosuu * Math.cos(degToRad(currAngle))
  currY += hosuu * Math.sin(degToRad(currAngle))
  currAngle += deg
end
puts currY.to_i
puts currX.to_i

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

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

using namespace std;

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

	int min = 10000000000;
	int max = 0;

	rep(i, n)
	{
		int a;
		cin >> a;
		if ( min > a ) min = a;
		if ( max < a ) max = a;
	}

	cout << max - min << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main(){
	string str;
	getline(cin,str);
	for(int i=0;i<(int)str.size();i++){
		if('a'<=str[i] && str[i]<='z'){
			str[i]=toupper(str[i]);
		}else if('A'<=str[i] && str[i]<='Z'){
			str[i]=tolower(str[i]);
		}
	}
	cout << str << endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;


int main(){
    string s;
    cin >>s;
    ll n=s.size();
    vector<ll>co(26,0);
    for (int i = 0; i < n; ++i) {
        co[s[i]-'a']++;
    }
    bool flg=true;
    for (int i = 0; i < 26; ++i) {
        if(co[i]%2==1)flg=false;
    }
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}

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

const int N_MAX = 1e5 + 10;

typedef long long ll;

using namespace std;


int main() {
    int n;
    cin >> n;
    ll dp[N_MAX][2] = {0};
    int a[N_MAX];

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

    dp[0][0] = a[0];
    dp[0][1] = -a[0];
    for (int i=1; i<n-1; ++i) {
        dp[i][0] = max(dp[i-1][0] + a[i], dp[i-1][1] - a[i]);
        dp[i][1] = max(dp[i-1][0] - a[i], dp[i-1][1] + a[i]);
    }

    cout << max(dp[n-2][0] + a[n-1], dp[n-2][1] - a[n-1]) << endl;
}


Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(op != '?'){
        cin >> a >> op >> b;
        if(op == '+'){
            cout << a + b << endl;
        } else if(op == '-'){
            cout << a - b << endl;
        } else if(op == '*'){
            cout << a*b << endl;
        } else if(op == '/'){
            cout << a/b << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3084
check=dict()
N,z,d=0,[],0
#ttfは235、chaはabc

def dfs_sub(n,ttf,cha,d):
    global check

    #-1ずつしていく場合
    check[0]=min(check[n]+n*d,check[0])

    #最寄りまで-してく場合
    x1,x2=n//ttf,n%ttf
    if x1 in check:
        if check[x1]>check[n]+x2*d+cha:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)
    else:
        check[x1]=check[n]+x2*d+cha
        dfs(x1)

    #最寄りまで+1してく場合
    x1,x2=n//ttf+1,ttf-n%ttf
    if x1 in check:
        if check[x1]>check[n]+x2*d+cha:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)
    else:
        check[x1]=check[n]+x2*d+cha
        dfs(x1)


def dfs(n):
    global b,d
    for i,j in zip([2,3,5],b):
        dfs_sub(n,i,j,d)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    z=list(zip([2,3,5],b))
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])

    

Measured memory_bytes: 122208
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+7;
int h[N], f[N];
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &h[i]);
	}
	for(int i = 2; i <= n; i++)
	{
		f[i] = 2e9;
		for(int j = 1; j <= k; j++)
		{
			if(i-j>0)
			{
				f[i] = min(f[i], f[i-j]+abs(h[i]-h[i-j]));
			}
		}
	}
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 1024
A,B,X = gets.split.map(&:to_f)

BASE = (A * B) / 2
S = X / A

x, y = nil, nil

if S < BASE
    x = S * 2 / B
    y = B
else
    x = A
    y = (A * B - S) * 2 / A
end

puts Math.atan2(y,x) * 180 / Math::PI

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){

  string s; cin >> s;
  if(s[2] == s[3] && s[4] == s[5]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    W = input() 
    if W == "AC":
        AC += 1
    elif W == "WA":
        WA += 1
    elif W == "TLE":
        TLE += 1
    elif W == "RE":
        RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

Measured memory_bytes: 9208
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N / i != i)
                res.push_back(N / i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

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

    ll N;
    cin >> N;
    vector<ll> en = enum_divisors(N);
    ll sum = 0;
    rep(i, en.size()) {
        ll m = en[i] - 1;
        if (m == 0)
            continue;
        if (N / m == N % m)
            sum += m;
    }

    cout << sum << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
ll x;cin>>x;
ll n=100;
int count=0;
while(n<x){
    n=n+n*0.01;
    count++;
}
cout<<count<<endl;
}

Measured memory_bytes: 3600
use std::io::*;
use std::str::*;

fn scan_token<T: FromStr>() -> T {
    stdin().bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
        .parse::<T>().ok().unwrap()
}

fn scan_line<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map( |token| token.parse::<T>().ok().unwrap() ).collect()
}

fn count_divisor(x: i32) -> i32 {
    let mut count = 0;
    for d in 1..x+1 {
        if x % d == 0 {
            count += 1;
        }
    }
    count
}

fn main() {
    let n: i32 = scan_token();

    let mut ans = 0;

    for x in 1..n+1 {
        if x % 2 == 1 && count_divisor(x) == 8 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int N = 3005;

string s;
int n;
double p[N];
double dp[N][N];
bool memo[N][N];

int main () {
  cin >> n;
  double result;
  result = n % 2 ? (n+1) / 2.0 / n : 0.5;
  pd(result);br();
}


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

const int mod=int(1e9)+7;

int fact(int n){
  if(n==0)return 1;
  return ((long)n*(long)fact(n-1))%mod;
}

int pow(int n, int i){
  if(i==0)return 1;
  long s = pow(n, i/2);
  if(i%2==0){
    return (s*s)%mod;
  }
  else {
    return (((s*s)%mod)*(long)n)%mod;
  }
}

int comb(int n, int r){
  if(r<0 || r>n)return 0;
  long nf=fact(n), rf=fact(r), rnf=fact(n-r);
  return (((nf*pow(rf, mod-2))%mod)*pow(rnf, mod-2))%mod;
}

int main(){
  int x, y;
  cin >> x >> y;
  if((x+y)%3!=0){
    cout << 0;
    return 0;
  }
  int n=(x+y)/3;
  cout << comb(n, x-n);
  return 0;
}


Measured memory_bytes: 10752
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] s = new int [N];
        int sum = 0;
        for(int i=0; i<N; i++){
            s[i] = sc.nextInt();
            sum+=s[i];
        }
        System.out.println(function(N,s,sum));
    }
    static int function(int N, int [] s, int sum){
        if(sum%10!=0) return sum;
        boolean [] boo = new boolean [sum+1];
        boo[0] = true;
        for(int i=0; i<N; i++){
            for(int j=sum; j>=0; j--){
                if(boo[j]){
                    boo[j+s[i]] = true;
                }
            }
        }
        for(int j=sum; j>=0; j--){
            if(boo[j]&&j%10!=0){
                return j;
            }
        }
        return 0;
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    vector<int> dp(n,1000);
    int ans=1000;
    for(int i=0;i<n;i++)
    {
        if(i!=0)
        dp[i]=dp[i-1];
        for(int j=i-1;j>=0;j--)
        {
            int num=dp[j]/a[j];
            int rem=dp[j]%a[j];
            //cout<<num<<endl;
            dp[i]=max(dp[i],num*a[i]+rem);
        }
       // cout<<dp[i]<<endl;
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3612
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int[] arr = new int[] {3, 5, 7};

      System.out.println(dfs(0, arr, N));
  }

  private static int dfs(long curNum, int[] arr, int N) {
    if(curNum > N)
      return 0;

    int res = check(curNum, arr) ? 1 : 0;
    for(int a : arr) {
      res += dfs(curNum * 10 + a, arr, N);
    }
    return res;
  }

  private static boolean check(long curNum, int[] arr) {
    boolean[] flags = new boolean[10];
    while(curNum > 0) {
      flags[(int)(curNum % 10)] = true;
      curNum /= 10;
    }
    return flags[3] && flags[5] && flags[7];
  }
}

Measured memory_bytes: 24148
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>

const int MaxFact = pow(10, 9);

struct Card{
    char suit;
    int value;
};
int partition(Card A[], int p, int r){
    int x = A[r].value;
    Card t;
    int i = p-1;
    for(int j=p; j<r; j++){
        if(A[j].value <= x){
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i+1;
}
void quicksort(Card A[], int p, int n){
    if(p < n){
        int keyindex = partition(A, p, n-1);
        quicksort(A, p, keyindex);
        quicksort(A, keyindex+1, n);
    }
}
void merge(Card A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    Card L[n1 + 1], R[n2 + 1];
    for(int i=0; i<n1; i++){
        L[i] = A[left + i];
    }
    for(int i=0; i<n2; i++){
        R[i] = A[mid + i];
    }
    L[n1].value = MaxFact;
    R[n2].value = MaxFact;
    int l=0, r=0;
    for(int i=left; i<right; i++){
        if(L[l].value <= R[r].value){
            A[i] = L[l];
            l++;
        } else {
            A[i] = R[r];
            r++;
        }
    }
}
void mergesort(Card A[], int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergesort(A, left, mid);
        mergesort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n, v;
    char str[2];
    scanf("%d", &n);
    Card A[n], B[n];
    for(int i=0; i<n; i++){
        scanf("%s %d", str, &v);
        A[i].suit = B[i].suit = str[0];
        A[i].value = B[i].value = v;
    }
    mergesort(B, 0, n);
    quicksort(A, 0, n);

    int stable = 1;
    for(int i=0; i<n; i++){
        if(A[i].suit != B[i].suit){
            stable = 0;
        }
    }
    if(stable){printf("Stable\n");}
    else {printf("Not stable\n");}

    for(int i=0; i<n; i++){
        printf("%c %d\n", A[i].suit, A[i].value);
    }

    
    return 0;
}


Measured memory_bytes: 5528
s = list(input())
# s = list(str(10**200000))
n = len(s)
ans = 0
s.reverse()
# print(s)
x = 1
tot = 0
count = [0]*2019
for i in range(n):
    count[tot]+=1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    ans += count[tot]
    x = x*10%2019
print(ans)

Measured memory_bytes: 10424
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int answer = A + B;
        answer = Math.max(answer,A - B);
        answer = Math.max(answer,A * B);
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
import _heapq
inf=float("inf")


def prim():
    color=["white" for _ in range(v)]
    D=[inf for _ in range(v)]
    M=[[] for _ in range(v)]

    for s,t,w in STW:
        M[s].append([w,t])
        M[t].append([w,s])

    queue=[[0,0]]
    _heapq.heapify(queue)
    color[0]="gray"
    D[0]=0

    while len(queue)>0:
        num=_heapq.heappop(queue)[1]
        if color[num]=="black":continue
        color[num]="black"

        for i,j in M[num]:
            if i<D[j] and color[j]!="black":
                color[j]="gray"
                D[j]=i
                _heapq.heappush(queue,[i,j])

    return D


v,e=map(int,input().split())
STW=[list(map(int,input().split())) for _ in range(e)]
print(sum(prim()))


Measured memory_bytes: 48308
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
typedef long long ll;
int n, k;
int main() {
  cin >> n >> k;
  vector<ll> ar(n);
  for (int i = 0; i < n; i++) cin >> ar[i];
  ll sum = 0;
  for (int ambil = 0; ambil <= min(n, k); ambil++) {
    int balik = k-ambil;
    for (int kiri = 0; kiri <= ambil; kiri++) {
      int kanan = ambil-kiri;
      priority_queue<ll, vector<ll>, greater<ll>> pq;
      ll tmp = 0;
      for (int i = 0; i < kiri; i++) {
        tmp += ar[i];
        pq.push(ar[i]);
      }
      for (int i = 0; i < kanan; i++) {
        tmp += ar[n-1-i];
        pq.push(ar[n-1-i]);
      }
      for (int i = 0; i < balik; i++) {
        if (pq.empty()) break;
        if (pq.top() > 0) break;
        tmp -= pq.top();
        pq.pop();
      }
      sum = max(sum, tmp);
    }
  }
  cout << sum << el;
  return 0;
}

Measured memory_bytes: 256
def solve():
    
    INF = 10 ** 12
    
    N, W = map(int, input().split())
    
    items =[] * N
    
    for i in range(N):
        v, w = map(int, input().split())
        items.append([v,w])
    
    dp = [[INF for i in range(W+1)] for j in range(N+1)]
    
    for i in range(W+1):
        dp[0][i] = 0
    
    for i in range(N+1):
        dp[i][0] = 0
    
    for i in range(1,N+1): #1<= i <= N
        for j in range(1, W+1): # 1 <= j <= W
            if j - items[i-1][1] >= 0:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j - items[i-1][1]] + items[i-1][0], dp[i][j - items[i-1][1]] + items[i-1][0])
            else:
                dp[i][j] = dp[i-1][j]
    
    print(dp[N][W])

if __name__ == '__main__':
    solve()

Measured memory_bytes: 18304
import java.io.*;
import java.util.*;
 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      //begin
      int n = sc.nextInt();
      int a = sc.nextInt();
      int b = sc.nextInt();
      out.println(Math.min(n * a, b));
      //end
      out.close();
   }
 
   public static PrintWriter out;
      
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
      long nextLong() {
          return Long.parseLong(next());
      }
      double nextDouble() {
          return Double.parseDouble(next());
      }
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;
constexpr ll mm=1e18;

int main()
{
    ll ans=1;
    int n;
    cin>>n;
    vector<ll> a(n);
    bool zeroflag=false;
    rep(i,n)
    {
        cin>>a[i];
        if(a[i]==0)zeroflag=true;
    }
    if(zeroflag)
    {
        cout<<0;
        return 0;
    }
    rep(i,n)
    {
        if(a[i]<=mm/ans)
        {
            ans*=a[i];
        }
        else
        {
            cout<<-1;
            return 0;
        }
        
    }
    cout<<ans;
}


Measured memory_bytes: 4044
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int O = S.length()-1;
        int ans = 1;
        char[] C = S.toCharArray();
        if (O% 2 == 1) {
            O = O - 1;
            ans++;
        }
        lavel:for (int i = 0;;i=i+2) {
            for (int j = 0; j < (O-i) / 2; j++) {
                if (C[j] == C[(O-i) / 2 + j]){} else {
                    ans=ans+2;
                    continue lavel;
                }
            }
            break;
        }
        System.out.println(S.length()-ans);
    }
}

Measured memory_bytes: 21972
from itertools import accumulate


def solve(condition):
    sub, add = 0, 0
    for i in range(N):
        cur = acc[i] + add - sub
        if i % 2 == condition:
            if cur > 0:
                continue
            add += 1 - cur
        else:
            if cur < 0:
                continue
            sub += cur + 1
    return sub + add


N, *A = map(int, open(0).read().split())
acc = list(accumulate(A))
ans = min(solve(0), solve(1))
print(ans)


Measured memory_bytes: 20160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
typedef long long ll;

void ans(bool qus)
{
    if (qus == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool qust)
{
    if (qust == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

/////////////////////////////////////////

int main(){
    int a,b;
    cin >> a >> b;
    if((a+b)%2==0){
        cout << (a + b) / 2 << endl;
    }
    else
    {
        cout << (a + b) / 2 + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    string s; cin>>s;
    int n=s.size();
    string ans;
    if(s[0]==s[n-1]){
        ans=((n-1)%2?"First":"Second");
    }else{
        ans=((n-1)%2?"Second":"First");
    }
    cout<<ans<<endl;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,X;

ll hoge(ll a,ll b) {
	if(a<b) swap(a,b);
	
	if(a%b==0) return b*(2*(a/b)-1);
	else return b*(2*(a/b)) + hoge(b,a%b);
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>X;
	cout<<N+hoge(X,N-X)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

using namespace std;

int main()
{
    int n, r;
    while (cin >> n >> r, n | r)
    {
        vector<int> deck(n);
        for (int i = 1; i <= n; ++i)
        {
            deck[n - i] = i;
        }
        for (int i = 0; i < r; ++i)
        {
            int p, c;
            cin >> p >> c;

            vector<int> buf(deck.begin(), deck.begin() + p - 1);
            copy(deck.begin() + p - 1, (deck.begin() + p - 1) + c, deck.begin());
            copy(buf.begin(), buf.end(), deck.begin() + c);
        }
        cout << deck[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
//等号、不等号は甘え
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(!(a-b)) {
		printf("a == b\n");
		return 0;
	}
	if((a-b)>>31) {
		printf("a < b\n");
	} else {
		printf("a > b\n");
	}
	return 0;
}

Measured memory_bytes: 580