akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
lr = [[int(i) for i in input().split()] for i in range(m)]

low = 1
high = n

for i in range(m):
        lr_temp = lr[i]
        if low < lr_temp[0]:
                low = lr_temp[0]
        if high > lr_temp[1]:
                high = lr_temp[1]

ans = high - low + 1

if ans < 0:
        ans = 0

print(ans)

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

int main()
{
    int A, B;
    cin >> A >> B;

    if( A%3 == 0 || B%3 == 0 || (A+B)%3 == 0 )
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;

    return 0;
}


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

using namespace std;

char str1[3005],str2[3005];
int dp[3005][3005],len1,len2;

string backtrack(int ch1,int ch2)
{
  if (ch1==0||ch2==0)return "";
  if (str1[ch1]==str2[ch2])
  return backtrack(ch1-1,ch2-1)+str1[ch1];
  else
  return (dp[ch1-1][ch2]>dp[ch1][ch2-1]?backtrack(ch1-1,ch2):backtrack(ch1,ch2-1));
}

int main()
{
  scanf("%s%s",&str1[1],&str2[1]);
  len1=strlen(&str1[1]);
  len2=strlen(&str2[1]);
  for(int c=1;c<=len1;c++)
  {
    for(int c2=1;c2<=len2;c2++)
    {
      if (str1[c]==str2[c2])
      dp[c][c2]=dp[c-1][c2-1]+1;
      else dp[c][c2]=max(dp[c-1][c2],dp[c][c2-1]);
    }
  }
  printf("%s\n",backtrack(len1,len2).c_str());
}


Measured memory_bytes: 35712
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        a: [isize; n],
    }

    let mut cum = vec![0; n + 1];

    let mut acc = 0;
    for i in 0..n {
        acc += a[i];
        cum[i + 1] = acc;
    }

    let mut map = HashMap::new();
    for &c in &cum {
        let entry = map.entry(c).or_insert(0);
        *entry += 1usize;
    }

    let mut ans = 0;
    for (_, value) in &map {
        ans += value * (value - 1) / 2;
    }
    println!("{}", ans);
}


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

int main(){
	int n,m;
	cin >> n >> m;
	int sum=0;
	vector<int> a(m);
	rep(i,m)cin >> a[i];
	rep(i,m)sum+=a[i];

	if(n-sum<0){cout << -1;}
	else{
		cout << n-sum;	
	}
	return 0;
}


Measured memory_bytes: 3664
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

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

	void run() throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = Integer.MAX_VALUE / 3;
		for (int A = 1; A <= N - 1; ++A) {
			int B = N - A;
			ans = Math.min(ans, cnt(A) + cnt(B));
		}
		System.out.println(ans);
	}

	int cnt(int a) {
		int ret = 0;
		while (a > 0) {
			ret += a % 10;
			a /= 10;
		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 21204
#include <cstdio>

int main() 
{
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	int op = 0;
	while (a >= b) {
		b *= 2;
		++op;
	}
	while (b >= c) {
		c *= 2;
		++op;
	}
	if (op <= k) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

const int N = 1000 * 200 + 5;
long long n, k, l, vis[N][2], a = 1;
vector <long long> adj[N][2];
map <pair <long long, long long>, long long> ans;

void dfs(int v) {
	vis[v][0] = a;
	for (auto u : adj[v][0])
		if (!vis[u][0]) 
			dfs(u);
}

void dfs1(int v) {
	vis[v][1] = a;
	for (auto u : adj[v][1])
		if (!vis[u][1]) 
			dfs1(u);
}

int main() {
	cin >> n >> k >> l;
	for (long long i = 0, u, v; i < k; i++)
		cin >> u >> v, adj[u][0].push_back(v), adj[v][0].push_back(u);
	for (long long i = 0, u, v; i < l; i++)
		cin >> u >> v, adj[u][1].push_back(v), adj[v][1].push_back(u);
	for (int i = 1; i <= n; i++)
		if (vis[i][0] == 0)
			dfs(i), a++;
	for (int i = 1; i <= n; i++)
		if (vis[i][1] == 0)
			dfs1(i), a++;
	for (int i = 1; i <= n; i++)
		ans[{vis[i][0], vis[i][1]}]++;
	for (int i = 1; i <= n; i++)
		cout << ans[{vis[i][0], vis[i][1]}] << ' ';
	cout << endl;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

ll dp[4444][4444];

void modadd(ll &a, ll b){
	a += b;
	a %= MOD;
}

int main(){
	
	string str;
	cin >> str;
	ll n = str.size();
	ll sum = 0;
	dp[0][0] = 1;
	REP(i,2 * n){
		if(i < n)sum += 2;
		REP(j, 2 * n)if(dp[i][j]){
			ll now = j;
			if(i < n)now += str[i] - '0';
			if(now)modadd(dp[i+1][now-1], dp[i][j]);
			if(sum - now - i)modadd(dp[i+1][now], dp[i][j]);
		}
	}
	//cerr << endl << endl;
	//SHOW2d(dp,2*n+1,2*n+1);
	
	cout << dp[2*n][0] << endl;
	
	return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R, -1);
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }
    vector<vector<int>> G(N, vector<int>(N, INF));
    for (int i = 0; i < N; i++) {
        G[i][i] = 0;
    }

    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        G[a][b] = G[b][a] = c;
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    vector<int> order(0);
    rep(i, R) { order.push_back(i); }
    int mi = INF * 2;
    do {
        int sum = 0;
        for (int i = 0; i < R - 1; i++) {
            sum += G[r[order[i]]][r[order[i + 1]]];
        }
        mi = min(sum, mi);
    } while (next_permutation(all(order)));
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 384
import sys

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


ans = 0
for a in A:
    ans += abs(a)

c = 0
m = abs(A[0])
for a in A:
    if a < 0:
        c += 1
    elif a == 0:
        print(ans)
        sys.exit()

    if abs(a) < m:
        m = abs(a)

if c % 2 == 0:
    print(ans)
else:
    print(ans - 2 * m)


Measured memory_bytes: 19956
#include<iostream>
#include<set>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<int, int > P;

int N, M;
P ar[100000];

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> ar[i].second >> ar[i].first;
	}
	sort(ar, ar + M);

	int ans = 0;
	int bd = 0;
	for (int i = 0; i < M; i++) {
		if (bd < ar[i].second)ans++, bd = ar[i].first - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > s(m);
    for(int i=0; i<m; ++i){
        int k;
        cin >> k;
        s[i].resize(k);
        for(int j=0; j<k; ++j){
            cin >> s[i][j];
            -- s[i][j];
        }
    }
    vector<int> p(m);
    for(int i=0; i<m; ++i)
        cin >> p[i];

    int ans = 0;
    for(int i=0; i<(1<<n); ++i){
        bitset<32> bs(i);
        vector<int> cnt(m, 0);
        for(int j=0; j<m; ++j){
            for(int k : s[j]){
                if(bs[k])
                    ++ cnt[j];
            }
        }
        bool ok = true;
        for(int j=0; j<m; ++j){
            if(cnt[j] % 2 != p[j])
                ok = false;
        }
        if(ok)
            ++ ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

typedef long long ll;

const ll M=100000007;

ll dp[2][100001];

ll f(char c,int n){ return (c=='0'||c=='8')?dp[0][n]:dp[1][n]; }

int main(){
	rep(t,2){
		int T=(t==0?3:5);
		rep(i,T) dp[t][i+1]=1<<i;
		for(int i=T;i<100000;i++) rep(j,T) dp[t][i+1]=(dp[t][i+1]+dp[t][i-j])%M;
		for(int i=T;i<100000;i++) dp[t][i+1]=(dp[t][i+1]+dp[t][i+1-T])%M;
	}

	for(char s[100001];scanf("%s",s),s[0]!='#';){
		ll ans=1;
		for(int i=1,p=0;s[i-1];i++) if(s[p]!=s[i]) ans=ans*f(s[p],i-p)%M, p=i;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2424
#include <stdio.h>
int main(){
  int x,y,tmp,r;
  scanf("%d %d",&x,&y);
  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }

  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 2728
N, M, Q = gets.chomp.split(" ").map(&:to_i)
T = Array.new(N + 1)
T.map!{ Array.new(N + 1, 0)}
M.times{
  l, r = gets.chomp.split(" ").map(&:to_i)
  T[l][r] += 1
}
QU = []
Q.times{
  QU << gets.chomp.split(" ").map(&:to_i)
}

(N-1).downto(1){|i|
  (i..N).each{|j|
    T[i][j] += T[i+1][j]
  }
}
(N-1).downto(1){|i|
  (i..N).each{|j|
    T[i][j] += T[i][j-1]
  }
}

QU.each{|p, q|
  puts T[p][q]
}


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

#define N 100001
#define M 1000

int bs (int [], int, int);

int compar (const void *a, const void *b) {
  return *(int *)a- *(int *)b;
}

int main(void)
{
  while(1)
    {
      int c,D,m,n,i,j,h=0,sum=0;
      int d[N],d2[N];

      scanf("%d",&D);
      if(D==0) break;
      scanf("%d",&n);
      scanf("%d",&m);
      d[0]=0;
      for(i=1;i<=n-1;i++)
        {
          scanf("%d",&d[i]);
        }
      d[n]=D;
      for(i=0;i<=n;i++)
        {
          d2[i]=d[i];
        }   
      qsort(d2,n+1,sizeof(int),compar);
      for(i=0;i<=m-1;i++)
        {
          scanf("%d",&c);
          sum = sum + bs(d2,n,c);
        }
      printf("%d\n",sum);
    }
  return 0;
}

int bs (int D[], int n, int c) {
  int i=0,j,k,l;
  j=0;
  k=n-1;
  while(1)
    {
      i++;
      l=(j+k)/2;
      if(D[l] > c)
	{
	  k=l-1;
	}
      else if(D[l+1] < c)
	{
	  j=l+1;
	}
      else
	{
	  return (c-D[l]<D[l+1]-c) ? c-D[l] : D[l+1]-c;
	}
  }
}

Measured memory_bytes: 1704
#include <stdio.h>

int main(void){
  long long a,b,c,d,max;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
   max=a*c;
  if(max<b*d) max=b*d;

  if(max<a*d) max=a*d;
  if(max<c*b) max=c*b;
  printf("%lld\n",max);


  return 0;
}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
int main(){
  #define int long long
  int r,l;
  cin >> r >> l;
  for (int i = r; i < l; i++)
  {
    if(i%2019==0){
      cout << 0 << endl;
      return 0;
    }
  }
  
  r = r%2019;
  l = l%2019;
  int ans = 2019;
  for(int i=r;i<l+1;i++){
    for(int j=i+1;j<l+1;j++){
      int ss = (i*j)%2019;
      ans = min(ans,ss);
    }
   }
   cout << ans << endl;
  }


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

class Program {
  static void Main (string[] args) {
    string[] str = Console.ReadLine().Split(' ');
    int a = int.Parse(str[0]);
    int b = int.Parse(str[1]);
    if (a <= 5) {
      Console.WriteLine("0");
    }
    else if (a >= 6 && a <= 12) {
      int res = b / 2;
      Console.WriteLine(res);
    }
    else if (a >= 13) {
      Console.WriteLine(b);
    }
  }
}

Measured memory_bytes: 11092
MOD = 10**9 + 7

s = str(input())

dp0 = [0] * (len(s)+1)
dp1 = [0] * (len(s)+1)
dp0[0] = 1

for i in range(1,len(s)+1):
    if s[i-1] == "0":
        dp0[i] = dp0[i-1]
        dp1[i] = dp1[i-1] * 3
    else:
        dp0[i] = dp0[i-1] * 2
        dp1[i] = dp0[i-1] + dp1[i-1] * 3
    dp0[i] %= MOD
    dp1[i] %= MOD

answer = dp0[-1] + dp1[-1]
if answer >= MOD:
    answer -= MOD
print(answer)


Measured memory_bytes: 11076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS vector<string>
LL facctorialMethod(int k);
int main(){
    LL n;
    cin >> n;
    if( (n/100)==7 || ((n/10)%10)==7 || (n%10)==7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll p[11][11];

int main(void){
	int n,i,j,l,r;
	ll ans=0ll;
	cin >> n;
	for(i=1; i<=n; ++i){
		j = i;
		r = j%10;
		while(j){
			l = j;
			j /= 10; 
		}
		++p[l][r];
	}
	for(i=1; i<10; ++i){
		for(j=1; j<10; ++j){
			ans += p[i][j]*p[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}


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

template <typename T>
string pairToString(const pair<T, T>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void solve() {
  int R, C;
  cin >> R >> C;
  vector<pair<int, int>> intervals(R);
  for (int i = 0; i < R; ++i) {
    cin >> intervals[i].first >> intervals[i].second;
    --intervals[i].first;
    --intervals[i].second;
  }

  multiset<int> values;
  set<pair<int, int>> paths;  // { ending point, starting point }
  for (int i = 0; i < C; ++i) {
    paths.insert({ i, i });
    values.insert(0);
  }

  const int INFTY = 10 * (R + C);
  for (int i = 0; i < R; ++i) {
    // Update.
    pair<int, int> path_to_add = { -1, -1 };
    auto it = paths.lower_bound(make_pair(intervals[i].first, -1));
    while (it != paths.end()) {
      const int endpoint = it->first;
      const int startpoint = it->second;
      if (endpoint > intervals[i].second) {
        break;
      }
      const int old_value = endpoint - startpoint;
      path_to_add = { intervals[i].second + 1, startpoint };
      values.erase(values.find(old_value));
      it = paths.erase(it);
    }

    if (intervals[i].second != C - 1 && path_to_add.first != -1) {  // Don't add INFTY values.
      paths.insert(path_to_add);
      values.insert(path_to_add.first - path_to_add.second);
    }

    // Vertical component.
    const int vertical = i + 1;

    // Horizontal component.
    if (values.empty()) {
      cout << -1 << endl;
    } else {
      int horizontal = *values.begin();
      cout << horizontal + vertical << endl;
    }

  }
}

int main() {
  solve();
}

Measured memory_bytes: 23576
#include <iostream>

int main(){
   std::string s;
   std::cin >> s;

   const int N = s.size();
   int ans = N;
   for(char ch='a'; ch<='z'; ++ch){
      if(s.find(ch)==-1) continue;
      std::string t = s;
      int count = 0;
      int n = 0;
      for(int i=0; i<t.size(); ++i)
	 if(t[i]==ch) ++n;
      while(n<t.size()){
	 for(int i=0; i<t.size()-1; ++i){
	    if(t[i+1]==ch){
	       t[i] = ch;
	    }
	 }
	 t.pop_back();
	 ++count;
         n = 0;
         for(int i=0; i<t.size(); ++i)
	    if(t[i]==ch) ++n;
      }
      ans = std::min(ans,count);
   }
   std::cout << ans << std::endl;
   return 0;

}


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

int main(){
    int n, l;
    int aji = 0;
    bool flg = false;

    cin >> n >> l;

    for(int i = l; i < l + n; i++){
        if(i == 0) flg = true;
        aji += i;
    }
    if(flg){
        cout << aji << endl;
    }
    else if(l < 0){
        aji -= l + n - 1;
        cout << aji << endl;
    }
    else{
        aji -= l;
        cout << aji << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int last_left_block[2000][2000];
int next_right_block[2000][2000];
int last_up_block[2000][2000];
int next_down_block[2000][2000];
string S[2000];
int main(void){
  int H;
  int W;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    cin >> S[i];
  }
  for(int i = 0; i <  H; i++){
    int last_block = -1;
    for(int j = 0; j < W; j++){
      if(S[i][j] != '#'){
        last_left_block[i][j] = last_block;
      } else {
        last_block = j;
      }
    }
  }
  for(int i = 0; i < H; i++){
    int next_block = W;
    for(int j = W - 1; j >= 0; j--){
      if(S[i][j] != '#'){
        next_right_block[i][j] = next_block;
      } else {
        next_block = j;
      }
    }
  }

  for(int i = 0; i <  W; i++){
    int last_block = -1;
    for(int j = 0; j < H; j++){
      if(S[j][i] != '#'){
        last_up_block[j][i] = last_block;
      } else {
        last_block = j;
      }
    }
  }
  for(int i = 0; i < W; i++){
    int next_block = H;
    for(int j = H - 1; j >= 0; j--){
      if(S[j][i] != '#'){
        next_down_block[j][i] = next_block;
      } else {
        next_block = j;
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      ans = max(ans, next_right_block[i][j] - last_left_block[i][j] + next_down_block[i][j] - last_up_block[i][j] - 3);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 66816
#!/usr/bin/env python3

def solve(s):
    s = str(s)
    c = 0
    for i in range(1000):
        v = [i//100, i//10%10, i%10]
        f = 0
        for j in range(len(s)):
            if int(s[j]) == v[f]:
                f += 1
            if f == 3:
                break
        if f == 3:
            c += 1
    return c

def main():
    N = int(input())
    S = input()
    print(solve(S))


if __name__ == '__main__':
    main()


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

int hantei(int);

int main()
{
  int sei[10000], N, i, count = 0;
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &sei[i]);
    count += hantei(sei[i]);
  }
  
  printf("%d\n", count);
  return 0;
}

int hantei(int x)
{
  int i = 3;
  if(x == 2) return 1;
  if(x < 2 || x % 2 == 0) return 0;

  while(i <= sqrt(x)){
    if(x % i == 0) return 0;
    i += 2;
  }
  return 1;
}

Measured memory_bytes: 628
#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 all(v) v.begin(),v.end()
#define v vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    string s;
    cin >> s;
    rep(i, s.size()){
        if(s[i]=='?') s[i] = 'D';
    }
    rep(i,s.size()){
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 3752
import java.util.Scanner;

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

		int ans = 0;
		for (int n = 1; n <= N; n++) {
			if (A <= sumDigits(n) && sumDigits(n) <= B) {
				ans += n;
			}
		}
		System.out.println(ans);
	}

	public static int sumDigits(int n) {
		int sum = 0;
		while (n != 0) {
			sum += n % 10;
			n /= 10;
		}
		return sum;
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Console.WriteLine(Solve() ? "Yes" : "No");
		Out.Flush();
	}
	int N, Q;
	List<Edge>[] g;
	int[] l, r, d, x;
	bool[] done;
	bool Solve()
	{
		var I = G;
		N = I[0];
		Q = I[1];
		l = new int[Q];
		r = new int[Q];
		d = new int[Q];
		var uf = new UnionFindTree(N);
		x = new int[N];
		done = new bool[N];
		g = new List<Edge>[N];
		for (var i = 0; i < N; i++) g[i] = new List<Edge>();
		for (var i = 0; i < Q; i++)
		{
			I = G;
			l[i] = I[0] - 1;
			r[i] = I[1] - 1;
			d[i] = I[2];
			g[l[i]].Add(new Edge(r[i], -d[i]));
			g[r[i]].Add(new Edge(l[i], +d[i]));
			uf.UniteCategory(l[i], r[i]);
		}
		for (var i = 0; i < N; i++) if (!done[uf.GetRootOf(i)] && !DFS(uf.GetRootOf(i), 0)) return false;
		return true;
	}
	bool DFS(int u, int y)
	{
		if (done[u])
		{
			if (x[u] != y) return false;
			return true;
		}
		x[u] = y;
		done[u] = true;
		foreach (var v in g[u]) if (!DFS(v.To, x[u] - v.D)) return false;
		return true;
	}
}
// x[i] - x[to] = d
struct Edge
{
	public readonly int To, D;
	public Edge(int t, int d) { To = t; D = d; }
}
class UnionFindTree
{
	int N;
	int[] parent, rank, size;
	public UnionFindTree(int capacity)
	{
		N = capacity;
		parent = new int[N];
		rank = new int[N];
		size = new int[N];
		for (var i = 0; i < N; i++) { parent[i] = i; size[i] = 1; }
	}
	public int GetSize(int x) => size[GetRootOf(x)];
	public int GetRootOf(int x) => parent[x] == x ? x : parent[x] = GetRootOf(parent[x]);
	public bool UniteCategory(int x, int y)
	{
		if ((x = GetRootOf(x)) == (y = GetRootOf(y))) return false;
		if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; }
		else
		{
			parent[y] = x; size[x] += size[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
		return true;
	}
	public bool IsSameCategory(int x, int y) => GetRootOf(x) == GetRootOf(y);
}


Measured memory_bytes: 42768
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B, H, M = get_ints

hour_angle_one = 360 / 12.0
hour_angle_minute_one = hour_angle_one / 60.0
minute_angle_one = 360 / 60.0

hour_angle = H * hour_angle_one + M * hour_angle_minute_one
minute_angle = M * minute_angle_one

PI = Math::PI

def rad(x)
  x / 180.0 * PI
end

length = Math.sqrt(A**2 + B**2 - 2 * A * B * Math.cos(rad(hour_angle - minute_angle)))
puts length


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

using namespace std;

using ll = long long;

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

    vector<int> h(n);
    for (auto &&x: h) cin >> x;

    int num = 0, l = 0;
    while (l < n) {
        while (l < n && h[l] == 0) ++l;
        if (l == n) break;

        int min_h = 10000, r = l;
        while (r < n && h[r] != 0)
            min_h = min(min_h, h[r++]);

        num += min_h;
        for (int i = l; i < r; ++i) h[i] -= min_h;
    }

    return num;
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 256
"""
実験のためにkobaya0514様のコードをいじくらせていただいております
"""

N = int(input())
A = [int(x) for x in input().split()]
# 重複始点終点調査
se = []
c = sum(A) - N * (N + 1) / 2
for i in range(len(A)):
    if A[i] == c:
        se.append(i)
l = se[0]
r = se[1]

mod = 10 ** 9 + 7

# 階乗計算
factorial = [1]
inverse = [1]
for i in range(1, N + 2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append((pow(factorial[-1], mod - 2, mod)))


# combination計算
def nCr(n, r):
    if n < r or n == 0 or r == 0:
        return 0
    return factorial[n] * inverse[r] * inverse[n - r] % mod


print(N)
for i in range(2, N + 2):
    print(int(nCr(N + 1, i) - nCr(l + N - r, i - 1)) % mod)

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int H, W;
string s[50];
bool went[50][50];

int bfs() {
	queue<Pi> que;
	que.push(Pi(P(0, 0), 1));
	while (!que.empty()) {
		Pi p = que.front(); que.pop();
		if (p.first.first == H - 1 && p.first.second == W - 1) return p.second;
		rep(i, 4) {
			int nx = p.first.second + dx[i], ny = p.first.first + dy[i];
			if (nx < 0 || nx >= W || ny < 0 || ny >= H || went[ny][nx] || s[ny][nx] == '#') continue;
			went[ny][nx] = true;
			que.push(Pi(P(ny, nx), p.second + 1));
		}
	}
}

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

	cin >> H >> W;
	rep(i, H) cin >> s[i];
	int black = 0;
	rep(i, H) rep(j, W) if (s[i][j] == '#') ++black;
	int res = bfs();
	if(went[H - 1][W - 1]) cout << H * W - black - res << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
/*  CREATED BY
    STREAM_CIPHER
    07-sep-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        int ten=1,nine=1,eight=1;
        for(int i=1;i<=n;i++)
        {
        	ten*=10,ten%=mod;
        	nine*=9,nine%=mod;
        	eight*=8,eight%=mod;
        }
        cout<<(ten%mod-nine%mod+mod-nine%mod+eight+mod)%mod;
}

Measured memory_bytes: 3644
H, W = map(int, input().split())
S = [input() for _ in range(H)]
 
f = False
for h in range(H):
  pre = '.'
  now = S[h][0]
  nxt = S[h][1]
  abv = '.' if h == 0 else S[h-1][0]
  blw = '.' if h == H-1 else S[h+1][0]
  for w in range(W):
    if now == '.':
      f = False
    elif now in [pre, nxt, abv, blw]:
      f = False
    else:
      f = True
    
    pre = now
    now = nxt
    nxt = '.' if w == W-1 else S[h][w+1]
    abv = '.' if h == 0 else S[h-1][w]
    blw = '.' if h == H-1 else S[h+1][w]
    
    if f:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 9092
#include<stdio.h>

int main(){
  int a[100],flag,j,n,cnt=0,temp;

  scanf("%d",&n);

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

  flag=1;

  while(flag){
    flag=0;
    for(j=n-1;j>0;j--){
      if(a[j]<a[j-1]){
	temp=a[j];
	a[j]=a[j-1];
	a[j-1]=temp;
	flag=1;
	cnt++;
      }
    }
  }
      
  for(j=0;j<n;j++){
    printf("%d",a[j]);
    if(j!=n-1)printf(" ");
  }

  printf("\n%d\n",cnt);

  return 0;
}
  
  



Measured memory_bytes: 2108
#include <stdio.h>

int main(void) {
	int a,b,c;
	int ans; 
	scanf("%d %d %d",&a,&b,&c);
	ans = a*b;
	if(ans <c){
	    printf("%d",ans);
	}else{
	    printf("%d",c);
	}
	return 0;
}



Measured memory_bytes: 128
#include<iostream>
using namespace std;
  
bool isP(int x){
  if(x==0||x==1)return false;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)return false;
  }
  return true;
}
  
int main(){
  int n,a,cnt=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    cnt+=isP(a);
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3080
# 2019-11-28 00:55:58(JST)
import sys
def main():
    s = sys.stdin.readline().rstrip()

    t = 'keyence'

    for i in range(8):
        if t[:i] == s[:i] and t[i:] == s[len(s)-7+i:len(s)]:
            ans = 'YES'
            break
    else:
        ans = 'NO'

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.*;

public class Main {

	public static Scanner scan = new Scanner(System.in);
  	public static void main(String[] args) {
    
      String s = scan.next();
      String t = scan.next();
      
      int count = 0;
      
      for(int i=0; i<s.length(); i++) {
      
        if(s.charAt(i) != t.charAt(i))
          count++;
      
      }
      
      System.out.println(count);
      
    }
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int w,a,b;
    cin >> w >> a >> b;
    if(abs(a-b)<=w){
    	cout << 0;
    	return 0;
    }

    cout << abs(a-b)-w << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	vector<int> xy(4);
	for (int i = 0; i < 4; i++) cin >> xy[i];

	cout << xy[2] - (xy[3] - xy[1]) << " " << xy[3] + (xy[2] - xy[0]) << " ";
	cout << xy[0] - (xy[3] - xy[1]) << " " << xy[1] + (xy[2] - xy[0]) << "\n";

	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getMaxEffectiveBit(ull a)
{
	ll index = -1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

inline ll getSpecifiedBit(ull a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}


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

	ll N, M;
	cin >> N >> M;

	vector<tuple<ll, ll, ll>> xyzs;
	xyzs.reserve(N);
	ll x, y, z;
	for (ll i = 0; i < N; ++i)
	{
		cin >> x >> y >> z;
		xyzs.emplace_back(x, y, z);
	}

	ll all_res = -0x7FFFFFFFFFFFFFFFLL;
	for (ll coef = 0; coef < (1LL << 3); ++coef)
	{
		ll coef_x, coef_y, coef_z;
		coef_x = ( (coef >> 0) & 1 ) * 2 - 1;
		coef_y = ((coef >> 1) & 1) * 2 - 1;
		coef_z = ((coef >> 2) & 1) * 2 - 1;
		auto comp = [&](const tuple<ll, ll, ll>& a, const tuple<ll, ll, ll>& b)
		{
			auto val_a = get<0>(a) * coef_x + get<1>(a) * coef_y + get<2>(a) * coef_z;
			auto val_b = get<0>(b) * coef_x + get<1>(b) * coef_y + get<2>(b) * coef_z;
			return val_a > val_b;
		};
		sort(xyzs.begin(), xyzs.end(), comp);
		ll res = 0;
		for (ll i = 0; i < M; ++i)
		{
			res += get<0>(xyzs[i]) * coef_x + get<1>(xyzs[i]) * coef_y + get<2>(xyzs[i]) * coef_z;
		}
		all_res = max(all_res, res);
	}

	cout << all_res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    cout << n / 3 << endl;

    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>

int main(void)
{
 int a,b,c[7],d;
 for(d=0;d<7;d++){
    scanf("%d %d",&a,&b);
    c[d]=a-b;
 }
 for(d=0;d<7;d++){
    printf("%d\n",c[d]);
 }
	return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
 
int main(){
  ll a,b,k,aa;
  cin>>a>>b>>k;
  aa=max(0ll,a-k);
  k=max(0ll,k-a);
  b=max(0ll,b-k);
  cout<<aa<<" "<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, cnt = 0;
	cin >> n;
	char s[n + 1];
	cin >> s;
	for(int i = 2 ; i < n ; i++)
		cnt += (s[i] == 'C' && s[i - 1] == 'B' && s[i - 2] == 'A');
	cout << cnt << '\n';
	return 0;
}

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

typedef struct List {
	struct List *next;
	int id;
} list;

int main()
{
	int i, N, M, K, A[100001], B[100001], C[100001], D[100001];
	scanf("%d %d %d", &N, &M, &K);
	for (i = 1; i <= M; i++) scanf("%d %d", &(A[i]), &(B[i]));
	for (i = 1; i <= K; i++) scanf("%d %d", &(C[i]), &(D[i]));
	
	list *friend[100001] = {}, *block[100001] = {}, data[400001];
	for (i = 1; i <= M; i++) {
		data[(i-1)*2].id = A[i];
		data[(i-1)*2+1].id = B[i];
		data[(i-1)*2].next = friend[B[i]];
		data[(i-1)*2+1].next = friend[A[i]];
		friend[B[i]] = &(data[(i-1)*2]);
		friend[A[i]] = &(data[(i-1)*2+1]);
	}
	for (i = 1; i <= K; i++) {
		data[(M+i-1)*2].id = C[i];
		data[(M+i-1)*2+1].id = D[i];
		data[(M+i-1)*2].next = block[D[i]];
		data[(M+i-1)*2+1].next = block[C[i]];
		block[D[i]] = &(data[(M+i-1)*2]);
		block[C[i]] = &(data[(M+i-1)*2+1]);
	}
	
	list *p, *head, *tail, person[100001];
	int suggest[100001] = {}, flag[100001] = {}, count;
	for (i = 1; i <= N; i++) {
		if (flag[i] != 0) continue;
		flag[i] = 1;
		person[i].id = i;
		for (head = &(person[i]), tail = &(person[i]), count = 0; head != NULL; head = head->next) {
			for (p = friend[head->id]; p != NULL; p = p->next) {
				if (flag[p->id] == 0) {
					flag[p->id] = 1;
					count++;
					person[p->id].id = p->id;
					tail->next = &(person[p->id]);
					tail = tail->next;
				}
			}
		}
		for (head = &(person[i]); head != NULL; head = head->next) {
			suggest[head->id] = count;
			for (p = friend[head->id]; p != NULL; p = p->next) suggest[head->id]--;
			for (p = block[head->id]; p != NULL; p = p->next) if (flag[p->id] == 1) suggest[head->id]--;
		}
		for (head = &(person[i]); head != NULL; head = head->next) flag[head->id] = -1;
	}
	
	for (i = 1; i <= N; i++) printf("%d ", suggest[i]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 12416
#include <cstdio>
#include <cctype>
#include <cstring>
#include <queue>
const int MX = 0x3f3f3f3f, MN = 0x9f9f9f9f;
using namespace std;
const int N = 100005, M = 200005;
int to[M], nt[M], hd[N], tot = 0;
int lb[N], rb[N], fa[N], dep[N], ord[N], cnt = 0;
int type[N];
bool have_result = true;

inline void in(int &x){
    register char ch;
    x = 0;
    while(isspace(ch = getchar()));
    do x = x * 10 + ch - '0'; while(isdigit(ch = getchar()));
}
char _stk[50];
int _top = 0;
void out(int x){
    while(x != 0) _stk[++_top] = x % 10, x /= 10;
    while(_top != 0) putchar(_stk[_top--] + '0');
}
inline void addedge(int x, int y){
    ++tot;
    to[tot] = y; nt[tot] = hd[x]; hd[x] = tot;
}

void bfs(){
    queue<int> q;
    q.push(1);
    fa[1] = 1; dep[1] = 0;
    int x;
    while(!q.empty()){
        x = q.front(); q.pop();
        // printf("bfs %d\n", x);
        ord[++cnt] = x;
        for(int i=hd[x]; i; i=nt[i]){
            if(to[i] != fa[x]){
                fa[to[i]] = x;
                dep[to[i]] = dep[x] + 1;
                if(type[to[i]] == type[x] && type[x] != 0x01010101) have_result = false;
                if(type[x] != 0x01010101) type[to[i]] = type[x] ^ 1;
                // printf("lb[x] = %d rb[x] = %d\n", lb[x], rb[x]);
                if(lb[x] != MN) lb[to[i]] = max(lb[to[i]], lb[x] - 1);
                if(rb[x] != MX) rb[to[i]] = min(rb[to[i]], rb[x] + 1);
                q.push(to[i]);
            }
        }
    }
}

int main(){
    // freopen("at2148.in", "r", stdin);
    // freopen("at2148.out", "w", stdout);
    int n, k, x, y;
    in(n);
    for(int i=1; i<n; i++){
        in(x); in(y);
        addedge(x, y); addedge(y, x);
    }
    memset(lb, 0x9f, sizeof lb); memset(rb, 0x3f, sizeof rb);
    memset(type, 0x01, sizeof type);
    in(k);
    for(int i=1; i<=k; i++){
        in(x); in(y);
        lb[x] = y; rb[x] = y;
        type[x] = y & 1;
    }
    bfs();
    for(int i=n; i>=2; i--){
        if(lb[ord[i]] != MN){
            if(type[ord[i]] == type[fa[ord[i]]] && type[ord[i]] != 0x01010101) have_result = false;
			lb[fa[ord[i]]] = max(lb[fa[ord[i]]], lb[ord[i]] - 1);
		}
        if(rb[ord[i]] != MX){
            if(type[ord[i]] == type[fa[ord[i]]] && type[ord[i]] != 0x01010101) have_result = false;
			rb[fa[ord[i]]] = min(rb[fa[ord[i]]], rb[ord[i]] + 1);
		}
    }
    cnt = 0;
    bfs();
    bool flag = false;
    for(int i=1; i<=n; i++){
        // printf("i = %d [%d, %d]\n", i, lb[i], rb[i]);
        if(lb[i] > rb[i]){
            flag = true;
            break;
        }
    }
    if(flag || !have_result) puts("No");
    else{
        puts("Yes");
        for(int i=1; i<=n; i++)
            printf("%d\n", lb[i]);
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 5384
k, n = map(int,input().split())
p = list(map(int, input().split()))
l = []

for i in range(n-1):
  a = p[i+1]-p[i]
  x = min(a, k-a)
  l.append(x)
l.append(k-p[-1]+p[0])
  
print(k-max(l))

Measured memory_bytes: 86140
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n'); // read all data first.

  var N = parseInt(lines.shift());
  var data = [];
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    for (var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      var line = _step.value;

      var _splitNum = splitNum(line),
          _splitNum2 = _slicedToArray(_splitNum, 3),
          x = _splitNum2[0],
          y = _splitNum2[1],
          h = _splitNum2[2];

      data.push({
        x,
        y,
        h
      });
    } // check for all possible (Cx, Cy).

  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator.return != null) {
        _iterator.return();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }

  for (var cx = 0; cx <= 100; cx++) {
    check: for (var cy = 0; cy <= 100; cy++) {
      var ph = null;

      for (var _i = 0; _i < data.length; _i++) {
        var _data$_i = data[_i],
            x = _data$_i.x,
            y = _data$_i.y,
            h = _data$_i.h;
        // distance from the center.
        var d = Math.abs(x - cx) + Math.abs(y - cy);

        if (h >= 1) {
          // if not saturated...
          var phc = h + d;

          if (ph == null) {
            ph = phc;
          } else if (ph !== phc) {
            // conflict
            continue check;
          }
        }
      } // check for other data.


      for (var _i2 = 0; _i2 < data.length; _i2++) {
        var _data$_i2 = data[_i2],
            x = _data$_i2.x,
            y = _data$_i2.y,
            h = _data$_i2.h;

        var _d = Math.abs(x - cx) + Math.abs(y - cy);

        if (h === 0) {
          if (ph - _d > 0) {
            // conflict
            continue check;
          }
        }
      } // complete!


      console.log(`${cx} ${cy} ${ph}`);
      return;
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 10188
S = input()
N = len(S)
mod = 10**9+7
dp = [[0] * N for _ in range(13)]

if S[0] == "?":
    for i in range(10):
        dp[i][0] = 1
else:
    dp[int(S[0])][0] = 1
        
for i in range(1, N):
    if S[i] == "?":
        for s in range(10):
            for x in range(13):
                dp[(x*10 + s)%13][i] += dp[x][i-1]
    else:
        for x in range(13):
            dp[(x*10 + int(S[i]))%13][i] += dp[x][i-1] 
    for t in range(13):
        dp[t][i] = dp[t][i]%mod
print(dp[5][N-1])  

Measured memory_bytes: 53100
#include <stdio.h>
#include <stack>
#include <vector>

using namespace std;

//FILE *in = freopen("input.txt", "r", stdin);
//FILE *out = freopen("output.txt", "w", stdout);

int n, m;
char str1[1000];

int ind[15][3];
int indent[15];

int rind[15][3];

int res[15];

int R, C, S;

void input() {
	for(int i = 0; i < m; i++) {
		res[i] = -2;
	}
	
	ind[0][0] = ind[0][1] = ind[0][2] = 0;
	for(int i = 0; i < n; i++) {
		gets(str1);
		int cnt = 0;
		int j;
		for(j = 0; str1[j]; j++) {
			if(str1[j] == '.') {
				++cnt;
			}
			else
				break;
		}
		indent[i] = cnt;
		for(;str1[j];j++) {
			switch(str1[j]) {
			case '(':
				++ind[i][0];
				break;
			case '{':
				++ind[i][1];
				break;
			case '[':
				++ind[i][2];
				break;
			case ')':
				--ind[i][0];
				break;
			case '}':
				--ind[i][1];
				break;
			case ']' :
				--ind[i][2];
				break;
			}
		}
		ind[i+1][0] = ind[i][0];
		ind[i+1][1] = ind[i][1];
		ind[i+1][2] = ind[i][2];
	}

	rind[0][0] = rind[0][1] = rind[0][2] = 0;
	for(int i = 0; i < m; i++) {
		gets(str1);
		for(int j = 0; str1[j]; j++) {
			switch(str1[j]) {
			case '(':
				++rind[i][0];
				break;
			case '{':
				++rind[i][1];
				break;
			case '[':
				++rind[i][2];
				break;
			case ')':
				--rind[i][0];
				break;
			case '}':
				--rind[i][1];
				break;
			case ']' :
				--rind[i][2];
				break;
			}
		}
		rind[i+1][0] = rind[i][0];
		rind[i+1][1] = rind[i][1];
		rind[i+1][2] = rind[i][2];
	}
}

void process2() {
	for(int i = 0; i < m - 1; i++) {
		int r = R*rind[i][0];
		int c = C*rind[i][1];
		int s = S*rind[i][2];

		if(r < 0 || c < 0 || s < 0) {
			res[i] = -1;
		}
		else {
			if(res[i] != -2 && res[i] != r + c + s) {
				res[i] = -1;
			}
			else {
				res[i] = r + c + s;
			}
		}
	}
}

void process() {
	bool rf = false, cf = false, sf = false;
	for(int i = 0; i < n - 1; i++) {
		if(ind[i][0])rf = true;
		if(ind[i][1])cf = true;
		if(ind[i][2])sf = true;
	}
	for(R = rf ? 1 : -1; R <= 20; R++) {
		if(R == 0) continue;
		for(C = cf ? 1 : -1; C <= 20; C++) {
			if(C == 0) continue;
			for(S = sf ? 1 : -1; S <= 20; S++) {
				if(S == 0) continue;
				int i;
				for(i = 0 ; i < n - 1; i++) {
					if(indent[i+1] != R*ind[i][0] + C*ind[i][1] + S*ind[i][2])
						break;
				}
				if(i == n - 1) {
					process2();
				}
			}
		}
	}
}

void output() {
	printf("0");
	for(int i = 0; i < m - 1; i++) {
		printf(" %d", res[i]);
	}
	printf("\n");
}

int main() {
	while(true){
		scanf("%d%d\n", &n, &m);
		if (n == 0 && m == 0) break;
		R = -1;
		C = -1;
		S = -1;
		input();
		process();
		output();
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,f[60][60],c[60][60];
void add(int&x,int y){x=(x+y)%mod;}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<=n;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	f[1][0]=f[1][1]=1;
	for(int i=1;i<n;i++)
	for(int j=0;j<=i;j++)
	if(f[i][j])
	for(int x=0;x+i<=n;x++)
	for(int y=max(1,j)-x;x+y+i<=n;y++)
	if((x+y-j)%2==0)
	add(f[i+x+y][abs(j+(x+y-j)/2-x)],1ll*f[i][j]*c[i+x+y][x+y]%mod*c[x+y][x]%mod);
	printf("%d",f[n][0]);
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <iomanip>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt = 0;
    REP(i, 0, n) {
        cnt += (i + 1) % 2;
    }
    cout << fixed << setprecision(10) << (double)cnt / n << endl;

    return 0;
}


Measured memory_bytes: 256