akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7


s=S()
t=S()
ans=0
for i in range(len(s)-len(t)+1):
    ret=0
    for j in range(len(t)):
        if t[j]==s[i+j]:
            ret+=1
    ans=max(ret,ans)

print(len(t)-ans)


Measured memory_bytes: 77692
from itertools import permutations
lst = []
for _ in range(5):
    lst.append(int(input()))
    
ans = float('inf')
for p in permutations(lst):
    elsp = 0
    for i, k in enumerate(p):
        if i <= 3:
            elsp += k
            tmp = elsp//10
            if elsp%10==0:
                elsp = tmp*10
            else:
                elsp = (tmp+1)*10
        else:
            elsp += k
    if elsp <= ans:
        ans = elsp
print(ans)

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

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

void solve(long long N){
    vector<pair<ll, ll>> res;
    for(ll i=2; i<=N/i; i++){
        ll b = 0;
        while(N % i == 0){
            N /= i;
            b++;
        }
        res.emplace_back(i,b);
    }
    if(N != 1) res.emplace_back(N,1);

    ll ans = 0;
    for(auto s : res){
        ll p = s.second;
        ll b = 1;
        while (b <= p){
            p -= b;
            b++;
            ans++;
        }
    }
    cout << ans << endl;
}

// void solve(long long N){
//     vector<pair<ll,int>> fs;
//     for(ll i = 2; i*i <= N; i++){
//         int x = 0;
//         while(N%i == 0){
//             N/=i;
//             ++x;
//         }
//         fs.emplace_back(i,x);
//     }
//     if(N != 1) fs.emplace_back(N,1);

//     int ans = 0;
//     for(auto p : fs) {
//         int x = p.second;
//         int b = 1;
//         while(b <= x){
//             x -= b;
//             b++;
//             ++ans;
//         }
//     }
//     cout << ans << endl;
// }

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


Measured memory_bytes: 19728
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  // input
  int n, k;
  cin >> n >> k;
  int l[60];
  for (int i=0; i<n; i++) cin >> l[i];

  // solve
  sort(l, l+n, greater<int>());
  int res = 0;
  for (int i=0; i<k; i++){
    res += l[i];
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 444444,mo=998244353;
int n;char s[N];
int d[N],len,dp[N],gg,mi[N];
void add(int d, int p, int x){
	if(p>d/2)gg+=x==s[p-d/2]-'0';
}
void del(int d, int p, int x){
	if(p>d/2)gg-=x==s[p-d/2]-'0';
}
int solve(int d){
	int res=0;gg=0;
	rep(i,1,n){
		if(s[i]=='1'){
			add(d,i,0);if(!gg){if(i>=d/2)res++;else res=(res+mi[d/2-i])%mo;}
			del(d,i,0);
		}
	//	if(d==4)cerr<<i<<' '<<res<<' '<<gg<<endl;
		add(d,i,s[i]-'0');
	}
	res+=!gg;
	return res;
}
int main() {
	read(n);scanf("%s",s+1);
	mi[0]=1;rep(i,1,n*2)mi[i]=2LL*mi[i-1]%mo;
	rep(i,1,2*n)if(2*n%i==0&&(2*n/i&1))d[++len]=i;
	rep(j,1,len)dp[j]=solve(d[j]);//,cerr<<d[j]<<' '<<dp[j]<<endl;
	rep(i,1,len)rep(j,1,i-1)if(d[i]%d[j]==0)
		dp[i]=(dp[i]-dp[j]+mo)%mo;
	int res=0;rep(i,1,len)res=(res+1LL*dp[i]*d[i])%mo;cout<<res;
	return 0;
}




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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int64_t mypow(int64_t x, int64_t y) //x ^ y
{
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    else if (y % 2 == 1)
        return mypow(x, y - 1) * x % MOD;
    else
    {
        int64_t tmp = mypow(x, y / 2);
        return tmp * tmp % MOD;
    }
}

int main()
{
    int N;
    cin >> N;
    cout << (mypow(10, N) - 2 * mypow(9, N) + mypow(8, N) + 2 * MOD) % MOD;
}

Measured memory_bytes: 3588
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    double L;
    cin>>L;
    double ans=L*L*L/27.0;
    cout<<ans<<endl;
}

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N;

    vector<int> P(N), Q(N), R(N);

    for(int i=0; i<N; i++)
        cin >> P[i];
    for(int i=0; i<N; i++)
        cin >> Q[i];
    for(int i=0; i<N; i++)
        R[i] = i + 1;

    int a = -1, b = -1, k = 0;

    do {
        k++;

        if(R == P)
            a = k;
        if(R == Q)
            b = k;
            
    } while(next_permutation(R.begin(), R.end()));

    cout << abs(a - b) << "\n";
    return 0;
}


Measured memory_bytes: 256
s=input()
t=input()

count_max = 0
for i in range(0, len(s)-len(t)+1):
    count_tmp = 0
    for j in range(len(t)):
        if s[i+j]==t[j]:
            count_tmp += 1
    if count_max < count_tmp:
        count_max = count_tmp

print(len(t)-count_max)

Measured memory_bytes: 9040
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    v=parseMap(split(readline()))
    odd=Dict{Int,Int}(0=>0)
    even=Dict{Int,Int}(0=>0)
    for i in 1:n
        if i%2==1
            if haskey(odd,v[i])
                odd[v[i]]+=1
            else
                odd[v[i]]=1
            end
        else
            if haskey(even,v[i])
                even[v[i]]+=1
            else
                even[v[i]]=1
            end
        end
    end
    c_odd=sort(collect(odd),by=x->x[2],rev=true)
    c_even=sort(collect(even),by=x->x[2],rev=true)
    if c_odd[1][1]==c_even[1][1]
        println(n-max(c_odd[1][2]+c_even[2][2],c_odd[2][2]+c_even[1][2]))
    else
        println(n-c_odd[1][2]-c_even[1][2])
    end
end
main()

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l-1);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,q; cin>>n>>q;
  vll c(n); rep(i,n) cin>>c[i];
  
  // r,クエリか重複する色の区間か,クエリなら番号,l
  priority_queue<tuple<ll,ll,ll,ll>, vector<tuple<ll,ll,ll,ll>>, greater<tuple<ll,ll,ll,ll>>> que;
  
  // その色が最後に登場したindexを管理する配列
  vll a(n+1,-1);
  rep(i,n){
    if(a[c[i]]!=-1){
      que.emplace(i+1, 0, -1, a[c[i]]);
      // cout<<a[c[i]]<<' '<<i+1<<endl;
    }
    a[c[i]]=i+1;
  }
  
  rep(i,q){
    ll l,r; cin>>l>>r;
    que.emplace(r, 1, i, l);
  }
  
  BIT<ll> bit(n);
  vll ans(q);
  while(!que.empty()){
    ll r, isQ, qNo, l; tie(r,isQ,qNo,l)=que.top(); que.pop();
    // cout<<r<<' '<<isQ<<' '<<qNo<<' '<<l<<endl;
    if(!isQ){
      bit.add(l);
    }else{
      ll res=r-l+1-bit.sum(r);
      if(l-1>0) res+=bit.sum(l-1);
      // cout<<bit.sum(r)<<' '<<bit.sum(l-1)<<endl;
      ans[qNo]=res;
    }
  }
  
  rep(i,q) cout<<ans[i]<<endl;
  
}


Measured memory_bytes: 49996
#include <stdio.h>

int main()
{
    int a, b;

    scanf("%d %d", &a, &b);

    if (a < b)
	printf("a < b");
    else if (a > b)
        printf("a > b");
    else
        printf("a == b");
    printf("\n");

    return 0;
}

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

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

    double a[n];
    double ans = 0;

    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        ans = ans + (1 / a[i]);
    }
    
    ans = 1 / ans;
    cout << fixed << setprecision(10);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

from collections import Counter
from bisect import bisect

N = int(input())
pn = Counter()
for n in range(1,N+1):
    pn.update(prime_factors(n))

pn = sorted(pn.values())

N = len(pn)
cnt = 0
# (3,5,5)
i3 = bisect(pn, 1)
i5 = bisect(pn, 3)
if i5+2 <= N and i3+3 <= N:
    cnt += (N-i3-2) * (N-i5) * (N-i5-1) // 2


# (5,15)
i15 = bisect(pn, 13)
if i15+1 <= N and i5+2 <= N:
    cnt += (N-i15) * (N-i5-1)

    
# (3,25)
i25 = bisect(pn, 23)
if i25+1 <= N and i3+2 <= N:
    cnt += (N-i25) * (N-i3-1)


# (75)
i75 = bisect(pn, 73)
if i75+1 <= N:
    cnt += (N-i75)

print(cnt)




Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main() {
    int n, y;
    cin >> n >> y;
    for(auto i10=n; i10>=0; --i10){
        for(auto i5=n-i10; i5>=0; --i5){
            auto i1=n-i10-i5;
            if(i10*10000+i5*5000+i1*1000==y){
                cout << i10 << " " << i5 << " " << i1 << "\n";
                return 0;
            }
        }
    }
    cout << "-1 -1 -1\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    Int X, A;
    cin >> X >> A;
    if (X>=A){
        cout << 10 << endl;
    }else{
        cout << 0 << endl;
    }




    return 0;
}

Measured memory_bytes: 256
dice = [int(e) for e in input().split()]
roll = input()
for roll1 in roll: 
    if roll1 == "N":
        dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    elif roll1 == "W":
        dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
    elif roll1 == "E":
        dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    elif roll1 == "S":
        dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
print(dice[0])


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    vector<int> a({
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51});
    int k;cin >> k;
    cout << a[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
N,W=map(int,input().split())
dp=[[0 for i in range(W+1)]for j in range(N+1)]
goods=[]
for i in range(N):
    v,w=map(int,input().split())
    goods.append([v,w])

    
for i in range(N):
    v=goods[i][0]
    w=goods[i][1]
    for j in range(W+1):
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        next_w=j+w
        next_v=dp[i][j]+v
        if(next_w<=W and next_v>dp[i+1][next_w]):
            dp[i+1][next_w]=next_v

ans=0
for i in range(W+1):
    ans=max(ans,dp[N][i])
print(ans)

Measured memory_bytes: 28000
N, K = map(int, input().split())
SC = list(map(int, input().split()))
T = input()
Q = []
for i in range(len(T)):
  if T[i] == "r":
    Q.append(0)
  elif T[i] == "s":
    Q.append(1)
  else:
    Q.append(2)
my = [0 for i in range(N)]
ans = 0
for i in range(N):
  if i < K:
    my[i] = (Q[i] - 1) % 3
    ans += SC[my[i]]
  else:
    n = (Q[i] - 1) % 3
    if my[i - K] != n:
      my[i] = n
      ans += SC[my[i]]
    else:
      if i + K < N:
        my[i] = Q[i+K]
print(ans)

Measured memory_bytes: 85624
#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
     
    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long
    #define ld long double
     
    #define vi vector<int>
    #define vl vector<long>
    #define vll vector<long long>
     
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
    #define F first
    #define S second
    #define G(a,b) get<a>(b)
    #define MP make_pair
    #define MT make_tuple
    #define pll pair<ll,ll> 
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;

         
    const ll N=1e6+7;
    ll p=998244353;
    ll fac[N];
     
    ll gcd(ll a, ll b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
     
    inline ll ceil(ll a,ll b)
    {
      return (a+b-1)/b;
    }
     
    ll max(ll x,ll y,ll z)
    {
      return max(x,max(y,z));
    }
     
     
    ll modpro(ll x,ll y,ll z=1)
    {
      x%=p;
      y%=p;
      z%=p;
      ll res=(x*y)%p;
      res=(res*z)%p;
      return res;
    }
     
    ll modadd(ll x,ll y,ll z=0)
    {
      ll res=(x+y)%p;
      res=(res+z)%p;
      return res;
    }
     
     
    ll pow_mod_p(ll a,ll b)
    {
      a=a%p;
      ll res=1;
      while(b>0)
      {
        if(b&1) res=(res*a)%p;
        b=b>>1;
        a=(a*a)%p;
      }
      return res;
    }
     
    inline ll mod_inv(ll x)
    {
      return pow_mod_p(x,p-2);
    }
     
    
    ll nCr(ll x,ll y)
    {
      if(x<y) return 0;
      ll res=fac[x];
      ll den=(fac[y]*fac[x-y])%p;
      ll deni=mod_inv(den);
      res=(res*deni)%p;
      return res;
    }


    ll n,m,k;
    ll calc(ll i)
    {
        ll res=m;
        res=modpro(res,pow_mod_p(m-1,i-1));
        return res;
    }


    void func()
    {
       
       cin>>n>>m>>k;

       fac[0]=fac[1]=1;
       f(i,2,N) fac[i]=modpro(fac[i-1],i);

       ll ans=0;
       f(z,0,k+1)
       {
          ans=modadd(ans,modpro(calc(n-z),nCr(n-1,z)));
       }

       pr(ans) nl

    }   
     
     
    int main() 
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE
        
     
        ll ntc=1;
        //cin>>ntc;
     
        f(i,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";
          func();
        }
     
        return 0;
    }

Measured memory_bytes: 11464
#include<iostream>
#include<string>
#include <vector>

using namespace std;

int main()
{
	int N, L;
	string result;
	int flag = 0;
	std::string tmp;

	std::cin >> N;
	std::cin >> L;

	vector<string> str(N);

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

	do
	{
		flag = 0;
		for (int i = 0; i < N-1; i++)
		{
			if (0 < str[i].compare(str[i + 1]))
			{
				flag = 1;
				tmp = str[i];
				str[i] = str[i + 1];
				str[i + 1] = tmp;
			}
		}
	} while (flag == 1);

	for (int i = 0; i < N; i++)
		result += str[i];

	std::cout << result << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
	string s;
	cin >> s;
	vector<int> v;
	for(auto it = s.begin(); it != s.end(); ++it) {
		v.push_back(*it - 0x61);
	}
	int K;
	cin >> K;
	int L = s.length();
	for(int i = 0; i < L - 1; i++) {
		if(v[i] == 0) continue;
		int M = 26 - v[i];
		if(K >= M) {
			v[i] = 0;
			K -= M;
		}
	}
	if(K >= 0) {
		v[L - 1] = (v[L - 1] + K) % 26;
	}
	for(int i = 0; i < L; i++) {
		s[i] = v[i] + 0x61;
	}
	cout << s << endl;
}

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

using namespace std;

using int64 = long long;

int main() {
  string S;
  cin >> S;

  int64 ret = 1LL << 60;
  for(int i = 0; i + 3 <= S.size(); i++) {
//    cout << S.substr(i, 3) << endl;

    int x = stoi(S.substr(i, 3));

    ret = min(ret, llabs(x - 753));
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,lint> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<pint> ta[114514],yo[114514];
vector<pint> gt[114514],gy[114514];
int r[114514],c[114514];
lint a[114514];
lint numt[114514],numy[114514],mint[114514],miny[114514];
bool sumt[114514],sumy[114514];
string out="Yes";
vector<int> V;lint mi;
void dfst(int now,lint v){
	if(sumt[now]){
		if(numt[now]!=v) out="No";
	}
	else{
		sumt[now]=true;numt[now]=v;mi=min(mi,v);V.pb(now);
		rep(i,gt[now].size()) dfst(gt[now][i].fi,gt[now][i].se+v);
	}
}
void dfsy(int now,lint v){
	if(sumy[now]){
		if(numy[now]!=v) out="No";
	}
	else{
		sumy[now]=true;numy[now]=v;mi=min(mi,v);V.pb(now);
		rep(i,gy[now].size()) dfsy(gy[now][i].fi,gy[now][i].se+v);
	}
}
int main()
{
	int R,C,n;
	scanf("%d %d",&R,&C);
	scanf("%d",&n);
	rep(i,n) scanf("%d %d %lld",&r[i],&c[i],&a[i]);
	rep(i,n){
		r[i]--;c[i]--;
		ta[r[i]].pb(mp(c[i],a[i]));
		yo[c[i]].pb(mp(r[i],a[i]));
	}
	rep(i,100100){
		if(ta[i].size()<2) continue;
		int m=ta[i].size();
		sort(All(ta[i]));
		rep(j,m-1){
			gt[ta[i][j].fi].pb(mp(ta[i][j+1].fi,ta[i][j+1].se-ta[i][j].se));
			gt[ta[i][j+1].fi].pb(mp(ta[i][j].fi,ta[i][j].se-ta[i][j+1].se));
		}
	}
	rep(i,100100){
		if(yo[i].size()<2) continue;
		int m=yo[i].size();
		sort(All(yo[i]));
		rep(j,m-1){
			gy[yo[i][j].fi].pb(mp(yo[i][j+1].fi,yo[i][j+1].se-yo[i][j].se));
			gy[yo[i][j+1].fi].pb(mp(yo[i][j].fi,yo[i][j].se-yo[i][j+1].se));
		}
	}
	
	memset(sumt,false,sizeof(sumt));
	rep(i,100100){
		if(sumt[i]) continue;
		mi=0;V.clear();dfst(i,0);
		rep(j,V.size()) mint[V[j]]=mi;
	}
	memset(sumy,false,sizeof(sumy));
	rep(i,100100){
		if(sumy[i]) continue;
		mi=0;V.clear();dfsy(i,0);
		rep(j,V.size()) miny[V[j]]=mi;
	}
	/*rep(i,6){
		if(sumt[i]) cout<<numt[i]<<' '<<mint[i]<<endl;
		if(sumy[i]) cout<<numy[i]<<' '<<miny[i]<<endl;
	}*/
	rep(i,n){
		swap(r[i],c[i]);
		if((lint)a[i]-numt[r[i]]-numy[c[i]]+mint[r[i]]+miny[c[i]]<0) out="No";
	}
	/*if(out=="No"){
		while(1){}
	}*/
	cout<<out<<endl;
}


Measured memory_bytes: 28800
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n);
    int[] b = na(n);

    int ret = 0;

    for (int i = 28; i >= 0; i--) {
      for (int j = 0; j < n; j++) {
        a[j] &= ~(1 << (i + 1));
        b[j] &= ~(1 << (i + 1));
      }
      Arrays.sort(a);
      long x = 0;
      for (int v : b) {
        x += lowerBound(a, (2 << i) - v) - lowerBound(a, (1 << i) - v);
        x += n - lowerBound(a, (3 << i) - v);
      }
      ret |= (x % 2) << i;
    }

    System.out.println(ret);
  }


  public static int lowerBound(int[] a, int v) {
    int low = -1, high = a.length;
    while (high - low > 1) {
      int h = high + low >>> 1;
      if (a[h] >= v) {
        high = h;
      } else {
        low = h;
      }
    }
    return high;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

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

  int dummy = n;
  int sum = 0;

  while(dummy != 0){
    sum += (dummy % 10);
    dummy /= 10;
  }

  if(n % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 636
#include <stdio.h>

int main(void){
	int a,b,i,j,no,set;
	int sa_a,sa_b;
	int tama[10];
	
	scanf("%d",&set);
	for(j=0;j < set;j++){
		scanf("%d %d %d %d %d %d %d %d %d %d",&tama[0],&tama[1],&tama[2],&tama[3],&tama[4],&tama[5],&tama[6],&tama[7],&tama[8],&tama[9]);
		a=0,b=0,no=0;
		for(i=0;i < 10;i++){
			sa_a = tama[i]-a;
			sa_b = tama[i]-b;
			if(sa_a <= sa_b && sa_a > 0){
				a = tama[i];
			}else if(sa_b > 0){
				b = tama[i];
			}else{
				printf("NO\n");
				no = 1;
				break;
			}
		}
		if(no == 0) printf("YES\n");
	}
	return 0;
}

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

int main() {
    long long N, K;
    cin >> N >> K;
    
    double res = 0.0;
    for (long long n = 1; n <= N; ++n) {
        double tmp = 1.0;
        long long nn = n;
        while (nn < K) nn *= 2, tmp /= 2.0;
        res += tmp;
    }
    res /= N;
    cout << fixed << setprecision(10) << res << endl;
}

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

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

pair<int,int>s[10];
int p[10];
void solve(){
    int n;
    s[0].X = s[0].Y = 0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        p[i] = i;
    }
    int cnt = 0;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&s[i].X,&s[i].Y);
    }
    double ans = 0;
    do{
        ++cnt;
        // for(int i=1;i<=n;i++)
        // {
        //     printf("%d%c", p[i]," \n"[i==n]);
        // }
        double tmp = 0;
        for(int i=2;i<=n;i++){
            tmp += sqrt((s[p[i]].X - s[p[i-1]].X)*(s[p[i]].X - s[p[i-1]].X) + (s[p[i]].Y - s[p[i-1]].Y)*(s[p[i]].Y - s[p[i-1]].Y));
        }
      //  printf("tmp = %.10f\n",tmp );
        ans += tmp;
    }while(next_permutation(p+1,p+1+n));
    
    printf("%.10f\n",ans/cnt);
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
   // freopen("in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
#ifndef ONLINE_JUDGE
   // printf("%.10f\n",1.0*clock()/CLOCKS_PER_SEC);
#endif
    return 0;
}

Measured memory_bytes: 256
(function(input) {
    console.log(input.replace(/\n$/, '').split('').map(function(e) {
        if (e.match(/[a-z]/)) {
            return e.toUpperCase();
        } else if (e.match(/[A-Z]/)) {
            return e.toLowerCase();
        }
        return e;
    }).join(''));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9392
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    long long int n,d,c=0,ans=0;
    vector<vector<int>>a(1000,vector<int>(1000));
    cin>>n>>d;
    for(long long int i=0;i<n;i++){
        for(long long int j=0;j<d;j++){
            cin>>a[i][j];
        }
    }
    for(long long int i=0;i<n;i++){
        for(long long int j=i+1;j<n;j++){
            for(long long int k=0;k<d;k++){
                c+=((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
            }
            for(int k=1;k*k<=c;k++){
                if(c==k*k){
                    ans++;
                }
            }
            c=0;
        }
        
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7532
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
string s,t;
int main(){
	cin>>s>>t;
	string ans="~";
	for(int i=0;i+SZ(t)<=SZ(s);i++){
		bool ok=true;
		string b="";
		for(int j=i;j<i+SZ(t);j++){
			if(s[j]=='?'){
				continue;	
			}
			if(s[j]!=t[j-i]){
				ok=false;
				break;
			}
		}
		if(ok){
			for(int j=0;j<i;j++){
				if(s[j]=='?')b+='a';
				else b+=s[j];
			}
			for(int j=i;j<i+SZ(t);j++){
				b+=t[j-i];
			}
			for(int j=i+SZ(t);j<SZ(s);j++){
				if(s[j]=='?')b+='a';
				else b+=s[j];
			}
			if(b<ans){
				ans=b;
			}
		}
	}
	if(ans=="~"){
		cout<<"UNRESTORABLE"<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

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

class PaizaSample
{


    static void Main()
    {

        List<List<int>> list = new List<List<int>>();
        string input;
        while ((input = Console.ReadLine()) != null)
        {
            int[] array = input.Split(',').Select(a => int.Parse(a)).ToArray();

            if (list.Count == 0)
            {
                list.Add(array.ToList());
            }
            else if (list[list.Count - 1].Count < array.Length)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    if (i == 0)
                    {
                        array[i] += list[0][0];
                    }
                    else if (i == array.Length - 1)
                    {
                        array[i] += list[0][array.Length - 2];
                    }
                    else
                    {
                        array[i] += list[0][i - 1] > list[0][i] ? list[0][i - 1] : list[0][i];
                    }
                }
                list[0] = array.ToList();
            }
            else
            {
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] += list[0][i] > list[0][i + 1] ? list[0][i] : list[0][i + 1];
                }
                list[0] = array.ToList();
            }
            
        }

        Console.WriteLine(list[0][0]);

        //Console.ReadKey();

    }
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+5;
ll aa[N];
ll bb[N];
ll cc[N];
void solve(){
	int x,y; 
	cin>>x>>y;
	int a,b,c;
	cin>>a>>b>>c;
	priority_queue<ll > pa;
	priority_queue<ll > pb;
	for(int i=0;i<a;i++){
		cin>>aa[i];
	}
	for(int i=0;i<b;i++){
		cin>>bb[i];
	}
	for(int i=0;i<c;i++){
		cin>>cc[i];
	}
	sort(aa,aa+a);
	sort(bb,bb+b);
	sort(cc,cc+c);
	reverse(aa,aa+a);
	reverse(bb,bb+b);
	reverse(cc,cc+c);
	for(int i=0;i<x;i++){
		pa.push(-aa[i]);
	}
	for(int i=0;i<y;i++){
		pb.push(-bb[i]);
	}
	for(int i=0;i<c;i++){
		ll tra = -pa.top();
		pa.pop();
		ll trb = -pb.top();
		pb.pop();
		if(cc[i]<=tra and cc[i]<=trb){
			pa.push(-tra);
			pb.push(-trb);
			break;
		}
		if(tra<=trb){
			if(cc[i]<=tra)break;
			pa.push(-cc[i]);
			pb.push(-trb);
		}
		else{
			if(cc[i]<=trb)break;
			pb.push(-cc[i]);
			pa.push(-tra);
		}
	}
	ll ans = 0;
	while(!pa.empty()){
		ans+=-pa.top();
		pa.pop();
	}
	while(!pb.empty()){
		ans+=-pb.top();
		pb.pop();
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 7948
# 参考url: https://beta.atcoder.jp/contests/abc045/submissions/2365068

from collections import Counter, defaultdict

H, W, N = map(int, input().split())

squares = defaultdict(int)
for i in range(N):
    h, w = map(int, input().split())
    for hh in range(3):
        for ww in range(3):
            th, tw = h-hh, w-ww
            # th, twを左上とする3×3の正方形は与えられたグリッドに収まるか
            if 1 <= th <= H-2 and 1 <= tw <= W-2:
                squares[(th, tw)] += 1

ans = [0] * 10
for v in squares.values():
    ans[v] += 1

# 黒マスが0 = 正方形の総数-黒マスが1個以上の正方形
ans[0] = (H-2)*(W-2) - sum(ans)

print(*ans, sep="\n")

Measured memory_bytes: 166860
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 6e18
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
signed main(){
    int n,m;
    cin>>n>>m;
    vp vec(n);
    map<int,int> a,b;
    REP(i,n){
        cin>>vec[i].fi>>vec[i].se;
        a[vec[i].fi]=0;
        b[vec[i].se]=0;
    }
    int aa=0;
    vi x;
    vi y;
    for(auto itr:a){
        a[itr.fi]=aa;
        aa++;
        x.pb(itr.fi);
    }
    int bb=0;
    for(auto itr:b){
        b[itr.fi]=bb;
        y.pb(itr.fi);
        bb++;
    }
    
    vvi sum(50,vi(50));
    REP(i,n){
        sum[a[vec[i].fi]][b[vec[i].se]]=1;
    }
    FOR(i,0,50){
        FOR(j,1,50){
            sum[i][j]+=sum[i][j-1];
        }
    }
    FOR(i,1,50){
        FOR(j,0,50){
            sum[i][j]+=sum[i-1][j];
        }
    }
    int p=x.size(),q=y.size();
    int ans=INF;
    REP(i,p){
        REP(j,q){
            FOR(k,i+1,p){
                FOR(l,j+1,q){
                    int t=0;
                    t=sum[k][l];
                    if(i-1>=0)t-=sum[i-1][l];
                    if(j-1>=0)t-=sum[k][j-1];
                    if(i-1>=0&&j-1>=0)t+=sum[i-1][j-1];
                    if(t>=m){
                        ans=min(ans,(x[k]-x[i])*(y[l]-y[j]));
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX_V 1000000
int prime[MAX_V + 1];
int count;
int main(){
  int n, i, k;
  for(i = 2;i <= MAX_V;i++){
    prime[i] = 1;
  }
  for(i=2;i*i<=MAX_V;i++){
    if(prime[i]){
      for(k = 2*i;k <= MAX_V;k += i){
        prime[k] = 0;
      }
    }
  }
  scanf("%d", &n);
  while(n != 0){
    for(i=n;i>0;i--){
      if(prime[i]){
        if(prime[i-2]){
          printf("%d %d\n", i-2, i);
          break;
        }
      }
    }
    scanf("%d", &n);
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int countAB(string s){
    int ret = 0;
    reps(i,1,s.size()-1){
        if(s[i-1]=='A'&&s[i]=='B'){
            ret++;
            i++;
        }
    }
    return ret;
}

int main(){
    int N; cin >> N;
    vector<string> s(N);
    collect(s, N);
    int res = 0;
    int a = 0, b = 0, ba = 0;
    rep(i,N){
        res += countAB(s[i]);
        bool has_A = *(s[i].end()-1)=='A';
        bool has_B = *(s[i].begin())=='B';
        if(has_A && has_B){
            ba++;
            continue;
        }
        if(has_A) a++;
        if(has_B) b++;
    }
    
    if(ba>0){
        res += ba - 1;
        if(a > 0){
            res++; a--;
        }
        if(b > 0){
            res++; b--;
        }
    }
    res += min(a,b);
    
    cout << res << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
 
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  //  freopen("./input.txt","r",stdin);
  //  freopen("./output.txt","w",stdout);
    int n;
    cin>>n;
    vector< pair<int,int> > v;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back(make_pair(b,a));
    }
    sort(v.begin(),v.end());
    int crt= 0;
    for(int i=0;i<n;i++)
    {
        crt+=v[i].second;
        if(crt>v[i].first)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

}

Measured memory_bytes: 2420
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    max_a = min(x - 3, n)
    min_a = max(x // 3 + 1, 3)
    cnt = 0
    for i in range(min_a, max_a + 1):
        max_b = min(i - 1, x - i - 1)
        min_b = (x - i) // 2 + 1
        cnt += (max_b - min_b + 1)
    print(cnt)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

ll dp[20001][256];
ll f(ll x, ll y) {
	return (x - y) * (x - y);
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M;
	while ( cin >> N >> M, N || M ) {
		fill(dp[0], dp[20001], linf);
		vector<int> C(M); cin >> C;
		vector<int> x(N); cin >> x;
		dp[0][128] = 0;
		REP(i, N) {
			REP(j, 256) {
				if (dp[i][j] == linf) continue;
				REP(k, M) {
					int nj = max(0LL, min(255LL, j + C[k]));
					dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + f(nj, x[i]));
				}
			}
		}
		ll ans = linf;
		REP(i, 256) ans = min(ans, dp[N][i]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 43164
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;
const int BIG = 998244353;

const int X = 2019;




int main() {

	int N;
	cin >> N;
	ll A[200000];

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

	ll sum = 0;

	for (int i=1; i<=N; i++){
		sum += A[i];
	}

	for (int i = 2; i <= N - 1; i = i + 2) {
		sum = sum - A[i]*2;
	}

	cout << sum <<" ";

	for (int i = 1; i <= N - 1; i++) {
		sum = 2 * A[i] - sum;
		cout << sum << " ";
	}


	

	system("PAUSE");
}

Measured memory_bytes: 2296
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	vector<LL> cost(4);
	for(int i=0;i<4;++i){
		cin >> cost[i];
	}
	LL MIN2 = LINF;
	MIN2 = min(cost[0]*8,cost[1]*4);
	MIN2 = min(MIN2,cost[2]*2);
	MIN2 = min(MIN2,cost[3]);
	
	LL MIN1 = LINF;
	MIN1 = min(cost[0]*4,cost[1]*2);
	MIN1 = min(MIN1,cost[2]);

	LL N;
	cin >> N;

	LL ans = (N/2)*MIN2 + (N%2)*MIN1;
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
def simulate(s,td,m):
  pos=m
  for i in range(q):
#    print(i,s[pos],td[i][0],pos)
    if s[pos]!=td[i][0]:
      continue
    if td[i][1]=='R':
      pos+=1
      if pos>n-1:
#        print("r fall")
        return 1
    else:
      pos-=1
      if pos<0:
#        print("l fall")
        return -1
  return 0
    
n,q=map(int,input().split())
s=input()
td=[input().split() for i in range(q)]

l=-1
r=n

while l+1<r:
  m=(l+r)//2
#  print("l=",l,"m=",m,"r=",r)
  if simulate(s,td,m)==-1:
    l=m
  else:
    r=m
left=r
#print("left",left)

l=-1
r=n
while l+1<r:
  m=(l+r)//2
  if simulate(s,td,m)==1:
    r=m
  else:
    l=m
right=n-1-l

print(n-left-right)



Measured memory_bytes: 39728
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s, t = S_MAP()
print(t + s)

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

vector<pair<int,int>> prime_fact(int n){
    vector<pair<int,int>> a;
    if (n <= 1) return a;
    int n_origin = n;
    for(int i=2; i<=(int)sqrt(n_origin); i++){
        if (n%i == 0){
            int count = 0;
            while(n%i == 0){
                n/=i;
                count ++;
            }
            a.push_back(make_pair(i, count));
        }
    }
    if (n!=1){
        a.push_back(make_pair(n,1));
    }
    return a;
}

int main() {
    int n; cin >> n;
    vector<pair<int,int>> primes = prime_fact(n);
    cout << n << ":";
    for (auto p: primes){
        REP(i, p.second){
            cout << " " << p.first;
        }
    }
    cout << endl;

    return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep (i, h) {
    cin >> a[i];
  }
  vll dp(h, vl(w));
  dp[0][0] = 1;
  rep (i, h) {
    rep (j, w) {
      if (a[i][j] == '#') continue;
      if (i != 0) {
        dp[i][j] += dp[i - 1][j];
      }
      if (j != 0) {
        dp[i][j] += dp[i][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[h - 1][w - 1] << endl;
}
  


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, i, x, prv = -1, sol = 0;
	
	cin>>n;
	
	for (i = 0; i < n; ++i)
	{
		cin>>x;
		
		if (x == prv)
		{
			++sol;
			prv = -1;
		}
		else prv = x;
	}
	
	cout<<sol<<'\n';
}


Measured memory_bytes: 892