akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    long long int K,N;
    cin>>K>>N;
    int P[N];
    for(int i=0;i<N;i++){
        cin>>P[i];
    }
    int L[2*N];
    long long int a,b;
    for(int i=0;i<N;i++){
        if(i==0){
            a=K-P[N-1]+P[0];
            b=abs(P[1]-P[0]);
            L[0]=K-a;
            L[1]=K-b;
        }
        else if(i==N-1){
            a=K-P[N-1]+P[0];
            b=abs(P[N-1]-P[N-2]);
            L[2*i]=K-a;
            L[2*i+1]=K-b;
        }
        else{
            a=abs(P[i+1]-P[i]);
            b=abs(P[i]-P[i-1]);
            L[2*i]=K-a;
            L[2*i+1]=K-b;
        }
    }
    long long int min=1000000;
    for(int i=0;i<2*N;i++){
        if(L[i]<=min){
            min=L[i];
        }
    }
    cout<<min<<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0,h,w;
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }return res;
}
int main() {
    int h, w; cin >> h >> w; ll ans = 0;
    vector<vector<int>> A(h, vector<int>(w));
    int dp[10][10];
    rep(i, 10) rep(j, 10) cin >> dp[i][j];
    rep(i, 10) rep(j, 10) rep(k, 10) dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
    rep(i, h) {
        rep(j, w) {
            cin >> A[i][j];
            if (A[i][j] == -1 || A[i][j] == 1) continue;
            ans += dp[A[i][j]][1];
        }
    }cout << ans << endl;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if((m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12) && d1==31)cout<<1<<endl;
    else if(m1==2 && d1==28)cout<<1<<endl;
    else if((m1==4||m1==6||m1==9||m1==11) && d1==30)cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int N,A;
    cin >> N >> A;
    if (N % 500 <= A) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
	int n, s[200] = {}, num[200] = {}, result = 0, lamp = 1, in, ax, h, w, m;
	string str[106];
	cin >> n>>m;
	for (int i = 0; i < 2*m; i++) {
		cin >> s[i];
		num[s[i]]++;
	}
	
	for (int i = 1; i <= n; i++) {
		cout  << num[i]  << endl;
	}
	
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    // x < y < z
    for(int i=0;i<n;i++){
        auto x = upper_bound(a.begin(),a.end(),b[i]-1);
        if(x == a.begin()) continue;
        x--;
        ll lo = x - a.begin();
        auto z = upper_bound(c.begin(),c.end(),b[i]);
        if(z == c.end()) continue;
        ll hi = z - c.begin();
        ll aux = n  - hi;
        ans += (lo+1) * aux;
    }
    cout<<ans<<"\n";
    return 0;
}




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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int64 N;
vector<int64> a;
vector<int64> G[212345];
vector<int64> res;
stack<PLL> undo;
vector<int64> lis;

void dfs(int64 v, int64 p) {
  int64 idx = lower_bound(all(lis), a[v]) - lis.begin();
  undo.emplace(idx, lis[idx]);
  lis[idx] = a[v];
  res[v] = lower_bound(all(lis), INF_LL) - lis.begin();

  for (auto& u: G[v]) {
    if (u == p) continue;
    dfs(u, v);
  }

  lis[undo.top().fs] = undo.top().sc;
  undo.pop();
}

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

  int64 N, M;
  cin >> N >> M;
  int64 i = 0, geta = 0;
  map<int, int> mp;
  REP(_, M) {
    int64 aida = N-i-(i+1)-1;
    if (aida*2 + 2 == N || mp.count(aida)) {
      geta = 1;
    }
    cout << i+1+geta << " " << N-i << endl;
    mp[aida] = mp[N-aida-2] = 1;
    i++;
  }
}



Measured memory_bytes: 16960
#include<iostream>
#include<string.h>
using namespace std;

main(){
  int m,d;
  int dc,mc;
  string week[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
  int month_days[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
  while(cin >> m >> d){
    
    if(m==0 && d == 0)break;
    
    mc=1;
    dc=3;
    while(1){
      
      for(int i=1;i<=month_days[mc];i++,dc++){
	if(m==mc&& d==i)break;
      }
      if(m==mc)break;
      mc++;
    }
    
    cout << week[dc%7]<<endl;
    
    

  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> n;
	vector<ll> a(n);
	ll p = 0;
	ll k = 1;
	rep(i, n) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			p++;
		}
	}
	ll res = 1;
	rep(i, n) {
		res *= 3;
	}
	rep(i, p) {
		k *= 2;
	}
	res -= k;
	cout << res << endl;
}

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

namespace P_AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var monCount = int.Parse(Console.ReadLine());
            var colorArray = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var noUseArray = Enumerable.Range(1, 10000).Except(colorArray).ToList();

            var changeCount = 0;
            for(int index = 0; index < monCount - 1; index++)
            {
                if(colorArray[index] == colorArray[index + 1])
                {
                    colorArray[index + 1] = noUseArray[0];
                    noUseArray.RemoveAt(0);
                    changeCount++;
                }
            }

            Console.WriteLine(changeCount);
        }
    }
}

Measured memory_bytes: 13920
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) int {
	A := sc.f()
	B := sc.f()
	H := sc.f()
	M := sc.f()

	rad := math.Pi / 30 * (5*(H+M/60) - M)

	d := A*A + B*B - 2*A*B*math.Cos(rad)

	fmt.Printf("%.10f\n", math.Sqrt(d))

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 1728
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int h,w,k;
    cin >> h >> w >> k;
    int ans[h][w] = {};
    int berry = 0;
    for(int i = 0;i < h;i++)
    {
        for(int j = 0;j < w;j++)
        {
            char ch;
            cin >> ch;
            if(ch == '#')
            {
                berry++;
                ans[i][j] = berry;
            }
        }
    }
    for(int i = 0;i < h;i++)
    {
        int num = -1;
        for(int j = 0;j < w;j++)
        {
            if(ans[i][j] > 0)
            {
                num = ans[i][j];
            }
            if(num == -1)
            {
                continue;
            }
            if(ans[i][j] == 0)
            {
                ans[i][j] = num;
            }
        }
    }
    for(int i = 0;i < h;i++)
    {
        int num = -1;
        for(int j = w - 1;j >= 0;j--)
        {
            if(ans[i][j] > 0)
            {
                num = ans[i][j];
            }
            if(num == -1)
            {
                continue;
            }
            if(ans[i][j] == 0)
            {
                ans[i][j] = num;
            }
        }
    }
    for(int i = 0;i < w;i++)
    {
        int num = -1;
        for(int j = 0;j < h;j++)
        {
            if(ans[j][i] > 0)
            {
                num = ans[j][i];
            }
            if(num == -1)
            {
                continue;
            }
            if(ans[j][i] == 0)
            {
                ans[j][i] = num;
            }
        }
    }
    for(int i = 0;i < w;i++)
    {
        int num = -1;
        for(int j = h - 1;j >= 0;j--)
        {
            if(ans[j][i] > 0)
            {
                num = ans[j][i];
            }
            if(num == -1)
            {
                continue;
            }
            if(ans[j][i] == 0)
            {
                ans[j][i] = num;
            }
        }
    }
    for(int i = 0;i < h;i++)
    {
        for(int j = 0;j < w;j++)
        {
            cout << ans[i][j] << " ";
        }
        cout << "\n";
    }
    
    return 0;
}

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

using namespace std;
string s;
int j=0,o=0,i=0;
int pos=0;
int maxlevel=0;
int flag_j=0,flag_o=0,flag_i=0;
int main(void){
	cin >> s;
	while(pos<s.size()){
		while(s[pos]=='J' && pos<s.size()){
			pos++;
			j++;
			flag_j++;
		}
		while(s[pos]=='O' && pos<s.size()){
			pos++;
			o++;
			flag_o++;
		}
		while(s[pos]=='I' && pos<s.size()){
			pos++;
			i++;
			flag_i++;
		}
		if(flag_j!=0 && flag_o!=0 && flag_i!=0 &&j>=o && i>=o && maxlevel<o){
			maxlevel=o;
		}
		j=0;
		o=0;
		i=0;
		flag_j=0;
		flag_o=0;
		flag_i=0;
	}
	cout << maxlevel << endl;
	return 0;
} 

Measured memory_bytes: 3952
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        if (a + b <= k) {
            System.out.println(0 + " " + 0);
            return;
        }
        long sub = a - k;
        if (sub <= 0) {
            long sub2 = b + sub < 0 ? 0 : b + sub;
            System.out.println(0 + " " + sub2);
        } else {
            System.out.println(sub + " " + b);
        }
    }
}

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

int gcd(int a, int b){
    if(a<b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    while(r!=0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main() {
    int K;
    cin >> K;
    int x, y;
    int s =0;
    for(int a=1; a<=K; a++){
        for(int b=1; b<=K; b++){
            for(int c=1; c<=K; c++){
                x = gcd(a,b);
                y = gcd(b,c);
                s += gcd(x,y);
            }
        }
    }
    cout << s << endl;
    return 0;
}



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

#define int long long

#define Vanya Unstoppable

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int n;
    cin >> n;
    
    multiset<int> s;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        s.insert(a);
    }
    
    vector<int> a;
    for (int to : s) {
        a.push_back(to);
    }
    
    n = (int)a.size();
    
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if (a[i] != a[j] && a[j] != a[k]) {
                     if (a[i] + a[j] > a[k]) ++ans;
                }
            }
        }
    }
    
    cout << ans;
}


Measured memory_bytes: 3648
# problem D
mod=10**9+7

N=int(input())
A=list(map(int,input().split()))

b=[[0 for i in range(N)] for k in range(60)] # i番目の数の2^kの位(0<=k<60)
d0=[0 for k in range(60)]
d1=[0 for k in range(60)]

for i in range(N):
    for k in range(60):
        if A[i]>>k&1:
            d1[k]+=1
        else:
            d0[k]+=1

ans2=0
for k in range(60):
    ans2+=2**k*d0[k]*d1[k]

print(ans2%mod)

Measured memory_bytes: 299852
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	int hishi = 0;
	int tyouhou = 0;
	while(sc.hasNext()){
	    String[] line = sc.nextLine().split(",");
	    int hen1 = Integer.parseInt(line[0]);
	    int hen2 = Integer.parseInt(line[1]);
	    int hen3 = Integer.parseInt(line[2]);
	    if(hen1==hen2 && hen3>0){hishi++;}
	    else if(hen1*hen1+hen2*hen2==hen3*hen3){tyouhou++;}
	}

	System.out.println(tyouhou);
	System.out.println(hishi);
    }
}

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

using namespace std;

int main() {
	// your code goes here
	int n;
	string E;
	cin >>n;
		int runner=0;
		int pts=0;
		int out=0;
	while(n){

		cin >>E;
		if(E=="HOMERUN"){
			pts+=runner+1;
			runner=0;
		}else if(E=="HIT"){
			if(runner==3){pts++;}else{
				runner++;
			}
		}else if(E=="OUT"){
			out++;
			if(out==3){
				cout << pts <<endl;
				pts=0;
				runner=0;
				out=0;
				n--;
			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 3132
height, width = map(int, input().split(" "))
target = []
queue = []
WHITE = "."
BLACK = "#"
for h in range(height):
    temp = [n for n in input()]
    for w in range(width):
        if temp[w] == BLACK:
            queue.append([w, h])
    target.append(temp)
all_move = [[0, 1], [0, -1], [1, 0], [-1, 0]]

answer = 0
while queue:
    next_queue = []
    for q in queue:
        here_x, here_y = q
        for x, y in all_move:
            next_x, next_y = here_x + x, here_y + y
            if 0 <= next_x < width and 0 <= next_y < height:
                if target[next_y][next_x] == WHITE:
                    next_queue.append([next_x, next_y])
                    target[next_y][next_x] = BLACK
    if not next_queue:
        print(answer)
        break
    queue = next_queue
    answer += 1
                    

Measured memory_bytes: 171380
#include <cassert>
#include "limits.h"
#include <limits>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long,long long>;

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

  std::vector<bool> prime(100500,true);

  prime[0]=false;
  prime[1]=false;

  rep(i,2,100500){
    if(prime[i]){
      for(ll j=2*i;j<100500;j+=i){
        prime[j]=false;
      }
    }
  }

  ll x;
  std::cin>>x;

  rep(i,x,100500){
    if(prime[i]){
      std::cout<<i<<"\n";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
vector<int> v[300001];
int val[300001];
int ans[300001];
void dfs(int u,int par,int value)
{
    for(int i=0;i<v[u].size();++i)
    {
        if(v[u][i]==par)
            continue;
        else
        {
            ans[v[u][i]]=val[v[u][i]]+value;
            dfs(v[u][i],u,ans[v[u][i]]);
        }
    }
}
int32_t main()
{
    IOS
     
    
    
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n-1;++i)
    {
        int p,q;
        cin>>p>>q;
        v[p].push_back(q);
        v[q].push_back(p);
    }
    memset(val,0,sizeof(val));
    while(q--)
    {
        int a,b;
        cin>>a>>b;
        val[a]+=b;
    }
    memset(ans,0,sizeof(ans));
    ans[1]=val[1];
    dfs(1,0,ans[1]);
    for(int i=1;i<=n;++i)
        cout<<ans[i]<<" ";

    


}



Measured memory_bytes: 28672
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		String T = sc.next();
		String ans ="";
		for(int i=0; i<N; i++) {
			ans += S.substring(i,i+1);
			ans += T.substring(i,i+1);
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
int n,v[100+1][100+1]={},color[100+1]={},tim,d[1000],f[1000];
void visit(int u){
  color[u]=1;
  d[u]=++tim;
  rep(i,n){
    if(v[u][i]==0)continue;
    if(color[i]==0)
      visit(i);
  }
  color[u]=2;
  f[u]=++tim;
}
void dfs(){
  rep(i,n)color[i]=0;
  tim = 0;
  rep(i,n){
    if(color[i]==0)
      visit(i);
  }
}

int main(){
  cin>>n;
  int u,k,in;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>in;
      v[u-1][in-1]=1;
    }
  }
  dfs();
  rep(i,n)cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,k;cin>>n>>k;
	ll one=-1;
	ll a[n];For(i,0,n){
		cin>>a[i];
		if(a[i]==1) one=i;
	}
	ll ans=0;
	ll t1 = (n-(one+1))/(k-1);	
	ll t2 = (one)/(k-1);
	ll x = (n-(one+1))%(k-1)+(one)%(k-1);
	ans = t1+t2;
	if(x%(k-1)==0) ans+=(x/(k-1));
	else ans+=((x/(k-1))+1);
	cout<<ans<<endl;









	
}

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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && a == c) cout << "Yes";
    else cout << "No";
    
    
    return 0;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;


int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  bool flag = false;
  for (int i = 1; i <= 3; ++i) {
    int tmp = a * b * i;
    if (tmp % 2 == 1)
      flag = true;
  }
  cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    ll s = 1;
    rep(i,n)cin >> a[i];
    rep(i,n)if(a[i]==0){
        cout << 0 << endl;
        return 0;
    }
    rep(i,n){
        if(a[i] <= 1000000000000000000/s){

            s *= a[i];
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << s<< endl;
}


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

int main() {
  int N, M, X;
  int cost1, cost2 = 0;
  cin >> N >> M >> X;
  vector<int> A(M);
  for(int i = 0; i < M; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < M; i++) {
    if(A.at(i) > X) {
      cost1++;
    }
    else if(A.at(i) < X) {
      cost2++;
    }
  }
  cout << min(cost1,cost2) << endl;
}


Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)

for _ in range(M):
    tmp = heapq.heappop(A)
    heapq.heappush(A, -(-tmp // 2))

print(-sum(A))


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

VVI edge(114514, VI(0));

int main() {
	int n, m; cin >> n >> m;
	VI h(n); REP(i,n) cin >> h[i];
	int a, b;
	REP(i,m){
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int ans=0;
	REP(i,n){
		bool f=1;
		for(auto p:edge[i]){
			if(h[i]<=h[p])
				f=0;
		}
		if(f)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10120
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int n,d;
    cin >> n >> d;
    int sum;
    if(n%(2*d+1)==0) sum = n/(2*d+1);
    else sum = n/(2*d+1)+1;
    cout << sum << endl;
}

Measured memory_bytes: 256
n = int(input())
data = list(map(int, input().split()))
print(*data)
for i in range(1, n):
    v = data[i]
    j = i-1
    while j>=0 and data[j] > v:
        data[j+1] = data[j]
        j-=1
    data[j+1] = v
    print(*data)



Measured memory_bytes: 5976
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n; cin>>n;
    string s; cin>>s;
    s.insert(0,"0");
    vector<string> c={"SS","WW","SW","WS"};
    for(auto x:c){
        string a(n+1,'0');
        a[0]=x[0],a[1]=x[1];
        char t=a[0];
        for(int i=1;i<=n;i++){
                long nx=(i+1)%(n+1);
                if(i==n){
                        if(a[i]!=a[nx]){
                                a[0]='0';
                                break;
                        }
                }
                if(a[i]=='S'){
                        if(s[i]=='o')
                                a[nx]=a[i-1];
                        else{
                                if(a[i-1]=='S')
                                        a[nx]='W';
                                else
                                        a[nx]='S';
                        }
                }
                else{
                        if(s[i]=='x')
                                a[nx]=a[i-1];
                        else{
                                if(a[i-1]=='S')
                                        a[nx]='W';
                                else
                                        a[nx]='S';
                        }
                }
        }
        if(a[0]==a[1]){
                        for(int j=1;j<=n;j++)
                                cout<<a[j];
                        return 0;
        }
    }
    cout<<-1;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		boolean[] solved = new boolean[N];
		int[] wa = new int[N];
		Arrays.fill(solved, false);


		int penalty = 0;
		for (int i=0;i<M;i++) {
			int p = sc.nextInt()-1;
			String S = sc.next();

			if (S.equals("AC")) {
				if (!solved[p]) penalty+=wa[p];
				solved[p] = true;
			} else { // S.equals("WA")
				if (!solved[p]) wa[p]++;
			}
		}

		int accepted = 0;
		for (int i=0;i<N;i++) {
			if (solved[i]) accepted++;
		}
		System.out.println(accepted+" "+penalty);
	}
}


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

#define int long long

using namespace std;

const int mod = 1e9+7;

vector<int> f(2e5 + 10), inv_f(2e5 + 10);

int bin_pow(int a, int b) {
    if (b == 0) {
        return 1;
    }
    int res = bin_pow(a, b / 2);
    res *= res;
    res %= mod;
    if (b % 2) {
        res *= a;
        res %= mod;
    }
    return res;
}

int inv(int a) {
    return bin_pow(a, mod - 2);
}

int c(int n, int k) {
    return f[n] * inv_f[n - k] % mod * inv_f[k] % mod;
}

int32_t main() {
    f[0] = 1;
    for (int i = 1; i < f.size(); i++) {
        f[i] = i * f[i - 1] % mod;
    }
    for (int i = 0; i < f.size(); i++) {
        inv_f[i] = inv(f[i]);
    }
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        a[i].first--; a[i].second--;
    }
    n++;
    a.push_back({h - 1, w - 1});
    sort(a.begin(), a.end());
    vector<int> dp(n);
    for (int i = 0; i < n; i++) {
        int x = a[i].first, y = a[i].second;
        dp[i] = c(x + y, x);
        for (int j = 0; j < i; j++) {
            int cx = a[j].first, cy = a[j].second;
            if (cx <= x && cy <= y) {
                dp[i] += mod - dp[j] * c(x - cx + y - cy, x - cx) % mod;
                dp[i] %= mod;
            }
        }
    }
    cout << dp.back() << endl;
}


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

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (s==u) {
        a--;
    } else if (t==u) {
        b--;
    }

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,k[100005];
  bool ev=true;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>k[i];
    if(k[i]%2==1){ev=false;}
  }
  if(ev){cout<<"second"<<endl;}
  else{cout<<"first"<<endl;}
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();

        System.out.println(solve(A, B, T));

        sc.close();
    }

    static int solve(int A, int B, int T) {
        return T / A * B;
    }
}

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

int main(){

  while(true){
    string x;
    cin >> x;
    if(x == "0"){
      break;
    }
    int answer = 0;
    for(int i = 0; i < x.size(); i++){
      int y = x.at(i) - '0';
      answer += y;
    }
    cout << answer << endl;
  }
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  
  int n;
  cin >> n;
  
  vector<ll> L(n);
  rep(i,n) cin >> L[i];
  
  int ans = 0;
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(L[i] == L[j]) continue;
        if(L[j] == L[k]) continue;
        if(L[k] == L[i]) continue;
        bool ijsub = L[i]+L[j] > L[k];
        bool jksub = L[j]+L[k] > L[i];
        bool kisub = L[k]+L[i] > L[j];
        if(ijsub && jksub && kisub){
          ans ++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		HashMap<Integer, Integer> mapEv = new HashMap<>();
		HashMap<Integer, Integer> mapOd = new HashMap<>();
		ArrayList<Integer> evlist = new ArrayList<>();
		ArrayList<Integer> odlist = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			if (i%2 == 0) {
				int num = sc.nextInt();
				if (mapEv.containsKey(num)) {
					int cnt = mapEv.get(num);
					mapEv.put(num, cnt+1);
				} else {
					mapEv.put(num, 1);
					evlist.add(num);
				}
			} else {
				int num = sc.nextInt();
				if (mapOd.containsKey(num)) {
					int cnt = mapOd.get(num);
					mapOd.put(num, cnt+1);
				} else {
					mapOd.put(num, 1);
					odlist.add(num);
				}
			}
		}

		int Amax1Number = 0;
		int Amax2Number = 0;
		int Amax1 = 0;
		int Amax2 = 0;

		int Bmax1Number = 0;
		int Bmax2Number = 0;
		int Bmax1 = 0;
		int Bmax2 = 0;
		int ans = 0;

		//パターンA
		for (int i = 0; i < evlist.size(); i++) {
			int tmp = mapEv.get(evlist.get(i));
			if (Amax1 <= tmp) {
				Amax2 = Amax1;
				Amax1 = tmp;
				Amax2Number = Amax1Number;
				Amax1Number = evlist.get(i);
			} else if (Amax2 <= tmp) {
				Amax2 = tmp;
			}
		}
		//パターンB
		for (int i = 0; i < odlist.size(); i++) {
			int tmp = mapOd.get(odlist.get(i));
			if (Bmax1 <= tmp) {
				Bmax2 = Bmax1;
				Bmax1 = tmp;
				Bmax2Number = Bmax1Number;
				Bmax1Number = odlist.get(i);
			} else if (Bmax2 <= tmp) {
				Bmax2 = tmp;
			}
		}
		if (Amax1Number == Bmax1Number) {
			//どちらの場合が良いか判定
			if (Amax1 + Bmax2 < Amax2 + Bmax1) {
				ans = n - Amax2 - Bmax1;
			} else {
				ans = n - Amax1 - Bmax2;
			}
		} else {
			ans = n - Amax1 - Bmax1;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 67004
import numpy as np
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
MOD = 1000000007

dp = np.zeros(N + 2, dtype='int')
dp[0] = 1
for now in range(N):
    for _next in range(now + 1, now + 3):
        if _next not in A:
            dp[_next] += dp[now]
            dp[_next] %= MOD
print(dp[N])


Measured memory_bytes: 22492
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " ";
#define outline(x) cout << x << endl;
#define sortvector(v) sort(v.begin(), v.end());
#define sortvectorrev(v) sort(v.rbegin(), v.rend());
#define inf INT64_MAX
ll poww(long long a, long long n, long long m)
{
        long long ans = 1;
        long long mul = a;
        while (n != 0)
        {
                if (n % 2)
                {
                        ans = (ans * mul) % m;
                }
                mul = (mul * mul) % m;
                n /= 2;
        }
        return ans;
}
long long moduloMultiplication(ll a, ll b) 
{ 
    long long res = 0;
    a %= mod; 
    while (b) 
    { 
        if (b & 1) 
            res = (res + a) % mod; 
  

        a = (2 * a) % mod; 
  
        b >>= 1; // b = b / 2 
    } 
    return res; 
}
int32_t main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if(n <= 1)
    {
        outline(0)
        return 0;
    }
    int ans = (n*(n - 1));
    int a = poww(8, n - 2, mod);
    int a1= poww(10, n, mod);
    int a2 = moduloMultiplication(1, poww(9, n, mod)); // poww(9, n, mod);
    int a3 = poww(8, n, mod);
    a2 = moduloMultiplication(2, a2);
    int ff = a1 - a2 + a3;
    while(ff <= 0) 
        ff += mod;
    ff %= mod;
    int f = moduloMultiplication(ans, a);
    outline(ff)
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.close();

        int num = N;
        if(N>10) {
            num = N % 10;
        }
        if(num==3){
            System.out.println("bon");
        }else if(num==0 || num==1 || num==6 || num==8){
            System.out.println("pon");
        }else{
            System.out.println("hon");
        }
    }
}


Measured memory_bytes: 35788
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
 
using namespace std;
using ll = long long;
 
const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);
 
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)
 
int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H); rep(i, H) cin >> S[i];
 
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '.') {
                int cnt = 0;
                if (i > 0 && j > 0 && S[i - 1][j - 1] == '#') cnt++;
                if (i > 0 && S[i - 1][j] == '#') cnt++;
                if (i > 0 && j < W - 1 && S[i - 1][j + 1] == '#') cnt++;
                if (j > 0 && S[i][j - 1] == '#') cnt++;
                if (j < W - 1 && S[i][j + 1] == '#') cnt++;
                if (i < H - 1 && j > 0 && S[i + 1][j - 1] == '#') cnt++;
                if (i < H - 1 && S[i + 1][j] == '#') cnt++;
                if (i < H - 1 && j < W - 1 && S[i + 1][j + 1] == '#') cnt++;
                
                S[i][j] ='0'+cnt; // int を char に変換
            }
        }
    }
    
    rep(i, H) {
        cout << S[i] << endl;    
    }
    return 0;
}


Measured memory_bytes: 256
def solve():
    S = list(input())

    ans = len(S)
    # 0, 1
    for iro in range(2):
        cnt = 0
        for idx, s in enumerate(S):
            if idx % 2 == 0 and str(iro) != s: cnt += 1
            if idx % 2 != 0 and str(iro) == s: cnt += 1
        # print(cnt)
        ans = min(ans, cnt)

    print(ans)
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x==1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
//vector <bool> prime(boolsize,1);
//void seive()
//{
//    ll n=boolsize;
//    prime[0]=prime[1]=0;
//    for(ll i=2;i<=sqrt(boolsize);i++)
//    {
//        if(prime[i]==1)
//        {
//            for(ll j=i*i;j<=n;j+=i)
//            {
//                prime[j]=0;
//            }
//        }
//    }
//}

void fun()
{

}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {
        string a,b;
        cin>>a>>b;
        ll x=a.size(),y=b.size();
        if(x>y)
            cout<<"GREATER\n";
        else if(x<y)
            cout<<"LESS\n";
        else

        {
            fo(i,x)
            {
                if(a[i]>b[i])
                    {cout<<"GREATER";return 0;}
                else if(a[i]<b[i])
                    {cout<<"LESS";return 0;}
            }
            cout<<"EQUAL";
        }
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not




Measured memory_bytes: 3628
from collections import deque

def Graph(ab):
    G = [[] for i in range(n)]
    for a,b in ab:
        G[a-1].append(b)
        G[b-1].append(a)
    return G

def dfs(G, a, b):
    #(a, b)は除外する辺
    q = deque()
    q.append((1,-1))
    log = [0] * n
    log[0] = 1
    while q:
        V, P = q.pop()
        for new_v in G[V-1]:
            if {a, b} == {new_v, V}:#除外する辺であれば
                continue
            if new_v == P:#戻らない
                continue
            if log[new_v - 1]:#過去に行った頃がある点に行かない。
                continue
            log[new_v - 1] = 1
            q.append((new_v,V))
    return sum(log) != n

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
G = Graph(ab)

ans = 0
for a, b in ab:
    if dfs(G, a, b):
        ans += 1
print(ans)

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

ac = [0] * (n)
wa = [0] * (n)

for _ in range(m):
    p,s = input().split()
    p = int(p)-1
    
    if s == 'AC':
        ac[p] = 1
    
    if s == 'WA' and ac[p] == 0: 
        wa[p] += 1

print(sum(ac),sum([wa[x] for x in range(n) if ac[x]==1]))

Measured memory_bytes: 51416
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int a, b; cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3596
N, M = map(int, input().split())
high = list(map(int, input().split()))
road = [list(map(int, input().split())) for i in range(M)]
p=[True for _ in range(N)]

for i in road:
    if high[i[0]-1]<=high[i[1]-1] and p[i[0]-1]==True:
        p[i[0]-1]=False
        
    if high[i[0]-1]>=high[i[1]-1] and p[i[1]-1]==True:
        p[i[1]-1]=False

print(p.count(True))

Measured memory_bytes: 31916
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#define ll long long
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
using namespace std;
int main() {
  ll n,m;
  cin >> n >> m;
  ll a[100000];
  REP(i,n){
    ll ai,bi;
    cin >> ai >> bi;
    a[i] = ai * 1000000000 + bi;
  }
  ll ans = 0;
  ll cnt = 0;
  sort(a,a+n);
  REP(i,n){
    ll ai,bi;
    ai = a[i] / 1000000000;
    bi = a[i] - ai * 1000000000;
    ll pn = min(m-cnt,bi);
    ans += ai * pn;
    cnt += pn;
    //cout << "ai : " << ai << ",bi: " << bi << "pn: " << pn << endl;
    if(cnt==m) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024