akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;

	set<int> ST;
	int P[200000];
	rep(i, N) cin >> P[i];
	int a[200000] = {};
	rep(i, N - 1) {
		if (P[i] < P[i + 1]) a[i + 1] = 1;
	}
	rep(i, N - 1) a[i + 1] = a[i + 1] + a[i];
	int kazu = 0;
	int mae = 0;
	rep(i, N - K + 1) {
		if (a[i + K - 1] - a[i] == K - 1) {
			if (mae == 0) kazu++;
			mae = 1;
		}
		else mae = 0;
	}
	ce(kazu);


	rep(i, K) ST.insert(P[i]);

	int kotae = 1;
	rep(i, N - K) {
		ST.insert(P[i + K]);
		int tigau = 0;

		int saishou = *ST.begin();
		int saidai = *(--ST.end());

		if (saidai != P[i + K]) tigau = 1;
		if (saishou != P[i]) tigau = 1;

		ST.erase(P[i]);

		if (tigau) kotae++;
	}
	if (kazu >= 2) kotae -= kazu - 1;
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 11264
/* ex7_1.c "バイナリハックイージー"
    dada__                      */
#include<stdio.h>
#include<stdlib.h>
#define SIZE 11

typedef struct stack{
    int count;
    int size;
    char data[SIZE];
    char *top;
}stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count=0;
    stk->size=SIZE;
    stk->top=&(stk->data[SIZE]);
}
//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr,"Error: stack overflow.\n");
        exit (1);
    }
    else{
        stk->top--;
        *(stk->top)=elem;
        stk->count++;
    }
}
//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        return 0;
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return 0;
    }
}

int main(void){
    stack stk;
    char key[SIZE];
    char *read=key;
    //入力
    scanf("%s", key);
    //スタックの初期化
    initialize_stack(&stk);
    //入力の読み込み
    while(*read){
        //各文字に対してスタックを操作
        if(*read=='0'){
            push(&stk, '0');
        }
        else if(*read == '1'){
            push(&stk, '1');
        }
        else{
            pop(&stk);
        }
        read++;
    }
    //結果の出力
    for(int i=0; i<stk.count; i++){
        printf("%c", stk.data[SIZE-1-i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1640
#include<stdio.h>
#include<string.h>

#define LEN 100000

typedef struct pp {
	char name[100];
	int t;
} P;

P Q[ LEN+1 ];
int head, tail, n;

void enqueue( P x )
{
	Q[ tail++ ] = x;
	if( LEN < tail ) {
		tail = 0;
	}
}

P dequeue( )
{
	if( tail == head || LEN < head ) { 
		head = 0;
	}
	return Q[ head++ ];
}

int main( int argc, char *argv[] ) 
{
	int elaps = 0;
	int i, q;
	P u;
	
	scanf( "%d%d", &n, &q );
	for ( i=0; i<n; i++ ) {
		scanf( "%s%d", Q[i].name, &Q[i].t );
	}

	head = 0;
	tail = n;	
	while( head != tail ) {
		u = dequeue( );
		if( u.t <= q ) {
			elaps += u.t;
			printf( "%s %d\n", u.name, elaps );
		} else {
			u.t -= q;
			enqueue( u );
			elaps += q;
		}
	}	
   
    return 0;
}

Measured memory_bytes: 10756
S = input()
while len(S) > 0:
    if S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    else:
        break
if len(S) == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}


//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var a = one[0];
	var b = one[1];
	var x = one[2];
	var pi2 = Math.PI * 2;
	if(b * a * a / 2 <= x){
		var soko = a;
		var nokoriS = b * a - (x / a);
		var tate = nokoriS / a * 2;
		var naname = Math.sqrt(soko*soko+tate*tate);
		myerr({naname, b,soko});
		myerr(soko / naname);
		var kakudo = Math.acos(soko / naname) * 180 / Math.PI;
		myout(kakudo);
	}else{
		x /= a;
		var soko = x / b * 2;
		var naname = Math.sqrt(soko*soko+b*b);
		myerr({naname, b,soko});
		myerr(soko / naname);
		var kakudo = Math.acos(soko / naname) * 180 / Math.PI;
		myout(kakudo);
	}
}


Measured memory_bytes: 30608
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, T, U, V, L, x;
int main() {
	cin >> N >> K >> T >> U >> V >> L;
	vector<bool> v(L);
	for (int i = 0; i < N; i++) cin >> x, v[x] = true;
	double ret = 0.0, car = 0.0;
	for (int i = 0; i < L; i++) {
		if (v[i]) car = min(car + 1.0, 1.0 * K + 1);
		if (car > 1.0e-8) ret += 1.0 / V, car -= 1.0 / (V * T);
		else ret += 1.0 / U;
	}
	cout << fixed << setprecision(15) << ret << endl;
	return 0;
}

Measured memory_bytes: 3252
#include<iostream>

using namespace std;
int main()
{
	int a[7] = {};
	int b[7] = {};
	for (int i = 0; i < 7; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < 7; i++) {
		cout << a[i] - b[i] << endl;
	}

	return 0;
	
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    double T, X;
    cin >> T >> X;
    fcout << T / X << endl;
}


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

int main() {
	int a,b,c;
	
	cin>>a>>b>>c;
	
	if(a==1 && b==0 && c==0){
		cout<<"Close"<<endl;
	}
	if(a==0 && b==1 && c==0){
		cout<<"Close"<<endl;
	}
	if(a==1 && b==1 && c==0){
		cout<<"Open"<<endl;
	}
	if(a==0 && b==0 && c==1){
		cout<<"Open"<<endl;
	}if(a==0 && b==0 && c==0){
		cout<<"Close"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3080
import math

K = int(input())

sum = 0

for a in range(1,K + 1):
    sum += a
    #print(a, a)
    for b in range(a + 1,K + 1):
        gcd2_sum = math.gcd(a, b) * 3 * 2
        sum += gcd2_sum
        #print(a, b, gcd2_sum)
        for c in range(b + 1, K + 1):
            gcd3_sum = math.gcd(math.gcd(a, b), c) *  6
            sum += gcd3_sum
            #print(a, b, c, gcd3_sum)
print(sum)


Measured memory_bytes: 9160
import java.util.*;
public class Main {
	static long M = 1000000007;
	public static void main(String[] args) {
		for(int i = 0; i < 200001; i++) fac(i);
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int k = seer.nextInt();
		//todos contra todos
		long[] calc = new long[n];
		for(int i = 1; i < m; i++){
			calc[0] = sum(calc[0], mult(i, m-i));
		}
		for(int i = 1; i < n; i++){
			calc[i] = sum(calc[i-1], mult(calc[0], 2), mult(m, m, i));
		}
		long tot = 0;
		for(long c: calc) tot = sum(tot, c);
		
		System.out.println(mult(tot, comb(n*m-2, k-2)));
	}
	static long[] fac = new long[200001];
	static long[] invfac = new long[200001];
	static long fac(int n){
		if(n == 0) return fac[0] = 1;
		else if(fac[n] > 0) return fac[n];
		else return fac[n] = mult(n, fac(n-1));
	}
	static long invfac(int n){
		if(invfac[n] > 0) return invfac[n];
		else return invfac[n] = inv(fac[n]);
	}
	static long inv(long a){
		return (gcdex(a, M).r + M) % M;
	}
	static Pair gcdex(long a, long b){
		if(b > a) return gcdex(b, a).invert();
		else if(b == 0) return new Pair(1, 0);
		else{
			Pair p = gcdex(b, a%b); //p.r * b + p.s * (a - b(a/b)) = 1
			return new Pair(p.s, p.r - p.s*(a/b));
		}
	}
	static class Pair{
		long r, s;
		public Pair(long r, long s){
			this.r = r; this.s = s;
		}
		public Pair invert(){
			return new Pair(s, r);
		}
	}
	static long comb(int n, int k){
		return mult(fac(n), invfac(k), invfac(n-k));
	}
	static long mult(long... ls){
		long res = 1;
		for(long a: ls){
			res = (res * a) % M;
		}
		return res;
	}
	static long sum(long... ls){
		long res = 0;
		for(long a: ls){
			res = (res + a) % M;
		}
		return res;
	}
}


Measured memory_bytes: 44244
#
# File    : C.rb
# Author  : Kazune Takahashi
# Created : 12/6/2018, 11:10:15 PM
# Powered by Visual Studio Code
#

n, x = gets.chomp.split(" ").map{|i| i.to_i}
a = gets.chomp.split(" ").map{|i| i.to_i}
ans = 0
if a[0] > x
  ans = a[0] - x
  a[0] = x
end
for i in 1...n
  t = a[i-1] + a[i] - x
  if t > 0
    ans += t
    a[i] -= t
  end
end

puts ans


Measured memory_bytes: 9604
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  bool ans = true;
  rep(i,s.size()) {
    if (i%2==0) {
      if (s[i] != 'h') {
        ans = false;
        break;
      }
    } else {
      if (s[i] != 'i') {
        ans = false;
        break;
      }
    }
  }
  if(s.size()==0 || s.size()%2 !=0) ans = false;
  cout << (ans ? "Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int x,y;
  cin>>x>>y;
  if(x==0&&y>=0){
  	cout<<abs(y)<<endl;
  	return 0;
  }else if(x==0&&y<0){
  	cout<<abs(y)+1<<endl;
  	return 0;
  }
  int ans;
  if(x>0&&y>0){
  	int a=abs(x),b=abs(y);
  	if(x>y){
  		ans=2+abs(a-b);
  	}else{
  		ans=abs(a-b);
  	}
  }else if(x<=0&&y<=0){
  	int a=abs(x),b=abs(y);
  	if(x>y){
  		ans=2+abs(a-b);
  	}else{
  		ans=abs(a-b);
  	}
  }else if(x>=0&&y<=0){
  	int a=abs(x),b=abs(y);
  	if(a<b){
  		ans=1+abs(a-b);
  	}else{	
  		ans=1+abs(a-b);
  	}
  }else if(x<=0&&y>=0){
  	int a=abs(x),b=abs(y);
  	if(a<b){
  		ans=1+abs(y-a);
  	}else{	
  		ans=1+abs(a-b);
  	}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  int table[7][7] = {{ 0,300,500,600,700,1350,1650}
                     ,{6,0,350,450,600,1150,1500}
                     ,{13,7,0,250,400,1000,1350}
                     ,{18,12,5,0,250,850,1300}
                     ,{23,17,10,5,0,600,1150}
                     ,{43,37,30,25,20,0,500}
                     ,{58,52,45,40,35,15,0}};
  int ss = 17*60+30;
  int tt = 19*60+30;
  int s, sh, sm, t, th, tm;
  while(cin >> s, s) {
    cin >> sh >> sm >> t >> th >> tm;
    s--;t--;
    if (s>t) swap(s,t);
    int ans = table[s][t];

    int sss = sh*60+sm;
    int ttt = th*60+tm;
    if (table[t][s] <= 40) {
      if (ss<=sss&&sss<=tt || ss<=ttt&&ttt<=tt) {
        ans /= 2;
        ans = (ans + 49) / 50 * 50;
      }
    }
    cout << ans << endl;
  }
}

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

int main()
{
    string a, b;
    cin >> a >> b;
    int ans = stoi(a + b);
    for (int i = 1; i <= 1000; i++)
    {
        if (i * i == ans)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

int main() {
  std::cout << std::setprecision(9);
  long n;
  cin >> n;

  string ans = "";
  while (true) {
    char c = int_to_char(n % 26 - 1);
    ans = c + ans;
    if (n % 26 == 0) {
      n -= 26;
    }
    else {
      n -= n % 26;
    }
    n /= 26;
    if (n == 0) {
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cmath>

using namespace std;
typedef unsigned long long ullong;

ullong power(ullong x, ullong n, ullong M){
    ullong res = 1;
    if(n > 0){
        res = power(x, n/2, M);
        if(n%2 == 0) res = (res * res) % M;
        else res = (((res * res)%M)*x)%M;
    }
    return res;
}

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

    cout << power(m, n, 1000000007) << endl;

    return 0;
}


Measured memory_bytes: 3120
#!/usr/bin/python
# -*- coding: utf-8 -*-

# def
def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(map(int,input().split())))
    return np.array(x)

def str_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return np.array(x)

def int_map():
    return map(int,input().split())

def int_list():
    return list(map(int,input().split()))

def print_space(l):
    return print(" ".join([str(x) for x in l]))

# import
import numpy as np
import collections as col

# main

X = int(input())

if X <=2:
    print(0)
    exit()
elif 3<= X and X <=5:
    print(1)
    exit()
else:
    A = [[x for x in range(1,X-4)]]
    i = 0
    while X-(6+3*(i+1)) >= 0:
        A.append([1])
        for j in range(0,X-(6+3*(i+1))):
            A[i+1].append(A[i+1][j]+A[i][j+1])
        i = i+1
    
    ans = 1

    for a in A:
        ans += a[-1]
    
    print(ans%(10**9+7))





Measured memory_bytes: 102156
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int n;
  int ans = 0;
  string s;

  cin >> n;

  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  for(int i = 1; i < n-1; i++){
    if((p[i-1] < p[i] && p[i] < p[i+1])
       || (p[i-1] > p[i] && p[i] > p[i+1])){
      ans++;
      //      cout << "..." << p[i-1] << ", " << p[i] << ", " << p[i+1] << endl;
    }
  }
  cout << ans << endl;
}


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

int abs(int a, int b)
{
  if (a-b > 0) {
    return a-b;
  } else {
    return b-a;
  }
}

int main(void)
{

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

  unsigned long long cnt = 0;
  long long sum = 0;

  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      if (a[i] > 0) {
        sum += a[i];
      } else {
        cnt += abs(sum+a[i], 1);
        sum = 1;
      }
      continue;
    }
    if ((sum > 0 && sum+a[i] > 0) || (sum < 0 && sum+a[i] < 0) || (sum+a[i] == 0)) {
      if (sum > 0) {
        cnt += abs(sum+a[i], -1);
        sum = -1;
      } else {
        cnt += abs(sum+a[i], 1);
        sum = 1;
      }
    } else {
      sum += a[i];
    }
  }

  unsigned long long max_cnt = cnt;
  cnt = 0; sum = 0;
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      if (a[i] < 0) {
        sum += a[i];
      } else {
        cnt += abs(sum+a[i], -1);
        sum = -1;
      }
      continue;
    }
    if ((sum > 0 && sum+a[i] > 0) || (sum < 0 && sum+a[i] < 0) || (sum+a[i] == 0)) {
      if (sum > 0) {
        cnt += abs(sum+a[i], -1);
        sum = -1;
      } else {
        cnt += abs(sum+a[i], 1);
        sum = 1;
      }
    } else {
      sum += a[i];
    }
  }
  if (cnt < max_cnt) {
    max_cnt = cnt;
  }
  cout << max_cnt << endl;
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    cout << (k%2 ? b-a : a-b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#define int long long
using namespace std;
int N, M;
map<int, int>t;
map<int, int>p;
char arr[200100];
string st[200100];
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N;
	int a, b, c;
	cin >> a >> b >> c;
	int i;
	for (i = 0; i < N; i++)
	{
		cin >> st[i];
	}
	for (i = 0; i < N; i++)
	{
		if (st[i] == "AB")
		{
			if (a == 0 && b == 0)
			{
				cout << "No";
				return 0;
			}
			if (a == 1 && b == 1)
			{
				if (st[i + 1] == "AC")
				{
					arr[i] = 'A';
					a++;
					b--;
				}
				else
				{
					arr[i] = 'B';
					b++;
					a--;
				}
			}
			else
			{
				arr[i] = a > b ? 'B' : 'A';
				if (a <= b)
				{
					a++;
					b--;
				}
				else
				{
					a--;
					b++;
				}
			}
		}
		else if (st[i] == "AC")
			{
			if (a == 0 && c == 0)
			{
				cout << "No";
				return 0;
			}
			if (a == 1 && c == 1)
			{
				if (st[i + 1] == "AB")
				{
					arr[i] = 'A';
					a++;
					c--;
				}
				else
				{
					arr[i] = 'C';
					c++;
					a--;
				}
			}
			else
			{
				arr[i] = a > c ? 'C' : 'A';
				if (a <= c)
				{
					a++;
					c--;
				}
				else
				{
					a--;
					c++;
				}
			}
			}
		else
		{
			if (c == 0 && b == 0)
			{
				cout << "No";
				return 0;
			}
			if (c == 1 && b == 1)
			{
				if (st[i + 1] == "AC")
				{
					arr[i] = 'C';
					c++;
					b--;
				}
				else
				{
					arr[i] = 'B';
					b++;
					c--;
				}
			}
			else
			{
				arr[i] = c > b ? 'B' : 'C';
				if (c <= b)
				{
					c++;
					b--;
				}
				else
				{
					c--;
					b++;
				}
			}
		}
	}
	cout << "Yes" << '\n';
	for (i = 0; i < N; i++)
	{
		cout << arr[i] << '\n';
	}
}

Measured memory_bytes: 10016
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

using namespace std;



long long solve(long long d,long long k1,long long k2,bool p){
	if(k2==k1){
		if(d==0)return 10;
		else return 0;
	}
	if(k2>k1){
		if(d==0)return 1;
		else return 0;
	}
	if(d==0){
		return 10*solve(d,k1/10,k2*10,1);
	}
	if(d<0){
		return 0;
	}
	long long ans=0;
	long long a;
	long long x,y;
	x=0,y=0;
	a = d/(k1-k2);
	if(a>=10){
		return 0;
	}
	if(d%(k1-k2)==0){
		if(p==0){
			return(9-a)*solve(0,k1/10,k2*10,1);
		}
		return (10-a)*solve(0,k1/10,k2*10,1);
	}else{
		if(p==0){
			x = (9-a)*solve(d-a*(k1-k2),k1/10,k2*10,1);
			if(a<9){
				y = (9-a-1)*solve((a+1)*(k1-k2)-d,k1/10,k2*10,1);
			}
		}else{
			x = (10-a)*solve(d-a*(k1-k2),k1/10,k2*10,1);
			y = (10-a-1)*solve((a+1)*(k1-k2)-d,k1/10,k2*10,1);
		}
	}
	return x+y;
}




int main(){
	long long d;
	cin >> d;
	int dig=0;
	int t =d;
	long long dv = 9;
	for(int i=0;i<10;i++){
		if(t/dv>0){
			dig +=1;
			dv = dv*10+9;
		}else{
			break;
		}
	}
	long long  k1 = (dv+1)/10;
	long long k2 = 1;
	long long ans =0;
	for(int i=0;i<10;i++){
		ans += solve(d,k1,k2,0);
		k1 *= 10;
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long 
#define mod 1000000007

using namespace std;

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

	vector<ll> dp(S+1, 0);

	for(ll i=3; i<=S; i++){
		dp[i] = 1;
		for(int j = 3; j<=(i-3); j++){
			// if(j!=(i-j)){
				dp[i] = (dp[i] + dp[i-j])%mod;
				// cout<<dp[i]<<endl;
			// }
			// else{
			// 	dp[i]+=dp[i-j];
			// }
		}
	}

	cout<<dp[S];

	return 0;
}

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

class Main {

	static int count = 0;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String line = br.readLine();
		String[] str = line.split(" ");
		int[] a = new int[n];

		for (int i=0; i<n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		margeSort(a,0,n);

		StringBuilder sb = new StringBuilder();
		sb.append(a[0]);
		for (int i=1; i<n; i++) {
			sb.append(" ").append(a[i]);
		}
		System.out.println(sb);
		System.out.println(count);

		br.close();
	}

	static void marge(int[] a,int left,int mid,int right){
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1+1];
		int[] R = new int[n2+1];
		for (int i=0; i<n1; i++) {
			L[i] = a[left+i];
		}
		for (int i=0; i<n2; i++) {
			R[i] = a[mid+i];
		}
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		int i = 0;
		int j = 0;
		for (int k=left; k<right; k++) {
			count++;
			if (L[i] <= R[j]) {
				a[k] = L[i];
				i++;
			}else {
				a[k] = R[j];
				j++;
			}
		}
	}

	static void margeSort(int[] a,int left,int right){
		if (left+1 < right) {
			int mid = (left+right)/2;
			margeSort(a,left,mid);
			margeSort(a,mid,right);
			marge(a,left,mid,right);
		}
	}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main(){
	llong N, K;
	cin >> N >> K;

	llong ans = 1;

	cout << N-K+1 << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int n = sc.nextInt();
    String[] s = new String[n];

    for(int i = 0; i < n; i++){
      String city = sc.next();
      int point = sc.nextInt();
      int num = i + 1;
      s[i] = city + " " + 1 / (double)point + " " + num;
    }

    Arrays.sort(s);

    for(int i = 0; i < n; i++){
      String ans = s[i].split(" ")[2];
      System.out.println(ans);
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int W, H, n;

int compress(vector<int> &x1, vector<int> &x2, int w) {
	vector<int> xs;

	rep(i, n) {
		for(int d = -1; d <= 1; d++) {
			int tx1 = x1[i] + d, tx2 = x2[i] + d;
			if(1 <= tx1 && tx1 < w) xs.push_back(tx1);
			if(1 <= tx2 && tx2 < w) xs.push_back(tx2);
		}
	}

	xs.push_back(0);
	xs.push_back(w-1);

	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());

	rep(i, n) {
		x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
		x2[i] = lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin();
	}

	return xs.size();
}

bool used[1000 * 6 + 5][1000 * 6 + 5];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool can(int y,int x) {
	if(0 <= y && y < H && 0 <= x && x < W) return true;
	return false;
}

int main() {

	while(cin >> W >> H) {
		if(W == 0 && H == 0) break;
		cin >> n;

		vector<int> x1(n), x2(n), y1(n), y2(n);
		rep(i, n) {
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		}

		W = compress(x1, x2, W);
		H = compress(y1, y2, H);

		memset(used, 0, sizeof(used));
		rep(i, n) {
			REP(y, y1[i], y2[i]) {
				REP(x, x1[i], x2[i]) {
					used[y][x] = true;
				}
			}
		}

		int ans = 0;
		rep(i, H) {
			rep(j, W) {
				if(used[i][j]) continue;
				ans++;

				queue<P> que;
				que.push(mp(i, j));
				used[i][j] = true;

				while(que.size()) {
					P p = que.front();
					que.pop();

					rep(k, 4) {
						int ny = p.first + dy[k];
						int nx = p.second + dx[k];

						if(can(ny, nx) && !used[ny][nx]) {
							used[ny][nx] = true;
							que.push(mp(ny, nx));
						}
					}
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

bool f(char x) {
  if (x == 'A' || x == 'T' || x == 'C' || x == 'G') return 1;
  return 0;
}

int main2() {
  string s; cin >> s;

  int ans = 0;
  int len = 0;
  REP(i, s.size()) {
    if (f(s[i])) {
      len++;
    } else {
      chmax(ans, len);
      len = 0;
    }
  }
  chmax(ans, len);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    int a,b,c,x;
    int ans = 0;
    cin >> a >> b >> c >> x;

    irep2(i,0,a+1) {
        irep2(j,0,b+1) {
            irep2(k,0,c+1) {
                if(i == 0 && j == 0 && k == 0) { continue; }
                if((500*i+100*j+50*k) == x) { ans++; }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
    



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#define ARMAX 200000
double calcDistance(int a,int b);
int main(){
  int n,d;//入力
  int x[ARMAX],y[ARMAX];//座標群
  int i;//制御変数
  int cnt=0;//カウント
  scanf("%d %d",&n,&d);
  for(i=0;i<n;i++){
    scanf("%d %d",&x[i],&y[i]);
  }
  //処理//////////////////////////////////////////////////////////
  for(i=0;i<n;i++){
    if(calcDistance(x[i],y[i])<=double(d)){
      
      cnt++;
    }
    else{
      //printf("%d %d : %lf\n",x[i],y[i],calcDistance(x[i],y[i]));
    }
    
  }
  printf("%d",cnt);
  return 0;
}
  
double calcDistance(int x,int y){
  return sqrt(pow(x,2)+pow(y,2));
}


//テスト用
/*
printf("N=%d D=%d\n",n,d);
  for(i=0;i<n;i++){
    printf("%d %d\n",x[i],y[i]);
  }
*/

Measured memory_bytes: 5340
#include<stdio.h>

int main(){

int n,i,max,min;

int R[200000];
 
 

     scanf("%d",&n);

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

    scanf("%d",&R[i]);

}

   max = R[1]-R[0];
 
   min = R[0];

   for(i = 1; i < n; i++){

      if(max < R[i]-min){

       max = R[i]-min;

 }

   if(min > R[i]){

    min = R[i];

  }

}

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

    return 0;

}

Measured memory_bytes: 2564
#include<bits/stdc++.h>
#define MSET(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535 


int main() {
  fastio;
  ll n;
  cin>>n;
  ll ans = INF;
  for(ll i=1;i<=sqrt(n);i++) {
    if(n%i == 0) {
      ans = min(ans, n/i + i - 2);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
graph=[[] for _ in range(N)]
for _ in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

for i in range(N):
    print(len(graph[i]))

Measured memory_bytes: 3060
#include <stdio.h>

const int Mod = 1000000007;

int main()
{
	int N;
	scanf("%d", &N);
	if (N == 1) {
		printf("0\n");
		fflush(stdout);
		return 0;
	}
	
	int i;
	long long pow[3][1000001];
	for (i = 1, pow[0][0] = 1, pow[1][0] = 1, pow[2][0] = 1; i <= N; i++) {
		pow[0][i] = pow[0][i-1] * 10 % Mod;
		pow[1][i] = pow[1][i-1] * 9 % Mod;
		pow[2][i] = pow[2][i-1] * 8 % Mod;
	}		
	
	printf("%lld\n", (pow[0][N] - pow[1][N] * 2 + pow[2][N] + Mod * 2) % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 25168
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        arr: [isize; n],
    }

    let mut x = 0;
    for (i, a) in arr.iter().enumerate() {
        let pa = if i%2==0 { 1 } else { -1 };
        x += pa * a;
    }

    print!("{} ", x);
    for i in 0..n-1 {
        x = -x + 2 * arr[i];
        print!("{} ", x);
    }
}


Measured memory_bytes: 3928
n = int(input())
a = list(map(int ,input().split()))
cnt = 0
for i in range(1, n-1):
  hoge = [a[i-1], a[i], a[i+1]]
  if(max(hoge) != a[i] and min(hoge) != a[i]):
     cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

int main()
{
	long long int n, m;
	cin >> n >> m;
	long long int a[100001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i] %= m;
	}
	long long int sum = 0;
	map<long long int, long long int> cnt;
	long long int ans = 0;
	for(int i = 0; i < n; i++){
		sum += a[i];
		sum %= m;
		if(sum == 0) ans++;
		// cout << m << " " << sum << endl;
		if(cnt.find(sum % m) != cnt.end()) ans += cnt[sum % m];
		// cout << a[i] << " " << ans << endl;
		if(cnt.find(sum) != cnt.end()) cnt[sum]++;
		else cnt[sum] = 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define inf (long long)1e9
using namespace std;

long long n, t;
vector<long long> sum;

long long solve();

int main() {
  cin >> n >> t;
  sum.assign(t + 1, 0);
  for(int i = 0; i < n; ++i) {
    long long l, r;
    cin >> l >> r;
    ++sum[l];
    --sum[r];
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i <= t; ++i) {
    if(i != 0) sum[i] += sum[i - 1];
    ans = max(ans, sum[i]);
  }
  return ans;
}


Measured memory_bytes: 3620
#!/usr/bin/env python3
n, m = map(int, input().split())
penalty = 0
ac = [0] * n
wa = [0] * n
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "AC":
        if ac[p] == 0:
            penalty += wa[p]
        ac[p] += 1
    else:
        wa[p] += 1
print(sum(x > 0 for x in ac), penalty)

Measured memory_bytes: 4596
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define For(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define sz(x) ((int)(x).size())
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef long long ll;
typedef unsigned long long ull;

const int N = 2222;

vi e[N],st;
int in_stack[N], visited[N];
int n,m;

bool check(vector<int> &ret) {
  set<int> S(ret.begin(),ret.end());
  for(auto &u: ret) {
    int cnt = 0;
    for(int &x: e[u]) {
      if(S.count(x)) cnt++;
    }
    if(cnt>1) return false;
  }
  return true;
}

bool dfs(int u) {
  if(visited[u]) {
    if(in_stack[u]) {
      vi ret;
      for(int k=sz(st)-1;st[k]!=u;k--) {
        ret.pb(st[k]);
      }
      ret.pb(u);
      reverse(all(ret));
      if(check(ret)) {
        cout<<sz(ret)<<"\n";
        for(int &i: ret) {
          cout<<i+1<<'\n';
        }
        cout<<endl;
        return true;
      }
      return false;
    }
    return false;
  }
  visited[u] = true;
  in_stack[u] = true;
  st.pb(u);
  for(int &v: e[u]) {
    if(dfs(v)) return true;
  }
  in_stack[u] = false;
  st.pop_back();
  return false;
}

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

  cin>>n>>m;
  rep(i,m) {
    int u,v; cin>>u>>v;
    u--,v--;
    e[u].pb(v);
  }
  bool found = false;
  rep(i,n) {
    if(dfs(i)) {
      found = true;
      break;
    }
  }
  if(!found) puts("-1");
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

#define ALL(v) begin(v),end(v)
typedef pair<int,int> pii;

int solve(){
	ios::sync_with_stdio(false);
	
	int h, w, k, r1, c1, r2, c2;
	cin >> h >> w >> k >> r1 >> c1 >> r2 >> c2;
	vector<vector<int>> vis(h + 2, vector<int>(w + 2, 15));
	for(int i = 0; i < h; ++i){
		string s;
		cin >> s;
		for(int j = 0; j < w; ++j){
			if(s[j] == '.'){ vis[i + 1][j + 1] = 0; }
		}
	}
	vector<pii> curr, nxt;
	auto process = [&](int dy, int dx, int f){
		for(const auto &p : curr){
			for(int i = 1; i <= k; ++i){
				int y = p.first + dy * i;
				int x = p.second + dx * i;
				if(vis[y][x] & f){ break; }
				vis[y][x] |= f;
				nxt.emplace_back(y, x);
			}
		}
	};
	nxt.emplace_back(r1, c1);
	for(int tm = 0; !nxt.empty(); ++tm){
		curr.swap(nxt);
		nxt.clear();
		sort(ALL(curr));
		curr.erase(unique(ALL(curr)), curr.end());
		for(const auto &p : curr){
			if(p.first == r2 && p.second == c2){
				return tm;
			}
			vis[p.first][p.second] = 15;
		}
		process(-1, 0, 1);
		reverse(ALL(curr));
		process(1, 0, 2);
		sort(ALL(curr), [](const pii &p, const pii &q){ return p.second < q.second; });
		process(0, -1, 4);
		reverse(ALL(curr));
		process(0, 1, 8);
	}
	return -1;
}

int main(){
	cout << solve() << '\n';
}


Measured memory_bytes: 18796
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    string s;
    cin >> s;
    ll ans=0,c=0;
    for (ll i=0;i<s.size();i++){
        if (s[i]=='S')c++;
        else{
            if(c==0)ans++;
            else c--;
        }
    }
    ans+=c;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1336
# -*- coding: utf-8 -*-

"""
ちょっと編集
・残り調べるとこ、ビットシフトにしてみた。この方が前からいけるしいいかな。
"""

L = int(input())

# 2べきで表せる基本部分を作る
edges = []
# baseは基本部分の守備範囲
v = base = 1
while base * 2 <= L:
    edges.append([v, v+1, 0])
    edges.append([v, v+1, base])
    base *= 2
    v += 1
# ゴールの頂点
end = edges[-1][1]
# 残りがいくつか
rest = L - base
# 残りを2べきに分割
for i in range(19):
    if rest >> i & 1:
        num = 2 ** i
        # ちょうどいい位置(ここより手前で2**iまでを網羅)にバイパスを作る感じ
        edges.append([i+1, end, L-rest])
        rest -= num
print(v, len(edges))
for i in range(len(edges)):
    print(*edges[i])


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
#include <string>
#include <queue>
using namespace std;
typedef long long int ll;

int h,w,kk;
char fi[15][1010];

int cnt[15][1010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> kk;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> fi[i][j];
            if(fi[i][j]=='1'){
                cnt[i+1][j+1]=cnt[i+1][j]+1;
            }else{
                cnt[i+1][j+1]=cnt[i+1][j];
            }
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cnt[i][j]+=cnt[i-1][j];
        }
    }
    int ans=1e9;
    for(int i=0;i<(1<<(h-1));i++){
        int res=__builtin_popcount(i);
        int p=1;
        for(int k=1;k<=w;k++){
            int l=1;
            for(int j=0;j<h-1;j++){
                if((1<<j)&i){
                    if(cnt[j+1][k]+cnt[l-1][k-1]-cnt[j+1][k-1]-cnt[l-1][k]>kk){
                        res=1e8;
                        break;
                    }
                    if(cnt[j+1][k]+cnt[l-1][p-1]-cnt[j+1][p-1]-cnt[l-1][k]>kk){
                        if(p!=k)res++;
                        p=k;
                    }
                    l=j+2;
                }
            }
            if(cnt[h][k]+cnt[l-1][k-1]-cnt[h][k-1]-cnt[l-1][k]>kk){
                res=1e8;
                break;
            }
            if(cnt[h][k]+cnt[l-1][p-1]-cnt[h][p-1]-cnt[l-1][k]>kk){
               if(p!=k) res++;
               p=k;
            }
        }
        /*for(int j=0;j<h-1;j++){
            if((1<<j)&i){
                for(int k=1;k<=w;k++){
                    if(cnt[j+1][k]+cnt[l-1][p-1]-cnt[j+1][p-1]-cnt[l-1][k]>kk){
                        res++;
                        if(p==k){
                            res=1e8;
                            break;
                        }
                        p=k;
                        if(cnt[j+1][k]+cnt[l-1][p-1]-cnt[j+1][p-1]-cnt[l-1][k]>kk){
                            res=1e8;
                            break;
                        }
                    }
                }
                l=j+2;
                p=1;
            }
        }
        for(int k=1;k<=w;k++){
            if(cnt[h][k]+cnt[l-1][p-1]-cnt[h][p-1]-cnt[l-1][k]>kk){
                res++;
                if(p==k){
                    res=1e8;
                    break;
                }
                p=k-1;
            }
        }*/
        ans=min(ans,res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int N,R; cin>>N>>R;
    if(N>=10) cout<<R<<endl;
    else cout<<R+100*(10-N)<<endl;
    return 0;
}


Measured memory_bytes: 256
S = input()

nums = []
for s in S:
    nums.append(int(s))

count = 0
i = 0
while i < len(nums)-1:
    if nums[i] != nums[i+1]:
        nums.pop(i+1)
        nums.pop(i)
        count += 1
        if i != 0:
            i -= 1
        continue
    i += 1

print(count*2)


Measured memory_bytes: 3964
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;   int n, ans = 0, a = 0, b = 0, ab = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        int l = s.length();
        if (s[0] == 'B' && s[l-1] == 'A')
            ab++;
        else if (s[0] == 'B')
            b++;
        else if (s[l-1] == 'A')
            a++;

        for (int j = 0; j < l-1; j++) {
            if (s[j] == 'A' && s[j+1] == 'B')
                ans++;
        }
    }

    if (a > 0) {
        cout << ans + ab + min(a, b) << endl;
        return 0;
    }
    else if (ab > 0){
        cout << ans + ab-1 + ((b > 0)?1:0) << endl;
        return 0;
    }
    else {
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 3636
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin,stdout
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math
import math
import time
from queue import Queue
# PradeepGhosh_2017076

def seive(n):
	l=[True]
	l=l*(n+1)
	for i in range(2,int(sqrt(n))+1):
		if(l[i]==True):
			val=i*i
			while(val<len(l)):
				l[val]=False
				val+=i
	prime=[]
	for i in range(2,len(l)):
		if(l[i]==True):
			prime.append(i)
	return prime

def dp(l,i,n,val,ans):
	if(i>=n or val<0):
		return 1000000
	elif(val==0):
		return 0
	else:
		if(ans[i]==1000000):
			ans[i]=min(min(1+dp(l,i+1,n,val-l[i],ans),1+dp(l,i,n,val-l[i],ans)),dp(l,i+1,n,val,ans))
		return ans[i]
from queue import Queue
def factors(n):
	l=[]
	for i in range(1,int(sqrt(n))+1):
		if(n%i==0):
			if(n//i==i):
				l.append(i)
			else:
				l.append(i)
				l.append(n//i)
	return l
def check1(s,v,x):
	while(True):
		if(v not in s):
			return v
		else:
			v-=1
def check2(s,v,x):
	while(True):
		if(v not in s):
			return v
		else:
			v+=1

def up(n):
	j=n-1
	while(j>0):
		if(n%j==0):
			break
		j-=1
	return j		
def fac(n):
	c=1
	i=1
	while(i<=n):
		c*=i
		i+=1
	return c
def check_happy(n):
	ss=set()
	print(n)
	while(n!=1):
		val=n
		s=0
		print(val)
		while(val!=0):
			s+=(val%10)**2
			val=val//10
		print(val)
		print("hi")
		if(val in ss):
			return False
		else:
			n=val
			ss.add(n)
	return True
if __name__ == '__main__':
	n=int(input())
	print(1000*(int(math.ceil(n/1000)))-n)

Measured memory_bytes: 10668
#include <deque>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;

map<pair<int, int>, int> memo;
int parent[300005][2];

int find(int x, int i)
{
	if (parent[x][i] != x)
		parent[x][i] = find(parent[x][i], i);
	return parent[x][i];
}

void merge(int x, int y, int i)
{
	x = find(x, i);
	y = find(y, i);
	if (x != y)parent[x][i] = y;
}

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N, K, L;
	cin >> N >> K >> L;
	for (int i = 1; i <= N; i++) {
		parent[i][0] = i;
		parent[i][1] = i;
	}
	while (K--)
	{
		int u, v;
		cin >> u >> v;
		merge(u, v, 0);
	}
	while (L--)
	{
		int u, v;
		cin >> u >> v;
		merge(u, v, 1);
	}
	for (int i = 1; i <= N; i++)
		memo[{find(i, 0), find(i, 1)}]++;
	for (int i = 1; i <= N; i++)
		cout << memo[{find(i, 0), find(i, 1)}] << ' ';
}

Measured memory_bytes: 13568
N = int(input())
X = list(map(int,input().split()))
X.sort()
min_pw = 10**30

for i in range(min(X),max(X)+1):
    sum_pw = 0
    for x in X:
        sum_pw += (i-x)**2
    if sum_pw < min_pw:
        min_pw = sum_pw

print(min_pw)

Measured memory_bytes: 3064