akhauriyash/Code-Regression huggingface dataset:
from collections import deque
h,w= map(int,input().split())
dist = [[-1 for _ in range(w)]for _ in range(h)]
y = [1,-1, 0, 0]
x = [0, 0, 1,-1]
graph = []
q = deque([(0,0)])
count = -2
for i in range(h):
    j = input()
    count += j.count(".")
    graph.append(j)
while q:
    v = q.popleft()
    for j in range(4):
        nh,nw = v[0]+y[j],v[1]+x[j]
        if nh < 0 or nh >= h or nw < 0 or nw >= w or graph[nh][nw] == "#" or dist[nh][nw] != -1:continue
        if nh == h-1 and nw == w-1:
            dist[nh][nw] = dist[v[0]][v[1]]+1
            break
        else:
            q.append((nh,nw))
            dist[nh][nw] = dist[v[0]][v[1]]+1
    else:continue
    break
else:print(-1);exit()
print(count-dist[h-1][w-1])

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll X, Y;
  cin >> X >> Y;

  ll leng = 0;
  ll bottom = X;

  while(bottom <= Y){
    leng++;
    bottom *= 2;
  }

  cout << leng << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    Tree = [0 for _ in range(N)]
    cnt = [0 for _ in range(N)]

    for _ in range(M):
        A, B = map(int, input().split())

        cnt[A - 1] += 1
        cnt[B - 1] += 1
        if H[A - 1] > H[B - 1]:
            Tree[A - 1] += 1
        elif H[B - 1] > H[A - 1]:
            Tree[B - 1] += 1
    answer = 0
    for i in range(N):
        if Tree[i] == cnt[i]:
            answer += 1
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    // 4x + 7y = n;
    for (int i = 0; i <= n/4; i++)
    {
        for (int j = 0; j <= n/7; j++)
        {
            if (4*i + 7*j == n)
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
s = input()

s1 = s
s2 = s[::-1]

start = 0
end = 0

for i in range(len(s1)):
    if s1[i] == 'A':
        start = i
        break

for i in range(len(s2)):
    if s2[i] == 'Z':
        end = len(s) - i
        break

print(end - start)

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;   
  cin >> S;
 if ( S.at(0)==S.at(1)){
   cout << "Bad";
 }
  else if ( S.at(1)==S.at(2)){
   cout << "Bad"; 
 }
  else if ( S.at(2)==S.at(3)){
   cout << "Bad"; 
 }
  else  {
    cout << "Good";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

int main(void) {
	int n; cin >> n;
	vi p(n); rep(i,n) cin >> p[i];
	vi pmin(n);
	pmin[0]=p[0];
	rep2(i,1,n) pmin[i]=min(pmin[i-1],p[i]);
//	rep(i,n) out(pmin[i]);
	int ans=0;
	rep(i,n){
		if(p[i]<=pmin[i]) ans++;
	}
	out(ans);
}




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

int main(){
	string s;
	cin >> s;
	int len = s.size();
	long long ans = 0;

	for(int bit = 0; bit < (1<<(len-1)); bit++)
	{	
		long long num = s[0] - '0';
		for(int i = 0; i < len-1; i++)
		{
			if(bit&(1<<i)){
				ans += num;
				num = 0;
			}
			num = num*10 + (s[i+1] - '0');
		}
		ans += num;		
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#B-Christmas Eve Eve
N = gets.chomp.to_i
P = []
sum = 0
for i in 0..N-1 do
    P[i] = gets.chomp.to_i
end
P[P.index(P.max)] = P.max / 2
for i in 0..N-1 do
    sum = sum + P[i]
end
puts sum

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

int main() {
  int N;
  cin >> N;

  vector<int> X(N);
  for(int i = 0; i < N; i++){
    cin >> X[i];
  }
  sort(X.begin(), X.end());
  int min = X[0];
  int max = X[N-1];
  
  int result = numeric_limits<int>::max();
  for(int i = min; i <= max; i++){
    int sum = 0;
    for(int j = 0; j < N; j++){
      int d =  pow((i - X[j]), 2);
      sum += d;
    }
    if (sum < result){
      result = sum;
    }
  }
  cout << result << endl;
}



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

int main() { 
  int n;
  cin >> n;
  
  int min = 1e9;
  

  vector<int> w(n);

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

  for (int t=1;t<n;t++){
    int s1=0, s2=0; //ループのたび初期化忘れずに！

    for(int i=0;i<n;i++){
      if(i<=t){ //iとw.at(i)区別すること
        s1 += w.at(i);
      }else{
        s2 += w.at(i);
      }
    }
    
    if (min > abs(s1-s2)) min = abs(s1-s2) ;
  }

  cout << min << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_8_C
{
    public class Program

    {
        public static void Main(string[] args)
        {

            string line;
            Dictionary<char,int> rlt = new Dictionary<char, int>();
            for (char i = 'a' ; i <= 'z' ; i++) rlt.Add(i, 0);

            while ((line = ReadSt()) != null)
            {
                for (int i = 0 ; i < line.Length ; i++)
                {

                    if (char.ToLower(line[i]) >= 'a' && char.ToLower(line[i]) <= 'z')
                    {
                        rlt[char.ToLower(line[i])]++;
                    }
                }
            }

            foreach (var item in rlt)
            {
                Console.WriteLine("{0} : {1}", item.Key, item.Value);
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 18064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  int n;
  cin>>n;
  ll arr[n];
  ll sum=0;
  for(int i=0;i<n;i++)
  {cin>>arr[i];
   sum+=arr[i];
  }
  ll table[n][n]; 
  
    // Fill table using above recursive formula. Note  
    // that the table is filled in diagonal fashion (similar 
    // to http:// goo.gl/PQqoS), from diagonal elements to 
    // table[0][n-1] which is the result. 
    for (int gap = 0; gap < n; ++gap) { 
        for (int i = 0, j = gap; j < n; ++i, ++j) { 
  
            // Here x is value of F(i+2, j), y is F(i+1, j-1) and 
            // z is F(i, j-2) in above recursive formula 
            ll x = ((i + 2) <= j) ? table[i + 2][j] : 0; 
            ll y = ((i + 1) <= (j - 1)) ? table[i + 1][j - 1] : 0; 
            ll z = (i <= (j - 2)) ? table[i][j - 2] : 0; 
  
            table[i][j] = max(arr[i] + min(x, y), arr[j] + min(y, z)); 
        } 
    } 
  
    cout<<2*table[0][n - 1]-sum; 
}

Measured memory_bytes: 70016
#include<stdio.h>
#include<math.h>

int main(void)
{
  
  int num;
  int result = 0;
  int i,j;
  double sqr;

  while(1){
    
    scanf("%d",&num);
    if(num == 0)
      break;
    
    for(i = num+1;i <= (2*num);i++){
      if(i == 2){
	result++;
	continue;
      }
      else if(i < 2 || (i % 2) == 0)
	continue;

      sqr = sqrt(i);
      for(j = 3;j < sqr ;j = j + 2){
	if((i % j) == 0)
	  break;
      }


      if(i != 3 && (i % j) == 0)
	continue;
      
      result++;
    }
    
    printf("%d\n",result);

    result = 0;
    
  }

  return 0;
}
    

Measured memory_bytes: 600
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();
	static Node[] V;

	public static void main(String[] args) {
		int n = sc.nextInt();
		int q = sc.nextInt();
		V = new Node[n];
		
		for(int i=0; i<n; i++) {
			V[i] = new Node(i);
		}
		
		StringBuilder ans = new StringBuilder();
		for(int i=0; i<q; i++) {
			int cmd = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			if(cmd == 0) {
				int x_parent = V[x].findParent();
				int y_parent = V[y].findParent();
				if(x_parent != y_parent) {
					V[y_parent].parent = x_parent;
				}
			} else {
				int x_parent = V[x].findParent();
				int y_parent = V[y].findParent();
				if(x_parent == y_parent) {
					ans.append("1\n");
				} else {
					ans.append("0\n");
				}
			}
		}
		
		System.out.print(ans);
	}
	
	static class Node {
		int id;
		int parent = -1;
		
		Node(int i) {
			id = i;
		}
		
		public int findParent() {
//			System.out.println(id);
			if(parent == -1) {
				return id;
			} else {
				int temp = V[parent].findParent();
				parent = temp;
				return parent;
			}
		}
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 60708
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Main {

	public static void main(String[] args) throws IOException {

		Character[] ch = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
				't', 'u', 'v', 'w', 'x', 'y', 'z' };
		int[] sum = new int[ch.length];

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str;

		while ((str = br.readLine()) !=null) {




		String[] str2 = str.split(" ");

		StringBuilder builder = new StringBuilder();

		List<Character> liststr = new ArrayList<>();

		for (String s : str2) {

			builder.append(s.toLowerCase());
		}
		for (int i = 0; i < builder.length(); i++) {

			liststr.add(builder.charAt(i));
		}

		Collections.sort(liststr);


		for(int i =0; i<ch.length; i++){
			for(int j=0; j<liststr.size(); j++){
				if(ch[i].equals(liststr.get(j))){
					sum[i] +=1;
				}

			}
		}
		}

		for(int i =0; i<ch.length; i++){
			System.out.print(ch[i]+" "+":"+" "+sum[i]+"\n");
		}


	}
}

Measured memory_bytes: 24796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
void selectionSort(vector<int> A, int N)
{
  int times = 0;
  rep(i, N)
  {
    int minj = i;
    for (int j = minj; j < N; j++)
    {
      if (A[j] < A[minj])
      {
        minj = j;
      }
    }
    if (i != minj) times++;
    swap(A[i], A[minj]);
  }

  rep(i, N)
  {
    if (i == N - 1)
    {
      cout << A[i];
    }
    else
    {
      cout << A[i] << " ";
    }
  }
  cout << "\n";
  cout << times << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N)
  {
    cin >> A[i];
  }
  selectionSort(A, N);
  return 0;
}


Measured memory_bytes: 3156
#coding:utf-8
#A,Bの上からi桁目のビットの組み合わせの数を求める
L = input()
lenL = len(L)
dp1 = [0] * lenL  #i桁目まででL未満になることが確定済みの組み合わせの数
dp2 = [0] * lenL  #i桁目まででA+BがLと一致している組み合わせの数、dp1[i+1]を求めるためにも利用
dp1[0] = 1 #0... となる数,最初の1桁目は(0,0)
dp2[0] = 2 #1... 

mod = 10**9 + 7
for i in range(1,lenL):
    
    dp1[i] = (3 * dp1[i-1]) % mod  #L未満であることは確定しているので(0,0),(1,0),(0,1)の3通り
    if L[i] == '1':
        dp2[i] = (dp2[i] + 2 * dp2[i-1]) % mod  #A+BをLと一致させるために(1,0),(0,1)の2通りをとる
        dp1[i] = (dp1[i] + dp2[i-1]) % mod  #Lのi桁目が1で(0,0)を選択した場合これ以降の桁(この桁を含む)でどんな組み合わせを選んでもL以下になることが確定
    else:
        dp2[i] = dp2[i-1]  #A+BをLと一致させるために(0,0)の1通り

print((dp1[-1] + dp2[-1]) % mod)

Measured memory_bytes: 41328
import sys

cards = [[False for i in range(13)] for j in range(4)]
pattern = ["S", "H", "C", "D"]
n = int(input())
lines = [line.split() for line in sys.stdin.readlines()]

for line in lines:
    cards[pattern.index(line[0])][int(line[1]) - 1] = True

for i in range(4):
    for j in range(13):
        if cards[i][j] == False:
            print(pattern[i], j + 1)




Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define MAX 100
#define INF 800000000
int main(){
  int N,K;
  cin>>N>>K;
  deque<int> W;
  for(int i=0;i<N;i++){
    int v;
    cin>>v;
    W.push_back(v);
  }

  int ans=-1000000000;
  for(int i=0;i<=K;i++){
    for(int j=0;i+j<=K;j++){
      if(i+j>N){
        continue;
      }
      deque<int> V=W;
      priority_queue<int,vector<int>,greater<int>> pq;
      for(int k=0;k<i;k++){
        int v=V.front();
        V.pop_front();
        pq.push(v);
      }
      for(int k=0;k<j;k++){
        int v=V.back();
        V.pop_back();
        pq.push(v);
      }
      for(int k=0;k<K-i-j;k++){
        if(pq.empty()){
          break;
        }
        int v=pq.top();
        if(v<0){
          pq.pop();
        }else{
          break;
        }
      }
      //cout<<"hello"<<endl;
      int sum=0;
      while(!pq.empty()){
        sum+=pq.top();
        pq.pop();
      }
      ans=max(ans,sum);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
        }
    }

    REP(i, H) {
        REP(j, W) {
            if (A[i][j] != '#') continue;
            bool r = false;
            bool l = false;
            bool d = false;
            bool u = false;
            if (i + 1 < H && A[i + 1][j] == '#') {
                r = true;
            }
            if (j + 1 < W && A[i][j + 1] == '#') {
                d = true;
            }
            if (i - 1 >= 0 && A[i - 1][j] == '#') {
                l = true;
            }
            if (j - 1 >= 0 && A[i][j - 1] == '#') {
                u = true;
            }
            if (i == 0 && j == 0) l = true;
            if (i == H - 1 && j == W - 1) r = true;
            if ((r ^ d) && (l ^ u)) {
                continue;
            }
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=(b+c-1)/b;
  int y=(d+a-1)/d;
  if(x<=y){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int D,N;

	scanf("%d %d",&D,&N);

	vector<int> V;

	int base;

	if(D == 0){

		base = 1;

	}else if(D == 1){

		base = 100;

	}else{

		base = 10000;
	}

	for(int i = 1; i <= 99; i++){

		V.push_back(base*i);
	}
	V.push_back(base*101);

	printf("%d\n",V[N-1]);

	return 0;
}


Measured memory_bytes: 3756
//https://atcoder.jp/contests/abc106/tasks/abc106_d
//D - AtCoder Express 2
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll N,M,Q; cin>>N>>M>>Q;
  vector<pair<ll,ll>> lrs(M);
  for(auto&& lr:lrs) cin>>lr.first>>lr.second;
  vector<pair<ll,ll>> querys(Q);
  for(auto&& q:querys) cin>>q.first>>q.second;
  //終端でsort
  //sort(lrs.begin(),lrs.end(),[](auto&a,auto&b){return a.second<b.second;});
  vector<vector<ll>> lsums(N+1,vector<ll>(N+1));//終端に応じた始点の累積和
  vector<ll> rsums(N+1);
  for(const auto& p:lrs){
    lsums[p.second][p.first]+=1;
    rsums[p.second]+=1;
  }
  FOR(i,1,N+1){
    rsums[i] += rsums[i-1];
  }

  FOR(i,1,N+1){
    FOR(t,1,N+1){
      lsums[t][i] += lsums[t-1][i];
    }
  }
  FOR(t,1,N+1){
    FOR(i,1,N+1){
      lsums[t][i] += lsums[t][i-1];
    }
  }

  for(const auto& qq:querys){
    ll p,q; tie(p,q)=qq;
    ll ans=rsums[q]-lsums[q][p-1];
    cout<<ans<<endl;
  }
#if 0
  vector<ll> lsums(N+1);
  vector<ll> rsums(N+1);
  REP(i,M){
    ll l,r; cin>>l>>r;
    ++lsums.at(l);
    ++rsums.at(r);
  }
  FOR(i,1,N+1){
    lsums[i] += lsums[i-1];
    rsums[i] += rsums[i-1];
  }
  dump(lsums);
  dump(rsums);
  REP(i,Q){
    ll p,q; cin>>p>>q;
    ll ans=rsums[q]-lsums[p-1];
    cout<<ans<<endl;
  }
#endif
  return 0;
}

Measured memory_bytes: 7552
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <string>
using namespace std;
string str;
int main() {
	cin >> str;
	int ans = 0;
	for (size_t i = 0;i < str.size()>>1;i++)
		if (str[i] ^ str[str.size()-i-1]) ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second

using namespace std;

typedef long long ll;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    int n = s.length() + 1;
    vector <ll> nums(n, 0);
    for(int i=n-2; i>=0; i--){
        if(s[i] == '>'){
            nums[i] = nums[i+1] + 1;
        }
    }
    ll last = nums[0];
    ll ans = last;
    //cout << "i = " << 0 << " ans = " << ans << '\n';
    for(int i=1; i<n; i++){
        if(i == n-1){
            if(s[i-1] == '>'){
                ans += 0;
            }
            else{
                ans += last+1;
            }
        }
        else if(s[i] == '>'){
            if(s[i-1] == '<'){ 
                ans += max(nums[i], last+1);
                last = max(nums[i], last+1);
            }
            else{
                ans += nums[i];
                last = nums[i];
            }
        }
        else{
            if(s[i-1] == '>'){
                ans += 0;
                last = 0;
            }
            else{
                ans += last+1;
                last++;
            }
        }
        //cout << "i = " << i << " ans = " << ans << '\n';
    }
    cout << ans << '\n';
    return 0;
}


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

int main(){
	const int MOD = 1e9+7;
	int N;
	cin >> N;
	vector<ll> A;
	rep(i,N){ ll t; cin >> t; A.push_back(t); }

	ll ans = 0;
	for(int i=0; i<60; i++){
		ll o=0;
		rep(j,N){ if(A[j]>>i & 1)o++; }
		ll x = o*(N-o) % MOD;
		rep(j,i){ x = x*2 % MOD; }
		ans += x;
		ans %= MOD;
	}
	cout << ans << endl;
}



Measured memory_bytes: 6384
#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[i];
  }
  sort(d.begin(),d.end());
if(d.size() % 2 != 0)//要素が奇数個あるとき//
  {
      cout << 0 << endl;
  }
if(d.size() % 2 == 0){
     int a = d[(N-1)/2], b = d[(N+1)/2];
     cout << b - a << endl;
  }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> U;
    if (U == S) A--;
    else B--;
    cout << A << " " << B << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;
int N, X, Y, Z;
int dp[45][300005];
int p10[45];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    scanf("%d%d%d", &X, &Y, &Z);

    int M = (1 << (X + Y + Z)) - 1;
    int mskXYZ = (1 << (Z - 1)) | (1 << (Z + Y - 1)) | (1 << (Z + Y + X - 1));

    p10[0] = 1;
    for(int i = 1; i <= N; i++)
        p10[i] = (10LL * p10[i - 1]) % mod;

    dp[0][0] = 1;
    for(int i = 0; i < N; i++)
        for(int j = 1; j <= 10; j++)
            for(int msk = 0; msk <= M; msk++)
            {
                int newmsk = ( (msk << (j)) | (1 << (j - 1)) ) & M;
                if( (newmsk & mskXYZ) != mskXYZ )
                    (dp[i + 1][newmsk] += dp[i][msk]) %= mod;
            }

    int ans = p10[N];
    for(int msk = 0; msk <= M; msk++)
        (ans -= dp[N][msk]) %= mod;
    (ans += mod) %= mod;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 47872
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;


int main()
{
	int t[31 + 3];
	t[0] = t[1] = 0;
	t[2] = 1;
	for (int i = 3; i < 31 + 3; ++i)
		t[i] = t[i-1] + t[i-2] + t[i-3];

	int n;
	while (scanf("%d", &n), n)
		printf("%d\n", ((t[n+2]+9)/10+364) / 365);

	return 0;
}

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

long long func(long long x){
    return 10 * x + 7;
}

void solve(long long K){
    int val = 7%K;
    for (int i = 1; i <= K; i++)
    {
        if(val == 0){
            cout << i << endl;
            return;
        }
        val = func(val) % K;
    }
    cout << -1 << endl;
    return;
}

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


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

int main()
{
    int64_t n, c;
    cin >> n >> c;
    int64_t x[n], v[n];
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> v[i];
    }
    int64_t dp[n + 1]{}, dp2[n + 1]{};
    for (int64_t i = 0, p = 0; i < n; i++)
    {
        dp[i + 1] = dp[i] + v[i] - (x[i] - p);
        p = x[i];
    }
    for (int64_t i = n - 1, p = c; 0 <= i; i--)
    {
        dp2[n - i] = dp2[n - i - 1] + v[i] - (p - x[i]);
        p = x[i];
    }
    int64_t puni[n + 1]{}, muni[n + 1]{};
    for (int i = 0; i < n; i++)
    {
        puni[i + 1] = max(puni[i], dp[i + 1]);
        muni[i + 1] = max(muni[i], dp2[i + 1]);
    }
    int64_t ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans = max(ans, dp[i]);
        ans = max(ans, dp[i] + muni[n - i] - x[i - 1]);
        ans = max(ans, dp2[i]);
        ans = max(ans, dp2[i] + puni[n - i] - (c - x[n - i]));
    }
    cout << ans << endl;
    return 0;
}

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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

int main()
{
	string s, t;
	cin >> s >> t;
	for(int i = 0; i < 3; i++) {
		if(s[i] != t[3-i-1]) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    int n,m; cin >> n >> m;
    vector<ll> p(m), y(m);
    vector<vector<ll> > v(n+1);
    rep(i, m) cin >> p[i] >> y[i], v[p[i]].push_back(y[i]);
    rep(i, n) sort(v[i+1].begin(), v[i+1].end());
    rep(i,m) printf("%06lld", (ll)p[i]), printf("%06lld\n", (ll)(lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) -v[p[i]].begin() + 1));
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <stdio.h>
static const int MAX = 200000;

using namespace std;

int bubbleSort(int a[], int n){
  int sw = 0;
  bool flag = 1;
  for(int i = 0; flag; i++){
    flag = 0;
    for(int j = n -1; j >= i + 1; j--){
      if(a[j] < a[j-1]){
        swap(a[j], a[j-1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main(int argc, const char * argv[]) {
  int n, a[MAX], sw;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  
  sw = bubbleSort(a, n);
  
  for(int i = 0; i < n; i++){
    if(i) cout << " ";
    cout << a[i];
  }
  cout << endl;
  cout << sw << endl;
  
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define M 256;
using namespace std;
typedef pair <int,int> P;
typedef pair <int,P> PP;


int main(){
  while(1){
    int n,l[258],R[258],O[258];
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++)cin>>l[i];
    
    double ans=1e9;
    PP SAC;
    for(int s=0;s<=15;s++)
      for(int a=0;a<=15;a++)
	for(int c=0;c<=15;c++){
	  R[0]=s;
	  for(int i=1;i<=n;i++) R[i]=(a*R[i-1]+c)%M;
	  for(int i=1;i<=n;i++) O[i]=(l[i]+R[i])%M;
	  int cnt[258]={};
	  for(int i=1;i<=n;i++)cnt[O[i]]++;
	  double H=0;
	  for(int i=0;i<256;i++)
	    if(cnt[i])H-=(1.0*cnt[i]/n)*log(1.0*cnt[i]/n);
	  
	  if(ans-(1e-9)>H) ans=H,SAC=PP(s,P(a,c));
	  if(fabs(ans-H)<=0.0000001) SAC=min(SAC,PP(s,P(a,c)));
	}
    cout <<SAC.first<<" "<<SAC.second.first<<" "<<SAC.second.second<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
from collections import deque
n = int(input())
Ps = []
for _ in range(n):
  lis = list(map(int, input().split()))
  if len(lis)>2:
    Ps.append(lis[2:])
  else:
    Ps.append([])
ans = [-1]*n
ans[0] = 0
queue = deque()
checked = deque()
[queue.append([p, 1]) for p in Ps[0]]
checked.append(1)
while queue:
  t, pa = queue.popleft()
  if not t in checked:
    for i in Ps[t-1]:
      queue.append([i, t])
    ans[t-1] = ans[pa-1]+1
    checked.append(t)
for i, a in enumerate(ans):
  print(i+1, a)


Measured memory_bytes: 6032
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll d,t,s;
    cin>>d>>t>>s;
    if((s*t)>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }

        map<int, int> hash;
        for (int i = 0; i < n; i++) {
            int num;
            cin >> num;
            if (hash.find(num) == hash.end()) {
                hash.insert(make_pair(num, 1));
            } else {
                hash[num]++;
            }
        }
        int max = 0, max_i;
        for (map<int, int>::iterator it = hash.begin(); it != hash.end(); it++) {
            if (max < it->second) {
                max = it->second;
                max_i = it->first;
            }
        }
        if (max > n / 2) {
            cout << max_i << endl;
        } else {
            cout << "NO COLOR" << endl;
        }
    }
}

Measured memory_bytes: 1940
//#include "stdafx.h"
#include <cstdio>
#include <queue>
#include <cstring>
#define INF 1000000000
using namespace std;

int row, col, n;

typedef struct point {
	int x, y;
};

char map[1010][1010];
int d[1010][1010];
int direct[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };

int BFS(int &startX, int &startY, char target) {
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			d[i][j] = INF;

	queue<point> q;
	point p;
	p.x = startX;
	p.y = startY;
	d[startX][startY] = 0;
	q.push(p);
	while (!q.empty()) {
		int nowX = q.front().x,nowY = q.front().y;
		q.pop();

		if (map[nowX][nowY] == target) {
			startX = nowX;
			startY = nowY;
			return d[nowX][nowY];
		}

		int nextX, nextY;
		for (int i = 0; i < 4; i++) {
			nextX = nowX + direct[i][0];
			nextY = nowY + direct[i][1];

			if (nextX >= 0 && nextY >= 0 && nextX < row && nextY < col && 
					map[nextX][nextY] != 'X' && d[nextX][nextY] == INF) {
				d[nextX][nextY] = d[nowX][nowY] + 1;
				p.x = nextX;
				p.y = nextY;
				q.push(p);
			}
		}
	}
	return -1;
}

int main() {
	int startX, startY, sum = 0;

	scanf("%d%d%d", &row, &col, &n);
	for (int i = 0; i < row; i++) {
		scanf("%s", map[i]);
		for (int j = 0; j < col; j++) {
			if (map[i][j] == 'S') {
				startX = i;
				startY = j;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		int dis = BFS(startX, startY, i + '1');
		sum += dis;
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 7576
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;

	cin >> N;

	Int pmax = -INF;
	Int sum = 0;
	Int temp;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		if (temp>pmax) {
			pmax = temp;
		}
		sum += temp;
	}

	cout << sum-pmax/2 << "\n";

}


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

using namespace std;
typedef long long ll;
typedef double d;

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
        cin>>a[i];
	}
	int flag=1;
	for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0){
                flag=0;
                break;
            }
        }
	}
	if(flag)
        cout<<"APPROVED";
    else
        cout<<"DENIED";
        return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int N;
    bool flag = false;
    cin >> N;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if ((4 * i + 7 * j) == N) {
                flag = true;
                break;
            }
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
ans = "Yes"
for i in range(N - 1):
  diff = H[i + 1] - H[i]
  if diff >= 1:
    H[i + 1] -= 1
  elif diff < 0:
    ans = "No"
print(ans)

Measured memory_bytes: 14396
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

string s[100001];
int main() {
	ll n; cin >> n;
	ll B_A = 0;
	ll B_ = 0;
	ll _A = 0;
	ll ans = 0;
	rep(i, 0, n) {
		cin >> s[i];
		rep(j, 1, s[i].size()) {
			if (s[i][j - 1] == 'A' && s[i][j] == 'B') ans++;
		}
		if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') B_A++;
		else if (s[i][s[i].size() - 1] == 'A')_A++;
		else if (s[i][0] == 'B')B_++;
	}

	if (B_A > 0) {
		if (_A > 0 && B_ > 0) {
			ans += B_A + 1;
			_A--, B_--;
		}
		else if (_A > 0) {
			ans += B_A;
		}
		else if (B_ > 0) {
			ans += B_A;
		}
		else {
			ans += B_A - 1;
		}
	}

	ans += min(B_, _A);

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

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

long long dsum(long long n){
  long long res = 0;
	while(n > 0){
      res += n % 10;
      n /= 10;	
    }
  return res;
}


int main(){
  long long K;
  cin >> K;
  for (int i = 1; i < 10; i++){
    if (!K) return 0;
    cout << i << endl;
    K--;
  }
  long long tmp = 10;
  long long i = 19;
  while (i <= 1000000000000000L){
    if (!K) return 0;
    printf("%lld\n", i);
    K--;
    if ((double)(i+tmp)/(double)dsum(i+tmp) > tmp) tmp *= 10;
    i += tmp;
  }
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, M, A[MAX];

int main(){
    cin >> N >> M;
    rep(i, N) cin >> A[i];

    priority_queue<int> q;
    rep(i, N) q.push(A[i]);

    rep(i, M){
        int x = q.top();
        q.pop();
        x /= 2;
        q.push(x);
    }

    ll ans = 0;
    rep(i, N){
        int x = q.top();
        q.pop();
        ans += x;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l;
  cin >> n >> l;
  string s[110];
  for(int i=0; i<n; i++){  
    cin >> s[i];
  }
  sort(s, s+n);
  for(int i=0; i<n; i++){
    cout << s[i];
  }
}

Measured memory_bytes: 256
N = int(input())

Alist = list(map(int, input().split()))
plus = [abs(a) for a in Alist]

cnt = 0

for a in Alist:
    if a < 0:
        cnt += 1

if cnt%2==0:
    print(sum(plus))
else:
    print(sum(plus) - min(plus) * 2)

Measured memory_bytes: 20004
n, m = map(int,input().split())

h = list(map(int,input().split()))

# 各展望台について(自分が一番高い1, 高くない時0)
t = [1] * n
for i in range(m):
    a, b = map(int, input().split())

    if h[a-1] <= h[b-1]:
        t[a-1] = 0

    if h[b-1] <= h[a-1]:
        t[b-1] = 0

print(sum(t))

Measured memory_bytes: 20104
def judge(string):
    if string[0] != "A" or "C" not in string[2:len(string) - 1]:
        return False
    list_ = list(string)
    list_.remove("A")
    list_.remove("C")
    return all(c.islower() for c in list_)

print("AC" if judge(input()) else "WA")


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

int main()
{
  string S;
  cin >> S;
  int N = stoi(S);
  int div = 0;
  for(char c:S)
  {
    div += c-'0';
  }
  if(N%div == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int main(){
    int Q;
    cin >> Q;
    for (int z = 0; z < Q; z++) {
        ll A, B;
        cin >> A >> B;
        if (A > B) swap(A, B);
        if (A == B) cout << 2*A-2 << endl;
        else if (A+1 == B) cout << 2*A-2 << endl;
        else {
            ll C = sqrt(A*B);
            if (C*C == A*B) cout << 2*C-3 << endl;
            else if (C*(C+1) >= A*B) cout << 2*C-2 << endl;
            else cout << 2*C-1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ac,t,wa,tle,re;

string s;

int main (){
cin>>t;
for(int i=0;i<t;i++) {
  
  cin>>s;
  if(s=="AC") ac++;
  if(s=="TLE") tle++;
  if(s=="RE") re++;
  if(s=="WA") wa++;
}
  
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e3 + 10;
int n, a, b, c, d;
ll f[maxn][maxn];
ll fac[maxn], inv[maxn], facinv[maxn], facinvi[maxn][maxn];
void pre()
{
	fac[0] = 1; for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1; for(int i = 2; i < maxn; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	facinv[0] = 1; for(int i = 1; i < maxn; ++i) facinv[i] = facinv[i - 1] * inv[i] % mod;
	for(int i = 0; i < maxn; ++i) facinvi[i][0] = 1;
	for(int i = 0; i < maxn; ++i) for(int j = 1; j < maxn; ++j) facinvi[i][j] = facinvi[i][j - 1] * facinv[i] % mod;
}
ll C(int n, int m) { return n < m ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;}
int main()
{
	pre();
	cin >> n >> a >> b >> c >> d;
	f[a - 1][0] = 1;
	for(int i = a; i <= b; ++i)
		for(int j = 0; j <= n; ++j)
		{
			f[i][j] = f[i - 1][j];
			for(int k = c; k <= d && j >= i * k; ++k)
				f[i][j] = (f[i][j] + f[i - 1][j - i * k] * fac[j] % mod * facinv[j - i * k] % mod * facinvi[i][k] % mod * facinv[k] % mod) % mod;
		}
	cout << f[b][n] << endl;
	return 0;
}
		
			
	

Measured memory_bytes: 19480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    string s,t;
    cin>>s>>t;
    ll ans=0;
    rep(0,i,s.size())if(s[i]!=t[i])++ans;
    cout<<ans;
}


Measured memory_bytes: 3812
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	int n;
	cin>>n;
	int cnt=0;
	for(int a=1;a<n;a++){
		for(int b=1;b<=(n-1)/a;b++){
			++cnt;
		}
	}
	cout<<cnt<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



Measured memory_bytes: 3704
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int quantity = sc.nextInt();
        int[] prices = new int[quantity];
        for(int i = 0; i<quantity; i++){
            prices[i] = sc.nextInt();
        }
        Arrays.sort(prices);
        int total = 0;
        for(int i = 0; i<quantity; i++){
            int price = i == quantity - 1 ? prices[i] / 2 : prices[i];
            total += price;
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <stack>

int main() {
  std::string S;
  std::cin >> S;
  
  std::stack<char> st;
  for (int i = 0; i < S.size(); i++) {
    if (!st.empty() && st.top() == 'S' && S[i] == 'T')
      st.pop();
    else
      st.push(S[i]);
  }
  
  std::cout << st.size() << '\n';
}

Measured memory_bytes: 644
#include<stdio.h>

void rotateDice( int *dice, char ins )
{
	int tdice[7];
	int i;

	for( i=0; i<6; i++ ) {
    	tdice[i]=dice[i];
    }
	if( 'E' == ins ) {
		tdice[3-1]=dice[1-1];
		tdice[4-1]=dice[6-1];
		tdice[6-1]=dice[3-1];
		tdice[1-1]=dice[4-1];
	} else if( 'W' == ins) {
		tdice[4-1]=dice[1-1];
		tdice[3-1]=dice[6-1];
		tdice[1-1]=dice[3-1];
		tdice[6-1]=dice[4-1];
	} else if( 'N' == ins ) {
		tdice[5-1]=dice[1-1];
		tdice[2-1]=dice[6-1];
		tdice[1-1]=dice[2-1];
		tdice[6-1]=dice[5-1];
	} else if( 'S' == ins ) {
		tdice[2-1]=dice[1-1];
		tdice[5-1]=dice[6-1];
		tdice[6-1]=dice[2-1];
		tdice[1-1]=dice[5-1];
	}
   	for( i=0;  i<6; i++ ) {
		dice[i]=tdice[i];
	}
	
	return;
}

int main( void ) 
{
	int dice[7];
	int dice2[7];
	int i;
	int top;
	int j;
	int count[7]={0};
	
	for( i=0;  i<6; i++ ) {
		scanf( "%d", &dice[i] );
    }
 	for( i=0;  i<6; i++ ) {
		scanf( "%d", &dice2[i] );
    }

  	for( i=0; i<6; i++ ) {
  		for( j=0; j<6; j++ ) {
  			if( dice[i] == dice[j] ) {
  				count[i]++;
  			}
  		}
  	}
  	int max=888;
  	for( i=0; i<6; i++ ) {
  		if(  count[i] < max ) {
  			max=count[i];
  			top=i;
  		}
  	}
 
 	
	if( dice[top]!=dice2[top] ) {
		for( i=0; i<3; i++ ) {
			if( dice[top]==dice2[top] ) {
				break;
			}
			rotateDice( dice2, 'N' );
		}
	}

	if( dice[top]!=dice2[top] ) {		
		for( i=0; i<3; i++ ) {
			if( dice[top]==dice2[top] ) {
				break;
			}
			rotateDice( dice2,  'E' );
		}
	}

	int diff=0;
    if( dice[top]!=dice2[top] ) {
		diff=1;
	} else {	
		rotateDice( dice, 'W' );
		rotateDice( dice2, 'W' );
		for( i=0; i<3; i++ ) {
			if( dice[0]==dice2[0] ) {
				break;
			}
			rotateDice( dice2,  'N' );
		}		
	}

    for( i=0; i<6; i++ ) {
    	if( dice[i] != dice2[i] ) {
			diff=1;
			break; 
    	}
    }
    
    if( diff ) {
    	printf( "No\n" );
    } else {
    	printf( "Yes\n" );
    }
    
	return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <cstdio>
#include <cstring>
#define mid (l + r) / 2

const int N = 2e5 + 52;

int n, m, a[N];
bool check(int x) {
	for (int i = 0; i < m - 1; i++) {
		if ((a[m + i] <= x && a[m + i + 1] <= x) || (a[m - i] <= x && a[m - i - 1] <= x))
			return 1;
		if ((a[m + i] > x && a[m + i + 1] > x) || (a[m - i] > x && a[m - i - 1] > x))
			return 0;
	}
	return a[1] <= x;
}

int l, r;
int main() {
	scanf("%d", &n);
	m = n, n = n * 2 - 1;
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (l = 1, r = n; l <= r;)
		if (check(mid))
			r = mid - 1;
		else
			l = mid + 1;
	printf("%d", l);
}

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

int main(){
    using namespace std;
    unsigned long N, M, V, P;
    cin >> N >> M >> V >> P;
    --P;
    vector<unsigned long> A(N);
    copy_n(istream_iterator<unsigned long>(cin), N, A.begin());
    partial_sort(A.begin(), A.end() - P, A.end());
    A.erase(A.end() - P, A.end());
    V -= min(V, P);
    N -= P;
    vector<unsigned long> B(N);
    partial_sum(A.cbegin(), A.cend(), B.begin());
    const auto& check = [&N, &M, &V, &A, &B](unsigned long x) -> bool {
        return A[x] + M >= A.back() && (A[x] + M) * N >= B.back() - B[x] + M * V + A[x] * (x + 1);
    };
    if(check(0)){
        cout << N + P << endl;
        return 0;
    }
    unsigned long L{0}, R{N};
    while(L + 1 < R){
        auto m = (L + R) / 2;
        (check(m) ? R : L) = m;
    }
    cout << N - R + P << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
int dp[200010];
int h[200010];
int k,n;
int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
	cin>>n>>k;
	FOR(i,1,n)	cin>>h[i];
	fill(dp,0);
	dp[2] = abs(h[2]-h[1]); 
	FOR(i,3,n){
		dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=2;j<=k;j++){
			if(i-j>=1) dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1408