akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,n,m;
	long long a,b,sa,sb,x;
	scanf("%d %d",&n,&m);
	sa=0;
	for(i=0;i<n;i++)	{
		scanf("%lld",&a);
		sa+=a;
	}
	sb=0;
	for(i=0;i<m;i++)	{
		scanf("%lld",&b);
		sb+=b;
	}
	x=sa*sb;
	printf("%lld\n",x);
	return 0;
}


Measured memory_bytes: 2736
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846
// #define __LOCAL

#ifdef __LOCAL
#define DBG(X) cout << #X << " = " << (X) << endl;
#define SAY(X) cout << (X) << endl;
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

ull n,m,x;
vector<int> V,W;

int main()
{
    fast_io();
    // ull elem_2 = 0 ;
    ull elem_5 = 0 ;

    n = fetch<ull>();
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    else if(n==0){
        cout << 0 << endl;
        return 0;        
    }
    else{
    // ull i=1;
    // elem_2 += m;

    // while(m >= (ull)pow(2ULL,i)){
    //     elem_2 += (ull)(m/pow(2ULL,i));
    //     i++;
    //     }
        
    m = (ull)n/2;
    int k=1;
    ull K = 5;
    while(m >= K){
        elem_5 += (ull)(m/K);
        K *= 5;
        }

    // ull ans;
    // if(elem_2>elem_5) ans = elem_5;
    // else ans = elem_2;
    // ull ans = min(elem_2,elem_5);
    cout << elem_5 << endl;
    return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s; 
  int price = 700; 
  if(s.at(0) == 'o') price += 100;
  if(s.at(1) == 'o') price += 100;
  if(s.at(2) == 'o') price += 100;
    cout << price << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int a,b,c,k;
  int sum=0;
  
  scanf("%d %d %d %d",&a,&b,&c,&k);
  
  while(a!=0&&k!=0){
    sum+=1;
    a--;
    k--;
  }
  while(b!=0&&k!=0){
    sum+=0;
    b--;
    k--;
  }
  while(c!=0&&k!=0){
    sum-=1;
    c--;
    k--;
  }
  printf("%d\n",sum);
  return(0);
}

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

int n;
string s, t;

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

    for(int lg = n; lg >= 1; --lg) {
        if(s.substr(n - lg) == t.substr(0, lg)) {
            printf("%d\n", 2 * n - lg);
            return 0;
        }
    }

    printf("%d\n", 2 * n);

    return 0;
}

Measured memory_bytes: 384
N, Q = map(int, input().split())
S = input()
lr_list = [map(int, input().split()) for _ in range(Q)]

sum_list = [0]

# for i in range(N):
#     if S[i] == 'C' and S[i-1] == 'A' and i:
#         sum_list.append(sum_list[-1]+1)
#     else:
#         sum_list.append(sum_list[-1])

[sum_list.append(sum_list[-1]+1) if s == 'C' and S[i-1] == 'A' else sum_list.append(sum_list[-1]) for i, s in enumerate(S)]

for l, r in lr_list:
    print(sum_list[r] - sum_list[l])

Measured memory_bytes: 52200
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,x=na()
l=na()
l.append(0)

count=0
pos=0
for i in range(n+1):
    count+=1
    pos+=l[i]
    if pos>x:
        break
print(count)

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

void solveA(){
  int x;
  cin >> x;

  if(x==7 || (x==5 || x==3)) cout << "YES" << endl;
  else cout << "NO" << endl;
}
void solveB(){
  string s;
  cin >> s;
  int ans = 1000;
  for(int i=0;i<s.size()-2;i++){
    int n = (s[i]-'0')*100 + (s[i+1]-'0')*10 + s[i+2]-'0';
    ans = min(ans,abs(n-753));
  }
  cout << ans << endl;
  
}
long n,ans=0;
void func(long a,int b){
  if (a>n) return;
  if (b == 7) ans++;
  func(a*10+3,b|1);
  func(a*10+5,b|2);
  func(a*10+7,b|4);  
}
void solveC(){
  cin >> n;
  func(0,0);
  cout << ans << endl;
}
void solveD(){
  
}

int main(){
  solveC();
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    int MAX_VAL = 30;
    bool canBuy = false;
    rep(i, 30) {
        rep(j, 30) {
            if (N == 4 * i + 7 * j) canBuy = true;
        }
    }

    string ans = canBuy ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define bf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double d;
#define MAX 1000009
#define MIN -1
#define M 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> Vector;
typedef queue<ll > Queue;
typedef stack<ll> Stack;
typedef pair<ll,ll> Pair;
#define mp make_pair
#define pb push_back
bool desc(ll i, ll j) { return i > j; }
ll ar[MAX];
int main(){
    bf;
    ll i=0,j=1,t,k,n,l=0,a=0,m,b=0,ans=1e11; string s;
    cin>>n;
    for(i=1;i*i<=n;i++){
        if(n%i==0){
            t=i; a=0,b=0;
            while(t){
                t/=10;
                a++;
            }
            t=n/i;
            while(t){
                t/=10;
                b++;
            }
            l=max(a,b);
        }    
        ans=min(ans,l);
    }
    cout<<ans;
    return 0;
}  

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

flg = True
cnt = 0

for j in range(100):
    for i in range(n):
        if a[i] % 2 == 1:
            flg = False

    if flg is True:
        for i in range(n):
            a[i] = int(a[i] / 2)
        cnt += 1
    else:
        break

print(cnt)


Measured memory_bytes: 3060
/**
*    author:  boutarou
*    created: 20.06.2020 20:32:12
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    cin >> a;
    int cnt = 0;
    int ans = 0;
    while(1) {
        cnt += a;
        ans++;
        if (cnt % 360 == 0) {
            cout << ans << endl;
            return 0;
        }
    }    
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define z 5000000000000000
#define sh 100000
ll dp[sh+1];
int main()
{

	
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,w,i,j;
	cin>>n>>w;
	ll ar[n+1][2];
	for(i=1;i<=n;i++)
		cin>>ar[i][0]>>ar[i][1];
	for(i=0;i<=sh;i++)
		dp[i]=z;
	dp[0]=0;
	
	for(i=1;i<=n;i++)
	{
		for(j=sh;j>=0;j--)
		{
			if(j-ar[i][1]>=0)
			dp[j]=min(dp[j-ar[i][1]]+ar[i][0],dp[j]);
		}
	}
	ll ans=0;
	for(i=sh;i>=0;i--)
	{
		if(dp[i]<=w)
		{
			ans=i;
			break;
		}
	}
	
	cout<<ans;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define LL long long
using namespace std;

int N;
map<int, int> Map;
set<int> Set;

int main()
{
    scanf("%d", &N);
    for(int i = 0; i < N; i ++) {
        int x;
        scanf("%d", &x);
        Set.insert(x);
        Map[x]++;
    }

    int ans = 0;
    for(auto it = Set.begin(); it != Set.end(); it ++)
        ans += Map[*it] - *it < 0 ? Map[*it] : Map[*it] - *it;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 9216
N,K=map(int,input().split())
if (N-1)*(N-2)//2<K:
  print(-1)
else:
  a=((N-2)*(N-1)//2)-K
  M=N-1+a
  print(M)
  for i in range(2,N+1):
    print(1,i)
  cnt=0
  for i in range(2,N):
    for j in range(i+1,N+1):
      if cnt<a:
        print(i,j)
        cnt+=1
      else:
        exit()

Measured memory_bytes: 3608
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <queue>

template<typename T>
class TBinaryHeap
{
    std::vector<T> FArray;
    void BubbleUp(int Index)
    {
        assert(FArray.size() > Index);
        if(Index == 1) return;
        int Parent = Index / 2;
        if(FArray[Index] <= FArray[Parent]){
            return;
        }
        std::swap(FArray[Index], FArray[Parent]);
        BubbleUp(Parent);
    }
    void BubbleDown(int Index)
    {
        assert(FArray.size() > Index);
        int Left  = Index * 2;
        int Right = Left + 1;
        if(Left  >= FArray.size()) return;
        const int& Target = Right >= FArray.size() ? Left : FArray[Left] > FArray[Right] ? Left : Right;
        if(FArray[Target] > FArray[Index]){
            std::swap(FArray[Index], FArray[Target]);
            BubbleDown(Target);
        }
    }
public:
    TBinaryHeap()
    {
        FArray.reserve(2000000);
        FArray.resize(1); // dummy
    }
    void push(const T& Value)
    {
        FArray.push_back(Value);
        BubbleUp(FArray.size()-1);
    }
    void pop()
    {
        assert(FArray.size() >= 1);
        FArray[1] = FArray.back();
        FArray.pop_back();
        if(FArray.size() == 1) return; // dummy???????????????
        BubbleDown(1);
    }
    const T& top()
    {
        return FArray[1];
    }
};
int main()
{
    char Line[19];
    int Value;

    // std::priority_queue<int> S;
    TBinaryHeap<int> S;
    while(1){
        std::fgets(Line, 19, stdin);
        if(Line[0] == 'i'){
            S.push(std::atoi(&Line[7]));
        }else
        if(Line[1] == 'x'){
            std::printf("%d\n", S.top());
            S.pop();
        }else{
            break;
        }
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  bool chk = false;
  for (int i=0;i<n;i++){
    string s;
    cin >> s;
    if (s == "Y"){
      cout << "Four" << endl;
      chk = true;
      break;
    }
  }
  if (!chk){
    cout << "Three" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
import sys

def main():
    """ Code implementation """
    N = int(input())
    L = list(map(int, input().split()))
    longest = 0
    sum = 0
    for l in L:
        sum = sum + l
        if longest < l:
            longest = l
        
    if longest < (sum - longest):
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
/// 標準入力マクロ
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        x: i32,
    }

    let mut ret = 0;
    for ua in 0..a + 1 {
        for ub in 0..b + 1 {
            let uc = (x - ua * 500 - ub * 100) / 50;
            if 0 <= uc && uc < c + 1 {
                ret = ret + 1;
            }
        }
    }

    println!("{}", ret);
}


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


int main() {
   int n, m, penalty = 0, correct = 0;
   string k;
   cin >> n >> m;
   vector<int> checks(n, 0);


   for (int i = 0, p; i < m; i++){
   		cin >> p >> k;

   		if (k == "WA" && checks[p-1] >= 0){
   			checks[p-1]++;
   		}

   		else if(k == "AC" && checks[p-1] >= 0){
   			penalty += checks[p-1];
   			correct++;
   			checks[p-1] = -1;
   		}
   }

   cout << correct << " " << penalty;

}

Measured memory_bytes: 640
n=int(input())
A=list(map(int,input().split()))
S=[0] #累積和
cnt=0
for i in range(n):
    cnt+=A[i]
    S.append(cnt)

ans=S[n]
d1=1 #しきり1(i個目の右で切る)
d3=2 #しきり3

for d2 in range(2,n-1): #しきり2を全探索
    L=S[d2]
    R=S[n]-S[d2]
    for i in range(d1,d2): #しきり1を右に動かす
        if S[i]>=L/2:
            break
    if abs(S[i]-L/2)>=abs(S[i-1]-L/2): #しきり1を更新
        d1=i-1
    else:
        d1=i
    for i in range(d3,n): #しきり3を右に動かす
        if S[i]-S[d2]>=R/2:
            break
    if abs(S[i]-S[d2]-R/2)>=abs(S[i-1]-S[d2]-R/2): #しきり3を更新
        d3=i-1
    else:
        d3=i
    s=[S[d1],S[d2]-S[d1],S[d3]-S[d2],S[n]-S[d3]] #4分割の結果
    ans=min(max(s)-min(s),ans) #解答の更新
    #print(d1,d2,d3,s)
print(ans)

Measured memory_bytes: 25672
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize
    };
    for i in 1..=b {
        if a * i % b == c {
            println!("YES");
            return;
        }
    }
    println!("NO");
}


Measured memory_bytes: 2144
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextLine();
        List<String> ns = Arrays.stream(sc.nextLine().split(" "))
                                 .collect(Collectors.toList());
        Collections.reverse(ns);
        String s = ns.stream()
          .collect(Collectors.joining(" "));
        System.out.println(s);
    }
}



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

int main(){
	double a,b,x,k;
	scanf("%lf %lf %lf",&a,&b,&x);
	
	if(x>a*a*b/2){
		x=a*a*b-x;
		
		k=2*x/a/a;
		printf("%.10f\n",asin(k/sqrt(k*k+a*a))*180/M_PI);
	}else{
		k=2*x/b/a;
		printf("%.10f\n",asin(b/sqrt(k*k+b*b))*180/M_PI);
	}
	//printf("%f %f %f %f\n",a,b,x,k);
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

if A > 0:
    if A < K:
        K -= A
        A = 0
    else:
        A -= K
        K = 0

if B > 0:
    if B < K:
        B = 0
    else:
        B -= K

print(A, B) 

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

int main() {
    int k,s;
    cin>>k>>s;
    int res = 0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int t = s-i-j;
            if(t>=0 && t<=k) res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

void write_chess(int stage,int width);

int main()
{
		int h,w,s;
		int i,j,k;
		int check=1;

		while(check){
			scanf("%d %d",&h,&w);
			
			if(h==0 && w == 0){
					check=0;
			} else {
					for(i=1;i<=h;i++){
							s = i%2;
							write_chess(s,w);
					}
					printf("\n");
			}
		}

		return 0;

}

void write_chess(int stage,int width){
		int count;
		if(stage==0){
				for(count=1;count<=width;count++){
					if((count%2)==1){
							printf(".");
					}else{
							printf("#");
					}
				}
				printf("\n");
		}else if(stage==1){
				for(count=1;count<=width;count++){
					if((count%2)==1){
							printf("#");
					}else{
							printf(".");
					}
				}
				printf("\n");
	
		}
}


Measured memory_bytes: 2048
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	vector<vector<int>> a(3, vector<int>(3));
	rep(i, 3)rep(j, 3)cin >> a[i][j];
	int n; cin >> n;
	vector<vector<int>> c(3, vector<int>(3, 0));
	while (n--)
	{
		int b; cin >> b;
		rep(i, 3)rep(j, 3)if (a[i][j] == b)c[i][j] = 1;
	}
	bool ok = false;
	rep(i, 3)
	{
		int x = 0;
		rep(j, 3)x += c[i][j];
		if (x == 3)ok = true;
	}
	rep(j, 3)
	{
		int x = 0;
		rep(i, 3)x += c[i][j];
		if (x == 3)ok = true;
	}
	if (c[0][0] + c[1][1] + c[2][2] == 3)ok = true;
	if (c[2][0] + c[1][1] + c[2][0] == 3)ok = true;
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
d = list(map(int, input().split()))
cnt = defaultdict(int)
if d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(n):
        cnt[d[i]] += 1
    for i in range(1, n):
        ans = (ans * cnt[d[i] - 1] % 998244353)

    print(ans)

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

typedef long long                   ll;
typedef long double                 ld;
typedef pair<ll,ll>                 pll;
typedef pair<ld,ld>                 pld;


#define all(x)          (x).begin(),(x).end()
#define Sort(x)         sort(all(x))
#define sep             ' '

#define endl            '\n'
#define tab             '\t'
#define X               first
#define Y               second
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define set_random      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 1e9 + 7,
         MAXN= 1e6+10,
         INF=1e18;
ll dp[MAXN],n,h[MAXN];
int main()
{
    fast_io;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(ll i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
ll update_prefix(lvi &v,ll l,ll r,ll x)
{
	v[l]+=x;
	v[r+1]-=x;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n,m;
	cin>>n>>m;
	lvi a(n+2);
	lvi const_sum(m+2,0),linear_sum(m+2,0);
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
	{
		ll x=a[i],y=a[i+1];
		if(x==y) continue;
		if(x<y)
		{
			update_prefix(const_sum,1,x,y-x);
			update_prefix(const_sum,x+1,y,y+1);
			update_prefix(const_sum,y+1,m,y-x);
			update_prefix(linear_sum,x+1,y,1);// basically we need to subtract index value 1 time;
		}
		else
		{
			update_prefix(const_sum,y+1,x,m-x+y);
			update_prefix(const_sum,1,y,1+y);
			update_prefix(const_sum,x+1,m,y+m+1);
			update_prefix(linear_sum,x+1,m,1);
			update_prefix(linear_sum,1,y,1);
		}
	}
	for (int i = 1; i <=m; ++i)
	{
		const_sum[i]+=const_sum[i-1];
		linear_sum[i]+=linear_sum[i-1];
	}
	for (int i = 1; i <=m; ++i)
	{
		const_sum[i]-=(i*linear_sum[i]);
	}
	ll ans=const_sum[1];
	for (int i = 1; i <=m; ++i)
	{
		ans=min(ans,const_sum[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int selectionSort(int A[],int N){
  int i,j,t,sw=0,mini;
  for(i = 0; i < N - 1; i++){
    mini = i;
    for(j = i; j < N; j++){
      if(A[j] < A[mini]) mini = j;
    }
    t = A[i];
    A[i] = A[mini];
    A[mini] = t;
    if(i != mini) sw++;
  }
  return sw;

}




int main(){
  int A[100],N,i,sw;

  scanf("%d",&N);
  for( i = 0; i < N; i++ ) scanf("%d",&A[i]);

  sw = selectionSort(A,N);

  for(i = 0; i < N; i++){
    if(i > 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",sw);

  return 0;
}




Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
#define mod (int)1000000007
#define MOD (int)10000000007
#define X 1001100011100001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for0e(i, n) for (int i = 0; i <= n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define F first
#define S second
#define pi pair<int, int>
#define ppi pair<pair<int,int> , int >
#define vii vector<pi>
#define endl "\n"
const int MAXN = (int)((1e5) + 100);
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;} 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};

// ========================================================
ll n,w,wts[109],val[109];
ll dp[109][100009];
ll maxProfit(int W,int index){

    if(dp[index][W] != -1){
      return dp[index][W];
    }

    if(W == 0 || index == n){
        return 0;
    }

    if(wts[index] > W){
      return maxProfit(W ,index+1);
    }
    else{
      dp[index][W] = max(val[index] + maxProfit(W-wts[index],index+1),
          maxProfit(W,index+1));
      return dp[index][W];
    }
}

signed main(){
  #ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  #endif
  fio;
    cin>>n>>w;
    for(ll i=0;i<n;i++){
        cin>>wts[i]>>val[i];
    }
    ini(dp,-1);
    cout<<maxProfit(w,0)<<endl;

  rr;
}



Measured memory_bytes: 88832
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    for ( ;; ) {
      int n = ni();
      if ( n == 0 ) {
        break;
      }

      int[] imos = new int[24 * 60 * 60 + 60 * 60 + 60];
      for ( int i = 0; i < n; ++i ) {
        ++imos[ nt() ];
        --imos[ nt() ];
      }

      int max = 0;
      int ite = 0;
      for ( int v : imos ) {
        ite += v;
        // if ( v != 0 )
        // debug( v, ite, max );
        max = Math.max( max, ite );
      }

      System.out.println( max );
    }
  }

  int nt() {
    String str = sc.next();
    String[] spr = str.split( ":" );
    int h = Integer.parseInt( spr[ 0 ] );
    int m = Integer.parseInt( spr[ 1 ] );
    int s = Integer.parseInt( spr[ 2 ] );
    return h * 60 * 60 + m * 60 + s;
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

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

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }

}

Measured memory_bytes: 100064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  ll x;
  cin >> x;
  ll m = x % 11;
  ll cnt = x * 2 / 11;
  if(m != 0 && m != 6) cnt++;
  cout << cnt << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    if (n%2 == 1){
        float f = n+1;
        f = f/2;
        f = f/n;
        cout << std::fixed << std::setprecision(6) << f << endl;
    }
    else{
        float f = n/2;
        f = f/n;
        cout << std::fixed << std::setprecision(6) << f << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1000000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <cassert>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <limits.h>
#include <fstream>

#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define pll pair <ll, ll>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double ld;
#define uint unsigned int

const int maxn = (int)1e6 + 10, mod = 998244353;
char s[maxn];

int mul(int x, int y) {
	return (ll)x * y % mod;
}

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

int sub(int x, int y) {
	x -= y;
	if (x < 0) {
		x += mod;
	}
	return x;
}

int my_pow(int x, int y) {
	int ans = 1;

	while (y) {
		if (y & 1) {
			ans = mul(ans, x);
		}

		x = mul(x, x);
		y >>= 1;
	}
	return ans;
}

const int maxlog = 23;
int g[maxlog + 1];

int rev(int x, int st) {
	int y = 0;

	for (int i = 0; i < st; i++) {
		y <<= 1;
		y += x & 1;
		x >>= 1;
	}
	return y;
}

void fft(vector <int> &v, int st, bool fl) {
	int n = (1 << st);

	for (int i = 0; i < n; i++) {
		int x = rev(i, st);
		if (x < i) {
			swap(v[i], v[x]);
		}
	}

	for (int len = 2; len <= n; len <<= 1) {
		for (int i = 0; i < n; i += len) {
			for (int j = i; j < i + len / 2; j++) {
				int a = v[j];
				int b = v[j + len / 2];
				v[j] = add(a, b);
				v[j + len / 2] = sub(a, b);
			}
		}
	}

	if (fl) {
		int rn = my_pow(n, mod - 2);

		for (int i = 0; i < n; i++) {
			v[i] = mul(v[i], rn);
		}
	}
}

int n;

vector <int> red[maxn];

const int mag = 19;

int mex(vector <int> a) {
	vector <int> cnt((int)a.size() + 1, 0);

	for (int x : a) {
		if (x < (int)cnt.size()) {
			cnt[x]++;
		}
	}

	int ans = 0;

	while (cnt[ans]) {
		ans++;
	}

	return ans;
}

vector <int> get() {
	int m;
	cin >> m;

	for (int i = 1; i <= n; i++) {
		red[i].clear();
	}

	while (m--) {
		int x, y;

		scanf("%d %d", &x, &y);
		red[y].push_back(x);
		red[x].push_back(y);
	}

	vector <int> ans(1 << mag, 0);

	int f = my_pow(10, 18);
	int x = 1;

	vector <int> ps(n + 1);

	for (int i = n; i > 0; i--) {
		vector <int> a;

		for (int u : red[i]) {
			if (u > i) {
				a.push_back(ps[u]);
			}
		}

		ps[i] = mex(a);
	}

	for (int i = 1; i <= n; i++) {
		x = mul(x, f);

		ans[ps[i]] = add(ans[ps[i]], x);
	}

	return ans;
}

int main() {
	g[maxlog] = my_pow(3, (mod - 1) / (1 << maxlog));
	for (int i = maxlog - 1; i >= 0; i--) {
		g[i] = mul(g[i + 1], g[i + 1]);
	}

	cin >> n;
	auto a = get();
	auto b = get();
	auto c = get();

	fft(a, mag, false);
	fft(b, mag, false);
	fft(c, mag, false);

	for (int i = 0; i < (int)a.size(); i++) {
		a[i] = mul(mul(a[i], b[i]), c[i]);
	}

	fft(a, mag, true);
	cout << a[0] << endl;
}

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

int main()
{
  int r,d,c,i;
  cin>>r>>d;
  int data[20];
  cin>>data[0];

  for(i=0;i<10;i++){
    data[i+1] = data[i]*r - d;
    std::cout<<data[i+1]<<std::endl;
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
#define int long long
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int seen[55][2501]; // seen[visit][money] : min time
int n;
int c[55], t[55];
vector<vector<pair<int, pint>>> g (55); // now : {visit,{money,time}}
void dijkstra (int S) {
    // money max 50*50
    if (S >= 2500) S = 2500;
    // q : {time,{visit,money}}
    priority_queue<pair<int, pint>, vector<pair<int, pint>>,
                   greater<pair<int, pint>>>
        q;
    rep (i, 0, n) rep (j, 0, 2501) seen[i][j] = INF;
    seen[0][S] = 0;
    q.push ({0, {0, S}});

    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        int time = p.first;
        int v = p.second.first;
        int money = p.second.second;
        if (seen[v][money] < time) continue;

        // ここはwhileにしなくてもまたやってくる
        if (money + c[v] <= 2500) {
            int nmoney = money + c[v], ntime = time + t[v];
            if (seen[v][nmoney] > ntime) {
                seen[v][nmoney] = ntime;
                q.push ({ntime, {v, nmoney}});
            }
        }

        for (auto e : g[v]) {
            if (money < e.second.first) continue;
            int nv = e.first;
            int nmoney = money - e.second.first;
            int ntime = time + e.second.second;
            if (seen[nv][nmoney] > ntime) {
                seen[nv][nmoney] = ntime;
                q.push ({ntime, {nv, nmoney}});
            }
        }
    }
}

signed main() {
    int m, s;
    cin >> n >> m >> s;
    rep (i, 0, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        g[--u].push_back ({--v, {a, b}});
        g[v].push_back ({u, {a, b}});
    }
    rep (i, 0, n) cin >> c[i] >> t[i];
    dijkstra (s);
    rep (i, 1, n) {
        int ans = INF;
        rep (j, 0, 2501) ans = min (ans, seen[i][j]);
        cout << ans << "\n";
    }
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a = n / 100000 + (n / 10000) % 10 + (n / 1000) % 10 + (n / 100) % 10 + (n / 10) % 10 + n % 10;
	cout << (a < 2 ? 10 : a) << endl;
	return 0;
}


Measured memory_bytes: 256
input_list = input().split()
nine = [1,2,3,4,5,6,7,8,9]
A = int(input_list[0])
B = int(input_list[1])
if A in nine:
    if B in nine:
        print(A*B)
    else:
        print('-1')
else:
    print('-1')

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] B = new int[N];

        for (int i = 0; i < N - 1; i++) {
            int An = scanner.nextInt();
            B[An - 1]++;
        }

        for (int b: B) {
            System.out.println(b);
        }
    }
}


Measured memory_bytes: 61696
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exists(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}
inline ll modpow(ll x, ll y) {
    ll res = 1;
    while(y) {
        if(y&1) res = mul(res,x);
        y >>= 1;
        x = mul(x,x);
    }
    return res;
}

int main(){
    string S, T; cin >> S >> T;
    int rui1[100005];
    int rui2[100005];
    rui1[0] = 0;
    rui2[0] = 0;
    REP(i,S.size()) rui1[i+1] = rui1[i] + (S[i]=='A' ? 1:0);
    REP(i,T.size()) rui2[i+1] = rui2[i] + (T[i]=='A' ? 1:0);
    int q; cin >> q;
    while(q--) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        int sa = rui1[b] - rui1[a-1];
        int sb = b-a+1-sa;
        int ta = rui2[d] - rui2[c-1];
        int tb = d-c+1-ta;
        if((sa+2*sb)%3==(ta+2*tb)%3) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vs vector<string>
#define vpll vector<pll>
#define vvll vector<vector<ll>>
#define vvpll vector<vpll>
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll T;cin>>T; while(T--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pi 3.14159265358979323846
#define MOD 1000000007
#define MAX 2000000000000000000
#define MAXN 100005
void inout()
{
    fast_io;
    #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin);
        freopen("output.txt" , "w" , stdout);
    #endif
}
void solve() {
	ll h, w, m, a, b , i;
    cin >> h >> w >> m;
    vector<ll> l(h + 5, 0), r(w + 5, 0);
    map<pll, ll> t;
    for(i = 0 ; i < m ; i++){
        cin >> a >> b;
	a--;
	b--;
        l[a]++;
        r[b]++;
        pll p = make_pair(a, b);
        t[p]++;
    }
    ll max_l = *max_element(l.begin(), l.end());
    ll max_r = *max_element(r.begin(), r.end());
    vector<ll> ndx_l, ndx_r;
    for(i = 0 ; i < h + 1 ; i++) if (l[i] == max_l) ndx_l.push_back(i);
    for(i = 0 ; i < w + 1 ; i++) if (r[i] == max_r) ndx_r.push_back(i);
    ll ans = max_l + max_r - 1;
    for (auto x: ndx_l){
        for (auto y: ndx_r){
            pll p = make_pair(x, y);
            if (t[p]==0){
                ans = max_l + max_r;
                cout << ans << endl;
                return ;
            }
        }
    } 
    cout << ans << endl;
}
int main() {
    solve();
    return 0;
}



Measured memory_bytes: 34936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define forn1 for(i=1; i<=n; i++)




int main()
{
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r;
    string s,ss;
    cin>>n;
    forn1
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                c+=__gcd(j,__gcd(i,k));
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3600
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int a, b, c;
  get(a, b, c);
  print(3 - (a == b) - (b == c) - (c == a) + (a == b && b == c));
  return 0;
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int a, b, c;  cin >> a >> b >> c;
  int k;  cin >> k;
  while(k and a>=b){
    b*=2, k--;
  }
  while(k and b>=c){
    c*=2, k--;
  }
  if(a<b and b<c){
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3632
a = int(input())
b = int(input())
c = int(input())
X = int(input())

num = 0
total = 0

for i in range(a+1):
    for m in range(b+1):
        for p in range(c+1):
            total = 500*i + 100*m + 50*p
            if(X == total):
                num += 1

print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    string S;
    cin >> N >> S;
    
    int count = 0;
    char c = 'A';
    for (int i = 0; i < N; i++) {
        if (c == S[i])
            c++;
        else if (S[i] != 'A')
            c = 'A';
        else
            c = 'B';
        if (c == 'D') {
            count++;
            c = 'A';
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int m, d; cin >> m >> d;
  int ans = 0;
  REP(i,1,m+1) {
    REP(j,1,d+1) {
      int d1 = j%10, d10 = j/10;
      if (d1>=2 && d10>=2 && d1*d10==i) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			c[i] = s.charAt(i);
		}
		int num = 0;
		for (int i = 0; i < s.length(); i++) {
			num += Character.getNumericValue(c[i]);
		}
		int x = Integer.parseInt(s);
		if (x%num==0) {
			System.out.println("Yes");			
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23380
import java.io.*;
import java.util.*;

class Main{
		private static ArrayList<String> check_point(ArrayList<Double> a){
			ArrayList<String> b = new ArrayList<String>();
			for(int i=0;i<a.size()/8;i++){
				String ch = "YES";
				double x1,y1,x2,y2,x3,y3,xp,yp;
				x1 = a.get(i*8);
				y1 = a.get(i*8+1);
				x2 = a.get(i*8+2);
				y2 = a.get(i*8+3);
				x3 = a.get(i*8+4);
				y3 = a.get(i*8+5);
				xp = a.get(i*8+6);
				yp = a.get(i*8+7);
				if(((x3 * (y1-y2) + y3 * (x2 - x1) +x1 * y2 - x2 * y1) * (xp * (y1-y2) + yp * (x2 - x1) +x1 * y2 - x2 * y1)) < 0) ch = "NO";
				else if (((x3 * (y1-y2) + y3 * (x2 - x1) +x1 * y2 - x2 * y1) * (xp * (y1-y2) + yp * (x2 - x1) +x1 * y2 - x2 * y1)) < 0) ch = "NO";
				else if (((x1 * (y2-y3) + y1 * (x3 - x2) +x2 * y3 - x3 * y2) * (xp * (y2-y3) + yp * (x3 - x2) +x2 * y3 - x3 * y2)) < 0 )ch = "NO";
				else if (((x2 * (y3-y1) + y2 * (x1 - x3) +x3 * y1 - x1 * y3) * (xp * (y3-y1) + yp * (x1 - x3) +x3 * y1 - x1 * y3)) < 0) ch = "NO";
				b.add(ch);
			}
			return b;
		}
		
		public static void main(String args[]) throws IOException{
			ArrayList<Integer> inp = new ArrayList<Integer>();
			ArrayList<Integer> out = new ArrayList<Integer>();
			Scanner scan = new Scanner(System.in);
			while(scan.hasNext()){
				String str1 = scan.next();
				inp.add(Integer.valueOf(str1).intValue());
			}
			
			for(int i=0;i<inp.size();i++){
				if(inp.get(i) != 0) out.add(inp.get(i));
				else{
					System.out.println(out.get(out.size()-1));
					out.remove(out.size()-1);
					}
			}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a,b,t;
	string s,w;
	
	cin >> s >> w;
	s.pb(w.back());
	if(s==w)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e18;

int main() {
	
	ll x,count = 0;
	cin >> x;
	count += (x / 11)*2;
	count += ((x %11 == 0)?0:((x % 11 <= 6) ? 1 : 2));
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		long[][] dp = new long[n-1][21];
		for(int j=0;j<=20;j++) {
			dp[0][j] = 0;
		}
		dp[0][a[0]] = 1;
		for(int i=1;i<n-1;i++) {
			for(int j=0;j<=20;j++) {
				if(j-a[i]>=0) dp[i][j] += dp[i-1][j-a[i]];
				if(j+a[i]<=20) dp[i][j] += dp[i-1][j+a[i]];
			}
		}
		System.out.println(dp[n-2][a[n-1]]);
	}	
	
}





Measured memory_bytes: 26104
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(b)  (b).begin(),(b).end()
#define RALL(b) (b).rbegin(), (b).rend()
#define PB push_back
#define MP make_pair
#define SZ(b) int((b).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(b) memset((b), 0 ,sizeof(b))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main()
{
	int n;
	cin >> n;
	string s1, s2;
	cin >> s1 >> s2;
	int i = 0;
	vector<bool> b(0);
	while (i < n) {
		if (s1[i] == s2[i]) {
			b.push_back(true);
			++i;
		}
		else {
			b.push_back(false);
			i += 2;
		}
	}
	long long c = b[0] ? 3 : 6;
	REP(i, b.size()-1) {
		if (b[i]) c = (c * 2) % 1000000007;
		else if(!b[i+1]) c = (c * 3) % 1000000007;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256