akhauriyash/Code-Regression huggingface dataset:
from sys import exit
n = int(input())
stone = list(input())
w_num = stone.count("W")
r_num = stone.count("R")
if w_num == n or r_num == n:
    print(0)
    exit()

####
#stone = ["W"] * 100000 + ["R"] * 10000
####

def w_serch(entry_point):
    for i in range(n):
        try:
            pointer_left = entry_point + i
            if stone[pointer_left] == "W":
                return pointer_left
        except:
            return n

def r_serch(entry_point):
    for i in range(n):
        try:
            pointer_right = entry_point - i
            if stone[pointer_right] == "R":
                return pointer_right
        except:
            return -1

counter = 0
pointer_l = 0
pointer_r = n-1
for i in range(n // 2):
    pointer_l = w_serch(pointer_l)
    pointer_r = r_serch(pointer_r)
    #print(stone, pointer_l, pointer_r)
    if pointer_l > pointer_r:
        break
    else:
        stone[pointer_l] = "R"
        stone[pointer_r] = "W"
    #print(stone, pointer_l, pointer_r)
    counter += 1
print(counter)

Measured memory_bytes: 77896
/* Coached by rainboy */
#include <stdio.h>

#define N 100
#define P 25

int pp[P] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };

int count(int n, int p) {
	return n % p ? 0 : count(n / p, p) + 1;
}

int main() {
	static int kk[P];
	int n, x, i, j, k, ans;

	scanf("%d", &n);
	for (x = 2; x <= n; x++)
		for (i = 0; i < P; i++)
			kk[i] += count(x, pp[i]);
	ans = 0;
	for (i = 0; i < P; i++)
		if (kk[i] >= 74)
			ans++;
	for (i = 0; i < P; i++)
		for (j = 0; j < P; j++)
			if (i != j && kk[i] >= 2 && kk[j] >= 24)
				ans++;
	for (i = 0; i < P; i++)
		for (j = 0; j < P; j++)
			if (i != j && kk[i] >= 4 && kk[j] >= 14)
				ans++;
	for (i = 0; i < P; i++)
		for (j = 0; j < P; j++)
			for (k = j + 1; k < P; k++)
				if (i != j && i != k && kk[i] >= 2 && kk[j] >= 4 && kk[k] >= 4)
					ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define ll long long
#define mp make_pair
#define pb push_back

ll INF = 1000000007;

int ret(int get)
{
	if (!get) return 1;
	else if (get < 0) return - get;
	else return get;
}

int main(void)
{
	int n;
	cin >> n;
	vec<pair<int, int>> a(2 * n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = 1;
	}
	rep(i, n) {
		cin >> a[i + n].first;
		a[i + n].second = - 1;
	}

	sort(a.begin(), a.end());

	vec<int> cur;
	int count = 0;
	ll ans = 1;
	rep(i, n * 2) {
		count += a[i].second;
		cur.pb(a[i].second);
		if (!count) {
			int start = cur[0];
			ll c = 0;
			rep(j, cur.size()) {
				if (start == cur[j]) c++;
				else {
					ans *= c;
					ans %= INF;
					c--;
				}
			}
			cur.clear();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2936
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long ll;
using namespace std;
int main()
{
    string a,b;
    cin >> a>>b ;
    int sum = 0;
    for (int i = 0; i < a.length(); i++) {
        if (a[i] != b[i]) sum++;
    }
    cout << sum;

    return 0;
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<lli, int> pii;


int main()
{
    set<int> st;
    int n, k;
    cin >> n >> k;
    while(k--){
        int d;
        cin >> d;
        while(d--){
            int x;
            cin >> x;
            st.insert(x);
        }
    }
    cout << n-st.size() << endl;

    return 0;
}


Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

#[test]
fn test() {
    assert_eq!(one_clue(3, 7), [5, 6, 7, 8, 9]);
    assert_eq!(one_clue(4, 0), [-3, -2, -1, 0, 1, 2, 3]);
    assert_eq!(one_clue(1, 100), [100]);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
    token.parse().ok().expect("failed to parse token")
}

fn one_clue(k: i64, x: i64) -> Vec<i64> {
    let mut v = Vec::new();
    for i in x-(k-1)..x+k {
        v.push(i);
    }
    v
}
fn main() {
    let k: i64 = read();
    let x: i64 = read();

    for i in one_clue(k, x).iter() {
        print!("{} ", i);
    }
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    //if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s,t;
  int a, b;
  string u;
  cin >> s >> t>> a >> b>> u;
  if(u == s) cout << a-1 << " " << b  << endl;
  else cout << a << " " << b-1 << endl;
}

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

int main(){
  string s;
  cin>>s;
  ll x=0;
  for(int i=0;i<s.size();i++){
    x+=int(s[i]-'0');
  }
  if(x%9==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3752
import sys

input = sys.stdin.buffer.readline

n = int(input())
A = []
B = []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if n % 2 == 1:
    saisho = A[(n - 1) // 2]
    saidai = B[(n - 1) // 2]
    print(saidai - saisho + 1)
else:
    saisho1 = A[n // 2 - 1]
    saisho2 = A[n // 2]
    saidai1 = B[n // 2 - 1]
    saidai2 = B[n // 2]
    saidai = saidai2 + saidai1
    saisho = saisho2 + saisho1
    delta = saidai - saisho
    print(delta + 1)


Measured memory_bytes: 88280
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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

int dp[110000][3];
int main()
{
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N);
  REP(i, N) cin >> a[i] >> b[i] >> c[i];

  REP(i, N) {
    dp[i + 1][0] = max({dp[i + 1][0], dp[i][1] + a[i], dp[i][2] + a[i]});
    dp[i + 1][1] = max({dp[i + 1][1], dp[i][0] + b[i], dp[i][2] + b[i]});
    dp[i + 1][2] = max({dp[i + 1][2], dp[i][0] + c[i], dp[i][1] + c[i]});
  }
  cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

  return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int a, b, c, d, e, k;
        Scanner sc = new Scanner(System.in);

        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        e = sc.nextInt();
        k = sc.nextInt();

        if(e - d <= k && e - c <= k && e - b <= k && e - a <= k && d - c <= k && d - b <= k && d - a <= k && c - b <= k && c - a <= k && b - a <= k)
            System.out.println("Yay!");
        else
            System.out.println(":(");
    }
}


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

a, b = (int(i) for i in input().split())
s = input()

#print(a,b,s,s.lower())
if b==1:
  s = s[b-1].lower() + s[b:]
elif b==a:
  s = s[:b-1]+s[b-1].lower()
else:
  s=s[:b-1]+s[b-1].lower()+ s[b:]

print(s)

Measured memory_bytes: 3060
import java.util.*;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = sc.nextInt(), b = sc.nextInt();
		int total = 0;
		
		for(int i = 1; i<=N; i++) {
			int count = 0;
			int temp = i;
			while(temp > 0) {
				count += temp%10;
				temp/=10;
			}
			if(count >= a && count <= b) total+=i;
		}
		
		System.out.println(total);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#define inf 10e8
#define rep(i,n) for(long i=0;i<n;i++)
using namespace std;

map< int64_t, int > prime_factor(int64_t n) {
    map< int64_t, int > ret;
    for(int64_t i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

long gcd(long a,long b){
    if (a<b) return gcd(b,a);
    else {
        if (b==1) return 1;
        else if (b==0) return a;
        else return gcd(b,a%b);
    }
}


int main(){
    long a,b;
    cin >> a >> b;
    long ans=0;
    for(auto p : prime_factor(gcd(a,b))) {
        long d=-inf;
        while(p.second--) {
            if(p.first!=d){
                ans++;
                d=p.first;
            }
        }
    }
    cout << ans+1 << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define pop(v) (v).back(); (v).pop_back()
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

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

    lint a, b;
    cin>>a>>b;
    coc((a*b)%2, "Odd", "Even");
}

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

int main(){
  int n, a[100];
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }
  for(int k = n - 1; k > -1; --k){
    cout << a[k];
    if( k == 0) break;
    cout << " ";
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int count[] = new int[26];
        while(scan.hasNextLine()) {
            String s = scan.nextLine();
            for(int i=0;i<s.length();i++){
                char c=s.charAt(i);
                if('a'<=c && c<='z'){
                    count[c-'a']++;
                }else if('A'<=c && c<='Z'){
                    count[c-'A']++;
                }
            }
        }
        for(int i=0;i<26;i++){
            System.out.printf("%c : %d\n",'a'+i,count[i]);
        }
    }
}



Measured memory_bytes: 26560
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
//#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    long int N,X,T;
    cin>>N>>X>>T;
    long int ans=0;
    ans=N/X;
    ans=ans*T;
    if (N%X!=0) ans+=T;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3520
#include<stdio.h>
#include<string.h>
int main()
{
		char c[19];
		int i,x;
		gets(c);
		for(i=0;i<strlen(c);i++)
			{
						if(c[i]==',')
						c[i]=39-7;	
				}
		printf("%s\n",c);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<double>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  sort(A.begin(),A.end());
  double ans=(A[0]+A[1])/2;
  for(int i=2;i<N;i++)ans=(A[i]+ans)/2;
  cout<<ans<<endl;
}

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

int main(){
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<vector<int> > vec(Q,vector<int>(2));
    rep(i,Q){
        cin >> vec[i][0] >> vec[i][1];
    }
    vector<int> ans(N,0);
    rep(i,N - 1){
        if (S[i] == 'A' && S[i + 1] == 'C'){
            ans[i]++;
        }
        ans[i + 1] = ans[i];
    }
    rep(i,Q){
        if (vec[i][0] == 1){
            cout << ans[vec[i][1] - 2]<< endl;
        }
        else{
            cout << ans[vec[i][1] - 2] - ans[vec[i][0] - 2] << endl;
        }
        //cout << ans[vec[i][1] - 2] - ans[vec[i][0] - 2] << endl;
    }
}


Measured memory_bytes: 6784
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let nk: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];
    let mut a: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let idx = a.iter().position(|&x| x == 1).unwrap();
    let lans = (idx + k - 2)/(k - 1);
    let rans = (n - (k-1) * lans - 1 + (k-2)) / (k-1);
    println!("{}",  lans + rans);
}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

template<class T>
void chmax(T& a,T b){
	a=max(a,b);
}

template<class T>
void chmin(T& a,T b){
	a=min(a,b);
}

template<class T>
void ResetVector(vector<T>& v,int n,const T& t){
	v.clear();
	v.resize(n,t);
}

int main(){
	int n=read(),k=read();
	vi c(26,0);
	REP(i,n){
		char buf[16];
		scanf("%s",buf);
		c[(int)buf[0]-'A']++;
	}
	int ans=0;
	while(1){
		sort(c.begin(),c.end(),greater<int>());
		if(*min_element(c.begin(),c.begin()+k)>0){
			ans++;
			REP(i,k)
				c[i]--;
		}else
			break;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
using System;

class Program
{
  static void Main(string[] args)
  {
    string str1 = Console.ReadLine();
    string str2 = Console.ReadLine();
    string str3 = Console.ReadLine();
    
    Console.WriteLine("{0}{1}{2}", str1[0], str2[1], str3[2]);
  }
}

Measured memory_bytes: 13140
n=int(input())
Mantion=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    b,f,r,v=map(int,input().split())
    Mantion[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" %d"%Mantion[i][j][k],end="")
        print()
    if i != 3:
        print('#'*20)



Measured memory_bytes: 5628
#include<stdio.h>
int main(void)
{
	int s[5];
	int sum,i,j,k;
	for(i=0;i<5;i++){
		scanf("%d",&s[i]);
	}
	sum=0;
	for(j=0;j<=4-1;j++){
		for(k=j+1;k<=4;k++){
			if(s[j]<=s[k]){
				sum=s[j];
				s[j]=s[k];
				s[k]=sum;
		}
	}
	}
	
		printf("%d %d %d %d %d\n",s[0],s[1],s[2],s[3],s[4]);
		return 0;
	}


Measured memory_bytes: 2108
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll dp[55][55][3000];
int main(){
    int n,a;
    cin >> n >> a;
    vector<int>x(n);
    rep(i,n){
        cin >> x[i];
    }
//    sort(x.begin(),x.end());
    rep(i,n+1)dp[i][0][0] = 1;
    rep(i,n){
        for(int j = 1; j <= i + 1; j ++){
            rep(k,3000){
                dp[i+1][j][k] = dp[i][j][k];
                if(j-1>=0 and k-x[i]>=0)dp[i+1][j][k] += dp[i][j-1][k-x[i]];
//                cerr << i+1 << " " << j << " " << k << " " << dp[i+1][j][k] << endl;
            }
        }
    }
    ll ans = 0;
    rep(i,n){
        ans += dp[n][i+1][(i+1)*a];
    }
    cout << ans << endl;
}

Measured memory_bytes: 65792
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e15)

typedef enum{
	false,
	true
}Boolean;

typedef struct node_sub{
	int data;
	struct node_sub *next;
}node;

typedef struct {
	node *fst;
	node *last;
	int num;
}queue;

queue *make_queue(){
	queue *q = (queue *)malloc(sizeof(queue));
	q->fst = NULL;
	q->last = NULL;
	q->num = 0;
	return q;
}

Boolean is_empty(queue *q){
	if(q->num == 0){
		return true;
	}
	else{
		return false;
	}
}

void add_data(int val, queue *q){
	node *last = (node *)malloc(sizeof(node));
	last->data = val;
	last->next = NULL;
	if(is_empty(q) == true){
		q->fst = last;
	}
	else{
		q->last->next = last;
	}
	q->last = last;
	q->num++;
}

int take_data(queue *q){
	if(q->num == 0){
		printf("no data in the queue\n");
	}
	int ans = q->fst->data;
	node *fst = q->fst;
	if(q->num == 1){
		q->fst = NULL;
		q->last = NULL;
	}
	else{
		q->fst = fst->next;
	}
	free(fst);
	q->num--;
	return ans;
}

void to_empty(queue *q){
	int a;
	while(is_empty(q) == false){
		a = take_data(q);
	}
}

int min(int a, int b){
	if(a < b){
		return a;
	}
	else{
		return b;
	}
}

//n:頂点数, s:始点の番号, t:終点の番号, e:(u, v)->f uからvへの容量
int Edmonds_Karp(int n, int s, int t, int **e){
	int v, i;
	int flow_sum = 0;
	int *flow = (int *)malloc(sizeof(int) * n);//各頂点に流せるフロー
	int *p = (int *)malloc(sizeof(int) * n);//増加道の履歴 前の頂点を入れる
	queue *q = make_queue();

	for(;;){
		//初期化
		for(i = 0; i < n; i++){
			flow[i] = 0;
			p[i] = -1;
		}
		flow[s] = inf;
		p[s] = -2;

		add_data(s, q);
		while(is_empty(q) == false){
			v = take_data(q);
			if(v == t){
				break;
			}
			for(i = 0; i < n; i++){
				if(e[v][i] > 0 && p[i] == -1){
					p[i] = v;
					flow[i] = min(flow[v], e[v][i]);
					add_data(i, q);
				}
			}
		}
		//増加道がなかった場合
		if(flow[t] == 0){
			break;
		}
		//残余ネットワークの構築
		for(v = t; v != s; v = p[v]){
			e[p[v]][v] -= flow[t];
			e[v][p[v]] += flow[t];
		}
		flow_sum += flow[t];
		to_empty(q);
	}
	return flow_sum;
}

int main(){
	int N, a, i, j, sum = 0;
	scanf("%lld", &N);
	int **e = (int **)malloc(sizeof(int *) * (N + 2));
	for(i = 0; i <= N + 1; i++){
		e[i] = (int *)malloc(sizeof(int) * (N + 2));
		for(j = 0; j <= N + 1; j++){
			e[i][j] = 0;
		}
	}
	for(i = 1; i <= N; i++){
		scanf("%lld", &a);
		if(a <= 0){
			e[0][i] = -a;
		}
		else{
			e[i][N + 1] = a;
			sum += a;
		}
	}
	for(i = 1; i <= N; i++){
		for(j = 2 * i; j <= N; j += i){
			e[i][j] = inf;
		}
	}
	printf("%lld\n", sum - Edmonds_Karp(N + 2, 0, N + 1, e));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
int n, m, x, y,z,w,h, sum= 0, ans;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
template <typename T>
struct BIT {
    int n;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int n_) { init(n_); }
    void init(int n_) {
        n = n_ + 1;
        for (int p = 0; p < 2; p++) bit[p].assign(n, 0);
    }
    void add_sub(int p, int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[p][idx] += x;
        }
    }
    void add(int l, int r, T x) {  // [l,r) に加算
        add_sub(0, l, -x * (l - 1));
        add_sub(0, r, x * (r - 1));
        add_sub(1, l, x);
        add_sub(1, r, -x);
    }
    T sum_sub(int p, int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[p][idx];
        }
        return s;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
};
int main(void) {
    cin >> n >> m; BIT<int> b(n);
    rep(i, m) {
        cin >> x;
        if (x == 0) {
            cin >> y >> z >> w;
            b.add(y, z+1, w);
        }
        else {
            cin >> y;
            cout << b.sum(y) - b.sum(y-1) << endl;
        }
    }
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,k;cin>>n>>k;
 	int A[n];
  vector<int> dp(n+k,1000000007);
  for( i=0;i<n;i++)
    cin>>A[i];
  dp[0]=0;
  for(i=0;i<n;i++)
  {	
    for(j=i+1;j<=i+k;j++)
    {
     	if(j<n)
		dp[j]=min(dp[j],dp[i]+abs(A[j]-A[i]));
    }
  }
  cout<<dp[n-1];
}

  

Measured memory_bytes: 1024
'use strict'

const main = (INPUT) => {
  const S = INPUT.split('\n')[0].split('')
  const ary = S.filter((x, i, self) => self.indexOf(x) === i)
  if (ary.length == 2) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int D;
  cin>>D;

  const int A = 26;
  vector<int> cs(A+1);
  for(int j=1;j<=A;j++) cin>>cs[j];

  vector s(D+1,vector<int>(A+1));
  for(int i=1;i<=D;i++)
    for(int j=1;j<=A;j++)
      cin>>s[i][j];

  vector<int> ts(D+1);
  {
    vector<int> ls(A+1,0);
    for(int i=1;i<=D;i++){
      vector<int> ss(A+1,0);
      for(int j=1;j<=A;j++)
        ss[j]=s[i][j]+cs[j]*(i-ls[j]);
      ts[i]=max_element(ss.begin()+1,ss.end())-ss.begin();

      ls[ts[i]]=i;
    }
  }

  auto calcScore=[&]()->int{
    int res=0;
    vector<int> ls(A+1,0);
    for(int i=1;i<=D;i++){
      res+=s[i][ts[i]];
      ls[ts[i]]=i;
      for(int j=1;j<=A;j++)
        res-=cs[j]*(i-ls[j]);
    }
    return res;
  };

  cerr<<calcScore()<<newl;
  for(int i=1;i<=D;i++) cout<<ts[i]<<newl;
  return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
struct Node;
vector<Node> V;
struct Node {
  int idx;
  int grp;
  int ans;
  vector<int> nbr;
  bool vst = false;
  void dfs(int group_id) {
    vst = true;
    grp = group_id;
    for(int x : nbr) {
      if(!V[x].vst) {
        V[x].dfs(group_id);
      }
    }
  };
};
int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(M);
    vector<int> B(M);
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    vector<int> C(K);
    vector<int> D(K);
    REP(i, K) {
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }
    REP(i, N) {
        V.emplace_back();
    }
    REP(i, M) {
        V[A[i]].nbr.push_back(B[i]);
        V[B[i]].nbr.push_back(A[i]);
    }
    int group_id = 0;
    REP(i, N) {
        if(!V[i].vst) {
            V[i].dfs(group_id);
            group_id++;
        }
    }
    vector<int> group_size(group_id);
    REP(i, N) {
        group_size[V[i].grp]++;
    }
    REP(i, N) {
        V[i].ans = group_size[V[i].grp] - 1;
    }
    REP(i, M) {
        V[A[i]].ans--;
        V[B[i]].ans--;
    }
    REP(i, K) {
        if(V[C[i]].grp == V[D[i]].grp) {
            V[C[i]].ans--;
            V[D[i]].ans--;
        }
        
    }

    REP(i, N) cout << V[i].ans << (i!=N-1 ? " " : "");
    cout << endl;
}

Measured memory_bytes: 11480
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
const int MAX = 100;
const int BLACK = 2;
const int GRAY = 1;
const int WHITE = 0;
using namespace std;

int n, M[MAX][MAX];

void dijkstra(){
  int minv;
  int color[MAX];
  //d[i] : 自集合からの点iへの最短距離
  int d[MAX];

  rep(i,n){
    color[i] = WHITE;
    d[i] = INT_MAX;
  }
  d[0] = 0;
  color[0] = GRAY;

  while(1){
    minv = INT_MAX;
    int u = -1;
    rep(i,n){
      if(color[i] != BLACK && minv > d[i]){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    rep(v,n){
      //uとvがつながっている、かつvが未探索
      if(M[u][v] != INT_MAX && color[v] != BLACK){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  rep(i,n){
    cout << i << " " << (d[i] == INT_MAX ? -1 : d[i]) << endl;
  }
}

int main(){
  cin >> n;
  rep(i,n){
    rep(j,n){
      M[i][j] = INT_MAX;
    }
  }

  rep(i,n){
    int u,k;
    cin >> u >> k;
    rep(j,k){
      int v,c;
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
}


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

int main() {
  int n,m,s,a;
  cin >> n >> m;
  s=0;
  for(int i=0; i<m; i++){
    cin >> a;
    s+=a;
  }
  if(s>n) cout << "-1" << endl;
  else{
    cout << n-s << endl;
  }
}


Measured memory_bytes: 3592
import numpy as np

N, M = map(int, input().split())

#データの入力
array = np.array([[0]*N]*M)
for i in range(M):
    switch = list(map(int, input().split()))
    List = [0]*N
    for j in switch[1:]:
        List[j-1] = 1
    array[i] = np.array(List)



condition = np.array([list(map(int, input().split()))])


def onoff(array, List):
    return np.dot(array, List) % 2

def mklist(i):
    binnum = bin(i)
    binnum = binnum[2:].zfill(N)
    return np.array([list(map(int, list(binnum)))]).T

ans = 0
for i in range(2**N):
    if np.all(condition == onoff(array, mklist(i)).T):
        ans = ans + 1
    
print(ans)    
    

Measured memory_bytes: 12436
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 = sc.nextInt();
		int B = sc.nextInt();
		
		if ((A-B)%2 == 0)
			System.out.println("Alice");
		else
			System.out.println("Borys");
	}
}

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

string S;

int main(){
	cin >> S;
	for(int i = 0; i < S.length() - 5; i++) {
		string str = S.substr(i, 6);
		if(str == "eraser")
			for(int j = 0; j < 6; j++) S[i + j] = '-';
	}
	for(int i = 0; i < S.length() - 4; i++){
		string str = S.substr(i, 5);
		if(str == "erase")
			for(int j = 0; j < 5; j++) S[i + j] = '-';
	}
	for(int i = 0; i < S.length() - 6; i++){
		string str = S.substr(i, 7);
		if(str == "dreamer")
			for(int j = 0; j < 7; j++) S[i + j] = '-';
	}
	for(int i = 0; i < S.length() - 4; i++){
		string str = S.substr(i, 5);
		if(str == "dream")
			for(int j = 0; j < 5; j++) S[i + j] = '-';
	}
	bool full = false;
	for(int i = 0; i < S.length(); i++)
		if(S[i] != '-') full = true;
	if(full) printf("NO\n");
	else printf("YES\n");
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int>G[MAX];
int color[MAX];

void dfs(int r, int c) {
	stack<int>S;
	S.push(r);
	color[r] = c;
	while (!S.empty()) {
		int u = S.top(); S.pop();
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (color[v] == NIL) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	int id = 1;
	for (int i = 0; i < n; i++)color[i] = NIL;
	for (int u = 0; u < n; u++) {
		if (color[u] == NIL)dfs(u, id++);
	}
}
int main() {
	int s, t, m, q;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	assignColor();
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> s >> t;
		if (color[s] == color[t]) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 8944
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static long[] list=new long[87];

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

  // String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();
 
   String[] s=sc.nextLine().split(" ");
 //    String[] t=sc.nextLine().split("");

//int N=Integer.parseInt(s[0]);
int A=Integer.parseInt(s[0]);
int B=Integer.parseInt(s[1]);

String[] S=sc.nextLine().split("-");
if(S.length!=2)
System.out.println("No");
else{
try{
int mae=Integer.parseInt(S[0]);
int usi=Integer.parseInt(S[1]);
if(S[0].length()==A && S[1].length()==B){
System.out.println("Yes");
}else{
System.out.println("No");
}
}catch(Exception e){
System.out.println("No");
}

}


}

}



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

#define int int64_t
#define pb push_back
#define ibsws ios_base::sync_with_stdio
#define gcd __gcd
#define S second
#define F first

using namespace std;

int ans,mn=1e3;
string s;

int32_t main(){
	ibsws(true==false);
    cin>>s;
    for(int i=0;i<s.size()-2;i++){
        ans=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        ans=abs(ans-753);
        mn=min(mn,ans);
    }
    cout<<mn;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Common;

public static class Common
{

    public static int BinSearchIndex(int v, int[] list)
    {
        v = v + 1;
        if (v > list.Last())
        {
            return list.Length;
        }
        int minRange = 0;
        int maxRange = list.Count() - 1;
        while (minRange != maxRange)
        {
            var center = (minRange + maxRange) / 2;
            if (list[center] < v)
            {
                minRange = center + 1;
            }
            else
            {
                maxRange = center;
            }
        }

        return minRange;
    }
}

class Solution
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(i => i).ToArray();
        var b = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(i => i).ToArray();
        var c = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(i => i).ToArray();

        long count = 0;
        var bPattern = new long[b.Length + 1];
        bPattern[b.Length] = 0;
        for (int bi = 0; bi < b.Length; bi++)
        {
            var y = b[bi];
            var cIndex = BinSearchIndex(y, c);
            bPattern[bi] = c.Length - cIndex;
        }

        var bSum = new long[b.Length + 1];
        bSum[b.Length] = 0;
        long sum = 0;
        for (int bi = b.Length - 1; bi >= 0; bi--)
        {
            sum += bPattern[bi];
            bSum[bi] = sum;
        }
        foreach (var x in a)
        {
            var bIndex = BinSearchIndex(x, b);
            count += bSum[bIndex];
        }

        Console.WriteLine(count);
    }
}

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

void fnInput(vector<int>& rvnNum)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvnNum.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnNum[i];
}

int fnPartition(vector<int>& rvnNum, int nFront, int nBack)
{
  int nMid = nFront;

  for (int i = nFront; i < nBack; i++)
    if (rvnNum[i] <= rvnNum[nBack])
      swap(rvnNum[nMid++], rvnNum[i]);

  swap(rvnNum[nMid], rvnNum[nBack]);
  return nMid;
}

void fnResult(const vector<int>& cnrvnNum, int nMid)
{
  for (int i = 0; i < cnrvnNum.size(); i++)
  {
    if (i)  cout << " ";
    if (i == nMid) cout << "[";
    cout << cnrvnNum[i];
    if (i == nMid) cout << "]";
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnNum;

  fnInput(vnNum);
  int nFront = 0;
  int nBack = vnNum.size() - 1;

  int nMid = fnPartition(vnNum, nFront, nBack);
  fnResult(vnNum, nMid);

  return 0;
}

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

int main(){
  int N,K,sum=0;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  for(int i=0;i<K;i++){
    sum+=A.at(i);
  }
  cout << sum << endl;
}
    
  
  

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007;
int main()
{
	li x,n;
	cin>>x>>n;
	if(n==0)
	{
		cout<<x;
		return 0;
	}
	li a[n],i,j;
	map<li,li>m;
	F {
	cin>>a[i];
	m[a[i]]++;
}
if(m[x]==0)
{
	cout<<x;
	return 0;
}
for(i=x-1,j=x+1;; i--,j++)
{
	if(m[i]==0)
	{
		cout<<i;
		break;
	}
	else if(m[j]==0)
	{
		cout<<j;
		break;
	}
	
}

}

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

using namespace std;

int const maxn = 1e5 + 5;
pair < int, int > a[maxn];
vector < pair < int, int > > g[maxn];
vector < int > ans;
int used[maxn];

int dfs(int v) {
    used[v] = 1;
    int child = 0;
    for (auto u : g[v]) {
        if (used[u.first] == 0) {
            if (dfs(u.first)) {
                child++;
                ans.push_back(u.second);
            }
        }
    }
    child %= 2;
    if (a[v].second != child) return 1;
    else return 0;
}

main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, l, r;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1);
    for (int i = n + 1; i >= 2; --i) a[i].second = (a[i].second^a[i - 1].second);
    for (int i = 1; i <= m; ++i) {
        cin >> l >> r;
        pair < int, int > tmp = {l, -1};
        l = lower_bound(a + 1, a + n + 1, tmp) - a;
        tmp = {r + 1, -1};
        r = lower_bound(a + 1, a + n + 1, tmp) - a;
        if (l != r) g[l].push_back({r, i}), g[r].push_back({l, i});
    }
    for (int i = 1; i <= n; ++i) {
        if (used[i] == 0) {
            if (dfs(i)) {
                cout << -1 << '\n';
                exit(0);
            }
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << '\n';
    for (auto key : ans) cout << key << " ";
    return 0;
}


Measured memory_bytes: 15100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}


const int mod = MOD9;
const int max_n = 2000050;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(max_n);

int main(){
  ll n;cin >> n;
  vl v(n);rep(i,n)cin >> v[i];
  if(v[0]!=0)cout << 0 <<endl,exit(0);
  if(n==1)cout << 1 <<endl,exit(0);
  sort(all(v));
  if(v[1]==0)cout << 0 <<endl,exit(0);
  ll now=0;
  rep(i,n){
    if(v[i]-now>1)cout << 0 <<endl,exit(0);
    if(v[i]-now==1)now++;
  }
  mint ans=1;
  mint pre=1;
  rep(i,now+1){
    int t=upper_bound(all(v),i)-lower_bound(all(v),i);
    ans*=pre.pow(t);
    pre=t;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 35208
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REPC(x,c) for(auto x:(c))
#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	VI a(n);
	REP(i, n) { cin >> a[i]; }
	sort(a.begin(),a.end());

	int min = a[0];
	int count = 0;
	REPC(x, a) {
		if (min == x) { ++count; }
		else { break; }
	}

	cout << (n - count + k-2) / (k - 1) << endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

void debug(unordered_map<int, unordered_set<int>> &m){
    for(auto isi : m){
        fprintf(stderr, "%d: ", isi.first);
        for(auto s : isi.second){
            fprintf(stderr, "%d ", s);
        }
        cerr << endl;
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    unordered_map<int, unordered_set<int>> teikibin;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        teikibin[a].insert(b);
    }
    
    for(int i = 1; i < n; i++){
        if(teikibin[1].find(i) != teikibin[i].end() && teikibin[i].find(n) != teikibin[i].end()){
            cout << "POSSIBLE\n";
            return 0;
        }
    }

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

Measured memory_bytes: 28268
#include <stack>
#include <cstdio>
using namespace std;

char s[100005];

int main() {
    stack<char> st;
    scanf("%s", s);
    int ans = 0;
    for (int i = 0; s[i]; ++i) {
        if (!st.empty() && s[i] != st.top()) {
            st.pop();
            ++ans;
        } else {
            st.push(s[i]);
        }
    }
    printf("%d\n", ans << 1);
    return 0;
}

Measured memory_bytes: 512
import copy
import sys
from bisect import bisect_left, bisect_right
from collections import ChainMap, Counter, deque, defaultdict, namedtuple
from fractions import gcd
from heapq import heappop, heappush
from itertools import accumulate
from math import ceil, floor
from operator import itemgetter

# sys.setrecursionlimit(10**6)


def main():
    n, a, b = [int(x) for x in input().split(' ')]

    ans = min(n * a, b)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n[2];
ll cnt[2][1500010];
ll h[2][1500010];

int main() {
	while (cin >> n[0] >> n[1]) {
		if (n[0] + n[1] == 0) {
			return 0;
		}
		REP(i, 2) {
			fill(cnt[i], cnt[i] + 1500010, 0);
			fill(h[i], h[i] + 1500010, 0);
		}
		REP(i, 2) {
			FOR(j, 1, n[i] + 1)cin >> h[i][j];
			REP(j, n[i])h[i][j + 1] += h[i][j];
		}
		REP(i, 2) {
			REP(j, n[i]) {
				FOR(k, j + 1, n[i] + 1) {
					cnt[i][h[i][k] - h[i][j]]++;
				}
			}
		}
		ll ans = 0;
		REP(i, 1500010) {
			ans += (cnt[0][i] * cnt[1][i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 49872
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <complex.h>
#include <fenv.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	if(n==1) n=14;
	if(m==1) m=14;
	if(n>m)
	{
		cout<<"Alice"<<endl;
		return 0;
	}else if(m>n){
		cout<<"Bob"<<endl;
		return 0;
	}
	cout<<"Draw"<<endl;
	return 0;
}


Measured memory_bytes: 256
from fractions import gcd #最大公約数
A, B, C, D = map(int, input().split())
# (0~Bのうち, C,D,C*Dの倍数ではないものの数)　- (0~-Aのうち, C,D,C*Dの倍数ではないものの数)
lcm = C * D // gcd(C, D) #C,Dの最小公倍数
x = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // lcm
y = B - B // C - B // D + B // lcm
# (0~Bの数) - {(0~BのうちCで割り切れる数) + (0~BのうちDで割り切れる数) - (0~BのうちC,Dの最小公倍数で割り切れる数)}
print(y - x)

Measured memory_bytes: 10680
#include<iostream>
#include<cstdio>

#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 40000000+2
bool pd[MAXN];
int n;
int l[10];
char a[10000];
char b[10000];
void input(){
	cin>>n;
	for(int i=0;i<n;++i){
		scanf("%s%s", a, b);
		int g=0;
		if(a[0]=='i'){
			for(int j=0;j<strlen(b);++j){
				if(b[j]=='A') g=g*4+1;
				if(b[j]=='C') g=g*4+2;
				if(b[j]=='G') g=g*4+3;
				if(b[j]=='T') g=g*4+4;
			}
			pd[g]=1;
		}
		else{
			for(int j=0;j<strlen(b);++j){
				if(b[j]=='A') g=g*4+1;
				if(b[j]=='C') g=g*4+2;
				if(b[j]=='G') g=g*4+3;
				if(b[j]=='T') g=g*4+4;
			}
			if(pd[g]==1) cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
	}
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 4512
N = input()
if N[0]>N[1]:
    print(int(N[0]*3))

elif N[0] == N[1]:
    if N[1] == N[2]:
        print(int(N[0] * 3))
    elif N[1]>N[2]:
        print(int(N[0] * 3))
    else:
        print(str(int(N[0]) + 1) * 3)

else:
    print(str(int(N[0]) + 1) * 3)

Measured memory_bytes: 3064
S = raw_input()
count = [0,0]
oe = 0
n = 0
for c in S:
	if(c =='1'):
		count[oe] += 1
	else:
		count[(oe+1)%2] += 1
	oe = (oe+1)%2
	n += 1
print(n - max(count))

Measured memory_bytes: 2820