akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void)
{
  int a, b, c, m, flag = 0, i;
  scanf("%d %d %d", &a, &b, &c);

  m = a;
  for(i = 0; i < 1000; i++){
    if(a%b == c){
      flag = 1;
      break;
    }
    a+=m;
  }
  if(flag) printf("YES\n");
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; 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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans = "No";

  if (abs(a-c) <= d) ans = "Yes";
  if (abs(a-b) <= d && abs(b-c) < d) ans = "Yes";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
Date: 2017/01/15 19:44:54 Sunday
*/
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,x,y;
int a[N];
ll b[N];
int main(){
#ifdef LOCAL
	freopen("B.in","r",stdin);//freopen("B.out","w",stdout);
#endif
	scanf("%d%d%d",&n,&x,&y);
	rep(i,1,n)scanf("%d",&a[i]);
	ll ans=0;
	rep(i,1,n-1)b[i]=min(1ll*(a[i+1]-a[i])*x,ll(y)),ans+=b[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
R,G,B,N = map(int,input().split())

ans = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        if N - R*i - G*j < 0:
            break
        if (N - R*i - G*j) % B == 0:
            ans += 1
print(ans)


Measured memory_bytes: 40684
#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 n,q;
    string s;
    cin>>n>>q>>s;
    vector<int>ans(n,0);
    rep(i,n-1){
        ans[i+1]=ans[i];
        if(s[i]=='A'&&s[i+1]=='C')ans[i+1]++;
    }
    rep(i,q){
        int l,r;
        cin>>l>>r;
        l--; r--;
        printf("%d\n",ans[r]-ans[l]);
    }
    return 0;
}

Measured memory_bytes: 3948
N,K=map(int,input().split())

h=list(map(int,input().split()))
INF=10**10
dp=[INF]*N
dp[0]=0

for i in range(N):
  for j in range(1,K+1):
    if i-j>=0:
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])

Measured memory_bytes: 84648
str = input()
n = int(input())

for _ in range(n):
    cmd = list(input().split())
    command, a, b = cmd[0], int(cmd[1]), int(cmd[2])
    if command == 'replace':
        str = str[:a] + cmd[3] + str[b+1:]
    elif command == 'reverse':
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]
    elif command == 'print':
        print(str[a:b+1])
    else:
        pass



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define mod 1000000007

int32_t main()
{
	/*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    */
    
    int n,a,b;
    cin>>n>>a>>b;
    int x[2];
		x[0]=a;
		x[1]=b;
		sort(x,x+2);
    if(abs(a-b)%2==0)
    {
    	cout<<(abs(a-b))/2<<endl;
	}
	else if(a==b)
	{
		cout<<0<<endl;
	}
	else
	{
		int mmm;
		mmm=min(x[0]-1,n-x[1]);
		if(x[0]-1<n-x[1])
		{
			x[0]=1;
			x[1]=x[1]-mmm-1;
			cout<<(x[1]-x[0])/2+mmm+1<<endl;
		}
		else
		{
			x[1]=n;
			x[0]=x[0]+mmm+1;
			cout<<(x[1]-x[0])/2+mmm+1<<endl;
		}
	}
    return 0;
}

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

int main() {
  int a, b; cin >> a >> b;
  string s; cin >> s;
  string ans = "Yes";
  
  for (int i = 0; i < s.size(); ++i) {
    char c = s[i];
    if (i == a) {
      if (c != '-') {
        ans = "No";
        break;
      }
    }
    else {
      if (c == '-') {
        ans = "No";
      	break;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
ll N,M;
  cin>>N>>M;
  ll A[M],B[M];

  vector<vector<ll>> fri(N+1,vector<ll>(0,0));
  for(ll i=0;i<M;i++){
  cin>>A[i]>>B[i];
    fri[A[i]].push_back(B[i]);
    fri[B[i]].push_back(A[i]);
  }
  /*
  for(ll i=1;i<N+1;i++){
    cout<<i<<":";
   for(ll j=0;j<(ll)fri[i].size();j++){
   cout<<fri[i][j]<<" ";
   }
    cout<<endl;
  }*/
  
  
  vector<ll> dist(N+1,-1);
  queue<ll> que;
  ll val=1;
  que.push(1);
  dist[1]=1;
  for(ll i=1;i<N+1;i++){
    if(i!=1){
	  if(dist[i]!=-1)continue;
    }
   	  while(!que.empty()){
     	ll num=que.front();
     	que.pop();
     	for(ll j=0;j<(ll)fri[num].size();j++){
          if(dist[fri[num][j]]!=-1)continue;
          que.push(fri[num][j]);
          dist[fri[num][j]]=val;
          //cout<<fri[i][j]<<"!"<<j<<"!"<<i<<endl;
          }
     
   		}

    val++;
    if(dist[i]!=-1)continue;
    que.push(i);
    dist[i]=val;
  }
  
  vector<ll> cost(2*N+1,0);
  ll ans=1;
  
  for(ll i=1;i<N+1;i++){
    //cout<<i<<":"<<dist[i]<<"cost"<<cost[dist[i]]<<endl;
    if(dist[i]==-1)continue;
    cost[dist[i]]++;
    ans=max(ans,cost[dist[i]]);
  }
  
  cout<<ans<<endl;
  
}


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

using namespace std;

void b_palindrome_philia(void) {
	string s;
	cin >> s;

	int s_size_h = s.size() >> 1;

	string s_upper = s.substr(0, s_size_h);

	int h_start = s.size() % 2 == 1 ? s_size_h + 1 : s_size_h;

	string s_lower = s.substr(h_start, s_size_h);
	int hug_cnt = 0;
	for (int i = 0; i < s_size_h; i++) {
		if (s_upper[i] != s_lower[s_size_h - i-1]) hug_cnt++;
	}

	cout << hug_cnt << endl;
}

int main()
{
    b_palindrome_philia();

    return 0;
}

Measured memory_bytes: 3608
#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; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n);

    rep(i, k) {
        int d; cin >> d;
        rep(j, d) {
            int a; cin >> a;
            a--;
            cnt[a]++;
        }
    }

    int ans = 0;
    rep(i, n) {
        if (cnt[i] == 0) ans++;
    }
    cout << ans << endl;
}


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

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

  vector<int> a(N);
  rep(i,0,N-1) cin >> a[i];

  int xor_a = 0;
  rep(i,0,N-1) xor_a ^= a[i];

  queue<int> q;
  rep(i,0,N-1) q.push(xor_a ^ a[i]);

  while (!q.empty()) {
    cout << q.front() << ' '; q.pop();
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 4748
I = [int(_) for _ in open(0).read().split()]
N, X, Y = I[0], I[1::2], I[2::2]
mod = 998244353


def compress_coord(raw):
    #i_v = {}
    v_i = {}
    for i, v in enumerate(sorted(set(raw))):
        #i_v[i] = v
        v_i[v] = i
    return v_i  #, i_v


class BinaryIndexedTree():
    def __init__(self, n):
        """
        constructs binary indexed tree

        Parameters
        ----------
        n : int
            maximum index value
        """
        self.n = n
        self.dat = [0] * (n + 1)

    def sum(self, i):
        """
        returns the sum of [1, i]

        Parameters
        ----------
        i : int
            right end of the interval
        """
        s = 0
        while i:
            s += self.dat[i]
            i -= i & -i
        return s

    def add(self, i, x):
        """
        adds x to i-th element

        Parameters
        ----------
        i : int
            index
        x : int
            additional value
        """
        while i <= self.n:
            self.dat[i] += x
            i += i & -i


xi = compress_coord(X)
yj = compress_coord(Y)
X = [xi[x] for x in X]
Y = [yj[y] for y in Y]
LL = [0] * (2 * N)
LR = [0] * (2 * N)
RL = [0] * (2 * N)
RR = [0] * (2 * N)
sortXY = sorted(zip(X, Y))
bit = BinaryIndexedTree(N + 10)
for x, y in sortXY:
    LL[x] = bit.sum(y + 1)
    LR[x] = bit.sum(N + 1) - bit.sum(y + 1)
    bit.add(y + 1, 1)
bit = BinaryIndexedTree(N + 10)
for x, y in sortXY[::-1]:
    RL[x] = bit.sum(y + 1)
    RR[x] = bit.sum(N + 1) - bit.sum(y + 1)
    bit.add(y + 1, 1)
ans = N * (pow(2, N, mod) - 1) % mod
for ll, lr, rl, rr in zip(LL, LR, RL, RR):
    a = pow(2, ll + lr, mod)
    b = pow(2, rl + rr, mod)
    c = pow(2, ll + rl, mod)
    d = pow(2, lr + rr, mod)
    e = pow(2, ll, mod)
    f = pow(2, lr, mod)
    g = pow(2, rl, mod)
    h = pow(2, rr, mod)
    ans -= a + b + c + d
    ans += e + f + g + h
    ans %= mod
print(ans)


Measured memory_bytes: 182444
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<int> rate(9);
  rep(i,n){
    cin >> a.at(i);
    if(a.at(i)>=3200) rate.at(8)++;
    else rate.at(a.at(i)/400)++;
  }

  int Min=0,Max=0,no=0;

  rep(i,8){
    if(rate.at(i)>0) Min++;
    else if(rate.at(i)==0) no++;
  }

  if(Min==0){
    Min=1;
    Max=rate.at(8);
  }else{
    Max=Min+rate.at(8);
  }

  cout << Min << " " << Max <<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c){
    cout<<(a&1?0:-1)<<endl;
    return 0;
  }
  Int t=0;
  while(1){
    if(a&1) break;
    if(b&1) break;
    if(c&1) break;
    Int x=a/2;
    Int y=b/2;
    Int z=c/2;
    a=0+y+z;
    b=x+0+z;
    c=x+y+0;
    t++;
  }
  cout<<t<<endl;
  return 0;
}


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

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define PI 3.14159265
#define take(a,n) for(int i=0;i<(n);i++) cin>>(a)[i]
#define out(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int (i)=0;i<(n);(i)++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
using namespace std;


ll poww(ll a,ll b)
{
  ll ans=1;
  for(int i=1;i<=b;i++)
  {
    ans*=a;
  }
  return ans;
}


int max(int a,int b,int c)
{
  if(a>=b && a>=c) return a;
  if(b>=a && b>=c) return b;
  return c;
}

ll ncr(int n,int r)
{
  ll ans=1;
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

int main()
{
  string s,t;
  cin>>s>>t;
  int ans=0;
  forup(i,3)
  {
    if(s[i]==t[i]) ans++;
  }
  cout<<ans;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int r,g,b,n; cin >> r>>g>>b>>n;

    int ans = 0;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            int s = n - i * r - j * g;
            if(0 <= s && s % b == 0) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3576
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().unwrap()
}

fn main() {
    let a: u64 = read();
    let b: u64 = read();

    let res = if (a * b) % 2 == 0 { "Even" } else { "Odd" };
    println!("{}", res);
}

Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	nm := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(nm[0])
	l := 1
	r := n
	m, _ := strconv.Atoi(nm[1])
	for i := 0; i < m; i++ {
		sc.Scan()
		lr := strings.Split(sc.Text(), " ")
		newL, _ := strconv.Atoi(lr[0])
		if l < newL {
			l = newL
		}
		newR, _ := strconv.Atoi(lr[1])
		if newR < r {
			r = newR
		}
	}
	res := r - l + 1
	if res < 0 {
		res = 0
	}
	fmt.Println(res)
}


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

int main(void) {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (t  ==
        s.substr(i, s.size() - i) + s.substr(0, i)) {
      cout << "Yes" << endl;
    return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque
s=list(input())
s=deque(s)
q=int(input())
a=0
for i in range(q):
  A=list(input().split())
  if A[0]=="1":
    a=(a+1)%2
  else:
    if A[1]=="1":
      if a==0:
        s.appendleft(A[2])
      else:
        s.append(A[2])
    else:
      if a==0:
        s.append(A[2])
      else:
        s.appendleft(A[2])
if a==1:
  S=[]
  c=len(s)
  for i in range(c):
    S.append(s[-1])
    s.pop()
else:
  S=s
for i in range(len(S)):
  print(S[i],end="")
print()

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a + b < c) cout << "NA" << endl;
  else {
    if(a < c) cout << c - a << endl;
    else cout << 0 << endl;
  }
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
inline int read(){char c = getchar();int x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e3 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 998244353;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
int n,m,fx,fy,ex,ey,vis[N][N],way[4][2] = {{1,0},{-1,0},{0,1},{0,-1}},ans[N][N];
char str[N][N];
struct node
{
    int x,y,step;
};
deque<node> q;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    cin >> n >> m >> fx >> fy >> ex >> ey;
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++)
            cin >> str[i][j],ans[i][j] = INF;
    q.push_back({fx,fy,0});
    while(!q.empty())
    {
        node t = q.front();
        int x = t.x,y = t.y,step = t.step;
        q.pop_front();
        if(vis[x][y]) continue;
        ans[x][y] = min(step,ans[x][y]),vis[x][y] = 1;
        for(int i = 0;i < 4;i++)
        {
            int xx = x+way[i][0],yy = y+way[i][1];
            if(xx > 0 && xx <= n && yy > 0 && yy <= m && !vis[xx][yy] && str[xx][yy] == '.')
                q.push_front({xx,yy,step});
//            cout << xx << " " << yy << " " << step << endl;
        }
        for(int i = -2;i <= 2;i++)
        {
            for(int j = -2;j <= 2;j++)
            {
                int xx = x+i,yy = y+j,flag = 0;
                if(xx > 0 && xx <= n && yy > 0 && yy <= m && !vis[xx][yy] && str[xx][yy] == '.')
                    q.push_back({xx,yy,step+1});
            }
        }
    }
    if(ans[ex][ey] == INF) cout << -1 << endl;
    else cout << ans[ex][ey] << endl;
}


Measured memory_bytes: 12944
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int ans = 0;
    for(int i = 0; i < N; i++){
        if (i % 2 == 0 && a[i] % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
from collections import Counter


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

sifter = {i: True for i in range(1, A[N - 1] + 1)}
counter = Counter(A)
ans = 0
for A_i in A:
  if sifter[A_i]:
    if counter[A_i] == 1:
      ans += 1
    for i in range(A_i, A[N - 1] + 1, A_i):
      sifter[i] = False
      
print(ans)

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


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

  string s; cin >> s;
  int n = si(s);

  rep(i, n) if (s[i] == '?') s[i] = 'D';
  cout << s << endl;
}

Measured memory_bytes: 3744
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

    public static void main(String[] args) {
        new Main().run();
    }

    void solve() {
        final String BADRESULT = "UNRESTORABLE";
        String S = in.nextToken();
        String T = in.nextToken();
        int type = 0;

        int startIndex = 0;
        for (int i = 0; i < S.length(); i++) {
            if (i + T.length() > S.length()) {
                if (type == 0) {
                    out.println(BADRESULT);
                    return;
                } else {
                    break;
                }
            } else if (compare(T, S.substring(i, i + T.length())) == 2) {
                type = 2;
                startIndex = i;
            } else if (compare(T, S.substring(i, i + T.length())) == 1) {
                type = 1;
            }
        }
        if (type == 1) {
            startIndex = S.length() - T.length();
        }
        StringBuilder sb = new StringBuilder(S.substring(0, startIndex).replaceAll("\\?", "a"));
        sb.append(T);
        sb.append(S.substring(startIndex + T.length()).replaceAll("\\?", "a"));
        out.println(sb.toString());
    }

    int compare(String T, String sub) {
        int result = 1;
        for (int i = 0; i < T.length(); i++) {
            if (sub.charAt(i) == '?') {
                continue;
            } else if (T.charAt(i) == sub.charAt(i)) {
                result = 2;
            } else if (T.charAt(i) != sub.charAt(i)) {
                return 0;
            }
        }
        return result;
    }


    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

}

Measured memory_bytes: 23124
#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: 11888
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };


vector<int>dev;


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


void devisor(ll n) {
	for (ll i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			if (i == n / i) {
				dev.push_back(i);
			}
			else {
				dev.push_back(i);
				dev.push_back(n / i);
			}
		}
	}
}


int main() {
	int a, b, k;
	cin >> a >> b >> k;

	devisor(gcd(a, b));
	sort(all(dev));
	reverse(all(dev));

	cout << dev[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	char s; cin >> s; s++;
	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> k(100002);
    int ma=0;
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        ma=max(ma,b);
        k[a-1]--;
        k[b]++;
    }
    int count=1;
    for(int i=ma;i>=0;i--){
        count+=k[i];
        if(count>=i){
            count=i;break;
        }
    }
    cout<<count-1<<endl;
}



Measured memory_bytes: 3104
#include "stdio.h"
int main()
{
	int a;
	int cnt = 0;
	scanf("%d%d", &a);
	
	
	if ((a & 1) == 1) {
		cnt++;
	}
	a = a / 10;

	if ((a & 1) == 1) {
		cnt++;
	}
	a = a / 10;
	if ((a & 1) == 1) {
		cnt++;
	}

	printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)
  
a,b,c,d=map(int,input().split())

c1=(b//c)-(-((-1*a)//c))+1
d1=(b//d)-(-((-1*a)//d))+1
cd=lcm(c, d)
#print(cd)
cd1=(b//cd)-(-((-1*a)//cd))+1

print(b-a-c1-d1+cd1+1)


Measured memory_bytes: 3064
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll mod = 2019;
ll modpow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1){
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return res;
}
int main(void){
    string s;
    cin >> s;

    vector<ll> num(s.size() + 1, 0);

    ll now = 0;

    reverse(all(s));

    map<ll,ll> mp;
    mp[0]++;
    ll ans = 0;
    for(ll i = 0; i < s.size(); i++){
        now += modpow(10, i) * (s[i] - '0');
        now %= mod;
        //cout << i << " " << now << endl;
        ans += mp[now];
        mp[now]++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 5244
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int maxn = 300500;

int s[maxn];

int main(){
	int n; sci(n);
	int s = 0;
	int nn = n;
	while (n > 0){
		s += n % 10;
		n /= 10;
	}
	puts(nn%s == 0 ? "Yes" : "No");
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
        // 出力
        int yaku_c;
        int ok_c = 0;
        for(int i=1; i<=n; i++){
            yaku_c = 0;
            for(int j=1; j<=i; j++){
                if(i%2==0)break;
                if(i%j==0)yaku_c++;
            }
            if(yaku_c == 8)ok_c++;
            //System.out.println("i="+i+" yaku_c="+yaku_c+"\n\n");
        }

		System.out.println(ok_c);
	}
}

Measured memory_bytes: 22868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;

using DWORD = unsigned int;
using WORD = unsigned short;

int main()
{
    DWORD dwInput_N, dwInput_M, dwInput_Q;
    char str[200];

    fgets(str, sizeof(str), stdin);
    dwInput_N = atoi(strtok(str, " "));
    dwInput_M = atoi(strtok(NULL, " "));
    dwInput_Q = atoi(strtok(NULL, " "));

    /* input train */
    static DWORD aadwTrainMap[501][501];
    for (DWORD dwIdx = 0; dwIdx < dwInput_M; dwIdx++) {
        fgets(str, sizeof(str), stdin);
        WORD wCity_L, wCity_R;

        wCity_L = atoi(strtok(str, " "));
        wCity_R = atoi(strtok(NULL, " "));
        aadwTrainMap[wCity_L][wCity_R]++;
    }

    /* calc camsum(Row, Col) */
    for (DWORD dwRow = 1; dwRow <= dwInput_N; dwRow++) {
        DWORD dwSum = 0;
        for (DWORD dwCol = 1; dwCol <= dwInput_N; dwCol++) {
            dwSum += aadwTrainMap[dwRow][dwCol];
            aadwTrainMap[dwRow][dwCol] = dwSum + aadwTrainMap[dwRow-1][dwCol];
        }
    }

    /* input question */
    for (DWORD dwIdx = 0; dwIdx < dwInput_Q; dwIdx++) {
        DWORD dwAnswer;
        fgets(str, sizeof(str), stdin);
        WORD wBegin = atoi(strtok(str, " "));
        WORD wEnd   = atoi(strtok(NULL, " "));

        dwAnswer= (aadwTrainMap[wEnd][wEnd]
                    - aadwTrainMap[wBegin-1][wEnd]
                    - aadwTrainMap[wEnd][wBegin-1]
                    + aadwTrainMap[wBegin-1][wBegin-1]);
        printf("%d\n", dwAnswer);
    }

    return 0;

}



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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);

  for (int i = 0; i < n; i++)
  {
    cin >> d[i];
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      ans += d[i]*d[j];
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef struct node{
  int wh[4][2];
  int w;
  struct node* c[4];
} node;

int w,h;
int f[62][14];
int i,j;
char c[12];
int s,n;
node t;

int sc(int wh[4][2],int x,int y){
  if(f[x][y] == n){
    wh[s][0] = x;
    wh[s][1] = y;
    f[x][y] = 0;
    s++;
    if(s == 4)
      return 1;
    if(sc(wh,x+1,y))
      return 1;
    if(sc(wh,x,y+1))
      return 1;
    if(sc(wh,x,y-1))
      return 1;
    if(sc(wh,x-1,y))
      return 1;
  }
  else
    return 0;
}

void add(node* p,int x,int y){
  int z;
  node *nd = new node;
  s = 0;
  sc(nd->wh,x,y);
  nd->w = 0;
  for(z = 0;z < 4;z++){
    nd->w += nd->wh[z][1];
    nd->c[z] = NULL;
  }
  for(z = 0;p->c[z] != NULL;z++);
  p->c[z] = nd;
  for(z = 0;z < 4;z++){
    x = nd->wh[z][0] + 1;
    y = nd->wh[z][1];
    if(n=f[x][y])
      add(nd,x,y);
  }
}

int k;

int sw(node* p){
  int z;
  int m = p->w;
  k++;
  for(z = 0;z < 4;z++){
    if(p->c[z] != NULL)
      m += sw(p->c[z]);
    else
      break;
  }
  return m;
}

int ck(node* p){
  int z,a,b,m;
  int min,max;
  for(z = 0;z < 4;z++){
    if(p->c[z] != NULL){
      min = 12;
      max = 0;
      for(a = 0;a < 4;a++){
	for(b = 0;b < 4;b++){
	  if(p->wh[a][0]+1 == p->c[z]->wh[b][0] &&
	     p->wh[a][1] == p->c[z]->wh[b][1]){
	    min = (min < p->wh[a][1])?min:p->wh[a][1];
	    max = (max > p->wh[a][1])?max:p->wh[a][1];
	  }
	}
      }
      k = 0;
      m = sw(p->c[z]);
      if(!((2*min-1)*2*k < m && m < (2*max+1)*2*k))
	return 0;
      if(!ck(p->c[z]))
	return 0;
    }
  }
  return 1;
}

int main(void){
  while(1){
    cin >> w >> h;
    if(w == 0)
      break;
    for(i = 0;i < 62;i++){
      for(j = 0;j < 14;j++)
	f[i][j] = 0;
    }
    for(i = h;i > 0;i--){
      cin >> c;
      for(j = 1;j <= w;j++){
	if(0<c[j-1]-'0' && c[j-1]-'0'<10){
	  f[i][j] = c[j-1]-'0';
	}
	else
	  f[i][j] = 0;
      }
    }
    for(j = 1;j <= w;j++){
      if(n=f[1][j]){
	for(i = 0;i < 4;i++){
	  t.wh[i][0] = 0;
	  t.wh[i][1] = j+i;
	  t.c[i] = NULL;
	}
	add(&t,1,j);
      }
    }
    if(ck(&t))
      cout << "STABLE" << endl;
    else
      cout << "UNSTABLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 1328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

const int Q = 100001;
vector<int> isPrime, is;
vector<int> sumP;

void init() {
	isPrime.resize(Q);
	for (int i = 2; i < Q; i++) {
		int n = i;
		bool b = true;
		for (int j = 2; j * j <= n; j++) {
			if (n % j == 0) {
				b = false;
				break;
			}
		}
		if (b) {
			isPrime[i]++;
		}
	}
	is.resize(Q);
	rep(i,Q) {
		if (i % 2 == 0) continue;
		if (isPrime[i] && isPrime[(i + 1) / 2]) is[i]++;
	}
	sumP.resize(Q);
	for (int i = 1; i < Q; i++) {
		sumP[i] = sumP[i - 1] + is[i];
	}
}

void solve() {
	int q;
	cin >> q;
	vector<int> l(q), r(q);
	rep(i,q) {
		cin >> l[i] >> r[i];
	}
	rep(i,q) {
		cout << sumP[r[i]] - sumP[l[i] - 1] << endl;
	}
}

int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 5100
#include<stdio.h>

int main(void){
    float a,b,c,d,e,f,x,y;
    while(scanf("%f%f%f%f%f%f", &a, &b, &c, &d, &e, &f)!=EOF){
        y=(c*d-f*a)/(b*d-e*a);
        x=(c-b*y)/a;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}


Measured memory_bytes: 2024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

char m[55][55];
int a[55][55];

int main(){
	int h, w;
	
	cin >> h >> w;
	
	REP(i,h){
		REP(j,w){
			cin >> m[i][j];
			
			if (m[i][j] == '#'){
				a[i][j]++;
				a[i][j+1]++;
				a[i][j+2]++;
				a[i+1][j]++;
				a[i+1][j+1] = -1;
				a[i+1][j+2]++;
				a[i+2][j]++;
				a[i+2][j+1]++;
				a[i+2][j+2]++;
			}
		}
	}
	
	FOR(i,1,h+1){
		FOR(j,1,w+1){
			if (m[i-1][j-1] == '#') cout << "#";
			else cout << a[i][j];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np

def is_connected(npmat):
    mat = np.copy(npmat)
    dim = mat.shape[0]
    for i in range(dim):
        mat[i][i] = 0
    accessible = set([0])
    queue = [0]
    while len(queue) > 0:
        i = queue.pop()
        js = filter(lambda x:x[1], enumerate(mat[i] > 0))
        for j, bool in js:
            if not j in accessible:
                accessible.add(j)
                if len(accessible) == dim :
                    return True
                queue.append(j)
    return len(accessible) == dim


N, M = map(int,input().split())

V = np.zeros((M,2))
for i in range(M):
    V[i,0], V[i,1] = map(int,input().split())

V = V.astype(np.int)

count = M
for i in range(M):
    mat = np.identity(N, dtype=np.int)
    for j in range(M):
        if i != j:
            mat[V[j,0]-1, V[j,1]-1] = 1
            mat[V[j,1]-1, V[j,0]-1] = 1
    if is_connected(mat):
        count -= 1


print(count)

Measured memory_bytes: 21656
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    ll n, k;
    cin >> n >> k;
    vector < ll > v(n+1);
    v[0] = 0;
    fo(i, 1, n){
        cin >> v[i];
        v[i] += v[i-1];
    }
    ll x = lob(all(v), k) - v.begin();
    //cout << x << endl;
    if(find(all(v), k) != v.end()){
        x++;
    }
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll ans = 0;
  ll tmp;
  rep(i, N) {
    cin >> A[i];
    if(i) {
      tmp = min(A[i-1], A[i]);
      ans += tmp;
      A[i-1] -= tmp;
      A[i] -= tmp;
    }
    tmp = A[i] / 2;
    ans += tmp;
    A[i] -= 2 * tmp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc161
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc161B();
        }

        public static void solve_abc161B()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nm[0];
            int m = nm[1];
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += a[i];
            }
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] >= (double)sum / (4 * m))
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt >= m ? "Yes" : "No");
        }

        public static void solve_abc161A()
        {
            int[] xyz = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Console.WriteLine("{0} {1} {2}", xyz[2], xyz[0],xyz[1]);
        }
    }
}


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

typedef long long ll;

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

    int n;
    cin >> n;
    double uku = n / 1.08;
    int ans = (int)uku;
    if(ans*1.08==n){
        cout << ans << endl;
    }else{
        if((int)((ans+1)*1.08)==n){
            cout << ans+1 << endl;
        }else{
            cout << ":(" << endl;
        }
    }
    return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  cin>>N;
  while(cin>>N && N){
    string s;
    cin>>s;
    int dp[3] = {};
    dp[0] = 0; dp[1] = INF; dp[2] = INF;
    for(int i = 0; i < N + 1; i++){
      int nextdp[3] = {};
      fill(nextdp, nextdp + 3, INF);
      bool need[2] = {};
      if(i != 0) need[0] |= s[2 * i - 1] == 'Y';
      if(i != 0) need[1] |= s[2 * i - 1 + 2 * N] == 'Y';
      if(i != N) need[0] |= s[2 * i] == 'Y';
      if(i != N) need[1] |= s[2 * i + 2 * N] == 'Y';
      REP(j, 3)REP(k, 3){
        int x = -1;
        if(j == 0){
          if(need[1]) x = 3 + abs(2 * k - 3);
          else if(need[0]) x = 1 + abs(2 * k - 1);
          else x = abs(2 * k - 0);
        }else if(j == 1){
          if(need[0] && need[1]) x = 4;
          if(need[0] && !need[1]) x = 1 + abs(2 * k - 1);
          if(!need[0] && need[1]) x = 1 + abs(2 * k - 3);
          if(!need[0] && !need[1]) x = abs(2 * k - 2);
        }else {
          if(need[0]) x = 3 + abs(2 * k - 1);
          else if(need[1]) x = 1 + abs(2 * k - 3);
          else x = abs(2 * k - 4);
        }
        nextdp[k] = min(nextdp[k], dp[j] + x + 2);
      }
      memcpy(dp, nextdp, sizeof(dp));
      /*
      printf("%d: need[0] = %d need[1] = %d ", i, need[0], need[1]);
      debug(dp, dp + 3);
      */
    }
    cout<<dp[0] / 2 - 1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <ctime>
#include <map>
#include <queue>

using namespace std; using ll=long long; using P=pair<ll,ll>; const int INF=1e9; const ll LNF=1e18;

int main(){
  int n; ll l; cin>>n>>l;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll good=-1; for(int i=0;i<n-1;i++) if (a[i]+a[i+1]>=l) good=i;

  if (good == -1) {
    cout<<"Impossible"<<endl;
    return 0;
  }

  cout<<"Possible"<<endl;
  for(int i=0;i<good;i++) {
    cout<<i+1<<endl;
  }
  for(int i=n-1;i>good;i--) {
    cout<<i<<endl;
  }
}

Measured memory_bytes: 1536