akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
const ll MOD=1000000007ll;
const int MAX=5100000;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll comb(ll n, ll r){
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int main()
{
  ll const mod = 1000000007;
  ll i,j;
  ll x,y; cin >> x >> y;
  if((x+y)%3 != 0){cout << 0 << endl; return 0;}
  ll newx = (ll)((2 * x - y) / 3);
  ll newy = (ll)((2 * y - x) / 3);
  if(newx < 0 || newy < 0){cout << 0 << endl; return 0;}
	ll n=1000000;
	fact[0]=1;
	REP(i, n) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[n]=power(fact[n], MOD-2);
        // 逆元の計算
	FORR(i, 0, n) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
        // nCrの計算
        cout<< comb(newx + newy, newy) << endl;

  return 0;
}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    map<char, int> m;
    m['r'] = p;
    m['s'] = r;
    m['p'] = s;
    bool flag[n];
    fill(flag, flag + n, true);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i < k)
            ans += m[t[i]];
        else {
            if (t[i] == t[i - k] && flag[i - k]) {
                flag[i] = false;
            } else {
                ans += m[t[i]];
            }
        }
    }
    OUT(ans);
}

Measured memory_bytes: 512
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;
const ll INF = 1e18 + 10 ;
set<int> s[N] ;
int n , m ;
vector<int> vis(N) ;
void dfs(int x){
    if ( vis[x] ) return ;
    vis[x] = true ;
    for(int c : s[x]){
        dfs(c) ;
    }
}
signed main(){
    fastio
    cin >> n >> m ;
    for(int i = 0; i < m; i++){
        int a , b , c ;
        cin >> a >> b >> c ;
        a--, b--;
        s[a].insert(b) ;
        s[b].insert(a) ;
    }
    int ans = 0 ;
    for(int i = 0; i < n; i++){
        if ( not vis[i] ) {
            ans++ ;
            dfs(i) ;
        }
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 21052
//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define MIN(a, b)		((a) < (b) ? a : b)
#define MAX(a, b)		((a) > (b) ? a : b)
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)		/* 奇数 */
#define IsEven(x)		(!IsOdd((x)))					/* 偶数 */
#define ArrayLength(x)	(sizeof(x) / sizeof(x[0]))
#define DWORD_MAX		(0xFFFFFFFF)

typedef short SWORD;
typedef unsigned short WORD;
typedef long SDWORD;
typedef unsigned long DWORD;
typedef long long int QWORD;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
DWORD dp[200 * 1000];
int h[200 * 1000];
int main()
{
	int N, K;
	cin >> N >> K;
	REP(i, N)	cin >> h[i];

	DWORD min;
	int i, j;
	dp[0] = 0;
	for (i = 1; i < N; i++) {
		min = DWORD_MAX;
		for (j = 0; j < K; j++) {
			if (0 <= (i - j - 1)) {
				DWORD val = dp[i - j - 1] + abs(h[i] - h[i - j - 1]);
				min = MIN(min, val);
			} else {
				break;
			}
		}
		dp[i] = min;
	}

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



Measured memory_bytes: 1408
n = int(input())
a = list(int(x) for x in input().split())

ans = 1
key = [0, 0, 0]
for i in range(n):
    k = a[i]
    p = 0
    q = 0
    if key[0] == k:
        p += 1
        q = 1
    if key[1] == k:
        p += 1
        if q == 0:
            q = 2
    if key[2] == k:
        p += 1
        if q == 0:
            q = 3
    ans = (ans*p)%1000000007
    key[q-1] = key[q-1]+1
print(ans)

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

int main()
{
	int m1,m2,d1,d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2)
	{
		cout << "1" << endl; 
	}
	else
	{
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include <queue>
#include <cstring>

#define mp make_pair
#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%lf",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"
#define sag (sol|1)
//#define sol (root<<1)
#define ort (bas+son)/2
#define SIZE  ( int)(1e9 + 7)
#define MAXN (ll) ((1e5+5))
#define K 25
#define  ALPHABET_SIZE  26
#define N (int)(1e5+10)
#define INF (ll )1e18
#define int ll
using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;

signed main(){
   ll n ;
cin >> n;
ll m ;
cin >>m;
if(n <=m)cout<<"Yes";
else cout << "No";

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
const int INF = 10000000;

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

    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0;i<h;i++) cin >> s[i];
    int ans = 0;
    for(int sh=0;sh<h;sh++){
        for(int sw=0;sw<w;sw++){
            if(s[sh][sw] == '#') continue;
            vector<vector<int>> dist(h,vector<int>(w,INF));
            queue<P> q;
            auto update = [&](int i,int j,int x){
                if(dist[i][j] != INF) return;
                dist[i][j] = x;
                q.emplace(i,j); //q.push(P(i,j))
            };
            update(sh,sw,0);
            while(!q.empty()){
                int i = q.front().first;
                int j = q.front().second;
                q.pop();
                for(int dir=0;dir<4;dir++){
                    int nh = i + dy[dir];
                    int nw = j + dx[dir];
                    if(nh<0||nh>=h || nw<0||nw>=w || s[nh][nw]=='#') continue;
                    update(nh,nw,dist[i][j]+1);   
                }
            }
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(dist[i][j]==INF) continue;
                    ans = max(ans,dist[i][j]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int n = int(a/d);
    if (a % d != 0) n++;
    int m = int(c/b);
    if (c % b != 0) m++;
    // cout << n << endl;
    // cout << m << endl;
    if (m<=n) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <assert.h>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

typedef long long ll;
const int mod = 1000000007;
// const int mod = 998244353;
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;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }

  mint permutation(ll n, ll k){
      if(k<0 || k>n) return 0;
      return fact[n] * ifact[n-k];
  }
};



void Main(){
    ll N, M;
    sll(N);
    sll(M);
    combination comb(M);
    mint a_num = comb.permutation(M, N);
    mint ks = 0;
    ll coef = 1;
    for(ll i=0;i<=N;++i){
        ks += comb(N, i) * comb.permutation(M-i, N-i) * coef;
        coef = coef - (coef * 2);
        // printf("i=%lld, %lldP%lld=%lld, k=%lld\n", i, M-i, N-i, comb.permutation(M-i, N-i), ks.x);
    }

    cout << ks * a_num<< endl;
}

int main(){
    Main();
    // string S = "ksdfjl";
    // char v = S[3];
    // S[3] = 'a';
    // cout << S <<endl;
}

Measured memory_bytes: 10784
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;}
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int N = 0;
	int max = -1;
	int min = 1000000000;
	cin >> N;
	int A[110];


	for (int i = 0; i < N; i++)
		cin >> A[i];

	for (int i = 0; i < N; i++) {
		if (A[i] < 0)
			A[i] = -A[i];

		if (min > A[i])
			min = A[i];

		if (max < A[i])
			max = A[i];
	}
	cout << max - min;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        String s = sc.next();
        if (!s.contains("N") && s.contains("S") || s.contains("N") && !s.contains("S")) {
            System.out.println("No");
        } else if (!s.contains("W") && s.contains("E") || s.contains("W") && !s.contains("E")) {
                System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 23508
/*

*/
#include <iostream>
using namespace std;

// 各桁の和を計算する関数
int findkaibunsuu(int n) {
  int A[5]; //各桁を収納
  int sum = 0;
  int i=0;
  while (n > 0) { // n が 0 になるまで
    A[i] = n % 10;
    n /= 10;
    ++i;
  }
  return A[0]==A[4] & A[1]==A[3];
}

int main() {
  int A, B;
  cin >> A >> B;
  
  int res = 0;
  for (int i = A; i <=B; ++i) {
    int kaibunsuu = findkaibunsuu(i); // N の各桁の和
    res += kaibunsuu;
  }
  cout << res << endl;
}

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

constexpr int IINF = INT_MAX;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> ecnt(n+1,0), wcnt(n+1,0);
    for(int i=0;i<m;i++){
        string d;
        cin >> d;
        for(int j=0;j<n;j++){
            if(d[j]=='W') wcnt[j+1]++;
            else ecnt[j+1]++;
        }
    }
    for(int i=0;i<n;i++){
        wcnt[i+1] += wcnt[i];
        ecnt[i+1] += ecnt[i];
    }
    int ans = -1, err = IINF;
    for(int i=0;i<=n;i++){
        if(ecnt[i]+(wcnt[n]-wcnt[i]) < err){
            ans = i;
            err = ecnt[i]+(wcnt[n]-wcnt[i]);
        }
    }
    cout << ans << " " << ans+1 << endl;
    return 0;
}



Measured memory_bytes: 3308
/*  I love Cara Delevingne */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e6 + 5;

int n;
string a, b;

bool check(int s) {
	int j = 0;
	for (int i = s; i < n; i++) {
		if (a[i] != b[j]) return 0;
		else j++;
	}
	return 1;
}


int main() {
   
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
    	if (check(i)) {
    		cout << 2 * n - (n - i);
    		return 0;
    	}  
	}
	cout << 2 * n;
	return 0;
}


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

using namespace std;

struct Info{
	int number;
};


void func(int n){

	int tmp,index = 0,firstCheck[10000],checkTable[10000];
	Info info[10000];

	for(int i = 0; i < 10000; i++)firstCheck[i] = 0;

	for(int i = 1; i <= n-1; i++){
		checkTable[i] = 0;
		tmp = (i*i)%n;

		if(firstCheck[tmp] == 0){
			info[index].number = tmp;
			index++;
			firstCheck[tmp] = 1;
		}
	}

	for(int i = 0; i < index; i++){
		for(int k = 0; k < index; k++){
			if(i != k){
				tmp = info[i].number - info[k].number;
				if(tmp < 0)tmp += n;
				if(tmp > (n-1)/2)tmp = n - tmp;
				checkTable[tmp]++;
			}
		}
	}

	int limit = (n-1)/2;

	for(int i = 1; i <= limit; i++)printf("%d\n",checkTable[i]);

}


int main(){

	int n;

	while(true){
		scanf("%d",&n);

		if(n == 0)break;

		func(n);
	}

    return 0;
}

Measured memory_bytes: 3304
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
  int a,counter;cin >> a;
  if(a/100==1){
    counter++;
    a=a-100;
  }
  if(a/10==1){
    counter++;
    a=a-10;
  }
  if(a==1){
    counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;
int main(){
	int n, c;
	cin >> n >> c;
	int bc[c][200001] = { };
	REP(i, n){
		int s, t, ch;
		cin >> s >> t >> ch;
		bc[ch-1][2*s-2]++;
		bc[ch-1][2*t]--;
	}
	REP(i, c){
		FOR(j, 1, 200001){
			bc[i][j] += bc[i][j-1];
		}
	}
	int k[200001] = { };
	REP(i, c){
		REP(j, 200001){
			if(bc[i][j] != 0) k[j]++;
		}
	}
	int m = 0;
	REP(i, 200001) m = max(m, k[i]);
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#include <algorithm>
#define MAX_N 100001
#define rep(i, n) for(ll i=0; i<n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n;

signed main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << a[0] * a[1] / 2.0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    ll n=s.size()+1,a[500010]={},sum=0;
    rep(i,n-1){
        if(s[i]=='>'&&s[i+1]=='<') a[i+1]=0;
        if(i==0&&s[i]=='<') a[i]=0;
        if(s[i]=='<') a[i+1]=a[i]+1;
    }
    repr(i,n-1){
        if(s[i]=='>'){
            if(s[i-1]=='>') a[i]=a[i+1]+1;
            else if(a[i+1]+1>a[i-1])a[i]=a[i+1]+1;
        }
    }
    rep(i,n) sum+=a[i];
    cout<<sum<<endl;
    return 0;
}


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

const int M = 998244353;
const int N = 1e5+7;
const long long B = 1000000000000000000;
typedef long long LL;

LL pb[N];
void pre() {
    pb[0] = 1;
    LL b = B%M;
    for (int i=1; i<N; i++)
        pb[i] = (pb[i-1]*b)%M;
}

vector<int> bfs(vector<vector<int>>adj) {
    int n = adj.size()-1;
    vector<int> col(n+1, N);

    vector<bool> vis(n);
    for (int i=n; i>0; i--) {
        for (int v: adj[i]) {
            if (v > i)    vis[col[v]] = 1;
        }

        for (int ii=0; ii<=n; ii++)
            if (!vis[ii]) {
                col[i] = ii;
                break;
            }

        for (int v: adj[i]) {
            if (v > i)    vis[col[v]] = 0;
        }
    }
    return col;
}

int m[3];
vector<vector<int>> adj[3];
vector<int> dis[3];
vector<LL> con[3];

int main() {
    pre();

    int n;
    cin>>n;
    const int MX = 1<<17;

    for (int g=0; g<3; g++) {
        cin>>m[g];
        adj[g].resize(n+1);
        for (int i=0; i<m[g]; i++) {
            int u, v;
            cin>>u>>v;
            adj[g][u].push_back(v);
            adj[g][v].push_back(u);
        }
        dis[g] = bfs(adj[g]);

        con[g].resize(MX);
        for (int i=1; i<=n; i++) {
            con[g][dis[g][i]] = (con[g][dis[g][i]] + pb[i])%M;
        }
    }
    LL ans = 0;
    for (int i=0; i<MX; i++) {
        if (con[0][i] == 0) continue;
        for (int j=0; j<MX; j++) {
            if (con[1][j] == 0)  continue;
            ans = (ans + ((con[0][i]*con[1][j])%M)*con[2][i^j])%M;
        }
    }
    cout<<ans<<endl;
}


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

int main () {
     int N, A, B;
     cin >> N >> A >> B;
     if (A * N > B) {
         cout << B << endl;
     }
     else if (A * N < B) {
         cout << A * N << endl;
     }
     else {
         cout << B << endl;
     }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

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 DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 2e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

struct Str: set<ii> {
	bool inv;
	map<int, int> mp;
	void agrega(int x) {
		if(inv) x = -x;
		if(mp[x]) erase(ii(mp[x], x));
		mp[x]++;
		insert(ii(mp[x], x));
	}

	void elimi(int x) {
		if(inv) x = -x;
		assert(mp[x] > 0);
		erase(ii(mp[x], x));
		mp[x]--;
		if(mp[x]) insert(ii(mp[x], x));
	}

	int getb(int nt) {
		if(inv) nt = -nt;
		auto iter = rbegin();
		while(iter != rend() && iter->se == nt) iter++;
		if(iter == rend()) return -1;
		if(inv) return -iter->se;
		return iter->se;
	}
} a, b;

vector<int> adj[maxN];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	b.inv = 1;
	int n;
	cin >> n;
	vector<int> ans(n), arr(n);
	for(int i = 0, inp; i < n; i++) {
		cin >> inp;
		a.agrega(inp);
		arr[i] = inp;
		adj[inp].push_back(i);
	}
	for(int i = 0, inp; i < n; i++) {
		cin >> inp;
		b.agrega(inp);
	}

	debug(arr);
	for(int i = 0; i < n; i++) {
		int cr = a.getb(-1);
		assert(cr != -1);
		int w = adj[cr].back();
		adj[cr].pop_back();

		int ot = b.getb(cr);
		if(ot == -1) {
			cout << "No\n"; return 0;
		}
		ans[w] = ot;
		//debug(cr, ot, ans);
		a.elimi(cr);
		b.elimi(ot);
	}

	cout << "Yes\n";
	for(auto el: ans) cout << el << ' '; cout << '\n';
}



Measured memory_bytes: 59364
/**
class cfmaster {
 public:
  struct code {
  	see the details down there !
  };
};
**/
#include <bits/stdc++.h>
 
using namespace std;

const long long inf = (long long) 9e18;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = inf;
  for (int p = 1; p <= 100; p++) {
    long long cost = 0;
    for (int i = 0; i < n; i++) {
      cost += (a[i] - p) * (a[i] - p);
    }
    ans = min(ans, cost);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll inf = (1LL << 60);
const int MOD = 1000000007;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int n, m, k,d[100],sum = 0;
int main() {
    cin >> n >> m; vector<int> h(n),a(m),b(m);
    vector<vector<int>> v(n);
    rep(i, n) {
        cin >> h[i];
    }
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }
    vector<bool> is(n, true);
    rep(i, n) {
        rep(j, v[i].size()) {
            if (h[v[i][j]] >= h[i]) {
                is[i] = false;
            }
        }
    }
    rep(i, n) {
        if (is[i]) {
            sum++;
        }
        
    }cout << sum << endl;
}

Measured memory_bytes: 9596
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans;
    if((a==b&&b!=c)||(a==c&&a!=b)||(b==c&&c!=a)){
        ans=2;
    }
    if(b==c&&c==a){
        ans=1;
    }
    if(c!=a&&c!=b&&a!=b){
        ans=3;
    }
    cout << ans << endl;
}

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

// Shortcut

#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
#define PrintVl(a) for (int i = 0; i < a.size(); i++) cout << a[i] << endl;
#define PrintA(a, n) for (int i = 0; i < n; i++) cout << a[i] << ' ';
#define PrintAl(a, n) for (int i = 0; i < n; i++) cout << a[i] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
	cout << *it << " = " << a << endl;
	DEB(++it, args...);
}

// Functions

#define bend(a) a.begin(),a.end()
#define mset(a) memset(a, 0, sizeof(a));
#define sortV(a) sort(bend(a));
#define sortA(a, n) sort(a, a + n);
#define rev(s) reverse(bend(a));

// Data Structure

#define pque priority_queue
#define mts multiset
typedef vector <int> vi;
typedef pair <int, int> ii;
typedef vector <vi > vvi;
typedef vector <ii > vii;

const int N = 1e5 + 5, mod = 1e9 + 7, inf = 1e18 + 7;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int a[n], sum = 0;
    For(i, 0, n){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a+  n);
    sum -= a[n - 1];
    if (a[n - 1] < sum) cout << "Yes";
    else cout << "No";
}

/*
----------------------------------+
INPUT:                            |
==============================    |

==============================    |
----------------------------------+
OUTPUT:                           |
==============================    |

==============================    |
----------------------------------+
*/

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import Data.Map ((!))
import qualified Data.Map as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------
 
main :: IO ()
main = do
  [x,t] <- getIntList
  print $ (x - t) `max` 0

Measured memory_bytes: 508
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll A, B;
	cin >> A >> B;
	string S;
	cin >> S;
 
	// 解法
	bool ans = true;
	string number = "1234567890";

	//出力
	REP(i, A+B+1){
		// cout << number.find(S.substr(i,1)) << endl;
		if (i!=A && number.find(S.substr(i,1))>10) ans = false;
		if (i==A && S[A]!='-') ans = false;
	}
	if (ans) printf("Yes\n");
	else printf("No\n");
}


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

vector<vector<int>> ki(0, vector<int>(0));
vector<vector<int>> ma(0, vector<int>(0));
vector<int> ans(0);
vector<int> it(0);
int l=0;

int f(int k, int j){
    it.at(k) = 1;
    if(ma.at(l).at(k) > j) ma.at(l).at(k) = j;
    if(ma.at(k).at(l) > j) ma.at(k).at(l) = j;
    rep(i, ki.at(k).size()) if(it.at(ki.at(k).at(i)) == 0) f(ki.at(k).at(i), j+1);
    return 0;
}

int main(){
    ll N, X, Y;
    cin >> N >> X >> Y;
    rep(i, N){
        ki.push_back({});
        ans.push_back(0);
        it.push_back(0);
    }
    ki.at(0).push_back(1);
    ki.at(N-1).push_back(N-2);
    for(int i=1; i<N-1; i++){
        ki.at(i).push_back(i-1);
        ki.at(i).push_back(i+1);
    }

    rep(i, N){
        ma.push_back({});
        for(int j=0; j<N; j++){
            ma.at(i).push_back(20000);
        }
    }
    /*
rep(i, N){
    rep(j, ki.at(i).size()) cout << ki.at(i).at(j) << ' ';
    cout << endl;
}
*/

    rep(i, N){
        rep(j, N) it.at(j) = 0;
        l = i;
        f(i, 0);
    }
    int ll = ki.at((X+Y-2)/2).size(); 
    rep(i, ll) ki.at((X+Y-2)/2).pop_back();
    ki.at(X-1).push_back(Y-1);
    ki.at(Y-1).push_back(X-1);
    /*
rep(i, N){
    rep(j, ki.at(i).size()) cout << ki.at(i).at(j) << ' ';
    cout << endl;
}
*/
    rep(i, N){
        rep(j, N) it.at(j) = 0;
        l = i;
        f(i, 0);
    }
    rep(i, N-1){
        ma.at(i).push_back({});
        for(int j=i+1; j<N; j++){
            ans.at(ma.at(i).at(j))++;
        }
    }
    rep(i, N-1) cout << ans.at(i+1) << endl;

    return 0;
}


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

class List
{
public:
    struct Node{
        int key;
        Node *next, *prev;
    };

    Node *nil;
    List(){
        nil = (Node *)malloc(sizeof(Node));
        nil->next = nil;
        nil->prev = nil;
    }

    Node* search(int key){
        Node *cur = nil->next;
        while(cur != nil && cur->key != key)
            cur = cur->next;
        return cur;
    }

    void print(){
        Node *cur = nil->next;
        while(1){
            if(cur == nil) break;
            cout << cur->key << char((cur->next == nil) ? '\n' : ' ');
            cur = cur->next;
        }
        return;
    }

    void del_node(Node *t){
        if(t == nil) return;
        t->prev->next = t->next;
        t->next->prev = t->prev;
        free(t);
        return;
    }

    void del_first(){
        del_node(nil->next);
        return;
    }

    void del_last(){
        del_node(nil->prev);
        return;
    }

    void del_key(int key){
        del_node(search(key));
        return;
    }

    void insert(int key){
        Node *x = (Node *)malloc(sizeof(Node));
        x->key = key;
        x->next = nil->next;
        nil->next->prev = x;
        nil->next = x;
        x->prev = nil;
        return;
    }
};

int main(){
    List list;
    int n; scanf("%d", &n);
    for(int i = 0; i < n; i++){
        char command[20];
        scanf("%s", command);
        if(strlen(command) > 6){
            if(command[6] == 'L') list.del_last();
            else if(command[6] == 'F') list.del_first();
        } else {
            int num;
            scanf("%d", &num);
            if(command[0] == 'i') list.insert(num);
            else list.del_key(num);
        }
    }
    list.print();
    return 0;
}


Measured memory_bytes: 34312
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MOD = (ll)1000000000 + 7;
ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
const int MAX = 500050;
typedef pair<int, int>P;

int N, Q;
string S;
int k[100];
signed main() {
	cin >> N >> S >> Q;
	REP(i, Q)cin >> k[i];
	REP(i, Q) {
		int K = k[i];
		int l = 0, r = 0;
		int sumD = 0, sumM = 0, sumDM = 0, res = 0;
		if (S[l] == 'D')sumD++;
		if (S[l] == 'M')sumM++;
		while (r < N) {
			if (r - l < K-1) {
				r++;
				if (S[r] == 'D')sumD++;
				if (S[r] == 'M') {
					sumDM += sumD;
					sumM++;
				}
				if (S[r] == 'C') {
					res += sumDM;
				}
			}
			else {
				if (S[l] == 'D') {
					sumDM -= sumM;
					sumD--;
				}
				if (S[l] == 'M') {
					sumM--;
				}
				l++;
				r++;
				if (S[r] == 'D')sumD++;
				if (S[r] == 'M') {
					sumDM += sumD;
					sumM++;
				}
				if (S[r] == 'C') {
					res += sumDM;
				}
			}
		}
		print(res);
	}
}


Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include <bitset>
#include <vector>

using namespace std;

int main() {
	int sum = 0;
	string s; cin >> s;
	vector<int> v(4);
	for (int i = 0; i < 4; i++) v.at(i) = s[i] - '0';
	for (int i = 0; i < (1 << 4); i++) {
		sum = v.at(0);
		bitset<4> bit(i);
//		cout << bit << endl;
		for (int j = 0; j < 3; j++) {
			if (bit.test(j)) sum += v.at(j+1);
			else sum -= v.at(j+1);
		}
//		cout << sum << endl;
		if (sum == 7) {
			cout << v.at(0);
			for (int j = 0; j < 3; j++) {
				if (bit.test(j)) cout << "+";
				else cout << "-";
				cout << v.at(j + 1);
			}
			cout << "=7" << endl;
			break;
		}

		else sum = 0;
	}
	return 0;
}

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

int main() {
    int x, y;

    scanf("%d %d", &x, &y);

    int c, t;

    t = y / 2 - x;
    c = x - t;

    if (c + t == x && 2 * c + 4 * t == y && c >= 0 && t >= 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}

Measured memory_bytes: 1660
#include<stdio.h>
int main()
{
	int i,j,k,l,m;
	scanf("%d",&k);
	scanf("%d",&l);
	scanf("%d",&m);
	if(m-(k-l)>0)
	{
		printf("%d",m-(k-l));
	}
	else
	{
		printf("0");
	}
}

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

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

int main(void) {

  int N, M, P;
  int x[128];

  for(;;) {
    std::cin >> N >> M >> P;
    if( N == 0 and M == 0 and P == 0 ) break;

    for(int i = 0; i < N; ++i) {
      std::cin >> x[i];
    }

    s64 sum = std::accumulate(x, x+N, 0);

    s64 totalmoney = sum * 100;

    s64 sharemoney = totalmoney * (100 - P) / 100;

    s64 ans = x[M - 1] != 0 ? sharemoney / x[M - 1] : 0;

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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std; 
#define int long long
const int maxn = 5050 * 5050;
const int mod = 1e9 + 7;
int dp[maxn];
int n;
int g[2], s[2], b[2];

int solve(int N){
    memset(dp, 0, sizeof dp);
    for(int i = 0 ; i <= N ; ++i){
        dp[i] = i;
        if(g[0] <= i && g[1] > g[0]) dp[i] = max(dp[i], g[1] + dp[i - g[0]]);
        if(s[0] <= i && s[1] > s[0]) dp[i] = max(dp[i], s[1] + dp[i - s[0]]);
        if(b[0] <= i && b[1] > b[0]) dp[i] = max(dp[i], b[1] + dp[i - b[0]]);
    }
    return dp[N];
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 0 ; i < 2 ; ++i)
        cin >> g[i] >> s[i] >> b[i];
    int ans = solve(n);
    swap(g[0], g[1]);    
    swap(s[0], s[1]);    
    swap(b[0], b[1]);
    cout << solve(ans) << '\n'; 
    return 0;

}

Measured memory_bytes: 199552
#include<cstdio>
using namespace std;
int n,b[105],m;
char c, a;
int main() {
	scanf("%d%d", &n, &m);
	long long  ans = 0,flag=0;
	scanf("%c", &a);
	while(a!='L'&&a!='R')scanf("%c", &a);
	for (int i = 2; i <= n; ++i) {
		scanf("%c", &c);
		if (a == c)++ans;
		else ++flag;
		a = c;
	}
	if (m < (flag+1)>>1)ans += (m << 1);
	else ans += flag;
	printf("%lld", ans);
}

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

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

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

#define INF INT_MAX/3

#define MAX_N 1000

ll gcd(ll x,ll y){
  return y?gcd(y,x%y):x;
}

struct frac{
  ll m,d; // m/d
  frac():m(0),d(1){}
  frac(ll a,ll b):m(a),d(b){}
  frac& fix() { if(d<0)m=-m,d=-d; ll g=gcd(m<0?-m:m,d<0?-d:d); if(g!=0)m/=g,d/=g; return *this;}
  frac& operator+=(const frac& a){ ll mm=a.d*m+a.m*d; ll dd=d*a.d; m=mm; d=dd; fix(); return *this;}
  frac& operator-=(const frac& a){ ll mm=a.d*m-a.m*d; ll dd=d*a.d; m=mm; d=dd; fix(); return *this;}
  frac& operator*=(const frac& a){ ll mm=a.m*m; ll dd=a.d*d; m=mm; d=dd; fix(); return *this;}
  frac operator+(const frac& a)const{ return frac(*this) += a;}
  frac operator-(const frac& a)const{ return frac(*this) -= a;}
  frac operator*(const frac& a)const{ return frac(*this) *= a;}
  bool operator==(const frac& a)const{ return m*a.d==d*a.m; }
  bool operator<(const frac& a)const{ if(*this==a){ return false; }else if(m*a.m>=0){ return m*a.d<a.m*d; }else{ return m<0; } }
  bool operator>(const frac& a)const{ return !(*this==a)&&!(*this<a); }
  void show(){ fix(); printf("%lld/%lld\n", m,d); }
};

ll mem[55][55];

ll comb(ll n,ll r)
{
  if(mem[n][r]!=-1)return mem[n][r];
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return mem[n][r]=(comb(n-1,r-1)+comb(n-1,r));
}

ll n,a,b;
ll v[66];
map<ll,ll> cnt;

int main(){
	cin.sync_with_stdio(false);
  memset(mem,-1,sizeof(mem));
  cin>>n>>a>>b;
  rep(i,n)cin>>v[i];
  rep(i,n){
    cnt[v[i]]++;
  }
  sort(v,v+n);
  reverse(v,v+n);
  frac maxx(-1,1); ll res=0;
  repl(i,a,b+1){
    frac ave;
    map<ll,ll> cntt;
    rep(j,i){
      ave+=frac(v[j],1);
      cntt[v[j]]++;
    }
    ave*=frac(1,i);
    ll ncnt=1;
    each(it,cntt){
      ncnt*=comb(cnt[it.fi],cntt[it.fi]);
    }
    if(ave==maxx){
      res+=ncnt;
    }else if(maxx<ave){
      maxx=ave;
      res=ncnt;
    }
  }
  printf("%.10f\n", (double)maxx.m/maxx.d);
  printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 256
n = int(input())

f = [1]*(n+1)
for i in range(2,n+1):
    f[i]+=1
    for j in range(i*2, n+1, i):
        f[j]+=1

ans = 0

for i in range(1,n+1):
    ans += i*f[i]


print(ans)

Measured memory_bytes: 145916
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let v = read_vec::<i64>();
        let (a, b, c) = (v[0] as usize - 1, v[1] as usize - 1, v[2]);
        graph[a].push((b, -c));
    }
    let (cost, negative) = shortest_path(&graph, 0);
    if negative[n - 1] {
        println!("inf");
        return;
    }
    println!("{:?}", -cost[n - 1]);
}

const INF: i64 = std::i64::MAX;

fn shortest_path(graph: &Vec<Vec<(usize, i64)>>, start: usize) -> (Vec<i64>, Vec<bool>) {
    let n = graph.len();
    let mut dist = vec![INF; n];
    dist[start] = 0;
    for _ in 0..n {
        for v in 0..n {
            for &(to, cost) in &graph[v] {
                if dist[v] == INF || dist[to] <= dist[v] + cost {
                    continue;
                }
                dist[to] = dist[v] + cost;
            }
        }
    }

    let mut negative = vec![false; n];
    for _ in 0..n {
        for v in 0..n {
            for &(to, cost) in &graph[v] {
                if dist[v] == INF {
                    continue;
                }
                if dist[to] > dist[v] + cost {
                    dist[to] = dist[v] + cost;
                    negative[to] = true;
                }
                if negative[v] {
                    negative[to] = true;
                }
            }
        }
    }

    return (dist, negative);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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



int main()
{
  ll N, M;
  cin >> N >> M;
  vector<vector<bool>> connect(N, vector<bool>(N, false));
  for (ll i = 0; i < M; ++i)
  {
    ll a, b;
    cin >> a >> b;
    connect.at(a - 1).at(b - 1) = true;
    connect.at(b - 1).at(a - 1) = true;
  }
  vector<ll> perm(N);
  for (ll i = 0; i < N; ++i)
  {
    perm.at(i) = i;
  }
  ll ans = 0;
  while (true)
  {
    if (perm.at(0) == 0)
    {
      ans += 1;
      for (ll i = 0; i < N - 1; ++i)
      {
        if (!connect.at(perm.at(i)).at(perm.at(i + 1)))
        {
          ans -= 1;
          break;
        }
      }
    }
    if (!next_permutation(perm.begin(), perm.end()))
    {
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())
S=[]
T=[]

for i in range(N):
    s,t=input().split()
    S.append(s)
    T.append(int(t))

X=input()
ans=0
for i in range(N):
    if S[-1-i]==X:
        break
    else:
        ans+=T[-1-i]

print(ans)



Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ans=0;
	char before='.';
	for(int i=0;i<n;i++){
		if(s[i]!=before){
			ans++;
		}
		before = s[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 512