akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> sum(n + 1);
    for (int i = 1; i < s.size(); i++) {
        sum[i + 1] = sum[i];
        if (s[i - 1] == 'A' && s[i] == 'C')sum[i + 1]++;
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, M; cin >> N >> M;
  vector<bool> bs(N);
  while (M--) {int a; cin >> a; bs[--a] = true;}
  vector<int64_t> dp(N + 1); dp[0] = 1;
  for (int i = 0; i < N; ++i) if (!bs[i]) dp[i + 1] = (dp[i] + (i >= 1 ? dp[i - 1] : 0)) % 1000000007;
  cout << dp[N] << endl;}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#include <set>
#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 llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

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

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);

int func(int a)
{
    int res=0;
    while(a>0)
    {
        int tmp=a%10;
        res+=tmp;
        a/=10;
    }
    return  res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int ans=INF;
    for(int i=1; i<n; i++)
    {
        int cnt=func(i)+func(n-i);
        ans=min(cnt,ans);
    }
    cout<<ans<<endl;

    return  0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real() * b.imag() - a.imag() * b.real(); }
ld dot(const P& a, const P& b) { return a.real() * b.real() + a.imag() * b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps)
{
	auto c3 = [](const P& a, const P& b, const P& c) {
		ld A = norm(b - c);
		ld B = norm(c - a);
		ld C = norm(a - b);
		ld S = abs(cross(b - a, c - a));
		P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
		ld r = abs(p - a);
		return make_pair(r, p);
	};

	auto c2 = [](const P& a, const P& b) {
		P c = (a + b) / (ld)2;
		ld r = abs(a - c);
		return make_pair(r, c);
	};

	auto in_circle = [](const P& a, const C& c) {
		return norm(a - c.pnt) <= c.rad * c.rad + eps;
	};

	int n = ps.size();
	random_shuffle(ps.begin(), ps.end());
	C c = c2(ps[0], ps[1]);
	for (int i = 2; i < n; ++i)
	{
		if (!in_circle(ps[i], c))
		{
			c = c2(ps[0], ps[i]);
			for (int j = 1; j < i; ++j)
			{
				if (!in_circle(ps[j], c))
				{
					c = c2(ps[j], ps[i]);
					for (int k = 0; k < j; ++k)
					{
						if (!in_circle(ps[k], c))
						{
							c = c3(ps[i], ps[j], ps[k]);
						}
					}
				}
			}
		}
	}
	return c;
}

int main()
{
	cout << fixed << setprecision(10);
	int n; cin >> n;
	G g(n);
	for (int i = 0; i < n; i++)
	{
		ld x, y;
		cin >> x >> y;
		g[i] = P(x, y);
	}
	cout << smallest_enclosing_disc(g).rad;
}

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

typedef long long ll;

int main(){
	ll N, K;
	cin >> N >> K;
	vector<ll> H(N);
	
	for(int i = 0; i < N; i++){
		cin >> H[i];
	}
	
	if(N <= K){
		cout << 0 << endl;
		return 0;
	}
	
	sort(H.begin(), H.end());
	
	ll sum = 0;
	for(int i = 0; i < N - K; i++){
		sum += H[i];
	}
	
	cout << sum << endl;
}


Measured memory_bytes: 1792
/**
 * THIS IS MOOONI'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>
 
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  cout << (s[0] == '7' || s[1] == '7' || s[2] == '7' ? "Yes" : "No") << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

int a,b,c,d,r[105],ans;

int main () {
	scanf("%d%d%d%d",&a,&b,&c,&d);
	FOE(i,a,b-1) ++r[i];
	FOE(i,c,d-1) ++r[i];
	FOE(i,0,100) if (r[i]==2)++ans;
	printf("%d\n",ans);
	return 0;	
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> d(k);
  rep(i, k) cin >> d[i];

  auto ok = [&](ll x) {
    bool flag = true;
    while (x > 0) {
      rep(i, k) flag &= (x % 10) != d[i];
      x /= 10;
    }
    return flag;
  };

  while (!ok(n)) n++;

  cout << n << endl;
  return 0;
}


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

int ans=1e9;
string s;
set<char> has;

inline bool finish(string cur)
{
	for(int i=1;i<cur.size();i++) if(cur[i]!=cur[i-1]) return 0;
	return 1;
}

inline int solve(string cur,char fin)
{
	if(finish(cur)) return (s.size()-cur.size());
	for(int i=1;i<cur.size();i++) if(cur[i]==fin) cur[i-1]=fin;
	cur=cur.substr(0,cur.size()-1);
	return solve(cur,fin);
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>s;
	
	for(int i=0;i<s.size();i++)
	{
		if(has.count(s[i])) continue;
		ans=min(ans,solve(s,s[i]));
		has.insert(s[i]);
	}
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdlib.h>
using namespace std;

int cal(int x1,int y1,int x2,int y2) {
	int d,x,y;
	if (y1==y2) return abs(x1-x2);
	if (x1==x2) return abs(y1-y2);
	if (x1>x2) { swap(x1,x2); swap(y1,y2);}
	d= y1<y2 ? 0 : 1;
	if ((d==0 && (y2 % 2)==1 && y2+1==y1) || (d==1 && (y1 % 2)==1 && y1+1==y2)) x=0; else x=x2-x1;
	y=abs(y2-y1)/2;
	if (abs(y2-y1) % 2 == 1) if (y2 % 2==0) y++;
	if (x>y) x=y;
	d=abs(x1-x2)+abs(y1-y2)-x;
	return d;
}

int main() {
    int a,c,m,n,s,p,k,x,y,i,j,mp[100][100];
    while(cin >> m >> n && m>0) {
	  for (i=0;i<n;i++) for (j=0;j<m;j++) mp[i][j]=999;
	  a=0;
	  for (p=0;p<2;p++) {
	  cin >> s; 
	  for (;s>0;s--) {
		   cin >> x >> y; k=0; x--; y--;
	       for (i=0;i<n;i++) for (j=0;j<m;j++) {
			   c=cal(x,y,j,i);
	       if (mp[i][j]>c) { if (p==0) mp[i][j]=c; else k++; }
	       }
	       if (a<k) a=k;
		}
	}
	cout << a << endl;
	}
	 return 0;
}

Measured memory_bytes: 1184
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	int n, r;
	while(scanf("%d%d", &n, &r)==2)
	{
		int ans=r;

		if(n<10) ans=r+1000-100*n;
		printf("%d\n", ans);
	}
	return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string t;
    cin >> t;
    for(i = 0;i < t.size();++i){
        if(t.at(i) == '?') t.at(i) = 'D';
    }
    cout << t << endl;

    return 0;
}

Measured memory_bytes: 3748
from sys import stdin
def check(s,t):
    d=dict()
    for c in s:
        if c not in d:
            d[c]=1

    res=0
    for c in t:
        if c in d:
            if d[c]==1:
                res+=1
                d[c]=0

    return res

def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    S=readline().strip()

    res=0
    for i in range(1,N):
        X=S[:i]
        Y=S[i:]
        res=max(res,check(X,Y))

    print(res)
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

def main():
    N,M,P = map(int,input().split())
    edges = []


    for _ in range(M):
        A,B,C = map(int,input().split())
        edges.append([A-1,B-1,P-C])

    reachable_from = [False for _ in range(N)]
    reachable_from[0] = True
    reachable_to = [False for _ in range(N)]
    reachable_to[N-1] = True

    for i in range(N-1):
        for edge in edges:
            if reachable_from[edge[0]]:
                reachable_from[edge[1]] = True
            if reachable_to[edge[1]]:
                reachable_to[edge[0]] = True

    edges2 = []
    for edge in edges:
        if reachable_from[edge[0]] and reachable_to[edge[1]]:
            edges2.append(edge)

    inf = 10000*(10**5)
    dist = [inf for _ in range(N)]
    dist[0] = 0

    for i in range(N):
        for edge in edges2:
            if dist[edge[1]] > dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]]+edge[2]
                if i==N-1:
                    print(-1)
                    break
        else:
            continue
        break
    else:
        print(max(0,-1*dist[N-1]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 44060
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>

using namespace std;

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

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

    long long stepSum = 0;
    long long height = 0;
    
    for ( int i = 0; i < n; i++ ) {
        if (height <= a[i]) {
            height = a[i];
            continue;
        }
        stepSum += height - a[i];
    }

    cout << stepSum << endl;

    return 0;
}


Measured memory_bytes: 3940
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

bool ok(ll K, ll a) {
    bool flag = true;
    for(int j = 0; j <= 30; j++) {
        if ((!((K >> j) & 1)) && ((a >> j) & 1)) {
            flag = false;
            break;
        } 
    }
    return flag;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (ok(K, A[i])) {
            ans += B[i];
        }
    }
    for (int k = 0; k <= 30; k++) {
        if (K >> k & 1) {
            ll sum = 0;
            ll newK = (K & ~(1 << k));
            if (k > 0) newK |= ((1 << k) - 1);
            for (int i = 0; i < N; i++) {
                if (ok(newK, A[i])) {
                    sum += B[i];
                }
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

const int mod=1000000007;

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

string s;
int n;
long long dp[200005][2];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>s;
    n=s.size();
    s='#'+s;
    dp[n+1][0]=1;
    dp[n+1][1]=1;
    for(int i=n;i>=1;i--){
        dp[i][0]=dp[i+1][0]*3%mod;
        if(s[i]=='1'){
            dp[i][1]=(dp[i+1][1]*2+dp[i+1][0])%mod;
        }else{
            dp[i][1]=dp[i+1][1]%mod;
        }
    }
    cout<<dp[1][1]<<endl;

    return 0;
}

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

int main(){
	int x,a,b; cin>>x>>a>>b;
	if(a>=b) cout<<"delicious"<<endl;
	else if(b-a<=x) cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
}


Measured memory_bytes: 3568
H, N = map(int, input().split())
AB=[]
for _ in range(N):
    AB.append(list(map(int, input().split())))

Max_A = max(a for a, b in AB)
# print(Max_A)

dp = [10 ** 18] * (H + Max_A)
dp[0] = 0
for i in range(1, H + Max_A):
    dp[i] = min(dp[i - a] + b for a, b in AB)
print(min(dp[H:]))


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

int main()
{
  int		n, count = 0;
  double	sq;
  
  cin >> n;
  for (int c = 1; c < n; c++)
  {
    sq = sqrt((double(n - c)));
    if ((int)sq * (int)sq == n - c)
      count++;
    for (int a = 1; a < sq; a++)
    {
      if (((n - c) % a) == 0)
        count += 2;
    }
  }
  cout << count << endl;
  return (0);
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vl s(n);
    rep(i,n) cin >> s[i];
    vl s1;
    rep(i,n){
        if(s[i]%10!=0)s1.push_back(s[i]);
    }
    sort(all(s1));
    ll res = accumulate(all(s),0LL);
    if(res % 10 !=0)cout << res << endl;
    else{
        if(s1.size()==0)cout << 0 << endl;
        else cout << res - s1[0] << endl;
    }
}


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

using namespace std;

int N, K;
string S;
vector<pair<int, int>> v;

int main() {
    cin >> N >> K >> S;
    S += '0';
    bool f = false;
    int a, b;
    if (S[0] == '0') {
        v.push_back(make_pair(-1, -1));
    }
    for (int i = 0; i <= N; i++) {
        if (S[i] == '1') {
            if (!f) {
                f = true;
                a = i;
            }
        } else if (S[i] == '0') {
            if (f) {
                f = false;
                b = i - 1;
                v.push_back(make_pair(a, b));
            }
        }
    }
    if (S[N - 1] == '0') {
        v.push_back(make_pair(N, N));
    }
    int l = v.size();
    if (l - 1 <= K) {
        cout << N << endl;
        return 0;
    }
    int ans = 0;
    for (int i = 0, j = K; j < l; i++, j++) {
        int a = v[j].second - v[i].first + 1;
        if (v[i].first == -1) {
            a--;
        }
        if (v[j].second == N) {
            a--;
        }
        ans = max(ans, a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

int lcm(int a, int  b){
    return (a*b)/gcd(a,b);
}

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //x???n???????¨????????????????n??????2?????¨?¨???????????¨????
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//???????????????
        }
        x=(x*x)%mod;//2???
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    int zenbu=0;
    int kidoku=0;
};

class xxIntu {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        //?¬¬1?????¶
        if(riLeft.z != riRight.z){
            return riLeft.z > riRight.z;//<:??????(?°??????????)???>:??????(??§?????????)
        }
        //?¬¬2?????¶
        return riLeft.y < riRight.y;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/



int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //????????????
    
    int n=0,m=0;
    cin >> n>> m;
    int c[20];
    for(int i=0;i<m;i++)
        cin >>c[i];
    
    //j?????¨??????????????????????°??????°
    int dp[50000];
    for(int i=0;i<50000;i++){
        dp[i]=-1;
    }
    dp[0]=0;
    

    
    for(int j=0;j<=n;j++){
        int mmin=55555;
        for(int p=0;p<m;p++){
            if(j-c[p]<0){
                continue;;
            }
            if(dp[j-c[p]]!=-1){
                if(mmin>dp[j-c[p]]+1){
                    mmin=dp[j-c[p]]+1;
                }
            }
        }
        if(mmin!=55555){
            dp[j]=mmin;
        }
    }

    cout << dp[n] << endl;
    
    //???????????§
    //cout << "ans" << endl;????????????
    //printf("%.0f\n",ans);//?°???°?????\?????¨?????????
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 3296
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(2*c>a+b)cout<<a*x+b*y;
    else
    {
        if(x>y)
        cout<<y*c*2+min(2*c,a)*(x-y);
        else
        cout<<x*2*c+(y-x)*min(b,c*2);
    }
    return 0;
}


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

int main(){
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    int ans = 0;
    if(x*2==w && y*2==h) ans = 1;
    printf("%.10f %d\n", (double)w*h/2, ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    ll N, L;
    cin >> N >> L;
    ll a[N];
    REP(i, 0, N) {
        cin >> a[i];
    }
    REP(i, 0, N - 1) {
        if (a[i] + a[i + 1] >= L) {
            cout << "Possible" << endl;
            REP(j, 0, i) {
                cout << j + 1 << endl;
            }
            PER(j, N - 2, i) {
                cout << j + 1 << endl;
            }
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << "Impossible" << endl;
}


Measured memory_bytes: 1536
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let n:u32 = read();

    println!("{}", if n%2==0 {n} else {n*2});

}


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

const int maxn = 3010;
int n, m, f[maxn][maxn], g[maxn][maxn]; char a[maxn], b[maxn];

void print(int x, int y) {
	if (!x || !y) return;
	if (!g[x][y]) {
		print(x - 1, y - 1), putchar(a[x]);
	} else {
		print(x - (g[x][y] == 2), y - (g[x][y] == 1));
	}
}

int main() {
	scanf("%s %s", a + 1, b + 1);
	n = strlen(a + 1), m = strlen(b + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i] == b[j]) {
				f[i][j] = f[i - 1][j - 1] + 1;
			} else {
				if (f[i - 1][j] < f[i][j - 1]) {
					f[i][j] = f[i][j - 1], g[i][j] = 1;
				} else {
					f[i][j] = f[i - 1][j], g[i][j] = 2;
				}
			}
		}
	}
	print(n, m);
	return 0;
}

Measured memory_bytes: 70912
// C - Maximal Value

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

	int A[100];
	int B[99];

	for (int i=0; i<N-1; i++) {
		cin >> B[i];
	}

	A[0] = B[0];
	for (int i=1; i<N-1; i++) {
		A[i] = min(B[i-1], B[i]);
	}
	A[N-1] = B[N-2];

	int ans = 0;
	for (int i=0; i<N; i++) {
		ans += A[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    string S;   cin>>S;
    for(int bit=0;bit<(1<<3);bit++){
        int s=S[0]-'0';
        for(int i=0;i<3;i++){
            if(bit & 1<<(2-i)){
                s+=S[i+1]-'0';
            }
            else{
                s-=S[i+1]-'0';
            }
        }
        if(s==7){
            cout<<S[0];
             for(int i=0;i<3;i++){
                 if(bit & 1<<(2-i)){
                        cout<<'+'<<S[i+1];
                  }
                 else{
                      cout<<'-'<<S[i+1];
                  }
             }
            cout<<"=7";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int a,b,q;
ll INF = 100000000000000;
ll s[200000],t[200000],xi,pos;

ll shrine_left (ll x){
    if(x<s[1]){return INF;}
    else{
        ll l = 1;
        ll r = a;
        while(l<=r){
            ll mid = (l+r)/2;
            if(s[mid]<=x && s[mid+1]>x){pos = s[mid]; return (ll) abs(x-s[mid]);}
            else if(s[mid]<=x && s[mid+1]<=x){l=mid+1;}
            else {r=mid-1;}
        }
    }
}
ll shrine_right (ll x){
    if(x>s[a]){return INF;}
    else{
        ll l = 1;
        ll r = a;
        while(l<=r){
            ll mid = (l+r)/2;
            if(s[mid]>=x && s[mid-1]<x){pos=s[mid]; return (ll) abs(x-s[mid]);}
            else if(s[mid]>=x && s[mid-1]>=x){r=mid-1;}
            else{l=mid+1;}
        }
    }
}
ll temple_left (ll x){
    if(x<t[1]){return INF;}
    else{
        ll l = 1;
        ll r = b;
        while(l<=r){
            ll mid = (l+r)/2;
            if(t[mid]<=x && t[mid+1]>x){pos = t[mid];return (ll) abs(x-t[mid]);}
            else if(t[mid]<=x && t[mid+1]<=x){l=mid+1;}
            else {r=mid-1;}
        }
    }
}
ll temple_right (ll x){
    if(x>t[b]){return INF;}
    else{
        ll l = 1;
        ll r = b;
        while(l<=r){
            ll mid = (l+r)/2;
            if(t[mid]>=x && t[mid-1]<x){pos=t[mid]; return (ll) abs(x-t[mid]);}
            else if(t[mid]>=x && t[mid-1]>=x){r=mid-1;}
            else{l=mid+1;}
        }
    }
}


int main(){
    cin>>a>>b>>q;
    for(int i=1;i<=a;i++)cin>>s[i];
    sort(s+1,s+1+a);s[a+1]=INF;

    for(int i=1;i<=b;i++)cin>>t[i];
    sort(t+1,t+1+b);t[b+1]=INF;

    for(int query=1;query<=q;query++){
        ll dist = INF;
        cin >> xi;
        ll temp;
        pos = xi;
        temp = shrine_left(pos);
        temp += temple_left(pos);
        dist = min(dist,temp);

        pos = xi;
        temp = shrine_left(pos);
        temp += temple_right(pos);
        dist = min(dist,temp);

        pos = xi;
        temp = shrine_right(pos);
        temp += temple_left(pos);
        dist = min(dist,temp);

        pos = xi;
        temp = shrine_right(pos);
        temp += temple_right(pos);
        dist = min(dist,temp);

        pos = xi;
        temp = temple_left(pos);
        temp += shrine_left(pos);
        dist = min(dist,temp);

        pos = xi;
        temp = temple_left(pos);
        temp += shrine_right(pos);
        dist = min(dist,temp);

        pos = xi;
        temp = temple_right(pos);
        temp += shrine_left(pos);
        dist = min(dist,temp);

        pos = xi;
        temp = temple_right(pos);
        temp += shrine_right(pos);
        dist = min(dist,temp);

        cout<<dist<<endl;
    }
}


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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD (int)10e9+7

template<typename T>
void amax(T& a, T b) { a=a>b?a:b; }
template<typename T>
void amin(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;


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

    int n;
    cin >> n;

    cout << ((n+1)/2) << endl;
    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
 
	// ??????????????\????????????2????????°?????\???????????°
	int line, column;
	scanf("%d %d", &line, &column);
	
	// ???????????????????????????
	int grid[line+1][column+1];
	
	for(int cnt1 = 0; cnt1 <= line; cnt1++) {
	  
	  for(int cnt2 = 0; cnt2 <= column; cnt2++) {
	    
	    grid[cnt1][cnt2] = 0;
	  }
	}
	
	// ????????????????????\??????
	for(int cnt1 = 0; cnt1 <= line; cnt1++) {
		
		if(cnt1 < line) {
			
			for(int cnt2 = 0; cnt2 <= column; cnt2++) {
				
				if(cnt2 < column) {
				
					scanf("%d", &grid[cnt1][cnt2]);
					printf("%d ", grid[cnt1][cnt2]);
					
					// ??????????????????????????????????¨??????\??????
					grid[cnt1][column] += grid[cnt1][cnt2];
					
					// ??????????????????????????????????¨??????\??????
					grid[line][cnt2] += grid[cnt1][cnt2];
				
				// ??????????¨??????????	
				} else {
					
					printf("%d\n", grid[cnt1][cnt2]);
					grid[line][column] += grid[cnt1][cnt2];
				}
			}
			
		} else {
			
			for(int cnt2 = 0; cnt2 <= column; cnt2++) {
			  
			  if(cnt2 != column) {
				
			  	printf("%d ", grid[cnt1][cnt2]);
				
			  } else {
			  
			   printf("%d\n", grid[cnt1][cnt2]);
			  }
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1820
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int di[] = {-1,0,1,0};
int dj[] = {0,1,0,-1};
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    int ans=0;
    for(int si = 0;si < h; si++){
        for(int sj = 0;sj < w; sj++){
            if(s[si][sj]=='#') 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.push(P(i,j));
            };
            update(si,sj,0);
            while(!q.empty()){
                int i= q.front().first;
                int j= q.front().second;
                q.pop();
                rep(dir,4){
                    int ni=i+di[dir],nj=j+dj[dir];
                    if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
                    if(s[ni][nj]=='#') continue;
                    update(ni,nj,dist[i][j]+1);
                }
            }
            rep(i,h){
                rep(j,w){
                    if(dist[i][j]==inf) continue;
                    ans=max(ans,dist[i][j]);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
from fractions import gcd
def Lcm(x):
  L = 1
  for a in x:
    a=a//2
    L = (a // gcd(a, L))*L
  return L
X=Lcm(A)
fg = 0
for i in A:
  if (X//(i//2))%2==0:
    fg=1
    break
if fg==1:
  print(0)
else:
  print(((M//X)+1)//2)

Measured memory_bytes: 14292
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

typedef pair<int,int> P;

signed main() {
	int H,W,N;
	cin >> H >> W >> N;
	vector<pair<int,int>> vec(N);
	for(int i = 0;i < N;i++) {
		int A,B;
		cin >> A >> B;
		vec.at(i) = make_pair(A - 1,B - 1);
	}
	map<P,int> ma;
  	for(auto x:ma) {
      	x.second = 0;
    }
	for(int i = 0;i < N;i++) {
		for(int j = -1;j <= 1;j++) {
			for(int k = -1;k <= 1;k++) {
				if(vec[i].first + j >= 1 && vec[i].second + k >= 1 && vec[i].first + j < H - 1 && vec[i].second + k < W - 1) {
					ma[P(vec[i].first + j,vec[i].second + k)] += 1;
				}
			}
		}
	}
	vector<int> ret(10);
	for(int i = 0;i < 10;i++) {
		ret.at(i) = 0;
	}
	for(auto x:ma) {
		ret.at(x.second)++;
	}
	int cnt = 0;
	for(int i = 1;i < 10;i++) {
		cnt += ret.at(i);
	}
	ret.at(0) = (H - 2) * (W - 2) - cnt;
	for(int i = 0;i < 10;i++) {
		cout << ret.at(i) << endl;
	}
}

Measured memory_bytes: 58112
#include<iostream>
#include<complex>
#include<cmath>
#include<vector>
#include<algorithm>

#define X real()
#define Y imag()

using namespace std;

typedef complex<double>P;
typedef vector<P>POL;

const double INF = 1e12;

namespace std{
  bool operator < (const P&a, const P& b){
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

struct Data{
  P p;
  bool mine,up;
  bool operator < (const Data &d)const{
    return p < d.p;
  }
};

struct L : public POL{
  L(){};
  bool mine,up;
  L(const P &a, const P &b){
    push_back(a); push_back(b);
  }
};

double cross(const P& a, const P& b){
  return imag(conj(a)*b);
}

double dot(const P& a, const P&b){
  return real(conj(a)*b);
}

int ccw(P a,P b,P c){
  b -= a; c -= a;
  if(cross(b,c) > 0)return 1;
  if(cross(b,c) < 0) return -1;
  if(dot(b,c) < 0) return 2;
  if(norm(b) < norm(c))return -2;
  return 0;
}

bool intersectSS(const L &s,const L&t){
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
    ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P intersection_ss(L line1, L line2){
  if(!intersectSS(line1,line2))return P(INF,INF);
  P a = line1[1] - line1[0]; P b = line2[1] - line2[0];
  return line1[0] + a * cross(b,line2[0]-line1[0]) / cross(b,a);
}

vector<Data>vec;
L line;

void input(){
  P p1,p2;
  cin >> p1.X >> p1.Y >> p2.X >> p2.Y;
  line = L(p1,p2);
  line.mine = true;

  int n;
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> p1.X >> p1.Y >> p2.X >> p2.Y;
    L l = L(p1,p2);
    cin >> l.mine >> l.up;
    if(intersectSS(line,l)){
      Data d;
      d.p = intersection_ss(line,l);
      d.mine = l.mine;
      d.up = l.up;
      vec.push_back(d);
    }
  }
}

int solve(){
  vec.clear();
  input();

  bool up;
  int res = 0;


  if(vec.size() == 0)return 0;

  sort(vec.begin(),vec.end());
  
  if(vec[0].mine) up = vec[0].up;
  else up = !vec[0].up;

  for(int i = 1 ; i < vec.size() ; i++){
    if(vec[i].mine){
      if(up != vec[i].up){
	up = !up;
	res++;
      }
    }
    else {
      if(up == vec[i].up){
	up = !up;
	res++;
      }
    }
  }
  return res;
}

int main(){
  int tc;
  cin >> tc;
  while(tc--){
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	ll x;
	cin >> x;
	ll now = 100;
	int cnt = 0;
	while(x > now){
		cnt++;
		now += now/100;
	}
	cout << cnt << endl;
}


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


int main(){
    ll N;
    cin >> N;
    vector<ll> d(N);
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }

    sort(d.begin(), d.end());

    if(N % 2 == 1 || d[N/2] == d[N/2 - 1]){
        cout << 0 << endl;
    }else {
        cout << abs(d[N/2] - d[N/2 - 1]) << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
  int N,K;
  cin >> N >> K;

  vector<int> H;
  H.reserve(N);
  
  for (int n=0; n<N; ++n) {
    int h;
    cin >> h;
    H.push_back(h);
  }

  sort(H.begin(), H.end());

  auto end = H.begin() + max(N-K,0);
  uint64_t ans = accumulate(H.begin(), end, uint64_t(0));
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: usize = read();
    let t: usize = read();
    if t > x {
        println!("0")
    } else {
        println!("{}", x - t);
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>
#include <list>
#include <bit>
#include <bitset>

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ui=unsigned int;

#define BUY 1
#define SELL 0

#define UP 0
#define DOWN 1
#define UNDEF 2

ll N;
ll price[81];
ll info[82];

int main()
{
  cin >> N;

  for(ll i = 0;i < N;i++)
  {
    cin >> price[i];
  }
  price[N] = price[N-1];
  ll sum = 1000;
  ll stock = 0;
  ll state = DOWN;

  ll n = 0;
  while(n < N)
  {
    if(state == DOWN)
    {
      if(price[n] < price[n+1])
      {
        stock += (sum / price[n]);
        sum -= stock * price[n];
        state = UP;
      }
    }
    else if(state == UP)
    {
      if(price[n] > price[n+1])
      {
        sum += price[n] * stock;
        stock = 0;
        state = DOWN;
      }
    }
    n++;
  }
  sum += stock * price[N - 1];
  cout << sum << endl;


  return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
using namespace std;
LL a,b,c,d;
int main() {
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	LL t=c*d/__gcd(c,d);
	printf("%lld",b-a+1-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/t-(a-1)/t));
	return 0;
}

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

int main() {
    int n,k,up,down,sum=1; cin>>n>>k;
    rep(i,n) {
        int up=(sum+k);
        int down=(sum*2);
        sum=min(up,down);
    }
  cout<<sum<<endl;
    return 0;
} 

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

int main(){
    long int N,A,B;
    cin>>N>>A>>B;
    long int hun,jan;
    hun=A+B;
    jan=(N/hun)*A;
    long int kan;
    kan=N%hun;
    if(kan>A){
        jan+=A;
    }
    else{
        jan+=kan;
    }
    cout<<jan<<endl;
}


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

int main(){
    int N;
    cin >> N;
    ll ans = 0;
    for (int i=1; i<=N; i++){
        if ((i % 3 == 0) || (i % 5 == 0)){
            // do nothing;
        } else{
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
  int n,nc=0;
  ll sum = 0,mini=1e9+7;
  cin >> n;
  rep(i,n){
      ll a;
      cin >> a;
      if(a < 0){
          nc++;
      }
      sum += abs(a);
      mini = min(mini,abs(a));
  }
  if(nc % 2 == 0){
      P(sum);
  }else{
      P(sum - (2*mini));
  }
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/

int num[3000];

/*ここからmain関数*/

int main()
{
	int H, W;
	char A[1000][1000];

	cin >> H >> W;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			cin >> A[i][j];
		}
	}

	queue<int> h, w;

	int B[1002][1002];
	for (int i = 0; i <= H + 1; i++)
	{
		for (int j = 0; j <= W + 1; j++)
		{
			if (i == 0 || i == H + 1 || j == 0 || j == W + 1) B[i][j] = 10000;
			else if (A[i - 1][j - 1] == '#')
			{
				B[i][j] = 0;
				h.push(i);
				w.push(j);
				num[0]++;
			}
			else B[i][j] = 3000;
		}
	}

	int fro = 0;
	//第i階層について
	while (num[fro] > 0)
	{
		for (int i = 0; i < num[fro]; i++)
		{
			int x = h.front();
			int y = w.front();

			if (B[x - 1][y] == 3000)
			{
				B[x - 1][y] = fro + 1;
				num[fro + 1]++;
				h.push(x - 1);
				w.push(y);
			}
			if (B[x + 1][y] == 3000)
			{
				B[x + 1][y] = fro + 1;
				num[fro + 1]++;
				h.push(x + 1);
				w.push(y);
			}
			if (B[x][y - 1] == 3000)
			{
				B[x][y - 1] = fro + 1;
				num[fro + 1]++;
				h.push(x);
				w.push(y - 1);
			}
			if (B[x][y + 1] == 3000)
			{
				B[x][y + 1] = fro + 1;
				num[fro + 1]++;
				h.push(x);
				w.push(y + 1);
			}

			h.pop();
			w.pop();
		}

		fro++;
	}

	cout << fro - 1;

	return 0;
}


Measured memory_bytes: 13312
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cassert>
#include<vector>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=5.3e5+20;
const int mod=924844033;

struct node {
	int v,next;
};
node e[maxn<<1];
int cnt,start[maxn];

inline void addedge(int u,int v){ e[++cnt]=(node){v,start[u]};start[u]=cnt;}
int n,sz[maxn],num[maxn],jc[maxn],jcn[maxn],inv[maxn];

inline void pls(int &a,int b){ a+=b;if(a>=mod)a-=mod;}

inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%mod;
		b>>=1;
		a=(ll)a*a%mod;
	}
	return ans;
}

void dfs(int u,int fa)
{
	sz[u]=1;
	EREP(i,u)
	{
		int v=e[i].v;
		if(v==fa)continue;
		dfs(v,u);
		sz[u]+=sz[v];
		pls(num[sz[v]],mod-1);
	}
	pls(num[n-sz[u]],mod-1);
}

inline void init()
{
	n=read();
	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;
	REP(i,2,n)jc[i]=(ll)i*jc[i-1]%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)inv[i]*jcn[i-1]%mod;
	REP(i,1,n-1)
	{
		int u=read(),v=read();
		addedge(u,v);
		addedge(v,u);
	}
	dfs(1,0);
	num[n]=n;
}

int st[maxn],rev[maxn];

inline void FFT(int *p,int n,int op)
{
	int l=0;
	while((1<<l)<n)l++;
	REP(i,1,n-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<l-1);
	REP(i,1,n-1)if(i<rev[i])swap(p[i],p[rev[i]]);
	for(int i=1;i<n;i<<=1)
	{
		int w=power(5,(mod-1)/(i<<1));
		st[0]=1; REP(j,1,i-1)st[j]=(ll)st[j-1]*w%mod;
		for(int j=0;j<n;j+=i<<1)
			for(int k=0;k<i;k++)
			{
				int x=p[j+k],y=(ll)st[k]*p[i+j+k]%mod;
				p[j+k]=x+y; if(p[j+k]>=mod)p[j+k]-=mod;
				p[i+j+k]=x-y; if(p[i+j+k]<0)p[i+j+k]+=mod;
			}
	}
	if(op==-1)
	{
		int inv=power(n,mod-2);
		REP(i,0,n-1)p[i]=(ll)inv*p[i]%mod;
		reverse(p+1,p+n);
	}
}

int f[maxn],g[maxn];

inline void doing()
{
	int N=1;
	while(N<=2*n)N<<=1;
	REP(i,0,n)f[i]=(ll)num[i]*jc[i]%mod,g[i]=jcn[i];
	f[0]=0;
	reverse(g,g+n+1);
	FFT(f,N,1); FFT(g,N,1);
	REP(i,0,N-1)f[i]=(ll)f[i]*g[i]%mod;
	FFT(f,N,-1);
	REP(i,1,n)printf("%lld\n",(ll)f[i+n]*jcn[i]%mod);
}

int main()
{
	init();
	doing();
	return 0;
}



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

int solve(int *str){
	int i,c=0;
	char st[100];
	for(i=0;i<100;i++){
		st[i]=0;
	}
	for(i=0;str[i]!='.';i++){
		switch(str[i]){
			case '(':
				st[c]=1;
				c++;
				break;
			case '[':
				st[c]=2;
				c++;
				break;
			case ')':
				if(st[c-1]!=1){
					return 0;
				}
				else {
					c--;
					st[c]=0;
				}
				break;
			case ']':
				if(st[c-1]!=2){
					return 0;
				}
				else {
					c--;
					st[c]=0;
				}
				break;
			default :
				break;
		}
	}
	if(st[0]==0){
		return 1;
	}
	else return 0;
}


int main(){
	
	while(1){
		int str[101];
		int c=0;

		while(str[c]=getchar()){
			if(str[c]=='\n')continue;
			if(str[c]=='.'){
				if(c==0){
					return 0;
				}
				break;
			}
			else{ c++;}
		}
		if(solve(str)){
			printf("yes\n");
		}
		else{
			printf("no\n");
		}
	}


}

Measured memory_bytes: 0
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn read_str_as_char_vec() -> Vec<char> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().chars().collect()
}

fn read_str_as_T<T>() -> T 
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().unwrap()
}

fn main() {
    let k: usize = read_line()[0];
    let in_vec: Vec<usize> = read_line();
    let a = in_vec[0];
    let b = in_vec[1];

    for i in a..=b {
        if i % k == 0 {
            println!("OK");
            return;
        }
    }
    println!("NG");
}


Measured memory_bytes: 2164