akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string s;
  cin >> s;
  ll n = s.size();

  ll ans = 1;
  string t = s.substr(0, 1), reset;
  for (ll i = 1; i < n; i++) {
    string u = s.substr(i, 1);
    if (u == t && i + 1 < n) {
      u.push_back(s[i + 1]);
      i++;
    }
    if (u == t) break;
    t = u;
    u = reset;
    ans++;
  }
  cout << ans << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int H[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>H[i];
		if(i==0) {
			H[i]--;
		}
		else {
			if(H[i]!=H[i-1]) H[i]--;
			if(H[i]<H[i-1]) return _P("No\n");
		}
	}
	cout<<"Yes"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();
   
    int a = n/x;
        
    if(n%x==0){
    	System.out.println(a*t);
    }else{
    	System.out.println((a+1)*t);
    }
}
}

Measured memory_bytes: 35536
#!python3

from collections import defaultdict

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    A = list(iim())

    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, ai in enumerate(A):
        d1[i+ai] += 1
        d2[i-ai] += 1

    ans = 0
    for k, v in d1.items():
        if k in d2:
            ans += v * d2[k]

    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 57644
s = input()
pat_list = ["dream","dreamer","erase","eraser"]

while 1:
    flag=0
    for p in pat_list:
        if s.endswith(p):
            flag=1
            s = s[:-len(p)]
    if not s:
        print("YES")
        break
    if not flag:
        print("NO")
        break


Measured memory_bytes: 9084
import java.util.Scanner;

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

        int i ,j;

        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();

            if(H == 0  && W == 0)break;

            for(i = 0;i < H;i++){
                for(j = 0;j < W;j++){
                    if(i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }
                }

                System.out.printf("\n");

            }

            System.out.printf("\n");

        }
    }
}


Measured memory_bytes: 63584
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define NMAX    50000
#define MMAX    20
#define MAX     1000000000

int *c;
int memo[MMAX][NMAX + 1];

int min2(int x, int y) {

    return x < y ? x : y;
}

// 0???m?¨????????????????????????£???n??????????????¨??????????????????????°?????????°???
int dp(int m, int n) {
    int rep;

    if( m < 0 ) return MAX;
    if( memo[m][n] < MAX ) return memo[m][n];

    if( n == 0 ) {
        rep = 0;
    } else if( n < c[m] ) {
        rep = dp(m - 1, n);
    } else {
        rep = min2(dp(m - 1, n), dp(m, n - c[m]) + 1);
    }
    
    return memo[m][n] = rep;
}

void insertsort(int *a, int n) {
    int i, j;

    for( i = 1; i < n; i++ ) {
        int tmp = a[i];
        for( j = i; j > 0 && a[j - 1] > tmp; j-- ) {
            a[j] = a[j - 1];
        }
        a[j] = tmp;
    }

    return;
}

int main(void) {
    int n, m;
    int i, j;

    scanf("%d %d", &n, &m);
    c = (int *)malloc(sizeof(int) * m);
    for( i = 0; i < m; i++ ) {
        scanf("%d", c + i);
        for( j = 0; j <= NMAX; j++ ) {
            memo[i][j] = MAX;
        }
    }
    //insertsort(c, m);

    printf("%d\n", dp(m - 1, n));

    free(c);

    return 0;
}

Measured memory_bytes: 4616
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	S, T := sc.nextStr(), sc.nextStr()
	set := make(map[byte][]int)
	for i := 0; i < len(S); i++ {
		set[S[i]] = append(set[S[i]], i)
	}
	ans := 0
	now := -1
	for i := 0; i < len(T); i++ {
		t := T[i]
		if len(set[t]) == 0 {
			fmt.Fprintln(wtr, -1)
			return
		}
		a := set[t]
		l := -1
		r := len(a)
		for abs(r-l) > 1 {
			mid := (r + l) / 2
			if a[mid] > now {
				r = mid
			} else {
				l = mid
			}
		}
		if r != len(a) {
			//fmt.Fprintln(wtr, now, i, a[r])
			if now != -1 {
				ans += a[r] - now
			} else {
				ans += a[r] + 1
			}
			now = a[r]
		} else {
			//fmt.Fprintln(wtr, now, i, r)
			first := set[t][0]
			ans += len(S) - 1 - now + first + 1
			now = first
		}
	}

	fmt.Fprintln(wtr, ans)
}


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

void Factorize(int n,vector<int> &result){
	int amari;
	int i=2;
	int N=n;
	while(i<=sqrt(N)){
		amari=n%i;
		if(amari){
			i++;
		}else{
			n=n/i;
			result.push_back(i);
		}
	}
	if(n!=1){
		result.push_back(n);
	}
	return;
}

int main(){
	int n;
	cin >> n ;
	vector<int> result;
	Factorize(n,result);
	
	cout << n <<":";
	for (int i=0;i<result.size();i++){
		cout << " " << result[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1220
#include<cstdio>
using namespace std;
int d2b(int n,int b,char c[])
{
    int i=0,k;                                                                                                                                                   
    while(n!=0)
    {
        k=n%b;
        n/=b;
        if(k<0){k-=b;n+=1;}//这里是负进制的重点
        if(k>9)c[i]=char(k-10+'A');
        else c[i]=char(k+'0');
        i++;
    }
    return i-1;
}
int main()
{
    int a,n,i;
    char b[400];
    scanf("%d",&a);n=-2;
    if(a==0)printf("0");
    for(i=d2b(a,n,b);i>=0;i--)printf("%c",b[i]);
}


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

using namespace std;

const int maxn = 1e5 + 10;
long long int a[maxn], b[maxn];

int main()
{
    long long int n,jav = 0;
    cin >> n;

    for(int i = 0; i < n; i ++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = n - 1; i >= 0; i --)
    {
        a[i] += jav;
        if (a[i] % b[i] != 0)
        {
            jav += a[i] / b[i] * b[i] + b[i] - a[i];
        }
    }
    cout << jav;
    return 0;
}


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

using namespace std;
using ll = long long;

int n;
vector<ll> a;
vector<vector<ll>> dp;

int main(){
    cin>>n;
    a.resize(n);
    dp.resize(n, vector<ll>(n, 0));
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    for(int j = 0; j < n; j++){
        for(int i = j; i >= 0; i--){
            if(i == j){
                dp[i][i] = a[i];
            }else{
                dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]);
            }
        }
    }
    ll res = dp[0][n-1];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N, M;
    cin >> N >> M;
    vector<ll> Pref(M), Year(M);
    vector<vector<int>> pref_year(N+1);  // 県ごとの誕生年を管理する
    REP(i, M) {
        cin >> Pref[i] >> Year[i];
        pref_year[Pref[i]].push_back(Year[i]);
    }
    
    // calculation
    // 各県の誕生年をソート
    unordered_map<ll, ll> year_rank;
    REPN(i, N) {
        sort(pref_year[i].begin(), pref_year[i].end());
        for (ll j = 0; j < pref_year[i].size(); ++j) {
            year_rank[pref_year[i][j]] = j + 1;
        }
    }
    
    REP(i, M) {
        cout << zero_pad(6) << Pref[i] << zero_pad(6) << year_rank[Year[i]] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 12708
import java.util.Scanner;

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

        int n= sc.nextInt();
        int intarr[]=new int[n];
        for(i=0;i<n;i++){
            intarr[i]=sc.nextInt(); 
        }
        int pivot=n;
        int times=0;
        int swap;

        while(pivot>0){
            for(i=0;i<pivot-1;i++){
                if(intarr[i]>intarr[i+1]){
                    swap=intarr[i];
                    intarr[i]=intarr[i+1];
                    intarr[i+1]=swap;
                    times++;
                }                
            }
            pivot--;
        }

        for(i=0;i<n;i++){
            if(i==n-1){
                System.out.printf("%d",intarr[i]);
            }else{
                System.out.printf("%d ",intarr[i]);
            }
            
        }
        System.out.printf("%n");
        System.out.println(times);
    }    
}


Measured memory_bytes: 26464
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int len = Integer.parseInt(scanner.nextLine());
        String inputs[] = scanner.nextLine().split(" ", -1);

        int numbers[] = new int[len];
        for (int i = 0; i < len; i++) {
            numbers[i] = Integer.parseInt(inputs[i]);
        }

        new Main().selectionSort(numbers, len);
    }

    private void selectionSort(int numbers[], int len) {
        int times = 0;
        boolean sorted = true;

        for (int i = 0; i < len; i++) {
            int minJ = i;
            for (int j = i; j < len; j++) {
                if (numbers[j] < numbers[minJ]) {
                    minJ = j;
                }
            }

            if (i != minJ) {
                int temp = numbers[i];
                numbers[i] = numbers[minJ];
                numbers[minJ] = temp;
                times++;
            }
        }

        for (int i = 0; i < len; i++) {
            System.out.print(numbers[i]);
            if (i == len - 1) {
                System.out.print("\n");
            } else {
                System.out.print(" ");
            }
        }
        System.out.println(times);
    }
}



Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

  int need_left = 0, need_right = 0;
  int pointer = 0;
  REP(i,n) {
    if (s[i] == '(') {
      pointer++;
    } else {
      if (pointer == 0) need_left++;
      else --pointer;
    }
  }
  need_right = pointer;

  string left, right;
  REP(i,need_left) left.push_back('(');
  REP(i,need_right) right.push_back(')');
  COUT(left + s + right);
  return 0;
}


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

left = int(s/100)
right = int(s%100)


if left > 12 or left <= 0:
    if right > 12 or right <= 0:
        print('NA')
    else:
        print('YYMM')
else:
    if right > 12 or right <= 0:
        print('MMYY')
    else:
        print('AMBIGUOUS')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n,m;
    cin>>n;
    cin>>m;
    vpllll payday(n);
    rep(i,0,n){
        ll a,b;
        cin>>a>>b;
        payday[i].first=b;
        payday[i].second=a;
    }
    sort(payday.rbegin(),payday.rend());
    set<int> s;
    rep(i,1,m+1){
        s.insert(i);
    }
    ll ans=0;
    rep(i,0,n){
       auto p=s.lower_bound(payday[i].second);
       if(p!=s.end()){
           ans+=payday[i].first;
           s.erase(p);
       }
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 6528
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
 
        int[][] list = new int[a][b];
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
        int[] list2 = new int[b];
        for (int i = 0; i < b; i++) {
            list2[i] = scanner.nextInt();
        }
        int sum;
        for (int i = 0; i < a; i++) {
            sum = 0;
            for (int j = 0; j < b; j++) {
                sum += list[i][j] * list2[j];
            }
            System.out.println(sum);
        }
 
    }
}


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

using namespace std;

int n,l;
int arr[201];
int psum[201];
int sum = 0;
int res;
int dif = 1e9;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> l;
	for (int i=1;i<=n;i++)
	{
		arr[i] = l + i - 1;
		sum += arr[i];
		psum[i] = psum[i-1] + arr[i];
	}	
	for (int i=1;i<=n;i++)
	{
		int cur = psum[i-1] + (psum[n] - psum[i]);
		if (abs(sum - cur)  < dif)
		{
			dif = abs(sum - cur);
			res = cur;
		}
	}			
	cout << res;
}

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

typedef long long ll;
ll MOD = 1000000007;

int main(){
  string S;cin >> S;
  int N,So,W,E;
  N = count(S.begin(),S.end(),'N');
  So = count(S.begin(),S.end(),'S');
  W = count(S.begin(),S.end(),'W');
  E = count(S.begin(),S.end(),'E');
  if((N > 0 && So > 0) || (N == 0 && So == 0)){
    if((E > 0 && W > 0) || (E == 0 && W == 0)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
const int M = 105;
const int mod = 1e9 + 7;
int n, num[N], d;
string snum;

int add(int x, int y) {
	if (x + y >= mod) {
		return x + y - mod;
	}
	return x + y;
}

/* TOP DOWN 
int mem[N][M][2];
bool vis[N][M][2];

int dp(int i, int m, bool border) {
	if (i == n) {
		return m ? 0 : 1;
	}
	if (vis[i][m][border]) {
		return mem[i][m][border];
	}
	vis[i][m][border] = true;

	int lv = border ? num[i] : 9;

	int ans = 0;
	for (int j = 0; j <= lv; j++) {
		bool nb = border && j == lv;
		ans = add(ans, dp(i + 1, (m + j) % d, nb));
	}

	return mem[i][m][border] = ans;
}
*/

int dp[M][2], dp1[M][2];

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

	cin >> snum >> d;
	n = snum.size();

	for (int i = 0; i < n; i++) {
		num[i] = snum[i] - '0';
	}

	dp1[0][1] = 1;
	dp1[0][0] = 1;
	for (int i = n - 1; i >= 0; i--) {
		for (int m = 0; m < d; m++) {
			for (int border = 0; border < 2; border++) {
				int lv = border ? num[i] : 9;

				for (int j = 0; j <= lv; j++) {
					int nb = border && (j == lv);
					dp[m][border] = add(dp[m][border], dp1[(m + j) % d][nb]);
				}
			}
		}

		for (int m = 0; m < d; m++) {
			for (int b = 0; b < 2; b++) {
				dp1[m][b] = dp[m][b];
				dp[m][b] = 0;
			}
		}
	}

	cout << (mod + dp1[0][1] - 1) % mod << '\n';

	return 0;
}


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


int main(){
  string s;
  cin >> s;
  ll cnt = 0;
  ll res = 0;
  for(int i = 0; i + 1< s.length(); i++) {
    if(s[i] == 'B' && s[i+1] == 'C') {
      res += cnt;
      i++;
    }else if(s[i] == 'A'){
      cnt++;
    }else{
      cnt = 0;
    }  
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    ll n;
    cin >> n;
    vint sq(n + 1);
    rep(i, n + 1) sq[i] = i;

    for (ll i = 1; i <= n; i++)
    {
        int cur = 0;
        int m = ceil(sqrt(i));
        for (int x = 1; x <= m; x++)
        {
            for (int y = 1; y <= m; y++)
            {
                int now = x * x + y * y + x * y;
                now = i - now;
                int z = lower_bound(sq.begin(), sq.end(), now, [&](int a, int b) { return (a * a + a * x + a * y < b); }) - sq.begin();

                if (now && z * z + z * x + z * y == now)
                {
                    cur++;
                }
            }
        }
        cout << cur << endl;
    }

    return 0;
}

Measured memory_bytes: 3532
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int H,W;

ll a(int h,int w)
{
	if(h<3)return 1e11;
	ll res2=1e11;
	ll hh=h/3;
	ll res1=abs((hh*w)-max(((h-hh*2)*w),(h-hh*2-1)*w));
	hh++;
	if(hh*2<h)res2=abs((hh*w)-(h-hh*2)*w);
	return min(res1,res2);
}


ll b(int h,int w)
{
	ll res=1e11;
	for(ll i=max(h/2-1,1);i<=min(w,h/2+2);i++)
		for(ll j=1;j<=w;j++)
		{
			ll mi=min(i*j,min(h*(w-j),(h-i)*j));
			ll mx=max(i*j,max(h*(w-j),(h-i)*j));
			res=min(res,mx-mi);
		}
	return res;
}

int main()
{
	cin>>H>>W;
	cout<<min(a(H,W),min(a(W,H),min(b(H,W),b(W,H))))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int a,b;
  cin>>a>>b;

  int k=b-a;
  int m=k*(k+1)/2;
  int ans=m-b;

  cout<<ans<<"\n";
  return 0;
}


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

#define ll long long int
#define vl vector<ll>
#define vvl vector<vl>
#define INF 1e12

int main() {

    ll N, M, L;
    cin >> N >> M >> L;

    vvl len(310, vl(310, INF));
    ll A, B, C;
    for (ll i = 0; i < M; i++) {
        cin >> A >> B >> C;
        len[A][B] = C;
        len[B][A] = C;
    }

    ll Q;
    cin >> Q;
    vl s, t;
    ll ts, tt;
    for (ll i = 0; i < Q; i++) {
        cin >> ts >> tt;
        s.push_back(ts);
        t.push_back(tt);
    }

    for (ll i = 0; i < 310; i++) {
        len[i][i] = 0;
    }


    for (ll i = 1; i <= N; i++) {
        for (ll j = 1; j <= N; j++) {
            for (ll k = 1; k <= N; k++) {
                len[j][k] = min(len[j][k], len[j][i] + len[i][k]);
            }
        }
    }

    vvl cost(310, vl(310, INF));
    for (ll i = 1; i <= N; i++) {
        for (ll j = 1; j <= N; j++) {
            if (len[i][j] <= L) {
                cost[i][j] = 1;
            }
        }
    }

    for (ll i = 0; i < 310; i++) {
        cost[i][i] = 0;
    }

    for (ll i = 1; i <= N; i++) {
        for (ll j = 1; j <= N; j++) {
            for (ll k = 1; k <= N; k++) {
                cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
            }
        }
    }

    for (ll i = 0; i < Q; i++) {
        if (cost[s[i]][t[i]] < INF) {
            cout << cost[s[i]][t[i]] - 1 << endl;
        }
        else {
            cout << -1 << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3484
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long int a,b,c,d,s=0,l=0,m=0,z=0;
  cin>>a>>b>>c>>d;
  s=a*c;
  l=a*d;
  m=b*c;
  z=b*d;
  long long int  x[4];
  x[0]=s;
  x[1]=l;
  x[2]=m;
  x[3]=z;
  sort(x,x+4);
  cout<<x[3]<<endl;
  
  return 0;
}
  
    

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 505;

char col[] = "RGBY";

int main(void) {
  int H, W, D;
  scanf("%d %d %d", &H, &W, &D);
  REP(i, H) {
    REP(j, W) {
      int a = (i + j) % (2 * D);
      int b = (i - j) % (2 * D);
      if (b < 0) b += 2 * D;

      int r = (a < D) * 2 + (b < D);
      putchar(col[r]);
    }
    putchar('\n');
  }
  
  return 0;
}


Measured memory_bytes: 512
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n,p=map(int,input().split())

dp0=[1]*(n+1)
dp1=[0]*(n+1)

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

for i in range(n):
    if a[i]%2==0:
        dp0[i+1]=dp0[i]+dp0[i]
        dp1[i+1]=dp1[i]+dp1[i]
    else:
        dp0[i+1]=dp0[i]+dp1[i]
        dp1[i+1]=dp1[i]+dp0[i]

if p==0:
    print(dp0[n])
else:
    print(dp1[n])

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

int main(){	
		
int a;

cin >> a;

 if(a>9){
	
	if(a%10==2||a%10==4||a%10==5||a%10==7||a%10==9){
		cout << "hon" << endl;
	}else if(a%10==0||a%10==1||a%10==6||a%10==8){
		cout << "pon" << endl;
	}else if(a%10==3){
		cout << "bon" << endl;
	}
}

else if(a>99&&a<1000){
	
	if(a%100==2||a%100==4||a%100==5||a%100==7||a%100==9){
		cout << "hon" << endl;
	}else if(a%100==0||a%100==1||a%100==6||a%100==8){
		cout << "pon" << endl;
	}else if(a%100==3){
		cout << "bon" << endl;
	}
}

else if(a<10){
	
	if(a==2||a==4||a==5||a==7||a==9){
		cout << "hon" << endl;
	}else if(a==0||a==1||a==6||a==8){
		cout << "pon" << endl;
	}else if(a%10==3){
		cout << "bon" << endl;
	}
}
			
return 0;	
}


Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0)
typedef long long ll;


ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

//#######################################




int main(){
  boost;
 double d,t,s;
 cin>>d>>t>>s;
 
 if(d/s<=t and (s!=0)){
   cout<<"Yes";
 }
 else{
   cout<<"No";
 }
}



Measured memory_bytes: 3748
#!/usr/bin/perl
use POSIX qw(floor);

my ($x) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $y = 100;

my $i = 0;

while(1){
  if( $y >= $x ){
    print "$i\n";
    exit(0);
  }
  $y = floor($y * 1.01);
  $i ++;
}



Measured memory_bytes: 6648
n = int(input())
f = [int(input().replace(" ",""),2) for i in range(n)] #数にしてしまう
p = [list(map(int,input().split())) for i in range(n)]
ans = -10**12
for i in range(1,1024):
    #print("i=",i)
    temp = 0
    for j in range(n): #j = 0,1,2,..,n-1で店番号
        fi = f[j]
        ci = bin(fi&i).count("1") #bin()は2進法表記のstrになる。
        #print("ci=",ci)
        temp += p[j][ci]
    #print(temp)
    #print(temp)
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  ll c = 0;
  REP(i, N) if ((i + 1) % 2 == 1 && A[i] % 2 == 1) c++;
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;


int main() {
  int N,S,n=0;
  cin >> N;
  S = N;

  while(N>0){
    n += N%10;
    N /=10;
  }
  if(S%n == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <climits>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

class SegmentTree
{
  private:
    int N = 1;
    vector<int> node;

  public:
    SegmentTree(vector<int> vec)
    {
        int size = vec.size();

        while (N < size)
            N *= 2;

        node.resize(2 * N - 1, INT_MAX);

        rep(i, size) node[i + N - 1] = vec[i];
        for(int i = N - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int i, int value)
    {
        i += N - 1;
        node[i] = value;
        while(i > 0)
        {
            i = (i - 1) / 2;
            node[i] = min(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    int getmin(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if(r < 0) r = N;

        if(r <= a || b <= l) return INT_MAX;

        if(a <= l && r <= b) return node[k];

        int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);

        return min(vl, vr);
    }
};

int main()
{
    int N, Q;
    cin >> N >> Q;
    SegmentTree seg(vector<int>(N, INT_MAX));
    rep(i, Q)
    {
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0)
            seg.update(x, y);
        else 
            cout << seg.getmin(x, y + 1) << endl;;
    }
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007; 

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

int main(){
  ll n, k;
  cin >> n >> k;
  vll a(n);
  vin(a);
  sort(all(a), greater<ll>());
  ll sum = 0;
  rep(i, k, n) sum+= a.at(i);
  cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() 
{
  int n,ans = 0,d[110],num[110] = {0};
  cin >> n;
  for(int i = 0; i < n; i++) cin >> d[i];

  for(int i = 0; i < n; i++)
    num[d[i]]++;

  for(int i = 1; i<= 100; i++)
    if(num[i] != 0) ans++;

  cout << ans << endl;
}

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

int n, g;
int turn;

void solve(){
	stack<int> st;
	st.push(0);
	cin >> g;
	turn = g;
	for(int i = 1; i < n; i++){
		cin >> g;
		if(i%2 == 0){
			if(turn != g){
				st.push(i);
				turn = g;
			}
		} else{
			if(turn != g){
				if(st.size() != 1) st.pop();
				turn = g;
			}
		}
	}
	int ans = 0;
	int s, e = n;
	int si = st.size();
	for(int i = 0; i < si; i++){
		s = st.top();
		st.pop();
		if(turn == 0) ans += e-s;
		turn = (turn+1)%2;
		e = s;
	}
	cout << ans << endl;
}

int main(){
	while(cin >> n,n) solve();
}

Measured memory_bytes: 1200
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int n,r;
        n=scan.nextInt();
        r=scan.nextInt();
        if(n<10){
            System.out.println(r+(100*(10-n)));
        }
        else {
            System.out.println(r);
        }
        
    }
}

Measured memory_bytes: 21716
n = int(input())
s = input()
s = list(s)
string = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

for i in range(len(s)):
    if string.index(s[i]) + n <= 25:
        s[i] = string[string.index(s[i]) + n]
    else:
        s[i] = string[string.index(s[i]) + n-26]

print(*s, sep='')


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

constexpr int nax = 1e5, inf = 1e9;

int n, k, res, tab[nax + 1], deg[nax + 1], dis[nax + 1];
vector< int > gr[nax + 1];

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

    cin >> n >> k;

    for (int i = 1; i <= n; ++i)
    {
        int v; cin >> v;
        tab[i] = v;
        if (i == 1 and v != 1) tab[i] = 1, ++res;
        else gr[v].push_back(i);
    }

    for (int i = 1; i <= n; ++i)
        deg[i] = gr[i].size();

    queue< int > Q;

    for (int i = 1; i <= n; ++i)
        if (not deg[i])
            Q.push(i);

    while (not Q.empty())
    {
        int v = Q.front(); Q.pop();
        for (int s : gr[v])
            dis[v] = max(dis[v], dis[s] + 1);
        if (dis[v] == k - 1 and v != 1 and tab[v] != 1)
            ++res, dis[v] = -inf;
        if (not --deg[tab[v]])
            Q.push(tab[v]);
    }

    cout << res << '\n';
}


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

int main() {
    int N;
    int S[100];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> S[i];

    int res = 0;
    sort(S, S + N);
    for (int i = 0; i < N; ++i){
        if (S[i]==S[i+1]) res += 1;
    }
    cout << N-res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int n;
void make_map(map<int,int>& col, map<int,int>& row, map<int,bool>& dia, map<int,bool>& rdia) {
	int temp;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> temp;
			col[temp] = j + 1;
			row[temp] = i + 1;
			if (i == j) {
				dia[temp] = true;
			}
			if (i+j == n-1) {
				rdia[temp] = true;
			}
		}
	}
}

int main(void) {
	int u,v,m;
	cin >> n >> u >> v >> m;
	map<int,int> rcol,ccol;
	map<int,int> rrow,crow;
	map<int,bool> rdia,cdia;
	map<int,bool> rrdia,crdia;
	int temp;
	if (n > 1) {
		make_map(rcol,rrow,rdia,rrdia);
		make_map(ccol,crow,cdia,crdia);
		/*
			 for (int i = 0; i < n; ++i) {
			 for (int j = 0; j < n; ++j) {
			 cin >> temp;
			 rcol[temp] = j + 1;
			 rrow[temp] = i + 1;
			 if (i == j) {
			 rdia[temp] = true;
			 }
			 if (i+j == n-1) {
			 rrdia[temp] = true;
			 }
			 }
			 }
			 for (int i = 0; i < n; ++i) {
			 for (int j = 0; j < n; ++j) {
			 cin >> temp;
			 ccol[temp] = j + 1;
			 crow[temp] = i + 1;
			 if (i == j) {
			 cdia[temp] = true;
			 }
			 if (i+j == n-1) {
			 crdia[temp] = true;
			 }
			 }
			 }
			 */
	}
	else {
		cin >> temp;
		rdia[temp] = true;
		cin >> temp;
		cdia[temp] = true;
	}

	int card,rc,cc;
	vector<int> rc_col(n,0),cc_col(n,0);
	vector<int> rc_row(n,0),cc_row(n,0);
	vector<int> rc_dia(2,0),cc_dia(2,0);
	rc = cc = 0;
	bool fin = false;
	for (int i = 0; i < m; ++i) {
		cin >> card;
		if (!fin) {
			if (rcol[card] > 0) {
				++rc_col[rcol[card]-1];
				if (rc_col[rcol[card]-1] == n) {
					++rc;
				}
			}
			if (rrow[card] > 0) {
				++rc_row[rrow[card]-1];
				if (rc_row[rrow[card]-1] == n) {
					++rc;
				}
			}
			if (rdia[card]) {
				++rc_dia[0];
				if (rc_dia[0] == n) {
					++rc;
				}
			}
			if (rrdia[card]) {
				++rc_dia[1];
				if (rc_dia[1] == n) {
					++rc;
				}
			}
			if (ccol[card] > 0) {
				++cc_col[ccol[card]-1];
				if (cc_col[ccol[card]-1] == n) {
					++cc;
				}
			}
			if (crow[card] > 0) {
				++cc_row[crow[card]-1];
				if (cc_row[crow[card]-1] == n) {
					++cc;
				}
			}
			if (cdia[card]) {
				++cc_dia[0];
				if (cc_dia[0] == n) {
					++cc;
				}
			}
			if (crdia[card]) {
				++cc_dia[1];
				if (cc_dia[1] == n) {
					++cc;
				}
			}

			if (rc >= u && cc >= v) {
				cout << "DRAW" << endl;
				fin = true;
			}
			else if (rc >= u) {
				cout << "USAGI" << endl;
				fin = true;
			}
			else if (cc >= v) {
				cout << "NEKO" << endl;
				fin = true;
			}
		}
	}
	if (!fin) {
		cout << "DRAW" << endl;
	}
	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  if (a > b) swap(a, b);
  cout << max(0, b - (a + w)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,a[200001];


int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    int min = a[0];
    int count = 0;
    for (int i=0;i<N;i++){
        if (a[i] <= min){
            min = a[i];
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int x) {
  if (x < 2) return false;
  if (x <= 3) return true;
  if ((x % 2) == 0 || (x % 3) == 0) return false;
  for (int k = 5; k * k <= x; k += 6) {
    if ((x % k) == 0 || (x % (k + 2)) == 0) return false;
  }
  return true;
}

int v[100000 + 10];
int d[100000 + 10];
int sum[100000 + 10];
void gen(int n) {
  fill(v, v + n + 1, 1);
  v[0] = v[1] = 0;
  for (int i = 2; i * i <= n; i++) {
    if (!v[i]) continue;
    for(int k = i + i; k <= n; k += i) {
      v[k] = 0;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  gen(100000);
  for (int i = 1; i <= 100000; i += 2) {
    if (v[i] && v[(i + 1) / 2]) d[i] = 1;
  }

  for (int i = 1; i <= 100000; ++i) {
    sum[i] = sum[i - 1] + d[i];
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int l, r;
    cin >> l >> r;
    cout << sum[r] - sum[l - 1] << '\n';
  }
}

Measured memory_bytes: 1792
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	string s = read;
	
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) "Bad".writeln;
	else "Good".writeln;
	
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
int main()
{
	int n;
	scanf("%d", &n);
	int a[100005];
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	std::sort(a, a + n);
	if (n % 2 == 0) {
		int m = n / 2;
		long long ans = 0;
		for (int i = 0; i < m; i++) {
			ans -= a[i] * 2;
		}
		for (int i = m; i < n; i++) {
			ans += a[i] * 2;
		}
		ans += a[m - 1];
		ans -= a[m];
		printf("%lld\n",ans);
	}
	if (n % 2) {
		int m = n / 2;
		long long ans = 0;
		for (int i = 0; i <= m; i++) {
			ans -= a[i] * 2;
		}
		for (int i = m + 1; i < n; i++) {
			ans += a[i] * 2;
		}
		if (a[m - 1] + a[m] > 3 * a[m] - a[m + 1]) {
			ans += a[m - 1] + a[m];
			printf("%lld\n", ans);
		}
		else {
			ans += a[m] * 3 - a[m + 1];
			printf("%lld\n", ans);
		}
	}
}

Measured memory_bytes: 512
n,x,m=map(int,input().split())
l=[x]
c=1
d=-1
f=0
while(x>0 and c<n):
    g=(x*x)%m
    d=g
    if(g in l):
        f=1
        break
    l.append(g)
    x=g
    c+=1
s=sum(l)
if(f==1):
    r=l.index(g)
    o=(n-c)//(c-r)
    t=(n-c)%(c-r)
    s+=o*(sum(l[r:]))+sum(l[r:r+t])
print(s)


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



int main() {
    int n;
    cin >> n;
    
    vector<int> a(n+1), b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    
    ll cnt = 0;
    rep(i,n) {
        if(a[i] >= b[i]) {
            a[i] -= b[i];
            cnt += b[i];
        }
        else {
            b[i] -= a[i];
            cnt += a[i];
            a[i] = 0;
            if(a[i+1] >= b[i]) {
                a[i+1] -= b[i];
                cnt += b[i];
            }
            else {
                cnt += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    
    cout << cnt << endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 3920
use proconio::input;

#[allow(unused_imports)]
use std::collections::HashSet;

use std::cmp;


fn main() {
    input! {
        n: usize,
        k: usize,
    }
    solve(n, k);
}

fn prepare(m: usize, k: usize, p :u64) -> Vec<Vec<u64>> {
    let mut v : Vec<Vec<u64>> = Vec::<Vec<u64>>::with_capacity(m + 1);
    let v0 : Vec<u64> = vec![1; 1];
    v.push(v0);
    for i in 1..m+1 {
        let mut vi : Vec<u64>;
        if i <= k {
            vi = vec![0; i+1];
            for j in 0..i/2+1 {
                vi[j] = 
                if j == 0 || j==i {
                    1
                } else {
                    (v[i-1][j-1] + v[i-1][j]) % p
                };
                vi[i-j] = vi[j];
            }
            v.push(vi);
        }
        else if i < 2 * k {
            let jmax = cmp::min(i, k);
            vi = vec![0; jmax+1];
            for j in 0..i/2+1 {
                vi[j] = 
                if j == 0 || j==i {
                    1
                } else {
                    (v[i-1][j-1] + v[i-1][j]) % p
                };
                if i-j <= jmax {
                    vi[i-j] = vi[j];
                }
            }
            v.push(vi);
        } else {
            vi = vec![0; k+1];
            for j in 0..k+1 {
                vi[j] = 
                if j == 0 || j==i {
                    1
                } else {
                    (v[i-1][j-1] + v[i-1][j]) % p
                };
            }
            v.push(vi);
        }
    }
    return v;
}

fn solve(n: usize, k: usize) {
    let p : u64 = (10u32.pow(9u32) + 7) as u64;

    // 1. Calculate values of combinations
    let m = cmp::max(k-1, n-k+1);
    let c = prepare(m, k, p);

    // 2. Calculate possible ways
    for i in 1..k+1 {
        let b = c[k-1][i-1];
        let r = if i > n-k+1 { 
            0
        } else {
            c[n-k+1][i]
        };
        let t = b * r % p;
        println!("{}", t);
    }
}


Measured memory_bytes: 17748
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const D EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> PII;

/** Problem1020 : Cleaning Robot **/
struct  P {
	int x, y;
	P() {}
	P(int x_, int y_) : x(x_), y(y_) {}
};

int main()
{
	double dp[16][3][3];
	P s, b, t;
	int N;
	char S, T, B;
	while (cin>>N, N) {
		cin>>S>>T>>B;
		memset(dp, 0, sizeof(dp));
		
		s.x = (S-'A')%3;
		s.y = (S-'A')/3;
		b.x = (B-'A')%3;
		b.y = (B-'A')/3;
		t.x = (T-'A')%3;
		t.y = (T-'A')/3;
		
		dp[0][t.x][t.y]=1;
		
		REP(i, 1, N+1) {
			rep(y, 3) {
				rep(x, 3) {
					rep(j, 4) {
						int ox = x+dx[j], oy=y+dy[j];
						if_range(ox, oy, 3, 3) {
							if (b.x==ox && b.y == oy) {
								ox = x; oy=y;
							}
							
						} else {
							ox = x; oy = y;
						}
						dp[i][x][y] += dp[i-1][ox][oy]*0.25;
					}
				}
			}
		}
		printf("%.8f\n", dp[N][s.x][s.y]);
	}
}

Measured memory_bytes: 1188