akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x.at(i);

    int ans = MOD;
    for (int p = 1; p <= 100; p++) {
        int now = 0;
        rep(i, n) now += (x.at(i) - p) * (x.at(i) - p);
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e10)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}

int N,M;
ll ans = INF;
ll H, W;
int main()
{
	cin >> H>>W;

	REP(h,1,H){
		ll s1 = h * W;
		ll s2 = (H - h) / 2 * W;
		ll s3 = H * W - s1 - s2;
		ll mi = min(s3,min(s1, s2));
		ll ma = max(s3,max(s1, s2));
		ll a = ma - mi;
		if(a<ans){
			ans = a;
		}
		s1 = h * W;
		s2 = (H - h)* (W-W/2);
		s3 = H * W - s1 - s2;
		mi = min(s3,min(s1, s2));
		ma = max(s3,max(s1, s2));
		a = ma - mi;
		if(a<ans){
			ans = a;
		}
	}

	ll tmp = W;
	W= H;
	H = tmp;

	REP(h,1,H){
		ll s1 = h * W;
		ll s2 = (H - h) / 2 * W;
		ll s3 = H * W - s1 - s2;
		ll mi = min(s3,min(s1, s2));
		ll ma = max(s3,max(s1, s2));
		ll a = ma - mi;
		if(a<ans){
			ans = a;
		}
		s1 = h * W;
		s2 = (H - h)* (W-W/2);
		s3 = H * W - s1 - s2;
		mi = min(s3,min(s1, s2));
		ma = max(s3,max(s1, s2));
		a = ma - mi;
		if(a<ans){
			ans = a;
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vc vector
#define a first
#define b second
#define pb push_back
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

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

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

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

void Main(){
  int N; cin >> N;
  vc<vc<int>> vv(10, vc<int>(10, 0));
  rep(i, 1, N + 1){
    int n = i;
    int h, t;
    t = n % 10;
    while(true){
      if(n >= 10){
        n /= 10;
      }else{
        h = n;
        break;
      }
    }
    vv[h][t] += 1;
  }
  int res = 0;
  rep(i, 0, 10){
    rep(j, 0, 10){
      res += vv[i][j] * vv[j][i];
    }
  }
  cout << res << endl;
}

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

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

  Main();

  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> H >> W;
	vector<string>s(H);
	vector<vector<int>>ans(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	int x[] = { 1,1,1,0,-1,-1,-1,0 };
	int y[] = { -1,0,1,1,1,0,-1,-1 };
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#') {
				for (int k = 0; k < 8; k++) {
					if (i + y[k] < 0 || i + y[k] >= H || j + x[k] < 0 || j + x[k] >= W) {
						continue;
					}
					ans[i + y[k]][j + x[k]]++;
				}
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j]=='#') {
				cout << s[i][j];
			}
			else {
				cout << ans[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}


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

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

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (L[i] == L[j]) { continue; }
            for (int k = j + 1; k < N; k++) {
                if (L[i] == L[k] || L[j] == L[k]) { continue; }
                if (L[i] + L[j] > L[k]) { ans++; }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
int y,m,d;
  char c1,c2;
  cin>>y>>c1>>m>>c2>>d;
  if(m<=4)
    cout<<"Heisei"<<endl;
  else
    cout<<"TBD"<<endl;
   return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<long long>> a(n, vector<long long>(2));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> a.at(i).at(j);
    }
  }
  vector<vector<long long>> b(m, vector<long long>(2));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> b.at(i).at(j);
    }
  }
  vector<vector<long long>> min(n, vector<long long>(2));
  for(int i=0;i<n;i++){
  	min.at(i).at(0)=pow(10,16);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if(min.at(i).at(0)>abs((a.at(i).at(0))-b.at(j).at(0))+abs(a.at(i).at(1)-b.at(j).at(1))){
        min.at(i).at(0) =abs(a.at(i).at(0)-b.at(j).at(0))+abs(a.at(i).at(1)-b.at(j).at(1));
        min.at(i).at(1)=j+1;
       }
    }
  }
  for(int i=0;i<n;i++){
  	cout << min.at(i).at(1) << endl;
  }
}




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

#define st              first
#define nd              second
#define pb              push_back
#define lwb             lower_bound
#define upb             upper_bound
#define all(a)          (a).begin(), (a).end()
#define Reset(s, n)     memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       (a).resize(unique(all(a)) - (a).begin())
#define bit(n, i)       (((n) >> (i)) & 1)
#define cntbit(n)       __builtin_popcountll(n)

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-12;
inline bool isPrime (ll x){ if(x <= 1) return 0; if(x <= 3) return 1; if (!(x % 2) || !(x % 3)) return 0; ll s = sqrt(1.0 * x) + EPS; for(ll i = 5; i <= s; i += 6){if (!(x % i) || !(x % (i + 2))) return 0;}return 1;}
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline void onbit(ll &a, int i){a |= 1LL << i;}
inline void offbit(ll &a, int i){onbit(a, i), a -= (1LL << i);}

const int N = 3e3 + 5;

int n, m, k;
ll a[N], b[N];
ll f[N][N][3];

void solve(){
   cin >> n;
   std::vector<pair<ll, ll>> b(n + 1);
   for(int i = 1; i <= n; i++){
      cin >> a[i];
      b[i] = {a[i], i};
   }
   b[0] = {INF, INF};
   sort(all(b), greater<pair<ll,ll>>());
   ll res = 0;
   for(int k = 1; k <= n; k++){
      ll x = b[k].st;
      ll y = b[k].nd;
      int len = n - k + 1;
      for(int i = 1; i + len - 1 <= n; i++){
         f[i][len][0] = max(f[i - 1][len + 1][0] + x * abs(y - i), 
                            f[i][len + 1][1] + x * abs(y - i));
         f[i][len][1] = max(f[i - 1][len + 1][0] + x * abs(y - (i + len - 1)), 
                            f[i][len + 1][1] + x * abs(y - (i + len - 1)));
         res = Max(res, f[i][len][0], f[i][len][1]);
      }
   }
   cout << res << "\n";

  

}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(10);
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   int query = 1;
   // cin >> query;
   int start = 1000 * clock() / CLOCKS_PER_SEC;
   while(query--) solve();
   cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC  - start << "ms\n";
}


Measured memory_bytes: 58632
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1e18;

int n, m;

typedef struct edge_ {
		int from, to, cost;
		edge_(int f, int t, int c): from(f), to(t), cost(c){};
} edge;

int par[501];
int r[501];

void init(){
		for(int i = 0; i < n; i++){
				par[i] = i;
				r[i] = 0;
		}
}

int find(int x){
		if(par[x] == x)return x;
		else return par[x] = find(par[x]);
}

void unite(int x, int y){
		int xp = find(x);
		int yp = find(y);
		if(xp == yp)return;
		if(r[xp] < r[yp])par[xp] = yp;
		else {
				par[yp] = xp;
				if(r[xp] == r[yp])r[xp]++;
		}
}

bool comp(const edge &ed1, const edge &ed2){
		return ed1.cost < ed2.cost;
}

vector<edge> vec;
vector<edge> ansvec;

ll kruscal(edge e){
	init();
	ll ans = 0;
	for(auto itr = vec.begin(); itr != vec.end(); ++itr){
			int from = (*itr).from;
			int to = (*itr).to;
			int cost = (*itr).cost;
			if(from == e.from && to == e.to)continue;
			if(find(from) != find(to)){
					ans += cost;
					unite(from, to);
					if(e.from == -1)ansvec.pb((*itr));
			}
	}
	return ans;

}

int main(int argc, char const* argv[])
{
	cin >> n >> m;
	for(int i = 0; i < m; i++){
			int s, t, u;
			cin >> s >> t >> u;
			s--; t--;
			vec.pb(edge(s, t, u));
	}
	sort(vec.begin(), vec.end(), comp);
	ll ans = kruscal(edge(-1, -1, -1));
	int num = 0;
	ll costsum = 0;
	for(auto itr = ansvec.begin(); itr != ansvec.end(); ++itr){
			ll thisans = kruscal(*itr);
			if(thisans != ans){
					num++;
					costsum += (*itr).cost;
			}
	}
	cout << num << " " << costsum << endl;
	return 0;
}



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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;


signed main(){
    int N, M;
    cin >> N >> M;
    vector<int> k(M), p(M);
    vector<vector<int>> s(M);
    rep(i,0,M) {
        cin >> k[i];
        s[i] = vector<int>(k[i]);
        rep(j,0,k[i]) cin >> s[i][j];
    }
    rep(i,0,M) cin >> p[i];
    int answer = 0;
    rep(i,0,1 << N) {
        bool isValid = true;
        rep(j,0,M) {
            int cnt = 0;
            rep(l,0,k[j]) {
                if (i & (1 << (s[j][l]-1))) cnt++;
            }
            if (cnt % 2 != p[j]) {
                isValid = false;
                break;
            }
        }
        if (isValid) answer++;
    }
    cout << answer << endl;
    return 0;
}


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

int main(){
int N, K;
string S;

cin >> N >> K >> S;

string ans="";

rep(i,N) {
    if (K-1 == i){
        if (S[i]=='A') ans += 'a';
        if (S[i]=='B') ans += 'b';
        if (S[i]=='C') ans += 'c';
    }
    else ans += S[i];
}

cout << ans << endl;

}


Measured memory_bytes: 256
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s: Vec<char> = s.trim().chars().collect();
    let n = s.len();
    let mut ans = 0;
    for i in 0..n {
        if s[i] != s[n - 1 - i] {
            ans += 1;
        }
    }
    ans /= 2;
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		scan.close();
		String nstr=String.valueOf(n);
		int sn=0;
		for(int i=0;i<nstr.length();i++) {
			sn+=Character.getNumericValue(nstr.charAt(i));
		}
		System.out.println((n%sn==0)? "Yes":"No");
	}
}

Measured memory_bytes: 23636
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

bool eq(double a, double b) {
    return abs(a - b) < 1e-14;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<long long> v(n);

    FOR(i, 0, n) {
        cin >> v[i];
    }
    vector<long long> dp(n + 1);
    vector<long long> cnt(n + 1);
    dp[0] = 0.0;
    cnt[0] = 1;


    // 整数でのDPをまずやる
    FOR(i, 1, n + 1) {
        RFOR(j, n, 1) {
            if (cnt[j - 1]) {
                if (dp[j - 1] + v[i - 1] > dp[j]) {
                    dp[j] = dp[j - 1] + v[i - 1];
                    cnt[j] = cnt[j - 1];
                }
                else if (dp[j - 1] + v[i - 1] == dp[j]) {
                    cnt[j] += cnt[j - 1];
                }
            }
        }
    }

    double maxx = 0.0;
    long long num = 0;
    IFOR(i, a, b) {
        double av = (long double)dp[i] / i;
        if (eq(av, maxx)) {
            num += cnt[i];
        }
        else if (av > maxx) {
            maxx = av;
            num = cnt[i];
        }
    }

    printf("%.14f\n%lld\n", maxx, num);
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	s := sc.Text()
	ans := 0
	for i := 0; i < 4; i++ {
		if s[i] == '+' {
			ans++
		} else {
			ans--
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
string s[100000];

int main() {

    int N;
    cin>>N;
    int c[4]={0};
    for(int i=0;i<N;i++){
        cin>>s[i];
        if(s[i] == "AC") c[0]++;
        if(s[i]=="WA")   c[1]++;
        if(s[i]=="TLE") c[2]++;
        if(s[i]=="RE")  c[3]++;
    }
    cout<<"AC x "<<c[0]<<'\n';
    cout<<"WA x "<<c[1]<<'\n';
    cout<<"TLE x "<<c[2]<<'\n';
    cout<<"RE x "<<c[3]<<'\n';


    return 0;
}

Measured memory_bytes: 6760
#include<bits/stdc++.h>
#define N 5009
#define P pair<int,int>
#define mm make_pair
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int tot,head[N],dp[N],root2,root1,b[N],tp,n,size[N];
ll f[N][N],jie[N],ni[N];
int mx,now;
inline ll rd(){
    ll x=0;char c=getchar();bool f=0;
    while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return f?-x:x;
}
inline ll pf(ll x){return x*x%mod;}
inline void MOD(ll &x){x=x>=mod?x-mod:x;}
inline ll C(int n,int m){return jie[n]*ni[m]%mod*ni[n-m]%mod;}
inline ll A(int n,int m){return jie[n]*ni[n-m]%mod;}
struct edge{int n,to;}e[N<<1];
inline void add(int u,int v){e[++tot].n=head[u];e[tot].to=v;head[u]=tot;}
inline ll power(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1)ans=ans*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ans;
}
void getroot(int u,int fa){
    size[u]=1;dp[u]=0;
    for(int i=head[u];i;i=e[i].n)if(e[i].to!=fa){
        int v=e[i].to;
        getroot(v,u);
        size[u]+=size[v];
        dp[u]=max(dp[u],size[v]);
    }
    dp[u]=max(dp[u],n-size[u]);
    if(dp[u]<mx){root1=u;root2=0;mx=dp[u];}
    else if(dp[u]==mx)root2=u;
}
int main(){
    mx=1e9;
    n=rd();
    jie[0]=1;
    for(int i=1;i<=n;++i)jie[i]=jie[i-1]*i%mod;ni[n]=power(jie[n],mod-2);
    for(int i=n-1;i>=0;--i)ni[i]=ni[i+1]*(i+1)%mod;
    int x,y;
    for(int i=1;i<n;++i){
        x=rd();y=rd();
        add(x,y);add(y,x);
    }
    getroot(1,0);
    if(root2){
      printf("%lld\n",pf(jie[n/2]));
      return 0;
    }
    for(int i=head[root1];i;i=e[i].n){
        int v=e[i].to;
        if(size[v]>size[root1])size[v]=n-size[root1];
        b[++tp]=size[v];
    }
    f[1][0]=1;
    int now=1,pre=0;
    int siz=0;
    for(int i=1;i<=tp;++i){
        swap(now,pre);
        siz+=b[i];
        memset(f[now],0,sizeof(f[now]));
        for(int j=0;j<=siz;++j)
            for(int k=0;k<=min(j,b[i]);++k)
                MOD(f[now][j]+=f[now^1][j-k]*C(b[i],k)%mod*A(b[i],k)%mod);
    }
    ll ans=0;
    for(int i=0;i<=siz;++i){
        if(i&1)MOD(ans+=f[now][i]*jie[n-i]%mod*(mod-1)%mod);
        else MOD(ans+=f[now][i]*jie[n-i]%mod);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
S=input()
if S=='SAT':
    print(1)
if S=='MON':
    print(6)
if S=='TUE':
    print(5)
if S=='WED':
    print(4)
if S=='THU':
    print(3)
if S=='FRI':
    print(2)
if S=='SUN':
    print(7)

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

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

	int n;cin >> n;
	vector<tuple<string,int,int>> sp;
	for(int i = 0; i < n; i++){
		string s;cin >> s;
		int p;cin >> p;
		sp.push_back(make_tuple(s,100-p,i+1));
	}

	sort(sp.begin(),sp.end());
	for(int i = 0; i < n; i++){
		cout << get<2>(sp[i]) << endl;
	}
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

const int mod = 1e9+7;
struct mint {
    ll x;
    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 {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (t == 0) 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 {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& i, mint& var) {
    ll tmp; i >> tmp;
    var.x = tmp;
    return i;
}
ostream& operator<<(ostream& o, const mint& var) {
    o << var.x;
    return o;
}

vector<mint> fac;
mint ncr(int n, int r) {
    if (fac.empty()) {
        int MAX_N = 2e6+10;
        fac.assign(MAX_N,1);
        for (int i = 0; i < MAX_N; ++i) {
            fac[i+1] = fac[i] * mint(i+1);
        }
    }
    return fac[n] / fac[n-r] / fac[r];
}

int main() {
    ll n, k; cin >> n >> k;
    vl a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    mint ans = 0;
    rep(i,n) {
        if (i >= k-1) ans += mint(a[i]) * ncr(i,k-1);
        if (n-i-1 >= k-1) ans -= mint(a[i]) * ncr(n-i-1,k-1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16640
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))


INF = 2147483647


import sys
stdin = sys.stdin

s =        ( stdin.readline().strip() )

c = s.find('C')
if -1 != c:
    f = s[c:].find('F')
    if f != -1:
        print "Yes"
        s = None

if s is not None:
    print "No"



Measured memory_bytes: 2696
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let ans = xs[0]+xs[1]+xs[2];
   if(ans<=21){
      console.log('win');
   }else{
      console.log('bust');
   }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 21064
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
		long countA = 0;
    long countB = 0;
    long countC = 0;
    bool answer = true;
    long maxCount = 0;
    long minCount = 0;

    for(long i = 0; i < s.Length; i++)
    {
      if(s[(int)i] == 'a') countA++;
      if(s[(int)i] == 'b') countB++;
      if(s[(int)i] == 'c') countC++;
    }

    if(countA == 0)
    {
      if(countB > 1 || countC > 1) answer = false;
    }
    if(countB == 0)
    {
      if(countA > 1 || countC > 1) answer = false;
    }
    if(countC == 0)
    {
      if(countB > 1 || countA > 1) answer = false;
    }
    if(countA>0 && countB>0 && countC>0)
    {
      maxCount = Math.Max(countA,countB);
      maxCount = Math.Max(maxCount,countC);
      minCount = Math.Min(countA,countB);
      minCount = Math.Min(minCount,countC);
      if(maxCount - minCount > 1) answer = false;
    }

    Console.WriteLine((answer) ? "YES" : "NO");
	}
}

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

using namespace std;

int const N = 5e5+10;
pair<int ,int > aa[N];
set<int > st;

int main() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>aa[i].second>>aa[i].first;
    sort(aa,aa+n);
    int day = 1;
    int an = 0;
    for(int i=1;i<=m;i++)st.insert(i);
    for(int i=n-1;i>-1;i--){
        auto v = st.upper_bound(m-aa[i].second+1);
        if(v==st.begin())continue;
        v--;
        st.erase(v);
        an+=aa[i].first;
    }
    cout<<an<<endl;
    return 0;
}






Measured memory_bytes: 5760
#include<stdio.h>
        #include<string.h>
        #include<math.h>
        int main(void)
        {
          int a,s,d,f,g,h,i,j;
          s=0;
          scanf("%d",&a);
          for(i=1;i<=9;i++){
            if(a%i==0&&a/i<=9){
              s=1;
              break;
            }
          }
          if(s==0) printf("No\n");
          else if(s==1) printf("Yes\n");
          return 0;
        }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(j, n) cout << a[j] << ((j<n-1) ? " " : "");
    cout << endl;

    FOR(i, 1, n) {
        int v = a[i];
        int j = i-1;
        while(j>=0 && a[j]>v) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        rep(j, n) cout << a[j] << ((j<n-1) ? " " : "");
        cout << endl;
    }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using ll = long long;
using namespace std;        
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define ar array


void solve(){
		double d,t,s;
		cin>>d>>t>>s;
		if(d/s<=t) cout<<"Yes";
		else cout<<"No";
		cout<<endl;

	

}

int main(){
	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
//	freopen("input.txt",r,"stdin");
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}





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

using namespace std;

vector<int> cut(vector<int>& card, int ft, int noc)
{
	vector<int>::iterator itr;
	for(itr = card.begin(); itr != card.end(); ++itr){
		if(*itr < ft){
			*itr += noc;
		}else if(*itr < ft + noc ){
			*itr -= ft - 1;
		}
	}
	//for(itr = card.begin(); itr != card.end(); ++itr)
		//cout << *itr <<endl;
	//cout << endl;
	return card;
}

int main(void)
{
	int num, cut_num, top;
	vector<int>::iterator itr;

	while(1){
		cin >> num >> cut_num;
		if(num == 0 && cut_num == 0){
			break;
		}

		vector<int> card;
		for(int i = 0; i < num; i++){
			card.push_back(i + 1);
		}

		for(int i = 0; i < cut_num; i++){
			int from_top, num_of_cards;
			cin >> from_top >> num_of_cards;
			card = cut(card, from_top, num_of_cards);
		}

		itr = card.begin();
		for(int i = 0; i < num; i++){
			if(*itr == 1){
				top = i;
				break;
			}
			itr += 1;
		}
		cout << num - top << endl;

	}
	return 0;
}

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

#define pb emplace_back
#define fi first
#define se second
#define m_p make_pair
#define vi vector<int>
#define pi pair<int, int>
#define mem(a,b) memset(a,b,sizeof(a))
#define el cout<<endl
#define sz(a) (int)a.size()
const int mod = (int)1e9+7;
typedef long long int ll;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = (int)1e5+5;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int x,y;
	cin>>x>>y;
	string ans = (y-2*x>=0 and (y-2*x)%2==0 and (4*x-y)>=0 and (4*x-y)%2==0)? "Yes": "No";
	cout<<ans<<endl;	
}

ll power(ll a,ll b, ll md=mod){
	ll r=1;
	while(b){
		if(b%2) 
			r=(r*a)%md;
		a=(a*a)%md;
		b>>=1;
	}
	return r;
}

Measured memory_bytes: 3640
/*Name - Rishabh Kumar Gupta 
   NIT Patna B.tech CSE 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	ll a,b;
	cin>>a>>b;
	ll ans=0;
	if(a>b)
		ans+=a,a-=1;
	else ans+=b,b-=1;
	if(a>b)
		ans+=a;
	else ans+=b;
	cout<<ans<<endl;

	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int num = s.size();
  int count = 0;
  //cout << num << endl;
  for(int i = 0; i < num; i++){
    if(s[i] == 'x'){
      count++;
    }
  }
  if(count >= 8){
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = 998244353;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



ll n, k, p[2020];

const int MAXS = 10010;
ll fact[MAXS+1], factr[MAXS+1], inv[MAXS+1];
ll comb(ll n, ll r) {
	if (fact[0]==0) {
		fact[0] = factr[0] = inv[1] = 1;
		for (int i=2; i<=MAXS; i++) inv[i] = inv[mod%i] * (mod-mod/i) %mod;
		for (int i=1; i<=MAXS; i++) fact[i] = fact[i-1]*i %mod, factr[i] = factr[i-1]*inv[i] %mod;
	}
	if (r<0 || n<r) return 0;
	return fact[n]*factr[r] %mod *factr[n-r] %mod;
}
ll hcomb(ll n, ll r) { return comb(n+r-1,r); }


signed main() {
	p[0] = 1;
	reps(i,1,2020) p[i] = p[i-1]*2 %mod;
	cin >> k >> n;
	reps(i,2,k*2+1) {
		ll x = 0, res = 0;
		reps(a,1,k+1) if (a<i-a && i-a<=k) x++;
		rep(y,x+1) {
			if (i%2==0) (res += comb(x,y)*p[y] %mod *(hcomb(k-x*2-1+y,n-y) + hcomb(k-x*2-1+y,n-y-1)) %mod) %= mod;
			else (res += comb(x,y)*p[y] %mod *hcomb(k-x*2+y,n-y) %mod) %= mod;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 512
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) {
    swap(a, b);
  }
  
  if (a == 1 && b == 2) {
    cout << 3 << endl;
  } else if (a == 1 && b == 3) {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n=0,i,max=0,count=0;
    scanf("%d",&n);
    int heignt[n];
    for(i=0;i<n;i++){
        scanf("%d",&heignt[i]);
        if(max<=heignt[i]) {
            max = heignt[i];
            count++;
        }
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 128
N = int(input())

ans = 0

if 1 <= N <= 9:
    print(N)
elif N <= 99:
    print(9)
elif N <= 999:
    print(9 + N - 99)
elif N <= 9999:
    print(909)
elif N <= 99999:
    print(909 + N - 9999)
else:
    print(90909)

Measured memory_bytes: 3060
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;

# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12



template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int n;
vector<pii> a;
int memo[120][120];
int dp(int l, int r)
{
	if (memo[l][r] != -1)return memo[l][r];
	if (l == r)return 0;
	int ans = INT_MAX;
	for (int i = l; i < r; i++)
	{
		ans = min(ans, dp(l, i) + dp(i+1, r)+a[l].first*a[i].second*a[i+1].first*a[r].second);
	}
	return memo[l][r] = ans;
}

int main()
{
	memset(memo, -1, sizeof memo);
	cin >> n;
	FOR(i, n)
	{
		pii p; cin >> p.first >> p.second;
		a.push_back(p);
	}
	cout << dp(0, n - 1) << endl;
}

Measured memory_bytes: 3120
let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let ( *@) a b = (a * b) mod 998244353 in
    let calc a b acc =
        let rec loop k i acc =
            if i = 0 then acc else
                let acc = if i mod 2 = 1 then acc *@ k else acc in
                let k = k *@ k in
                loop k (i / 2) acc
        in
        loop a b acc
    in
    let main () =
        let n = int_of_string (read_line ()) in
        let d = Array.of_list (split (read_line ())) in
        let r =
            if d.(0) <> 0 then 0 else (
                let hist = Array.make n 0 in
                Array.iter (fun v -> hist.(v) <- hist.(v) + 1) d;
                let dmax = Array.fold_left max 0 d in
                if hist.(0) <> 1 then 0 else (
                    let rec loop i acc =
                        if i = dmax then acc else loop (i + 1) (calc hist.(i) hist.(i + 1) acc)
                    in
                    loop 0 1
                )
            )
        in
        Printf.printf "%d\n" r
    in
    main ()

Measured memory_bytes: 15872
#include <iostream>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    pair<int, string> p[M];
    for (int i = 0; i < M; i++)
    {
        cin >> p[i].first >> p[i].second;
    }
    pair<bool, int> tf[N];
    for (int i = 0; i < N; i++)
    {
        tf[i].first = false;
        tf[i].second = 0;
    }
    int ac = 0;
    int wa = 0;
    for (int i = 0; i < M; i++)
    {
        if (!tf[p[i].first - 1].first)
        {
            if (p[i].second == "AC")
            {
                tf[p[i].first - 1].first = true;
                ac++;
            }
            else
            {
                tf[p[i].first - 1].second++;
            }
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (tf[i].first)
        {
            wa += tf[i].second;
        }
    }
    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int k, a, b;
    cin >> k;
    cin >> a >> b;
    string ans = "NG";
    for(int i = 0; i*k <= b; i++){
        if(i*k >= a && i*k <= b) ans = "OK";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
// 2150.cpp
//
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=110000;
const int MAX_P=100;

bool prime[MAX_N+1];
vector<int> t;
void sieve(){
  fill(prime,prime+MAX_N+1,1);
  prime[0]=prime[1]=0;
  for(int i=2;i<=MAX_N;++i){
    if(prime[i]){
      for(int j=i*2;j<=MAX_N;j+=i){
        prime[j]=0;
      }
      t.push_back(i);
    }
  }
}

int M(int n, int p){
  auto itr=upper_bound(t.begin(),t.end(),n);

  vector<int> sum;
  for(int i=0;i<p;++i)
    for(int j=i;j<p;++j)
      sum.push_back(*(itr+i) + *(itr+j));
  sort(sum.begin(),sum.end());
  return sum[p-1];
}
int main() {
  sieve();

  int n,p;
  while(cin>>n>>p){
    if(n==-1&&p==-1) break;
    cout<<M(n,p)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3268
def prime_factorization(n):
    """
    nを素因数分解
    :param n:
    :return:素因数分解結果 [(素数S1, count S1),(素数S2, count S2), ...]

    """
    from math import sqrt
    if (n == 0): return []
    if (n == 1): return [(1, 1)]

    res = []
    for i in range(2, int(sqrt(n)) + 1):
        if n == 1: break
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt > 0:
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))

    return res


class ModFactorial:
    """
    階乗, 組み合わせ, 順列の計算
    """

    def __init__(self, n, MOD=10 ** 9 + 7):
        """

        :param n: 最大の要素数.
        :param MOD:
        """
        kaijo = [0] * (n + 10)
        gyaku = [0] * (n + 10)

        kaijo[0] = 1
        kaijo[1] = 1
        for i in range(2, len(kaijo)):
            kaijo[i] = (i * kaijo[i - 1]) % MOD
        gyaku[0] = 1
        gyaku[1] = 1
        for i in range(2, len(gyaku)):
            gyaku[i] = pow(kaijo[i], MOD - 2, MOD)
        self.kaijo = kaijo
        self.gyaku = gyaku
        self.MOD = MOD

    def nCm(self, n, m):
        return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD

    def nPm(self, n, m):
        return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD

    def factorial(self, n):
        return self.kaijo[n]


N, M = [int(_) for _ in input().split()]
if M == 1:
    print(1)
    exit()

primes = [v for _, v in prime_factorization(M)]

MOD = 10 ** 9 + 7
mf = ModFactorial(max(primes) + 1 + N, MOD)

ans = 1
for cnt in primes:
    ans = ans * mf.nCm(cnt + N - 1, N - 1)
    ans = ans % MOD
print(ans)


Measured memory_bytes: 16968
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------


string x;

stack<int> st;

int main(){
    //cout<<"aaa";
    cin>>x;
    int ans=0;
    int len=x.length();

    REP(i,len){
        if(x[i]=='S'){st.push(1);}
        else{
            if(st.empty())st.push(2);
            else if(st.top()==2)st.push(2);
            else st.pop();
        }
    }



    cout<<st.size();
    


    return 0;
}

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


int main()
{
	int a,b,c,x; cin >>a>>b>>c>>x;
	int ans = 0;
	for (int i = 0; i <= a; ++i)
		for (int j = 0; j <= b; ++j)
			for (int k = 0; k <= c; ++k)
				if (500*i+100*j+50*k == x) ans++;
	cout << ans << endl;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;

#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define ROF(i, a, b) for(int i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

ll st[MAXN], sz;

void update(ll x, ll val){
    x+=sz;
    st[x]=val;
    while (x){
        x/=2;
        st[x] = max(st[x<<1], st[x<<1|1]);
    }
    return;
}

ll query(ll a, ll b){
    a+=sz, b+=sz;
    ll res=0;
    for (; a<b; a>>=1, b>>=1){
        if (a&1) res = max(res, st[a++]);
        if (!(b&1)) res = max(res, st[b--]);
    }
    if (a==b) res = max(res, st[a]);
    return res;
}

int main(){
    FAST
    ll n;
    vector<ll> v;
    cin >> n;

    v.pb(0);
    FOR(i,1,n){
        ll x;
        cin >> x;
        v.pb(x);
    }

    if (n%2){
        ll ans=-INF;
        ll sum=0;
        for (int i=2; i<n; i+=2){
            sum += v[i];
        }

        ans = max(ans, sum);

        sz = n/2;
        ll left[sz+1], right[sz+1];

        for (int i=1; i<=sz; i++){
            left[i] = v[i*2-1] - v[i*2];
            right[i] = v[i*2+1] - v[i*2];
        }

        for (int i=sz; i; i--){
            if (i==sz) update(i-1, right[i]);
            else {
                right[i] += right[i+1];
                update(i-1, right[i]);
            }
        }

        left[0] = 0;
        ll change=0;
        for (int i=0; i<=sz; i++){
            change += left[i];
            ll maxx = query(i,sz-1);
            ll final = sum + change + maxx;
            ans = max(ans, final);
        }

        cout << ans;


    } else {
        ll ans=-INF;
        ll sum=0;
        for (int i=1; i<n; i+=2){
            sum += v[i];
        }
        ans = max(ans, sum);
        for (int i=n; i; i-=2){
            sum-=v[i-1];
            sum+=v[i];
            ans = max(ans, sum);
        }

        cout << ans;
    }
}

Measured memory_bytes: 7956
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define m0(x) memset(x, 0, sizeof(x))
#define fill(x, y) memset(x, y, sizeof(x))

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

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

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vlint a(n+1); rep1(i, n+1) cin >> a[i];
    vlint b(m+1); rep1(i, m+1) cin >> b[i];

    rep1(i, n+1){
        a[i] += a[i-1];
    }
    lint ans = 0;
    lint time = 0;
    rep(i, m+1){
        time += b[i];
        if (k-time < 0) break;
        chmax(ans, i + ub(a, k-time)-1);
    }
    cout << ans << endl;

}


Measured memory_bytes: 6432
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
bool vis[1003][1003];
int ans=0;
int dist[1003][1003],dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
int main(){
	int n,m;
	cin>>n>>m;
	queue <int> qu,qv;
	for(int i=0;i<n;i++)
		for (int j=0;j<m;j++){
			char c;
			cin>>c;
			dist[i][j]=1e9;
			if (c=='#'){
				vis[i][j]=1;
				qu.push(i);
				qv.push(j);  
				dist[i][j]=0;
			}
		}
	while (!qu.empty()){
		int x=qu.front(),y=qv.front();
		qu.pop(),qv.pop();
		for (int i=0;i<4;i++){
			int u=x+dir[i][0],v=y+dir[i][1];
			if (u<0 || v<0 || u>=n || v>=m) continue;
			if (dist[u][v]>dist[x][y]+1){
				dist[u][v]=dist[x][y]+1;
				qu.push(u),qv.push(v);  
			}
		}
		ans=max(ans,dist[x][y]);
	}
	cout<<ans;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
        int M1,D1,M2,D2;

        cin >> M1 >> D1 >> M2 >> D2;
        if(M1 != M2) cout << 1;
        else cout << 0;
        cout << endl;
        return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k, sum int
	_, _ = fmt.Scan(&n, &k)
	var p = make([]int, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&p[i])
	}
	sort.Ints(p)

	for i := 0; i < k; i++ {
		sum += p[i]
	}
	fmt.Println(sum)
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll l, r;
  cin >> l >> r;
  ll ans = 2020;
  if(r-l>=2019){
    r = l + 2019;
  }
  for (ll i = l; i <= r - 1; ++i) {
    for (ll j = l + 1; j <= r; ++j) {
      ans = min(ans, i * j % 2019);
    }
  }

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


Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())

    if n==0 and x==0 :
        break
    else:
        count = 0
        for i in range(1,n-1):
            for j in range(i+1,n):
                if j < x-i-j <= n:
                    count += 1
    print(count)



Measured memory_bytes: 5596
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main(){
        long long N , ans = 0;
        cin>>N;
        vector<long long>A(N+1),B(N);
        for(int i=0;i<N+1;i++) scanf("%ld",&A[i]);
        for(int j=0;j<N;j++){
                scanf("%ld",&B[j]);
                if(A[j]>=B[j]) ans += B[j];
                else{
                        if(A[j+1] >= B[j]-A[j]){
                                ans += B[j];
                                A[j+1] -= B[j]-A[j];
                        }
                        else{
                                ans += A[j];
                                ans += A[j+1];
                                A[j+1] = 0;
                }
        }
        }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792