akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <vector>   // vector
#include <iomanip>
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
using namespace std;

int main(void)
{
  int a, b;
  cin >> a >> b;
  cout << a / b << " " << a % b << " " << fixed << setprecision(20) << static_cast<double>(a) / b << endl;
  return 0;
}


Measured memory_bytes: 3284
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main()
{
	int R[MAX],n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>R[i];
	int maxv=-2000000000;
	int minv=R[0];
	for(int i=1;i<n;i++)
	{
		maxv=max(maxv,R[i]-minv);
		minv=min(minv,R[i]);
	}
	cout<<maxv<<endl;
	return 0;
}


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

using namespace std;

int main()
{
    int n;

    cin >> n;

    long long int ans = 0;

    for (int i = 0; i <= n; i++)
    {
        if (i % 3 == 0 || i % 5 == 0)
            continue;

        ans += i;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3644
import math
A, B = map(int, input().strip().split())
def helper(val):
  return math.floor(val * 0.08) == A and math.floor(val * 0.1) == B

i = 0
while i < 1100:
  if helper(i):
    print(i)
    exit()
  i += 1

print(-1)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int keta_sum(int x){
  
  int sum = 0; //各桁の和
  
  while(true){
    int r = x%10;
    sum += r;
    x = x/10;
    if(x == 0) break;
  }
  
  return sum;
  
}

int main(){
  int N;
  cin >> N;
  int ans = 1000000;
  for(int i = 1;i<=N/2;i++){
    int A = i;
    int B = N-i;
    int keta_sum_ab = keta_sum(A) + keta_sum(B);
    ans = min(ans,keta_sum_ab);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
x = int(input())

A = [i for i in range(500)]
B = [i for i in range(-500, 500)]

for a in A:
	for b in B:
		if a - b != 0:
			if x % (a - b) == 0:
				if a ** 5 - b ** 5 == x:
					print(a, b)
					exit()

Measured memory_bytes: 64724
#include<cstdio>
#include<iostream>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.find("AC")!=string::npos) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int M = (1 << N);
    long A[M];
    pair<long, long> maximum[N + 1][M];
    for(int i = 0; i < M; i++){
        cin >> A[i];
        maximum[0][i] = {A[i], 0};
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(j & (1 << i)){
                long nums[4] = {maximum[i][j].first, maximum[i][j].second, maximum[i][j & ~(1 << i)].first, maximum[i][j & ~(1 << i)].second};
                sort(nums, nums + 4, greater<long>());
                maximum[i + 1][j] = {nums[0], nums[1]};
            }else{
                maximum[i + 1][j] = maximum[i][j];
            }
        }
    }
    for(int i = 1; i < M; i++){
        long ans = maximum[N][i].first + maximum[N][i].second;
        for(int j = 0; j < N; j++){
            if(i & (1 << j)){
                int this_pattern = ((i & ~(1 << j)) | ((1 << j) - 1));
                ans = max(ans, maximum[N][this_pattern].first + maximum[N][this_pattern].second);
            }
        }
        cout << ans << endl;
    }
}


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

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

using namespace std;

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

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,k,sr,sb,sa;
int a[65],r[65],b[65],d[65][3005],f[65][3005];

int main(){
	n=readint(); k=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	for(int i=1;i<=k;i++) r[i]=readint();
	for(int i=1;i<=k;i++) b[i]=readint();
	for(int i=1;i<=k;i++) sr+=r[i],sb+=b[i];
	for(int i=1;i<=n;i++) sa+=a[i];
	sort(r+1,r+k+1); reverse(r+1,r+k+1);
	sort(b+1,b+k+1); reverse(b+1,b+k+1);
	sort(a+1,a+n+1); reverse(a+1,a+n+1);
	memset(f,0x3f,sizeof(f));
	memset(d,0x3f,sizeof(d));
	d[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			for(int l=0;l<=sr;l++){
				if(j&&j<=k&&l>=a[i]) chkmin(f[j][l],d[j-1][l-a[i]]+max(0,a[i]-r[j]));
				if(i-j&&i-j<=k) chkmin(f[j][l],d[j][l]+max(0,a[i]-b[i-j]));
			}
		}
		swap(d,f);
		memset(f,0x3f,sizeof(f));
	}
	int ans=0x3f3f3f3f;
	for(int i=0;i<=k;i++) for(int k=0;k<=sr;k++) if(sa-k<=sb) chkmin(ans,d[i][k]);
	printf("%d\n",ans==(0x3f3f3f3f)?-1:ans);
	return 0;
}


Measured memory_bytes: 4808
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

#define rep(i, n) for(int i=0;i<(int)(n);i++)

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 N;
string S, T;

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

    for (int i = 0; i < N; i++) {
        cout << S[i] << T[i];
    }
    cout << endl;
}



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

int main(){
  double A, B, H, M;
  cin>>A>>B>>H>>M;
  
  double a1 = 360*(H*60+M)/(12*60);
  double a2 = 6*M;
  
  //cout<<a1<<' '<<a2<<endl;
  double diff=abs(a1-a2);
  diff = min(diff, 360-diff);
  
  const double PI = acos(-1);
  double ans_2 = A*A + B*B - 2*A*B*cos(diff*PI/180);
  
  cout<<fixed<<setprecision(20)<<sqrt(ans_2)<<endl;
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[100010];
int main() {
	ll n,t;
	cin>>n>>t;
	map<ll,ll>b;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll buy=a[0];
	for(ll i=1;i<n;i++){
		b[a[i]-buy]++;
		buy=min(buy,a[i]);
	}
	cout << b.rbegin()->second;
	// your code goes here
	return 0;
}

Measured memory_bytes: 7296
import sys
INF = 9999999999999
N = int(input())
A = [int(n) for n in input().split()]
memo = [INF]*N
memo[0] = 0
memo[1] = abs(A[1] - A[0])
for i in range(2,N):
    memo[i] = min(memo[i], memo[i-1] + abs(A[i] - A[i-1]))
    memo[i] = min(memo[i], memo[i-2] + abs(A[i] - A[i-2]))
print(memo[N-1])


Measured memory_bytes: 14052
module Main where

import qualified Data.Vector as V
import           Data.List
import           Control.Applicative
import           Control.Monad

main :: IO ()
main = do
  n <- readLn
  print $ f n 0

f n x
  | x ^ 2 <= n = f n $ x + 1
  | otherwise = (x - 1) ^ 2


Measured memory_bytes: 892
from collections import Counter
S = input()
c = list(Counter(S).values())

if len(c) != 3:
    ans = "YES" if len(S) == len(c) else "NO"
else:
    flag = True
    for i in range(len(c) - 1):
        for j in range(i+1, len(c)):
            if abs(c[i] - c[j]) > 1:
                flag = False
    ans = "YES" if flag else "NO"

print(ans)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <cstdlib>
// #include <algorithm>
// #include <cmath>
// #include <vector>
// #include <set>
// #include <map>
// #include <queue>
// #include <ctime>
// #include <cassert>
// #include <complex>
// #include <string>
// #include <cstring>
// #include <queue>
// #include <bitset>

using namespace std;

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


#define ll              long long int
#define vi              vector< int >
#define vll             vector< ll >

#define sc              scanf
#define pf              printf
#define cspf(i)         pf("Case %d: ", i)
#define spc             pf(" ")
#define line            pf("\n")

#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define ppb             pop_back
#define tp(v,j)         get<j>(v)
#define Log(b,x)        (log(x)/log(b))

#define FOR(i,x,y)      for(int i = int(x); i < int(y); i++)
#define ROF(i,x,y)      for(int i = int(x)-1; i >= int(y); i--)
#define clr(arr,x)      memset(arr, x, sizeof arr)
#define vout(v,sz)      for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
#define all(v)          v.begin(), v.end()
#define rall(v)         v.rbegin(), v.rend()
#define unq(v)          sort(all(v)),(v).resize(unique(all(v))-v.begin())
#define fastIO          ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define sc1(x)          sc("%d",&x)
#define sc2(x,y)        sc("%d %d", &x, &y)
#define sc3(x,y,z)      sc("%d %d %d", &x, &y, &z)
#define scl1(x)         sc("%lld",&x);
#define scl2(x,y)       sc("%lld %lld", &x, &y)
#define scf1(x)         sc("%lf",&x)
#define scf2(x,y)       sc("%lf %lf", &x, &y)

#define pf1(x)          pf("%d",x)
#define pf2(x,y)        pf("%d %d", x, y)
#define pf3(x,y,z)      pf("%d %d %d", x, y, z)
#define pfl1(x)         pf("%lld",x)
#define pfl2(x,y)       pf("%lld %lld",x,y)
 
#define MOD             (int)(998244353)
#define MaxN            200000
#define inf             0x3f3f3f3f
#define PI              acos(-1.0)  // 3.1415926535897932
#define eps             1e-9

template <class T> inline T bigMod(T p,T e,T M){T ret=1; for(;e>0;e>>=1){ if(e&1) ret=(ret*p)%M; p=(p*p)%M;} return (T)ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline T SQR(T a){return a*a;}


 
int main()
{
    // #ifndef ONLINE_JUDGE
    //     clock_t tStart = clock();
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    // #endif   
    
    ll n,k; scl2(n,k);
    ll x = (n/k) * k;
    ll y = ((n+k-1)/k)*k;
    cout<< min(n-x, y-n)<<'\n';



    // #ifndef ONLINE_JUDGE
    //     fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    // #endif

    return 0;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    max_num = 0
    for i in range(n-1):
        for j in range(i+1,n):
            max_num = max(max_num, abs(num_list[i]-num_list[j]))

    print(max_num)

if __name__ == '__main__':
    main()


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

const int Mod = 1000000007;
int main() {
	int N;
	cin >> N;
	vector<int> T(N), A(N);
	vector<long long>MIN(N), MAX(N);
	for (int i = 0; i < N; i++) cin >> T[i];
	for (int i = 0; i < N; i++) cin >> A[i];
	MIN[0] = T[0];
	MAX[0] = T[0];
	for (int i = 1; i < N; i++) {
		if (T[i] > T[i - 1]) {
			MIN[i] = T[i];
			MAX[i] = T[i];
		}
		else {
			MAX[i] = MAX[i - 1];
			MIN[i] = 1ll;
		}
	}
	MIN[N - 1] = max(MIN[N - 1], (long long)A[N - 1]);
	MAX[N - 1] = min(MAX[N - 1], (long long)A[N - 1]);
	for (int i = N - 2; i >= 0; i--) {
		if (A[i] > A[i + 1]) {
			MIN[i] = A[i];
			MAX[i] = A[i];
		}
		else {
			MAX[i] = min(MAX[i], MAX[i + 1]);
			MIN[i] = max(MIN[i], 1ll);
		}
	}
	long long ans = 1;
	for (int i = 0; i < N; i++) {
		ans *= max(0ll, MAX[i] - MIN[i] + 1);
		ans %= Mod;
	}
	cout << ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

int isvacant(int i)
{
    std::cout << i << endl;
    fflush(stdout);
    string s;
    cin >> s;
    if (s[0] == 'V')
    {
        exit(0);
    }
    else if (s[0] == 'F')
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

void solve()
{
    int N;
    cin >> N;
    int l = 0, r = N - 1;

    int sl = isvacant(l);
    int sr = isvacant(r);

    while (true)
    {
        int m = (l + r) >> 1;
        int sm = isvacant(m);
        if ((sm == sl) != (l % 2 == m % 2))
        {
            r = m;
            sr = sm;
        }
        else
        {
            l = m;
            sl = sm;
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int cnt = 0;
  rep(i, s.size()) {
    if(s[i] != t[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3848
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll inf = (1 << 29);
template<typename T>
T GCD(T a, T b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a = a % b;
		else b = b % a;
	}
	return min(a, b);
}
template<typename T>
T LCM(T a, T b) {
	return a / GCD(a, b)*b;
}
bool prime(ll a) {
	for (int i = 2; i <= sqrt(a); i++) {
		if (!(a%i))return false;
	}
	return true;
}
int ans[1010][1010];
int main() {
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 0; i < m; i++) {
		int s, e;
		cin >> s >> e;
		ans[s][e]++;
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			ans[i][j] += ans[i - 1][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 2; j <= n; j++) {
			ans[i][j] += ans[i][j - 1];
		}
	}
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		cout << ans[y][y] - ans[x][y] - ans[y][x] + ans[x][x] << endl;
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <tuple>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){

    long long A;
    string B;
    cin >> A >> B;

    string C;


    for(long long i = 0; i < B.size(); i++){
        if(B.at(i) == '.'){
            continue;
        }

        else{
            C += B.at(i);
        }
    }

    long long B_num;

    B_num = stoll(C);

    long long result;

    result = A * B_num / 100;
    
    cout << result << endl;



}

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

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;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

struct PROFILE {
    char name[5];
    int score;
};

bool operator<(const PROFILE& left, const PROFILE& right)
{
    return left.score > right.score;
}

int main(void)
{
    struct PROFILE team[10];
    int n;
    
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < 10; i++){
           team[i].score = 0;
        }
        
        int tmp;
        for (int i = 0; i < n; i++){
            scanf("%s", team[i].name);
            for (int j = 0; j < (n - 1); j++){
                scanf("%d", &tmp);
                if (tmp == 0) team[i].score += (n - 1);
                else if (tmp == 1) team[i].score += -1;
            }
        }
        
        
        sort(team, team + n);
        
        for (int i = 0; i < n; i++){
            printf("%c\n", team[i].name[0]);
        }
    }
    
    return (0);
}

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

int main()
{
    int a, b, c, tmp;
    cin >> a >> b >> c;

    // 箱Aと箱Bの中身を入れ替える
    tmp = a;
    a = b;
    b = tmp;

    // 箱Aと箱Cの中身を入れ替える
    tmp = a;
    a = c;
    c = tmp;

    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        int i;

        int n = int.Parse(Console.ReadLine());
        string[] s = new string[n];

        for(i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }

        int acCnt = 0;
        int waCnt = 0;
        int tleCnt = 0;
        int reCnt = 0;

        for(i = 0; i < n; i++)
        {
            switch (s[i])
            {
                case "AC":
                    acCnt++;
                    break;
                case "WA":
                    waCnt++;
                    break;
                case "TLE":
                    tleCnt++;
                    break;
                case "RE":
                    reCnt++;
                    break;
            }
        }

        Console.WriteLine("AC x " + acCnt);
        Console.WriteLine("WA x " + waCnt);
        Console.WriteLine("TLE x " + tleCnt);
        Console.WriteLine("RE x " + reCnt);

        return;
    }
}

Measured memory_bytes: 31484
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  map<char, int> m;
  vector<char> ans;
  m['A'] = a;
  m['B'] = b;
  m['C'] = c;
  rep(i, n) {
    string res = s[i];
    if (m[res[0]] == 0 && m[res[1]] == 0) {
      cout << "No\n";
      return 0;
    }
    else if (m[res[0]] == 0) {
      m[res[0]]++;
      m[res[1]]--;
      ans.push_back(res[0]);
    }
    else if (m[res[1]] == 0) {
      m[res[1]]++;
      m[res[0]]--;
      ans.push_back(res[1]);
    }
    else if (i != n - 1 && m[res[0]] == 1 && m[res[1]] == 1) {
      string nxt = s[i + 1];
      if (res[0] == nxt[0] || res[0] == nxt[1]) {
        m[res[0]]++;
        m[res[1]]--;
        ans.push_back(res[0]);
      }
      else {
        m[res[1]]++;
        m[res[0]]--;
        ans.push_back(res[1]);
      }
    }
    else {
      if (m[res[0]] < m[res[1]]) {
        m[res[0]]++;
        m[res[1]]--;
        ans.push_back(res[0]);
      }
      else {
        m[res[1]]++;
        m[res[0]]--;
        ans.push_back(res[1]);
      }
    }
  }
  cout << "Yes\n";
  rep(i, n) cout << ans[i] << '\n';







  
  return 0;
}

Measured memory_bytes: 6700
#include<bits/stdc++.h>
using namespace std;
char a;
int ans;
int main()
{
	while(cin>>a){
		if(a=='C'&&ans==0)ans++;
		if(a=='F'&&ans==1){
			cout<<"Yes"<<endl;
			return 0;
			
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
 
		long nico = Long.parseLong(sc.nextLine());
		long maki = nico % 50;
		
		int n = 50;
		System.out.println(n);
		
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			long num = 49 + nico / 50;
			if (i < maki) {
				num = num + 50 - maki + 1;
			} else {
				num = num - maki;
			}
				
			if (i == 0) {
				sb.append(num);
			} else {
				sb.append(" " + num);
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2; typedef pair<int, P2> P3;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<1010> fact; constexpr Prime<10> prime;
constexpr long long comb(int a, int b){if(a < b) return 0LL;if(!a or !b) return 1LL; long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b]; return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr long double PI = abs(acos(-1));
constexpr int sqrtN = 512, logN = 32;
constexpr long long LINF=1e18;

int main(){
	string a, b, c; cin >> a >> b >> c;
	
	if(a.back() == b[0] and b.back() == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	
	return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

const int n = 8;
const int s[] = {4, 1, 4, 1, 2, 1, 2, 1};
int p[n];
int res;
int ptr;

inline int next(int& ptr){ return ptr = (ptr + 1) % n; }

int main()
{
  while(true){
    int sum;
    int mn = INF;
    rep(i, n) if(!(cin >> p[i])) return 0;
    rep(i, n){
      sum = 0;
      rep(j, n) sum += max(p[j] - s[(i + j) % n], 0);
      if(mn == sum){
        vi a, b;
        rep(k, n) a.pb(s[(k + res) % n]);
        rep(k, n) b.pb(s[(k + i) % n]);
        if(a > b) res = i;
      }
      else if(minup(mn, sum)) res = i;
    }
    rep(i, n) cout << s[(i + res) % n] << (i >= n-1 ? "\n" : " ");
  }

  return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<algorithm>

using namespace std;
int main() {
	int n, s[101], m = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		m = m + s[i];
	}
	sort(s, s + n);
	for (int i = 0; i < n; i++) {
		if (m % 10 != 0) {
			break;
		}
		m = m - s[i];
		if (m % 10 != 0) {
			break;
		}
		m = m + s[i];
	}
	if (m % 10 == 0) {
		cout << "0" << endl;
	}
	else {
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 256
local n, a, b = io.read("*n", "*n", "*n")
if (a + b) % 2 == 0 then
  print((b - a) // 2)
else
  local c = b - a
  local p1 = a + (c - 1) // 2

  a, b = n + 1 - a, n + 1 - b
  local d = b - a
  local p2 = a + (d - 1) // 2
  print(math.min(p1, p2))
end


Measured memory_bytes: 760
#include <stdio.h>
 #include <string.h>
 char s[101];
 int main(void) {
 scanf("%s", s);
 int res = 0;
 int n = strlen(s);
 for (int i = 0; i < n; i++) {
 if (s[i] != s[n - 1 - i]) res++;
}
printf("%d\n", res / 2);
 }

Measured memory_bytes: 1728
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.ARC077
{
    class pushpush
    {
        public static void Main()
        {
            var n = int.Parse(ReadLine().Trim());
            var nums = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
            var even = nums.Where((v, i) => i % 2 == 1);
            var odd = nums.Where((v, i) => i % 2 == 0);
            Write(string.Join(" ", (n % 2 == 0) ? even.Reverse() : odd.Reverse()));
            if (n != 1) Write(' ');
            Write(string.Join(" ", (n % 2 == 0) ? odd : even));
        }
    }
}


Measured memory_bytes: 46904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    sort(A.rbegin(), A.rend());

    ll ans = 0;
    ans += A[0];
    priority_queue<int> que;
    que.push(min(A[0], A[1]));
    que.push(min(A[0], A[1]));
    for (int i = 2; i < N; ++i) {
        ans += que.top();
        que.pop();
        que.push(A[i]);
        que.push(A[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5064
#include <stdio.h>

int main(void)
{
    int num_people;
    int emit_sec;
    if (scanf("%d %d", &num_people, &emit_sec) != 2)
    {
        puts("num_people or emit_sec input error.");
        return 1;
    }
    
    long long total_emit_sec = 0;
    int start_sec = 0;
    for (int i = 0; i < num_people; i++)
    {
        int prev_sec = start_sec;
        if (scanf("%d", &start_sec) != 1)
        {
            puts("start_sec input error.");
            return 1;
        }
       
        total_emit_sec += ((start_sec - prev_sec) > emit_sec) ? emit_sec : (start_sec - prev_sec);
    }
    total_emit_sec += emit_sec;

    printf("%lld", total_emit_sec);

    return 0;
}


Measured memory_bytes: 128
int main(int argc, const char * argv[])
{
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 584
#include <iostream>

using namespace std;

int main(){
 int n;
  int len=0,sum=0;
  cin >> n;
  
  for(int i=0;i<n;i++){
    int l;
    cin >> l;
    sum+=l;
   len=max(len,l);
  }

  if(sum-len>len){
   cout << "Yes" << endl;
  }
  else{
   cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int arr[1000000];
int mem[1000000]={0};
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	} 
	mem[0]=0;
	mem[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		mem[i]=min(mem[i-1]+abs(arr[i]-arr[i-1]),mem[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<mem[n-1]<<endl;
}

Measured memory_bytes: 4736
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
ll b[100000];
int main()
{
    int n;
    scanf("%d",&n);
    ll a[100005],i;

    for(i=0; i<n; i++)
        scanf("%lld",&a[i]),b[i]=0;
    if(a[0]!=0)
            printf("0\n");
    else
    {
        ll ans=1;
        for(i=0;i<n;i++)
            b[a[i]]++;
        for(i=1;i<n;i++)
        {
            ans*=b[a[i]-1];
            ans%=998244353;
        }

        printf("%lld\n",ans);
    }
    return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

LL K, T;
LL ans = 0;

LL getMaxIndex(vector<LL> &v, int t){
	LL ret = -1;
	LL max = -1;
	for(int i=0; i<v.size(); i++){
		if(i == t) continue;
		if(max < v[i] && v[i] > 0){
			max = v[i];
			ret = i;
		}
	}
	return ret;
}

LL eatCake(vector<LL> &v, LL t, LL c){
	LL ret = getMaxIndex(v, t);
	if(ret == -1 && v[t] > 0){
		v[t]--;
		ans++;
		return t;
	}

	v[ret]--;
	return ret;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	vector<LL> A;
	cin >> K >> T;
	for(int i=0; i<T; i++){
		LL a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());

	A[A.size()-1]--;
	LL type = T - 1;
	for(int i=1; i<K; i++){
		type = eatCake(A, type, i);
		if(type < 0){
			break;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int A, B;
	char op;
	cin >> A >> op >> B;
	cout << (op == '+' ? A+B : A-B) << endl;
}


Measured memory_bytes: 256
n = int(input())

a = list(map(int,input().split()))

maxabs =(a[0])
maxidx = 0
for i in range(n):
    if abs(a[i]) >abs(maxabs):
        maxabs = a[i]
        maxidx = i 
res = []
for i in range(n):
    if a[i]*maxabs<0:
        a[i] += maxabs
        res.append((maxidx+1,i+1)) 
if maxabs>0:
    for i in range(1,n):
        res.append((i,i+1))
elif maxabs<0:
    for i in range(n,1,-1):
        res.append((i,i-1))

print(len(res))
for x,y in res:
    print(x,y)


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int n, A, B;

int main() {
	while (true) {
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i<n; i++) {
			int a, b;
			cin >> a >> b;
			if (a > b)A = A + a + b;
			else if (a < b)B = B + a + b;
			else A = A + a, B = B + b;
		}
		cout << A << " " << B << endl;
		A = 0, B = 0;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;


void solve(){
	int n ;
	cin >> n ;
	int cnt = 0 ;
	for(int i = 1 ; i <= n ; i++){
		if(i%3==0) ;
		else if(i%5 == 0) ;
		else cnt += i ;
	}
	cout << cnt << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 3616
n = int(input())

import math

def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f*f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

def make_divisors(n):
  divisors = []
  mod = 10**9 + 7
  s = (n**0.5)%mod
  for i in range(1, int(s)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

p = []
for i in range(1, n+1):
  p += prime_factorize(i)

import collections
pc = collections.Counter(p)

a = 1
for v, c in pc.items():
  a *= c+1

mod = 10**9 +7
print(a%mod)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
ll power(ll x,ll y,ll p){
ll res = 1;x = x % p;
while (y > 0){
if (y & 1){res = (res*x) % p;}
y = y>>1;
x = (x*x) % p;}
return res;}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}
ll t,n,m,k;
bool esprimo(ll n){
ll s=0;
for(ll i=1;i*i<=n;i++){
    if(n%i==0){s++;}}
if(s>=2){return false;}
return true;
}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

cin>>n;
ll a[n];
for(int i=0;i<n;i++){cin>>a[i];}
sort(a,a+n);
ll s=a[n-1];
for(int i=n-2;i>=n/2;i--){s+=2*a[i];}
if(n%2!=0)s-=a[n/2];
cout<<s;
}



Measured memory_bytes: 5204
# https://atcoder.jp/contests/abc158/tasks/abc158_c


A, B = gets.split.map(&:to_i)

r08 = 0.08
r10 = 0.10

min_x = (A / r08).ceil
max_x = ((A + 1) / r08).ceil
(min_x...max_x).each do |x|
  if (x * r10).truncate == B
    puts x
    exit
  end
end
puts '-1'


Measured memory_bytes: 3836
a, b = map(int, input().split())
sheet = [list(map(int, input().split())) for i in range(a)]
for row in sheet:
    print(' '.join(map(str, row + [sum(row)])))
lastrow = [sum([j[i] for j in sheet]) for i in range(b)]
print(' '.join(map(str, lastrow + [sum(lastrow)])))


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

int H, W;
char g[1000][1000];
ll dp[1000][1000];
const ll M = 1e9 + 7;

ll f (int r, int c)
{
	if (r >= H || c >= W || g[r][c] == '#') return 0;

	if (r == H-1 && c == W-1) return 1;

	if (dp[r][c] != -1) return dp[r][c];

	return dp[r][c] = (f(r+1, c) + f(r, c+1)) % M;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> H >> W;
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j)
			cin >> g[i][j];

	memset(dp, -1, sizeof(dp));
	cout << f(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 9088
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <set>

using namespace std;

int main() {
    vector<int> nums(3);
    scanf("%d", &nums[0]);
    scanf("%d", &nums[1]);
    scanf("%d", &nums[2]);
    
    int numOdd = (nums[0] % 2 == 1) + (nums[1] % 2 == 1) + (nums[2] % 2 == 1);
    int numOper = 0;
    if (numOdd == 1) {
        numOper += 1;
        for (int i = 0; i < 3; i++) {
            if (nums[i] % 2 == 0) {
                nums[i] += 1;
            }
        }
    } else if (numOdd == 2) {
        numOper += 1;
        for (int i = 0; i < 3; i++) {
            if (nums[i] % 2 == 1) {
                nums[i] += 1;
            }
        }
    }
    sort(nums.begin(), nums.end());
    numOper += (nums[2] - nums[0]) / 2;
    numOper += (nums[2] - nums[1]) / 2;
    printf("%d\n", numOper);
    return 0;
}

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

int main(){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    if(a==0){
        cout << 1;   
    }
    if(b==0){
        cout << 2;   
    }
    if(c==0){
        cout << 3;   
    }
    if(d==0){
        cout << 4;   
    }
    if(e==0){
        cout << 5;   
    }
}


Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }


#define debug(x) cout << #x << "==" << x << endl;

const int mod = 1e+9 + 7;

typedef long long ll;



int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

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

  ll sum = 0;
  ll ans1 = 0;
  for(int i = 0; i < N; i++) {
    sum += a[i];
    if( i % 2 == 0 ) { // 正
      if( sum < 0 ) {
        ans1 += abs(sum) + 1;
        sum = 1;
      } else if (sum == 0) {
        sum++;
        ans1++;
      }
    } else { //負
      if( sum > 0 ) {
        ans1 += abs(sum) + 1;
        sum = -1;
      } else if (sum == 0) {
        sum--;
        ans1++;
      }
    }
  }

  sum = 0;
  ll ans2 = 0;
  for(int i = 0; i < N; i++) {
    sum += a[i];
    if( i % 2 != 0 ) { // 正
      if( sum < 0 ) {
        ans2 += abs(sum) + 1;
        sum = 1;
      } else if (sum == 0) {
        sum++;
        ans2++;
      }
    } else { //負
      if( sum > 0 ) {
        ans2 += abs(sum) + 1;
        sum = -1;
      } else if (sum == 0) {
        sum--;
        ans2++;
      }
    }
  }


  cout << min(ans1, ans2) << "\n";

  return 0;
}
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

ll dp[111][101010],W[101010];
int V[101010];
ll INF=1e15;

int main(){
  int N,WW; cin>>N>>WW;
  rep(i,N) cin>>W[i]>>V[i];
  rep(i,111) rep(j,101010) dp[i][j]=INF;
  dp[0][0]=0;
  int ans=0;
  rep(i,N) rep(j,101010) if(dp[i][j]!=INF){
    dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
    if(W[i]+dp[i][j]<=WW){
      dp[i+1][V[i]+j]=min(dp[i+1][V[i]+j],dp[i][j]+W[i]);
      ans=max(ans,V[i]+j);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 87808
{-# OPTIONS_GHC -O2 #-}
import Control.Applicative
import Data.List
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BS
import Data.Maybe (fromJust)

show2 (x,y) = shows x " " ++ show y

f :: [Int] -> [String]
f (n:k:_)
    | node < 0  = ["-1"]
    | otherwise = (show (node + n - 1)) : map show2 (zip (replicate (n-1) 1) [2..n] ++ take node [ (x,y) | x <- [2..n], y <- [2..n], x < y])
    where
      node = (n-1) * (n-2) `div` 2 - k

main :: IO()
main = interact $ unlines . f . map read . words

Measured memory_bytes: 1020
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n = in();
    VL a(n), b(n);
    REP(i,n){
        a[i] = in();
        b[i] = in();
    }

    vector<PL> p;
    REP(i,n){
        p.push_back(PL(a[i], i));
        p.push_back(PL(b[i], i + n));
    }

    sort(ALL(p));
    int ca = 0, cb = 0;
    set<int> st;
    ll sum = 0;
    REP(i,n){
        sum += p[i].first;
        st.insert(p[i].second % n);
        if (p[i].second < n) ca++;
        else cb++;
    }

    if (st.size() < n || ca == 0 || cb == 0){
        cout << sum << endl;
        return 0;
    }

    ll ans = 1e18;
    FOR(j,n,n+1){
        PL x = p[j];
        REP(i,n){
            bool ok = false;
            if ((p[i].second % n) != (x.second % n)){
                ok = true;
            }else{
                if (x.second < n){
                    if (ca + 1 == n) ok = true;
                }else{
                    if (cb + 1 == n) ok = true;
                }
            }
            if (ok){
                ans = min(ans, sum + x.first - p[i].first);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  ll h;
  cin >> h;
  ll num=1,ans=0;
  while(h>=1){
    ans+=num;
    h/=2;
    num*=2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math


def div_with_mod(x, y, mod):
    # Fermat's little theorem
    return x*pow(y, mod - 2, mod)


def comb(n, r, mod):
    # calculates C(n,r) with mod (assuming mod is prime)
    nc = n
    for rc in range(1, r):
        nc -= 1
        n = n*nc % mod
        r = r*rc % mod

    return div_with_mod(n, r, mod)


def solve():
    N = int(input())
    # ord("a") Unicode コードポイントを返す
    codepoint = ord("a")

    def dfs(word, dep):
        if len(word) == N:
            return print(word)

        for i in range(dep):
            dfs(word + chr(codepoint+i), dep)

        dfs(word + chr(codepoint+dep), dep+1)

    dfs("a", 1)


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 62040
import java.util.*;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      //入力
      int N = sc.nextInt();//木の本数
      int D = sc.nextInt();
      
      //1人の監視員が監視できる範囲
      int one = D*2+1;
      
      //監視員が最低何人必要か求める
      int min = N/(D*2+1);
      if(N%one!=0){
        	System.out.println(min+1);
      }
      else{
        	System.out.println(min);
    }
    }
}

Measured memory_bytes: 20820
S = input()
Sr = S[::-1]
token = ['dream', 'dreamer', 'erase', 'eraser']
tokenr = list(map(lambda x:x[::-1], token))
t = ''
while(len(Sr)>0):
    notFound = True
    for w in tokenr:
        if w==Sr[:len(w)]:
            Sr = Sr[len(w):]
            t+=w
            notFound = False
    if notFound:
        break
if Sr == '':
    print('YES')
else:
    print('NO')

Measured memory_bytes: 137236
import sys
input=sys.stdin.readline

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N = int(input())
    # N! の約数の個数は N! の素因数がわかれば計算できる
    # ⇒ 1 ~ N の素因数を計算して、辞書を使って数えていく
    d = dict()
    for n in range(1, N+1):
        for p in prime_factorize(n):
            if p in d:
                d[p] += 1
            else:
                d[p] = 1
    ans = 1
    for i in d.values():
        ans *= (i+1)
        ans %= (10**9+7)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i+=2) {
		int cnt = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j==0) cnt++;
		}
      	if (cnt == 8) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
texts=sys.stdin.read()
texts=texts.lower()
cnt=[0]*26

letters=list('abcdefghijklmnopqrstuvwxyz')
for x in texts:
    i=0
    for y in letters:
        if x==y:
            cnt[i]+=1
        i+=1
for i in range(26):
    print(letters[i]+' : '+str(cnt[i]) )



Measured memory_bytes: 5564
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, a, b) for(int i = a; i < b; i++)

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    while (b != 0) {
        a = a % b;
        swap(a, b);
    }

    return a;
}

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

// x \in [a,b]において x % div == 0を満たすものの数
ll calc_div_num(ll a, ll b, ll div) {
    if (a > b) {
        swap(a, b);
    }

    return b / div - (a - 1) / div;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll cd_lcm = lcm(c, d);

    ll div_num = calc_div_num(a, b, c) + calc_div_num(a, b, d) - calc_div_num(a, b, cd_lcm);

    cout << (b - a + 1 - div_num) << endl;

    return 0;
}

Measured memory_bytes: 256