akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define INF 1000000007
#define SMO -1000000007
using namespace std;
bool prime(int n){
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0)return false;
	}
	return n!=1;
}
int kaicnt;
int kai(int n,int x){
	kaicnt++;
	if(kaicnt==x){
		kaicnt=0;
		return n%INF;
	}
	return (kai(n-1,x)%INF*n)%INF;
}
int conbi(int n,int x){
	x=min(x,n-x+1);
	return kai(n,x)/kai(x,x);
}
int n,a[100005],ans;
signed main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		ans+=a[i]/2;
		a[i]-=a[i]/2*2;
		if(a[i]&&i<n-1){
			if(a[i]<a[i+1]){
				a[i+1]-=a[i];
				ans+=a[i];
			}else {
				ans+=a[i+1];
				a[i+1]=0;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

#define INF 100000

int n, x, m[INF], ans;

void solve()
{
    ans = 0;

    int mini = INF;
    for (int i = 0; i < n; i++) {
        int temp = m[i];
        x -= temp;
        if (temp < mini) mini = temp;
    }
    ans += n;

    ans += x/mini;
}

int main()
{
    scanf("%d%d", &n, &x);
    for (int i = 0; i < n; i++) {
        int temp;
        scanf("%d", &temp);
        m[i] = temp;
    }

    solve();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input()
b=input()
c=input()
abc=list('0'*n)
for i in range(n):
    if a[i]==b[i]:
        abc[i]=a[i]
    if b[i]==c[i]:
        abc[i]=b[i]
    if c[i]==a[i]:
        abc[i]=c[i]
    if abc[i]=='0':
        abc[i]=a[i]
count=0
for i in range(n):
    if a[i]!=abc[i]:
        count+=1
    if b[i]!=abc[i]:
        count+=1
    if c[i]!=abc[i]:
        count+=1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i,j,k;
	cin >> n;
	long long int sum =0;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				sum = sum + __gcd(i,__gcd(j, k) ); 
			}
		}
	}
	cout << sum << endl;
}

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

a=list(map(int,input().split()))
sum=0
b=[]
for i in range(N):
    b.append(2*a[i])
    sum+=a[i]

ans=[]
a_1=0
for j in range((N-1)//2):
    a_1-=b[2*(j+1)-1]

a_1=sum+a_1
ans.append(a_1)
for i in range(N-1):
    ans.append(b[i]-ans[i])

for j in range(N):
    print(ans[j])

Measured memory_bytes: 16068
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#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 MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    COMinit();
    int N,K;cin>>N>>K;
    FOR(i,1,K+1){
        cout<<(COM(N-K+1,i)*COM(K-1,i-1))%MOD<<endl;
    }
}

Measured memory_bytes: 12160
import sys
import bisect
readline = sys.stdin.buffer.readline

"""素数判定はこっち"""
def factrize(n):
    b = 2
    while b*b <= n:
        if n % b == 0:
            return False
        b = b+1
    return True

f = []

for i in range(3,10**5+2,2):
    if factrize(i):
        if factrize((i+1)//2):
            f.append(i)
q = int(readline())
for _ in range(q):
    l,r = map(int,readline().split())
    print(bisect.bisect(f,r)-bisect.bisect(f,l-1))

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


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

using namespace std;

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

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

string S;
ll com[100010];//0~i-1桁の組み合わせ
ll dp[100010];
vector<int>v;
ll func(int n) {
	if (dp[n] != 0) {
		return 0;
	}
	auto itr = lb(v, n);
	if (itr == v.begin()) {
		return add(2, com[n]);
	}
	else {
		itr--;
		return add(com[n], mult(2,func(*itr)));
	}
}

signed main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);*/
	cin >> S;
	com[0] = 1;
	REP(i, 100009) {
		com[i + 1] = mult(com[i], 3);
	}
	int N = S.size();
	VREVERSE(S);
	REP(i, N) {
		if (S[i] == '1') {
			v.pb(i);
		}
	}
	VSORT(v);
	int M = v.size();
	ll ans = func(v[M - 1]);
	print(ans);

}


Measured memory_bytes: 3700
#include<iostream>
#include<iomanip>

using namespace std;

void Main(){
  int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
}

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  Main();
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,x;
	i=0;
	while(i<10000)
	{
		i++;
		scanf("%d",&x);
		printf("Case %d: %d\n",i,x);
		
		((x>1)&&(x<10000));
		if(x==0)break;
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <climits>
#include <cmath>
#include <stdlib.h>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<int> dp(n);
    dp[0] = 0;

    for (int i = 1; i < n; i++)
    {
        dp[i] = INT_MAX;
        for (int j = i - 1; j >= 0 && j >= i - k; j--)
        {
            dp[i] = min(dp[i], dp[j] + abs(v[j] - v[i]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

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

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

  vector<int> cards(N);
  for (int i=0; i<N; i++){
    cin >> cards.at(i);
  }

  int score=0;
  int max,wheremax;
  
  for (int i=0; i<N; i++){
    max=0;
    wheremax=0;
    for (int j=0; j<N; j++){
      if(max < cards.at(j)){
        max = cards.at(j);
        wheremax = j;
      }
    }
    cards.at(wheremax) = 0;
    if(i%2 == 0)
      score += max;
    else
      score -= max;
  }
  cout << score << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/

struct point {int h, w;};

int dh[] = {0, 1, 0, -1};
int dw[] = {1, 0, -1, 0};
/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int H, W;
	point s, g;
	cin >> H >> W >> s.h >> s.w >> g.h >> g.w;

	s.h--; s.w--; g.h--; g.w--;

	vector<string> maze(H);
	vector<vector<int>> cost(H, VI(W, INF));
	cost[s.h][s.w] = 0;

	REP(i, H) { cin >> maze[i]; }

	deque<point> dq;

	dq.push_front(s);

	while (!dq.empty()) {
		point now = dq.front(); dq.pop_front();

		REP(i, 4) {
			int nh = now.h + dh[i];
			int nw = now.w + dw[i];
			if (nh < 0 || nw < 0 || nh >= H || nw >= W)continue;
			if (maze[nh][nw] == '#')continue;
			else if (cost[nh][nw] > cost[now.h][now.w]) {
				cost[nh][nw] = cost[now.h][now.w];
				point u; u.h = nh; u.w = nw;
				dq.push_front(u);
			}
		}

		FOR(eh, -2, 2)FOR(ew, -2, 2) {
			int nh = now.h + eh;
			int nw = now.w + ew;
			if (nh < 0 || nw < 0 || nh >= H || nw >= W)continue;
			if (maze[nh][nw] == '#')continue;
			else if (cost[nh][nw] > cost[now.h][now.w] + 1) {
				cost[nh][nw] = cost[now.h][now.w] + 1;
				point u; u.h = nh; u.w = nw;
				dq.push_back(u);
			}
		}
		//被りを気にしていないのがポイント
	}
	if ( cost[g.h][g.w] == INF )cout << -1 << endl;
	else cout << cost[g.h][g.w] << endl;

	return 0;
}











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

int main(){
    ll k, q;
    cin >> k >> q;
    ll dd[k], d[k], n, x, m;
    REP(i, k) cin >> dd[i];

    REP(i, q){
        cin >> n >> x >> m;
        x %= m;
        ll s = 0;
        ll c = 0;
        REP(i, k) {
            d[i] = dd[i] % m;
            s += d[i];
            if(d[i] == 0) c++;
        }
        s *= (n-1)/k;
        c *= (n-1)/k;
        REP(i, (n-1)%k) {
            s += d[i];
            if(d[i] == 0) c++;
        }
        ll a = (x+s)/m + c;
        a = (n - 1) - a;
        cout << a << endl;
    }
} 

Measured memory_bytes: 384
a = list()
n = int(input())

for i in range(120):
    a.append(0)

for i in range(n):
    b,f,r,v = map(int,input().split())
    a[(b-1)*30 + (f-1)*10 + (r-1)] += v
    
for i in range(4):
    if i >= 1:
        print("#" * 20)
    for j in range(3):
        for k in range(10):
            print(' ', end = '')
            print(a[i * 30 + j * 10 + k], end = '')
        print()
    



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

S=input()


def getShiftedStr(args,num):
    ConverseCode=''
    for i in args:
        t=ord(i)
        t+=num
        if t>90:
            t-=26
        new=chr(t)
        ConverseCode+=new
    print(ConverseCode)


getShiftedStr(S,N)





Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(ll i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(ll i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

#define print(d, arr) REP(i, d) cout << arr[i] << " "; cout << endl;
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }

#define INF (1000000000)

struct edge {
    ll u, v, cost;
};

ll V, E;
edge es[100000];

class UnionFind {
private:
    vector<ll> dataArray;
public:
    UnionFind(size_t size): dataArray(size, -1) {}
    void unite(ll lhs, ll rhs) {
        lhs = root(lhs);
        rhs = root(rhs);
        bool isUnion = (lhs != rhs);
        if (isUnion) {
            if (dataArray[lhs] > dataArray[rhs] ) {
                swap(lhs, rhs);
            }
            dataArray[lhs] += dataArray[rhs];
            dataArray[rhs] = lhs;
        }
        return;
    }
    
    ll root(ll id) {
        if (dataArray[id] >= 0) {
            return dataArray[id] = root(dataArray[id]);
        } else {
            return id;
        }
    }
    
    bool same(ll lhs, ll rhs) {
        return (root(lhs) == root(rhs));
    }
};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

int main() {
    cin >> V >> E;
    UnionFind uf(V);
    
    ll s, t, w;
    REP(i, E) {
        edge e;
        cin >> s >> t >> w;
        e.u = s;
        e.v = t;
        e.cost = w;
        es[i] = e;
    }
    
    sort(es, es + E, comp);
    
    ll ans = 0;
    REP(i, E) {
        edge e = es[i];
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            ans += e.cost;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

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

    int n, t;
    cin >> n >> t;
    SegmentTree<int> seg(n, [](int a, int b){return max(a, b);}, 0);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        seg.set(i, a);
    }
    seg.build();
    int maxval = 0;
    for(int i = 0; i + 1 < n; ++i){
        int val = seg.query(i + 1, n);
        chmax(maxval, val - seg[i]);
    }
    int ans = 0;
    for(int i = 0; i + 1 < n; ++i){
        int val = seg.query(i + 1, n);
        if(val - seg[i] == maxval)  ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4236
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define N 1005
#define M 200005
using namespace std;
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
int n,m,a[N][N],x[M],y[M],z[M],vis[N],p[N][N],q[N][N];
vector<int> e[N];
void dfs(int st,int u){
	vis[u]=1; a[st][u]=1;
	rep (i,0,(int)e[u].size()-1){
		int v=e[u][i]; if (!vis[v]) dfs(st,v);
	}
}
void dfs1(int st,int u,int id){
	vis[u]=1; p[st][u]=id;
	rep (i,0,(int)e[u].size()-1){
		int v=e[u][i]; if (!vis[v]) dfs1(st,v,id);
	}
}
void dfs2(int st,int u,int id){
	vis[u]=1; q[st][u]=id;
	rep (i,0,(int)e[u].size()-1){
		int v=e[u][i]; if (!vis[v]) dfs2(st,v,id);
	}
}
int main(){
	n=read(); m=read();
	rep (i,1,m){
		x[i]=read(),y[i]=read(); z[i]=(int)e[x[i]].size();
		e[x[i]].push_back(y[i]);
	}
	rep (i,1,n){
		memset(vis,0,sizeof(vis));
		dfs(i,i);
	}
	rep (i,1,n){
		memset(vis,0,sizeof(vis)); vis[i]=1;
		rep (j,0,(int)e[i].size()-1) if (!vis[e[i][j]]) dfs1(i,e[i][j],j);
		memset(vis,0,sizeof(vis)); vis[i]=1;
		per (j,(int)e[i].size()-1,0) if (!vis[e[i][j]]){
			dfs2(i,e[i][j],j);
		}
	}
	//printf("%d\n",a[3][1]);
	//printf("%d %d\n",p[1][3],q[1][3]);
	//printf("%d\n",a[4][3]);
	//printf("%d %d\n",p[3][4],q[3][4]);
	rep (i,1,m){
		bool f1=a[y[i]][x[i]];
		bool f2=p[x[i]][y[i]]!=z[i] || q[x[i]][y[i]]!=z[i];
		if (f1==f2) puts("same"); else puts("diff");
	}
	return 0;
}

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

int main() {
  int n, m; cin >> n >> m;
  vector<pair<int, int>> ab(n);
  rep(i, n) cin >> ab[i].first >> ab[i].second;

  sort(all(ab));
  priority_queue<int> pq;
  int ans = 0;
  int index = 0;
  for (int i = m - 1; i >= 0; i --) {
    while (ab[index].first <= m - i) {
      pq.push(ab[index].second);
      index ++;
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1660
N,M = map(int,input().split())
S = [list(map(int,input().split())) for n in range(N)]
P = [list(map(int,input().split())) for m in range(M)]

for a,b in S:
  D = []
  for c,d in P:
    D.append(abs(a-c)+abs(b-d))
  print(1+D.index(min(D)))

Measured memory_bytes: 9200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();

            if(m == -1 && f == -1 && r == -1 ) break;

            if( m == -1 || f == -1 ){
                System.out.println("F");
            } else if(m+f >= 80){
                System.out.println("A");
            } else if(m+f >= 65){
                System.out.println("B");
            } else if(m+f >= 50 || r >= 50){
                System.out.println("C");
            } else if(m+f >= 30){
                System.out.println("D");
            } else {
                System.out.println("F");
            }
        }
    }
}

Measured memory_bytes: 26244
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define mp make_pair
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005  //check the limits, man
const ll INF = 1e18;
int main()
{
    ll x,n,m;
    cin >> n >> m;
    x=min(n,m/2);
    n-=x,m-=(2*x);
    if(n==0)
        x+=(m/4);
    llout(x);
}




Measured memory_bytes: 256
read A
read B
read C
read X

count=0

for (( a = 0; a <= A; a++ )); do
    for (( b = 0; b <= B; b++ )); do
        for (( c = 0; c <= C; c++ )); do
            (( a * 500 + b * 100 + c * 50 == X )) && count=$((count + 1))
        done
    done
done

echo ${count}


Measured memory_bytes: 376
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+5;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
#define eps 1e-6
ll a[200005];
int main()
{
	int n;sca(n);
	ll ans;
	for(int i=0;i<n;i++)
	{
		scall(a[i]);
	}
	ans=a[0];
	for(int i=1;i<n;i++)
	ans=ans^a[i];
	for(int i=0;i<n;i++)
	printf("%lld ",ans^a[i]);
	cout<<endl;
 } 

Measured memory_bytes: 5268
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

/**
 * Hokkaido Univ.& Hitachi 2nd New-concept Computing Contest 2017
 *
 * @author tsukammo
 */
public class Main {
	FastScanner in = new FastScanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);;

	void solve() {
		String S = in.next();
		char[] c = S.toCharArray();
		int ans = 0;
		for (int i = 0; i < c.length; i++) {
			if(c[i]=='1'){
				ans++;
			}
		}
		out.print(ans);
	}

	public static void main(String[] args) throws IOException {
		new Main().solve();
		out.flush();
	}

	// library
	class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		FastScanner(InputStream in) {
			this.in = in;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	class Random {
		private long seed;
		private final long multiplier = 0x5DEECE66DL, addend = 0xBL,
				mask = (1L << 48) - 1;
		int bits, val;

		Random(long seed) {
			this.seed = seed;
		}

		int nextInt(int n) {
			do {
				bits = (int) ((seed = (seed * multiplier + addend) & mask) >>> 17);
				val = bits % n;
			} while (bits - val + (n - 1) < 0);
			return val;
		}

		double nextDouble() {
			return nextInt(10000000) / 10000000.0;
		}
	}

	static final int PONIT_CONNECT = 1;
	static final long TL = 9000;
	static boolean debug = false;
	static boolean cut = false;
	static boolean submit = true;
}

Measured memory_bytes: 20692
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){
    
    string s;
    cin >> s;

    int start = 0;
    int end = 0;
    bool flg = 0;

    for(int i = 0; i <s.size(); i++){
        
        if(s[i] == 'Z') end = i;

        if(!flg && s[i] == 'A') {
            start = i;
            flg = 1;
        }

    };

    int cnt =0;
    if(flg)  cnt = end - (start-1); 
    else cnt = end - start;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  ll ans = 0;
  rep(i, 0, N + 1) rep(j, 0, N + 1) {
    int tot = R * i + G * j;
    if(tot > N) continue;
    int k = N - tot;
    if(k % B == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])
C = [0] * 101010
S = [0] * 101010

for a in A[::-1]:
    C[a] += 1
    S[a] += a
for i in range(101000)[::-1]:
    C[i] += C[i+1]
    S[i] += S[i+1]

def cnt(n):
    re = 0
    for a in A:
        b = min(max(n-a, 0), 101000)
        re += C[b]
    return re
def calc(n):
    re = 0
    for a in A:
        b = min(max(n-a, 0), 101000)
        re += S[b]  + C[b] * a
    return re

l, r = 0, 200001
while r - l > 1:
    m = (l+r) // 2
    if cnt(m) >= M:
        l = m
    else:
        r = m

print(calc(l) - (cnt(l) - M) * l)

Measured memory_bytes: 54924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> x(N), y(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> x.at(i) >> y.at(i);
  }

  vector<ll> P(N);
  for (ll i = 0; i < N; i++)
  {
    P.at(i) = i;
  }

  long double sum = 0;
  do
  {
    for (ll i = 0; i < N - 1; i++)
    {
      long double x0 = x.at(P.at(i)), x1 = x.at(P.at(i + 1));
      long double y0 = y.at(P.at(i)), y1 = y.at(P.at(i + 1));

      long double tmp = sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
      sum += tmp;
      //cerr << tmp << endl;
    }

  } while (next_permutation(P.begin(), P.end()));

  long double ans = sum;
  for (ll i = 1; i <= N; i++)
  {
    ans /= i;
  }
  cout << fixed << setprecision(15) << ans << endl;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int N;
  while(cin >> N, N){
    int cnt = 0;
    for(int i = 3; i <= N; i+=2){
      if(N % i == 0)cnt++;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 2976
N = int(input())
a = list(map(int, input().split()))
dp = [[0]*N for _ in range(N)]

for l in range(N):
    for i in range(N):
        j = i+l
        
        if j>=N:
            continue
        
        if (N-l-1)%2==0:
            if i==j:
                dp[i][j] = a[i]
            else:
                dp[i][j] = max(dp[i+1][j]+a[i], dp[i][j-1]+a[j])
        else:
            if i==j:
                dp[i][j] = -a[i]
            else:
                dp[i][j] = min(dp[i+1][j]-a[i], dp[i][j-1]-a[j])
    
print(dp[0][N-1])

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back
#define ins insert

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

#define MAX 100010
int n;
ll A[MAX], B[MAX];


void compute() {

}

struct Data {
  int i;
  ll a,b;
  bool operator < ( const Data &data ) const {
    return a+b > data.a+data.b;
  }
};

int main() {
  cin >> n;
  rep(i,n) cin >> A[i] >> B[i];
  vector<Data> vec;
  rep(i,n) vec.push_back((Data){i,A[i],B[i]});
  sort(ALL(vec));
  ll chok = 0, aoki = 0;
  rep(i,n) {
    if( ( i & 1) ) aoki += vec[i].b;
    else           chok += vec[i].a;
  }
  cout << chok - aoki << endl;
  compute();
  return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

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

	int n;
	cin >> n;
	vector<double> v(n);
	rep(i, n){
		cin >> v[i];
	}

	sort(all(v));

	double ans = v[0];
	rept(i, 1, n){
		ans = (ans + v[i]) / 2.0;
	}

	cout << fixed;	
	cout << setprecision(6) << ans << endl;


    return 0;
}



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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    int n, m;
    cin >> n >> m;
    //vector<vector<bool>> check;
    vector<vector<int>> root;
    vector<int> h;
    rep(i, n){
        vector<int> c;
        // rep(j, n){
        //     c.push_back(false);
        // }
        root.push_back(c);
    }
    rep(i, n){
        int height;
        cin >> height;
        h.push_back(height);
    }
    rep(i, m){
        int a, b;
        cin >> a >> b;
        root[a-1].push_back(b-1);
        root[b-1].push_back(a-1);
        // check[a-1][b-1] = true;
        // check[b-1][a-1] = true;
    }
    int ans=n;
    rep(i, n){
        rep(j, root[i].size()){
            int enemy = root[i][j];
            if(h[i]<=h[enemy]){
                ans--;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8768
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


typedef unsigned long long ll;

vector<vector<ll> > lines;
int n;
int field[9][9];

vector<ll> tmp;

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

bool ok=false;

ll fin;


void dfs(ll s,int idx){
	if(ok){
		return;
	}
	if(idx==lines.size()){
		if(fin==s)
			ok=true;
		return;
	}
	for(int i = 0; i < lines[idx].size(); i++){
		if((s&lines[idx][i])==0){
			dfs(s|lines[idx][i],idx+1);
		}
	}
}

void lineSearch(ll s,int curSum,int ret,int x,int y){
	if(curSum==ret){
		tmp.push_back(s);
	}
	for(int i= 0; i < 4; i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx>=0&&ny>=0&&nx<n&&ny<n&&field[ny][nx]>=1&&(curSum+field[ny][nx]<=ret)){
			if(!((s>>(ny*n+nx))&(1ull))){
				ll ns=s|(((1ull)<<(ny*n+nx)));
				lineSearch(ns,curSum+field[ny][nx],ret,nx,ny);
			}
		}
	}
}

int main(){


	while(cin>>n&&n!=0){
		fin=0;
		for(int i = 0; i < n*n; i++){
			fin|=(1ull<<i);
		}

		ok=false;
		lines.clear();
		vector<pair<int,pair<int,int> > > vpii;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin>>field[i][j];
				if(field[i][j]<0){
					vpii.push_back(make_pair(field[i][j],make_pair(i,j)));
				}
			}
		}
		for(int i = 0; i < vpii.size(); i++){
			tmp.clear();
			if(i==5){
				//cout<<endl;
			}

			lineSearch(((1ull)<<(vpii[i].second.first*n+vpii[i].second.second)),0,-vpii[i].first,vpii[i].second.second,vpii[i].second.first);
			lines.push_back(tmp);
		}
		dfs(0ull,0);
		if(ok)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}

	return 0;
}

Measured memory_bytes: 968
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        // 主処理
        int result = 700 + (s.length() - s.replace("o", "").length()) * 100;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23764
#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<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cint(n) int n;cin>>n;
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
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;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int a,b;cin>>a>>b;
	if((a+b)%2){
	    cout<<(a+b)/2+1<<endl;
	}else{
	    cout<<(a+b)/2<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3612
program prob3
    implicit none
    character(len=1), dimension(:, :), allocatable :: S
    integer :: H, W, i, j, tmp
    
    read(*,*) H, W
    allocate(S(H, W))
    do i = 1, H
        do j = 1, W
            read(*,'(a)',advance='no') S(i, j)
        end do
        read(*,*) 
    end do

    do i = 1, H
        do j = 1, W
            if(S(i, j) == '.') then
                tmp = 0
                if(i>=2) then
                    if(j>=2)then
                        if(S(i-1, j-1) == '#') then
                            tmp = tmp + 1
                        end if
                    end if
                    if(j<=W-1)then
                        if(S(i-1, j+1) == '#') then
                            tmp = tmp + 1
                        end if                       
                    end if
                    if(S(i-1, j) == '#') then
                        tmp = tmp + 1
                    end if
                end if
                if(i<=H-1) then
                    if(j>=2)then
                        if(S(i+1, j-1) == '#') then
                            tmp = tmp + 1
                        end if
                    end if
                    if(j<=W-1)then
                        if(S(i+1, j+1) == '#') then
                            tmp = tmp + 1
                        end if                       
                    end if
                    if(S(i+1, j) == '#') then
                        tmp = tmp + 1
                    end if
                end if
                if(j>=2)then
                    if(S(i, j-1) == '#') then
                        tmp = tmp + 1
                    end if
                end if
                if(j<=W-1)then
                    if(S(i, j+1) == '#') then
                        tmp = tmp + 1
                    end if                       
                end if
                S(i, j) = char(ichar('0') + tmp)
            end if
        end do
    end do
    
    do i = 1, H
        write(*,*) S(i, :)
    end do

    stop
contains
end program prob3

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

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

	const int m = 9;
	vector<int> c(m, 0);

	for (int i = 0; i < n; i++) {
		int tmp_a;
		cin >> tmp_a;

		if (tmp_a < 3200) c[tmp_a / 400] = 1;
		else c[m - 1]++;
	}
	
	int ans = 0;
	for (int i = 0; i < m - 1; i++) ans += c[i];
	
	if (ans == 0) cout << 1 << " " << c[m - 1] << endl;
	else cout << ans << " " << ans + c[m - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll n, x, ans = 0;
ll a[2000], dp[2000][2000];

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

	for (int i = 1; i < n; i++) {
		ll sum = i*x;
		for (int j = 0; j < n; j++) {
			int backj = (j - 1) < 0 ? (j - 1 + n) : (j - 1);
			int k = (j - i) < 0 ? (j - i + n) : (j - i);

			sum += min(a[j], dp[backj][i - 1]);
			dp[j][i] = min(a[j], dp[backj][i - 1]);
		}
		ans = min(ans, sum);
	}

	cout << ans << endl;
}

Measured memory_bytes: 31488
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def check(x,N,M,V,P,A):
    if (N-x)<=P:
        return True
    if(V<=x+P):
        return(A[x]+M>=A[N-P])

    x_score = A[x]+M
    total_v = (V-x-P)*M

    if(A[N-P]>x_score):
        return False

    for i in range(x+1,N-P+1):
        total_v -= min(M,(x_score - A[i]))
    if total_v <= 0:
        return True
    else:
        return False

def main():
    N,M,V,P = map(int,input().split())
    A = [int(x) for x in input().split()]
    A.sort()

    if(check(0,N,M,V,P,A)):
        print(N)
        return

    isOK = N-1
    isNG = 0
    while(isOK-isNG>1):
        middle = (isOK+isNG)//2
        if(check(middle,N,M,V,P,A)):
            isOK = middle
        else:
            isNG = middle
    print(N-isOK)
    return


if __name__ == "__main__":
    main()



Measured memory_bytes: 62704
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll fact[300001];
ll ifact[300001];

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

constexpr ll MOD = 1000000007;

using T = tuple<ll,ll>;
T dfs1(const vector<vecint>& g, vector<T>& dp, int i, int p=-1) {
  ll cmb = 1;
  ll sum = 0;
  for (auto&& to:g[i]) {
    if (to == p) continue;
    ll c, sz;
    tie(c, sz) = dfs1(g, dp, to, i);
    cmb *= c;
    cmb %= MOD;
    sum += sz;
    cmb *= ifact[sz];
    cmb %= MOD;
  }
  cmb *= fact[sum];
  cmb %= MOD;
  dp[i] = make_tuple(cmb, sum + 1);
  return dp[i];
}

void dfs2(const vector<vecint>& g, const vector<T>& dp, T fromp, vecll& ans, int i, int p=-1) {
  ll cmb, sum;
  tie(cmb, sum) = fromp;
  cerr<<i<<" "<<cmb<<" "<<sum<<endl;
  cmb *= ifact[sum];
  cmb %= MOD;
  for (auto&& to:g[i]) {
    if (to == p) continue;
    sum += get<1>(dp[to]);
    cmb *= get<0>(dp[to]);
    cmb %= MOD;
    cmb *= ifact[get<1>(dp[to])];
    cmb %= MOD;
  }
  for (auto&& to:g[i]) {
    if (to == p) continue;
    ll c, sz;
    tie(c, sz) = dp[to];
    ll ccmb = inv(c, MOD) * cmb % MOD * fact[sum - sz] % MOD * fact[sz] % MOD;
    ll csz = sum - sz + 1;
    dfs2(g, dp, make_tuple(ccmb, csz), ans, to, i);
  }
  ans[i] = cmb * fact[sum] % MOD;
}

int main() {
  fact[0] = 1;
  REP(i,300000) {
    fact[i+1] = fact[i] * (i+1) % MOD;
  }
  ifact[300000] = inv(fact[300000], MOD);
  REP(i,300000) {
    ll j = 300000 - i;
    ifact[j-1] = ifact[j] * j % MOD;
  }
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin>>n;
  vector<vecint> g(n);
  REP(i,n-1) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<T> dp(n);
  dfs1(g, dp, 0);
  REP(i,n) {
    ll x,y;
    tie(x,y) = dp[i];
    cerr<<x<<" "<<y<<endl;
  }
  vecll ans(n);
  dfs2(g, dp, make_tuple(1, 0), ans, 0);
  REP(i,n) {
    cout<<ans[i]<<'\n';
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 23284
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define f first
#define s second
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,l;
	cin>>n>>l;
	multiset<string> s;
	for(int i =0;i< n; i++)
	{
		string h;
		cin>>h;
		s.insert(h);
	}
	for(auto it: s)
		cout<<it;
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
 
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000001
 
using namespace std;
 
 
 
int main(void) {
   string s;
   int count=700;
   
   cin>>s;
   FOR(i,0,2){
     if(s[i]=='o'){
     count+=100;
     }
   }
   cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef pair<double, double> P;

void solve()
{
	int rcount[4] = {0};
	int lcount[4] = {0};
	P p;
	while(cin >> p.first >> p.second)
	{
		if(p.first >= 1.1)
		{
			lcount[0]++;
		}
		else if(p.first >= 0.6)
		{
			lcount[1]++;
		}
		else if(p.first >= 0.2)
		{
			lcount[2]++;
		}
		else
		{
			lcount[3]++;
		}

		if(p.second >= 1.1)
		{
			rcount[0]++;
		}
		else if(p.second >= 0.6)
		{
			rcount[1]++;
		}
		else if(p.second >= 0.2)
		{
			rcount[2]++;
		}
		else
		{
			rcount[3]++;
		}
	}
	for(int i = 0; i < 4; ++i)
	{
		cout << lcount[i] << " " << rcount[i] << endl;
	}
}

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

Measured memory_bytes: 0
raw = input()
N, K = raw.split(' ')
N = int(N)
K = int(K)
str_li = input().split(' ')
num_li = list(map(int, str_li))
sum_li = [0]
for i in num_li:
    sum_li.append(sum_li[-1] + i + 1)
ans = 0
for index in range(K, N+1):
    ans_tmp = sum_li[index] - sum_li[index - K]
    if ans_tmp > ans:
        ans = ans_tmp
print(ans/2)

Measured memory_bytes: 33124
// I Just Decided By The Grace Of The God Poseidon , That You're So Dead To Me I Dug A Hole For You To Lie In

#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define all(x) x.begin() , x.end()

#define _sz(x) (int)x.size()
#define F first
#define S second
#define PB push_back

#define debug(x) cerr << #x << " = " << x << "\n"

typedef long long ll ;
typedef pair<int, int> pii ;

const int MAX_N = 3000 + 19 ;
const int inf = 2e9 + 19 ;

int n , A[MAX_N] ;
vector<int> g[MAX_N] ;

bool dfs(int v , int par = -1) {
        for (int u : g[v])
                if (u ^ par)
                        if (A[u] < A[v] && !dfs(u , v))
                                return true ;
        return false ;
}

int main() {
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) ;
        cin >> n ;
        for (int i = 0 ; i < n ; i ++)  cin >> A[i] ;
        for (int i = 1 , u , v ; i < n ; i ++) {
                cin >> v >> u ;
                g[-- v].PB(-- u) ;
                g[u].PB(v) ;
        }
        for (int i = 0 ; i < n ; i ++)
                if (dfs(i))
                        cout << i + 1 << ' ' ;
        return 0 ;
}


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

i = 0
j = N-1
ans = 0
while True:
    while i<N and C[i] != "W":
        i += 1
    while j>=0 and C[j] !="R":
        j -= 1
    if i>=j:
        break
    ans += 1
    i += 1
    j -= 1

print(ans)

Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double llf;
typedef pair<int, int> pii;
const int maxn = 4e4 + 5;
const int inf = 2e9 + 7;
int a[maxn], b[maxn];

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

	string s;
	int t, cnt = 0;
	cin >> s >> t;
	while (t--) {
		int op, pos;
		cin >> op;
		if (op == 1)cnt++;
		else {
			char c;
			cin >> pos >> c;
			if (pos == 1 && cnt % 2 == 0 || pos == 2 && cnt % 2 == 1)s.insert(s.begin(), c);
			else s.insert(s.end(), c);
		}
	}
	if (cnt % 2 == 1)reverse(s.begin(), s.end());
	cout << s << endl;

	return 0;
}


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

vector<vector<int> >v;
map<pair<int,int> ,int> vis;
int a,t;
set<int> s[2];
int ans=1e9;

bool flag=false;

void bfs(int i,int x)
{

    if(flag)
        return ;

    if(i==t&&x%3==0)
    {
        ans=x;
        flag=true;
        return ;
    }

    vis[{i,x%3}]=1;

    for(auto j:v[i])
    {
        if(vis[{j,(x+1)%3}]==0)
        {
            s[(x)%2].insert(j);
        }
    }

    if(s[(x+1)%2].empty())
    {
        int cnt=s[(x)%2].size();
        int y=-1;
        for(auto j:s[(x)%2])
        {
            if (flag)
                return ;
            cnt--;
            y=j;
            if(cnt==0)
                break;
            bfs(j,x+1);
        }
        s[x%2].clear();
        if(y!=-1)
        bfs(y,x+1);
    }

}

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

    int n,m;
    cin>>n>>m;
    v.resize(n);

    int x,y;
    for (int i = 0; i < m; ++i) {
        cin>>x>>y;
        x--;
        y--;
        v[x].push_back(y);
    }

    cin>>a>>t;
    a--;
    t--;

    bfs(a,0);

    if(ans==1e9)
        cout<<-1;
    else
        cout<<ans/3;
}

Measured memory_bytes: 71296
n=int(input())
d=[dict() for _ in range(n)]
for i in range(n):
    for c in input():
        if c not in d[i]:
            d[i][c]=1
        else:
            d[i][c]+=1
ans=""
for i in range(26):
    mini=10**18
    for j in range(n):
        if chr(97+i) not in d[j]:
            mini=0
        else:
            mini=min(mini,d[j][chr(97+i)])
    ans+=mini*chr(97+i)
print(ans)

Measured memory_bytes: 9168