akhauriyash/Code-Regression huggingface dataset:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

command = []

plus_max = max(As)
minus_min = min(As)
if abs(plus_max)>=abs(minus_min):
    maxi_idx = As.index(plus_max)
    for i in range(N):
        a = As[i]
        if a<0:
            As[i] += plus_max
            command.append((i, maxi_idx))
    for i in range(N-1):
        a = As[i]
        b = As[i+1]
        if a>=0 and a>b:
            command.append((i+1, i))
            As[i+1] += As[i]
else:
    mini_idx = As.index(minus_min)
    for i in range(N):
        a = As[i]
        if a>0:
            As[i] += minus_min
            command.append((i, mini_idx))
    for i in range(N-1, 0, -1):
        a = As[i]
        b = As[i-1]
        if a<0 and b>a:
            command.append((i-1, i))
            As[i-1] += As[i]
print(len(command))
for x, y in command:
    print(y+1, x+1)

Measured memory_bytes: 62272
inp = list(map(int, input().split()))

A = inp[0]
B = inp[1] + 1
ans = 0
for i in range(A, B):

  if str(i)[0:1] == str(i)[4:] :
    if str(i)[1:2] == str(i)[3:4] :
      ans += 1

print (ans)


Measured memory_bytes: 2940
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

s = input()
if s[len(s)-1] == 's':
    print(s+'es')
else:
    print(s+'s')

Measured memory_bytes: 9124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	string str;
	map<char, string> tbl;
	
	  tbl[' '] = "101";
	  tbl['\''] = "000000";
	  tbl[','] = "000011";
	  tbl['-'] = "10010001";
	  tbl['.'] = "010001";
	  tbl['?'] = "000001";
	  tbl['A'] = "100101";
	  tbl['B'] = "10011010";
	  tbl['C'] = "0101";
	  tbl['D'] = "0001";
	  tbl['E'] = "110";
	  tbl['F'] = "01001";
	  tbl['G'] = "10011011";
	  tbl['H'] = "010000";
	  tbl['I'] = "0111";
	  tbl['J'] = "10011000";
	  tbl['K'] = "0110";
	  tbl['L'] = "00100";
	  tbl['M'] = "10011001";
	  tbl['N'] = "10011110";
	  tbl['O'] = "00101";
	  tbl['P'] = "111";
	  tbl['Q'] = "10011111";
	  tbl['R'] = "1000";
	  tbl['S'] = "00110";
	  tbl['T'] = "00111";
	  tbl['U'] = "10011100";
	  tbl['V'] = "10011101";
	  tbl['W'] = "000010";
	  tbl['X'] = "10010010";
	  tbl['Y'] = "10010011";
	  tbl['Z'] = "10010000";
	
	map<string, char> tbl2;
	
	  tbl2["00000"] = 'A';
	  tbl2["00001"] = 'B';
	  tbl2["00010"] = 'C';
	  tbl2["00011"] = 'D';
	  tbl2["00100"] = 'E';
	  tbl2["00101"] = 'F';
	  tbl2["00110"] = 'G';
	  tbl2["00111"] = 'H';
	  tbl2["01000"] = 'I';
	  tbl2["01001"] = 'J';
	  tbl2["01010"] = 'K';
	  tbl2["01011"] = 'L';
	  tbl2["01100"] = 'M';
	  tbl2["01101"] = 'N';
	  tbl2["01110"] = 'O';
	  tbl2["01111"] = 'P';
	  tbl2["10000"] = 'Q';
	  tbl2["10001"] = 'R';
	  tbl2["10010"] = 'S';
	  tbl2["10011"] = 'T';
	  tbl2["10100"] = 'U';
	  tbl2["10101"] = 'V';
	  tbl2["10110"] = 'W';
	  tbl2["10111"] = 'X';
	  tbl2["11000"] = 'Y';
	  tbl2["11001"] = 'Z';
	  tbl2["11010"] = ' ';
	  tbl2["11011"] = '.';
	  tbl2["11100"] = ',';
	  tbl2["11101"] = '-';
	  tbl2["11110"] = '\'';
	  tbl2["11111"] = '?';
	
	while (getline(cin, str))
	{
		string code = "";
		string res = "";
		
		REP(str.length()) code += tbl[str[i]];
		int len = code.length();
		while (code.length() % 5 != 0) code += "0";
		
		while (code.length() > 0)
		{
			string temp = code.substr(0, 5);
			res += tbl2[temp];
			code = code.substr(5);
		}
		
		cout << res << endl;
	}
	
	return 0;
}



double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1204
H, W = map(int, input().split())
a = []
ans = []
for i in range(H):
    a.append(input())
    
    if len(set(a[-1])) == 1 and a[-1][0] == '.':
        del a[-1]

if len(a) == 1:
    kotae = a[0]
    kotae = kotae.replace('.', '')
    print(kotae)
else:
    for x in range(W):
        check = []
        for y in range(len(a)):

            if a[y][x] != '.':
                break
            else:
                check.append(a[y][x])
                
        if len(check) == len(a):
            ans.append(x)
            
    
    if len(ans) >= 1:
        re_ans = []
        for i in a:
            kari = list(i)
            for j in ans:
                kari[j] = '0'
           # print(kari)
            re_ans.append(kari)
        
        for i in re_ans:
            moji = ''.join(i)
            mojji = moji.replace('0', '')
            print(mojji)
    else:
        for i in a:
            print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  int alice=0,bob=0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<a.size();i++){
   if(i%2==0)alice+=a.at(i);
    else bob+=a.at(i);
  }
  cout<<alice-bob<<endl;
  
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=998244353;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

long long int pow_mod(long long int p_a,long long int p_n,long long int p_p=1e9+7){
	//p_a^p_n mod p_p
	long long int p_b=1,p_t=1;
	for(;p_b<=p_n;p_b<<=1);
	for(p_b>>=1;p_b>0;p_b>>=1){
		p_t*=p_t;
		if(p_t>=p_p)p_t%=p_p;
		if(p_n&p_b)p_t*=p_a;
		if(p_t>=p_p)p_t%=p_p;
	}
	return p_t;
}

long long int gcd(long long int g_a,long long int g_b){
	if(g_a<g_b)gcd(g_b,g_a);
	if(g_b==0)return g_a;
	return gcd(g_b,g_a%g_b);
}

long long int divide(long long int d_a,long long int d_b,long long int d_p=1e9+7,bool prime=true){
	// d_a/d_b mod d_p
	// prime:d_p is prime or not
	if(d_a>=d_p)d_a%=d_p;
	if(d_a<0)d_a+=d_p;
	if(d_b>=d_p)d_b%=d_p;
	if(d_b<0)d_b+=d_p;
	if(!prime){
		long long int d_d=gcd(d_a,d_b);
		if(d_d>1)d_a/=d_d,d_b/=d_d;
	}
	d_a*=pow_mod(d_b,d_p-2,d_p);
	return d_a%d_p;
}

queue<LL> q1;

int main(){
	LL n,m,t,p;
	int i,j,k;
	LL a,b,c;
	cin>>n>>m>>t;
	t=divide(t,100,MAX);//next_continue percent
	p=divide(1,n,MAX);//divide percent
	a=p,q1.push(p);
	for(i=1;i<m;i++){
		if(q1.size()>n){
			a-=q1.front(),q1.pop();
			if(a<0)a+=MAX;
		}
		b=a*t;
		if(b>=MAX)b%=MAX;
		b*=p;
		if(b>=MAX)b%=MAX;
		q1.push(b),a+=b;
		if(a>=MAX)a-=MAX;
	}
	b=0;
	while(!q1.empty()){
		if(q1.size()>(n--)){
			a-=q1.front(),q1.pop();
			if(a<0)a+=MAX;
		}
		b+=a;
		if(b>=MAX)b%=MAX;
	}
	cout<<b<<endl;
}


Measured memory_bytes: 3668
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let c1: Vec<char> = read::<String>().chars().collect();
  let c2: Vec<char> = read::<String>().chars().collect();
  if c1[0] == c2[2] && c1[2] == c2[0] && c1[1] == c2[1] {
    println!("YES");
  } else {
    println!("NO");
  }
}


Measured memory_bytes: 4352
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll X,N;
    cin >> X >> N;
    ll p[110];
    rep(i,0,N) cin >> p[i];
    sort(p, p+N);
    ll ans = -1, abs_val = INF;
    map<ll,ll> mp;
    rep(i,0,N) mp[p[i]]++;
    rep(i,-110,110){
        if(mp[i] > 0) continue;
        if(abs(i-X) < abs_val){
            ans = i;
            abs_val = abs(i-X);
        }
    }
    print(ans);

}

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

Measured memory_bytes: 3660
L, A = int(input()), input()
print(A)

A = [int(i) for i in A.split()]
for i in range(1, L):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    l = [str(k) for k in A]
    l = ' '.join(l)
    print(l)




Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n;
	while(cin >> n and n > 0) {
		pair<int, int> book[n];
		for(int i = 0; i < n; ++i) {
			int r, w; cin >> r >> w;
			book[i] = {r, w};
		}
		sort(book, book + n);
		reverse(book, book + n);
		int readSum = 0;
		for(int i = 0; i < n; ++i) {
			readSum += book[i].first;
		}
		if(book[0].first <= readSum - book[0].first) {
			int writeSum = 0;
			for(int i = 0; i < n; ++i) {
				writeSum += book[i].second;
			}
			cout << readSum + writeSum << endl;
		} else {
			int rest = book[0].first - (readSum - book[0].first);
			// iまでで時間jが可能か
			bool dp[n][rest + 1] = {};
			dp[0][0] = true;
			for(int i = 1; i < n; ++i) {
				for(int j = 0; j <= rest; ++j) {
					dp[i][j] = dp[i - 1][j];
					if(j - book[i].second >= 0) dp[i][j] |= dp[i - 1][j - book[i].second];
				}
			}
			int writeSum = 0;
			for(int i = 0; i < n; ++i) {
				writeSum += book[i].second;
			}
			for(int j = rest; j >= 0; --j) {
				if(dp[n - 1][j]) {
					writeSum -= j;
					break;
				}
			}
			cout << book[0].first * 2 + writeSum << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int cock_time[5];
    for (int i = 0; i < 5; i++) cin >> cock_time[i];
    int minute = 10;
    int offset;
    for (int i = 0; i < 5; i++){
        int cock_time_min = cock_time[i] % 10;
        if (cock_time_min != 0){
            if (minute > cock_time_min){
                minute = cock_time_min;
                offset = i;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 5; i++){
        if (i != offset){
            if (cock_time[i] % 10 != 0)
                ans += ((cock_time[i] / 10) + 1) * 10;
            else ans += cock_time[i];
        }
    }
    ans += cock_time[offset];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int solve(int a, int b) {
    // cout << "call:" << a << " " << b << endl;
    if (a < b) {
        int temp = a;
        a        = b;
        b        = temp;
    }
    int r;
    while (1) {
        r = a % b;
        if (r == 0) {
            return b;
        } else {
            a = b;
            b = r;
        }
    }
}

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n++;
    std::vector<int> num;
    int m1;
    for (int i = 0; i < n; i++) {
        cin >> m1;
        num.push_back(m1);
    }
    std::sort(num.begin(), num.end());
    std::vector<int> diff;
    int diffmax = 0;

    for (int i = 1; i < n; i++) {
        int push = num[i] - num[i - 1];
        diff.push_back(push);
        if (diffmax < push) {
            diffmax = push;
        }
    }
    int prev = diff[0];
    for (int i = 1; i < n - 1; i++) {
        prev = solve(diff[i], prev);
    }
    cout << prev << endl;

    
    return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=15;
int n,m,s[maxn],c[maxn],ans[maxn],vis[maxn];
int main()
{
	cin>>n>>m;
	int flag=1;
	for(int i=1;i<=m;i++)
	{
		cin>>s[i]>>c[i];
		if(s[i]==1&&c[i]==0&&n>1) flag=0;
	}
	if(!flag) puts("-1");
	else
	{
		int flag=1;
		for(int i=1;i<=m;i++)
		{
			if(vis[s[i]]&&ans[s[i]]!=c[i]) 
			{
				flag=0;
				break;
			}
			vis[s[i]]=c[i];
			ans[s[i]]=c[i];
		}
		if(!flag) puts("-1");
		else 
		{
			for(int i=1;i<=n;i++) 
			{
				if(i==1&&ans[i]==0&&n>1) cout<<1;
				else cout<<ans[i];
			}
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();
  ll n,k;cin>>n>>k;
  vector<ll>v(n);
  loop(i,0,n)cin>>v[i];
  vector<ll>win(k+10,0);

  for(int i = 0;i<=k;i++)
  {
  	int ls = 0;
  	for(int j = 0;j<n;j++)
  	{
  		if(i>=v[j] && win[i-v[j]]==0)
  		{
  			ls++;
  			break;
  		}
  	}
  	if(ls != 0)win[i] = 1;
  }
  if(win[k])
  	cout<<"First";
  else cout<<"Second";

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

ll dp[402][402];
ll T[402];
ll pref[402];

ll count_dp(int a, int b)
{
    if(dp[a][b] != 1e18) return dp[a][b];
    if(a == b) return 0;

    for(int i = a; i <= b; i++)
            dp[a][b] = min(dp[a][b], count_dp(a, i) + count_dp(i + 1, b) + pref[b] - pref[i] + pref[i] - pref[a - 1]);

    return dp[a][b];
}

int main()
{
    turbo

    int n; cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> T[i];

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            dp[i][j] = 1e18;

    for(int j = 1; j <= n; j++)
        pref[j] = pref[j - 1] + T[j];

    return cout << count_dp(1, n), 0;
}

Measured memory_bytes: 1536
#include<cstdio>
#include<vector>
#include<tuple>
using namespace std;
vector<pair<int, int>> map[100001];
int ind[100001];
int l[100001];
int v[100001];
bool dfs(int x) {
	int t, w;
	v[x] = 1;
	for (auto e : map[x]) {
		tie(t, w) = e;
		if (v[t] == 0) {
			l[t] = l[x] + w;
			if (!dfs(t)) return false;
		}
		else {
			if (l[t] != l[x] + w) return false;
		}
	}
	return true;
}
int main() {
	int n, m, a, b, c;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		scanf("%d%d%d", &a, &b, &c);
		map[a].emplace_back(b, c);
		map[b].emplace_back(a, -c);
	}
	for (int i = 1; i <= n; i++) {
		if (v[i] == 0) {
			if (!dfs(i)) {
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 11392
#include<iostream>
#include<algorithm>
#include<string>
#define NIL -1
using namespace std;
struct Node{
    int parent,right,left,sibling,depth,height;
    string name;
};
Node tree[26];
void depth_search(int,int);
int height_search(int,int);
int main(void){
    int n,key,l,r,root_id;
    cin >> n;
    for(int i=0;i<n;i++){
        tree[i].parent = tree[i].sibling = NIL;
    }
    for(int i=0;i<n;i++){
        cin >> key >> l >> r;
        tree[key].left = l;
        tree[key].right = r;
        if(l!=NIL){
            tree[l].parent = key;
            tree[l].sibling = r;
        }
        if(r!=NIL){
            tree[r].parent = key;
            tree[r].sibling = l;
        }
    }
    for(int i=0;i<n;i++){
        if(tree[i].parent == NIL){
            tree[i].name = "root";
            root_id = i;
        }
    }
    depth_search(root_id,0);
    height_search(root_id,0);
    for(int i=0;i<n;i++){
        cout << "node " << i << ": parent = " << tree[i].parent << ", sibling = " << tree[i].sibling << ", degree = ";
        if(tree[i].right==NIL && tree[i].left==NIL){
            cout << '0';
            if(i!=root_id){
                tree[i].name = "leaf";
            }
        }else if(tree[i].right!=NIL && tree[i].left!=NIL){
            cout << '2';
            if(i!=root_id){
                tree[i].name = "internal node";
            }
        }else{
            cout << '1';
            if(i!=root_id){
                tree[i].name = "internal node";
            }
        }
        cout << ", depth = " << tree[i].depth << ", height = " << tree[i].height << ", " << tree[i].name << endl;  
    }
    return 0;
}
void depth_search(int p,int d){
    tree[p].depth = d;
    if(tree[p].left!=NIL){
        depth_search(tree[p].left,d+1);
    }
    if(tree[p].right!=NIL){
        depth_search(tree[p].right,d+1);
    }
}
int height_search(int p,int count){
    int h1=0,h2=0;
    if(tree[p].left!=NIL){
        h1 = height_search(tree[p].left,h1);
        h1++;
    }
    if(tree[p].right!=NIL){
        h2 = height_search(tree[p].right,h2);
        h2++;
    }
    tree[p].height = max(h1,h2);
    return tree[p].height;
}


Measured memory_bytes: 3200
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
AC
*/

ll n,a[110],ans=0;

int main(void){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n-1){
		if(a[i]==a[i+1]){//後ろの方を使ってない色に変える
			ans++;
			i++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,b,c;

    Scd3(a,b,c);
    int d =  max(a,max(b,c));
    a = d - a;
    b = d - b;
    c = d - c;

    a = a+b+c;
    if( a % 2 ){
        printf("%d\n", (a+3) / 2 );
    }else{
        printf ("%d\n", a / 2 );
    }
    return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())

graph = [[] for i in range(N)]

for i in range(M):
    ai, bi = map(int, input().split())
    ai -= 1
    bi -= 1
    graph[ai].append(bi)
    graph[bi].append(ai)

rank = [N] * N
low = [N] * N
visited = [False] * N


def dfs(k, pos, parent):
    rank[pos] = k
    low[pos] = k

    k += 1

    visited[pos] = True

    for i in graph[pos]:
        if not visited[i]:
            k = dfs(k, i, pos)
            low[pos] = min(low[pos], low[i])
        elif i != parent:
            low[pos] = min(low[pos], low[i])

    return k


def main():
    dfs(0, 0, -1)

    ans = 0

    for i in range(N):
        for j in graph[i]:
            if rank[j] < low[i]:
                ans += 1

    print(ans)
    return


main()


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

int main()
{
    long long int x;
    cin >> x;

    long long int ans;

    if (x <= 0)
    {
        ans = 0;
    }
    else
    {
        if (x % 11 == 0)
        {
            ans = x / 11 * 2;
        }
        else if (x % 11 > 0 && x % 11 <= 6)
        {
            ans = x / 11 * 2 + 1;
        }
        else if (x % 11 > 6)
        {
            ans = x / 11 * 2 + 2;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int factorial(int n) {
    if (n == 1) return 1;
    else return n * factorial(n - 1);
}

int main() {
    int n;
    cin(n);

    vector<pair<int, int>> points(n);
    rep2(i, n) {
        int x, y;
        cin(x); cin(y);
        points[i] = make_pair(x, y);
    }

    vector<int> temp(n);
    rep2(i, n) temp[i] = i;

    int fact = factorial(n);
    double sum = 0;

    do {
        rep3(i, 1, n) {
            int dx = points[temp[i]].first - points[temp[i - 1]].first;
            int dy = points[temp[i]].second - points[temp[i - 1]].second;

            double d = pow(dx * dx + dy * dy, 0.5);
            sum += d;
        }
    } while (next_permutation(temp.begin(), temp.end()));

    printf("%0.12f\n", sum / fact);
    return 0;
}

Measured memory_bytes: 4224
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long int64;
typedef long double ld;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;














int N,x[301],y[301];


ld get_r(ld X, ld Y){
    ld ret = 0;
    
    for(int i = 0;i < N;++i)
        ret = max(ret,(X - x[i]) * (X - x[i]) + (Y - y[i]) * (Y - y[i]));
    
    return ret;
}

ld searchY(ld X){
    ld lo = 0,hi = 1000;
    
    for(int it = 0;it < 100;++it){
        ld a = (2 * lo + hi) / 3;
        ld b = (lo + 2 * hi) / 3;
        
        ld ra = get_r(X,a);
        ld rb = get_r(X,b);
        
        if(ra < rb) hi = b;
        else lo = a;
    }
    
    return get_r(X,lo);
}

ld searchX(){
    ld lo = 0,hi = 1000;
    
    for(int it = 0;it < 100;++it){
        ld a = (2 * lo + hi) / 3;
        ld b = (lo + 2 * hi) / 3;
        
        ld ra = searchY(a);
        ld rb = searchY(b);
        
        if(ra < rb) hi = b;
        else lo = a;
    }
    
    return searchY(lo);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i,N){ cin >> x[i] >> y[i];}

    ld ans = sqrt(searchX());
    cout << fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

LL T[MAX];
LL A[MAX];
LL Q[MAX];
int sz;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, q;
	cin >> n >> q;
	if (q == 0)
	{
		FOR(i, 0, n) cout << "1\n";
		return 0;
	}

	FOR(i, 0, q)
	{
		LL a;
		cin >> a;
		while (sz && Q[sz - 1] >= a) sz--;
		Q[sz++] = a;
	}
	
	//cout << sz << endl;
	//FOR(i, 0, sz) cout << Q[i] << " ";
	//cout << endl;
	T[sz - 1] = 1;
	LL cnt = min(Q[0], (LL)n);

	RFOR(i, sz, 0)
	{
		LL a = Q[i];
		while (1)
		{
			int ind = lower_bound(Q, Q + sz, a) - Q;
			if (ind == 0) break;
			ind--;

			T[ind] += T[i] * (a / Q[ind]);
			a %= Q[ind];
		}

		A[cnt - 1] += (a / cnt) * T[i];
		if (a % cnt) A[a % cnt - 1] += T[i];
	}

	//FOR(i, 0, n) cout << A[i] << " ";
	//cout << endl;
	RFOR(i, n - 1, 0)
	{
		A[i] += A[i + 1];
	}

	FOR(i, 0, n) cout << A[i] << " \n";
	cout << endl;
}

Measured memory_bytes: 4224
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for _ in range(N)]

first = 0
second = -1

for k in range(N):
    if A[k] > first:
        second = first
        first = A[k]
    elif second < A[k] <= first:
        second = A[k]

for l in range(N):
    if A[l] == first:
        print(second)
    else:
        print(first)

Measured memory_bytes: 58416
s=input()
for i in range(int(len(s)/2)):
    tmp=s[:-int((i+1)*2)]
    a=0
    for j in range(int(len(tmp)/2)):
        if tmp[j]==tmp[j+int(len(tmp)/2)]:
            a+=1
    if a==int(len(tmp)/2):
        print(len(tmp))
        exit()

Measured memory_bytes: 8916
package main

import (
	"fmt"
	"bufio"
	"strconv"
	"os"
)

const N = 100

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, N+1)
	m := make([][]int, N+1)
	for i := range m {
		m[i] = make([]int, N+1)
	}
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= n; i++ {
		scanner.Scan()
		p[i-1], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		p[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 1; i <= n; i++ {
		m[i][i] = 0
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i+l-1
			m[i][j] = 1 << 21
			for k := i; k <= j-1; k++ {
				m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}
	fmt.Println(m[1][n])
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for (int i = 0; i < N; i++) {
        cin >> l.at(i);
    }

    int ans = 0;
    sort(l.begin(), l.end());
    for (int i = N - 1; i > N - 1 - K; i--) {
        ans += l.at(i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> T;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using vec = vector<int>;

struct UnionFind {
    public:
    vector<int> child, tree, sum, ed;

    public:
    UnionFind(int v) {
        tree.resize(v);
        sum.resize(v);
        ed.resize(v,0);
        rep(i, v) tree[i] = i, sum[i] = 1;
    }

    int root(int i) {
        if(i == tree[i]) {
            rep(j, child.size()) tree[child[j]] = i;
            child.clear(); 
            return i;
        }
        else {
            child.push_back(i);
            return i = root(tree[i]);
        }
    }

    int size(int i) {
        return sum[root(i)];
    }

    int edsize(int i) {
        return ed[root(i)];
    }

    int unit(int x, int y) {
        x = root(x);
        y = root(y);
        if(isUnit(x,y)){
            ed[min(x,y)] ++;
            return 0;
        }
        sum[min(x,y)] += sum[max(x,y)];
        ed[min(x,y)] += 1 + ed[max(x,y)];
        tree[max(x,y)] = min(x,y);
    }

    bool isUnit(int x, int y) {
        return root(x) == root(y);
    }
};

int Nmax=100100;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,h,w;
    cin>>n>>h>>w;
    vector<T> x(n);
    rep(i,n){
        int r,c,a;
        cin>>r>>c>>a; // a is score
        x[i]=T(a,r,c);
    }
    sort(rall(x));
    UnionFind uf1(h+w+Nmax);
    UnionFind uf2(h+w+Nmax);
    ll ans=0;
    rep(i,n){
        int a,r,c; // a is score
        tie(a,r,c)=x[i];
        if(uf1.isUnit(r,c+Nmax)&&uf2.isUnit(r,c+Nmax)){
            // 取れない
        }
        else if(uf1.isUnit(r,c+Nmax)){
            // 辺がある
            if(uf1.edsize(r)<uf1.size(r)){
                uf1.unit(r,c+Nmax);
                uf2.unit(r,c+Nmax);
                ans+=a;
            }
        }
        else{
            // 辺がない
            if(uf1.edsize(r)+uf1.edsize(c+Nmax)<uf1.size(r)+uf1.size(c+Nmax)){
                uf1.unit(r,c+Nmax);
                ans+=a;
            }
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 15488
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
typedef long long int ll;
int n;
std::vector<ll> a;
ll dfs(int l,int r,ll A,ll b){
	if(l>r)return 0;
	ll ans=1e18;
	for(int i=l;i<=r;i++){
		ans=min(ans,a[i]*(A+b)+dfs(l,i-1,A,A+b)+dfs(i+1,r,A+b,b));
	}
	return ans;
}

int main(){
	cin >> n;
	a=vector<ll> (n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	cout << a[0]+a[n-1]+dfs(1,n-2,1,1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> pii;

const int N = 1e5;
int a[N];
char s[10];
int main()
{
    cin >> s + 1;
    int a = 0, b = 0;
    for (int i = 1; i <= 3; i++)
        if (s[i] == 'A')
            a++;
        else if (s[i] == 'B')
            b++;
    cout << (a && b ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;

#define M 1000000007

ll m4pow(ll i) {
    if (i == 0) {
        return 1;
    } else if (i == 1) {
        return 4;
    } else {
        auto res = m4pow(i/2);
        res *= res;
        res %= M;
        if (i % 2 == 1) {
            res *= 4;
            res %= M;
        }
        return res;
    }
}

int main() {
    ll n;
    cin >> n;
    vector<ll> C(n);
    for (auto & c : C) {
        cin >> c;
    }
    sort(C.begin(), C.end(), greater<ll>());

    ll res = 0;

    for (ll i = 0; i < n; ++i ) {
        res += C[i] * (i + 2);
        res %= M;
    }
    res *= m4pow(n-1);
    res %= M;
    cout << res << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	ll n,k; cin >> n >> k;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	vector<ll> b(n+1, 0);
	if (k > ceil(log2(n))*4) rep(i,n) b[i] = n; // todo
	else {
		rep(j,k) {
			rep(i, n) {
				++b[max(0LL, i - a[i])];
				--b[min((ll) n, i + a[i] + 1)];
			}

			rep1(i, n - 1) {
				b[i] += b[i - 1];
			}

			if (j != k-1) rep(i,n) { a[i] = b[i]; b[i] = 0;}
			b[n] = 0;
		}
	}
  
	rep(i,n) cout << b[i] <<  " "; cout << en;
}


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

std::string str;

uint64_t solve() {
    uint64_t a_cnt = 0;
    bool b_flg = false;
    uint64_t res = 0;
    char prev = 'S';
    for (auto c : str) {
        if (c == 'A') {
            if (prev == 'A') {
                a_cnt ++;
            }
            else {
                a_cnt = 1;
            }
            b_flg = false;
        }
        else if (c == 'B') {
            if (prev == 'A') {
                b_flg = true;
            }
            else {
                a_cnt = 0;
                b_flg = false;
            }
        }
        else if (c == 'C') {
            if (b_flg) {
                res += a_cnt;
                c = 'A';
            }
            else {
                a_cnt = 0;
            }
            b_flg = false;
        }
        prev = c;
        // std::cout << a_cnt << ", " << res << std::endl;
    }
    return res;
}

int main(int argc, char const* argv[])
{
    std::cin >> str;
    auto res = solve();
    std::cout << res << std::endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

struct fenwick_tree {
    ll N;
    vector<ll> bit;
    fenwick_tree(ll num) : bit(num + 1, 0) { N = num; }
    ll Sum(ll a) {
        ll ret = 0;
        for (ll x = a; x > 0; x -= x & -x) {
            ret += bit[x];
        }
        return ret;
    }
    void Add(ll a, ll w) {
        for (ll x = a; x <= N; x += x & -x) {
            bit[x] += w;
        }
    }
};

ll a[100005];

bool judge(ll mid, ll n) {
    int offset = n+1;
	ll num_inverse = 0;
	fenwick_tree bit(n*2+10);

	int sum_v = 0;
    bit.Add(sum_v+offset, 1);

	for (int i = 0; i < n; i++) {
		int s = (a[i] <= mid) ? 1 : -1;
		sum_v += s;
		num_inverse += (bit.Sum(sum_v-1+offset) - bit.Sum(0));
		bit.Add(sum_v+offset, 1);
	}
	if (num_inverse > (n+1)*n/2/2) {
        return true;
    } else {
        return false;
    }
}

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

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

    ll high = 1e18, low = 0; 

    while (low < high) {
        ll mid = ( high + low ) / 2;

        if ( judge(mid, n) ) {
            high = mid;
        } else {
            low = mid+1;
        }
    }

    cout << high << endl;

    return 0;
}

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

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000'000'007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//

int main()
{
	IOS

	ll n, k;
	cin >> n >> k;
	cout << n - k + 1;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() { 
    int n; cin >> n;
    vector<ll> A(n); rep(i, n)cin >> A[i];

    //+
    ll res1 = 0, sum = 0;
    rep(i, n){
        sum += A[i];
        if(i%2==1 && sum <=0){
            ll num = -sum+1;
            sum += num;
            res1+= num;
        }else if(i%2==0 && sum >= 0){
            ll num = sum+1;
            sum -= num;
            res1 += num;
        }
    }
    //-
    ll res2 = 0; sum = 0;
    rep(i, n){
        sum += A[i];
        if(i%2==0 && sum <=0){
            ll num = -sum+1;
            sum += num;
            res2+= num;
        }else if(i%2==1 && sum >= 0){
            ll num = sum+1;
            sum -= num;
            res2 += num;
        }
    }
    cout << min(res1, res2) << ln;
}

Measured memory_bytes: 1024
// AOJ 0023
#include<iostream>
#include<cmath>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

const long double EPS = 1e-16;

long double sq(long double x) {
  return x * x;
}

long double abs(long double x) {
  return (x > 0 ? x : -x);
}
/*
bool eq(long double x, long double y) {
  return abs(x - y) < EPS;
}*/

long double dist(long double xa, long double ya, long double xb, long double yb) {
  return sq(xa - xb) + sq(ya - yb);
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    long double xa, ya, ra, xb, yb, rb;
    cin >> xa >> ya >> ra >> xb >> yb >> rb;

    long double d = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
    
    if (ra - rb > d + EPS) {
      cout << 2 << endl;
    } else if (rb - ra > d + EPS) {
      cout << -2 << endl;
    } else if (d > ra + rb + EPS) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
}

Measured memory_bytes: 1232
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
cnt = 0

for i in range(N):
    x = 0
    for j in range(M):
        x += A[i][j] * B[j]
    if x+C > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n ; cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  ll ans = 0;
  REP(i, n) REP(j, n) if(i!=j){
    ll diff = abs(a[i]-a[j]);
    ans = max(ans, diff);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long a[1000005],b[1000005],c[1000005],fc[1000005],Ha[1000005],ans[3],C,n,tot;
int main()
{	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{	scanf("%lld",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	tot=unique(b+1,b+n+1)-(b+1);
	for(int i=1;i<=n;i++)
	{	c[i]=lower_bound(b+1,b+tot+1,a[i])-b;
		fc[c[i]]=a[i];
	}
	for(int i=1;i<=n;i++)Ha[c[i]]++;
	for(int i=tot;i>=1;i--)
	{	while(Ha[i]>=2)
		{	C++;
			ans[C]=i;
			Ha[i]-=2;
			if(C==2)break;
		}
		if(C==2)break;
	}
	if(C==2)printf("%lld",fc[ans[1]]*fc[ans[2]]);
	else printf("0");
}

Measured memory_bytes: 13312
from collections import defaultdict
s=input()
K=int(input())


def calc(s, K):
    a = defaultdict(list)
    for i, c in enumerate(s):
        a[c].append(i)
    result = set()
    for i in range(ord('a'), ord('z')+1):
        for j in a[chr(i)]:
            for l in range(min(K, len(s[j:]))):
                result.add(s[j:j+l+1])
        if len(result) >= K:
            return sorted(list(result))[K-1]

print(calc(s, K))


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 1e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
int main() {
    scanf("%d",&n);
    ll ret = 1;
    int d[] = {0, 0, 0};
    rep(i, 0, n) {
        int x; scanf("%d",&x);
        ll cnt = 0;
        int id = -1;
        rep(j, 0, 3) {
            if(d[j]==x) id = j, cnt++;
        }
        if(id==-1) return printf("0\n"),0;
        ret *= cnt; ret %= mod;
        d[id]++;
    }
    printf("%lld\n",ret);
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int n=0;
  for(int i=0; i<B; i++){
    if(A * i - i + 1 >= B)
      break;
  n++;
  }
  
  cout << n << endl;
}



Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<stack>

using namespace std;

int main() {
	int a, b, c,count=0;
	cin >> a >> b >> c;
	for (int i = a; i <= b; i++)
		if (c%i == 0)count++;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3092