akhauriyash/Code-Regression huggingface dataset:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    C=LLIN(3)
    A=[C[0][i]-C[0][0] for i in range(3)]
    B=[C[1][i]-C[1][0] for i in range(3)]
    C=[C[2][i]-C[2][0] for i in range(3)]
    if A==B==C:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 64108
n = gets.to_i
heights = gets.split.map(&:to_i)
ans = 0
tmp = 0
previous = 0
heights.each do |height|
  if height > previous
    tmp = 0
    previous = height
  else
    tmp += 1
    previous = height
    ans = tmp if tmp > ans
  end
end
puts ans


Measured memory_bytes: 8580
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main(){
    int q;
    long long int a, b, c, res;
    long long int xtmp, ntmp;
    cin >> q;
    REP(i, q){
        cin >> a >> b;
        xtmp = max(a, b);
        ntmp = min(a, b);
        if(xtmp == ntmp || ntmp + 1 == xtmp){
            print(2 * ntmp - 2);
        }else{
            c = (long long int)sqrt(a * b);
            if(c * c == a * b) c--;
            if(c * (c + 1) >= a * b) {
                res = 2 * (c - 1);
            }else if(c * c < a * b) {
                res = 2 * c - 1;
            }
            print(res);
        }
    }
}

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

int main() {
    int D, manzoku;
    cin >> D;
    vector<int> c(26, 0);
    vector<int> count(26, 0);
    vector<vector<int>> s(D, vector<int>(26));

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

    for(int i = 0; i < D; i++){
        for(int n = 0; n < 26; n++){
            cin >> s.at(i).at(n);
        }
    }

    vector<int> t(D, 0);
    for(int i = 0; i < D; i++){
        cin >> t[i];
        t[i] -= 1;
    }

    for(int i = 0; i < D; i++){
        manzoku += s.at(i).at(t[i]);
        for(int n = 0; n < 26; n++){
            if(n == t[i]){
                count[n] = 0;
            }else{
                count[n] += 1;
            }
            manzoku -= count[n] * c[n];
        }
        cout << manzoku << endl;
    }
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void){

  int n[4];
  for (int i = 0; i < 4; i++) {
    scanf("%d", &n[i]);
  }
  int digit[10];
  for (int i = 0; i < 10; i++) {
    digit[i] = 0;
  }
  for (int i = 0; i < 4; i++) {
    digit[n[i]]++;
  }
  if (digit[1] == 1 && digit[9] == 1 && digit[7] == 1 && digit[4] == 1) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
string a,b;
cin>>a>>b;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
reverse(b.begin(),b.end());
if(a<b)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
field = []
for i in range(h):
    if i % 2 == 0:
        field += list(map(int, input().split()))
    else:
        field += list(map(int, input().split()))[::-1]

n = h * w
answers = []
for i in range(n-1):
    if field[i] % 2 == 1:
        field[i+1] += 1
        y = i // w + 1
        x = i % w + 1
        ny = (i+1) // w + 1
        nx = (i+1) % w + 1
        if y % 2 == 0:
            x = w - x + 1
        if ny % 2 == 0:
            nx = w - nx + 1
        answers.append([y, x, ny, nx])

print(len(answers))
for ans in answers:
    a, b, c, d = ans
    print(a, b, c, d)


Measured memory_bytes: 30072
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long n, long long m, long long d){
  if(d==0)
    std::cout << setprecision(10) << (double)(m-1)/(double)n << std::endl;
  else
    std::cout << setprecision(10) << (double)(m-1)*2*(n-d)/(double)(n*n) << std::endl;
}

int main(){
  long long n;
  scanf("%lld",&n);
  long long m;
  scanf("%lld",&m);
  long long d;
  scanf("%lld",&d);
  solve(n, m, d);
  return 0;
}



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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d.at(i);
  int ans = 0;
  
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      ans += d.at(i) * d.at(j);
    }
  }
    
    cout << ans << endl;  
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


int main(){
    ll k, a, b;
    cin >> k >> a >> b;
    bool ans = false;
    
    for (int i=a; i<=b; i++){
        if (i%k ==0) {
            ans = true;
            break;
        }
    }
    
    if (ans) cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

int N;
int A[100005];

int main()
{
	int i,j,k, ans = 0;
	//freopen("sort.in", "r", stdin);
	scanf("%d", &N);
	for(i=0; i<N; i++)  scanf("%d", &A[i]);

	for(i=0; i<N; i++){
		if(i==N-1){
			ans++;
		}
		else{
			j = i+1;
			k = i+1;

			while(j<N && A[j-1]<=A[j]) j++;
			while(k<N && A[k-1]>=A[k]) k++;

			//printf("i:%d j:%d k:%d\n", i, j, k);
			ans++;
			i = max(j,k) - 1;
		}
	}

	printf("%d\n", ans);
	return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<int> a(n);
  for (int &i : a) in >> i;
  int p = -1, val = -1;
  for (int i = 0; i < n; ++i) {
    if (p == -1 || abs(val) < abs(a[i])) {
      p = i;
      val = a[i];
    }
  }
  vector<pair<int, int>> ops;
  ops.emplace_back(p, p);
  ops.emplace_back(p, p);
  for (int i = 0; i < n; ++i) {
    if (i != p) {
      ops.emplace_back(p, i);
    }
  }
  if (a[p] < 0) {
    for (int i = n - 1; i > 0; --i) {
      ops.emplace_back(i, i - 1);
    }
  } else {
    for (int i = 0; i < n - 1; ++i) {
      ops.emplace_back(i, i + 1);
    }
  }
  out << ops.size() << '\n';
  for (pair<int, int> pr : ops) {
    out << pr.first + 1 << ' ' << pr.second + 1 << '\n';
  }
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

pair<int64_t, int64_t> part[200005];

int main()
{
  int N;
  vector<int> A;

  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<int> sorted_A(A);

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

  int64_t total = 0;

  for (int i = 0; i < sorted_A.size(); i++) {
    static int64_t count = 1;

    if (i == sorted_A.size() - 1) {
      part[sorted_A[i]].first = max<int64_t>(0, count * (count - 1) / 2);
      part[sorted_A[i]].second = max<int64_t>(0, (count - 1) * (count - 2) / 2);
      total += part[sorted_A[i]].first;
    }
    else if (sorted_A[i] != sorted_A[i + 1]) {
      part[sorted_A[i]].first = max<int64_t>(0, count * (count - 1) / 2);
      part[sorted_A[i]].second = max<int64_t>(0, (count - 1) * (count - 2) / 2);
      total += part[sorted_A[i]].first;
      count = 1;
    }
    else {
      count++;
    }
  }

  for (int i = 0; i < A.size(); i++) {
    cout << fixed << total - part[A[i]].first + part[A[i]].second << endl;
  }

  return 0;
}


Measured memory_bytes: 6272
n = int(input())
a = list(map(int, input().split(' ')))
dictionary = {}
for i in range(n):
    if a[i] in dictionary:
        dictionary[a[i]] += 1
        if 2 <= dictionary[a[i]]:
            print("NO")
            exit()
    else:
        dictionary[a[i]] = 1
print("YES")


Measured memory_bytes: 32844
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if((a)%3==0)
        printf("Possible\n");
    else if((b)%3==0)
        printf("Possible\n");
    else if((a+b)%3==0)
        printf("Possible\n");
    else
        printf("Impossible\n");
    return 0;
}

Measured memory_bytes: 1632
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	lli a,b;
	lli ans = INF;
	for(lli i=1;i*i<=n;i++){
		if(n%i==0){
			a = i;
			b = n/i;
			ans = min(ans,a+b-2);
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

func nextInt() int {
  sc.Scan()
  i, e := strconv.Atoi(sc.Text())
  if e != nil {
    panic(e)
  }
  return i
}

func nextLine() string {
  sc.Scan()
  return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()

  as := make([]int, n)
  for i := 0; i < n; i++ {
    as[i] = nextInt()
  }

  sort.Slice(as, func(i, j int) bool {
    return as[i] > as[j]
  })

  ans := 0
  que := make([]int, 0)

  for k, a := range as {
    if k == 0 {
      que = append(que, a)
    } else {
      ans = que[0] + ans
      que = que[1:len(que)]
      que = append(que, a)
      que = append(que, a)
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 12944
listn = []
for i in range(28):
    n = int(input())
    listn.append(n)

for i in range(28):
    for j in range(27,0,-1):
        if listn[j-1]>listn[j]:
            listn[j-1],listn[j] = listn[j],listn[j-1]

flist = []
for i in range(1,31,1):
    if listn==[]:
        flist.append(i)
    else:
        if listn[0]==i:
            del(listn[0])
        else:
            flist.append(i)

print(flist[0])
print(flist[1])


Measured memory_bytes: 5596
#include<stdio.h>

int main (void){

while(1){

int i=0;

int sum=0;

char num[1001]={};

scanf("%s",num);

if(num[0]-'0'==0){break;}

while(num[i])

{

sum+=num[i]-'0';

i++;

}

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

}

return 0;

}

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

using namespace std;

int main() {
	string s;
	int k;
	cin>>k;
	cin>>s;
	if((int)s.length() <= k) {
		cout<<s<<endl;
	} else {
		cout<<s.substr(0, k)<<"...\n";
	}
	return 0;
}


Measured memory_bytes: 3628
n=int(input())
pos=n//2-1
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]=[arr[i],i]
arr=sorted(arr,key=lambda x:x[0])
ans=[0]*n
for i in range(n):
  if i<=pos:
    ans[arr[i][1]]=arr[pos+1][0]
  else:
    ans[arr[i][1]]=arr[pos][0]
for i in range(n):
  print(ans[i])

Measured memory_bytes: 42944
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

#define N_MAX (unsigned int)(pow(10, 5))

int main(){
	unsigned int n;
	cin >> n;
	vector<unsigned int> a(N_MAX, 0);
	unsigned int ans = 0;

	for(unsigned int i = 0; i < n; i++){
		unsigned int tmp;
		cin >> tmp;
		if(tmp > N_MAX) ans++;
		else a[tmp - 1]++;
	}

	for(unsigned int i = 0; i < N_MAX; i++){
		if(a[i] > i + 1){
			ans += a[i] - i - 1;
		}else if(a[i] < i + 1){
			ans += a[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define lsb(x) (x & (-x))


using namespace std;

const int MAXN = 200 + 5;
const float INF = (float) 1e9;

int v[MAXN * MAXN + 1], t[MAXN + 1];

float dp[MAXN * MAXN + 1][MAXN + 1];

int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n, x;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++)
        cin >> t[i];
    int sz = 0;
    for(i = 1; i <= n; i++) {
        cin >> x;
        while(t[i] > 0) {
            t[i]--;
            v[++sz] = x;
        }
    }
    n = sz;
    for(i = 0; i <= MAXN; i++)
        dp[0][i] = -INF;
    dp[0][0] = 0;
    for(i = 1; i <= n; i++) {
        for(j = 0; j <= MAXN; j++) {
            dp[i][j] = -INF;
        }
        for(j = 0; j <= v[i]; j++) {
            if(j > 0)
                dp[i][j] = dp[i - 1][j - 1] + (float) (2 * j - 1) / (float) 2.0;
            if(v[i] == j)
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + j);
            else
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + j + (float) 0.25);
            if(j < v[i])
                dp[i][j] = max(dp[i][j], dp[i - 1][j + 1] + (float) (2 * j + 1) / (float) 2.0);
        }
    }
    cout << setprecision(10) << dp[n][0];
    //cin.close();
    //cout.close();
    return 0;
}


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

using namespace std;

bool dp[100005];

void solve(vector<int> &A, int n) {
  if (dp[n]) {
    return;
  }
  for (int a : A) {
    if (n - a < 0) {
      continue;
    }
    if (dp[n - a]) {
      continue;
    }
    dp[n - a] = true;
    solve(A, n - a);
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto &a : A) {
    cin >> a;
  }
  for (int i = K; i >= 0; i--) {
    solve(A, i);
  }
  string ans = dp[0] ? "First" : "Second";
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 384
s = input()

even_s = ''
odd_s = ''
for i in range(len(s)):
    if i & 1:
        odd_s += s[i]
    else:
        even_s += s[i]

odd_0_count = odd_s.count('0')
odd_1_count = odd_s.count('1')

even_0_count = even_s.count('0')
even_1_count = even_s.count('1')

print(min(odd_1_count + even_0_count, odd_0_count + even_1_count))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  if(2 * x >= a * a * b) cout << fixed << setprecision(15) << atan(double(2 * (b - double(x) / double(a * a))) / double(a)) / 3.1415926535897932384626433832795028841971 * 180 << endl;
  else cout << fixed << setprecision(15) << atan(double(a * b * b) / double(2 * x)) / 3.1415926535897932384626433832795028841971 * 180 << endl;
}

Measured memory_bytes: 4008
#include<stdio.h>
#include<stdlib.h>
int main(){
    int a,s,i,j;
    int *retu;
    
    scanf("%d",&a);
    retu=(int *)malloc(a * sizeof(int));
    for(i=0;i<a;i++){
        scanf("%d",&retu[i]);
    }
    for(i=0;i<a;i++){
        s=retu[i];
        j=i-1;
        while(retu[j]>s && j>=0){
            retu[j+1]=retu[j];
            j--;
        }
	retu[j+1]=s;
	for(j=0;j<a;j++){
        printf("%d",retu[j]);
	if(j!=a-1)printf(" ");}
	printf("\n");
    }
}



Measured memory_bytes: 2736
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r,d,x;
    cin >> r >> d >> x;
    REP(i,10){
        x=r*x-d;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, j, i, k, x, c;
int main(){
	scanf("%d%d%d", &x, &n, &m);
	for(i=n; i<=m; i++){
		if(i%x==0) c++;
	}
	if(c>0) printf("OK");
	else printf("NG");
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 400
#define offset 200
#define ptr nodo*
struct nodo
{
	map<char,ptr> hijos;	
	int mapa[30];
};
nodo basura[1200000];int cnodo=0;
ptr getnodo()
{	
	memset(basura[cnodo].mapa,0,sizeof basura[cnodo].mapa);
	return &basura[cnodo++];
}
int mapa[tam];
void add(ptr root)
{
	forr(i,0,27)
	{
		if (mapa[i]!=-1)
			root->mapa[i]++;
	}
}

void insertar(ptr root,string &txt)
{
	//<<txt<<endl;
	forr(i,0,txt.size())
	{
//		print();

		//<<root<<":";
		add(root);
		if (mapa[txt[i]]==i)
			mapa[txt[i]]=-1;
		if (root->hijos.find(txt[i])==root->hijos.end())
			root->hijos[txt[i]]=getnodo();
		
		root=root->hijos[txt[i]];
	}
	//<<endl<<endl;
}
ll tot=0;
void query(ptr root,string &txt)
{
	forr(i,0,txt.size()-1)
	{
		root=root->hijos[txt[i]];
	}
	tot+=max(0,root->mapa[txt.back()]-1);
	//<<int(txt.back())<<" "<<root->mapa[txt.back()]<<" ";

	//<<tot<<"endl\n";
}
int main()
{
	int n;
	cin>>n;
	vector<string> lst;
	ptr root=getnodo();
	forr(i,0,n)
	{
		string txt;
		cin>>txt;
		
			forr(j,0,txt.size())txt[j]-='a';

		reverse(all(txt));
		memset(mapa,-1,sizeof mapa);
		forr(j,0,txt.size())
				mapa[txt[j]]=j;
		insertar(root,txt);
		lst.pb(txt);
	}
	for(string txt:lst)
	{
		query(root,txt);
	}
	cout<<tot<<endl;
}				

Measured memory_bytes: 263760
let rec drop n ls =
    match ls with
    | x :: xs when n > 0 -> drop (n - 1) xs
    | _ -> ls

let update dp w v =
    let rec update_sub dp dp_w =
        match dp, dp_w with
        | _, [] -> dp
        | x :: dp', x_w :: dp_w' ->
            let m = max x (v + x_w) in
            m :: update_sub dp' dp_w'
        | _, _ -> failwith "failed"
    in update_sub dp (drop w dp)

let rec solve (ws, vs) weight dp =
    match (ws, vs) with
    | (w :: ws', v :: vs') -> solve (ws', vs') weight (update dp w v)
    | _ -> List.hd dp

let () =
    Scanf.scanf "%d %d\n" @@ fun n w ->
        let rec loop n =
            if n = 0 then ([], [])
            else Scanf.scanf "%d %d\n" @@ fun w v ->
                let (ws, vs) = loop (n - 1) in
                (w :: ws, v :: vs)
        in
        let ws, vs = loop n in
        let rec init n =
            if n = 0 then []
            else 0 :: init (n - 1)
        in
        Printf.printf "%d\n" @@ solve (ws, vs) w (init (w + 1))


Measured memory_bytes: 16032
import bisect

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

vector = []

i = 1
while i * i <= M:
    if M%i == 0:
        vector.append(i)
        vector.append(M//i)
    i+=1

vector.sort()

bottom = M//N
index = bisect.bisect_right(vector, bottom)

ans = vector[index-1]
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long mod=1000000007;
long long dp[2000][2000];
long h,w,a[2000][2000];
char c;
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>c;
			if(c=='.') a[i][j]=1;
			else a[i][j]=0;
		}
	}
	dp[1][1]=1;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(a[i][j]==1){
				if(a[i][j-1]==1) dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
				if(a[i-1][j]==1) dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			}
		}
	}
	cout<<dp[h][w];
}

Measured memory_bytes: 32512
#include <iostream>
using namespace std;
int main() {
  int H[100], W[100];
  int counter =100;
  for (int i=0; i <= 100; i++) {
    cin >> H[i] >> W[i];
    if (H[i] ==0 && W[i] == 0) {
      counter =i;
      break;
    }
  }
  for (int i=0;i <= counter-1; i++) {
    for(int j=1; j <= H[i]; j++) {
      for (int k=1; k <= W[i]; k++) {
	if (j == 1 || k	== 1 ||	j == H[i] || k == W[i])
          cout << "#";
	else
          cout << ".";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 2996
A,B,C,K = gets.split.map(&:to_i)  # スペースで区切られた複数の整数
A.freeze
B.freeze
C.freeze
K.freeze

wk = K
ans = 0
loop do
  #Aカード
  if wk - A > 0 then
    ans = ans + (1 * A)
    wk = wk - A
  elsif wk == 0 then
    ans = ans + (1 * A)
    break
  else
    ans = ans + (1 * K)
    break
  end
  #Bカード
  if wk - B > 0 then
    ans = ans + (0 * B)
    wk = wk - B
  elsif wk == 0 then
    ans = ans + (0 * B)
    break
  else
    ans = ans + (0 * wk)
    break
  end
  #Cカード
  if wk - C > 0 then
    ans = ans + (-1 * C)
    wk = wk - C
    break
  elsif wk == 0 then
    ans = ans + (-1 * C)
    break
  else
    ans = ans + (-1 * wk)
    break
  end
end
puts ans

Measured memory_bytes: 14272
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <memory.h>
using namespace std;
const int INF = 2 << 27;
#define ll long long
typedef pair<int,int> P;

static int dp[4][500001];


int main() {
  int n,r,t;
  cin >> n >> r >> t;
  int p[n];
  for(int i = 0; i < n; i++) cin >> p[i];

  int ans = 0;
  int ad[r];
  int bd[r];
  int now[n];
  for(int i = 0; i < n; i++) {
    now[i] = 0;
  }
  for(int i = 0; i < r; i++) {
    ad[i] = 0;
    bd[i] = 0;
  }
  for(int j = 0; j < n; j++) {
    now[j] = (now[j] + p[j]) % r;
  }
  for(int j = 0; j < n; j++) {
    ans++;
  }

  for(int i = 1; i < t; i++) {
    for(int j = 0; j < r; j++) {
      ad[j] += bd[j];
      bd[j] = 0;
    }
    for(int j = 0; j < n; j++) {
      now[j] = (now[j] + p[j]) % r;
      bd[now[j]]++;
      ad[now[j]]--;
      if(ad[now[j]] < 0) {
        ad[now[j]]++;
        ans++;
      }
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int N,M,Q;
int a[50],b[50],c[50],d[50];
int ans;
int A[10];
void dfs(int id,int pre)
{
	if(id==N)
	{
		int now=0;
		for(int i=0;i<Q;i++)if(A[b[i]-1]-A[a[i]-1]==c[i])now+=d[i];
		if(ans<now)ans=now;
	}
	else
	{
		for(int i=pre;i<=M;i++)
		{
			A[id]=i;
			dfs(id+1,i);
		}
	}
}
main()
{
	cin>>N>>M>>Q;
	for(int i=0;i<Q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
	dfs(0,1);
	cout<<ans<<endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long

void solve()
{
	int k;
	cin >> k;
	for (int c = 0; c < k; c++)
		cout << "ACL";
	cout << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	t = 1;
	for (; t > 0; t--)
		solve();
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

const int MAXN = 200005;
const int MAXLOG = 20;

int n;
int a[MAXN];

int table[MAXLOG][MAXN];
int logs[MAXN];

void computeLogs() {
  for (int i = 2; i <= n; i++) {
    logs[i] = logs[i / 2] + 1;
  }
}

void buildSparseTable() {
  for (int i = 0; i <= logs[n]; i++) {
    int curLen = 1 << i;
    for (int j = 0; j + curLen <= n; j++) {
      if (curLen == 1) {
        table[i][j] = a[j];
      } else {
        table[i][j] = min(table[i - 1][j], table[i - 1][j + (curLen / 2)]);
      }
    }
  }
}

int getMin(int l, int r) {
  int p = logs[r - l + 1];
  int pLen = 1 << p;
  return min(table[p][l], table[p][r - pLen + 1]);
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  computeLogs();
  buildSparseTable();


  int s=1;

  for(int i=1;i<n;i++){
     int z=getMin(0,i-1);

     if(z>=a[i])
        s++;

  }

  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

//////////

int a[10000];
int dp[3001][3001][2];

signed main()
{
    fastio;
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<n;++j)
        {
            if(i+j<n)
            {
                if(i==0){
                    dp[j][i][0]=a[j];
                    dp[j][i][1]=-a[j];
                }
                else{
                    dp[j][i][0]=max(dp[j][i-1][1]+a[i+j],dp[j+1][i-1][1]+a[j]);
                    dp[j][i][1]=min(dp[j][i-1][0]-a[i+j],dp[j+1][i-1][0]-a[j]);
                }
            }
        }
    }
    cout<<dp[0][n-1][0];
}

Measured memory_bytes: 139648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		int a = scan.nextInt(), b = scan.nextInt();
		n -= a;
		n -= n/b*b;
		out.println(n);
		out.close();
	}
	
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

		public int nextInt() {return Integer.parseInt(next());}

		public long nextLong() {return Long.parseLong(next());}

		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a = new long[n];
			for(int i = 0; i < n; i++) a[i] = nextLong();
			return a;
		}

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}

Measured memory_bytes: 23380
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
l = [0] * 3
ans = 1

for a in A:
    # print(l)
    ans *= l.count(a)
    for i in range(3):
        if l[i] == a:
            l[i] += 1
            break

print(ans% mod)

# print(l)


Measured memory_bytes: 14056
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    string s, t;
    cin >> s >> t;
    string tmp = t;
    REP(i, s.size()) {
        REP(j, s.size()) {
            if (i + j < s.size()) {
                tmp[j] = t[j + i];
            } else {
                tmp[j] = t[j + i - s.size()];
            }
        }
        if (tmp == s) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    ll k, a[112345], b[112345];

    ll m[112345];

    memset(m, 0, sizeof(m));

    cin >> n >> k;
    REP(i, n)
    {
        cin >> a[i] >> b[i];
        m[a[i]] += b[i];
    }

    ll res = 0;
    while (k > 0)
    {
        res++;
        k -= m[res];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS

//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb emplace_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 3e5 + 50, oo = 2e18 + 500;
//const int mod = 998244353;
const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-6, PI = 2 * acos(0.0);
int n, m, k;
long long cnt = 0;
int lg = 18;
vvi g;
//vi rg[N];
vi visit(N, 0);

void dfs(int v)
{
	visit[v] = 1;
	for (auto to : g[v])
	{
		if (visit[to])continue;
		dfs(to);
	}
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("rblock.in", "r", stdin);
	//freopen("rblock.out", "w", stdout);

	cin >> n >> m;

	g.resize(n + 1);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}

	for (int i = 1; i <= n; i++)
	{
		if (!visit[i])
		{
			dfs(i);
			cnt++;
		}
	}

	cout << cnt - 1;
}



Measured memory_bytes: 11852
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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 FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll X, Y; cin >> X >> Y;

    ll diff = abs(X-Y);
    if(diff<=1){
      p("Brown");
    }else{
      p("Alice");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

void insertionSort(int A[], int N){
  int j, i, v;
  for ( i = 1; i < N; i++){
    v = A[i];
    j = i - 1;
    while ( j >= 0 && A[j] > v ){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A, N);
  }
}

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

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

  trace(A, N);
  insertionSort(A, N);

  return 0;
}


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

int main(){
  string s;
  cin>>s;
  
  string s2;
  
  int count=0;
  int Max=0;
  for(int i=0;i<s.size();i++){
    count=0;
    for(int l=0;l<s.size();l++){
      if(s.at(i)==s.at(l)){
       count++; 
      }else{
        if(count<3){
          count=0; 
        }
      }
    }
    if(count>Max){
      Max=count;
    }
  }
  
  if(Max>=3){
   cout<<"Yes"<<endl; 
  }else{
   cout<<"No"<<endl; 
  }
}

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

struct edge
{
	int to, d;
};

vector<vector<edge>> g;
int b[100000];
int n, u, v;

int dfs(int v, int parent) {
	int res = 0;
	for (edge &ne : g[v]) {
		if (ne.to == parent) continue;
		ne.d = 1;
		int now = dfs(ne.to, v) + 1;
		res = max(res, now);
	}
	b[v] = res;
	return res;
}

int main() {
	cin >> n >> u >> v;
	u--; v--;
	g.assign(n, vector<edge>());
	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back({b, 0});
		g[b].push_back({a, 0});
	}
	dfs(v, -1);
	int dist = 0;
	for (int i = u; i != v; ) {
		for (edge e : g[i]) {
			if (e.d == 0) {i = e.to; break;}
		}
		dist++;
	}
	int ans = 0;
	while (dist > 2) {
		for (edge e : g[u]) {
			if (e.d == 0) {u = e.to; break;}
		}
		dist -= 2;
		ans++;
	}
	ans += dist + b[u] - 1;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    int n,l;
    cin >> n >> l;

    vector<string> s(n);
    for(int i=0; i<n; i++)
        cin >> s[i];
    sort(all(s));
    string sol;
    sol=s[0];
    for(int i=1; i<n; i++)
        sol+=s[i];
    cout << sol;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	string S;
	cin >> S;
	int odd_0 = 0, odd_1 = 0, even_0 = 0, even_1 = 0;
	for (auto i = 0u; i < S.size(); ++i)
	{
		if (i % 2)
		{
			if (S[i] == '0')
			{
				++odd_0;
			}
			else
			{
				++odd_1;
			}
		}
		else
		{
			if (S[i] == '0')
			{
				++even_0;
			}
			else
			{
				++even_1;
			}
		}
	}

	cout << min(odd_1 + even_0, odd_0 + even_1);
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
from bisect import bisect_left

def main():
    n=int(input())
    l=sorted(list(map(int,input().split())))
    ans=0
    for i in range(n-2):
        a=l[i]
        for j in range(i+1,n-1):
            ans+=bisect_left(l,a+l[j])-j-1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
ans = 0
for k in range(K, N+2):
    mi = (k - 1) * k // 2
    ma = (N + 1) * N // 2 - (N - k) * (N - k + 1) // 2
    ans += ma - mi + 1
print(ans % mod)



Measured memory_bytes: 10044
//  LINK ZADATKA: http://arc082.contest.atcoder.jp/tasks/arc082_b

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;


#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9

int p[MAXN], uvjet[MAXN], all, sol;
int main(){
	
	int n;
	scanf("%d", &n);
	
	REP(i, n){
		scanf("%d", &p[i]);
		if (p[i] == (i+1)){
			all++;
			uvjet[i+1] = 1;
		}
	}
	
	while(all){
		FOR(i, 1, n-1){
			if(uvjet[i] == 1 && uvjet[i+1] == 1){
				uvjet[i] = uvjet[i+1] = 0;
				p[i-1] ^= p[i];
				p[i] ^= p[i-1];
				p[i-1] ^= p[i];
				all -= 2;
				sol++;
			}	
		}
		FOR(i, 1, n-1){
			if(uvjet[i] == 1 && uvjet[i+1] == 0){
				if(p[i] != i && p[i-1] != i+1){
					uvjet[i] = uvjet[i+1] = 0;
					p[i-1] ^= p[i];
					p[i] ^= p[i-1];
					p[i-1] ^= p[i];
					all--;
					sol++;
				}
			}
			if(uvjet[i] == 0 && uvjet[i+1] == 1){
				if(p[i] != i && p[i-1] != i+1){
					uvjet[i] = uvjet[i+1] = 0;
					p[i-1] ^= p[i];
					p[i] ^= p[i-1];
					p[i-1] ^= p[i];
					all--;
					sol++;
				}
			}		
		}
	}
	//REP(i, n) printf("%d ", uvjet[i]);
	//printf("\n");
	//REP(i, n) printf("%d ", p[i]);
	printf("%d\n", sol);
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long N, std::vector<long long> B){
    ll ans = 0;
    ans += B[0];
    ans += B[N-2];
    for (int i = 0; i < N-2; i++)
    {
        ans += min(B[i],B[i+1]);
    }
    cout << ans << endl;
    
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(B));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int sz = 1e6+5;
ll int arr[sz], arr1[sz];
//ll int arr[100][100]= {0};
bool prime[sz]= {0};
vector <ll int> pr,vec1,vec2;
//vector <pair <int,int>> vec;

int main()
{
    string s,s1;
    cin>>s>>s1;
    int k =0;
    for (int i=0;i<s.size();i++)
    {
        if(s[i]!=s1[i])
            k++;
    }

    cout<<k<<endl;
}


Measured memory_bytes: 3920
# Node
class Node
  attr_accessor :id, :edges, :visited, :cost

  def initialize(id, edges = [], visited = false, cost = nil)
    @id, @edges, @visited, @cost = id, edges, visited, cost
  end
end

# Edge
class Edge
  attr_accessor :to

  def initialize(to)
    @to = to
  end
end

# Graph
class Graph
  attr_accessor :nodes

  def initialize(data)
    @nodes = data.map do |id, edges|
      edges.map! { |edge| Edge.new(*edge) }
      Node.new(id, edges)
    end
  end

  def bfs(start)
    @nodes.each do |node|
      if node.id == start
        node.visited = true
        node.cost = 0
      else
        node.visited = false
        node.cost = -1
      end
    end

    queue = []
    queue << @nodes.find { |node| node.id == start }
    # queue = [start]

    # count = 0
    while queue.any?
      node = queue.shift
      node.visited = true
      node.edges.each do |edge|
        id = edge.to
        visited_node = @nodes.find { |item| item.id == id }
        unless visited_node.visited
          visited_node.cost = node.cost + 1 if visited_node.cost == -1
          queue << visited_node
        end
      end
    end
  end
end

n = gets.chop.to_i

data = {}

n.times do
  u, k, *v = gets.chop.split.map(&:to_i)
  data[u] = v
end

g = Graph.new data
g.bfs(1)

g.nodes.each do |node|
  puts "#{node.id} #{(node.visited) ? node.cost : -1}"
end

Measured memory_bytes: 6652
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力                                                                                                                              
        int N = sc.nextInt();
        // スペース区切りの整数の入力                                                                                                              
        int a = sc.nextInt();
        System.out.println((N*N-a));
    }
}


Measured memory_bytes: 21716