akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vlll = vector<vector<vector<ll>>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class BGreedyTakahashi {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll a, b, k;
	    in >> a >> b >> k;

	    ll aoki=a, taka=b;
	    aoki = max(aoki-k, 0LL);
	    if(!aoki){
            taka = max(a+b-k, 0LL);
	    }

	    out << aoki sp taka << enl;
	}
};


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	BGreedyTakahashi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int n,m;
int ar[maxn];
int mid[maxn];

int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", ar+i);
    }
    int be = maxn-1, en = maxn-1, ans=0;
    for(int i=1;i<=n;i++){
        int now = ar[i];
        int k = lower_bound(mid+be, mid+en, now)-mid;
        assert(k>=be && k<=en);
        if(k==be){
            mid[--be] = now;
            ans++;
        }
        else{
            k--;
            mid[k] = now;
        }
    }
    printf("%d\n", ans);


    return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    int x = 1;
    vi vec = {x};
    while (x < n) {
        vec.pb(x*=6);
    }
    x = 1;
    while (x < n) {
        vec.pb(x*=9);
    }

    vi dp(n+1, inf);
    dp[0] = 0;
    rep(i, vec.size()) {
        rrep(j, n) {
            if (j - vec[i] < 0) continue;
            chmin(dp[j], dp[j-vec[i]]+1);
        }
    }
    std::cout << dp[n] << "\n";
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    String a = null;
    
    switch(s) {
        case "A":
            a = "T";
            break;
        case "T":
            a = "A";
            break;
        case "G":
            a = "C";
            break;
        case "C":
            a = "G";
            break;
    }
    
    System.out.println(a);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int a,b;
    cin>>a>>b;
    ll c[3];
    c[0] = a + b;
    c[1] = a - b;
    c[2] = a * b;
    sort(c,c+3);
    cout<<c[2]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#define llint long long
#define inf 1e18

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

llint n, d, a;
P p[200005];
priority_queue<P, vector<P>, greater<P> > Q;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> d >> a;
	for(int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second;
	for(int i = 1; i <= n; i++){
		p[i].second = (p[i].second+a-1) / a;
		Q.push(p[i]);
	}
	
	llint ans = 0, sum = 0;
	while(Q.size()){
		llint pos = Q.top().first, hp = Q.top().second;
		Q.pop();
		if(hp > 0){
			if(sum >= hp) continue;
			ans += hp - sum;
			Q.push(P(pos+2*d+1, -(hp-sum)));
			sum = hp;
		}
		else sum += hp;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
signed main() {
	int n,k;
	double d=0;
	cin>>n>>k;
	REP(i,1,n+1){
		int memo=i;
		int cnt=0;
		while(memo<k){
			memo*=2;
			cnt++;
		}
		d+=pow(0.5,cnt)/n;
	}
	printf("%.12lf",d);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.14159265358979323846264338327950L
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;
using Graph = vector<vector<int>>;


int main() {

	int N, M;

	cin >> N >> M;

	Graph G(N);

	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	

	vector<int> dist(N, -1);
	queue<int> que;
	vector<int> ans(N);

	dist[0] = 0;
	que.push(0);

	while (!que.empty()) {
		int v = que.front();
		que.pop();

		// v から辿れる頂点をすべて調べる
		for (int nv : G[v]) {
			if (dist[nv] != -1) continue;

			// 新たな白色頂点 nv について距離情報を更新してキューに追加する
			dist[nv] = v+1;
			que.push(nv);
		}
	}

	cout << "Yes" << endl;

	FOR(i,1, N) {
		cout << dist[i] << endl;
	}



	return 0;
}

Measured memory_bytes: 10636
def isstraight(cs):
    if 1 in cs:
        if cs==[1,2,3,4,5] or cs==[1,10,11,12,13]:
            return True
        else:
            return False
    else:
        for i in range(len(cs)-1):
            if cs[i+1]!=cs[i]+1:
                return False
        return True

while 1:
    try:
        c= list(map(int, input().split(',')))
    except:
        break
    l= [c.count(i) for i in set(c)]
    ans= {7: "four card", 6: "full house", 5: "straight", 4: "three card", 3: "two pair", 2: "one pair", 1: "null"}
    if len(set(c))==5:
        v= 5 if isstraight(sorted(c)) else 1
    else:
        v= 7 if 4 in l else(6 if 3 in l and 2 in l else(4 if 3 in l else(3 if l.count(2)==2 else 2)))
    print(ans[v])

Measured memory_bytes: 7788
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 300005
#define M 2000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

int i,j,m,n,p,k,st,ed,c,x,S[N],T[N],fox[N],k1=1,Q[N];

vector<int>v[N],G[N];

int dis[N];

struct Node{
			int ed,before,flow;
}s[M];

void add(int x,int y,int flow)
{
		s[++k1].ed=y; s[k1].before=fox[x]; fox[x]=k1; s[k1].flow=flow;
		s[++k1].ed=x; s[k1].before=fox[y]; fox[y]=k1; s[k1].flow=0;
}

const int inf=(int)1e9;

int bfs()
{
		int i;
		Q[Q[0]=1]=st; memset(dis,-1,sizeof(dis)); dis[st]=0;
		for (int l=1;l<=Q[0]&&dis[ed]==-1;++l)
		{
				int p=Q[l];
				for (i=fox[p];i;i=s[i].before)
				{
							int k=s[i].ed;
							if (dis[k]!=-1||!s[i].flow) continue;
							dis[k]=dis[p]+1;
							Q[++Q[0]]=k;
				}
		}
		return dis[ed]!=-1;
}

int dfs(int x,int flow)
{
		if (x==ed) return flow;
		int i,nowans=0,a;
		for (i=fox[x];i&&flow;i=s[i].before)
		{
				int p=s[i].ed;
				if (dis[p]!=dis[x]+1||!s[i].flow) continue;
				a=dfs(p,min(flow,s[i].flow));
				nowans+=a;
				flow-=a;
				s[i].flow-=a;
				s[i^1].flow+=a; 
		}
		if (!nowans) dis[x]=-1;
		return nowans;	
}

int maxflow()
{
		int ans=0;
		while (bfs()) ans+=dfs(st,inf);
		return ans;
}

int main()
{
		scanf("%d",&n); st=n*2+1; ed=st+1;
		for (i=1;i<n;++i)
		{
				scanf("%d",&c);
				for (;c--;)
				{
						scanf("%d",&x);
						v[i].pb(x); 
						if (x>1) add(x,i+n,1);
				}
		}
		for (i=2;i<=n;++i) add(st,i,1);
		for (i=1;i<n;++i) add(i+n,ed,1);
		if (maxflow()!=n-1)
		{
				puts("-1");
				return 0;
		}
		for (i=2;i<=n;++i)
			for (j=fox[i];j;j=s[j].before)
				if (s[j].ed<=2*n&&s[j].flow==0) T[s[j].ed-n]=i;
		for (i=1;i<n;++i)
		{
				 for (j=0;j<(int)v[i].size();++j)
				 {
				 			int p=v[i][j];
				 			if (p==T[i]) continue;
				 			G[p].pb(i); 
				 }
		}
		Q[Q[0]=1]=1;
		for (int l=1;l<=Q[0];++l)
		{
					int p=Q[l];
					for (i=0;i<(int)G[p].size();++i)
					{
							int k=G[p][i];
							if (S[k]) continue;
							S[k]=p; Q[++Q[0]]=T[k];
					}
		}	
		if (Q[0]!=n) 
		{
				puts("-1");
				return 0;
		}
		for (i=1;i<n;++i) printf("%d %d\n",S[i],T[i]);
}


Measured memory_bytes: 44160
N = int(input())
A = input().split()
import numpy as np
A = [int(a) for a in A]
s = ""
toukou = list(np.argsort(np.array(A)))
for i in range(N):
    num = int(toukou[i])+1
    if(s == ""):
        s = str(num)
    else:
        s += " "+str(num)
print(s)

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

int GetDigit(long num){
    return log10(num)+1;
}

int main() {
  long  ans, divided_Num,i,Num,root_Num;
  
  cin >> Num;
  root_Num = floor(pow(Num,0.5));
  
  for(i = root_Num;i>0;i--){
    if(Num % i == 0){
      break;
    }
  }
  divided_Num = floor(Num / i);
  ans = GetDigit(divided_Num);
  cout << ans << endl;
}

 

  

  
  





Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h> 
#include <set>

using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9 + 7;

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}

int main() {
    int N, M;
    cin >> N >> M;
    bool frag;
    vector<string> A(N);
    vector<string> B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    rep(i, N - M+1) {
        rep(j, N - M+1) {
            frag = true;
            rep(k, M) {
                if (A[i + k].substr(j, M) != B[k]) {
                    frag = false;
                    break;
                }
            }
            if (frag)break;
        }
        if (frag) break;
    }
    if (frag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll a[20][20];
ll p[1<<16];
ll dp[1<<16];
ll rec(int S){
	if(S==0)return dp[0]=0ll;
	if(dp[S]!=-LLINF)return dp[S];
	ll ret = -LLINF;
	for(int i=S;i>0;i=(i-1)&S){
		ret = max(ret,rec(S^i)+p[i]);
	}
	return dp[S]=ret;
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin >> a[i][j];
		}
	}
	for(int i=1;i<(1<<N);i++){
		vector<int> vec;
		for(int j=0;j<N;j++){
			if((i>>j)&1)vec.pb(j);
		}
		int s = vec[0];
		int pre = i-(1<<s);
		ll add = 0ll;
		for(int j=1;j<vec.size();j++)add+=a[s][vec[j]];
		p[i] = p[pre]+add;
	}
	for(int i=0;i<(1<<N);i++)dp[i]=-LLINF;
	cout << rec((1<<N)-1) << endl;

	return 0;
}

Measured memory_bytes: 1280
from math import log2


L = int(input())
r = int(log2(L))
N = r + 1
edge = []
for i in range(r):
    edge.append((i + 1, i + 2, 2 ** i))
    edge.append((i + 1, i + 2, 0))
for t in range(N - 1, 0, -1):
    s = L - 2 ** (t - 1)
    if s >= 2 ** r:
        edge.append((t, N, s))
        L = s

print(N, len(edge))
for e in edge:
    print(*e)


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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int a = z;
    int b = x;
    int c = y;      
    cout << a << " " << b << " " << c << endl;
    return 0;
}

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

int main(){
    using namespace std;
    unsigned long ans{0};
    vector<unsigned long> cnt(2019);
    cnt[0] = 1;
    {
        string S;
        cin >> S;
        reverse(S.begin(), S.end());
        unsigned long prev{0}, v{1};
        for(const auto& c : S){
            ans += cnt[(prev += v * (c - '0')) %= 2019]++;
            (v *= 10) %= 2019;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3772
package main

import "fmt"

func main() {
	var n, a, b int

	fmt.Scan(&n, &a, &b)

	var result int
	for i := 0; i <= n; i++ {
		digitSum := digitSum(i)
		if a <= digitSum && digitSum <= b {
			result += i
		}
	}
	fmt.Println(result)
}

func digitSum(n int) int {
	var sum int

	for {
		digit := n % 10
		sum += digit
		if n/10 == 0 {
			break
		}
		n = n / 10
	}

	return sum
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans;
  if(a==b) ans = c;
  else if(a==c) ans = b;
  else ans = a;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
	int K;
	cin>>K;
	int k=K-1;
	cout<<s[k]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,sum = 0,ans = 0;
	map<int,int> cnt;
	cnt[0]++;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		sum += a;
		ans += cnt[sum];
		cnt[sum]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 12800
#include <stdio.h>
#define INF 100000000

int m[101][101];
int p[101];

int matrixChainOrder(int pl) {
  int n, i, j, l, k, q;

  n = pl-1;
  for (i = 1; i <= n; i++) {
    m[i][i] = 0;
  }
  for(l = 2; l <= n; l++) {
    for(i = 1; i <= n-l+1; i++) {
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k < j; k++) {
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        if(m[i][j] > q) m[i][j] = q;
      }
    }
  }
  return m[1][n];
}

int main() {
  int n, i, x, k;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    if(i < n-1)scanf("%d", &k);
  }
  scanf("%d", &p[n]);
  x = matrixChainOrder(n+1);
  printf("%d\n", x);

  return 0;
}

Measured memory_bytes: 636
l,r=map(int,input().split())
ans=int(10000000)
if r-l>2019:
    print(0)
    exit()

for i in range(l,r):
    for j in range(i+1,r+1):
        now=int((i*j)%2019)
        if ans>now:
            ans=now

print(ans)

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

int main()
{
	int q = 0;
	int	p0x = 0, p0y = 0, p1x = 0, p1y = 0, p2x = 0, p2y = 0, p3x = 0, p3y = 0;
	int n = 0;
	double u = 0, s = 0, t = 0;

	cin >> q;
	
	for (int i = 0; i < q; i++) {
		cin >> p0x >> p0y >> p1x >> p1y >> p2x >> p2y >> p3x >> p3y;
		n = 0;

		u = (p3y - p0y) * (p2x - p0x) - (p3x - p0x) * (p2y - p0y);
		
		if (u != 0) {
			s = (double)((p3y - p0y) * (p1x - p0x) - (p3x - p0x) * (p1y - p0y)) / u;
			t = - (double)((p2y - p0y) * (p1x - p0x) - (p2x - p0x) * (p1y - p0y)) / u;

			if (s >= 0 && t >= 0) {
				if (s + t >= 1)
					n = 1;
			}
		}
		else {
			if ((p2x == p0x && p2y == p0y)| (p3x == p0x && p3y == p0y))
				n = 1;

			if (p1x - p0x != 0) {
				if ((p0x - p2x) * (p0x - p3x) <= 0)
					n = 1;
				else if(((p2x - p0x) * (p2x - p1x) <= 0) | ((p3x - p0x) * (p3x - p1x) <= 0))
					n = 1;
			}
			else
				if ((p0y - p2y) * (p0y - p3y) <= 0)
					n = 1;			
				else if (((p2y - p0y) * (p2y - p1y) <= 0) | ((p3y - p0y) * (p3y - p1y) <= 0))
					n = 1;
		}

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

Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}




int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	cout << b * a / 2;
	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    for (int i = 0;; i++) {
      if (Math.pow(2, i) <= n) {
        continue;
      } else {
        System.out.println((int) Math.pow(2, i - 1));
        return;
      }
    }

  }
}

Measured memory_bytes: 35620
import numpy as np

N = int(input())
Alist = list(map(int,input().split()))

#ans = np.prod(Alist)
Alist.sort()
ans = 1
for i in range(N):
  #print (Alist[i])
  ans*= Alist[i]
  if Alist[i]==0:
    break
  if ans >10**18:
    break

if ans >10**18:
  print(-1)
else:
  print(ans)


Measured memory_bytes: 39952
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		char[][] s = new char[3][];
		s[0] = sc.next().toCharArray();
		s[1] = sc.next().toCharArray();
		s[2] = sc.next().toCharArray();
		sc.close();
		int[] sp = new int[3]; 
		int abc = 0;
		int tmp = 0;
		while(sp[abc] != s[abc].length) {
			tmp = (int)(s[abc][sp[abc]] - 'a');
			sp[abc]++;
			abc=tmp;
		}
		out.println((char)('A'+abc));
	}
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;
vector<int> C;
vector<vector<int> > g;
vector<int> res;
vector<int> sz;
void dfs(int a, int p) {
	sz[a] = 1;
	for (int i : g[a]) {
		if (i != p) {
			dfs(i, a);
			sz[a] += sz[i];
		}
	}
}
void dfs2(int a, int p, map<int, int> &mp, int &add) {
	int mx = -1;
	int mxn = -1;
	for (int i : g[a]) {
		if (i != p && mx < sz[i]) {
			mx = sz[i];
			mxn = i;
		}
	}
	if (mxn != -1) {
		dfs2(mxn, a, mp, add);
		{
			int t = mp[C[a]] + add;
			res[C[a]] += t * (t + 1) / 2;
		}
		for (int i : g[a]) {
			if (i != p && i != mxn) {
				map<int, int> mp2;
				int add2 = 0;
				dfs2(i, a, mp2, add2);
				{
					int t = mp2[C[a]] + add2;
					res[C[a]] += t * (t + 1) / 2;
				}
				add += add2;
				for (auto m : mp2) {
					mp[m.first] += m.second;
				}
			}
		}
	}
	add++;
	mp[C[a]] = -add;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	C.resize(N);
	g.resize(N);
	res.resize(N, 0);
	sz.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		C[i]--;
	}
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, -1);
	map<int, int> mp;
	int add = 0;
	dfs2(0, -1, mp, add);
	for (int i = 0; i < N; i++) {
		int t = mp[i] + add;
		res[i] += t * (t + 1) / 2;
	}
	int all = N * (N + 1) / 2;
	for (int i = 0; i < N; i++) {
		cout << all - res[i] << endl;
	}
}

Measured memory_bytes: 78176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  vector<int> sample(N);
  for(int i=N/2;i<N;i++)sample.at(i)=a.at(i);
  
  int sum;
  for(int i=N/2-1;i>=0;i--){
    sum=0;
    for(int j=N/(i+1);j>1;j--){
      sum+=sample.at((i+1)*j-1);
      sum%=2;
    }
    if(a.at(i)!=sum)sample.at(i)=1;
  }
  if(accumulate(sample.begin(),sample.end(),0)!=0){
    cout<<accumulate(sample.begin(),sample.end(),0)<<endl;
    for(int i=0;i<N;i++)if(sample.at(i)==1)cout<<i+1<<" ";
  }
  else cout<<0;
  cout<<endl;
}

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

ll N;
vector<ll> d;

int main(){
    cin >> N;
    d.resize(N);
    for (int i = 0; i < N; ++i) cin >> d[i];
    sort(d.begin(), d.end());
    cout << d[d.size() / 2] - d[d.size() / 2 - 1] << endl;
    return 0;
}

Measured memory_bytes: 4012
import sys
from fractions import gcd

n, m = list(map(int, input().split()))
lcm = n * m / gcd(n, m)

s = input()
t = input()

d = {}
for i, e in enumerate(s):
    d[(lcm / n) * i + 1] = e

for i, e in enumerate(t):
    if ((lcm / m) * i + 1) in d and d[(lcm / m) * i + 1] != e:
        print(-1)
        sys.exit()

print(int(lcm))


Measured memory_bytes: 16808
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t;
char a[maxn][maxn],b[maxn][maxn];
int main()
{
    int i,j;
    scanf("%d%d",&n,&m);
    rep(i,0,n-1)scanf("%s",a[i]),strcpy(b[i],a[i]);
    rep(i,0,n-1)
    {
        rep(j,0,m-1)
        {
            if(j==0)a[i][j]='#';
            if((i^1)&1&&j!=m-1)a[i][j]='#';
            if(j==m-1)b[i][j]='#';
            if(i&1&&j!=0)b[i][j]='#';
        }
    }
    rep(i,0,n-1)printf("%s\n",a[i]);
    printf("\n");
    rep(i,0,n-1)printf("%s\n",b[i]);
    //system("Pause");
    return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
static inline void fast_io()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
using ll = long long;
using ld = long double;

int main()
{
    fast_io();

    ll sum = 0;
    long n;
    cin >> n;
    vector<ll> all(n);
    for (long i = 0; i < n; i++) {
        cin >> all[i];
        sum ^= all[i];
    }
    for (long i = 0; i < n; i++) {
        cout << (sum ^ all[i]) << ' ';
    }
}


Measured memory_bytes: 4312
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t long long
using namespace std;


int main() {
  long long N,max=25;
  cin >> N;
  char s[N];
  cin >> s;
  long long checked[26];
  for (size_t i = 0; i < 26; i++) {
    checked[i] = 0;
  }
  for (size_t i = 0; i < N; i++) {
    checked[s[i] - 'a']++;
  }
  // sort(checked,checked+26,std::greater<char>());
  unsigned long long result = 1;
  for (size_t i = 0; i < 26; i++) {
    // if(!checked[i]) {
    //   max = i;
    //   break;
    // }
    result *= checked[i] + 1;
    result %=  1000000007;
  }


  // for(long long S = 1; S < (1<<max); S++) {
  //     long long sum = 1;
  //     for(int i = 0; i < max; i++) {
  //         if(S >> i & 1) {
  //           sum *= checked[i];
  //           sum %= 1000000007;
  //         }
  //     }
      // if (sum) {
      //   cout << sum <<endl;
      // }
  //     result += sum % 1000000007;
  //     result %= 1000000007 ;
  // }
  // for (size_t i = 0; i < s[N-1] - 'a'; i++) {
  //   for (size_t j = 0; j < i; j++) {
  //     /* code */
  //   }
  //   num += checked[i];
  // }

  // for (size_t i = 0; i < 26; i++) {
  //   cout << i << " : " << checked[i] << endl;
  // }
  // cout << checked[0] << endl;

  cout << result-1 << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long lon
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(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;

int main (void){
    
    int number;
    while(cin >> number,number)
    {
        int math[11][11] ={0};
        REP(i,number)
        {
            REP(j,number)
            cin >> math[i][j];
        }
        REP(i,number)
            REP(j,number)
        math[i][number] += math[i][j];
        REP(i,number)
            REP(j,number)
        math[number][i] += math[j][i];
        REP(i,number)
        REP(j,number)
        math[number][number]+= math[i][j];
        REP(j, number+1)
        REP(i,number+1){
            printf("%5d",math[j][i]);
            if(i == number || (j == number && i == number))
                cout << endl;
                 }
    }
    return 0;
    
  
}

Measured memory_bytes: 1192
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
	int H, W;
	cin >> H >> W;

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

	for(int i=0;i<W+2;i++){
		cout << '#';
	}
	cout <<endl;

	for(int i=0;i<H;i++){
		cout << '#';
		for(int j=0;j<W;j++){
			cout << a[i][j];
		}
		cout << '#' <<endl;
	}


	for(int i=0;i<W+2;i++){
		cout << '#';
	}
	cout <<endl;    
	return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
ans=0
 
if (B-A)%2==0:
  ans=(B-A)//2
else:
  if A-1<N-B:
    if B-A==1:
      ans=B-1
    else:
      ans=A+(B-A-1)//2
  else:
    if B-A==1:
      ans=N-A
    else:
      ans=N-B+1+(N-(A+N-B+1))//2
print(ans)

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

int main(){
  int N; cin >> N;
  int result=0;
  int a,b;
  for(int i=0; i<N; i++){
    if(i<N-1){
      cin >> b;
    }
    if(i==0){
      result+=b;
      a=b;
    }else{
      result+=min(a,b);
      a=b;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long 
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;
map<ll,ll> hr,hc;
vector<ll> row[300005],col[300005];
int main(){
   //boost;
   ll h,w,m;
   cin>>h>>w>>m;
   ll rmax=0;
   ll cmax=0;
   while(m--){
   	 ll x,y;
   	 cin>>x>>y;
   	 hr[x]++;
   	 hc[y]++;
   	 row[x].pb(y);
   	 col[y].pb(x);
   	 rmax=max(rmax,hr[x]);  	
     cmax=max(cmax,hc[y]); 
    }
    ll ans=rmax+cmax-1;
    ll c_cmax=0;
    for(ll i=1;i<=300000;i++){
    	if(hc[i]==cmax)c_cmax++;
	}
    
    for(ll i=1;i<=300000;i++){
    	  if(row[i].size()==0)continue;
    	  if(hr[i]!=rmax)continue;
    	  ll tc=0;
    	  for(ll j=0;j<row[i].size();j++){
    	  	  if(hc[row[i][j]]==cmax)tc++;
		  }
		  if(tc<c_cmax){ans++;break;}
	}
	cout<<ans;
    
  	 
  	 
  	 
  }
  
  
  
   


    


Measured memory_bytes: 73900
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
  int ans = 1000001;
  int n; cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 0; j <= n; j++) {
    int s1 = 0, s2 = 0;
    for (int i = 1; i <= j; i++) s1 += a[i];
    for (int i = j + 1; i <= n; i++) s2 += a[i];
    ans = min(ans, abs(s1 - s2));
  }
  cout << ans << endl;
}

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

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int min = a + b;
	if (min > a + c)
		min = a + c;
	if (min > b + c)
		min = b + c;
	printf("%d", min);
	return 0;
}

Measured memory_bytes: 128
package main
 
import (
	"fmt"
)
 
func main() {
	var n, x, t int
	fmt.Scanf("%d %d %d", &n, &x, &t)
	var a = n / x 
	var b = n % x
	var c int
	if b == 0{
		c = a * t
	} else {
		c = (a+1) *t
	}
	fmt.Printf("%d\n", c)
}

Measured memory_bytes: 1832
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
    int n, c = 0;
    scanf("%d", &n);
    long sum[400000], input, ans = 0;

    scanf("%ld", &input);
    sum[0] = input;
    for(int i = 1; i < n; i++){
        scanf("%ld", &input);
        sum[i] = sum[i-1] + input;
    }
    sort(sum, sum+n);

    for(int i = 0; i < n; i++){
        if(sum[i] == 0) ans++;

        if(i < n-1 && sum[i] == sum[i+1]){
            c++;
            ans += c;
        } else c = 0;

    }

    printf("%ld", ans);
    return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	    Scanner sc= new Scanner(System.in);

        int cnt1=0,cnt2=0;
        while(sc.hasNextLine()){
        String st[]=sc.nextLine().split(",");
        int a =Integer.parseInt(st[0]);
        int b =Integer.parseInt(st[1]);
        int c =Integer.parseInt(st[2]);

            if (a * a + b * b == c * c){
                cnt1++;
            }
            if (a==b){
                cnt2++;
            }

            }
        System.out.println(cnt1+"\n"+cnt2);

    }
}

Measured memory_bytes: 17132
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_INPUT_LEN  ( 1000 )

char str[MAX_INPUT_LEN + 1] = "";

int main() {

    int red = 0;
    int green = 0;
    int blue = 0;
    int num = 0;

    /* Get input data */
    scanf("%d %d %d", &red, &green, &blue);

    num = ( red * 100 ) + ( green * 10 ) + blue;

    if( num % 4 == 0 )
        printf( "YES\n" );
    else
        printf( "NO\n" );

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int N,K;
int A[100005];
int B[100005];
long long rez;
int main()
{
    cin>>N>>K;
    for(int i=1;i<=N;i++)cin>>A[i]>>B[i];
    for(int p=30;p>=0;p--)
    {
        if(!(K&(1<<p)))continue;
        K-=(1<<p);
        long long tmp=0;
        for(int i=1;i<=N;i++)
        {
            if((K>>p)==((K>>p)|(A[i]>>p)))
                tmp+=B[i];
        }
        rez=max(rez,tmp);
        K+=(1<<p);
    }
    int p=0;
    long long tmp=0;
    for(int i=1;i<=N;i++)
    {
        if((K>>p)==((K>>p)|(A[i]>>p)))
            tmp+=B[i];
    }
    cout<<max(rez,tmp);
    return 0;
}


Measured memory_bytes: 1024
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readContents 2 >>= print . solve

solve :: [[Int]] -> Int
solve [[h, w], [sh, sw]] = h * w - sh * w - sw * h + sh * sw

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
a1, b1 = list(map(int, input().split()))
a2, b2 = list(map(int, input().split()))
a3, b3 = list(map(int, input().split()))

h = [a1, b1, a2, b2, a3, b3]

c1 = 0
c2 = 0
c3 = 0
c4 = 0

for i in h:
    if i == 1:
        c1 += 1
    elif i == 2:
        c2 += 1
    elif i == 3:
        c3 += 1
    else:
        c4 += 1

ans = [c1, c2, c3, c4]

flag = False

for i in ans:
    if i == 3:
        flag = True

if flag == True:
    print("NO")
else:
    print('YES')

Measured memory_bytes: 3064
from collections import deque
S = deque(list(input()))
Q = int(input())
Flag = True
for _ in range(Q):
    q = input().split()
    if len(q) == 1:
        Flag = False if Flag else True
    else:
        if Flag:
            if q[1] == '1':
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if q[1] == '1':
                S.append(q[2])
            else:
                S.appendleft(q[2])
if Flag:
    print(''.join(S))
else:
    print(''.join(reversed(S)))

Measured memory_bytes: 8676
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt(), S = cin.getStr();
    let C = {};
    for (let n = 0; n < S.length; n++) {
        let c = C[S[n]] || 0;
        C[S[n]] = ++c;
    }
    const MOD = 1e9 + 7;
    let ans = 1;
    for (let n in C) {
        ans = (ans * (C[n] + 1)) % MOD;
    }
    ans = (ans - 1 + MOD) % MOD;
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;
typedef int lli;
#define mod 1000000007
#define fLoop for(lli i = 0; i < N; i++)
lli DFS(vector<lli> adj[], lli index, bool *visited, lli *DP) {
	if(visited[index]) {
		return DP[index];
	}
	visited[index] = true;
	lli output = 0;
	for(lli i = 0; i < adj[index].size(); i++) {
		output = max(output, 1 + DFS(adj, adj[index][i], visited, DP));
	}
	DP[index] = output;
	return output;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    lli N, M;
    cin >> N >> M;
    vector<lli > adj[N + 1];
    for(lli i = 0; i < M; i++) {
    	lli X, Y;
    	cin >> X >> Y;
    	adj[X].push_back(Y);
	}
	bool *visited = new bool[N + 1];
	lli *DP = new lli[N + 1];
	for(lli i = 0; i <= N; i++) {
		visited[i] = false;
		DP[i] = 0;
	}
	lli output = 0;
	for(lli i = 1; i <= N; i++) {
		if(!visited[i]) {
			output = max(output, DFS(adj, i, visited, DP));
		}
	}
	cout << output << '\n';
  	delete[] visited;
  	delete[] DP;
}



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

class Knapsack {
public:
    vector<vector<long long>> dp;

    long long solve(vector<long long> &val, vector<long long> &wt, int item, int capacity) {
        if(item <= 0 || capacity <= 0) return 0;

        if(dp[item][capacity] != -1) return dp[item][capacity];

        int itemCurr = item - 1;
        long long lastMax = solve(val, wt, item-1, capacity);
        long long currMax = 0;

        if(wt[itemCurr] <= capacity) {
            currMax = val[itemCurr] + solve(val, wt, item - 1, capacity-wt[itemCurr]);
        }

        dp[item][capacity] = max(lastMax, currMax);
        return dp[item][capacity];
    }
};


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

    int n, w;

    cin>>n>>w;
    int w_i, n_i;

    if(n==1) {
        cin>>w_i>>n_i;
        if(w_i <= w) {
            cout<<n_i<<endl;
        } else {
            cout<<0<<endl;
        }
        return 0;
    }
    vector<long long> val;
    vector<long long> wt;

    val.reserve(n);
    wt.reserve(n);

    

    for(int i = 0; i < n; ++i) {
        cin>>w_i>>n_i;
        wt.push_back(w_i);
        val.push_back(n_i);
    }

    Knapsack ks;
    ks.dp.resize(n+1, vector<long long>(w+1, -1));
    cout<<ks.solve(val, wt, n, w)<<endl;

    return 0;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#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 fs first
#define sc second
#define pb push_back
#define PB push_back
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    for (int ph = 0; ph < q; ph++) {
        int k;
        cin >> k;
        ll d_cnt = 0, d_mc = 0;
        ll mc = 0;
        ll ans = 0;
        V<ll> db_mc(n);
        for (int i = 0; i < n; i++) {
            if (i >= k && s[i-k] == 'D') {
                d_cnt--;
                d_mc -= db_mc[i-k];
            }
            char c = s[i];
            if (c == 'D') {
                d_cnt++;
                db_mc[i] = mc;
                d_mc += mc;
            } else if (c == 'M') {
                mc++;
            } else if (c == 'C') {
                ans += mc * d_cnt - d_mc;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int x, y, z, k;
long a[1000], b[1000], c[1000];
long d[1000000];
long e[3000000];

int main(){
    cin >> x >> y >> z >> k;
    for (int j = 0; j < x; j++) cin >> a[j]; 
    sort(a, a+x, greater<long>());
    for (int j = 0; j < y; j++) cin >> b[j]; 
    sort(b, b+y, greater<long>());
    for (int j = 0; j < z; j++) cin >> c[j]; 
    sort(c, c+z, greater<long>());

    for (int i = 0; i < x; i++){
        for (int j = 0; j < y; j++){
            d[i+j*x] = a[i] + b[j];
        }
    }
    sort(d, d+x*y, greater<long>());
    for (int i = 0; i < k; i++){
        for (int j = 0; j < z; j++){
            e[i+j*k] = d[i] + c[j];
        }
    }
    sort(e, e+k*z, greater<long>());
    for (int i = 0; i < k; i++){
        cout << e[i] << endl;
    }
}

Measured memory_bytes: 31616
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    int W[N]; rep(i,N) cin >> W[i];
    int sum=0; rep(i,N) sum+=W[i];
    int pos=0;
    int ans=INF;
    rep(i,N){
        pos+=W[i];
        ans=min(ans,abs(sum-pos*2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>				//written by thidailoc
using namespace std;				//team three wolves
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
#define fu(i,a,b)   for(ll i=a;i<b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define ms(a, x) 	memset(a, x, sizeof a)
#define prec(n) 	fixed<<setprecision(n)
#define pb(i)	    push_back(i)
#define popb()    	pop_back()
#define sc(a) 	    cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)	    cout<<a<<" "
#define pr2(a,b)    cout<<a<<" "<<b<<" "
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)	lower_bound(a.begin(),a.end(),x) -a.begin()
#define all(x) 		(x).begin(), (x).end()
#define sz(a) 		(ll)a.size()
#define le			length()						
#define re 			return 	
#define	mp(a,b)  	make_pair(a,b)
#define se			second
#define fi			first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)

double const eps = 1e-6;
ll const Base=1e9+7,oo=1e9;
ll arr[1000000],mark[1000000];

ll Solves(){
//	INPUT;
	ll n,k,cnt=0,ans=oo,A,B,l=1,r=oo,mid;
	// PROCESSING IN HERE
	//v[i] =arr[i]-mid1
	//(mid1-mid2)*b+mid2*a=arr[i]
	//
	//
	//(a-b)*mid2+b*mid1=arr[i]
	//mid1 la chat ket qua ,mid2 la chat so con A cho vitri i
	sc(n); sc2(A,B);
	fu(i,0,n)sc(arr[i]);
	
	
	while(l<=r){
		mid=(l+r)/2;
		cnt=0;
		fu(i,0,n)cnt+=max(0LL,(ll)ceil((double)(arr[i]-B*mid)/(A-B)));
	//	if(mid==5)debug(cnt);
		if(cnt<=mid) ans=min(ans,mid);
		
		if(cnt>mid)l=mid+1;
		else r=mid-1;
	}
	
	pr(ans);
	
	re 0;
}


int main(){

	ios_base::sync_with_stdio(0);	
	cin.tie(0);
	cout.tie(0);
	
	Solves();
}

Measured memory_bytes: 4352
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll q;
	cin >> q;
	rep(i, q){
		ll k;
		cin >> k;
		ll ans = 0, sum = 0;
		ll cntD = 0, cntM = 0;
		rep(i, n){
			if(i >= k){
				if(s[i - k] == 'D'){
					cntD--;
					sum -= cntM;
				}else if(s[i - k] == 'M') cntM--;
			}

			if(s[i] == 'D') cntD++;
			else if(s[i] == 'M'){
				cntM++;
				sum += cntD;
			}else if(s[i] == 'C') ans += sum;
		}
		co(ans);
	}

	return 0;
}


Measured memory_bytes: 1412
# include <iostream>
#include <math.h>
#include <string>

using namespace std;

typedef long long ll;

string c;

int pos;

int most_right_red_pos() {
	while (pos > 0) {
		if (c[pos] == 'R') return pos;

		pos--;
	}
	return pos;
}

int main() {
	ll n;
	cin >> n;
	pos = n - 1;

	cin >> c;

	int count = 0;

	for (int i = 0; i < n; i++) {
		if (i >= most_right_red_pos()) {
			break;
		}
		if (c[i] == 'W') {
			c[i] = 'R';
			c[most_right_red_pos()] = 'W';
			count++;
		}
	}

	if (c == "W") {
		cout << 0;
	}
	else {
		cout << count;
	}

}


//
//int main() {
//	ll k;
//
//	cin >> k;
//	
//	if (k % 2 == 0) {
//		cout << -1;
//		return 0;
//	}
//
//	ll seven = 7;
//
//	while (true) {
//		if (seven % k == 0) {
//			cout << seven;
//			break;
//		}
//		seven = seven * 10 + 7;
//	}
//}


Measured memory_bytes: 3732