akhauriyash/Code-Regression huggingface dataset:
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

int a[4];

int main(){
    int b;
    cin >> b;
    for(int i = 0; i<4; i++){
        a[3-i] = b % 10;
        b = b / 10;
    }
    for(int bit = 0; bit < (1<<3); bit++){
        int sum = a[0];
        for(int i = 0; i < 3; i++){
            if(bit & (1<<i)){
                sum += a[i+1];
            }else{
                sum -= a[i+1];
            }
        }
        if(sum == 7){
            cout << a[0];
            for(int i = 0; i<3; i++){
                if(bit & (1<<i)){
                    cout << "+";
                }else{
                    cout << "-";
                }
                cout << a[i+1];
            }
            cout << "=7" << endl; 
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

bool dp[2][16161];
string s; 

bool solve(int g, int mod, vector<int> a) {
	
	rep(i,2) rep(j,16161) dp[i][j]=false;

	dp[0][8000]=true;
	
	int i=0;
    
	if (!mod) {
        /*
		rep(j,16161) {
			if (!dp[0][j]) continue;
			dp[0][j]=false;
			dp[1][j+a[0]]=true;
			// cout << "i = "<<i<<", j+a[i] = "<<j+a[0] << endl;
		}*/
        dp[0][8000] = false;
        dp[1][8000+a[0]] = true;
	}

	for (; i < a.size(); ++i) {
		rep(j,16161) {
			if (!dp[i%2][j]) continue;
			dp[i%2][j]=false;
			dp[(i+1)%2][j+a[i]]=true;
			dp[(i+1)%2][j-a[i]]=true;
			// cout<< "i = "<<i%2<<", j+a[i] = "<<j+a[i]<<", j-a[i] = "<<j-a[i]<< endl;
		}
	}

	if (dp[a.size()%2][g+8000]) return true;
	else return false;
}

int main(int argc, char const *argv[]) {
	int x,y;
	cin>>s>>x>>y;
	int n = s.length();
	vector<int> a;
	vector<int> X,Y;

	// ランレングス変換をします
	int cnt=0;
	rep(i,n) {
		if (s[i]=='F') cnt++;
		else {
			a.push_back(cnt);
			cnt=0;
		}
	}
	if (cnt) a.push_back(cnt);

	rep(i,a.size()) {
		if (i%2==0) X.push_back(a[i]);
		else Y.push_back(a[i]);
	}

	if (solve(x,0,X)&&solve(y,1,Y)) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	sort(ALL(s));
	sort(ALL(t));
	reverse(ALL(t));
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    int wc=0;
    for(int i = 0; i < n; i++) {
        if(s[i]=='W') wc++;
    }

    int count=0;
    int chm=INT32_MAX;
    for(int i = 0; i < n; i++) {
        int cht;
        if(s[i]=='W'){
            cht=count + n-i-wc+count;
            count++;
        }
        else{
            cht=count + n-i-wc+count-1;
        }
        chm=min(chm,cht);
    }
    cout << chm << "\n";
    return 0;
}

Measured memory_bytes: 720
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include <assert.h>

int main(void){
		int a,b;
		int score;
		scanf("%d",&a);
		scanf("%d",&b);

		int c[b];
		for(int i = 0;i<b;i++){
			scanf("%d",&c[i]);
		}
int d[b];
		for(int j = 0;j<b-1;j++){
			d[j] =c[j+1]-c[j];
		}
int max = d[0];
for (int k = 1; k < b-1; k++) {
if (max < d[k]) {
		max = d[k];
}
}
int e;
e = a+c[0]-c[b-1];
if(e>max){
	score = a-e;
}else{
score = a - max;
}


printf("%d\n",score);

		return 0;
}


Measured memory_bytes: 1664
n = int(input())
A = list(map(int, input().split()))
A.sort()
check = [0]*(10**6+1)
for a in A:
    if check[a] != 0:
        check[a] += 1
        continue
    for i in range(10**6+1)[a::a]:
        check[i] += 1
cnt = 0
for a in A:
    if check[a] == 1: cnt += 1
print(cnt)

Measured memory_bytes: 32276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {


        public void Calc()
        {
            var N = long.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();



            long count = 0;
            long num = 1;


            for (long i = 0; i < N; i++)
            {
                if (a[i] == num)
                {
                    num++;
                }
                else
                {
                    count++;
                }
            }

            Console.WriteLine((count != N) ? count : -1);

        }
    }
}

Measured memory_bytes: 36420
n, m = map(int, input().split())
pp = list(map(int, input().split()))
xyxy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind(list) :
    def __init__(self, n) :
        super().__init__(range(n))

    def find(self, i) :
        if self[i] == i : return i
        self[i] = self.find(self[i])
        return self[i]

    def union(self, x, y) :
        x = self.find(x)
        y = self.find(y)
        self[y] = x

    def sameroot(self, x, y) :
        return self.find(x) == self.find(y)

uf = UnionFind(n)
for x, y in xyxy :
    uf.union(x-1, y-1)
for i in range(n) :
    uf.find(i)

d = {}
for i, k in enumerate(uf) :
    if k not in d :
        d[k] = {i}
    else :
        d[k].add(i)

e = {}
for k, set0 in d.items():
    e[k] = set()
    for i in set0 :
        e[k].add(pp[i]-1)

ans = 0
for k in d.keys() :
    set0 = d[k]
    set1 = e[k]
    ans += len(set0&set1)

print(ans)

Measured memory_bytes: 101084
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string a, b, out = "No";
    int d, e;
    cin >> a >> b;
    e = stoi(a+b);
    for(int i=1;i<=1000;i++){
        if((i*i) == e){
            out = "Yes";
            break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
/* ex7_1.c "Ruined Square"
    dada__              */
#include<stdio.h>

//構造体pointの定義
typedef struct point{
    int x_elem;
    int y_elem;
}point;
//関数shift_pointの定義
point shift_point(point p1,point p2){
    point shift_p, vector, rot_vector;
    //始点p1終点p2のベクトル
    vector.x_elem=p2.x_elem-p1.x_elem;
    vector.y_elem=p2.y_elem-p1.y_elem;
    //vectorを90度回転
    rot_vector.x_elem=-vector.y_elem;
    rot_vector.y_elem=vector.x_elem;
    //p2の隣の点の座標(p1ではない方の)
    shift_p.x_elem=p2.x_elem+rot_vector.x_elem;
    shift_p.y_elem=p2.y_elem+rot_vector.y_elem;

    return shift_p;
}

int main(void){
    point p1, p2, p3, p4;
    //入力
    scanf("%d %d %d %d", &p1.x_elem, &p1.y_elem, &p2.x_elem, &p2.y_elem);
    //残り二点の座標の求値
    p3=shift_point(p1,p2);
    p4=shift_point(p2,p3);
    //出力
    printf("%d %d %d %d\n", p3.x_elem, p3.y_elem, p4.x_elem, p4.y_elem);

    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    set<char> sc;
    REP(i,s.size()) sc.insert(s[i]);

    int ans = INF;

    for(auto c : sc){
        bool flg = true;
        int sum = 0;
        string tmp = s;
        while(true){
            REP(i,tmp.size()) if(c!=tmp[i]) flg = false;
            if(flg) break;
            else{
                sum++;
                REP(i,tmp.size()) if(c!=tmp[i] && c==tmp[i+1]) tmp[i] = c;
                tmp.pop_back();
            }
            flg = true;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<string,ll>mp;
map<ll,ll>mpp;
vector<ll>v;
#define Y cout<<"YES"<<endl
#define N cout<<"NO"<<endl

int main()
{

  ll n;
  set<string>s;
  string str;

  cin>>n;

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

    cin>>str;

    s.insert(str);
  }

  cout<<s.size()<<endl;
}


Measured memory_bytes: 19224
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



// combination mod prime
// mintが必要
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    int n,m,k;
    cin >> n >> m >> k;
    mint ans = 0;
    combination c(n);
    for(int i=0;i<=k;i++){
        mint cnow = c(n-1,i);
        mint pnow = modpow(m-1,n-1-i);
        mint now = m;
        now *= cnow;
        now *= pnow;
        ans += now;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6348
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int win = 0;
    int lose = 0;
    for (int i = 0; i < s.length(); i++) {
      if (i % 2 == 0 && s.charAt(i) == 'p') {
        lose++;
      } else if (i % 2 == 1 && s.charAt(i) == 'g') {
        win++;
      }
    }
    System.out.println(win - lose);
  }
}

Measured memory_bytes: 23960
#!/usr/bin/env python3


def solve(K, X):
    left = max(X-K+1, -1000000)
    right = min(X+K-1, 1000000)
    ans = range(left, right+1)
    return ans


if __name__ == '__main__':
    K, X = map(int, input().split())

    ans = solve(K, X)

    print(' '.join(map(str, ans)))


Measured memory_bytes: 2940
// C - Modulo Summation
// https://atcoder.jp/contests/abc103/tasks/abc103_c
//
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n;
  vlli a(n);
  rep(i, 0, n)
  {
    cin >> a[i];
    ans += a[i] - 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iostream>

using namespace std;

int main(){
    int l,r,n, count = 0;
    cin >> l >> r >> n;
    for(int i = 0; n*i<=r; i++){
        if(n*i>=l){
            count++;
        }
    }
    cout << count;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF=(1LL<<60);
ll N,M,a[20],p[20];
double ans=0;

ll lcm(ll a,ll b){
  ll c=__gcd(a,b);
  a/=c;
  if(a>INF/b)return INF;
  else return a*b;
}

void dfs(int x,ll k,double rate,int cnt){
  if(x==N||k==INF){
    if(cnt%2==1)ans+=(double)(M/k)*rate;
    else if(cnt>0)ans-=(double)(M/k)*rate;
  }else{
    dfs(x+1,k,rate,cnt);
    dfs(x+1,lcm(k,a[x]),rate*(double)p[x]/100.0,cnt+1);
  }
}

int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)cin>>p[i];
  dfs(0,1,1.0,0);
  printf("%.12f\n",ans);
  return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#define MAXN 3000
using std::cout;
using std::cin;
typedef long long ll;
const int mod=1E9+7;
inline ll expow(ll a,int x){
	ll ret=1;
	while(x){
		if(x&1) ret=(ret*a)%mod;
		a=(a*a)%mod;
		x>>=1;
	}
	return ret;
}
ll f[2][MAXN+10][2];
inline void ModAdd(ll &x,ll delta){
	x+=delta%mod;
	while(x>=mod) x-=mod;
	if(x<0) x+=mod; 
}
int main(){
	int n,m;ll ans=0;
	cin>>n>>m;	
	if(n==1) return cout<<expow(2,m+1),0;
	if(n>=m) return cout<<expow(2,2*m),0;
	//BR&RB B   R   2 j   -> j
	//BB    B-- R++ 1 j-1 -> j
	//RR    R-- B-- 1 j+1 -> j
	int cur=0;f[cur][0][1]=1;
	for(int i=1;i<=n;i++) f[cur][i][0]=1;
	for(int i=1;i<=m;i++){// i-th times (1~m) last j blocks of R(1~n) R=0 exist or not (Minimum representation)
		cur^=1;                                     /*R->0*/ 
		f[cur][0][1]=(f[cur^1][0][1]+f[cur^1][1][1]+f[cur^1][1][0])%mod; 
		
		f[cur][1][0]=(f[cur^1][1][0]+f[cur^1][2][0])%mod;              /*R->0*/ 
		f[cur][1][1]=(f[cur^1][0][1]+2LL*f[cur^1][1][1]+f[cur^1][2][1]+f[cur^1][1][0])%mod; 
		
		for(int j=2;j<n;j++){
			f[cur][j][0]=(f[cur^1][j-1][0]+2LL*f[cur^1][j][0]+f[cur^1][j+1][0])%mod;
			f[cur][j][1]=(f[cur^1][j-1][1]+2LL*f[cur^1][j][1]+f[cur^1][j+1][1])%mod;
		}
		
		f[cur][n][0]=(f[cur^1][n-1][0]+f[cur^1][n][0])%mod;
		f[cur][n][1]=(f[cur^1][n-1][1]+f[cur^1][n][1])%mod;
	}
	for(int i=0;i<=n;i++) ModAdd(ans,f[cur][i][1]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

	//反転して後ろから
	reverse(S.begin(), S.end());
	string div[4] = {"dream","dreamer","erase","eraser"};
	for (int i = 0; i < 4; i++) reverse(div[i].begin(), div[i].end());
	bool flag = true;
	int i = 0;
	for (int i = 0; i < S.size();) {
		bool flag2 = false;
		for (int j = 0; j < 4; j++) {
			string d = div[j];
			if (S.substr(i,  d.size()) == d) {
				i += d.size();
				flag2 = true;
				break;
			}
		}
		if (!flag2) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
    
    /////////////////////////////////
    //                             //
    //  @ Author: Ali Mohammed Ali //
    //                             //
    /////////////////////////////////
    
    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        
        int num;
        int sum = 0;
        
        num = in.nextInt();
        
        for (int i = 1; i <= num; i++) {
            sum += i;
        }
        
        System.out.println(sum);
        
    } // End of Main method
    
  } // End of class

Measured memory_bytes: 27072
#include<iostream>
using namespace std;
int main(void){
  int N;
  cin>>N;
  int L[N];
  for(int i(0);i<N;i++){
    cin>>L[i];
  }
  int max=L[0];
  for(int i(1);i<N;i++){
    if(max<L[i])max=L[i];
  }
  int s(0);
  for(int i(0);i<N;i++){
    s+=L[i];
  }
  s-=max;
  if(max<s)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    string acl = "ACL";
    int K;
    cin >> K;
    for (int i=0; i<K; i++) {
        cout << acl;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define push push_back
#define ii pair <int, int>
const int N = 1e5 + 7;
const int INF = 1e12 + 7;
struct Ex {
    int b, l, r, f, s;
};  
int n, x;
Ex a[N];
bool comp(Ex a, Ex b) {
    return a.f + a.s > b.f + b.s;
}
int pr[N], ps[N];
bool check(int i, int m) {
    int r = m % x;
    int d = m / x;
    int c;
    if (r <= a[i].b) c = a[i].l;
    else c = a[i].r;
    if (d <= i) {
        return pr[d] + c * r >= ps[i + 1] + (ps[d] - ps[i]) + c * a[i].b;
    }
    else {
        return (pr[d + 1] - a[i].f) + c * r >= ps[d + 1] + c * a[i].b;
    }   
}   
bool check_(int i, int m) {
    int r = x;
    int d = m;
    int c;
    if (r <= a[i].b) c = a[i].l;
    else c = a[i].r;
    if (d <= i) {
        return pr[d] + c * r >= ps[i + 1] + (ps[d] - ps[i]) + c * a[i].b;
    }
    else {
        return (pr[d + 1] - a[i].f) + c * r >= ps[d + 1] + c * a[i].b;
    }   
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].b >> a[i].l >> a[i].r;
        a[i].f = a[i].r * (x - a[i].b);
        a[i].s = a[i].l * a[i].b;
    }
    sort(a, a + n, comp);
    int s = 0;
    for (int i = 0; i < n; ++i) s += a[i].b;
    if (s == 0) {
        cout << "0\n";
        exit(0);
    }   
    for (int i = n - 1; i >= 0; --i) {
        ps[i] = ps[i + 1] + a[i].s;
    }   
    for (int i = 0; i < n; ++i) {
        pr[i + 1] = pr[i] + a[i].f;
    }
    int ans = INF;
    for (int i = 0; i < n; ++i) {
        int l, r;
        l = -1; r = n - 1;
        while (l < r - 1) {
            int m = (l + r) >> 1;
            if (check_(i, m)) r = m;
            else l = m;
        }   
        int t = r;
        l = 0; r = x;
        while (l < r - 1) {
            int m = (l + r) >> 1;
            if (check(i, t * x + m)) r = m;
            else l = m;
        }   
        ans = min(ans, t * x + r);
    }   
    cout << ans << '\n';
}   

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

int main(void){
    int N=0, L=0;
    int i;
    cin >> N >> L;

    int apple_taste[N+1];
    apple_taste[0] = (int)NULL;
    for(i = 1; i < N+1; i++){
        apple_taste[i] = L + i - 1;
    }
    int abs_min = 2e9;
    int abs_min_index;
    
    for(i = 1; i < N+1; i++){
        if(abs(apple_taste[i]) < abs_min){
            abs_min_index = i;
            abs_min = abs(apple_taste[i]);
        }
    }
    int apple_pie_taste = 0;
    for(i = 1; i < N+1; i++){
        if(i != abs_min_index){
            apple_pie_taste += apple_taste[i];
        }
    }
    cout << apple_pie_taste << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int a, b; cin >> a >> b;
    if (a>=10 || b>=10) {
        cout << -1 << endl;
        return 0;
    }
    cout << a*b << endl;

}

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

using namespace std;
typedef long long ll;

int main(){
    int n;
    ll size = 0,ans = 0;
    cin>>n;
    map<string,int> s;
    string input;
    rep(i,n){
        cin>>input;
        sort(input.begin(),input.end());
        if(s.find(input) == s.end()){
            s.insert(make_pair(input,0));
        }
        else{
            s[input]++;
            ans += s[input];
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 11136
#include <cmath>
#include <cstdio>

typedef long long LL;

const int MAXD = 4005;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

LL mon[MAXD];
LL X;

int main()
{
	read( X );
	mon[0] = 100;
	for( int i = 1 ; i <= 4000 ; i ++ ) mon[i] = LL( ( double ) 1.01 * mon[i - 1] );
	int l = 0, r = 4000, mid;
	while( r - l > 1 )
	{
		if( mon[mid = l + r >> 1] >= X ) r = mid;
		else l = mid + 1;
	}
	if( mon[l] >= X ) write( l );
	else write( r );
	puts( "" );
	return 0;
}

Measured memory_bytes: 1560
from  collections import deque
H,W=list(map(int,input().split()))
S=[list(input()) for i in range(H)]
dxdy=[[1,0],[0,1],[-1,0],[0,-1]]
ans=0
for w in range(W):
    for h in range(H):
        if S[h][w]!='#':
            temp=0
            stack=deque([[h,w]])
            visited=[[-1 for i in range(W)]for j in range(H)]
            visited[h][w]=0
            while stack:
                x,y=stack.popleft()
                for i in dxdy:
                    nx,ny=x+i[0],y+i[1]
                    if 0<=nx<H and 0<=ny<W and S[nx][ny]!='#'and visited[nx][ny]==-1:
                        stack.append([nx,ny])
                        visited[nx][ny]=visited[x][y]+1
            temp=max([j for i in visited for j in i])
            ans=max(ans,temp)
print(ans)

Measured memory_bytes: 46960
n=int(input())
s=input()

num_E=s.count('E')
num_W=0
ans=float('inf')
for i in range(n):
    if s[i]=='W':
        ans=min(ans,num_W+num_E)
        num_W+=1
    else:
        num_E+=-1
        ans=min(ans,num_W+num_E)
print(ans)

Measured memory_bytes: 3668
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define n_inf -(1 < <30);

int main()
{
    string str;cin >> str;
    int a=stoi(str.substr(0,1));
    int b=stoi(str.substr(1,1));
    int c=stoi(str.substr(2,1));
    int d=stoi(str.substr(3,1));

    vector<int> v={0,1};
    for(int i:v){        
        for(int j:v){
            for(int k:v){
                int res = a;
                
                if(i==0) res += b;
                else if(i==1) res -= b;

                if(j==0) res += c;
                else if(j==1) res -= c;

                if(k==0) res += d;
                else if(k==1) res -= d;

                if(res==7){
                    string s="";
                    s += to_string(a);
                    s += (i==0?"+":"-");
                    s += to_string(b);
                    s += (j==0?"+":"-");
                    s += to_string(c);
                    s += (k==0?"+":"-");
                    s += to_string(d);
                    s += "=7";
                    p(s)
                    return 0;
                }
            }
        }
    }
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=300000+5,mod=1e9+7;
int Cnt_r[N],Cnt_c[N],r[N],c[N],vis[N];
vector<int> v[N];
int main(){
    GO();
    int n,m;
    cin>>n>>m;
    int cnt;
    cin>>cnt;
    int mx=0;
    for(int i=0;i<cnt;i++){
        cin>>r[i]>>c[i];
        Cnt_r[r[i]]++;
        Cnt_c[c[i]]++;
        mx=max(mx,Cnt_c[c[i]]);
        v[c[i]].pb(r[i]);
    }
    int tot=0;
    for(int i=1;i<=300000;i++){
        if(Cnt_c[i]==mx){

            for(int j=0;j<sz(v[i]);j++){
                int rw=v[i][j];
                vis[rw]++;
            }
            tot++;
        }
    }
    int res=0;
    for(int i=1;i<=300000;i++){
        int ans= Cnt_r[i]+(vis[i]!=tot?mx:mx-1);
        res=max(res,ans);
    }
    cout<<res<<"\n";

}

























































































































































































Measured memory_bytes: 25836
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int N,r=0,b=0;
  string s;
  cin>>N>>s;
  for(char i:s){
    if(i=='R')r++;
    else b++;
  }
  if(r>b)cout<<"Yes"<<"\n";
  else cout<<"No"<<"\n";
}

Measured memory_bytes: 3632
// Aizu 1600: Entrance Examination
// 2017.9.21 bal4u@uu

#include <stdio.h>

int p[203];

int main()
{
	int m, nmin, nmax, i, gap, d, ans;

	while (scanf("%d%d%d", &m, &nmin, &nmax) && m) {
		for (i = 0; i < m; i++) scanf("%d", p+i);
		for (gap = -1, i = nmax-1; i >= nmin-1; i--) {
			if ((d = p[i] - p[i+1]) > gap) gap = d, ans = i+1;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1848
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main() {
  string s, t;
  int count=0;
  cin >>s>>t;
  rep (i,3) {
    if(s.at(i)==t.at(i)) {
      count++;
    }
  }
    cout << count << endl;
}

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

double x,y;
int a,b,c,d,e,f;
int sisya = 1000;


void setX() {
    double ae, bd, ce, bf;
    
    ae = a * e;
    bd = b * d;
    ce = c * e;
    bf = b * f;
    
    x = (double)((ce - bf) / (ae - bd));
    x *= sisya;
    if(x >= 0) x += 0.5;
    else x -= 0.5;
    x = int(x);
    x /= sisya;
}

void setY() {
    double ae, af, cd, bd;
    
    bd = b * d;
    ae = a * e;
    cd = c * d;
    af = a * f;
    
    y = (double)((cd - af) / (bd - ae));
    y *= sisya;
    if(y >= 0) y += 0.5;
    else y -= 0.5;
    y = int(y);
    y /= sisya;
    
}

int main(void) {    
    while(cin >> a >> b >> c >> d >> e >> f) {
        setX();
        setY();
        cout << setprecision(3);
        cout << setiosflags(ios::fixed);
        cout << x << " " << y << endl;
    }
    return 0;
}

Measured memory_bytes: 1236
/*
  AOJ 2188
  Title:Unit Converter
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
char buf[1061];
char num[1001];
char unit[60];
int n;
int sig_dig;
int point_pos;
struct prefix_exponent_st
{
  char prefix[7];
  int  exponent;
}
prefix_table[20]={
  {"yotta",24},
  {"zetta",21},
  {"exa",  18},
  {"peta", 15},
  {"tera", 12},
  {"giga",  9},
  {"mega",  6},
  {"kilo",  3},
  {"hecto", 2},
  {"deca",  1},
  {"deci", -1}, 
  {"centi",-2},
  {"milli",-3},
  {"micro",-6},
  {"nano", -9},
  {"pico", -12},
  {"femto",-15},
  {"ato",  -18},
  {"zepto",-21},
  {"yocto",-24}
};

int prefix2exponent(char *s)
{
  int i;
  for(i=0;i<20;i++)
    if(0==strcmp(prefix_table[i].prefix,s))
      return(prefix_table[i].exponent);
  return(0);
}
void output(char *num,int expo,char *unit)
{
  int c,len,i;
  char *p;

  if(*num=='0')
    {
      p=num;
      p+=2;c=1;
      while(*p=='0')
	{
	  c++;      
	  p++;
	}
      if(*(p+1))
	printf("%c.%s * 10^%d %s",*p,p+1,expo-c,unit);
      else
	printf("%c * 10^%d %s",*p,expo-c,unit);
    }
  else
    {
      c=strlen(num);
      for(i=0;i<strlen(num);i++)
	if(num[i]=='.')
	  c=i;
	else if(i==0)
	  printf("%c.",num[i]);
	else
	  printf("%c",num[i]);
      printf(" * 10^%d %s",expo+c-1,unit);
    }
}

main()
{
  int i,expon;
  char *p;
  scanf("%d ",&n);
  for(i=0;i<n;i++)
    {
      fgets(buf,1061,stdin);

      p=strtok(buf," ");
      strcpy(num,p);
      //printf("p=%s\n",num);

      p=strtok(NULL," ");
      if(0 != (expon=prefix2exponent(p)))
	p=strtok(NULL," ");
      strcpy(unit,p);

      output(num,expon,unit);
    }
  return(0);
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    string S;
    cin>>S;
    int ans=0,p=0;
    string now="";
    while(p<S.size()){
        if(now.size()==1 && S.at(p)==now.at(0)){
            if(p+1<S.size()){
            ans++;
            now="";
            now.pb(S.at(p));
            now.pb(S.at(p+1));}
            p+=2;
        }
        else{
            ans++;
            now="";
            now.pb(S.at(p));
            p++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
    int n = 0;
    int k = 0;
    std::cin >> n >> k;
    
    std::string faceline;
    std::cin >> faceline;

    int happy = n;
    
    for(int index = 1; index < n; ++index)
    {
        if(faceline.at(index - 1) == 'R' && faceline.at(index) == 'L')
        {
            // "RL"のペアはどちらもunhappy
            happy -= 2;
        }
    }
    
    // 左端がL
    if(faceline.front() == 'L')
    {
        // 左端の人はunhappy
        --happy;
    }

    // 右端がR
    if(faceline.back() == 'R')
    {
        // 右端の人はunhappy
        --happy;
    }
    
    // 1回の回転で2人がhappyに
    // 最後の1回は1人だが、「最大でもn-1人」で判定できる
    std::cout << (std::min)(happy + 2 * k, n - 1) << std::endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=2e9;

int main(){
    int n; cin>>n;
    int mina=INF,maxa=-INF;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        mina=min(mina,a);
        maxa=max(maxa,a);
    }
    cout<<maxa-mina<<endl;
}


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

int main() {
  int X,Y;
  int sum=0;
  int base=1;

  cin >> X;
  Y = X;
  for (int i=0; i<8; i++){
      base *= 10;
      for (int j=0; j<10; j++) {
          if ((X-j*(base/10))%base==0) {
              X -= j*(base/10);
              sum += j;
              break;
          }       
      }
      if (X==0) break;
  }

  if (Y % sum == 0) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, A = getNM()
Q = getList()
for i in range(N):
    Q[i] -= A

dp = [[0] * 5002 for i in range(N + 1)]
dp[0][2501] = 1

for i in range(1, N + 1):
    for j in range(5002):
        dp[i][j] += dp[i - 1][j]
        if 0 <= j - Q[i - 1] <= 5001:
            dp[i][j] += dp[i - 1][j - Q[i - 1]]

print(dp[-1][2501] - 1)

Measured memory_bytes: 83656
#include <stdio.h>

double get_normal_distance(int p, int n, int *x, int *y){
	int i,j;
	double dist,dist_p,dist_p_sum;
	double unit, result, result_next, result_next_p;

	// Calc Total
	dist_p_sum = 0;
	for(i=0; i<n; i++){
		dist = x[i] - y[i];
		if( dist < 0 ){
			dist *= (-1);
		}
		dist_p = dist;
		for(j=2;j<=p;j++){
			dist_p *= dist;
		}
		dist_p_sum += dist_p;
	}
	// Calc Result
	result = 0.0;
	for(i=31;i>=-31;i--){
		// Get Unit
		unit = 1.0;
		if( i > 0 ){
			for(j=1;j<=i;j++){
				unit *= 2.0;
			}
		} else if( i < 0 ){
			for(j=-1;j>=i;j--){
				unit /= 2.0;
			}
		}
		// Try & Add
		result_next = result;
		result_next += unit;
		result_next_p = 1.0;
		for(j=1;j<=p;j++){
			result_next_p *= result_next;
		}
		if( result_next_p <= dist_p_sum ){
			result = result_next;
		}
	}

	return result;
}

double get_infinity_distance(int n, int *x, int *y){
	int result = 0;
	int i,val;

	for(i=0; i<n; i++){
		val = x[i] - y[i];
		if( val < 0 ){
			val *= (-1);
		}
		if( val > result ){
			result = val;
		}
	}

	return (double)result;
}

int main(int argc, char** argv){
	int i,j;
	int n,xy[2][100];
	
	// Input
	scanf("%d",&n);
	for(i=0;i<=1;i++){
		for(j=0;j<n;j++){
			scanf("%d",xy[i]+j);
		}
	}

	// Output
	for(i=1;i<=3;i++){
		printf("%f\n",get_normal_distance(i, n, xy[0], xy[1]));
	}
	printf("%f\n",get_infinity_distance(n, xy[0], xy[1]));

	return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;


int main() {
    long long K,A,B;
    cin>>K>>A>>B;
    long long ans;
    if(A+2>=B||K<=A){
        ans=K+1;
    }
    else{
        ans=((K-A+1)/2)*(B-A)+A;
        if((K-A+1)%2==1){
            ans+=1;
        }
        }
    cout<<ans<<endl;
    
        
        
        
        
    }
          

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin >> S;
    string x=S.substr(0,2);
    string y=S.substr(2,2);

    int p = stoi(x);
    int q=stoi(y);
    string ans="NA";
    if(0<p && 13>p){
        if(0<q && 13>q) ans="AMBIGUOUS";
        else ans="MMYY";
    }else if(0<q && 13>q){
        ans="YYMM";
    }
    cout << ans << endl;



}


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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i);
    if (i < vec.size() - 1)
    {
      cout << ", ";
    }
  }
  cout << "]...size: " << vec.size() << endl;
}

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

  int least = 1001001001;
  int most = -1001001001;
  int64_t sum = 0;

  rep(i, n)
  {
    int num;
    cin >> num;

    least = min(least, num);
    most = max(most, num);
    sum += num;
  }

  printf("%d %d %ld\n", least, most, sum);
}



Measured memory_bytes: 3228
import collections


def bfs(i, path, dist, N):
    moves = 0

    pp = []
    pp = path[i]

    reached = [False for _ in range(N)]
    dist[i] = 0
    reached[i] = True
    for j in range(N + 1):
        moves += 1
        next_pp = []
        for i in pp:
            if reached[i]:
                continue
            else:
                reached[i] = True
                dist[i] = moves
                for p in path[i]:
                    next_pp.append(p)

        pp = next_pp


def flatten(nested_list):
    return [e for inner_list in nested_list for e in inner_list]


def main():
    N, X, Y = map(int, input().split())

    path = [[] for _ in range(N)]

    for i in range(N - 1):
        path[i].append(i + 1)
        path[i + 1].append(i)

    path[X - 1].append(Y - 1)
    path[Y - 1].append(X - 1)

    dist = [N for _ in range(N)]

    D_list = []

    for i in range(N):
        dist[i] = 0
        bfs(i, path, dist, N)
        D_list.append(dist)
        dist = [N for _ in range(N)]

    D = flatten(D_list)
    dic = collections.Counter(D)

    for i in range(1, N):
        print(dic[i] // 2)


main()


Measured memory_bytes: 174764
//gcc listsirkuler.c map.c player.c mesinkata.c mesinkar.c matriks.c pcolor.c point.c queue.c unit.c main.c -o main
#include <bits/stdc++.h>
#define Semangat using
#define World namespace
#define Final std;
#define WF {ios_base::sync_with_stdio(0);cin.tie(0);}
 
Semangat World Final

long x,y,z,i;

int main(){
	WF
	cin>>x>>y>>z;
	for(i=0; i<=100000; i++){
		if(y*i+z*(i+1)>x)
			break;
	}
	cout<<i-1<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
			tree_order_statistics_node_update>
	new_data_set;
//   <<implemented_sorted_vector>>  new_data_set p;
//   <<insert_like_set>>           insert(key):log(n)
//<<accessing_iterator_by_index>> find_by_order(idx):log(n)
//	    <<accessing_by_value>>   order_of_key(key):log(n)
// << replace less<int> by greater<int> for descending order>>
// find(key), erase(find(key)) works the same!
typedef long long ll;
typedef long l;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ERR(x) cout<<"#x:"<<x<<endl
#define ERR2(x,y) cout<<"#x:"<<x<<" "<<"#y:"<<y<<endl;
#define ERR3(x,y,z) cout<<"#x:"<<x<<" "<<"#y:"<<y<<" "<<"#z:"<<z<<endl;
#define show(v) for(auto e: v) cout<<e<<" ";
#define showArr(A,n) for(int i=0;i<n;i++) cout<<A[i]<<" ";
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll>::iterator
#define all(v) v.begin(),v.end()

ll nextW(ll i, string str){
	for(int j=i+1;j<str.length();j++){
		if(str[j] == 'W'){
			return j;
		}
	}
	return str.length();
}

ll prevR(ll j, string str){
	for(int i=j-1;i>=0;i--){
		if(str[i] == 'R'){
			return i;
		}
	}
	return -1;
}

int main()
{
	ll n;
	cin>>n;
	string str;
	cin>>str;
	// two pointer method
	ll i=-1,j=n;
	ll count = 0;
	while(i < j){
		i = nextW(i,str);
		j = prevR(j,str);
		if(j <= i){
			break;
		}
		else{
			count++;
		}
	}
	cout<<count;
	return 0;
}


Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
int f,tot,vis[N],a[N],b[N];
PI q[N<<1];
ll s,s1,s2,ans;
int main(){
	int n=read(); 
	For(i,1,n){
		a[i]=read(); b[i]=read();
		s1+=a[i]; s2+=b[i];
		q[++tot]=mp(a[i],i);
		q[++tot]=mp(b[i],i);
	}
	ans=min(s1,s2);
	sort(q+1,q+tot+1);
	For(i,1,n){
		if(vis[q[i].se])f=1;
		vis[q[i].se]=1;
		s+=q[i].fi;
	}
	if(f)cout<<s<<endl;
	else{
		if(q[n+1].se!=q[n].se)ans=min(ans,s+q[n+1].fi-q[n].fi);
		else{
			ans=min(ans,min(s+q[n+1].fi-q[n-1].fi,s+q[n+2].fi-q[n].fi));
		}
		cout<<ans<<endl;
	}
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<pair<int,int>>;//隣接する点とその点までのコスト

int main(){
  int H,W; cin>>H>>W;

  //ワーシャルフロイド法を用いてiから1の最短距離を計算していく
  vector<vector<int>> dp(10,vector<int>(10));
  rep(i,10){
    rep(j,10){
      int c; cin>>c;
      dp.at(i).at(j)=c;
    }
  }

  vector<int> res(10,0);//res(i)はAに含まれるiの個数
  rep(i,H)rep(j,W){
    int a; cin>>a;
    if(a==-1)continue;
    res.at(a)++;
  }

  for(int k = 0; k < 10; k++){
    for(int i = 0; i < 10; i++){
      for(int j = 0; j < 10; j++){
        dp.at(i).at(j)=min(dp.at(i).at(j),dp.at(i).at(k)+dp.at(k).at(j));
      }
    }
  }
  ll ans = 0;
  //v.at(i)からv.at(1)への最短距離はdp.at(i).at(1)を計算
  for(int i = 0; i < 10; i++){
    if(i==1)continue;
    else{
      ans+=res.at(i)*dp.at(i).at(1);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

map<string, int> memo;

int main() {
    int n;
    cin >> n;
    rep(i, n){
        string s;
        cin >> s;
        memo[s] += 1;
    }
    cout << memo.size() << endl;


}

Measured memory_bytes: 19224
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
		int times = sc.nextInt();
		int time = times % 3600 / 60;
		System.out.println(times / 3600 + ":" + time + ":" +  times % 60);
	}
}



Measured memory_bytes: 26372
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    string s = "ACL";
    for (int i = 0; i < k; i++) cout << s;
    cout << '\n';
    return 0;
}


Measured memory_bytes: 3520
#include<iostream>
#include<set>
#include<vector>

using namespace std;

int main() {
  int N,M;
  cin >> N >> M;
  set<int> winners;
  vector<long long int> Hs;
  for(int i=0;i<N;i++){
    long long int H;
    cin >> H;
    Hs.push_back(H);
    winners.insert(i);
  }
  for(int i=0;i<M;i++){
    int A,B;
    cin >> A >> B;
    if(Hs[A-1]>Hs[B-1]){
      winners.erase(B-1);
    }else if(Hs[A-1]<Hs[B-1]){
      winners.erase(A-1);
    }else{
      winners.erase(A-1);
      winners.erase(B-1);
    }
  }
  cout << winners.size() << endl;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

string str1,str2;
int ans;

int main(){

  cin >> str1 >> str2;
  ans = 0;
  for(int i = 0; i < 3; ++i){
    if(str1[i]==str2[i]){
      ans++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main()
{
  long long A, B;
  cin >> A >> B;
  long long ans = 0, now = 1;
  B++;
  for (int i = 0; i < 63; i++)
  {
    long long cntA, cntB;
    cntA = A / (now * 2) * now + ((A + now - 1) / now % 2 == 0 ? A % now : 0);
    cntB = B / (now * 2) * now + ((B + now - 1) / now % 2 == 0 ? B % now : 0);
    if ((cntB - cntA) % 2 == 1)
      ans |= (1LL << i);
    now *= 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256