akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

int main(){
    unsigned int a, b, c;
    cin >> a >> b;
    c = a & b;
    print_binary(c);
    c = a | b;
    print_binary(c);
    c = a ^ b;
    print_binary(c);
}


Measured memory_bytes: 3208
str = STDIN.gets.chomp
commands = STDIN.gets.chomp.to_i

1.upto(commands) {
	command = STDIN.gets.chomp.split(" ")
	command[1], command[2] = [command[1].to_i, command[2].to_i]
	
	if command[0].eql?("print") then
		print str[command[1]..command[2]], "\n"
	elsif command[0].eql?("replace") then
		str[command[1]..command[2]] = command[3]
	elsif command[0].eql?("reverse") then
		str_tmp = String.new(str)
		diff = command[2] - command[1]
		reverse_start = command[2] - str.length
		0.upto(diff) {|d|
			str[command[1] + d] = str_tmp[reverse_start - d]
		}
	end
} 


Measured memory_bytes: 6896
/***

   Author : Md. Jashim Uddin
   From   : RMSTU

 ***/
#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     pob             pop_back()
#define     ll              long  long int
#define     fast            ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define      mx              80000005
int main()
{
    int n; cin>>n;
    string s,ss;
    cin>>s;
    if(s.size()<=n)cout<<s<<'\n';
    else
    {        for(int i=0;i<=n;++i)
        {
            if(i==n) ss.append("...");
            else ss.pb(s[i]);
        }
        cout<<ss<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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




/******************************************************************************************/



int main() {


	int a, b;
	cin >> a >> b;

	int ans = 0;

	int cnt = 1;
	while (cnt < b) {

		ans++;
		
		cnt += (a - 1);
	}
	cout << ans << endl;



	

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

 // Compiler version JDK 11.0.2

  public class Main
 {
   public static void main(String args[])
   { 
    Scanner sc= new Scanner (System.in);
    int a= sc.nextInt();
    int b= sc.nextInt();
    int c= sc.nextInt();
    int t=b;
    b=a;
    a=c;
    c=t;
    System.out.println(a+" "+b+" "+c);
    
   }
 }


Measured memory_bytes: 20948
import java.util.*;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        int p = 0;

        for(int i=0; i<N; i++){
            h[i] = sc.nextInt();
            if(h[i]>=K){
                p += 1;
            }
        }
        System.out.println(p);
    }
}

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

int main(){
    int h,w,max;
    cin>>h>>w>>max;
    int s[15][1005]={};
    char c;
    REP(i,h)REP(j,w){
        cin>>c;
        s[i][j]=c-'0';
    }
    int min=114514;
    int keta[11]={};
    int mat[15][1005]={};
    REP(i,1<<(h-1)){
        REP(i,10)if(keta[i]==2){
            keta[i]=0;
            keta[i+1]++;
        }
        REP(j,15)REP(k,1005)mat[j][k]=0;
        int now=0;
        REP(j,h){
            if(j==0){}
            else if(keta[j-1])now++;
            REP(k,w){
                mat[now][k]+=s[j][k];
            }
        }
        int big=0;
        REP(j,h)REP(k,w){
            if(mat[j][k]>max)big=1;
        }
        if(big){
            keta[0]++;
            continue;
        }
        int reset=0;
        int val[15]={};
        now=0;
        int rescount=0;
        while(now<w){
            REP(j,h){
                val[j]+=mat[j][now];
                if(val[j]>max)reset=1;
            }
            if(reset){
                REP(j,h)val[j]=mat[j][now];
                reset=0;
                rescount++;
            }
            now++;
        }
        if(reset){
            rescount++;
        }
        //REP(i,11)cout<<keta[i]<<" ";
        //cout<<endl<<rescount<<endl;;
        int kai=rescount;
        REP(j,11)if(keta[j]==1)kai++;
        //cout<<kai-rescount<<endl;
        if(kai<min){
            min=kai;
        }
        keta[0]++;
    }
    cout<<min<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int a[30];
	int w, n;
	int i;
	int x, y;

	for (i = 0; i < 30; i++){
		a[i] = i + 1;
	}

	scanf("%d", &w);
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d,%d", &x, &y);

		a[x - 1] ^= a[y - 1];
		a[y - 1] ^= a[x - 1];
		a[x - 1] ^= a[y - 1];
	}

	for (i = 0; i < w; i++){
		printf("%d\n", a[i]);
	}

	return (0);
}

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

struct RMQ {
	using type = int;
	static type id() { return INT_MAX; }
	static type op(const type& l, const type& r) {
		return min(l, r);
	}
};

class seg_node {
public:
	using M = RMQ;
	using T = typename M::type;
	using U = int;

	T val;

private:
	bool flag;
	U lazy;

public:
	seg_node() : val(M::id()), flag(false) {}
	void init(const T& v) {
		val = v;
	}
	void init(const seg_node& l, const seg_node& r) {
		val = M::op(l.val, r.val);
	}
	void update(U v) {
		val = lazy = v;
		flag = true;
	}
	void push(seg_node& l, seg_node& r) {
		if (!flag) return;
		l.update(lazy);
		r.update(lazy);
		flag = false;
	}
	bool is_updated() const {
		return flag;
	}

};

class segment_tree {
	using M = typename seg_node::M;
	using T = typename seg_node::T;
	using U = typename seg_node::U;
	const int h, n;
	vector<seg_node> data;
	void init() {
		for (int i = n - 1; i >= 1; i--) {
			data[i].init(data[i << 1], data[(i << 1) | 1]);
		}
	}
	void push(int node) {
		data[node].push(data[node << 1], data[(node << 1) | 1]);
	}
	void update(int node) {
		data[node].val = M::op(data[node << 1].val, data[(node << 1) | 1].val);
	}
public:
	segment_tree(int n_)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2) {}
	segment_tree(int n_, T v1)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2) {
		for (int i = 0; i < n_; i++) {
			data[i + n].init(v1);
		}
		init();
	}
	segment_tree(const vector<T>& data_)
		: h(ceil(log2(data_.size()))), n(1 << h), data(n * 2) {
		for (int i = 0; i < (int)data_.size(); i++) {
			data[i + n].init(data_[i]);
		}
		init();
	}
	void update(int l, int r, U val) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		int tl = l, tr = r;
		r++;
		while (l < r) {
			if (l & 1) data[l++].update(val);
			if (r & 1) data[--r].update(val);
			l >>= 1; r >>= 1;
		}
		while (tl >>= 1, tr >>= 1, tl) {
			if (!data[tl].is_updated()) update(tl);
			if (!data[tr].is_updated()) update(tr);
		}
	}
	T find(int l, int r) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		r++;
		T res1 = M::id(), res2 = M::id();
		while (l < r) {
			if (l & 1) res1 = M::op(res1, data[l++].val);
			if (r & 1) res2 = M::op(data[--r].val, res2);
			l >>= 1; r >>= 1;
		}
		return M::op(res1, res2);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y, val;
	cin >> n >> q;
	segment_tree st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x, y));
		}
		else {
			cin >> val;
			st.update(x, y, val);
		}
	}
	return 0;
}



Measured memory_bytes: 6200
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,r;
    cin>>n>>r;
    cout<<(n>=10?r:r+100*(10-n))<<endl;
    return 0;
}

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

int main(){
	ll n;
	cin>>n;
	ll x=sqrt(n);
	ll ans=0;
	for(int i=2;i<=x;i++){
		ll cnt=0;
		while(n%i==0){
			n/=i;
			cnt++;
		}
		ll j=0;
		while(1){
			if(j*(j+1)/2<=cnt&&cnt<(j+1)*(j+2)/2)break;
			j++;
		}
		ans+=j;
	}
	if(n!=1)ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3660
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var M = one[1];
	var dp = new Array(N + 1);
	dp[0] = 1;
	for(var i = 0; i < M; i++){
		dp[nextInt()] = 0;
	}
	var mod = 1000000007;
	for(var i = 1; i <= N; i++){
		if(dp[i] == null){
			if(i == 1){
				dp[i] = 1;
			}else{
				dp[i] = dp[i - 2] + dp[i - 1];
				dp[i] %= mod;
			}
		}
	}
	myout(dp[N]);
}


Measured memory_bytes: 41964
use whiteread::*;
use std::collections::HashMap;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut hm = HashMap::new();
    for i in 0..n {
        let s: String = parse_line().unwrap();
        hm.insert(s, 0);
    }
    println!("{}", hm.len());
}


Measured memory_bytes: 18148
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
int cnr[2000][2000];
int cnl[2000][2000];

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>a(h);
	rep(i, h) {
		cin >> a[i];
	}
	vector<queue<int>>q(h);
	bool ok(true);

	rep(i, h) {
		int cnt(0);
		rep(j, w) {
			//cout << i << " " << j << endl;
			if (a[i][j] == '#') {
				if (ok) {
					ok = false;
					q[i].push(cnt);
					cnt = 0;
				}
				
			}
			else {
				ok = true;
				cnt++;
			}
		}
		//cout << cnt << endl;
		q[i].push(cnt);
	}
	ok=true;
	int kk(0);
	rep(i, h)rep(j, w) {
		if (a[i][j] == '#') {
			if (ok) {
				ok = false;
				q[i].pop();
				continue;
			}
		}
		else {
			ok = true;
			cnr[i][j] = q[i].front();
			//cout << i << j << cnr[i][j] << endl;
			kk = max(kk, cnr[i][j]);
		}
	}
	//cout << kk;
	vector<queue<int>>qq(w);
	bool ok2(true);

	rep(i, w) {
		int cnt(0);
		rep(j, h) {
			if (a[j][i] == '#') {
				if (ok2) {
					ok2 = false;
					qq[i].push(cnt);
					cnt = 0;
				}
				
			}
			
			else {
				ok2 = true;
				cnt++;
			}
		}
		qq[i].push(cnt);
	}
	ok2 = true;
	rep(i, w)rep(j, h) {
		if (a[j][i] == '#') {
			if (ok2) {
				ok2 = false;
				qq[i].pop();
				continue;
			}
		}
		else {
			ok2 = true;
			cnl[j][i] = qq[i].front();
		}
	}
	int ans(0);
	rep(i, h)rep(j, w) {
		 ans = max(ans, cnr[i][j] + cnl[i][j]);
	}
	ans--;
	cout << ans;
	return 0;
}

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

typedef long long ll;
#define f first 
#define s second 
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> Pii;
typedef vector<Pii> vpii;
#define rep(i,n) for(int i = 0; i < (n); ++i)

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.f << "," << P.s << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int n;
const int maxn = 2e5 + 1000;
int A[maxn];
int main()
{
	scanf("%d", &n);
	rep(i,n)
	{
		scanf("%d", A + i);
	}
	if(A[0] != 0)
	{
		puts("-1");
		return 0;
	}
	ll res = 0;
	for(int i = 1; i < n; ++i)
	{
		if(A[i] > A[i-1] + 1)
		{
			puts("-1");
			return 0;
		}
		if(A[i] == A[i-1] + 1)
			++res;
		if(A[i] < A[i-1] + 1)
			res += A[i];
	}
	printf("%lld\n", res);
}



Measured memory_bytes: 1024
# 初期入力
N = int(input())

#
fizbuz =[]
fizbuz_2 =[]
for i in range(1,N+1):
    if i%5 ==0 or i%3 ==0 :
        fizbuz_2.append("fizbuz")
    
    else:
        fizbuz.append(i)
print(sum(fizbuz))

#print(fizbuz)

Measured memory_bytes: 33616
#include<stdio.h>

int main(void){
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		if(b>c){
			printf("%d %d %d\n",c,b,a);
		}
		else{
			if(a>c){
				printf("%d %d %d\n",b,c,a);
			}
			else{
				printf("%d %d %d\n",b,a,c);
			}
		}
	}
	else{
		if(a>c){
			printf("%d %d %d\n",c,a,b);
		}
		else{
			if(b>c){
				printf("%d %d %d\n",a,c,b);
			}
			else{
				printf("%d %d %d\n",a,b,c);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 596
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))
    ans = [0] * (n + 1)

    for num in a:
        ans[num] += 1

    for i in range(1, n + 1):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 99764
N = int(input())
T, X, Y = [0], [0], [0]
for i in range(N):
    ti, xi, yi = map(int, input().split())
    T.append(ti)
    X.append(xi)
    Y.append(yi)

for i in range(1, N+1):
    if abs(X[i]-X[i-1]) + abs(Y[i]-Y[i-1]) > T[i]-T[i-1] or (-(abs(X[i]-X[i-1]) + abs(Y[i]-Y[i-1])) - T[i]-T[i-1]) % 2 == 1:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 11816
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        try:
            tmp = n*h*N / ( 4*h*n - N*n - N* h)
        except:
            continue
        if tmp == tmp//1 and tmp > 0:
            print(h,n,int(tmp))
            exit()

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

char c[10] = {'0','1','2','3','4','5','6','7','8','9'};

int main() {

    int a,b;

    cin >> a >> b;

    string s;

    cin >> s;

    string ans = "Yes";

    for(int i=0; i<a; i++){
        bool flag = false;
        for(int j=0; j<10; j++){
            if(s[i] == c[j]){
                flag = true;
            }
        }
        if(!flag){
            ans = "No";
        }
    }

    if(s[a] != '-'){
        ans = "No";
    }

    for(int i = 0; i<b; i++){
        bool flag = false;
        for(int j=0; j<10; j++){
            if(s[a+1+i] == c[j]){
                flag = true;
            }
        }
        if(!flag){
            ans = "No";
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,k;
	scanf("%d%d%d",&a,&b,&k);
	int n=a+1;
	for(int i=0;i<k;i++){
		while(1){
			n--;
			if(a%n==0 && b%n==0)break;
		}
	}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c,cnt=0;
    cin>>a>>b>>c;
    for(int i=a; i<=b; i++){
        if(c%i==0){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3092
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
counter = collections.Counter(s)
res = 0
for i, c in enumerate(s):
    if c == 'W':
        counter['W'] -= 1
    else:
        res += counter['W']
print(res)

Measured memory_bytes: 3876
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    long long int x, y;
    cin >> x >> y;
    if (x % y == 0) {
    	cout << -1 << endl;
    } else {
    	cout << x << endl;
    }
}






Measured memory_bytes: 3640
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  set<int> s;
  s.insert(A);
  s.insert(B);
  s.insert(C);
  cout << (s.size() == 2 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#入力
N, Y = map(int, input().split())


#総当たりで合計金額を算出
x = []
y = []
z = []

for num_ten_thousand in range(0, N+1):
    for num_five_thousand in range(0, N+1):
            
            #千円の枚数を算出
            if N-(num_ten_thousand+num_five_thousand)>=0:
                num_one_thousand = N-(num_ten_thousand+num_five_thousand)
            
            #合計金額を算出
            total = num_ten_thousand*10000 + num_five_thousand*5000 + num_one_thousand*1000
            
            #（合計金額がYと等しいか・合計枚数がNと等しいか）を確認し答えをリストに格納
            if Y==total and N==num_ten_thousand+num_five_thousand+num_one_thousand:
                x.append(num_ten_thousand)
                y.append(num_five_thousand)
                z.append(num_one_thousand)
                
                
#答えを出力
if not x:
    print(-1, -1, -1, sep=" ")
    
else:
    print(x[0], y[0], z[0], sep=" ")

Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    if(n*a<=b)
        printf("%d",n*a);
    else
        printf("%d",b);
    return 0;
}

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

int main(){
        int N,A[100000+2];
        int diff[100000+2];
        cin >> N;
        REP(i,1,N+1) cin>>A[i];
        A[0]=0; A[N+1]=0;
        int sum = 0;
        REP(i,1,N+1){
                sum+=abs(A[i-1]-A[i]);
                diff[i]=abs(A[i-1]-A[i])+abs(A[i]-A[i+1])-abs(A[i-1]-A[i+1]);
        }
        sum+=abs(A[N]-A[N+1]);
        REP(i,1,N+1){
                cout << sum-diff[i] << endl;
        }

        return 0;

}


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

int main()
{
    int n, m, q;
    int a[50], b[50], c[50], d[50];
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    vector<int> A(n, 1);
    int max_score = 0;

    while (true) {
        int score = 0;
        for (int i = 0; i < q; i++) {
            if (A[b[i] - 1] - A[a[i] - 1] == c[i])
                score += d[i];
        }
        max_score = max(max_score, score);

        // Generate next A
        int k = n - 1;
        while (A[k] == m && k >= 0) k--;
        if (k == -1) break;
        A[k]++;
        for (int i = k + 1; i < n; i++) A[i] = A[k];
    }
    cout << max_score << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
long long n,a,b;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a==b){
		printf("1");
	}else if(a>b){
		printf("0");
	}else{
		if(n==1){
			printf("0");
		}else{
			printf("%lld",a+(n-1)*b-b-(n-1)*a+1);
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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



int main() {
	
	ll A[4][4];
	repn(i, 3)repn(j, 3) {
		cin >> A[i][j];
	}

	bool ch[4][4] = {};

	ll N;
	cin >> N;

	repn(i, N) {
		ll b;
		cin >> b;

		repn(i, 3)repn(j, 3) {
			if (A[i][j] == b) { ch[i][j] = 1; }
		}
	}

	string ans = "No";

	repn(i, 3) {
		if (ch[i][1] == 1 && ch[i][2] == 1 && ch[i][3] == 1) { ans = "Yes"; }
		if (ch[1][i] == 1 && ch[2][i] == 1 && ch[3][i] == 1) { ans = "Yes"; }
	}
	
	if (ch[1][1] == 1 && ch[2][2] == 1 && ch[3][3] == 1) { ans = "Yes"; }
	if (ch[1][3] == 1 && ch[2][2] == 1 && ch[3][1] == 1) { ans = "Yes"; }

	cout << ans;

	system("PAUSE");
}






Measured memory_bytes: 504
#include <iostream>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	char a[n][m];
	int b[n];
	for(int i=0;i<n;i++){
		b[i]=0;
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	}
		
	for(int i=0;i<n;i++){
		int t=1;
		for(int j=0;j<m;j++)
			if(a[i][j]=='#')
				t=0;
		if(t==1){
			b[i]=1;
			for(int j=0;j<m;j++)
				a[i][j]='0';
		}
				
	}
	for(int i=0;i<m;i++){
		int t=1;
		for(int j=0;j<n;j++)
			if(a[j][i]=='#')
				t=0;
		if(t==1)
			for(int j=0;j<n;j++)
				a[j][i]='0';	
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			if(a[i][j]!='0')
				cout<<a[i][j];	
		if(b[i]==0)cout<<endl;
	}
		
} 

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	string s, t;
	cin >> s >> t;
	ALL(sort, s);
	ALL(sort, t, greater<char>());

	int len_s = SIZE(s);
	int len_t = SIZE(t);

	REP(i, max(len_s, len_t))
	{
		char cs = i < len_s ? s[i] : 0;
		char ct = i < len_t ? t[i] : 0;
		if (cs < ct)
		{
			print("Yes");
			return 0;
		}
		else if (cs > ct)
		{
			print("No");
			return 0;
		}
	}
	print("No");
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  int count=0;
  for(int i=0; i<s.size(); i++){
    if(s[i]==t[i]) ;
    else ++count;
  }
  if(count>0)cout << "No";
  else cout << "Yes";

return 0;
}

Measured memory_bytes: 3132
/*  -*- coding: utf-8 -*-
 *
 * 3043.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

/* subroutines */

/* main */

int main() {
  int w, h, sw, sh, x, y;
  scanf("%d%d%d%d%d%d", &w, &h, &sw, &sh, &x, &y);

  int x0 = - w / 2, y0 = -h / 2, x1 = w / 2, y1 = h / 2;
  int sx0 = x - sw / 2, sy0 = y - sh / 2, sx1 = x + sw / 2, sy1 = y + sh / 2;
  //printf("(%d,%d)-(%d,%d)\n", x0, y0, x1, y1);
  //printf("(%d,%d)-(%d,%d)\n", sx0, sy0, sx1, sy1);

  if (sx0 < x0) sx0 = x0;
  if (sy0 < y0) sy0 = y0;
  if (sx1 > x1) sx1 = x1;
  if (sy1 > y1) sy1 = y1;
  //printf("(%d,%d)-(%d,%d)\n", sx0, sy0, sx1, sy1);

  double dx = 0.5 * (sx0 + sx1), dy = 0.5 * (sy0 + sy1);
  printf("%.8lf\n", dy / dx);
  return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;

using namespace std;
int main(){
    int h, w;string str = "";
    cin >> h >> w;
    REP(i, 0, w+2){
        str += '#';
    }
    cout << str << '\n';
    string tStr;
REP_(i, 1, h){
    cin >> tStr;
    cout << '#' << tStr << '#' << '\n';
}
cout << str << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    string S;
    cin >> S;
    int b1 = 0, b2 = 0, w1 = 0, w2 = 0;
    int N = S.size();
    rep(i, N)
    {
        if (i % 2 == 0)
        {
            if (S[i] == '0')
            {
                b1++;
            }
            else
                w1++;
        }
        else
        {
            if (S[i] == '0')
            {
                b2++;
            }
            else
                w2++;
        }
    }
    int ans = min(b1 + w2, b2 + w1);
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
n, m = map(int, input().split())

MOD=10**9+7
MAXN=500000+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1): 
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

def comb(n, r): 
    if r<0 or r>n: 
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

def p(n, r):
    if r<0 or r>n:
        return 0
    return g1[n]*g2[n-r]%MOD

t = 0
sign = 1
for i in range(1, n+1):
    t += sign*comb(n, i)*p(m-i, n-i)
    t %= MOD
    sign *= -1
print(p(m, n)*(p(m, n)-t)%MOD)


Measured memory_bytes: 162792
<?php
$tmp = explode(' ', trim(fgets(STDIN)));
$a = (int)$tmp[0];
$b = (int)$tmp[1];
$n = $b - $a + 1;
if (($a<=0&&$b>=0)||$a==0||$b==0) {
    echo "Zero\n";
} else {
    if ($a>0 || $n%2==0) {
        echo "Positive\n";
    } else {
        echo "Negative\n";
    }
}


Measured memory_bytes: 4728
import java.util.*;

class Main{

    String S;
    int I;
    ArrayList<Character> line;
    boolean end;

    void solve(){
	Scanner sc = new Scanner(System.in);

	while(true){
	    S = sc.next();
	    I = sc.nextInt();
	    if(S.equals("0") && I==0)break;

	    line = new ArrayList<Character>();
	    end = false;
	    splitLine(S);

	    String ans = "";
	    if(I>=line.size())ans = "0";
	    else ans = String.valueOf(line.get(I));

	    System.out.println(ans);
	}
    }

    void splitLine(String s){
	if(end)return;

	for(int i=0; i<s.length(); i++){
	    if(s.charAt(i)-'A'<=25 && s.charAt(i)-'A'>=0){
		int j = i+1;
		for(j=i+1; j<s.length(); j++){
		    if(!(s.charAt(j)-'A'<=25 && s.charAt(j)-'A'>=0))break;
		}
		addLine(s.substring(i,j));
		if(end)return;
		i = j-1;
		
	    }else{
		int from = i;
		for(from=i+1; from<s.length(); from++){
		    char c = s.charAt(from);
		    if(!(c>='0' && c<='9')) break;
		}
		int N = Integer.parseInt(s.substring(i,from));

		int pair = 0;
		int to=from;
		for(to=from; to<s.length(); to++){
		    if(s.charAt(to)=='(') pair++;
		    if(s.charAt(to)==')') pair--;
		    if(pair==0)break;
		}
		
		String seq = "";
		if(from==to){
		    seq = s.substring(from,from+1);
		}else{
		    seq = s.substring(from+1,to);
		}
		
		while(N-->0)splitLine(seq);
		i = to;
	    }
	}
    }
    
    void addLine(String s){
	char[] c = s.toCharArray();
	for(int i=0; i<c.length; i++){
	    line.add(c[i]);
	    if(line.size()>I){end = true; return;}
	}
    }

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

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

using namespace std;

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

#define INF 1<<30
#define F first
#define S second

int main(){
  int h,a;
  cin>>h>>a;
  if(h%a!=0) cout<<h/a+1<<endl;
  else cout<<h/a<<endl;
  
  return 0;
}


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

static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

// uに隣接するvを番号順に取得
int next(int u){
    for(int v=nt[u]; v<n; v++){ // 訪問した場所は探索しなくていいため、v+1にしている？
        nt[u] = v+1;
        if(M[u][v]) return v;
    }
    return -1;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r){
    for(int i=0; i<n; i++) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    // 初期化
    for(int i=0; i<n; i++){
        color[i] =WHITE;
        nt[i] = 0;
    }
    tt = 0;

    // 未訪問のuを始点として深さ優先探索
    for(int u=0; u<n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(int i=0; i<n; i++){
        cout << i+1 << " " << d[i] << " " << f[i] <<endl; 
    }
}

int main(int argc, char const *argv[])
{
    int u, k, v;

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

    for(int i=0; i<n; i++){
        cin >> u >> k;
        u--; // 0 origin
        for(int j=0; j<k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}



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

int main(){
    int n;
    cin>>n;
    int a[100002]={0},sa[100002]={0},sa2[100002]={0};
    for(int i=0;i<n;++i){
        cin>>a[i+1];
    }
    int ans=0;
    for(int i=0;i<n+1;++i){
        sa[i]=abs(a[i]-a[i+1]);
        ans+=sa[i];
    }
    for(int i=0;i<n;++i){
        sa2[i]=abs(a[i]-a[i+2]);
        cout<<ans-(sa[i]+sa[i+1]-sa2[i])<<endl;
    }
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <climits>
#include <stack>
#include <string>
#include <random>
#include<set>
#include <iomanip>
#include <climits>
#include <memory>

constexpr int mod = 1000000007;
class Sum_Bit {
	std::vector<int> _array;
public:
	explicit Sum_Bit(const int size) :_array(size, 0) {}
	void increment(int index, const int value) {
		while (index < _array.size()) {
			_array[index] += value;
			index += ~index & (index + 1);
		}
	}
	int operator[](int index) const {
		auto result = 0;
		while (index >= 0) {
			result += _array[index];
			index -= ~index & (index + 1);
		}
		return result;
	}
};
int main() {
	std::vector<long long int> factorial(100001, 1);
	for (auto i = 2; i < factorial.size(); ++i) factorial[i] = i * factorial[i - 1] % mod;
	factorial[0] = 0;
	int n; std::cin >> n;
	while (n != 0) {
		int r; std::cin >> r;
		std::vector<int> word(n);
		for (auto i = 0; i < n; ++i) {
			word[i] = i;
		}
		int s, t;
		for (auto i = 0; i < r; ++i) {
			std::cin >> s >> t; --s; --t;
			word[s] -= word[t];
			word[t] += word[s];
			word[s] = word[t] - word[s];
		}
		Sum_Bit bit(n);
		long long int result = 0;
		for (auto i = 0; i < n; ++i) {
			auto num = bit[word[i]];
			result += (word[i] - num) * factorial[n - i - 1];
			result %= mod;
			bit.increment(word[i], 1);
		}
		std::cout << result << std::endl;
		std::cin >> n;
	}
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

const double PI=acos(-1.0);

int main()
{   
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double th = 2.0*PI*(60*h+m)/720.0;
    double tm = 2.0*PI*m/60.0;
    double ans = a*a + b*b - 2*a*b*cos(th-tm);
    ans = sqrt(ans);

    printf("%.10f\n", ans);

    return 0;
}


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

int main() {
  int a, ans=0, b;
  cin >> a;
  b = a;
  while(true){
   ans+=a%10;
   a/=10;
   if(a==0) break;
  }
  if(b%ans == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
    int n; cin >> n;
    char in[120];
    pair<pair<string, int>, int> p[110];
    rep(i, n){
        int t;
        cin >> in >> t;
        string tmp = in;
        p[i] = make_pair(make_pair(in, -t), i);
    }
    sort(p, p+n);
    rep(i, n)
        cout << p[i].second+1 << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
	string s;
    cin >> s;
    if(s=="SUN")cout << 7;
    if(s=="MON")cout << 6;
    if(s=="TUE")cout << 5;
    if(s=="WED")cout << 4;
    if(s=="THU")cout << 3;
    if(s=="FRI")cout << 2;
    if(s=="SAT")cout << 1;
    return 0;
}


Measured memory_bytes: 256
#if 0

#endif
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
ll Max, N, P, Q;
ll C[501000];
ll diff_by_min[501000];
void setup() {
    cin >> N >> P >> Q;
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
    }
}
void calc_diff_by_min() {
    for (int i = 0; i < N; ++i) {
        diff_by_min[i] = (Q - i) * P  - C[i];
    }
}
ll max_diff_by_jisui() {
    ll max_diff = 0;
    ll now_diff_by_min = 0;

    sort(diff_by_min, diff_by_min + N);

    for (ll i = 0; i < N; ++i) {
        now_diff_by_min += diff_by_min[N - i - 1];
        ll bonus = i * (i + 1) * P;

        max_diff = max(
            max_diff, now_diff_by_min + bonus);
    }

    return max_diff;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    #define ll int

    setup();

    // Calculate the quality of life when he always eats out.
    for (int i = 0; i < N; ++i) {
        Max += C[i];
    }

    calc_diff_by_min();

    cout << Max + max_diff_by_jisui() << endl;

    return 0;
}


Measured memory_bytes: 11016
n=int(input())
ma=2
mi=10**9+7
mu=2
me=10**10
for i in range(n):
    x,y=map(int,input().split())
    l=x+y
    s=-x+10**9+1+y
    ma=max(ma,l)
    mi=min(mi,l)
    mu=max(mu,s)
    me=min(me,s)
print(max(ma-mi,mu-me))

Measured memory_bytes: 72704
import java.util.*;

public class Main {
    static int[] coins = new int[]{1, 5, 10, 25};
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total = n / 50 * 2;
		n %= 50;
		int[][] dp = new int[4][50];
		System.out.println(dfw(dp, 3, n) + total);
	}
	
	static int dfw(int[][] dp, int idx, int amount) {
	    if (amount == 0) {
	        return 0;
	    }
	    if (idx < 0) {
	        return Integer.MAX_VALUE / 10;
	    }
	    if (dp[idx][amount] != 0) {
	        return dp[idx][amount];
	    }
	    int min = Integer.MAX_VALUE;
	    for (int i = 0; i * coins[idx] <= amount; i++) {
	        min = Math.min(min, dfw(dp, idx - 1, amount - i * coins[idx]) + i);
	    }
	    dp[idx][amount] = min;
	    return min;
	}
}



Measured memory_bytes: 26412
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,m;
vector<int> v[3];
int main(){
	read(n);read(m);
	for(int i=1;i<=m;i++){
		int x;read(x);
		v[x&1].push_back(x);
	}
	if(v[1].size()>2){puts("Impossible");return 0;}
	if(m==1){
		int p=v[0].size()?v[0][0]:v[1][0];
		cout<<p<<'\n';
		cout<<p/2+1<<'\n';
		if(p&1){
			for(int i=1;i<=p/2;i++) cout<<2<<' ';
			cout<<1<<'\n';
		}
		else{
			for(int i=1;i<=p/4;i++) cout<<2<<' ';
			cout<<1<<' ';
			for(int i=1;i<=(p-2)/4;i++) cout<<2<<' ';
			cout<<1<<'\n';
		}
		return 0;
	}
	if(v[1].size()) v[2].push_back(v[1][0]);
	for(int x:v[0]) v[2].push_back(x);
	if(v[1].size()>1) v[2].push_back(v[1][1]);
	for(int x:v[2]) cout<<x<<' ';cout<<'\n';
	cout<<v[2].size()-(v[2].back()==1)<<'\n';
	cout<<v[2][0]+1<<' ';
	for(int i=1;i+1<v[2].size();i++) cout<<v[2][i]<<' ';
	if(v[2].back()>1) cout<<v[2].back()-1<<'\n';
	return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<string> S(N);
    int numAB = 0;
    int num_backA = 0, num_frontB = 0, AandB = 0;
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        for (int j = 0; j + 1 < S[i].size(); j++) {
            if (S[i][j] == 'A' && S[i][j + 1] == 'B') numAB++;
        }
        if (S[i][0] == 'B' && S[i].back() == 'A') {
            AandB++;
            continue;
        }
        if (S[i][0] == 'B') num_frontB++;
        if (S[i].back() == 'A') num_backA++;
    }

    //cout << numAB << ", " << num_backA << ", " << num_frontB << ", " << AandB << endl;

    if (!num_backA && !num_frontB) {
        cout << numAB + max(0, AandB - 1) << endl;
    } else {
        int mi = min(num_frontB, num_backA);
        int ma = max(num_frontB, num_backA);
        int diff = ma - mi;
        int d = min(diff, AandB);

        AandB -= d;
        if (AandB == 0) {
            cout << numAB + mi + d << endl;
        } else {
            cout << numAB + mi + d + AandB << endl;
        }
    }

    
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#include<math.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
ll x[30][30];
ll n,d;
int main(){
  cin>>n>>d;
  for(int i=0;i<n;i++)for(int j=0;j<d;j++)cin>>x[i][j];
  ll ans=0;
  for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
      ll sum=0;
      for(int k=0;k<d;k++)sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      ll t=(ll)sqrt((ll)sum);
      if(t*t==sum)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

typedef long long ll;

using namespace std;

int n, m;
char d[54][54];
bool hasVisited[54][54];
queue<pair<int, pair<int, int> > > q;
vector<int> ans;

int main() {
    scanf("%d%d",&n,&m);
    for (int i=0; i<n; i++) {
        scanf("%s",d[i]);
    }
    int ixcor, iycor, jxcor, jycor;
    int a, b, c;
    for (int i=0; i<n*m; i++) {
        ixcor=i/m; iycor=i%m;
        for (int j=i+1; j<n*m; j++) {
            jxcor=j/m; jycor=j%m;
            if (d[ixcor][iycor]=='.' && d[jxcor][jycor]=='.') {
                while (!q.empty()) q.pop();
                for (int ii=0; ii<21; ii++) {
                    for (int jj=0; jj<21; jj++) hasVisited[ii][jj]=0;
                }
                if (d[ixcor+1][iycor]=='.' && ixcor+1<n) {
                    q.push({1,{ixcor+1,iycor}});
                    hasVisited[ixcor+1][iycor]=1;
                }
                if (d[ixcor-1][iycor]=='.' && ixcor>0) {
                    q.push({1,{ixcor-1,iycor}});
                    hasVisited[ixcor-1][iycor]=1;
                }
                if (d[ixcor][iycor+1]=='.' && iycor+1<m) {
                    q.push({1,{ixcor,iycor+1}});
                    hasVisited[ixcor][iycor+1]=1;
                }
                if (d[ixcor][iycor-1]=='.' && iycor>0) {
                    q.push({1,{ixcor,iycor-1}});
                    hasVisited[ixcor][iycor-1]=1;
                }
                while (!q.empty()) {
                    a=q.front().first; b=q.front().second.first; c=q.front().second.second; q.pop();
                    if (b==jxcor && c==jycor) {
                        // printf("%d %d->%d %d: %d\n",ixcor,iycor,jxcor,jycor,a);
                        ans.push_back(a); break;
                    }
                    if (d[b+1][c]=='.' && b+1<n && !hasVisited[b+1][c]) {
                        q.push({a+1,{b+1,c}});
                        hasVisited[b+1][c]=1;
                    }
                    if (d[b-1][c]=='.' && b>0 && !hasVisited[b-1][c]) {
                        q.push({a+1,{b-1,c}});
                        hasVisited[b-1][c]=1;
                    }
                    if (d[b][c+1]=='.' && c+1<m && !hasVisited[b][c+1]) {
                        q.push({a+1,{b,c+1}});
                        hasVisited[b][c+1]=1;
                    }
                    if (d[b][c-1]=='.' && c>0 && !hasVisited[b][c-1]) {
                        q.push({a+1,{b,c-1}});
                        hasVisited[b][c-1]=1;
                    }
                }
            }
        }
    }
    int maxN=-1;
    for (int i=0; i<ans.size(); i++) {
        if (ans[i]>maxN) maxN=ans[i];
    }
    printf("%d",maxN);
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  	int a[4] = {0};
  
  	int N, M;
    cin >> N >> M;

	// 矛盾チェック
  	for (int i = 0; i < M; i++) {
      	int s, c;
      	cin >> s >> c;
      	if (s == 1 && c == 0 && N != 1) {
            cout << -1 << endl;
          	return 0;
        }
      	if (a[s] != 0) {
          	if (a[s] != c) {
	          	cout << -1 << endl;
    	      	return 0;
            }
        } else {
          	a[s] = c;
        }
    }
  
  	if (a[1] == 0 && N != 1) {
      	a[1] = 1;
    }
  	for (int i = 1; i <= N; i++) {
      	cout <<  a[i];
    }
  	cout << endl;

    return 0;
}


Measured memory_bytes: 256