akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define M 1000000007
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define N 1000005
#define U 998244353
#define bs binary_search
#define endl '\n'
#define FILEIO     freopen("input.txt","r",stdin); freopen("output.txt","w", stdout);
#define PI 3.1415926535
#define INF LLONG_MAX-5
using namespace std;
int po(int n, int exp){
    int prod=1;
    rep(i,0,exp)
        prod*=n;
    return prod;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n,l;
        cin>>n>>l;
        int sum = n*l+(n*(n+1))/2-n;
        // cout<<sum<<" ";
        int mn = INT_MAX;
        int ans;
        rep(i,1,n+1){
            if(abs((l+i-1))<mn)
            {
                // cout<<i<<" ";
                mn =abs(l+i-1);
                ans = sum-(l+i-1);
            }
        }
        cout<<ans;
    }   
}   

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

int main(){
    int n,m,count;count=0;
    cin>>n>>m;
    for (int i = 0; i < m; i++)
    {
        int k;cin>>k;
        count+=k;
    }
    if(count<=n){
        cout<<n-count<<endl;
    }else{
        cout<<"-1"<<endl;
    }
    
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long c= n;
    long s = 0;
    for(int i =0;i<11;i++){
      if(n==0){
        break;
      }
      s=s+n%10;
      n=(n-n%10)/10;

    }
    if(c%s==0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
  

  
}

Measured memory_bytes: 23124
N, A, B = map(int, input().split(' '))


# N, A, B = 10 ** 18, 2, 10 ** 18
# N, A, B = 9, 5, 8


def main(n, a, b):
    distance = b - a

    if distance % 2 == 0:
        return distance // 2
    else:
        return min(a-1, n-b) + 1 + (distance - 1) //2

        # if a - 1 == n - b:
        #     return b - 1
        # if a < n - b + 1:
        #     return (a - 1) + (b - a) // 2 + 1
        # if n - a > n - b:
        #     return (n - b) + (b - a) // 2 + 1


print(main(N, A, B))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int a,b;
  for (int i=0;i<s.size();i++){
    if (s[i]=='A'){
      a=i;
      break;
    }
  }
  for (int i=0;i<s.size();i++){
    if (s[i]=='Z'){
      b=i;
    }
  }
  cout << b-a+1 << endl;
}

Measured memory_bytes: 640
import sys,math,copy,queue,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(-1,0),(0,1),(0,-1))

N,M,Q = LI()
req = [LI() for _ in range(Q)]
ans = 0
for a in itertools.combinations_with_replacement(range(1,M+1),N):
    cnt = 0
    for r in req:
        if a[r[1]-1] - a[r[0]-1] == r[2]: cnt+= r[3]
    ans = max(ans,cnt)
print (ans)

Measured memory_bytes: 70040
#include <stdio.h>

int main(){
    int i, n;
    int a[100];
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf(" %d", &a[i]);
    }
    for(i=0;i<n;i++){
        if(i)printf(" ");
        printf("%d", a[n-i-1]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2124
import sys


def input() -> str:
    return sys.stdin.readline().rstrip("\r\n")


def main():
    def min_dest(a, b):
        return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))

    n, x, y = map(int, input().split())
    x, y = x-1, y-1
    ans = [0] * (n-1)

    for i in range(n):
        for j in range(i+1, n):
            ans[min_dest(i, j)-1] += 1
    for a in ans:
        print(a)


if __name__ == "__main__":

    main()


Measured memory_bytes: 3444
N=int(input())
A=list(map(int,input().split()))
a=0
b=A[0]
for i in range(1,N):
    if b<=A[i]:
        b=A[i]
    elif b>A[i]:
        a+=(b-A[i])
        A[i]=b
        b=A[i]
print(a)

Measured memory_bytes: 104896
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int e,f;
	e=a*b; f=c*d;
	if(e>f)
	cout<<e<<endl;
	else 
	cout<<f<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  int n,x;
  cin >>n>>x;
  vector<int>l(n);
  for(int i=0;i<n;i++){
    cin >>l.at(i);
  }
  vector<int>d(n+1);
  d.at(0) = 0;
  for(int i=1;i<n+1;i++){
    d.at(i) = d.at(i-1) + l.at(i-1);
  }

  int cnt =0;
  for(int i=0;i<n+1;i++){
    if(d.at(i) <= x)cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main(void)
{
	double x1,x2,y1,y2,z1,z2,distance;

	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	z1=pow((x1-x2),2);
	z2=pow((y1-y2),2);
	distance=sqrt(z1+z2);

	printf("%f\n",distance);

}



Measured memory_bytes: 2044
<?php

    $S = trim(fgets(STDIN));
    
    switch ($S) {
        case "SUN":
            echo "7";
            break;
        case "MON":
            echo "6";

            break;
        case "TUE":
            echo "5";

            break;
        case "WED":
            echo "4";

            break;
        case "THU":
            echo "3";

            break;
        case "FRI":
            echo "2";

            break;
        case "SAT":
            echo "1";

            break;
    }

    
    
?>

Measured memory_bytes: 16228
#include<iostream>
#include<vector>

using namespace std;

int main(){

    int N; cin >> N;
    vector<int> d(N);
    for(int i=0; i<N; i++) cin >> d[i];
    long long res=0;

    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            res += d[i] * d[j];
        }
    }

    cout << res << endl;
    return 0;
}

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

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

	vector<int> v(n/2);
	
	vector<int> v2(n/2);
	for(int i=0;i<n;i++) {
		if (i%2 == 0)
	      cin >> v[i/2];
      else
        cin >> v2[i/2];
	}
  	sort(v.begin(),v.end());
  	sort(v2.begin(),v2.end());
  
	vector<int> count(n/2);
	vector<int> count2(n/2);
  	int now=0;
  int max =0,ooikazu=v[0];
	for(int i=0;i<n/2;i++) {
	    if(v[i] != v[now])
          now=i;
        count[now]++;
      if(count[now]>max) {
         ooikazu=v[now];
          max=count[now];
      }
	}
  int now2=0;
  int max2=0,ooikazu2=v2[0];
	for(int i=0;i<n/2;i++) {
	    if(v2[i] != v2[now2])
          now2=i;
        count2[now2]++;
      if(count2[now2]>max2){
          max2 = count2[now2];
          ooikazu2=v2[now2];
       }
	}
  sort(count.begin(),count.end());
  sort(count2.begin(),count2.end());
  if(ooikazu == ooikazu2)
  { if (n==2)
    {
      cout << 1<<endl;
      return 0;
    }
   	int t;
    
    t=(count2[n/2-1] +count[n/2-2] >= count[n/2-1]+count2[n/2-2]) 
      ? count2[n/2-1] +count[n/2-2] : count[n/2-1]+count2[n/2-2];
   

   cout << n-t << endl;
    return 0;
  }
  
  cout << n-count[n/2-1]-count2[n/2-1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int maxn = 1e5 + 10;
int dp[10005];
int cost[20]={0,2,5,5,4,5,6,3,7,6};
int recode[10005];
bool vis[10005];
int z[10];

int main()
{
    int n,m;

    cin>>n>>m;

    for (int q=0;q<m;q++)
    {
        scanf("%d",&z[q]);
    }

    dp[0]=0;
    vis[0]=1;

    sort(z,z+m);
    for (int q=1;q<=n;q++)
    {
        for (int w=m-1;w>=0;w--)
        {
            if (vis[q-cost[z[w]]]&&dp[q-cost[z[w]]]+1>dp[q])
            {
                dp[q]=dp[q-cost[z[w]]]+1;
                recode[q]=z[w];
                vis[q]=1;
            }
        }
    }

    int x=n;
    vector<int > p;
    while (x)
    {
        p.push_back(recode[x]);
        x-=cost[recode[x]];
    }
    sort(p.begin(),p.end(),greater<int>() ); 


    for (int q=0;q<p.size();q++)
    {
        printf("%d",p[q]);
    }
    printf("\n");
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i,m){
    cin >> a[i];
    n -=a[i];
  }
  if(n>=0){
    cout << n << endl;
  }
  else cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define mod 1000000007;
#define inf (1LL<<60)
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;

vector<vector<int>> multiply(vector<vector<int>> a,vector<vector<int>> b)
{
    int n=a.size();
    vector<vector<int>> v(n,vector<int>(n,0));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                v[i][j]=(v[i][j]+a[i][k]*b[k][j])%mod;
            }
        }
    }
    return v;
}

vector<vector<int>> power(vector<vector<int>> mat ,int exp)
{
    if(exp==1)
        return mat;
    vector<vector<int>> res=power(mat,exp/2);
    if(exp&1)
        return multiply(multiply(mat,res),res);
    else
        return multiply(res,res);
}

int solve(vector<vector<int>> adj,int k,int n)
{
    vector<vector<int>> ak=power(adj,k);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            ans=(ans+ak[i][j])%mod;
    }
    return ans;
}

signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<vector<int>> adj(n,vector<int>(n));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
          cin>>adj[i][j];
     cout<<solve(adj,k,n);
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int W,a,b;
    cin >> W>>a>>b;
    if(a<=b){
        if(b-a-W<=0){
            cout<<0<<endl;
        }else{
            cout<<b-a-W<<Endl;
        }
    }else{
        if(a-b-W<=0){
            cout<<0<<Endl;
        }else{
            cout<<a-b-W<<endl;
        }
    }
    return 0;
}   



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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

struct custom_hash {    // anti-hack for unordered_map. To declare: unordered_map<long long, int, custom_hash> safe_map;
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//

void solve()
{
	int d,t,s;
	cin >> d >> t >> s;
	if(s*t >= d)
		cout << "Yes";
	else
		cout << "No";
   
}


int main()
{
    int t;
    // cin>>t;
    // while(t--)
     solve();

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;
typedef unsigned long long ull;

#define F first
#define S second
#define en end()
#define bg begin()
#define rev reverse
#define mp make_pair
#define pb push_back
#define y1 y1234567890
#define um unordered_map                         
#define all(x) x.bg, x.en
#define sqr(x) ((x) * (x))
#define sz(x) (int)x.size()

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 2005;

char c[N][N];
int n, m, q, sum[N][N], u[N][N], l[N][N];

inline int getsum(int x, int y, int xx, int yy) {
	return sum[xx][yy] - sum[x - 1][yy] - sum[xx][y - 1] + sum[x - 1][y - 1];
}

inline int getu(int x, int y, int xx, int yy) {
	return u[xx][yy] - u[x - 1][yy] - u[xx][y - 1] + u[x - 1][y - 1];
}

inline int getl(int x, int y, int xx, int yy) {
	return l[xx][yy] - l[x - 1][yy] - l[xx][y - 1] + l[x - 1][y - 1];
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	scanf("%d %d %d", &n, &m, &q);

	for (int i = 1; i <= n; i++) {
		scanf("%s", c[i] + 1);
		for (int j = 1; j <= m; j++) {
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + c[i][j] - '0';
			u[i][j] = u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1];
			l[i][j] = l[i - 1][j] + l[i][j - 1] - l[i - 1][j - 1];
			if (c[i][j] == '1') {
				if (i != 1 && c[i - 1][j] == '1')
					u[i][j]++;
				if (j != 1 && c[i][j - 1] == '1')
					l[i][j]++;
			}
		}
	}

	for (int i = 1; i <= q; i++) {
		int x, y, xx, yy;
		scanf("%d %d %d %d", &x, &y, &xx, &yy);
		int res = getsum(x, y, xx, yy);
		if (x < xx)
			res -= getu(x + 1, y, xx, yy);
		if (y < yy)
			res -= getl(x, y + 1, xx, yy);
		printf("%d\n", res);
	}
	        
	return 0;
}


Measured memory_bytes: 52864
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC109.B
{
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            var k = sc.Nextint();

            var k2 = k / 2;
            if (k % 2 == 0) Console.WriteLine(k2 * k2);
            else Console.WriteLine(k2 * (k2 + 1));
        }
    }
    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        public double[] ArrayDouble(long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp90 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            int keta = (int)Math.Floor(Math.Log10(N)) + 1;

            string output = "";
            int remain;

            var outPutList = new List<string>();

            for (int k = keta; k >= 1; k--) {
                for (int i = 0; i < (int)Math.Pow(3, k); i++) {
                    output = "";
                    int temp = i;

                    for (int pos = 0; pos < k; pos++) {
                        remain = temp % 3;
                        output = remain.ToString() + output;
                        temp /= 3;
                    }
                    outPutList.Add(output);
                }
            }

            //0, 1, 2の集合
            var neededList = new List<char> { '0', '1', '2' };

            //3, 5, 7の集合
            var list_357 = new List<char> { '3', '5', '7' };

            int ans = 0;

            for (int i = 0; i < outPutList.Count(); i++) {
                //3種類の文字がそろっていない場合は飛ばす
                if (outPutList[i].ToCharArray().ToList().Intersect(neededList).Count() != 3) {
                    continue;
                }

                //文字列から整数を生成
                string num_str = "";
                for (int j = 0; j < outPutList[i].Length; j++) {
                    num_str += list_357[int.Parse(outPutList[i][j].ToString())].ToString();
                }

                int num = int.Parse(num_str);

                if (num <= N) {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 21080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0; i < m; i++)
        cin >> b[i];
    int ans = 0;
    while(n--){
        int sum = 0;
        for(auto i: b){
            int a;
            cin >> a;
            sum += a * i;
        }
        if(sum + c > 0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

long long getxor(long long x) {
    long long div2 = (x + 1) / 2;
    long long ret = 0;
    if (div2 % 2) {
        ret = 1;
    }

    if (x % 2 == 0) {
        ret = ret ^ x;
    }
    return ret;
}
int main() {
    long long a, b;
    cin >> a >> b;
    cout << (getxor(a - 1) ^ getxor(b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (auto& x : A) { cin >> x; -- x; }

	long long r = 0;
	vector<long long> a(M+10);
	vector<long long> b(M+10);
	for (int i = 1; i < N; ++ i) {
		int x = A[i-1];
		int y = A[i];
		if (x < y) {
			r += y - x;
			if (y - x - 1 > 0) {
				a[x+2] += 1;
				a[y+1] -= 1;
				b[y+1] -= y-x-1;
				//for (int i = 1; i <= y-x-1; ++ i) B[x+1+i] += i;
			}
		} else {
			r += y - x + M;
			if (y - x + M - 1 > 0) {
				if (x+2 < M) {
					a[x+2] += 1;
				} else {
					a[x+2-M] += 1;
				}
				if (y+1 < M) {
					a[y+1] -= 1;
					b[y+1] -= y-x+M-1;
				} else {
					a[y+1-M] -= 1;
					b[y+1-M] -= y-x+M-1	;
				}
				int j = M-(x+1);
				if (2 <= j && j <= y-x+M-1) {
					a[0] += 1;
					b[0] += j-1;
				}
				// for (int i = 1; i <= y-x+M-1; ++ i) B[(x+1+i) % M] += i;
			}
		}
	}
	long long rr = 0;
	long long aa = 0, bb = 0;
	for (int i = 0; i < M; ++ i) {
		aa += a[i];
		bb += aa;
		bb += b[i];
		rr = max(rr, bb);
	}
	cout << r-rr << endl;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    string s;
    cin >> s;

    int res = 0;
    bool judge = 1;
    char prev = '?';
    rep(i, s.size()) {
        if (prev != s[i])
            res++, judge = 1;
        else {
            if (judge) {
                i++;
                if (i >= s.size())
                    break;
                res++;
                judge = 0;
            } else {
                res++;
                judge = 1;
            }
        }
        prev = s[i];
    }

    cout << res << endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n , w;
	cin>>n>>w;
		
	long long int weight[n] , value[n] , i ,j;
	
	for(i=0;i<n;i++){
		cin>>weight[i]>>value[i];
	}
	
	long long int mat[n+1][w+1];
	
	memset(mat , 0, sizeof(mat));
	
	for(i=1;i<=n;i++){
		for(j=1;j<=w;j++){
			if(weight[i-1]<=j){
//				cout<<( value[i-1]+(mat[i-1][j-weight[i-1]]) )<<" "<<( mat[i-1][j] )<<"\n";
				mat[i][j] = max( ( value[i-1]+(mat[i-1][j-weight[i-1]]) ) , ( mat[i-1][j] ) );
//				cout<<mat[i][j]<<"\n";
			}
			else{
//				cout<<mat[i][j]<<"\n";
				mat[i][j]=mat[i-1][j];
			}
		}
	}
//	
//	cout<<"Ans\n";
//	
//	for(i=1;i<=n;i++){
//		for(j=1;j<=w;j++){
//			cout<<mat[i][j]<<" ";
//		}
//		cout<<"\n";
//	}
//	
//	
   cout<<mat[n][w];
   return 0;
}


Measured memory_bytes: 82472
n = int(input())
dp = [0]*3
for k in range(n):
    new_dp = [0]*3
    c = list(map(int, input().split()))
    for i in range(3):
        for j in range(3):
            if(i != j):
                new_dp[j] = max(new_dp[j], dp[i] + c[j])
    dp = new_dp
print(max(new_dp))


Measured memory_bytes: 3060
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
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 ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
struct UnionFind {
    vi par,size;
    UnionFind(int n) {
        par.resize(n);
        size.resize(n,1);
        rep(i, n) par[i]=i;
    }
    bool same(int x,int y) {
        return find(x)==find(y);
    }
    int consize(int k) {
        return size[find(k)];
    }
    int find(int k) {
        if(par[k]==k) return k;
        return par[k]=find(par[k]);
    }
    bool unite(int x,int y) {
        if(same(x,y)) return false;
        if(consize(x)<consize(y)) {
            par[find(x)]=find(y);
            size[y]+=size[x];
        }
        else {
            par[find(y)]=find(x);
            size[x]+=size[y];
        }
        return true;
    }
};
signed main() {
    int n,q;cin >> n >> q;
    UnionFind uf(n);
    rep(i, q) {
        int a,b,c;cin >> a >> b >> c;
        if(a) cout << uf.same(b,c) << endl;
        else uf.unite(b,c);
    }
    return 0;
}

Measured memory_bytes: 6036
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N+2);
    rep(i,N) cin >> A.at(i+1);
    A[0] = 0;
    A[N+1] = 0;
    vector<ll> B(N+1);
    int all = 0;
    for (int i = 0; i < N+1; i++) {
        B.at(i) = abs(A.at(i+1) - A.at(i));
        all += B[i];
    }
    for (ll i = 1; i <= N; i++) {
       int res = 0;
       if (i == 1) res = all - B[0] - B[1] + abs(A[2]);
       else if (i == N) res = all - B[N-1] - B[N] + abs(A[N-1]);
       else res = all - B[i-1] -B[i] + abs(A[i+1] - A[i-1]);
       cout << res << endl;
    }
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
 
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
 
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()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
 
    int N;
    cin >> N;
    int t=N;
 
    vector<ll> x, y, h;
    
    ll tx, ty, th;

    rep(i, t)
    {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        if(c!=0)
        {
            tx=a;
            ty=b;
            th=c;
        }
        x.push_back(a);
        y.push_back(b);
        h.push_back(c);
    }
 
    rep(cx, 101)
    {
        rep(cy, 101)
        {

            ll H = th+abs(cx-tx)+abs(cy-ty);
            rep(i, x.size())
            {
                if(H == h[i]+abs(cx-x[i])+abs(cy-y[i]) ||  (h[i]==0&&H<=abs(cx-x[i])+abs(cy-y[i])))
                {
                    
                }
                else
                {
                    break;
                }
                
 
                if(i==x.size()-1)
                {
                    cout << cx  << " " << cy << " " << H << endl;
                    return 0; 
                }
            }
        }
    }
 
 
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 19;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 16;
char dn[dm], * di = dn;
const int AS = 500000;
int dat[2 * AS];

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


	int N = 0;
	while ((ct = getchar_unlocked()) >= '0') N = N * 10 + ct - '0';
	fread(cn, 1, N + 1, stdin);
	auto da = dat + AS;
	rep(i, N) da[i] = (1 << *ci++ - 'a');
	for (int i = AS - 1; i >= 1; i--) dat[i] = dat[i << 1] | dat[(i << 1) + 1];

	ci = cn;
	fread(cn, 1, cm, stdin);
	int Q = getint();

	rep(j, Q) {
		char q = *ci++;
		ci++;
		if (q == '1') {
			int i = getint() - 1 + AS;
			for (dat[i] = 1 << *ci++ - 'a'; i > 1; i >>= 1) dat[i >> 1] = dat[i] | dat[i ^ 1];
			ci++;
		}
		else {
			int ret = 0;
			for (int l = getint() - 1 + AS, r = getint() + AS; l < r; l >>= 1, r >>= 1) {
				if (l & 1) ret |= dat[l++];
				if (r & 1) ret |= dat[--r];
			}
			int kotae = __builtin_popcount(ret);
			int ue = kotae / 10;
			if (ue) *di++ = ue + '0';
			*di++ = kotae - ue * 10 + '0';
			*di++ = '\n';
		}
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

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

int main(void) {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    vector<bool> b(n);
    bool t = true;
    REP(i, m) {
        int s, c; cin >> s >> c;
        s--;
        if (n != 1 && s == 0 && c == 0) t = false;
        if (b[s] && a[s] != c) t = false;
        a[s] = c; b[s] = true;
    }
    if (t) {
        if (a[0] == 0 && n != 1) a[0] = 1;
        for (auto v : a) cout << v;
    }
    else cout << -1;
    cout << endl;
}

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

using namespace std;

int main (){
	int n, k;
	cin >> n >> k;
	long long ans = n / k;
	ans = ans * ans * ans;
	long long koft = 0;
	if(k % 2 == 0){
		koft = n / k + 1;
		if((koft - 1) * k + k / 2 > n)
			koft--;
		koft = koft * koft * koft;
	}
	ans += koft;
	cout << ans << endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans;

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

	int X;
	cin >> X;

	if (X >= 500) {
		ans += (X / 500) * 1000 ;
		X -= (X/500) * 500;
	}

	if (X >= 5) {
		ans += (X / 5) * 5;
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np

A = np.array([list(map(int, input().split())) for _ in range(3)])
N = int(input())
B = [[False for j in range(3)] for i in range(3)]
for i in range(N):
    b = int(input())
    idx = np.where(A == b)
    # print(idx)
    try:
        x, y = int(idx[0]), int(idx[1])
        B[x][y] = True
    except:
        pass

flag = False

for i in range(3):
    if B[i][0] and B[i][1] and B[i][2]:
        flag = True
    if B[0][i] and B[1][i] and B[2][i]:
        flag = True
if B[0][0] and B[1][1] and B[2][2]:
    flag = True
if B[2][0] and B[1][1] and B[0][2]:
    flag = True
print("Yes" if flag else "No")



Measured memory_bytes: 12444
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int n;
	cin >> n;
	if(n <= 999) cout << "ABC" << endl;
	else cout << "ABD" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

template <typename T>
struct LazySegmentTree {
  int n;
  vector<T> data, lazy;
  LazySegmentTree() {}
  LazySegmentTree(const vector<T>& array) {
    int az = array.size();
    for (n = 1; n < az; n <<= 1);
    data.resize(2 * n - 1);
    lazy.resize(2 * n - 1);
    fill(data.begin(), data.end(), INF);
    fill(lazy.begin(), lazy.end(), INF);
  }
  void lazy_evaluate(int node, int l, int r) {
    if (lazy[node] != INF) {
      data[node] = lazy[node];
      if (l + 1 != r) {
        lazy[node * 2 + 1] = lazy[node];
        lazy[node * 2 + 2] = lazy[node];
      }
    }
    lazy[node] = INF;
  }
  void update(int a, int b, T val, int node = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    lazy_evaluate(node, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[node] = val;
      lazy_evaluate(node, l, r);
    } else {
      int mid = (l + r) / 2;
      update(a, b, val, node * 2 + 1, l, mid);
      update(a, b, val, node * 2 + 2, mid, r);
      data[node] = min(data[node * 2 + 1], data[node * 2 + 2]);
    }
  }
  T find(int a, int b, int node = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    lazy_evaluate(node, l, r);
    if (b <= l || r <= a) return INF;
    if (a <= l && r <= b) return data[node];
    int mid = (l + r) / 2;
    return min(find(a, b, node * 2 + 1, l, mid), find(a, b, node * 2 + 2, mid, r));
  }
};

int N,Q;
tuple<int,int,int> A[200010];
int D[200010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> Q;
  REP(i,N) {
    int S,T,X;
    cin >> S >> T >> X;
    A[i] = make_tuple(-X,S,T);
  }
  sort(A,A+N);
  REP(i,Q) cin >> D[i];
  LazySegmentTree<int> lst(vector<int>(Q, INF));
  REP(i,N) {
    int S,T,X;
    tie(X,S,T) = A[i];
    X *= -1;
    int posL = lower_bound(D,D+Q,S-X)-D;
    int posR = lower_bound(D,D+Q,T-X)-D;
    lst.update(posL,posR,X);
  }
  REP(i,Q) {
    int tmp = lst.find(i,i+1);
    cout << (tmp == INF ? -1 : tmp) << endl;
  }

  return 0;
}


Measured memory_bytes: 16356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string day;
  
  cin >> day;
  
  if(day =="SUN" ) cout << 7 <<endl;
   if(day =="MON" ) cout << 6<<endl; 
   if(day =="TUE" ) cout <<5 <<endl; 
   if(day =="WED" ) cout << 4<<endl; 
   if(day =="THU" ) cout << 3<<endl; 
   if(day =="FRI") cout << 2<<endl; 
   if(day =="SAT" ) cout << 1<<endl; 
  
   }

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

int main(){
  int x1=1,x2=2,x3=3,x4=4,x5=5,result;
  cin >> x1 >> x2 >> x3 >> x4 >> x5; 
 
  if(x1!=1) result=1;
  else if(x2!=2) result=2;
  else if(x3!=3) result=3;
  else if(x4!=4) result=4;
  else if(x5!=5) result=5;

  cout << result << endl;
}
  
  

Measured memory_bytes: 3628
import java.io.*
import java.util.*

fun solve(N: Int, L: IntArray){
    // 2つ長さa, b(a < b)を選んで、b <= c < a + bなるcを探す
    val sL = L.sorted()
    var ans = 0
    for(i in 0 until N){
        for(j in i + 1 until N){
            ans += sL.lowerBound(sL[i] + sL[j]) - j - 1
        }
    }
    println(ans)
    return
}

fun <T : Comparable<T>> List<T?>.lowerBound(
        element: T,
        fromIndex: Int = 0,
        toIndex: Int = size
): Int {
    var low = fromIndex
    var high = toIndex
    while (low < high) {
        val mid = (low + high) / 2
        if (element <= this.get(mid)!!) {
            high = mid
        } else {
            low = mid + 1
        }
    }
    return low
}


fun <T : Comparable<T>> List<T?>.upperBound(
        element: T,
        fromIndex: Int = 0,
        toIndex: Int = size
): Int {
    var low = fromIndex
    var high = toIndex
    while (low < high) {
        val mid = (low + high) / 2
        if (element >= this.get(mid)!!) {
            low = mid + 1
        } else {
            high = mid
        }
    }
    return low
}




fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val L = IntArray(N)
    for (i in 0 until N) {
        L[i] = sc.next().toInt()
    }
    solve(N, L)
}



Measured memory_bytes: 41252
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t 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(int64_t 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) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int n;
    cin >> n;
    vi c(n);
    rep(i, n) {
        cin >> c[i];
        --c[i];
        if(i && c[i] == c[i-1]) {
            c.pop_back();
            --i;
            --n;
        }
    }

    map<int, vi> mp;
    rep(i, n) {
        mp[c[i]].push_back(i);
    }

    vector<mint> dp(n+1);
    dp[0]=1;
    rep(i, n) {
        dp[i+1] = dp[i];
        vi::iterator itr = lower_bound(all(mp[c[i]]), i);
        if(itr != mp[c[i]].begin()) {
            --itr;
            dp[i+1] += dp[*itr+1];
        }
    }

    cout << dp[n] << endl;
}

Measured memory_bytes: 24448
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Int -> Int -> VU.Vector Int -> Int
solve !n !a !b !hs = if check 1
  then 1
  else let s = findInternal 1 in binsearch (s `div` 2) s
 where
  check !n =
    VU.foldr'
        (\(!h) (!acc) -> if acc >= 0
          then
            acc
            -     ceiling (fromIntegral (h - n * b) / fromIntegral (a - b))
            `max` 0
          else -1
        )
        n
        hs
      >= 0

  findInternal !k =
    head $ dropWhile (\(!n) -> not . check $ n) $ map (2 ^) [0 ..]

  -- search in (x,y]
  binsearch !x !y
    | y - x == 1
    = y
    | otherwise
    = let !z = (x + y) `div` 2
      in  if check z then binsearch x z else binsearch z y

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (n, a, b) <-
    (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2))
    .   VU.unfoldrN 3 readInt
    <$> B.getLine
  hs <-
    VU.replicateM n
    $   (\vec -> (vec VU.! 0))
    .   VU.unfoldrN 1 readInt
    <$> B.getLine
  print $ solve n a b hs


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

int main(){
    int n,ans = 0;
    string s;
    cin >> n >> s;
    for ( int i = 0; i + 2 < n; ++i ) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
           ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

getInts::IO[Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

main = do
  [k,n] <- map read . words <$> getLine
  an <- getInts
  let an' = an ++ [(k+(an !! 0))]
  print $ k - (maximum $ zipWith (-) (tail an') an')

Measured memory_bytes: 12284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll T, k;
    cin >> T >> k;
    int cnt = 0;
    for(int i = 0; i < T; i++){
        ll x, y;
        cin >> x >> y;
        if((x*x + y*y) <= k*k)
            cnt++;
    }
    cout << cnt;
}









Measured memory_bytes: 3632
from itertools import product
# from line_profiler import LineProfiler


def putpiece(X,Y,bitmap,unused,pieces,numans,pcsans,FINFLAG):
    if FINFLAG:
        return numans,pcsans
    if not unused:
        pcsans = pieces
        return numans + 1, pcsans
    if numans > 1:
        return 2, pieces
    b,k,y,x = unused[-1]
    for h,w in set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1)) if not (k//i)*(k//(k//i)) - k]):
        for pt,qt in product(range(max(0,y-h+1),min(Y-h+1,y+1)),range(max(0,x-w+1),min(X-w+1,x+1))):
            rt,st = pt+h-1, qt+w-1
            piece = 2**(st-qt+1)-1
            piece2 = 0
            for j in range(rt-pt+1): piece2 |= piece << j*X
            piece = ( piece2 << X-st-1 ) << (Y-rt-1)*X
            mark = ( 1 << X-x-1 ) << (Y-y-1)*X
            if not (bitmap&piece)^mark: numans,pcsans = putpiece(X,Y,bitmap|piece,unused[:-1],pieces+[[b,k,pt,qt,rt,st]],numans,pcsans,False)
            if numans > 1: return 2, pcsans
    else:
        return numans,pcsans

def main():
    while(True):
        X,Y,n = map(int,input().split())
        if not X: break
        bk = sorted([list(map(int,input().split())) for _ in range(n)])
        ss = [list(map(int,input().split())) for _ in range(Y)]
        yxs = sorted([ss[i][j],i,j] for i,j in product(range(Y),range(X)) if ss[i][j])
        bkyx = [ bk[i]+yxs[i][1:] for i in range(n)]
        filled = "".join([ "".join(["1" if ss[i][j] else "0" for j in range(X)]) for i in range(Y)])
        nans,pcs = putpiece(X,Y,int(filled,2),bkyx,[],0,0,False)
        if nans > 1:
            print("NA")
        elif nans:
            toprint = [[0]*X for _ in range(Y)]
            for i,_,sy,sx,ey,ex in pcs:
                for j in range(sy,ey+1): toprint[j][sx:ex+1] = [i]*(ex-sx+1)
            for a in toprint: print(" ".join(str(b) for b in a))
        else:
            print("NA")

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.add_function(putpiece)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 5716
def prime_checker(n, option = False) -> list:
    p = [False, True, False, False, False, True] * (n // 6 + 1)
    del p[n + 1:]
    p[1 : 4] = False, True, True
    for x in range(5, int(n**.5 + 1)):
        if p[x]:
            p[x * x :: 2*x] = [False] * ((n // x - x) // 2 + 1)
    return [e for e, q in enumerate(p) if q] if option else p

from itertools import accumulate
*c, = map(int, open(0))
*p, = accumulate(prime_checker(max(c)))
for i in c:
    print(p[i])


Measured memory_bytes: 54092
s = gets.chomp
t = gets.chomp
x = s.size
y = t.size
arr = []
for i in 0..(x-y)
  count = 0
  for j in 0..(y-1)
    if t[j] != s[i+j]
      count += 1
    end
  end
  arr << count
end
puts arr.min

Measured memory_bytes: 14248
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class H
{
	public static void Main()
	{
		int H = GetInt();
		int W = GetInt();
		char[,] a = new char[H, W];
		for(int i = 0; i < H; i++)
		{
			string S = GetString();
			for(int j = 0; j < W; j++)
				a[i, j] = S[j];
		}

		int mod = (int)(1e9 + 7);
		int[,] dp = new int[H, W];
		dp[0, 0] = 1;
		for(int i = 0; i < H; i++)
		{
			for(int j = 0; j < W; j++)
			{
				if(a[i, j] == '#')
					continue;
				
				if((i > 0) && (a[i - 1, j] == '.'))
					dp[i, j] = (dp[i, j] + dp[i - 1, j]) % mod;

				if((j > 0) && (a[i, j - 1] == '.'))
					dp[i, j] = (dp[i, j] + dp[i, j - 1]) % mod;
			}
		}

		Console.WriteLine(dp[H - 1, W - 1]);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 20824
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;		

void Main()
{
	int N;
	std::cin >> N;
	std::vector<int> order(N), point(N), bonus(N - 1);
	for (auto& i : order)
	{
		std::cin >> i;
		--i;
	}
	for (auto& p : point)
	{
		std::cin >> p;
	}
	for (auto& b : bonus)
	{
		std::cin >> b;
	}
	int prev = -2;
	int sum = 0;
	for (auto i : order)
	{
		sum += point[i];
		if (i == prev + 1)
		{
			sum += bonus[prev];
		}
		prev = i;
	}
	std::cout << sum << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256