akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n';
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<int> z_algorithm(const string& s) {
    int n = s.size();
    vector<int> p(n, 0);
    p[0] = n;
    int i = 1;
    int j = 0;
    while (i < n) {
        while (i + j < n && s[j] == s[i + j]) j++;
        p[i] = j;
        if (j == 0) {
            i++;
            continue;
        }
        int k = 1;
        while (i + k < n && k + p[k] < j) {
            p[i + k] = p[k];
            k++;
        }
        i += k; j -= k;
    }
    return p;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    REP(i, n) {
        auto z = z_algorithm(s.substr(i));
        FOR(j, i + 1, n) {
            if (z[j - i] <= j - i) chmax(ans, z[j - i]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




// https://atcoder.jp/contests/sumitrust2019/submissions/8739342
// youtube解説の通り

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    vector<ll> dp(100005);
    dp[0] = 1;
    int col = 3;
    vector<int> bc(n); // その個数のとこに何色あるか
    
    rep(i, n) {
        if (a[i] == 0) { // elseでa[i] - 1不可
            dp[i + 1] = dp[i] * col % inf;
            col--;
        } else {
            dp[i + 1] = dp[i] * bc[a[i] - 1] % inf;
            bc[a[i] - 1]--;
        }
        bc[a[i]]++;
    }
    cout << dp[n] << endl;
}

/*
 本質的な情報は何か
 
 最初
 0個 : 3色
 
 次 0
 0個 : 2色
 1個 : 1色
 
 次 1
 0個 : 2色
 1個 : 0色
 2個 : 1色
 
 
 */


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int n = 5;
  int a[n], b[n];
  for(int i = 1; i < 6; i++){
    a[i] = i;
    cin >> b[i];
    if(a[i] != b[i]){
      cout << i <<"\n";
      return 0;
  }
  }
}

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

typedef long long ll;

tuple<bool, int, int> check(vector<int>& x, vector<int>& y, vector<ll>& h, ll height)
{
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            bool ok = true;
            for (int k = 0; k < h.size(); k++) {
                ll hh = max(height - abs(x[k] - j) - abs(y[k] - i), 0LL);
                if (h[k] != hh) {
                    ok = false;
                    break;
                }
            }
            if (ok) return make_tuple(true, j, i); // ok, cx, cy
        }
    }
    return make_tuple(false, 0, 0);
}

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<ll> h(n);
    ll max_height = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
        max_height = max(max_height, h[i]);
    }
    for (ll height = max_height; height <= max_height + 200; height++) {
        tuple<bool, int, int> t = check(x, y, h, height);
        if (get<0>(t)) {
            cout << get<1>(t) << " " << get<2>(t) << " " << height << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 12.08.2020 00:19:05
*/

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


int main(){
    string s;
    int h,w;
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            cin >> s;
            if(s=="snuke"){
                cout << char('A'+j) << 1+i << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3620
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    if N > M:
        N, M = M, N
    ret = 0
    if N == 1:
        if M == 1:
            ret = 1
        else:
            ret = M - 2
    else:
        ret = (N - 2) * (M - 2)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


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

int main(void)
{
	char a[100], b[100];
	int i, j, num, equal = 0;
	scanf("%s", a);
	scanf("%s", b);
	i = strlen(a);
	j = strlen(b);
	if (i > j){
		equal++;
		printf("GREATER");
	}
	else if(i < j){
		printf("LESS");
		equal++;
	}
	else {
		for(num = 0; num < i; num++){
			if (a[num] > b[num]){
				printf("GREATER");
				equal++;
				break;
			}
			else if(a[num] < b[num]){
				printf("LESS");
				equal++;
				break;
			}
			else
				continue;
		}
	}
	
	if(!equal)
		printf("EQUAL");
	return 0;
}

Measured memory_bytes: 128
x, y = map(int, input().split())

if x < 0 and y < 0:
  if x > y:
    print(abs(y)-abs(x)+2)
  else:
    print(abs(x)-abs(y))
elif x < 0 and y >= 0:
  if y == 0:
    print(abs(x))
  elif abs(x) == abs(y):
    print(1)
  elif abs(x) < abs(y):
    print(y - abs(x) + 1)
  else:
    print(abs(x) - y + 1)
elif x >= 0 and y < 0:
  if x == 0:
    print(abs(y)+1)
  elif abs(x) == abs(y):
    print(1)
  elif abs(x) < abs(y):
    print(abs(y)-abs(x)+1)
  else:
    print(abs(x)-abs(y)+1)
elif x >= 0 and y >= 0:
  if x > y:
    if y == 0:
      print(abs(x) + 1)
    else:
      print(abs(x)-abs(y)+2)
  else:
    print(y-x)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	string  s; cin>>s;
	int fh = (s[0]-48)*10 + (s[1]-48);
	int sh = (s[2]-48)*10 + (s[3]-48);
	if(fh&&sh&&fh<13&&sh<13)
		cout<<"AMBIGUOUS\n";
	else if(sh&&sh<13)
		cout<<"YYMM\n";
	else if(fh&&fh<13)
		cout<<"MMYY\n";
	else 
		cout<<"NA\n";
	return 0;
}

Measured memory_bytes: 256
import sys
from string import ascii_lowercase

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    ans = []
    while N:
        N, r = N // 26, N % 26
        if r == 0:
            r = 26
            N -= 1
        ans.append(ascii_lowercase[r - 1])

    print(''.join(reversed(ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9784
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++) 
#define all(v) v.begin(),v.end()
#define F first
#define S second
ll fun(string s)
{
	ll res=0;
	for(int i=0;i<s.length();i++)
	{
		res+=(s[i]-'0');
	}
	return res;
}
void solve()
{
	string s;
	cin>>s;
	if(fun(s)%9==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}
int main()
{
//	ios_base::sync_with_stdio(false); 
  //  cin.tie(NULL);  
	int t;
	t=1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3828
#include <stdio.h>
 
int main(void)
{
  int x;
  int a, b, c, sum;
  scanf("%d", &x);
  a=x/500*1000;
  b=x%500;
  c=b/5*5;
  sum=a + c;
  printf("%d \n", sum);
  
  return 0;
}

Measured memory_bytes: 128
while ((n,x = gets.split(" ").map(&:to_i)) != [0,0]) do
  max = 3*(n-1)
  if !((6..max).include?(x))
    puts 0
    next
  end
  count = 0
  catch(:stop) do
    n.downto(1) do |n1|
      (n1-1).downto(1) do |n2|
        n3 = x - n1 - n2
        count += 1 if (n3 < n2) && (n3 > 0)
        throw :stop if (n3 > n1)
        break if (n3 > n2)
      end
    end
  end
  puts count
end

Measured memory_bytes: 8612
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

#define MAX (1<<24)

int main()
{
	string s;
	while(getline(cin,s))
	{
		string str(s), sb;
		while(getline(cin, s))
		{
			if(s.size()==0) break;
			str+=s;
		}

		if(str.size()==0) break;

		while(getline(cin, s))
		{
			if(s.size()==0) break;
			sb+=s;
		}


		int ansl=MAX, ret=0;
		string ans;
		map<char, int> d;
		for(int i=0; i<str.size(); i++)
		{
			string::iterator it=find(sb.begin(), sb.end(), str[i]);
			if(it==sb.end()) continue;

			d[*it]=i;
			int mi=MAX;
			bool f=true;
			for(int j=0; j<sb.size(); j++)
			{
				if(!d.count(sb[j]))
				{
					f=false;
					break;
				}
				mi=min(mi, d[sb[j]]);
			}

			if(!f) continue;
			
			if(i-mi < ansl)
			{
				ret=1;
				ansl=i-mi;
				ans.assign(str,mi,ansl+1);
			}
			else if(i-mi == ansl)
			{
				ret++;
			}
			
		}

		cout << ret << endl;
		if(ret!=0)
		{
			for(int i=0; i<ans.size(); i++)
			{
				if(i%72==0) cout << endl;
				cout << ans[i];
			}

			cout << endl;
		}

		cout << endl;
	}
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,s[100001],n;
int main(void){
	s[0]=1;
	cin>>n;
	for(ll i=0;i<6;i++){
		a=100+i;
		for(int j=0;j<=100000;j++){
			if(s[j]==1&&a+j<=100000){
				s[j+a]=1;
				if(j+a==n){
					cout<<1<<endl;
					return 0;
				}
			}
			else if(j+a>100000)break;
		}
	}
	cout<<0<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
 
int answer(char ch[])
{
    int sum = 0;
    int i;
     
    for(i=0;;i++){
        if(ch[i] == 0){
            break;
        }
        sum += ((int)ch[i]-48);
    }
     
    return sum;
}
int main()
{
    char ch[1001];
     
    while(1){
     
        scanf("%s",ch);
         
        if(answer(ch) == 0){
            break;
        }
     
        printf("%d\n",answer(ch));
 
    }
    return 0;
}


Measured memory_bytes: 2136
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+4;
int n,a[N];
bool f[N];
int main() {
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	f[0]=true;
	for (register int i=1;i<=n;++i)
		f[a[i]]=f[a[i]-1];
	int left=0;
	for (register int i=n;i;--i)
		if (f[i]) {
			left=i;
			break;
		}
	printf("%d\n",left?n-left:-1);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	ll i=1;
	while(true){
		if(i*(i+1)/2>=n){
			cout << i << endl;
			return 0;
		}
		i++;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
int main()
{
 long int x,y,i;

scanf("%ld%ld",&x,&y);

if((x+y)%3==0 || (x*y)%3==0 )
{
    printf("Possible");
}else{
    printf("Impossible");
}
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int a[5001], ans = -114514;
		for (int i = 0; i < n; i++)cin >> a[i];
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			for (int j = i; j < n; j++) {
				cnt += a[j];
				if (ans < cnt)ans = cnt;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

void swap(int& x, int& y){
	int tmp = x;
	x=y;
	y=tmp;
}

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	if(a>b) swap(a,b);
	
	cout << a << " " << b << " "  << c << endl;
}


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

using namespace std;

#define ll                  long long
#define vi                  vector<int>
#define vl                  vector<ll>
#define pii                 pair<int, int>
#define vvi                 vector<vi>
#define vvl                 vector<vl>
#define all(x)              x.begin(), x.end()
#define contains(con, x)    con.find(x) != con.end()
#define fastread            ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)


int main() {
    fastread;

    int T = 1;
    // cin >> T;

    while (T--) {
        int s, w;
        cin >> s >> w;

        if (w >= s) cout << "unsafe\n";
        else cout << "safe\n";
    }

}

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

template <typename T>
struct BIT {
	int n;
	vector<T> value;
	BIT(int n): n(n), value(n + 1){}
	
	void add(int k, T x){
		while (k <= n){
			value[k] += x;
			k += k & -k;
		}
	}
	
	T sum(int k){
		T s = 0;
		while (k){
			s += value[k];
			k -= k & -k;
		}
		return s;
	}
	
	void add(int s, int t, T x){
		add(t, x);
		if (s > 1) add(s - 1, -x);
	}
	
	T sum(int s, int t){
		return sum(t) - sum(s - 1);
	}
};

typedef long long lint;
const lint MOD = 1e9 + 7;
lint fact[100001];

int main()
{
	fact[0] = 1;
	for (int i = 1; i <= 100000; i++){
		fact[i] = (fact[i - 1] * i) % MOD;
	}
	
	int n, r;
	while (scanf("%d", &n), n){
		vector<int> v(n);
		BIT<lint> bit(n);
		for (int i = 0; i < n; i++){
			v[i] = i + 1;
			bit.add(i + 1, 1);
		}
		
		scanf("%d", &r);
		for (int i = 0; i < r; i++){
			int s, t;
			scanf("%d %d", &s, &t);
			swap(v[--s], v[--t]);
		}
		
		lint res = 0;
		for (int i = 0; i < n; i++){
			bit.add(v[i], -1);
			res += (bit.sum(v[i]) * fact[n - i - 1]);
			res %= MOD;
		}
		
		printf("%lld\n", res);
	}
	
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  long long ans = 0;

  vector<pair<int, int>> AB(N);
  for(int i = 0; i < N; i++)
  {
    cin >> AB.at(i).first >> AB.at(i).second;
  }
  
  sort(AB.begin(), AB.end());

  for(int i = 0; i < N; i++)
  {
    for(int j = 0; j < AB.at(i).second; j++)
    {
      if(M <= 0){
        break;
      }
      ans += AB.at(i).first;
      M--;
    }
    if(M <= 0){
      break;
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 101;
const int MAXW = 1e5 + 1;

int n, c;
int w[MAXN], v[MAXN];
ll dp[MAXN][MAXW];

int main(){

    cin >> n >> c;
    for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];

    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= c; j++){
            if (w[i] > j) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
        }
    }

    cout << dp[n][c];

    return 0;

}


Measured memory_bytes: 78336
a,b,k = map(int,input().split())

x = []

for i in range(0,k):
  if(a+i < a or b-i > b or a+i > b or b-i < a):
    continue
  else:
    if(a+i not in x and b-i not in x):
      if(a+i != b-i):
        x.append(a+i)
        x.append(b-i)
      else:
        x.append(a+i)
  
  
x.sort()  

for i in range(0,len(x)):
  print(x[i])
  

Measured memory_bytes: 38384
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var n=arr.shift()-0;
   if(n==0)break;
   var wh=arr.shift()-0;
   var obj=[];
   var ary=[];
   for(var i=0;i<n;i++){
      var data=arr.shift().split(" ");
      var name=data[0];
      var link=data[1]-0;
      obj[name]=[];
      if(i==0)ary.push(name);
      for(var j=0;j<link;j++)obj[name].push(arr.shift().split(" "));
   }
   var m=arr.shift()-0;
   var now=0;
   while(m--){
      var M=arr.shift().split(" ");
      if(M[0]=="show")console.log(ary[now]);
      else if(M[0]=="back"){
         now=Math.max(0,now-1);
      }else if(M[0]=="forward"){
         now=Math.min(now+1,ary.length-1);
      }else if(M[0]=="click"){
         var X=M[1]-0;
         var Y=M[2]-0;
         obj[ary[now]].forEach(function(v){
            var x1=v[0]-0;
            var y1=v[1]-0;
            var x2=v[2]-0;
            var y2=v[3]-0;
            if(x1<=X && X<=x2 && y1<=Y && Y<=y2){
               ary.length=now+1;
               ary.push(v[4]);
               now=ary.length-1;
            }
         });
      }
   }
}

Measured memory_bytes: 18028
from operator import itemgetter
import sys
input = sys.stdin.buffer.readline

class SegmentTree:
    """一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
    build(array)   := arrayを初期値とするセグメント木を構築する O(N)。
    update(i, val) := i番目の要素をvalに変更する。
    get_val(l, r)  := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
    """
    def __init__(self, n, op, e):
        """要素数、二項演算、単位元を引数として渡す
        例) 区間最小値 SegmentTree(n, min, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 2 ** ((n - 1).bit_length())
        self.node = [self.e] * (2 * self.size)

    def build(self, array):
        """arrayを初期値とするセグメント木を構築する"""
        for i in range(self.n):
            self.node[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])

    def update(self, i, val):
        """i番目の要素をvalに変更する"""
        i += self.size
        self.node[i] = val
        while i > 1:
            i >>= 1
            self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])

    def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res_l, res_r = self.e, self.e
        while l < r:
            if l & 1:
                res_l = self.op(res_l, self.node[l])
                l += 1
            if r & 1:
                r -= 1
                res_r = self.op(self.node[r], res_r)
            l, r = l >> 1, r >> 1
        return self.op(res_l, res_r)


h, w, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]


cnt_h = [0] * h
cnt_w = [0] * w
memo_i = {}
for i in range(h):
    memo_i[i] = []

for i, j in info:
    i -= 1
    j -= 1
    cnt_h[i] += 1
    cnt_w[j] += 1
    memo_i[i].append(j)


st = SegmentTree(w, max, 0)
st.build(cnt_w)


ans = 0
for i in range(h):
    for j in memo_i[i]:
        st.update(j, cnt_w[j] - 1)
    ans = max(st.get_val(0, w) + cnt_h[i], ans)
    for j in memo_i[i]:
        st.update(j, cnt_w[j])

print(ans)

Measured memory_bytes: 173664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double n =  Double.parseDouble(sc.next());
		double ans = 0;		
		double a = Math.ceil(n/2);
		ans = (double)a / n ;
		
		System.out.println(ans);
		
	}



}

Measured memory_bytes: 23124
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())

  a=s[:len(s)//2]
  if len(s)%2==0:
    b=s[len(s)//2:]
  else:
    b=s[len(s)//2+1:]

  # print(a)
  # print(b)

  ans=0
  a.reverse()

  for i in range(len(s)//2):
    x=a[i]
    y=b[i]

    if x!=y:
      ans+=1

  return ans

# main()
print(main())


Measured memory_bytes: 7844
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y;
if(x>y)std::cout << x-1 << '\n';
else std::cout << x << '\n';
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int k = Integer.parseInt(param[1]);
			
			int max = 0;
			int sum = 0;
			int[] loads = new int[lim];
			for (int i = 0; i < lim; i++) {
				loads[i] = Integer.parseInt(in.readLine());
				sum = sum + loads[i];
				
				if (max < loads[i]) max = loads[i];
			}
			
			int start = (int)Math.ceil((double)sum / k);
			if (start < max) start = max;

			while (true) {
				int count = 0;
				
				int tmp = 0;
				for (int i = 0; i < loads.length; i++) {
					tmp = tmp + loads[i];
					
					if (tmp > start) {
						count++;
						tmp = loads[i];
					}
				}
				
				if (count < k) {
					System.out.println(start);
					break;
				}
				start++;
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int BT=18;
int dp[1<<BT][2]; 

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	for(int i=0; i<(1<<n); i++)cin >> dp[i][1];
	for(int i=0; i<n; i++){
		for(int mask=0; mask < (1<<n); mask++){
			if(!dp[mask][1])continue;
			if(mask>>i&1){
				dp[mask][0]=max(dp[mask][0],dp[mask^(1<<i)][1]);
				if(dp[mask][0]>dp[mask][1])swap(dp[mask][0],dp[mask][1]);
			}
		}
	}
	int res = 0;
	for(int i=1; i<(1<<n); i++){
		res = max(res,dp[i][0]+dp[i][1]);
		cout << res << endl;
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

class Main {
    int S;
    vector<int> used;
    vector<mint> memo;
    mint dfs(int ret) {
        if (used[ret]) return memo[ret];
        if (ret == 0) return memo[ret] = 1;
        used[ret] = true;
        mint res = 0;
        for (int j = 3; ret - j >= 0; ++j) { res += dfs(ret - j); }
        return memo[ret] = res;
    }
    void input() { cin >> S; }
    void output() {
        used.resize(S + 1);
        memo.resize(S + 1);
        cout << dfs(S) << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 900000000000000
signed main(){
    int n;cin>>n;
    vector<int>dis(100010,0);
    int ma=0;
    rep(i,n){
        int x;cin>>x;
        if(i==0){
            if(x!=0){
                cout<<0<<endl;
                return 0;
            }
        }
        ma=max(ma,x);
        dis[x]++;
    }
    int count=0;
    rep(i,100009){
        if(dis[i]!=0&&dis[i+1]==0)count++;
    }
    if(count>1||dis[0]!=1){
        cout<<0<<endl;
        return 0;
    }
    int ans=1;
    rep(i,ma){
        rep(j,dis[i+1]){
            ans=ans*dis[i]%MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
    
    
    
}
        

Measured memory_bytes: 1024
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define f(i,n) for(ll i=0;i<n;i++)
    #define rf(i,n) for(ll i=n-1;i>=0;i--)
    #define f2(i,n) for(ll i=1;i<=n;i++)
    #define endl "\n"
    #define vll vector <ll>
    #define sz(a) (ll)a.size()
    #define all(a) (a).begin(),(a).end()
    #define mod 1000000007
    #define pb push_back
    const ll inf =1e13+5;

    typedef pair<ll,ll> pll;

    ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
    ll lcm(ll a, ll b){return a*b/gcd(a, b);}
    ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod; b/=2;a=a*a%mod;}return ans;}
    ll inverse(ll a, ll p){return fexp(a, p-2);}

    void solve(){
        ll n;cin>>n;
        ll k;cin>>k;
        vll a(n+1);
        for(int i=1;i<=n;i++)cin>>a[i];

        vector<vector<ll>>dp(n+1,vector<ll>(k+1,0));
        vector<ll>sum(k+1,0);
        dp[0][0]=1;
        for(int j=1;j<=k;j++)dp[0][j]=0;
        for(int i=1;i<=n;i++)dp[i][0]=1;

        for(int i=1;i<=n;i++){
            sum[0]=dp[i-1][0];
            for(int j=1;j<=k;j++){
                sum[j]=dp[i-1][j]+sum[j-1];
            }
            // f(temp,k+1)cout<<sum[temp]<<" ";
            for(int j=1;j<=k;j++){
                ll left=max((ll)0,j-a[i]);
                ll right=j;
                dp[i][j]=sum[right]-sum[left]+dp[i-1][left];
                dp[i][j]%=mod;
            }
        }
        cout<<dp[n][k]<<endl;

    }
    
    

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

        ll t;
        t=1;
        // cin>>t;
        while(t--){
           solve();
        }
       

        // #ifndef ONLINE_JUDGE
        // cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
        // #endif

        
        return 0;
    }

Measured memory_bytes: 83172
//借鉴李睿琛同学
#include<iostream>

using namespace std; 

int main()
{
	int N,K;
	char a[100000];
	cin>>N;
	cin>>K;
	for(int i=0;i<N;i++)
	{
		cin>>a[i];
	}	
	int m=1;
	char n=a[0];
	for(int i=0;i<N;i++)
	{
		
		if(n==a[i]);
		else {
			m++;
			n=a[i];		
		}
	}
	int M=N-m;
	for(int j=K;K>0;K--)
	{
		m-=2;
		if(m>0) M+=2;
		else if(m<0) break;
		 else
			{
			M+=1;
			break;
			} 			
	}
	cout<<M;
	return 0;
 } 

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

//library----------------------------------------------


int main(){
    CIN(k,x);
    if(k==1) printf("%d\n",x);
    else if(k>1){
        RepS(i,x-k+1,x+k-1) printf("%d ",i);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
	int	num1;
	int	num2;

	scanf("%d", &num1);
	scanf("%d", &num2);
	if (num1 + num2 >= 10)
	{
		printf("error");
		return 0;
	}
	printf("%d", num1 + num2);
	return 0;
}

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

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; }

using ll = long long;
using P = pair<ll,ll>;
using grid = vector<vector<int>>;

const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
const int INF = 1<<30;
const ll mod = 998244353LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int N;
    cin>>N;
    cout<<(N-1)/2+1<<endl;
}

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

using namespace std;

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

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

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

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
int n;

int number(int &pos) {
	int res = 0;
	while (s[pos] != ']') {
		res *= 10;
		res += (s[pos] - '0');
		pos++;
	}
	pos++;
	return res / 2 + 1;
}

int solve(int &pos) {
	//cout << "!" << pos << endl;
	if (s[pos] == '[') {
		vector<int> vi;
		while (s[pos] == '[') {
			pos++;
			vi.push_back(solve(pos));
		}
		sort(ALL(vi));
		//rep(i, vi.size())cout << "!" << vi[i];
		//cout << endl;
		int res = 0;
		rep(i, vi.size() / 2 + 1)res += vi[i];
		pos++;
		return res;
	}
	return number(pos);
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> s;
		int pos = 0;
		cout << solve(pos) << endl;
	}
}


Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
int main() {
	string W;
	int m;
	int h;
	int k;
	int n;
	while (1) {
		h = 0;
		cin >> W;
		n = W.size();
		if (W == "-")break;
		W = W + W;
		cin >> m;
		for (int i = 0;i < m;i++) {
			cin >> k;
			h = h + k;
		}
		h = h % n;
		for (int j = h;j < h + n;j++) {
			cout << W[j];
		}cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int kin,sum;
	while(1)
	{
		cin>>kin;
		if(kin==0)
			break;
		kin=1000-kin;
		sum=kin/500+(kin%500)/100+(kin%500%100)/50+(kin%500%100%50)/10+(kin%500%100%50%10)/5+(kin%500%100%50%10%5);
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3004
#include<iostream>
using namespace std;
#define W 10+2+2
#define H 10+2+2

int main()
{
  int field[W][H]={0},x,y,size,max,cnt,i,j;
  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
    x+=2;y+=2;
    if(size==1){
      field[x][y]++;
      field[x-1][y]++;
      field[x+1][y]++;
      field[x][y-1]++;
      field[x][y+1]++;
    }else if(size==2){
      field[x][y]++;
      field[x-1][y]++;
      field[x+1][y]++;
      field[x][y-1]++;
      field[x][y+1]++;
      field[x-1][y-1]++;
      field[x-1][y+1]++;
      field[x+1][y-1]++;
      field[x+1][y+1]++;
    }else{
      field[x][y]++;
      field[x-1][y]++;
      field[x+1][y]++;
      field[x][y-1]++;
      field[x][y+1]++;
      field[x-1][y-1]++;
      field[x-1][y+1]++;
      field[x+1][y-1]++;
      field[x+1][y+1]++;
      field[x-2][y]++;
      field[x+2][y]++;
      field[x][y-2]++;
      field[x][y+2]++;
    }
  }
  max=0;
  cnt=0;
  for(i=2;i<12;i++)for(j=2;j<12;j++){
    cnt+=field[i][j]==0;
    if(max<field[i][j])max=field[i][j];
  }
  cout<<cnt<<endl<<max<<endl;
}

Measured memory_bytes: 0
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(min(k,500)):
    ans=[0]*(n)
    for j in range(n):
        l=max(0,j-a[j])
        r=j+1+a[j]
        ans[l]+=1
        if r<n:
            ans[r]-=1
    for z in range(n-1):
        ans[z+1]+=ans[z]
    a=ans
print(" ".join(list(map(str,ans))))

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

int main() {
  int year, month, date;
  char s1, s2;
  cin >> year >> s1 >> month >> s2 >> date;
  if (month < 5) {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#include<ctype.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b

int main() {
	int w, d,ans=0;
	for (; ~fscanf(stdin, "%d%d", &w, &d), w, d;P(d,ans)) {
		int a[21] = {},
			i=0,b;
		ans = 0;
		for (; i < w; i++) {
			S(d, b);
			a[b]++;
			ans += b;
		}
		for (i = 0; i < d; i++) {
			S(d, b);
			if (a[b]) a[b]--;
			else ans += b;
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const int MAX= 4e5+6;
const ll inf =1e18;
 
 

ll a[MAX];
int main(){
	fastio;
	ll k,n,m,q,b,c,ans=0;
	string s;
	cin>>n>>k;
	f(i,1,k+1){
		cin>>c;
		f(i,0,c){
			cin>>q;
			a[q]=1;
		}
	}
	f(i,1,n+1) if(a[i]==0) ans++;
	cout<<ans<<endl;
	
}

Measured memory_bytes: 3652
S = list(input())
f = False
c = 0

for i  in range(len(S) - 1):
    # if i == len(S) - 2:
    #     break
    if S[i] != S[i + 1]:
        continue
    else:
        if S[i] == "0":
            S[i+1] = "1"
            c += 1
        else:
            S[i+1] = "0"
            c += 1

print(c)

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N;
  cin >> N;
  cout << 800 * N - (N / 15) * 200 << endl;
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int MAX=1000000007;
int n,k,a[100010],num[100010],inv[100010],ans;
int exgcd(int t1,int t2,int &x,int &y) {
	if(!t2) {
		x=1,y=0;
		return t1;
	}
	int tmp=exgcd(t2,t1%t2,y,x);
	y-=x*(t1/t2);
	return tmp;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	num[1]=1;inv[0]=1;
	for(int i=2;i<=n;++i) num[i]=(ll)num[i-1]*i%MAX;
	int tmp;
	exgcd(num[n],MAX,inv[n],tmp);
	inv[n]=(inv[n]%MAX+MAX)%MAX;
	for(int i=n-1;i>=1;--i) inv[i]=(((ll)(i+1)*inv[i+1])%MAX+MAX)%MAX;
	for(int i=k;i<=n;++i) {
		ans+=(ll)((ll)((ll)a[i]*num[i-1]%MAX)*inv[k-1]%MAX)*inv[i-k]%MAX;
		ans%=MAX;
	}
	for(int i=1;i+k-1<=n;++i) {
		ans-=(ll)((ll)((ll)a[i]*num[n-i]%MAX)*inv[k-1]%MAX)*inv[n-i-k+1]%MAX;
		ans=(ans%MAX+MAX)%MAX;
	}
	printf("%d",ans%MAX);
	return 0;
}

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

int main(){
  int n,maxnum=0;
  string s,base="abcdefghijklmnopqrstuvwxyz";
  cin>>n>>s;
  int c=1;
  vector<bool> flag(base.size());
  while(c<n-maxnum){
  for(int i=0;i<base.size();i++){
    for(int x=0;x<c;x++){
      if(s.at(x)==base.at(i)){
        flag[i]=true;
        break;
      }else flag[i]=false;
    }
    if(flag[i]){
    for(int z=c;z<n;z++){
      if(s.at(z)==base.at(i)) break;
      if(z==n-1) flag[i]=false;
    }
    }
  }
    int count=0;
  for(int i=0;i<base.size();i++){
    if(flag[i]) count++;
  }
    maxnum=max(maxnum,count);
    c++;
  }
  cout<<maxnum<<endl;
}

Measured memory_bytes: 256
import java.io.*; 
import java.util.*;
import java.util.Map.Entry;

public class Main {



	public static void main(String[] args) throws IOException {
		BufferedReader  jk =  new BufferedReader(new InputStreamReader( System.in))  ; 
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)) ; 
		StringTokenizer ana = new StringTokenizer(jk.readLine()) ;
		int  n =Integer.parseInt(ana.nextToken()) ; 
		int siz = Integer.parseInt(ana.nextToken())  ;
		int v[]= new int[n] ; long w []=new long[n] ; 
		for(int i=0 ; i<n ;i++)
		{
			ana = new StringTokenizer(jk.readLine()) ;
			w[i] = Long.parseLong(ana.nextToken()) ; 
			v[i]= Integer.parseInt(ana.nextToken())  ;
		}
		long dp[][]= new long[n][(n*1000)+1]  ;
		long big = (long) (Math.pow(10, 9)+4) ; 
		for(int i=0 ;i<n ;i++)
		{
			for(int j=0 ; j<=n*1000 ;j++) dp[i][j]=big ; 
		}

		dp[0][0]=0 ; dp[0][v[0]]= w[0]; 
		for(int i=1 ; i<n ;i++)
		{
			for(int ve=0 ;ve<=n*1000 ;ve++ )
			{
				long y = dp[i-1][ve] ; 
				if(y!=big)
				{
					dp[i][ve]= Long.min(dp[i][ve], dp[i-1][ve]) ;
					if(dp[i-1][ve]+w[i]<=siz) dp[i][ve+v[i]] = Long.min(dp[i][ve+v[i]], dp[i-1][ve]+w[i]) ; 
				}
			}
		}
		long res = 0 ;
		for(int j=1000*n ; j>=0 ;j--)
		{
			if(dp[n-1][j]!=big)
			{
				res = j ;  break ; 
			}
		}
		out.println(res);

		out.flush(); 
	}

}




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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  map<string, ll> m;
  rep(i, n) {
    in(string, s);
    sort(all(s));
    ++m[s];
  }
  ll ans = 0;
  for (const auto [_, cnt] : m) {
    if (cnt > 1) {
      ans += cnt * (cnt - 1) / 2;
    }
  }
  out(ans);
}


Measured memory_bytes: 11332
#include<stdio.h>
long long int dp[101][11][1001];
void solve() {
  int i, j, k;
  for (i = 0; i < 101; i ++) for (j = 0; j < 11; j ++) for (k = 0; k < 1001; k ++) dp[i][j][k] = 0;
  for (i = 0; i < 101; i ++) for (j = i; j > -1; j --) dp[i][1][j] = 1;
  for (i = 1; i < 101; i ++) {
    for (j = 2; j < 11; j ++) {
      for (k = 0; k < 1001; k ++) {
	dp[i][j][k] = dp[i - 1][j][k];
	if (i <= k) {
	  dp[i][j][k] += dp[i - 1][j - 1][k - i];
	}
      }
    }
  }
}
int main() {
  int n, s;
  solve();
  while (1) {
    scanf("%d %d", &n, &s);
    if(!(n||s)) break;
    printf("%lld\n", dp[100][n][s]);
  }
  return 0;
}

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

int main(void)
{
	char s[5];
	
	scanf("%s",s);
	
	int flag = 0;
	
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ){
		flag = 1;
	}
	
	if(flag){
		printf("Bad\n");
	}else{
		printf("Good\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
 
int main(){
    int i,j,flag=0;
    char s[256];
    while(fgets(s,sizeof(s),stdin)!=NULL){
        flag=0;
        for(i=1;i<=26;i++){
            for(j=0;j<strlen(s);j++){
                if(97<=s[j]&&s[j]<=122) {
                        if(s[j]+1>122) s[j]=(s[j]+1)%122+96;
                        else s[j]=s[j]+1;
                }
            }
            for(j=0;j<strlen(s);j++){
                if(s[j]=='t'){
                    if(!strncmp(s+j,"the",3)||!strncmp(s+j,"this",4)||!strncmp(s+j,"that",4)){
                        flag=1;
                    }
                }
            }
            if(flag) break;
        }
        printf("%s",s);
        memset(s,'\0',sizeof(s));
    }
    return 0;
}

Measured memory_bytes: 520
#include<stdio.h>
#include<string.h>
int main(void){
  char  s[100001];
  int i=0;
  int count=0;
  scanf("%s",&s);
  for(i=0;i<100000;i++){
    if(strncmp(&s[i],"1",1)==0)
    if(strncmp(&s[i],&s[i+1],1)==0){
      s[i+1]='0';
      count++;
    }

    if(strncmp(&s[i],"1",0)==0)
    if(strncmp(&s[i],&s[i+1],1)==0){
      s[i+1]='1';
      count++;
    }
    if(strncmp(&s[i+1],"\0",1)==0)break;
  }
  
  printf("%d",count);

    return 0;
}

Measured memory_bytes: 256
n,m=[int(i) for i in input().split()]
a=[]
for i in range(n):
    x,y=[int(i) for i in input().split()]
    a.append([x,y])
a.sort()
curr=0
ans=0
for i in range(len(a)):
    if(a[i][1]+curr>=m):
        ans+=(m-curr)*a[i][0]
        break
    else:
        ans+=a[i][0]*a[i][1]
        curr+=a[i][1]
print(ans)


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

using ll = long long;
using vll = vector<long long>;
using vi = vector<int>;

int solve(vi arr, int k){
  vi dp(arr.size(), INT_MAX);
  dp[0] = 0;
  for(int i = 1; i < arr.size(); i++){
    for(int j = max(0, i-k); j < i; j++){
      dp[i] = min(dp[i], dp[j]+abs(arr[j]-arr[i]));
    }
  }
  return dp[arr.size()-1];
}


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

  int n, k;
  cin >> n >> k;

  vi arr(n);
  for(auto &x: arr) cin >> x;
  cout << solve(arr, k) << endl;
  return 0;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll x,y,z; cin>>x>>y>>z;
    ll cnt=(x-z)/(y+z);
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3576