akhauriyash/Code-Regression huggingface dataset:
import itertools
K=int(input())
X,Y=map(int,input().split())
Mdist=abs(X)+abs(Y)
if Mdist%2==1 and K%2==0:
    print(-1)
    exit()
    #K:偶数ならマンハッタン距離が偶数の点にしか行けない
    #逆にKが偶数ならマンハッタン距離が偶数の任意の点に行ける
    #K:奇数なら理論上どこでも行ける
    #よってこれ以外のパターンは全部可能
    #(0,0)->(2n+1,0)->(n+1,n+1)->(1,0)
#K:奇数のとき、移動回数と距離がmod2 で合同
def searcheven(x,y):
    if abs(x)+abs(y)>2*K:
        return None
    if (abs(x)+abs(y))%2==1:
        return None
    for ps in itertools.product([-1,1],repeat=4):
        p1,p2,p3,p4=ps
        if p1*p4==p2*p3:
            if p3*(K-p1*x-p2*y)==-p1*K:
                a,b=0,p4*K
                if abs(x-a)+abs(y-b)==K and abs(a)+abs(b)==K:
                    return (a,b)
                a,b=p3*K,0
                if abs(x-a)+abs(y-b)==K and abs(a)+abs(b)==K:
                    return (a,b)
            else:
                pass
        else:
            tmp1=K-p1*x-p2*y
            tmp2=K
            tmp3=p4*tmp1+p2*tmp2
            tmp4=-p3*tmp1-p1*tmp2
            det=-p1*p4+p2*p3
            a,b=(tmp3//det,tmp4//det)
            if abs(x-a)+abs(y-b)==K and abs(a)+abs(b)==K:
                return (a,b)
            else:
                pass
    return None

ans=[(0,0)]
while(True):
    nx,ny=ans[-1]
    if abs(nx-X)+abs(ny-Y)<=2*K:
        if (abs(nx-X)+abs(ny-Y))%2==0:
            p,q=searcheven(X-nx,Y-ny)
            ans.append((p+nx,q+ny))
            ans.append((X,Y))
            break
        else:
            if abs(nx-X)+abs(ny-Y)==K:
                ans.append((X,Y))
                break
            tmpx=K//2
            tmpy=K-tmpx
            nextkouho=[(tmpx,tmpy),(tmpx,-tmpy),(-tmpx,tmpy),(-tmpx,-tmpy),(K,0),(-K,0),(0,K),(0,-K)]
            for point in nextkouho:
                ptmp,qtmp=point
                p=ptmp+nx;q=qtmp+ny
                if abs(X-p)+abs(Y-q)<=2*K:
                    ans.append((p,q))
                    break
    elif abs(nx)+K<=abs(X):
        if X<0:
            ans.append((nx-K,ny))
            continue
        else:
            ans.append((nx+K,ny))
            continue
    elif abs(ny)+K<=abs(Y):
        if Y<0:
            ans.append((nx,ny-K))
            continue
        else:
            ans.append((nx,ny+K))
            continue


#print(ans)
s=len(ans)-1
flag=1
for i in range(s):
    ax,ay=ans[i]
    bx,by=ans[i+1]
    if abs(ax-bx)+abs(ay-by)==K:
        pass
    else:
        flag=0
        break
if flag==0:
    print("NG")
print(s)
for i in range(1,s+1):
    print(ans[i][0],ans[i][1])


Measured memory_bytes: 26164
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
    ls <- map read . words <$> getLine
    let [n, m, x] = ls

    raw <- replicateM n getLine
    let ulis = map convert (map words raw)

    let ans = successList ulis (take m $ repeat 0) x 0 []
    print $ minimum $ if ans == []
                        then [-1]
                        else ans

convert :: [String] -> (Int, [Int])
convert l = ((read (head l)), (map read (tail l)))

successList :: [(Int, [Int])] -> [Int] -> Int -> Int -> [Int] -> [Int]
successList [] ulis _ cost lis = lis
successList (b:bs) ulis x cost ans = including ++ excluding
        where including = successList bs newlist x (cost + (fst b)) (newsuccesslist newlist)
              excluding = successList bs ulis x cost (newsuccesslist ulis)
              newlist = zipWith (+) (snd b) ulis
              newsuccesslist judging = if all (\y -> x <= y) judging
                  then (cost + (fst b)) : ans
                  else ans

Measured memory_bytes: 4980
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= a && c <= b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
x1, y1, x2, y2 = map(int,input().split())

dx = x2 - x1
dy = y2 - y1

x3, y3 = x2 - dy, y2 + dx
x4, y4 = x3 - dx, y3 - dy

print(x3, y3, x4, y4)


Measured memory_bytes: 38384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

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

ll dp[41][410][410];

int main(){
  int n,ma,mb; cin >> n >> ma >> mb;
  rep(z,41)rep(i,410)rep(j,410) dp[z][i][j]=inf;
  dp[0][0][0]=0;
  rep(z,n){
    int a,b,c;
    cin >> a >> b >> c;
    rep(i,410)rep(j,410){
      if(i+a<410&&j+b<410){
        chmin(dp[z+1][i+a][j+b],dp[z][i][j]+c);
        chmin(dp[z+1][i][j],dp[z][i][j]);
      }
    }
  }
  ll ans=inf;
  rep(i,410)rep(j,410){
    if(i==0||j==0) continue;
    ll GCD=gcd(i,j);
    if(i/GCD==ma&&j/GCD==mb) chmin(ans,dp[n][i][j]);
  }
  if(ans==inf) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 57472
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


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


    string s;
    cin>>s;
    int cnt = 0;
    for (int i = 0; i<s.size()-1; i++) if (s[i]!=s[i+1]) cnt++;
    cout<<cnt;


}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<ll> a(M), b(M), c(M, 0); // cはbitであらわす
  for (int i = 0; i < M; i++)
  {
    cin >> a[i] >> b[i];
    for (int j = 0; j < b[i]; j++)
    {
      int t;
      cin >> t;
      t--;
      c[i] += (1 << t);
    }
  }
  static ll dp[1100][5000];
  for (int i = 0; i < 1100; i++)
  {
    for (int j = 0; j < 5000; j++)
    {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;
  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < (1 << N); j++)
    {
      chmin(dp[i + 1][j], dp[i][j]);

      int nj = j | c[i];
      chmin(dp[i + 1][nj], dp[i][j] + a[i]);
    }
  }
  cout << (dp[M][(1 << N) - 1] < INF ? dp[M][(1 << N) - 1] : -1) << endl;
  return 0;
}

// bitDP? 0以上2^N未満の整数jが「1以上N以下の整数kについて現在購入している鍵で宝箱kを開けられることとjを2進数表記した際にk - 1桁目が1であることと同値．という状態を表すことにする．dpテーブルを次のように定義する．dpi,j= i+1番目以降の鍵を購入せずに状態をjにするために必要な最小費用　1以上N以下の整数iについて0以上2^N未満の整数diを1以上N以下の整数kについて鍵iで宝箱kを開けられることとdiを2進数表記したときにk-1桁目が1であることと同値　となるように定める．このとき，動的計画法の遷移式は
// dpi,j or di = min(dpi-1,j or di, dpi-1,j+ai) となる
// i番目の鍵を使わないとき　chmin(dp[i+1][s],dp[i][s]) i番目の鍵を使う時　i番目の鍵に対応している宝箱の集合をビットc[i]であらわすとするとchmin(dp[i+1][s | c[i]], dp[i][s] + ai)となる．(dp[i][s]:=最初のi個の鍵からいくつか選んで開いた宝箱の集合がSであらわされるような場合についての最小コスト)


Measured memory_bytes: 43264
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll; 
const ll max_n=1e5+50 ; 
const ll mod=1e9+7;
int x,y,A,B,C;
int a[max_n],b[max_n],c[max_n],res[max_n*2];
int main(){
    scanf("%d%d%d%d%d",&x,&y,&A,&B,&C);
    for(int i=0;i<A;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<B;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<C;i++){
        scanf("%d",&c[i]);
    }
    sort(a,a+A);sort(b,b+B);sort(c,c+C);
    ll ans=0;
    for(int i=1;i<=x;i++){
        res[i-1]=a[A-i];
    }
    for(int i=1;i<=y;i++){
        res[x+i-1]=b[B-i];
    }
    for(int i=1;i<=C;i++){
        res[x+y-1+i]=c[i-1];
    }
    sort(res,res+x+y+C);
    //for(int i=0;i<x+y;i++)cout<<res[i]<<' ';
    //cout<<endl;
    for(int i=1;i<=x+y;i++){
        ans+=res[x+y+C-i];
    }
    printf("%lld\n",ans);
	return 0 ; 
}



Measured memory_bytes: 2176
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;

int n;

struct node
{
	int id, k, d, pid;
	int* cid;
	string type;
}N[100005];

void GetDepth(node& GN)
{
	GN.d = 0;
	node temp = GN;

	while (temp.pid != -1)
	{
		GN.d++;
		temp = N[temp.pid];
	}
}

void GetType(node& GN)
{
	if (GN.pid == -1)
		GN.type = "root";
	else if (GN.k == 0)
		GN.type = "leaf";
	else
		GN.type = "internal node";
}

void print()
{
	for (int i = 0; i < n; i++)
	{
		cout << "node " << N[i].id << ": " << "parent = " << N[i].pid << ", " << "depth = " << N[i].d << ", " << N[i].type << ", " << "[";

		if (N[i].k != 0)
		{
			for (int j = 0; j < N[i].k - 1; j++)
				cout << N[i].cid[j] << ", ";
			cout << N[i].cid[N[i].k - 1];
		}

		cout << "]" << endl;
	}	
}

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

	int place;
	cin >> n;
	
	for (int i = 0; i < n; i++)
		N[i].pid = -1;
	
	for (int i = 0; i < n; i++)
	{
		cin >> place;
		N[place].id = place;
		cin >> N[place].k;

		if (N[place].k > 0)
			N[place].cid = (int*)malloc(sizeof(int) * N[place].k);

		for (int j = 0; j < N[place].k; j++)
		{
			cin >> N[place].cid[j];
			for (int t = 0; t < n; t++)
			{
				if (N[place].cid[j] == t)
				{
					N[t].pid = N[place].id;
					break;
				}	
			}
		}			
	}

	for (int i = 0; i < n; i++)
		GetDepth(N[i]);

	for (int i = 0; i < n; i++)
		GetType(N[i]);	

	print();

	return 0;
}


Measured memory_bytes: 11428
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ps = (0 until n).map {
        val (x, y, h) = readLine()!!.split(' ').map { it.toInt() }
        Triple(x, y, h)
    }

    val p = ps.first { it.third > 0 }

    for (cx in 0..100) {
        for (cy in 0..100) {
            val ch = p.third + Math.abs(p.first - cx) + Math.abs(p.second - cy)
            if (ps.all { it.third == Math.max(ch - Math.abs(it.first - cx) - Math.abs(it.second - cy), 0) }) {
                println("$cx $cy $ch")
                return
            }
        }
    }

}


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

int main() {
    int a, p;
    cin >> a >> p;
    int sum;
    sum = a*3 + p;
    int ans;
    ans = sum/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())
a = 0
b = 0
for i in range(X + 1):
    N = i
    if (X - N) % 2 != 0 and N != X:
        continue
    M = int((X - N) / 2)
    
    x = N + 2 * M
    y = 2 * N + M
    if X == x and Y == y:
        a = N
        b = M
#print(a)

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if a != 0 and b != 0:
    #print(a, b)
    ans = cmb(a + b,a) % (10**9+7)
    print(ans)
elif a == 0 and b != 0:
    print("1")
elif a != 0 and b == 0:
    print("1") 
else:
    print("0")

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

const int N = (int)1e6 + 6;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	if(n % 2 == 1) cout << "No";
	else{
		string a = s.substr(0,n / 2);
		string b = s.substr(n / 2,n / 2);
		if(a == b) cout << "Yes";
		else cout << "No";
	}	
	return 0;
}

Measured memory_bytes: 256
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

int n, k;
vector<int> p;

void read_input()
{
    cin >> n >> k;
    p.resize(n);
    for(auto&x: p) cin >> x;
}

void solve()
{
    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0; i < k; ++i)
        ans += p[i];
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



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

int main() {
  long n,m;
  cin >>n >>m;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++){
    int p,su;
    cin >>p>>su;
    a.at(i)=make_pair(p,su);
  }
  sort(a.begin(),a.end());
  long ans=0;
  int i=0;
  while(m!=0){
    long p,su;
    tie(p,su)=a.at(i);
    ans += p*min(m,su);
    m -= min(m,su);
    i++;
  }
  cout <<ans;
}

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

vector<int >sss[2000000];
stack<int>spisuk;
bool pos[2000000];
bool otg=false;
int kolko[2000000];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
int n,m,a,b,c=0;
cin>>n>>m;
for(int i=0;i<m;i++){
 cin>>a>>b;
 sss[a].push_back(b);
}
spisuk.push(1);
pos[1]=true;
kolko[1]=0;
while(spisuk.empty()==false){
    a=spisuk.top();
    spisuk.pop();
    for(int i=0;i<sss[a].size();i++){
            b=sss[a][i];
        if(pos[b]==false){

                kolko[b]=kolko[a]+1;
           pos[b]=true;
            spisuk.push(b);
        if(b==n and kolko[b]<=2){
            otg=true;
            goto kr;
        }
           }
    }
}
kr:;
if(otg==false){
    cout<<"IMPOSSIBLE";
}else{
cout<<"POSSIBLE";
}
cout<<"\n";
return 0;
}


Measured memory_bytes: 55544
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


Measured memory_bytes: 11880
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    cnt = {0 : 0}
    for i in range(n):
        a = int(input())
        cnt[a] = cnt.get(a, 0) + 1

    keys = list(cnt.keys())
    keys.sort()

    ok = 0
    for i in range(len(keys)-1):
        k1, k2 = keys[i], keys[i+1]
        if (k2-k1) % 2:
            ok ^= n
        n -= cnt[k2]

    if ok:
        print("first")
    else:
        print("second")


if __name__ == '__main__':
    main()


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

int main(){
    int N; cin >> N; N++;
    
    int t_prev=0;
    int x_prev=0;
    int y_prev=0;
    for(int i=1; i<N; ++i){
        int t_now; cin >> t_now;
        int x_now; cin >> x_now;
        int y_now; cin >> y_now;
        
        int t = t_now - t_prev;
        int d = abs(x_now - x_prev) + abs(y_now - y_prev);
//        if(t%d!=0){
        if((t+d)&1 || t<d){
            cout << "No";
            return 0;
        }
        t_prev = t_now;
        x_prev = x_now;
        y_prev = y_now;
    }
    cout << "Yes";
    
    return 0;
}

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

#define ll long long
#define ld long double
#define xx first
#define yy second
#define vi vector<int>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

#define MAX 400005

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

    ll n;
    cin >> n;

    vector<ll> a(n);
    ll s = 0;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];

        s^=a[i];
    }

    for(int i=0;i<n;i++)
    {
        cout << (s^a[i]) << " ";
    }

    cout << endl;



    return 0;
}

Measured memory_bytes: 4700
package main

import (
	"fmt"
	"math"
)
func main(){
	var N,maxN,n int
	fmt.Scan(&N)
	n = 10
	for ;;{
		a := int(math.Pow(float64(n),5))
		b := int(math.Pow(float64(n-1),5))
		if(a-b>int(math.Pow(float64(10),9))){
			maxN = n+1
			break
		}
		n++
	}
	for  i := -maxN; i < maxN; i++ {
		for j := -maxN; j < maxN; j++ {
		   a := int(math.Pow(float64(i), 5))
		   b := int(math.Pow(float64(j), 5))
		  if a - b == N {
			A := i
			B := j
			fmt.Println(A, B)
			return
		  }
		}
	  }


}

Measured memory_bytes: 1820
var
	h,w,i,j,r,c,tx,ty:Longint;
	s:array of string;
	dx:array[1..8]of Longint=(1,0,-1,0,1,1,-1,-1);
	dy:array[1..8]of Longint=(0,1,0,-1,1,-1,1,-1);
begin
	readln(h,w);
	setlength(s,h+2);
	for i:=0 to h+1 do setlength(s[i],w+2);
	for i:=1 to h do readln(s[i]);
	for i:=1 to h do begin
		for j:=1 to w do begin
			if s[i][j]='#' then write('#')
			else begin
				c:=0;
				for r:=1 to 8 do begin
					tx:=i+dx[r];
					ty:=j+dy[r];
					if s[tx][ty]='#' then inc(c);
				end;
				write(c);
			end;
		end;
		writeln('');
	end;
end.

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s; cin >> s;
	if (s == "KIHBR")cout << "YES\n";
	else if (s == "KIHBRA")cout << "YES\n";
	else if (s == "KIHBAR")cout << "YES\n";
	else if (s == "KIHBARA")cout << "YES\n";
	else if (s == "KIHABR")cout << "YES\n";
	else if (s == "KIHABRA")cout << "YES\n";
	else if (s == "KIHABAR")cout << "YES\n";
	else if (s == "KIHABARA")cout << "YES\n";
	else if (s == "AKIHBR")cout << "YES\n";
	else if (s == "AKIHBRA")cout << "YES\n";
	else if (s == "AKIHBAR")cout << "YES\n";
	else if (s == "AKIHBARA")cout << "YES\n";
	else if (s == "AKIHABR")cout << "YES\n";
	else if (s == "AKIHABRA")cout << "YES\n";
	else if (s == "AKIHABAR")cout << "YES\n";
	else if (s == "AKIHABARA")cout << "YES\n";
	else cout << "NO\n";
	return 0;
}

Measured memory_bytes: 760
#include<stdio.h>
#include<stdlib.h>

void maxHeapify(int);
void buildMaxHeap(void);

int a[5000000],n;


int main(){

  int i;


  scanf("%d",&n);

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

  buildMaxHeap();
 

  for(i = 1; i <= n; i++){
    printf(" %d",a[i]);
  }


  printf("\n");


  return 0;
}


void buildMaxHeap(void){

  int j;

  for(j = n/2; j >= 1; j--){
  
    maxHeapify(j);
  }
}
  
void maxHeapify(int i){

  int left,right,max,tmp;


  left = i*2;
  right = i*2+1;

  if(left <= n && a[left] > a[i]) max = left;


  else max = i;

  if(right <= n && a[right] > a[max])max = right;

  if(max != i){
    tmp = a[i];
    a[i] = a[max];
    a[max] = tmp;
    maxHeapify(max);
  }
}



Measured memory_bytes: 3668
X = int(input())
if 400 <= X <=599:
  print(8)
if 600 <= X <=799:
  print(7)
if 800 <= X <=999:
  print(6)
if 1000 <= X <=1199:
  print(5)
if 1200 <= X <=1399:
  print(4)
if 1400 <= X <=1599:
  print(3)
if 1600 <= X <=1799:
  print(2)
if 1800 <= X <=1999:
  print(1)

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

int main(){
	using namespace std;

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int cas = 1;
	//cin >> cas;
	while(cas--){
		string s;
		cin >> s;
		int n = s.size();

		if(s[n-1]=='s'){
			cout << s << "es" << "\n";
		}
		else cout << s << "s" << "\n";
	}
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    int count[100000+1] = {};
    for(int i = 0; i < n; i++){
        cin >> a[i];
        count[a[i]]++;
        if(a[i] > 0){
            count[a[i]-1]++;
        }
        count[a[i]+1]++;
    }
    int p = 0;
    for(int i = 0; i < 100000+1; i++){
        p = max(p,count[i]);
    }
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <bitset>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#include <cassert>
using namespace std;

long long GetGcd(long long a, long long b)
{
    while (a > 0 && b > 0) {
        if (a >= b) {
            a %= b;
        } else {
            b %= a;
        }
    }
    return a + b;
}

long long Ceil(long long num, long long den)
{
    return (num + den - 1) / den;
}

long long Floor(long long num, long long den)
{
    return num / den;
}

struct TSolver
{
    long long A;
    long long B;
    long long C;
    long long D;

    void Setup()
    {
        cin >> A >> B >> C >> D;
    }

    void Solve()
    {
        if (A < B) {
            Show(false);
            return;
        }

        if (D < B) {
            Show(false);
            return;
        }

        if (B > C + 1) {
            auto x = A % B;
            auto d = D % B;

            bool existsK = false;

            if (C >= x) {
                existsK |= ExistsK(d, B, C - x + 1, B - x - 1);
            } else {
                existsK |= ExistsK(d, B, 0, B - x - 1);
                existsK |= ExistsK(d, B, (C - x + B) % B, B - 1);
            }

            if (existsK) {
                Show(false);
            } else {
                Show(true);
            }
        } else {
            Show(true);
        }
    }

    static bool ExistsK(long long d, long long b, long long l, long long r)
    {
        // Returns |true| if and only if exists k >= 0: k * d \in [l, r] (mod b).
        assert(0 <= l && l <= r);
        assert(r < b);
        assert(0 <= d && d < b);
        auto g = GetGcd(d, b);
        d /= g;
        b /= g;
        l = Ceil(l, g);
        r = Floor(r, g);
        return l <= r;
    }

    void Show(bool indefinite)
    {
        if (indefinite) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }
    }

    void TearDown()
    {
        cout.flush();
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

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

    TSolver solver;
    int testCount;
    cin >> testCount;
    for (int i = 0; i < testCount; ++i) {
        solver.Setup();
        solver.Solve();
        solver.TearDown();
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
   
  return x;
}
 
Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
   
  return x;
}
 
Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key)
    return x;
  if(k < x->key)
    return treeSearch(x->left,k);
  else
    return treeSearch(x->right,k);
 
}
 
Node treeSuccessor(Node x){
  Node y;
   
  if(x->right != NIL)
    return treeMinimum(x->right);
 
  y = x->parent;
   
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
 
  return y;
}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 
  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);
 
  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;
 
  if(x != NIL)
    x->parent = y->parent;
 
  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;
 
  if(y != z)
    z->key = y->key;
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while(x!=NIL){
    y = x;
    if(z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }
   
  z->parent = y;
   
  if(y==NIL)
    root=z;
  else
    if(z->key < y->key)
      y->left=z;
    else
      y->right=z; 
}
 
void inorder(Node x){
  if(x != NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}
   
void preorder(Node x){
  if(x != NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}



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

using namespace std;
typedef long long ll;

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

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

    int ans = 0;
    rep2(i, 1, n - 1)
    {
        string x, y;
        x = s.substr(0, i);
        y = s.substr(i);
        int cnt = 0;
        rep(j, x.size())
        {
            bool flag = true;
            rep(k, j)
            {
                if (x[j] == x[k])
                {
                    flag = false;
                }
            }
            if (y.find(x[j]) != -1 && flag)
            {
                cnt++;
            }
        }
        ans = max(cnt, ans);
    }

    cout << ans << '\n';
    return (0);
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if(A > 9 || B > 9){
        cout << -1 << endl;
    }
    else{
        cout << A * B <<endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict

(n, m), d, a, b = map(int, input().split()), defaultdict(int), 0, 0
for i in range(m):
	p, s = input()[:-1].split(); p = int(p)
	if d[p] == sys.maxsize: continue
	if s == 'WA': d[p] += 1
	if s == 'AC': b += abs(d[p]); a += 1; d[p] = sys.maxsize
print(a, b)

Measured memory_bytes: 80908
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 105
#define M 205
#define ll long long
#define mod 1000000007
void Read(int &p)
{
	p = 0;
	int c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int n, m, k, ans, tp, tim;
int inv[M << 1], fac[M << 1], rev[N << 1], pw[M << 1];
int dfn[N], low[N], s[M], hh[M], ss[M << 1];
int tar[M << 1], nex[M << 1], fir[N], tot = 1;
int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
void Add(int x, int y)
{
	++tot;
	tar[tot] = y;
	nex[tot] = fir[x];
	fir[x] = tot;
}
void Sum(int &x, int y)
{
	x += y;
	if (x >= mod)
		x -= mod;
}
int Pow(int a, int k)
{
	if (!k)
		return 1;
	int p = Pow(a, k / 2);
	if (k & 1)
		return (ll)p * p % mod * a % mod;
	return (ll)p * p % mod;
}
int C(int n, int m)
{
	if (n < m)
		return 0;
	return (ll)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void Dfs(int x, int fa = 0)
{
    dfn[x] = low[x] = ++tim;
    for (int i = fir[x]; i; i = nex[i])
	{
		int y = tar[i];
		if (y != fa)
		{
		    if (!dfn[y])
		    {
		        s[++tp] = i >> 1;
			    Dfs(y, x);
			    low[x] = min(low[x], low[y]);
		        if (low[y] >= dfn[x])
		        {
		            hh[0] = 0;
		            while (1)
		            {
		                int z = s[tp--];
		                hh[++hh[0]] = z;
		                if (z == i >> 1)
		                	break;
		            }
		            if (hh[0] == 1)
		            {
		            	ans = (ll)ans * k % mod;
		            	continue;
		            }
					ss[0] = 0;
		            for (int i = 1; i <= hh[0]; i++)
		            {
		            	ss[++ss[0]] = tar[hh[i] << 1];
		            	ss[++ss[0]] = tar[hh[i] << 1 | 1];
					}
		            sort(ss + 1, ss + ss[0] + 1);
		            ss[0] = unique(ss + 1, ss + ss[0] + 1) - ss - 1;
		            if (ss[0] != hh[0])
		            {
		            	ans = (ll)ans * C(hh[0] + k - 1, k - 1) % mod;
		            	continue;
		            }
		            int cnt = 0;
				    for (int i = 0; i < hh[0]; ++i) 
				        Sum(cnt, pw[gcd(i, hh[0])]);
					ans = (ll)ans * cnt % mod * rev[hh[0]] % mod;
				}
		    }
		    else
		    {
		    	low[x] = min(low[x], dfn[y]);
		    	if (dfn[y] < dfn[x])
		    		s[++tp] = i >> 1;
			}
		}
	}
}
int main()
{
	fac[0] = 1;
	for (int i = 1; i <= 200; i++)
		fac[i] = (ll)fac[i - 1] * i % mod;
	inv[200] = Pow(fac[200], mod - 2);
	for (int i = 200; i >= 1; i--)
		inv[i - 1] = (ll)inv[i] * i % mod;
	rev[1] = 1;
	for (int i = 2; i <= 200; i++)
		rev[i] = (ll)(mod - mod / i) * rev[mod % i] % mod;
	Read(n), Read(m), Read(k);
    for (int i = 1; i <= m; i++) 
	{
		int x, y;
		Read(x), Read(y);
		Add(x, y), Add(y, x);
	}
	pw[0] = 1;
	for (int i = 1; i <= 200; i++)
    	pw[i] = (ll)pw[i - 1] * k % mod;
    ans = 1;
    for (int i = 1; i <= n; i++)
		if (!dfn[i])
			Dfs(i);
    printf("%d\n", ans);
}
//

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int L[100010];

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

	cin >> N;
	int A;
	fill(L, L + N, INF);
	rep(i, 0, N)
	{
		cin >> A;
		(*upper_bound(L, L + N, -A)) = -A;
	}

	int ans = 0;
	rep(i, 0, N)
	{
		if (L[i] != INF)
		{
			ans = i;
		}
	}

	cout << ans + 1 << endl;

	return 0;
}

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

int minimumCostSort(int *W, int n) {
  int X[1000], R[10001];
  for (int i = 0; i < n; i++) {
    X[i] = W[i];
  }
  sort(X, X + n);
  for (int i = 0; i < n; i++) R[X[i]] = i;
  int m = X[0];
  int sum = 0;

  for (int i = 0; i < n; i++) {
    int cur = i;
    if (X[cur] == -1) continue;
    int s = 0;
    int mm = 10000;
    int nn = 0;
    int v;
    while (true) {
      nn++;
      X[cur] = -1;
      v = W[cur];
      mm = min(v, mm);
      s += v;
      cur = R[v];
      if (X[cur] == -1) break;
    }
    sum += min(s + (nn - 2) * mm, s + mm + (nn + 1) * m);
  }

  return sum;
}

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

  int n;
  int W[1000];

  cin >> n;

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

  int c = minimumCostSort(W, n);

  cout << c << endl;

  return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int w, h;
	while (cin >> w >> h && w&&h) {
		int move[4][2] = { {1,0},{0,1},{-1,0},{0,-1} },cnt=0;
		char room[20][20];
		bool flag[20][20] = {};
		queue<pair<int, int>>que;
		pair<int, int>cur;
		for (int i = 0; i < h; ++i)
			for (int j = 0; j < w; ++j) {
				cin >> room[i][j];
				if (room[i][j] == '@') que.push(make_pair(j, i));
			}
		while (!que.empty()) {
			cur = que.front();
			que.pop();
			flag[cur.second][cur.first] = true;
			for (int i = 0; i < 4; ++i) {
				if (cur.first + move[i][0] >= 0 && cur.first + move[i][0] < w&&cur.second + move[i][1] >= 0 && cur.second + move[i][1] < h)
					if (!flag[cur.second + move[i][1]][cur.first + move[i][0]]&& room[cur.second + move[i][1]][cur.first + move[i][0]]=='.') {
						que.push(make_pair(cur.first + move[i][0], cur.second + move[i][1]));
						++cnt;
						flag[cur.second + move[i][1]][cur.first + move[i][0]] = true;
					}
			}
		}
		cout << cnt + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3012
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define rall(a)		(a).rbegin(), (a).rend()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;


int main()
{
	int n;
	while (cin >> n && n){
		const int M = 102;
		
		int m[M];
		int p[M][M];
		clr(p);

		For(i,1, n+1){
			cin >> m[i];
			rep(j, m[i]){
				int t;
				cin >> t;
				p[i][t] = 1;
			}
		}
		bool f[M]; clr(f);

		int am;
		cin >> am;
		rep(i, am){
			int t;
			cin >> t;
			For(i,1, n+1){
				if (!p[i][t])f[i] = 1;
			}
		}

		int ans = -1; int sum = 0;
		For(i,1, n+1){
			if (!f[i]){
				ans = i; sum++;
			}
		}
		if (sum == 1)cout << ans << endl;
		else cout << -1 << endl;
		
	}

	return 0;
}

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

#define st first
#define nd second
#define pb push_back

typedef long long   ll;
typedef double      db;
typedef long double ldb;

typedef pair <int, int> pii;
typedef pair <ll,  ll>  pll;
typedef pair <ll,  db>  pdb;
typedef pair <ldb, ldb> pldb;

template <typename T>
void   Debug (T begin, T end);
int    si    ();
ll     sl    ();
string ss    (int);
db     sf    ();
ldb    slf   ();
void   pi    (int, char = '\n');
void   pl    (ll, char = '\n');
void   pf    (db, char = '\n');
void   plf   (ldb, char = '\n');
void   ps    (string, char = '\n');

ll russian(ll, ll, ll);
ll fastpow(ll, ll, ll);
ll slowpow(ll, ll, ll);
ll _gcd(ll, ll);
ll _lcm(ll, ll);
ll extgcd(ll, ll, ll&, ll&);
ll _inv(ll, ll);

const int INF  = 1e9;
const ll  LINF = 1e18;

int main()
{
    int a = si(), b = si();
    pi(max(0, a - 2 * b));

    return 0;
}

template <typename T>
void Debug(T begin, T end)
{
    printf("\nDEBUG:\n");
    while (begin != end)
        printf("%d ", *begin),
        begin++;
    printf("\n\n");
}

template <typename T>
T scanf_t(string s)
{
    T a;
    scanf(s.c_str(), &a);
    return a;
}

template <typename T>
void printf_t(T a, string s, char end_l)
{
    s.push_back(end_l);
    printf(s.c_str(), a);
}

int si() { return scanf_t<int>("%d"); }
ll sl() { return scanf_t<ll>("%lld"); }
db sf() { return scanf_t<db>("%f"); }
ldb slf() { return scanf_t<ldb>("%Lf"); }

void pi(int a, char end_l) { printf_t<int>(a, "%d", end_l); }
void pl(ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); }
void pf(db a, char end_l) { printf_t<db>(a, "%lf", end_l); }
void plf(ldb a, char end_l) { printf_t<ldb>(a, "%Lf", end_l); }

void ps(string a, char end_l)
{
    string s = "%s";
    s.push_back(end_l);
    printf(s.c_str(), a.c_str());
}

string ss(int NN)
{
    char T[NN];
    scanf("%s", T);
    return (string)T;
}

ll fastpow(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = (r * a) % m;
        a = (a * a) % m;
        k >>= 1LL;
    }
    return r;
}

ll slowpow(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = russian(r, a, m);
        a = russian(a, a, m);
        k >>= 1LL;
    }
    return r;
}

ll russian(ll a, ll k, ll m)
{
    ll r = 0LL;
    while (k)
    {
        if (k & 1LL)
            r = (r + a) % m;
        a = (a + a) % m;
        k >>= 1LL;
    }
    return r;
}

ll _gcd(ll a, ll b)
{
    while (b)
        swap(a %= b, b);
    return a;
}

ll _lcm(ll a, ll b)
{
    return a / _gcd(a, b) * b;
}

ll extgcd(ll a, ll b, ll& k, ll& l)
{
    if (b == 0)
    {
        k = 1; l = 0;
        return a;
    }
    ll res = extgcd(b, a % b, l, k);
    l -= a / b * k;
    return res;
}

ll _inv(ll a, ll p)
{
    return fastpow(a, p - 2, p);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	if (A >= B)cout << "delicious" << endl;
	else if (B - A <= X)cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

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

std::string StringRotation(std::string s);

int main() {
  std::string S, T;
  std::cin >> S >> T;

  bool flag{false};
  // A string S returns to its original state after N rotations, N = S.length()
  for (int i = 0; i < S.length(); i++) {
    S = StringRotation(S);
    if (S == T) {
      flag = true;
      break;
    }
  }

  if (flag)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;

  return 0;
}

std::string StringRotation(std::string s) {
  // "abc" -> 'c' + "ab" -> "cab"
  return s.back() + s.substr(0, s.length() - 1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<pair<int,int>>p(N);
  for(int i=0;i<N;i++){
    int x,y;
    cin>>x>>y;
    p[i]=make_pair(x,y);
  }
  map<pair<int,int>,int>k;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j){continue;}
      auto q=make_pair(p[i].first-p[j].first,p[i].second-p[j].second);
       k[q]++;
    }
  }
  int MAX=0;
  for(auto c:k){
    if(c.second>MAX){MAX=c.second;}
  }
  cout<<N-MAX<<endl;
  return 0;
}

Measured memory_bytes: 3688
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

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

  int cum = 0, m = 0;

  for(auto k: s) {
    if(!(k == 'A' || k == 'C' || k == 'G' || k == 'T')) {
      m = max(m,cum); cum=0;
    }
    else
    cum++;

  }
  
  m = max(m, cum);
  cout << m << '\n';
  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
mod = (10**9) +7

def counts(n,k):
    if k==1:
        return N+1
    else:
        return k*N - k*( k - 1 ) + 1

total =0
for k in range(K,N+2):
    total += int(counts(N,k))

print(total%mod)

Measured memory_bytes: 9192
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9) + 7


n=int(data())
a=mdata()
s=[0]*n
s[-1]=a[-1]
for i in range(n-2,-1,-1):
    s[i]=s[i+1]+a[i]
ans=0
for i in range(n-1):
    ans=(ans+a[i]*s[i+1])%mod
out(ans)

Measured memory_bytes: 99448
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/* define */
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define REP(i, n) for ( int i = 0; i < (n) ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}

/* main */

int main() {
	int n, a, s = 0;
	scanf("%d", &n);
	REP(i, n) {
		scanf("%d", &a);
		s += a - 1;
	}
	printf("%d", s);
	return 0;
}


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

#define LL long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int maxn = (int) 1e5+10;
    int n,x,q; cin >> n;
    int ind[maxn];
    memset(ind, 0, sizeof(ind));
    LL sum = 0l;
    for(int i=0;i<n;i++){
        cin >> x;
        sum+=x;
        ind[x]++;
    }
    cin >> q;
    int b,c;
    while(q--){
        cin >> b >> c;
        sum -= (ind[b]*1LL*b);
        sum += (ind[b]*1LL*c);
        cout << sum << '\n';
        ind[c] += ind[b];
        ind[b] = 0;
    }
    return 0;
}

Measured memory_bytes: 4020
import sys

N = int(input())
S = input().strip()
ss = []
for c in S:
    ss.append(int(c))
if N == 2:
    print(abs(ss[0]-ss[1]))
    sys.exit()

X = []
X2 = []
fff = 0
for i in range(N-1):
    c = abs(ss[i] - ss[i+1])
    X.append(c%2)
    X2.append((c//2)%2)
    if c == 1:
        fff = 1


N=N-2

i = 0
Y = []
while N:
    if N%2:
        Y.append(i)
    i += 1
    N=N//2

C = [0]
for y in Y[::-1]:
    y = 2**y
#    print(y)
    tmp = []
    for c in C:
        tmp.append(c+y)
    for t in tmp:
        C.append(t)
r = 0
r2 = 0
for c in C:
    r = r^X[c]
    r2 = r2^X2[c]
if fff:
    print(r)
else:
    print(r2*2)


Measured memory_bytes: 139640