akhauriyash/Code-Regression huggingface dataset:
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int a[100010];
int b[100010];
int c[100010];
int dp[100010][5];
int main(){
//  cout<<fixed<<setprecision(1)<<1<<endl;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			dp[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			dp[i][j]=0;
		}
	}
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			if(j==0){
				dp[i][j]=max(dp[i][j],max(dp[i-1][1],dp[i-1][2])+a[i]);
			}
			if(j==1){
				dp[i][j]=max(dp[i][j],max(dp[i-1][0],dp[i-1][2])+b[i]);
			}
			if(j==2){
				dp[i][j]=max(dp[i][j],max(dp[i-1][0],dp[i-1][1])+c[i]);
			}
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	return 0;
}

Measured memory_bytes: 6728
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}//continue break
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<pii> vpii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int x;cin>>x;
        if(x>=30){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3656
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    l_i, r_i = map(int, input().split())
    print(t[r_i-1] - t[l_i-1])

Measured memory_bytes: 7748
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int X, Y; cin >> X >> Y;
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            if (i + j == X && 2 * i + 4 * j == Y) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for(int i=0;i<s.length();++i) {
        if(s[i] != t[i]) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3796
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(){
    int N, M;
    cin >> N >> M;
    ull K;
    cin >> K;
    vector<ull> A(N), B(M);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < M; i++) cin >> B[i];
    vector<ull> Asum(N+1), Bsum(M+1);
    Asum[0] = 0;
    Bsum[0] = 0;
    for(int i = 1; i < N + 1; i++){
        Asum[i] = Asum[i - 1] + A[i -1];
    }
    for(int i = 1; i < M+ 1; i++){
        Bsum[i] = Bsum[i - 1] + B[i - 1];
    }
    // for(ull a : Asum) cout << a << endl;
    // for(ull b : Bsum) cout << b << endl;
    int j = M;
    int max_c = 0;
    for(int i = 0; i < N+1; i++){
        if(Asum[i] > K) break;
        for(; j >= 0; j--){
            if(Asum[i] + Bsum[j] > K) continue;
            max_c = max(i + j, max_c);
            break;
        }
    }
    cout << max_c << endl;
}

Measured memory_bytes: 9612
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	if (x%y == 0)cout << -1 << endl;
	else cout << x << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        public static readonly long Mod = (long)Math.Pow(10, 9) + 7;
        static void Main()
        {
            var nm = ReadLongArray();
            var n = nm[0];
            var m = nm[1];
            var x = ReadLongArray();
            var y = ReadLongArray();

            long sumX = 0;
            for (int i = 0; i < x.Length - 1; i++)
            {
                sumX = (sumX + (x[i + 1] - x[i]) * (n - 1 - i) * (i + 1)) % Mod;
            }
            long sumY = 0;
            for (int i = 0; i < y.Length - 1; i++)
            {
                sumY = (sumY + (y[i + 1] - y[i]) * (m - 1 - i) * (i + 1)) % Mod;
            }

            Console.WriteLine($"{sumX * sumY % Mod}");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 31452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, C;
    cin >> N >> C;
    VVL D(C, VL(C)), c(N, VL(N));
    rep(i, 0, C){
        rep(j, 0, C) cin >> D[i][j];
    }

    VVL acc(3, VL(C, 0));
    rep(i, 0, N){
        rep(j, 0, N){
            cin >> c[i][j];
            c[i][j]--;
            acc[(i+j+2)%3][c[i][j]]++;
        }
    }

    ll ans = 1e18;
    rep(i, 0, C){
        ll s1 = 0;
        rep(l, 0, acc[0].size()){
            s1 += acc[0][l] * D[l][i];
        }
        rep(j, 0, C){
            if(i == j) continue;
            ll s2 = 0;
            rep(l, 0, acc[1].size()){
                s2 += acc[1][l] * D[l][j];
            }
            rep(k, 0, C){
                if(i == k || j == k) continue;
                ll s3 = 0;
                rep(l, 0, acc[2].size()){
                    s3 += acc[2][l] * D[l][k];
                }
                ans = min(ans, s1+s2+s3);
            }  
        }
    }

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

Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    vector<string> abc(3);
    rep(i, 3) cin >> abc[i];

    int next = 0;
    while (1) {
        int num = abc[next][0];

        abc[next].erase(abc[next].begin() + 0);
        if (num == 'a') next = 0;
        if (num == 'b') next = 1;
        if (num == 'c') next = 2;
        if (abc[next].size() == 0) break;

    }

    if (next == 0) cout << 'A' << endl;
    if (next == 1) cout << 'B' << endl;
    if (next == 2) cout << 'C' << endl;

    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3576
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=0; cin>>n;
    vector<ll> a(n,0);
    rep(i,n) cin>>a[i];
    rep(i,n-1){
        if(a[i+1]<a[i]){
            ans+=a[i]-a[i+1];
            a[i+1]=a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> arr;
typedef vector<arr> matrix;
typedef vector<ll> longarr;
typedef vector<longarr> longmat;
typedef map<int, arr> graph;
typedef vector<char> chararr;
typedef vector<chararr> charmat;
typedef pair<int, int> fraction;
ll MOD = 1000000007;
int n, k;
ll a[100];
ll dp[101][100001];

ll fun() {
	for (int i = 0; i <= n; ++i) {
		dp[i][0] = 1;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= k; ++j) {
			dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]);
			if (a[i - 1] < j) dp[i][j] = (MOD + dp[i][j] - dp[i - 1][j - a[i - 1] - 1]) % MOD;
			else dp[i][j] = (dp[i][j] ) % MOD;
		}
	}
	return dp[n][k];
}
int main() {

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

}

Measured memory_bytes: 82544
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node a);
Node treeMaximum(Node a);
Node treeSearch(Node u, int k);
Node treeSuccessor(Node a);
void treeDelete(Node a);
void insert(int k);
void inorder(Node u);
void preorder(Node u);
int main(){
       int n,i,x;
       char com[20];
       scanf("%d",&n);
       
       for(i = 0 ; i<n; i++){
	 scanf("%s",com);
	 
	 if(com[0] == 'f'){
	 scanf("%d",&x);
	 Node t = treeSearch(root,x);
	 if(t!=NIL)printf("yes\n");
	 else{
	   printf("no\n");
       }
	 
       }
       else if(com[0] == 'i'){
	 scanf("%d",&x);
	 insert(x);
       }
       else if(com[0] == 'p'){
	 inorder(root);
	 printf("\n");
	 preorder(root);
	 printf("\n");
	 
       }
       else if(com[0] == 'd'){
	 scanf("%d",&x);
	 treeDelete(treeSearch(root,x));
       }
     }
     return 0;
   }



Node treeMinimum(Node a){
  while(a->left!=NIL){
    a = a->left;
  }
  return a;
}

Node treeMaximum(Node a){
  while(a->right!=NIL){
    a = a->right;
  }
  return a;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k != u->key){
    if(k < u->key)u= u->left;
    else{
      u=u->right;
    }
  }
    return u;
  }


Node treeSuccessor(Node a){
  if(a->right != NIL) return treeMinimum(a->right);
  Node y;
  y = a->p;
  while(y != NIL && a == y->right){
    a = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Node a){
  Node y;
  Node x;
  if(a->left ==NIL || a->right==NIL)y=a;
  else{
    y = treeSuccessor(a);
  }
  if(y->left!=NIL)x = y->left;
  else {
    x = y->right;
  }

    if(x != NIL)x->p = y->p;
  if(y->p == NIL)root = x;
  else if(y==y->p->left) y->p->left = x;
  else{
    y->p->right = x;
  }
  if(y!=a)a->key = y->key;
}


 void insert(int k){
   Node y = NIL;
   Node x = root;
   Node z;

   z = malloc(sizeof(struct node));
   z ->key = k;
   z ->left = NIL;
   z ->right = NIL;

   while(x!= NIL){
     y= x;
     if(z->key < x->key) x= x->left;
   else{
     x = x->right;
 }
   }
     z->p = y;

     if(y == NIL) root =z;
     else if(z->key < y->key) y->left = z;
     else {
       y ->right =z;
     }
 }


 void inorder(Node u){
   if(u != NIL){
     inorder(u->left);
     printf(" %d", u->key);
     inorder(u->right);
   }
   else{
     return;
   }
 }

   void preorder(Node u){
     if(u!=NIL){
       printf(" %d",u->key);
       preorder(u->left);
       preorder(u->right);
     }
     else{
       return;
     }
   }



Measured memory_bytes: 25156
#include<iostream>
#include<math.h>
using namespace std;
int main() {
	int N,high;
	double v, y;
	while (cin >> v) {
		N = 1;
		high = 0;
		y = pow(v,2) / 19.6;
		while (high < y) {
			N += 1;
			high += 5;
		}
		cout << N << endl;
	}
	return 0;
}

Measured memory_bytes: 3024
N = int(raw_input())
sum = int(0)
maxv = 0
dict = {sum : int(-1)}

for i in range(N):
    val = int(raw_input())
    sum += val
    
    if dict.get(sum, int(-2)) != -2 :
        maxv = max(maxv, i - dict[sum])
    else :
        dict[sum] = i

print maxv

Measured memory_bytes: 35048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int SZ = 1000005;
int np[SZ];
vector<pair<ll,int>> v;
void myprime(ll n){
	for(ll i=2;i<SZ;i++){
		if(np[i]==1) continue;
		int aa = 0;
		while(n%i==0){
			n/=i;
			aa++;
		}
		if(aa!=0) v.push_back(make_pair(i,aa));
		for(ll j=2*i;j*j<SZ;j+=i){
			np[j]=1;
		}
	}
	if(n!=1) v.push_back(make_pair(n,1));
}
ll mypow(ll a, ll b){
	ll aa = 1;
	while(b){
		if(b%2==1) aa*=a;
		a=a*a;
		b/=2;
	}
	return aa;
}
int main(void){
	ll n,p; scanf("%lld %lld",&n,&p);
	myprime(p);
	ll ans = 1;
	int l = v.size();
	for(int i=0;i<l;i++){
		if(v[i].second>=n) ans*=mypow(v[i].first,v[i].second/n);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define DEBUG_DC(x) cout << #x << ": " << x << endl
#define INF 1e4+1

using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


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

	vector<int> w((int)n);
	vector<ll> v((int)n);

	FOR(i, 0, n)
	{
		cin >> w[i];
		cin >> v[i];
	}

	vector< vector<ll> > dp((int)n + 1, vector<ll>((int)wsum_max+1, 0));
	FOR(i, 1, dp.size())
	{
		FORE(wsum, 0, wsum_max)
		{
			if (wsum >= w[i - 1]) chmax(dp[i][wsum], dp[i - 1][wsum - w[i - 1]] + v[i - 1]);
			chmax(dp[i][wsum], dp[i - 1][wsum]);
		}
	}

	cout << dp[n][wsum_max] << endl;
	return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string S;  cin >> S;
  int N = (int) S.size();
  
  for(int k = N; k >= N/2; k--){
    bool flag = true;
    if( N-k > k-1){ continue;}
    for(int j = N-k; j < k-1; j++){
      if(S[j] != S[j+1]){ flag = false; break;}}
    if(flag){ cout << k << endl; return 0;}
  }
  cout << N/2 << endl; return 0;}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll n;
ll a[5];

int main(){
  cin>>n;
  REP(i,5)cin>>a[i];
  ll v = *min_element(a,a+5);
  ll t = (n+v-1)/v;
  cout<<(t+4)<<endl;
  return 0;
}


Measured memory_bytes: 256
//インクルード(アルファベット順)
#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>//可変長配列
#include<valarray>//なんとなく追加

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define pause system("pause")


signed main() {
	int N,count=0,frag=0;
	cin >> N;
	vector<int> A(N);
	REP(i, N) {
		cin >> A.at(i);
	}
	while (frag == 0) {
		REP(i, N) {
			if (A.at(i) % 2 != 0) {
				frag = 1;
			}
			else A.at(i) = A.at(i) / 2;
		}
		count += 1;
	}
	cout << count - 1 << endl;
	pause;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
const int inf=0x3f3f3f3f;

string str;

bool chk(int l,int r){
	while(l<=r){
		if(str[l]!=str[r]) return 0;
		l++; r--;
	}
	return true;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>str;
    int N=str.size();
    if(chk(0,N-1)&&chk(0,(N-1)/2-1)&&chk((N+3)/2-1,N-1)) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;

int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s[k-1] = tolower(s[k-1]);
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int head=0;
int stack[1000];

void push(int n){
  stack[++head]=n;
}

int pop(void){
  head--;
  return stack[head+1];
}

void calc(char op){
  int n1=pop(), n2=pop();
  if(op=='+') push(n1+n2);
  if(op=='-') push(n2-n1);
  if(op=='*') push(n2*n1);
}

int main(void){
  char a[1000];
  int t,s;
    while(scanf("%s",a)!=EOF){
      if(a[0]=='+' || a[0]=='-' || a[0]=='*') calc(a[0]);
      else push(atoi(a));
    }
  printf("%d\n",pop());
  return 0;
}

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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int blue = 0, red = 0;
  for (int i = 0; i < (int)S.size(); i++) {
    if (S[i] == '0')
      red++;
    else if (S[i] == '1')
      blue++;
  }
  cout << 2 * min(red, blue) << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int i, j, n, m;

int main()
{
    sf("%d%d", &n, &m);
    string a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = -1; i <= n; i++) {
        for (j = -1; j <= m; j++) {
            if (i == -1 || i == n) pf("#");
            else if (j == -1 || j == m) pf("#");
            else pf("%c", a[i][j]);
        }
        pf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
C = input()

cntR = C.count('R')
cntW = C.count('W')
if cntR == 0 or cntW == 0:
    print(0)
else:
    T = 'R' * cntR + 'W' * cntW
    ans = sum([1 for a, b in zip(C, T) if a != b]) // 2
    print(ans)
    


Measured memory_bytes: 11108
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    int N;
    std::cin >> N;

    std::vector<std::string> v;
    REP(i, N){
        std::string s;
        std::cin >> s;
        v.push_back(s);
    }
    
    std::string a[4];
    REP(i, 3){
        a[i] = "99999999";
    }

    REP(i, N){
        REP(j, N){
            if(i == j){continue;}

            std::string s = v[i] + v[j];
            for(int k=2;k>=0;k--){
                if(s.size() < a[k].size() || (s.size() == a[k].size() && s < a[k])){
                    a[k+1] = a[k];
                    a[k] = s;
                }else{
                    break;
                }
            }
        }
    }

    std::cout << a[2] << std::endl;
}

Measured memory_bytes: 1532
#include<stdio.h>
#include<string.h>
int main (void){
  char rowCol[100000][50];/*行列*/
  int numRow,numCol;
  int i,j,k,l;
  int rowColNum[100000][51]={0};/*注意)50→51だった。*/
  
  if(scanf("%d %d\n",&numRow,&numCol));
  
  for(i=0;i<numRow;i++){
      if(scanf("%s\n",rowCol[i])); 
  }
  

  for(i=0;i<numRow;i++){
    for(j=0;j<numCol;j++){      
   
      if(strncmp("#",&rowCol[i][j],1)==0){
         rowColNum[i][j] = 9;
         for(k=i-1;k<=i+1;k++){
           for(l=j-1;l<=j+1;l++){ 
             if(k==i&&l==j || rowColNum[k][l]==9){
               continue;
             }
             rowColNum[k][l] += 1;
      	   }
         }
      }
         
    }    
  }
  
  for(i=0;i<numRow;i++){
    for(j=0;j<numCol;j++){
      if(rowColNum[i][j]==9){
        printf("#");
        continue;
      
      }
      else{
        printf("%d",rowColNum[i][j]);
      }
     
    }
    printf("\n");
  }
  
  //for(i=0;i<numRow;i++){
      //printf("i=%d row[i]=%s\n",i,rowCol[i]);/*(注意)star型の時は、&をつけ出力*/
  //}
    
  return 0;
}

Measured memory_bytes: 22016
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m && n) {
    int t[n], h[m], a = 101, b = 101;
    double sum = 0, sum1 = 0, sum2 = 0;
    rep(i, n) {
      cin >> t[i];
      sum1 += t[i];
    }
    rep(i, m) {
      cin >> h[i];
      sum2 += h[i];
    }
    sum = (sum1 + sum2) / 2;
    rep(i, n){rep(j, m){
        if (sum - (sum1 - t[i] + h[j]) == 0 && t[i] + h[j] < a + b){a = t[i];
    b = h[j];
  }
}
}
(a > 100) ? cout << -1 << endl : cout << a << ' ' << b << endl;
}
return 0;
}



Measured memory_bytes: 3084
x=range(int(input()))
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
_=0
P+=[P[0]]
for j in x:
    k = j+1
    _+=P[j][0]*P[k][1]-P[j][1]*P[k][0]
print(_*0.5)

Measured memory_bytes: 7732
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589

signed main() {
    quickie 
    int n ;
    cin >> n ;
    db s = 0 ;
    rep(i, 0, n) {
        db a, b ;
        cin >> a ;
        b = 1/a ;
        s += b ;
    }
    db ans = 1 ;
    ans /= s ;
    cout << ans << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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

Measured memory_bytes: 256
// ABC134E
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> p(M);
    vector<string> S(M);
    map<ll, string> acs;
    map<ll, ll> penas;
    ll penacount = 0;
    ll account = 0;
    for (ll i = 0; i < M; i++)
    {
        cin >> p.at(i) >> S.at(i);
        if (S.at(i) == "WA")
        {
            if (acs[p.at(i)] != "AC")
            {
                if (penas[p.at(i)] == (ll)NULL)
                {
                    penas[p.at(i)] = 0;
                }
                penas[p.at(i)] += 1;
            }
        }
        else
        {
            if (acs[p.at(i)] != "AC")
            {
                acs[p.at(i)] = "AC";
                if (penas[p.at(i)] != (ll)NULL)
                {
                    penacount += penas[p.at(i)];
                }
                account++;
            }
        }
    }

    cout << account << " " << penacount << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


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

int main()
{
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  for (auto &e : a)
    cin >> e;
  sort(begin(a), end(a));
  int sum = accumulate(a.begin(), a.end(), 0);
  sum -= a[t - 1];
  if (a[t - 1] - sum < 2)
    cout << 0 << endl;
  else
    cout << a[t - 1] - sum - 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, t, a[100005], bf[100005], ans;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> t;
    rep(i, 0, n) cin >> a[i];
    int min_val = INF;
    rep(i, 0, n) {
        if (min_val > a[i]) min_val = a[i];
        bf[i] = a[i] - min_val;
    }
    int max_val = *max_element(bf, bf+n);
    rep(i, 0, n) {
        if (bf[i] == max_val) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
s = raw_input()
ans = ""
for i in range(len(s)):
    if('A' <= s[i] and s[i] <= 'Z'):
        ans += s[i].lower()
    elif('a' <= s[i] and s[i] <= 'z'):
        ans += s[i].upper()
    else:
        ans += s[i]
print(ans)

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

const ll inf = 1e18;

int main(){
    int n, W;
    while(cin>>n>>W){
        vi wt(n), val(n);
        forn(i,n)
            cin>>wt[i]>>val[i];

        // vl dp(W+1);
        // fore(i,1,n+1){
        //     for(int w=W; w>=1; w--){
        //         if(w-wt[i-1]>=0)
        //             max_self(dp[w], dp[w-wt[i-1]] + val[i-1]);
        //     }
        // }

        // vl dp(W+1);
        // fore(i,1,n+1){
        //     for(int wt_already = W - wt[i-1]; wt_already>=0; --wt_already)
        //         max_self(dp[wt_already+wt[i-1]], dp[wt_already] + val[i-1]);
        // }

        ll val_sum = accumulate(all(val), (ll)0);

        vl dp(val_sum + 1, inf); // minimum wt that could be obtained for a val v
        dp[0] = 0;
        forn(i,n){
            for(int val_already = val_sum - val[i]; val_already>=0; --val_already)
                min_self(dp[val_already + val[i]], dp[val_already] + wt[i]);
        }

        // print(dp);
        ll ans = 0;
        // Find the max val where wt is in limit
        forn(i,val_sum+1)
            if(dp[i]<=W)
                max_self(ans, i);

        cout<<ans<<endl;        

    }
    return 0;
}

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

const int MAX_N = 2005, INF = 1e9 + 7;
int B[MAX_N], W[MAX_N], dp[MAX_N][MAX_N], BB[2*MAX_N][MAX_N], WW[2*MAX_N][MAX_N];
int costB[MAX_N][MAX_N], costW[MAX_N][MAX_N];

int main(){
    int N; cin >> N;
    for(int i=1;i<=2*N;i++){
        char c; int a; cin >> c >> a;
        if(c=='B'){B[a] = i; BB[i+1][a+1]++;}
        else{W[a] = i; WW[i+1][a+1]++;}
    }

    for(int i=1;i<=2*N+1;i++){
        for(int j=1;j<=N;j++){BB[i][j+1] += BB[i][j]; WW[i][j+1] += WW[i][j];}
    }

    for(int i=1;i<=2*N;i++){
        for(int j=1;j<=N+1;j++){BB[i+1][j] += BB[i][j]; WW[i+1][j] += WW[i][j];}
    }

    for(int j=0;j<=N;j++)
        for(int i=1;i<=N;i++) costB[i][j] = BB[B[i]][N+1] - BB[B[i]][i] + WW[B[i]][N+1] - WW[B[i]][j+1];
    for(int i=0;i<=N;i++)
        for(int j=1;j<=N;j++) costW[i][j] = BB[W[j]][N+1] - BB[W[j]][i+1] + WW[W[j]][N+1] - WW[W[j]][j];
        
    for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) dp[i][j] = INF;
    dp[0][0] = 0;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            if(0<i) dp[i][j] = dp[i-1][j] + costB[i][j];
            if(0<j) dp[i][j] = min(dp[i][j], dp[i][j-1] + costW[i][j]);
        }
    }

    cout << dp[N][N] << endl;
    return 0;
}

Measured memory_bytes: 110208
int _a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k;

int parse(char *p){
  switch(*p){
    case 'F': return 0;
    case 'T': return 1;
    case 'a': return _a;
    case 'b': return _b;
    case 'c': return _c;
    case 'd': return _d;
    case 'e': return _e;
    case 'f': return _f;
    case 'g': return _g;
    case 'h': return _h;
    case 'i': return _i;
    case 'j': return _j;
    case 'k': return _k;
    case '-': return !parse(p+1);
    case '(': {
                int x=0;
                p++;
                char *q=p;
                for(;;p++){
                  if(*p=='(')x++;
                  if(*p==')')x--;
                  if(x==0&&(*p!='-'||p[1]=='>'))break;
                }
                p++;
                switch(*p){
                  case '*': return parse(q)&parse(p+1);
                  case '+': return parse(q)|parse(p+1);
                  case '-': return !parse(q)|parse(p+2);
                }
              }
  }
}

int main(){
  char p[1001],*q;
  while(1){
    scanf("%s",p);
    if(*p=='#')return 0;
	q=strchr(p,'=')+1;
    for(_a=0;_a<2;_a++)
      for(_b=0;_b<2;_b++)
        for(_c=0;_c<2;_c++)
          for(_d=0;_d<2;_d++)
            for(_e=0;_e<2;_e++)
              for(_f=0;_f<2;_f++)
                for(_g=0;_g<2;_g++)
                  for(_h=0;_h<2;_h++)
                    for(_i=0;_i<2;_i++)
                      for(_j=0;_j<2;_j++)
                        for(_k=0;_k<2;_k++)
                          if(parse(p)!=parse(q))goto fail;
    puts("YES");continue;
	fail:puts("NO");
  }
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int solve(int n, vector<pair<int, int>> a) {
    vector<int> dp(n+1, 0);
    for(int j = 0; j <= n; ++j) {
        for(auto p : a) {
            int buy, sell;
            tie(buy, sell) = p;
            if(j-buy >= 0)
                dp[j] = max(dp[j], dp[j-buy]+sell-buy);
        }
    }
    return dp[n] + n;
}

int32_t main() {

    int n, ga, gb, sa, sb, ba, bb; cin >> n >> ga >> sa >> ba >> gb >> sb >> bb;

    vector<pair<int, int>> a = {{ga, gb}, {sa, sb}, {ba, bb}};
    int num = solve(n, a);
    for(pair<int, int>& p : a) {
        int temp = p.first;
        p.first = p.second;
        p.second = temp;
    }
    int ans = solve(num, a);

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


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

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

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

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

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

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

void debug_out() { cerr << endl; }

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

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

const int N = 100010;
pair<int, int> drink[N];

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &drink[i].first, &drink[i].second);
  }
  sort(drink, drink + n);

  long long ans = 0;
  for (int i = 0; i < n && m; ++i) {
    ans += (long long) drink[i].first * min(m, drink[i].second);
    m -= min(m, drink[i].second);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1024
P = 10**9 + 7

def comb(a, b)
  b = a - b if (a - b < b)
  # 今回は b <= a < P なので 0割りエラーは起きないはず
  (fac(a, b) * recip(fac(b, b))) % P
end

def fac(a, b)
  (a-b+1 .. a).reduce(1) do |r, i| (r * i) % P  end
end

def e_gcd(n, m, x = 0, last_x = 1, y = 1, last_y = 0)
  if m == 0
    [n, last_x, last_y]
  else
    q, r = n.divmod(m)
    e_gcd(m, r, last_x - q * x, x, last_y - q * y, y)
  end
end

def recip(n)
  d, x, y = e_gcd n, P
  x % P
end

n, m, k = gets.split.map(&:to_i)

c = m**2 * (n+1)*n*(n-1)/6 + n**2 * (m+1)*m*(m-1)/6
d = comb(n*m-2, k-2)

p((c * d) % P)


Measured memory_bytes: 1788
from collections import deque
n = int(input())
route = [[] for i in range(n+1)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    route[a].append((b,c))
    route[b].append((a,c))
q,k = map(int,input().split())
ans = [-1 for i in range(n+1)]
ans[k] = 0
d = deque()
d.append((k,0))
while d:
    now,cost = d.popleft()
    for i , j in route[now]:
        if ans[i] == -1:
            ans[i] = cost+j
            d.append((i,cost+j))
for i in range(q):
    x,y = map(int,input().split())
    print(ans[x]+ans[y])

Measured memory_bytes: 50380
//You could not live with your own failure,
//where did that bring you? back to me.
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define vi vector <int>
#define vs vector <string>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll lcm(ll a, ll b){return a*b/__gcd(a, b);}
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
#define N 500001
vector<int> adj[N];

void DFS(int v, vector<bool>& visited){
	visited[v] = true;
	cout<<v<<" ";
	for(auto i:adj[v]){
		if(visited[i]==false){
			DFS(i,visited);
		}
	}
}

void BFS(int v, vector<bool>& visited){
	queue<int> q;
	q.push(v);
	while(!q.empty()){
		int u = q.front();
		q.pop();
		cout<<u<<" ";
		visited[u]=1;
		for(auto i:adj[u]){
			if(!visited[i])q.push(i);
		}
	}
}

bool isCyclicDFS(int v, vector<bool>& visited, int parent){
	visited[v] = true;
	//cout<<v<<" ";
	for(auto i:adj[v]){
		if(visited[i]==false){
			if(isCyclicDFS(i,visited,v))
				return true;
		}
		else if(i!=parent)return true;
	}
	return false;
}

void topologicalSort(int v, vector<bool>& visited, stack<int>& s){
	visited[v]=true;
	for(auto i:adj[v]){
		if(!visited[i]){
			topologicalSort(i,visited,s);
		}
	}
	s.push(v);
}

void solve()
{
	int n; cin>>n;
	string s; cin>>s;
	int start=0, last=n-1,cnt=0;
	while(start<last){
		if(s[start]=='R'){start++;continue;}
		else{
			if(s[last]=='W')last--;
			else{
				cnt++;
				start++;
				last--;
			}
		}
	}
	cout<<cnt<<endl;
}

using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("outp.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
  	//cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //if(t<T)cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15604
def resolve():
    N, T = list(map(int, input().split()))
    A = list(map(int, input().split()))
    counts = {}
    a_max = -float("inf")
    a_min = A[0]
    for i in range(1, len(A)):
        if a_min < A[i] and a_max < A[i]:
            a_max = A[i]
            counts.setdefault(a_max-a_min, 0)
            counts[a_max-a_min] += 1
        if a_min > A[i]:
            a_min = A[i]
            a_max = -float("inf")
    #print(counts)
    maxdiff = max(counts.keys())
    print(counts[maxdiff])


if __name__ == '__main__':
    resolve()

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

struct BIT{
    vector<int> array;
    int n;

    BIT(int _n): array(_n+1, 0), n(_n){
    }

    // [1, i] の和
    int sum(int i){
        int ans = 0;
        while(i != 0){
            ans += array[i];
            i -= i & (-i);
        }
        return ans;
    }

    // [i, j] の和
    int sum(int i, int j){
        return sum(j) - sum(i-1);
    }

    // i に x を加える
    void add(int i, int x){
        while(i <= n){
            array[i] += x;
            i += i & (-i);
        }
    }
};

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, q;
    cin >> n >> q;

    vector<int> c(n+1);
    for(int i=1; i<=n; i++){
        cin >> c[i];
    }

    vector<tuple<int, int, int>> rl(q);
    for(int i=0; i<q; i++){
        int l, r;
        cin >> l >> r;
        rl[i] = make_tuple(r, l, i);
    }
    sort(rl.begin(), rl.end());

    vector<int> ans(q);

    BIT bit(n);
    int prevr = 0;
    // 同色で一番右にあるものの場所
    map<int, int> mp;
    for(int i=0; i<q; i++){
        for(int rr=prevr+1; rr<=get<0>(rl[i]); rr++){
            if(mp[c[rr]] != 0){
                bit.add(mp[c[rr]], -1);
            }
            bit.add(rr, 1);
            mp[c[rr]] = rr;
        }
        ans[get<2>(rl[i])] = bit.sum(get<1>(rl[i]), get<0>(rl[i]));
        prevr = get<0>(rl[i]);
    }

    for(int i=0; i<q; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

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

ll n, a[M], dp[M];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], dp[i] = 1e9;
    dp[1] = 0;
    for (int i = 1; i <= n; i++){
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i + 1] - a[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i + 2] - a[i]));
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 5120
"use strict";
const main = arg => {
  let words = arg.split("\n");
  let sortWords = words.map(t => t.split("").sort().join(''));
  sortWords.splice(0, 1);
  let count = 0;
  let wordObj = {};
  for(let i = 0; i < words[0]; i++){
  if(isNaN(wordObj[sortWords[i]])){
    wordObj[sortWords[i]] = 1;
    }else {
        wordObj[sortWords[i]]++;        
    }
  }
  for(let num in wordObj){
  if(wordObj[num] > 1){
    count += wordObj[num]*(wordObj[num]-1)/2;
    }
  }
  console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 60736