akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int l=s.length();
  for(int i=1;i<l+1;++i) {
    if(i%2==0) {
      if(s[i-1]=='R') {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      if(s[i-1]=='L') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int a[] = new int[N];
    int odd = 0;
    int four = 0;
    for(int i=0; i<N; i++){
      a[i] = sc.nextInt();
      if(a[i] % 2 == 1) odd++;
      if(a[i] % 4 == 0) four++;
    }
    boolean check = false;
    if(four >= odd) check = true;
    else if(odd - four == 1 && odd + four == N) check = true;
    if(check) out.println("Yes");
    else out.println("No");    
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 24168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
    // input keybord
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int input = Integer.parseInt(br.readLine());
    
    // for output
    StringBuilder output = new StringBuilder();

    // hour
    int calcRes = input / 3600;
    output.append(calcRes + ":");
    
    // minitues
    input %= 3600;
    calcRes = input/60;
    output.append(calcRes + ":");
    
    // second
    input %= 60;
    output.append(input);

    System.out.println(output);
  }
}

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

using namespace std;

typedef long long ll;

inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int a[2020202];
int f[2020202];

struct node{
	int mx,l,r;
}t[4040404];

void build(int p,int l,int r){
	t[p].l=l;t[p].r=r;
	if(l==r){
		t[p].mx=0;
		return ;
	}
	int mid=l+r>>1;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
}

void add(int p,int x,int v){
	if(t[p].l==t[p].r){
		t[p].mx=v;
		return ;
	}
	int mid=t[p].l+t[p].r>>1;
	if(x<=mid) add(p*2,x,v);
	else add(p*2+1,x,v);
	t[p].mx=max(t[p*2].mx,t[p*2+1].mx);
}

int qmax(int p,int l,int r){
	if(l<=t[p].l && t[p].r<=r){
		return t[p].mx;
	}
	int mid=t[p].l+t[p].r>>1;
	int ans=0;
	if(l<=mid) ans=max(ans,qmax(p*2,l,r));
	if(r>mid) ans=max(ans,qmax(p*2+1,l,r)); 
	return ans;
}

int main(){
	int n=read(),k=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	int maxx=0;
	build(1,1,1000000);
	for(int i=1;i<=n;i++){
		f[i]=qmax(1,max(1,a[i]-k),a[i]+k)+1;
		add(1,a[i],f[i]);
		maxx=max(maxx,f[i]);
	}
	cout<<maxx<<endl;
	return 0;
}


Measured memory_bytes: 30564
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define INF 21474836
#define NINF -21474836

vector<int> minvalue;
vector<int> maxvalue;
int N;

int minquery(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return INF;
  if (a <= l && r <= b) return minvalue.at(k);
  else{
    int c1 = minquery(a, b, 2 * k + 1, l, (l + r) / 2);
    int c2 = minquery(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(c1, c2);
  }
}

int maxquery(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return NINF;
  if (a <= l && r <= b) return maxvalue.at(k);
  else{
    int c1 = maxquery(a, b, 2 * k + 1, l, (l + r) / 2);
    int c2 = maxquery(a, b, 2 * k + 2, (l + r) / 2, r);
    return max(c1, c2);
  }
}

void update(int i, int x) {
  i += N - 1;
  minvalue.at(i) = x;
  maxvalue.at(i) = x;
  while (i > 0) {
    i = (i - 1) / 2;
    minvalue.at(i) = min(minvalue[i * 2 + 1],minvalue[i * 2 + 2]);
    maxvalue.at(i) = max(maxvalue[i * 2 + 1],maxvalue[i * 2 + 2]);
  }
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  set<int> s;
  rep(i,n){
    cin >> p.at(i);
  }
  int count = 0;
  for(int i=1;i<n;i++){
    if(p.at(i) > p.at(i-1)){
      count++;
    }else{
      count = 0;
    }
    if(count >= k-1){
      //cout << i << endl;
      s.insert(i);
    }
  }
  N = 1;
  while(N < n) N *= 2;
  minvalue = vector<int>(2 * N - 1, INF);
  maxvalue = vector<int>(2 * N - 1, NINF);
  rep(i,n){
    update(i,p.at(i));
  }
  
  //rep(i,minvalue.size()) cout << minvalue.at(i) << endl;
  //cout << endl;
  //rep(i,maxvalue.size()) cout << maxvalue.at(i) << endl;
  
  int ans = 0;
  int alreadysort = false;
  rep(i,n-k+1){
    int j = i+k-1;
    if(s.count(j)){
      if(alreadysort) continue;
      ans++;
      alreadysort = true;
      continue;
    }
    if(i == 0){
      ans++;
      continue;
    }
    int mini = minquery(i-1,j,0,0,N);
    int maxi = maxquery(i,j+1,0,0,N);
    //cout << mini << " " << maxi << endl;
    if(mini == p.at(i-1) && maxi == p.at(j)) continue;
    ans++;
  }
  cout << ans << endl;
}

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

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

ll gcd(ll x, ll y) { return y? gcd(y,x%y) : x;}

vector<pair<ll,int>> factorize(ll n){
	vector<pair<ll,int>> res;
  	for(ll i = 2; i*i <= n; ++i) {
    	if(n%i) continue;
      	res.emplace_back(i,0);
      	while(n%i == 0){
        	n/= i;
          	res.back().second++;
        }
    }
  	if(n != 1) res.emplace_back(n,1);
  	return res;
}
  
int main(){
	ll a,b;
 	 cin >> a >> b;
  	ll g = gcd(a,b);
 	auto f = factorize(g);
  	int ans = f.size() + 1;
   cout << ans << endl;
  return 0;
}

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

void draw(int H, int W) {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if ((i + j) % 2 == 0) {
                cout << "#";
            } else {
                cout << ".";
            }
        }
        cout << endl;
    }
    cout << endl;
}

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

    int H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        } else {
            draw(H, W);
        }
    }
}


Measured memory_bytes: 3132
private fun readLineStrings(): List<String> = readLine()!!.split(" ")
private fun readLineInts(): List<Int> = readLineStrings().map { it.toInt() }

private fun List<Int>.firstLineCumulativeCandy(): List<Int> {
    var tempSum = 0
    return this.map {
        tempSum += it
        tempSum
    }
}

private fun List<Int>.nextLineCumulativeCandy(nextLine: List<Int>): List<Int> {
    var leftWiseMax = this.first()
    return nextLine.mapIndexed { idx, p ->
        leftWiseMax = listOf(leftWiseMax, this[idx]).max()!! + p
        leftWiseMax
    }
}


fun main(args: Array<String>) {
    val N = readLineInts()[0]
    val A = readLineInts()
    val B = readLineInts()

    println(A.firstLineCumulativeCandy().nextLineCumulativeCandy(B).last())
}

Measured memory_bytes: 35980
n = int(input())
ans = [0]*4
for i in range(n):
    s = input()
    if s=='AC':
        ans[0]+=1
    elif s=='WA':
        ans[1]+=1
    elif s=='TLE':
        ans[2]+=1
    else:
        ans[3]+=1
print('AC x {0}'.format(ans[0]))
print('WA x {0}'.format(ans[1]))
print('TLE x {0}'.format(ans[2]))
print('RE x {0}'.format(ans[3]))

Measured memory_bytes: 9208
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

#define eval() (x * x + y * y + z * z + x * y + y * z + z * x)

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

    auto cnt = vector<int>(1'000'005);
    for (auto x = 1LL; x <= 100; ++x) {
        for (auto y = 1LL; y <= 100; ++y) {
            for (auto z = 1LL; z <= 100; ++z) {
                auto k = eval();
                cnt[k]++;
            }
        }
    }

    auto a = string{};
    for (auto k = 1; k <= n; ++k) {
        a += to_string(cnt[k]) + "\n";
    }

    cout << a;
    return 0;
}


Measured memory_bytes: 7248
#include <stdio.h>

int main(){
  int x, y, z;
  scanf("%d%d", &x, &y);
  while(z!=0){
    z = x % y;
    if(z==0){
      printf("%d\n", y);
      break;
    }
    x = y;
    y = z;
  }
  return 0;
}



Measured memory_bytes: 2124
module Main where

import Control.Applicative
import Numeric
import Data.Char

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [n] <- getIntegers
  ; if n == 0 then return ()
    else do
      {print (sum(map digitToInt (show n)))
      ; loop
      }
  }
  
--
getIntegers :: IO [Integer]
getIntegers = map read . words <$> getLine

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords .  map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""


Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,d;
    cin>>n>>d;
    vector<vector<int>> x(n,vector<int>(d));
    for (int i = 0; i < n; i++)
    {   
        for (int k = 0; k < d; k++){
            cin>>x[i][k];
        }
    }
    int ans = 0;
    for (int i = 0; i < n-1; i++){  
        for (int j = i+1; j < n; j++){
            double normsq = 0; 
            for (int k = 0; k < d; k++){
                normsq += pow(x[i][k] - x[j][k],2);
            }
            normsq = sqrt(normsq);
            if(normsq - floor(normsq) < 0.0001){ 
                ans++;
            }
        }
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
        while(i+1<n&&a[i+1]==a[i]) i++;
        if(i+1<n&&a[i+1]>a[i]){
            while(i+1<n&&a[i+1]>=a[i]) i++;
        }else if(i+1<n&&a[i+1]<a[i]){
            while(i+1<n&&a[i+1]<=a[i]) i++;
        }
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3988
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

map<pair<string,string>,int> M;
char s[40];
int main() {
	int n;
	scanf("%d%s",&n,s);
	fup(k,0,(1<<n)-1,1)
	{
		string r,b;
		fup(i,0,n-1,1)
			if(k&(1<<i))r+=s[i];
		fdn(i,n-1,0,1)
			if(!(k&(1<<i)))b+=s[i];
		M[mp(r,b)]++;
	}
	ll ans=0;
	fup(k,0,(1<<n)-1,1)
	{
		string r,b;
		fup(i,0,n-1,1)
			if(k&(1<<i))b+=s[i+n];
		fdn(i,n-1,0,1)
			if(!(k&(1<<i)))r+=s[i+n];
		ans+=M[mp(r,b)];
	}
	printf("%lld",ans);
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

int n;
string s;

int main(){
	cin >> n;
	cin >> s;
	
	int c = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'E') c++;
	}
	int ans = c;
	for(int i = 0; i < n; i++){
		if(s[i] == 'E'){
			c--;
		}
		else{
			c++;
		}
		ans = min(ans, c);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int N, K;
double P[200005];

int main(){
    cin >> N >> K;
    vector<pair<pair<double,int>,pair<int,int>>> gds(N,make_pair(make_pair(0.0,0),make_pair(0,0)));
    FOR(i,1,N+1)
    {
        double p;
        cin >> p;
        P[i]=P[i-1]+(((p+1)*p)/2)/p;
    }
    double ans=0;
    FOR(i,K,N+1)
    {
        if(ans<P[i]-P[i-K])ans=P[i]-P[i-K];
    }
    cout << fixed << setprecision(7) << ans << endl;
    return 0;
}

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

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

using namespace std;

map<string,int> atoms;

tuple<int, int> num(const string& s, int i) {
  int v = 0;
  int n = s.size();
  for(;i<n;++i) {
    if (s[i] < '0' || '9' < s[i]) break;
    v *= 10;
    v += s[i] - '0';
  }
  return make_tuple(v, i);
}

tuple<int,int> atom(const string& s, int i) {
  string name;
  if ('a' <= s[i+1] && s[i+1] <= 'z') name = s.substr(i, 2);
  else name = s.substr(i,1);
  //cout<<name<<endl;
  if (atoms.find(name) == end(atoms)) return make_tuple(-1, i + name.size());
  return make_tuple(atoms[name], i + name.size());
}

tuple<int,int> atomss(const string& s, int i) {
  int w, e;
  tie(w, e) = atom(s, i);
  if ('0' <= s[e] && s[e] <= '9') {
    int t, te;
    tie(t, te) = num(s, e);
    if (w == -1) return make_tuple(-1, te);
    return make_tuple(w * t, te);
  }
  return make_tuple(w, e);
}

tuple<int,int> calc(const string& s, int i = 0) {
  int w, e;
  if (s[i] == '(') {
    int iw, ni;
    tie(iw, ni) = calc(s, i+1);
    int tm;
    tie(tm, e) = num(s, ni+1);
    if (iw == -1) w = -1;
    w = iw * tm;
  } else {
    tie(w, e) = atomss(s, i);
  }
  if (e != s.size() && s[e] != ')') {
    int tailw, taile;
    tie(tailw, taile) = calc(s, e);
    if (w == -1 || tailw == -1) return make_tuple(-1, taile);
    return make_tuple(tailw + w, taile);
  }
  if (w == -1) return make_tuple(-1, e);
  return make_tuple(w, e);
}

int main() {
  while(1){
    string atm;
    cin>>atm;
    if(atm == "END_OF_FIRST_PART") break;
    int w;
    cin>>w;
    atoms[atm] = w;
  }
  while(1) {
    string mol;
    cin>>mol;
    if(mol == "0") break;
    auto p = calc(mol);
    if (get<0>(p) != -1)
      cout<<get<0>(p)<<endl;
    else
      cout<<"UNKNOWN"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    
    int i, j, N, flag_r, flag_w, count;
    cin >> N;
  vector< long long int > L( N, 0 );
    flag_r = 0;
    flag_w = 0;
    count = 0;

    string S;
    cin >> S;
    
    for (i = 0; i < N; i++){
        if (S.at(i) == 'R'){
            L[i] = 1;
            flag_r = 1;
            
        } else {
            L[i] = 0;
            flag_w = 1;
        }
    }
        
    if (flag_r == 0 || flag_w == 0){
        cout << "0" << "\n";
        return 0;
    }
    
    i = 0;
    j = N - 1;
    
    while(1){
        
        while(L[i] == 1){
            i++;
        }

        while(L[j] == 0){
            j--;
        }
        
        if (i > j) break;
        
        L[i] = 1;
        L[j] = 0;
        count++;
    }
    
    cout << count << "\n";

    return 0;
}



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

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

Measured memory_bytes: 1168
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 下、右、上、左、右下、右上、左下、左上


def dfs8(y, x):
    dy = [1, 0, -1, 0, 1, -1, 1, -1]
    dx = [0, 1, 0, -1, 1, 1, -1, -1]
    cnt = 0
    for k in range(8):
        ny = y + dy[k]
        nx = x + dx[k]
        if ny < 0 or H <= ny or nx < 0 or W <= nx:
            continue
        if field[ny][nx] == '#':
            cnt += 1
    return str(cnt)


H, W = map(int, readline().split())
field = [list(readline().decode())for _ in range(H)]
for y in range(H):
    for x in range(W):
        if field[y][x] != '#':
            field[y][x] = dfs8(y, x)
    print("".join(field[y]))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define MAXN 262144
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int c[MAXN+5], h[MAXN+5], n, _; vector<int> e[MAXN+5];
int DP(int p, int fa){int U = 0, S = 0; for(auto v:e[p]) if(v^fa) _ = DP(v,p), S |= _&U, U |= _; for(_ = h[S]; U&1<<_; ++_); return U>>_<<_|1<<_;}
int main()
{
	n = read(); for(rint i = 2, a, b; i <= n; a = read(), b = read(), e[a].push_back(b), e[b].push_back(a), i++);
	c[1] = 1; for(rint i = 2; i <= MAXN; c[i] = -~c[i-(i&-i)], h[i] = -~h[i>>1], i++); return !printf("%d\n",h[DP(1,0)]);
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N;
LL dfs(int& i, int lv, VS& vs){
  if(vs[i][lv] == '+'){
	LL res = 0;
	++i;
	while(i<N && SZ(vs[i]) > lv && vs[i][lv] == '.')
	  res += dfs(i, lv+1, vs);
	return res;
  }
  else if(vs[i][lv] == '*'){
	LL res = 1;
	++i;
	while(i<N && SZ(vs[i]) > lv && vs[i][lv] == '.')
	  res *= dfs(i, lv+1, vs);
	return res;
  }

  return vs[i++][lv] - '0';
}

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

  while(cin>>N,N){
	VS str(N);
	REP(i,N) cin >> str[i];
	int i = 0;
	cout << dfs(i, 0, str) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3112
#a.py
lis = []
s = input()
flag = 0
two = 0
for x in s:
    if x in lis:
        flag += 1
    else:
        two += 1
    lis.append(x)
if two == 2 and  flag <= 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
using namespace std;

inline char gc() {
//	static char buf[100000],*p1,*p2;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin)),p1==p2)?EOF:*p1++;
	return getchar();
}

template<class T>
int read(T &ans) {
	ans=0;T f=1;
	char ch=gc();
	while(!isdigit(ch)) {if(ch=='-') f=-1; if(ch==EOF) return EOF; ch=gc();}
	while(isdigit(ch)) ans=ans*10+ch-'0',ch=gc();
	ans*=f;
	return 1;
}

typedef long long ll;
const int Maxn=210000;

ll n,a[Maxn],l[Maxn],r[Maxn],f[Maxn],ans=0x3f3f3f3f3f3f3f3f,b[Maxn],c[Maxn];

int main() {
//	freopen("test.in","r",stdin);
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);memcpy(c,a,sizeof(a));
	for(int i=1;i<n;i++) b[i]=a[i+1]/a[i];
	for(int i=1;i<n;i++) {
		ll sxz=b[i];b[i]=0;
		while(sxz>=4) b[i]++,sxz/=4;
	}
	b[n]=0x3f3f3f3f3f3f3f3f;
	int top=1;l[1]=r[1]=n;
	ll temp=0;
	for(int i=n-1;i>=1;i--) {
		if(a[i]<a[i+1]) {
			if(b[i]) r[++top]=i;
		}
		else
			while(a[i]>a[i+1]) {
				temp+=2*(r[top]-l[top]+1);
				a[i+1]*=4;
				b[r[top]]--;
				if(b[r[top]]==0) {
					l[top-1]=l[top];
					top--;
				}
			}
		l[top]=i;
		f[i]=temp;
	}
	temp=1;
	memcpy(a,c,sizeof(a));
	for(int i=1;i<=n;i++) a[i]*=2;
	for(int i=2;i<=n;i++) b[i]=a[i-1]/a[i];
	for(int i=2;i<=n;i++) {
		ll sxz=b[i];b[i]=0;
		while(sxz>=4) b[i]++,sxz/=4;
	}
	b[1]=0x3f3f3f3f3f3f3f3f;
	top=1;l[top]=r[top]=1;
	ans=min(f[1],f[2]+1);
	for(int i=2;i<=n;i++) {
		temp++;
		if(a[i]<a[i-1]) {
			if(b[i]) l[++top]=i;
		}
		else
			while(a[i]>a[i-1]) {
				temp+=2*(r[top]-l[top]+1);
				a[i-1]*=4;
				b[l[top]]--;
				if(b[l[top]]==0) {
					r[top-1]=r[top];
					top--;
				}
			}
		r[top]=i;
		ans=min(ans,temp+f[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
string s;
vi par;
int32_t main(){
	ios::sync_with_stdio(false);
    int n,q;
    cin>>n>>q;
    cin>>s;
    par.resize(n);
    par[0]=0;
    for(int i=1;i<=s.size();i++){
        par[i]=par[i-1];
        if(s[i]=='C' && s[i-1]=='A'){
            par[i]++;
        }
    }
    while(q--){
        int l, r;
        cin>>l>>r;
        int rans=par[r-1];
        int lans;
        if(l==1){
            lans=0;
        }
        else{
            lans=par[l-2];
            if(par[l-1]>par[l-2]){
                lans++;
            }
        }
        cout<<rans-lans<<"\n";
    }



	return 0;
}

Measured memory_bytes: 1872
n = gets.chop.to_i
al = gets.split.map(&:to_i)
bl = gets.split.map(&:to_i)
cl = gets.split.map(&:to_i)

satisfaction = 0
latest = nil

al.each do |a|
  satisfaction += bl[a - 1]
  satisfaction += cl[latest - 1] if latest && latest + 1 == a
  latest = a
end

puts satisfaction


Measured memory_bytes: 3836
#include<iostream>
#include<vector>

using namespace std;

int main()
{
  while(1){
    int hit = 0;
    int blow = 0;
    int q,a;
    cin>>q;
    cin>>a;

    if(q == 0 && a == 0){
      break;
    }

    int q2 = q;
    int a2 = a;

    vector<int> q3;
    vector<int> a3;

    //hit
    if(q2/1000 == a2/1000){
      ++hit;
    }
    q3.push_back(q2/1000);
    a3.push_back(a2/1000);
    q2 = q2 % 1000;
    a2 = a2 % 1000;

    if(q2/100 == a2/100){
      ++hit;
    }
    q3.push_back(q2/100);
    a3.push_back(a2/100);
    q2 = q2 % 100;
    a2 = a2 % 100;

    if(q2/10 == a2/10){
      ++hit;
    }
    q3.push_back(q2/10);
    a3.push_back(a2/10);
    q2 = q2 % 10;
    a2 = a2 % 10;

    if(q2 == a2){
      ++hit;
    }
    q3.push_back(q2);
    a3.push_back(a2);

    //blow
    for(int e : q3){
      for(int a : a3){
        if(e == a){
          ++blow;
          break;
        }
      }
      if(e == a){
        break; 
      }
    }

    blow = blow - hit;
    cout<<hit<<" "<<blow<<endl;
  }
  return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

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

  vector<long long> h(n);

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

  long long tmp = 0;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (i == n - 1) {
      break;
    }

    if (h[i] >= h[i+1]) {
      tmp++;
      ans = max(ans, tmp);
    } else {
      tmp = 0;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
n,m = map(int,input().split())
m = m//1000
for x in range(n+1):
    for y in range(n-x+1):
        z = n-x-y
        if 10*x+5*y+1*z == m:
            print(x,y,z)
            exit(0)
print(-1,-1,-1)

Measured memory_bytes: 3060
#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 eplus = 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;
		eplus += c;
		if( u.t > 0 ) enqueue(u);
		else{
			printf("%s %d\n",u.name, eplus);
		}
	}
	
	return 0;
}

Measured memory_bytes: 10752
#include <iostream>
#include <algorithm>
#include <cstdint>

using namespace std;

int main() {

	int64_t q, h, s, d;
	int n;

	cin >> q >> h >> s >> d >> n;

	h = std::min(h, 2 * q);
	s = std::min(s, 2 * h);
	d = std::min(d, 2 * s);

	cout << (n / 2) * d + (n % 2) * s << "\n";

	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  bool ans = false;

  rep(i,n){
    if(a[i]%2 == 1) continue;
    if(a[i]%3 != 0 && a[i]%5 != 0) ans = true;
  }

  if(ans) cout << "DENIED" << endl;
  else cout << "APPROVED" << endl;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
        int MOD = 1000000000 + 7;

        FastScanner sc = new FastScanner();
        String L = sc.nextToken();
        int N = L.length();

        long dp1[] = new long[N];
        long dp2[] = new long[N];
        dp1[0] = 1;
        dp2[0] = 2;

        for (int i=1;i<N;i++) {
            if (L.charAt(i) == '1') {
                dp1[i] = dp1[i-1] * 3 + dp2[i-1];
                dp2[i] = dp2[i-1] * 2;
            } else {
                dp1[i] = dp1[i-1] * 3;
                dp2[i] = dp2[i-1];
            }

            dp1[i] %= MOD;
            dp2[i] %= MOD;
        }

        System.out.println((dp1[N-1] + dp2[N-1]) % MOD);
    }

    public static long nCk(int n,int k,int M) {
        long ret = 1;
        int min = Math.min(k, n-k);
        for(int i=1;i<=min;i++) {
            ret = (ret * pow(i,M-2,M)) % M;
        }
        for(int i=n-min+1;i<=n;i++) {
            ret = (ret * i) % M;
        }
        return (long) ret;
    }

    public static long pow(long a,long b,int M) {
        long ret = 1;
        long tmp = a;
        while(b>0) {
            if((b&1)==1) ret = (ret * tmp) % M;
            tmp = (tmp * tmp) % M;
            b = b>>1;
        }
        return ret;
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

Measured memory_bytes: 27220
package main

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

var sc = bufio.NewScanner(os.Stdin)

const initBufSize, maxBufSize = 10000, 1000000

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	n := nextInt()
	m := nextInt()
	//丘の高さを格納
	height := make([]int, n+1)
	//良い展望台はTrue
	goodHill := make([]bool, n+1)
	for i := 1; i <= n; i++ {
		height[i] = nextInt()
		goodHill[i] = true
	}
	//道が繋がっている丘の高さを比較する
	var from, to, count int
	for i := 0; i < m; i++ {
		from = nextInt()
		to = nextInt()
		//低い方は良い展望台ではない。同じ高さの場合はどちらも良い展望台ではない。
		if height[from] < height[to] && goodHill[from] {
			goodHill[from] = false
		} else if height[from] > height[to] && goodHill[to] {
			goodHill[to] = false
		} else if height[from] == height[to] {
			if goodHill[from] {
				goodHill[from] = false
			}
			if goodHill[to] {
				goodHill[to] = false
			}
		}
	}
	for i := range goodHill {
		if goodHill[i] {
			count++
		}
	}
	fmt.Println(count)
}


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

using namespace std;
int b[20],a[20][20];
int main(){
	int n,m,c;
	cin>>n>>m>>c;
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		int ans=c;
		for(int j=0;j<m;j++){
			ans+=a[i][j]*b[j];
		}
		if(ans>0)cnt++;
	}
	cout<<cnt;
	return 0;
} 

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;
int a[1005];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> a[i];
    int ans =  -1;
    rep(i, n){
        rep(j, n) {
            if (i == j) continue;
            int tmp = a[i] * a[j];
            string s = to_string(tmp);
            bool ok = true;
            rep(k, s.size() - 1) {
                if ((s[k + 1] - '0') - (s[k] - '0') != 1) {
                    ok = false;
                    break;
                }
            }
            if (ok) ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
using namespace std;
 
int main() {
  int n;
  cin >> n;

  int floor,cap;

  floor = ((100 * n) + 108 -1) / 108;
  
  if((100 * (n + 1) % 108 == 0)){
     cout << ":(" << endl;
     return 0;
  }
  
  cap = (100 * (n + 1)) / 108;
 
  if(floor == cap){
      cout << floor << endl;
  }else{
      cout << ":(" << endl;
  }
  
}

Measured memory_bytes: 3588
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)
func kakunin(n int) []int{
	sum := make([]int,n)
	for i:= 0; i<n; i++ {
		sum[i] = 1
	}
	return sum
}
func main() {
	scan_init()
	n := scanInt()
	m := scanInt()
	k := scanInt()
	a := make([]int,n+1)
	b := make([]int,m+1)
	a[0] = 0
	for i:= 1; i<=n; i++ {
		a[i] = a[i-1]+scanInt()
	}
	b[0] = 0
	for i:= 1; i<=m; i++ {
		b[i] = b[i-1]+scanInt()
	}
	// aIndex := 0
	// inf := int(math.Pow(10,12))+1
	sum := 0
	for i:= 0; i<n+1; i++ {
		count := 0
		purser := k-a[i]
		count += i
		if purser < 0 {
			continue
		}
		bindex := sort.SearchInts(b,purser+1)
		if bindex > 0 {
			purser -= b[bindex-1]
			if purser >= 0 {
				count += bindex-1
			}
		}
		if sum < count {
			// fmt.Println(purser, "purser", count,a,b,bindex,a[i])
			sum = count
		}
	}
	fmt.Println(sum)
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
	buf := make([]byte, 10000)
	sc.Buffer(buf,1000000000000)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 8244
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

res = r * g * b
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if 1 <= k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                res -= 1
print(res)


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n,m;cin>>n>>m;
  ll l=0,r=INF;

  rep(i,0,m){
    ll a,b;cin>>a>>b;

    chmax(l,a);
    chmin(r,b);
  }
  if(r-l<0)out(0);
  else out(r-l+1);

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
plus = True
absmin = 10000000000
s = 0
for i in a:
    if i < 0:
        plus = not plus
    absi = abs(i)
    if absi < absmin:
        absmin = absi
    s += absi
if plus:
    print(s)
else:
    print(s - absmin * 2)

Measured memory_bytes: 14284
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]

        idx = bisect_left(L, a+b)
        ans += max(idx - (j+1), 0)

print(ans)


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

int main() {
  int n, a, b, c, d, e, f, g, h;
  while (cin >> n, n) {
    while (n--) {
      cin >> a >> b >> c >> d >> e >> f >> g >> h;
      cout << a * e - b * f - c * g - d * h << " "
           << a * f + b * e + c * h - d * g << " "
           << a * g - b * h + c * e + d * f << " "
           << a * h + b * g - c * f + d * e << "\n";
    }
  }
}


Measured memory_bytes: 3040
N, M = map(int, input().split())
H = list(map(int,input().split()))
AB = [map(int, input().split()) for _ in range(M)]
A, B = [list(i) for i in zip(*AB)]

obs = {i+1: {
    'height': H[i],
    'neighbor_height_max': 0
} for i in range(N)}

for i in range(M):
    obs[A[i]]['neighbor_height_max'] = max(obs[B[i]]['height'], obs[A[i]]['neighbor_height_max'])
    obs[B[i]]['neighbor_height_max'] = max(obs[A[i]]['height'], obs[B[i]]['neighbor_height_max'])


ans = 0
for k, v in obs.items():
    if v['height'] > v['neighbor_height_max']:
        ans += 1

print(ans)


Measured memory_bytes: 154432
#include<stdio.h>
#include<ctype.h>

int main(void) {
	char s[100];
	int i, n, k;

	scanf("%d %d", &n, &k);
	scanf("%s", &s);
	s[k-1] = tolower(s[k-1]);
	printf("%s", &s);

	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,t = 0,x = 0,y = 0;
	scanf("%d",&n);
	int i,nx,ny,nt;
	for(i = 1;i <= n; i++)
	{
		scanf("%d %d %d",&nt,&nx,&ny);
		if(abs(nx - x) + abs(ny - y) > (nt - t) || nt % 2 != (abs(nx - x) + abs(ny - y)) % 2)
		{
			printf("No\n");
			break;
		}
	}
	if(i > n)
		printf("Yes\n");
		return 0;
}

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

int H, W;

int main() {
    while (1) {
        
    cin >> H >> W;
    if (H == 0 && W == 0) {
        return 0;
    } else {
        for (int n = 0; n < H; n++) {
            for (int i = 0; i < W; i++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        
    }
        
    }
}



Measured memory_bytes: 3076
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{n:i32};
    println!("{}", n*(n+1)/2);
}

Measured memory_bytes: 4352
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = collections.Counter([x for i, x in enumerate(v) if i % 2 == 0]).most_common()
v2 = collections.Counter([x for i, x in enumerate(v) if i % 2 == 1]).most_common()
v1.append((0, 0))
v2.append((0, 0))
max_v1 = v1[0][1]
max_v2 = v2[0][1]

if v1[0][0] == v2[0][0]:
    if max_v1 == max_v2:
        if v1[1][1] >= v2[1][1]:
            max_v1 = v1[1][1]
        else:
            max_v2 = v2[1][1]
    elif max_v1 > max_v2:
        max_v2 = v2[1][1]
    elif max_v1 < max_v2:
        max_v1 = v1[1][1]

ans = 0
for a in v1:
    ans += a[1]

for a in v2:
    ans += a[1]

print(ans - max_v1 - max_v2)


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

using namespace std;

#define ll long long

int t;
int a, b;

void solve() {
  cin >> a >> b;
  if (2*b>=a) {
    cout<< "0\n";
  } else {
    cout << (a-2*b) << '\n';
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[505][505];
struct Data {
    pll a;
    pll b;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
        }
    }

    vector<Data> v;
    REP(i, H) {
        REP(j, W) {
            if (A[i][j] % 2 == 0)
                continue;

            ll ny = j + 1, nx = i;
            if (ny >= W) {
                ny = j;
                nx = i + 1;
            }
            if (nx >= H)
                break;

            A[i][j]--;
            A[nx][ny]++;
            v.push_back(Data{pll(i + 1, j + 1), pll(nx + 1, ny + 1)});
        }
    }

    cout << v.size() << endl;
    REP(i, v.size()) {
        cout << v[i].a.first << " " << v[i].a.second << " " << v[i].b.first << " " << v[i].b.second << endl;
    }

    return 0;
}

Measured memory_bytes: 8560
#include <stdio.h>
#include <ctype.h>
int main(void){
	int i;
	int counter[256] = {0};
	while((i=getchar()) != EOF){
		if(isupper(i)){
			i +=32;
		}
		counter[i] ++;
	}	
	for(i = 'a'; i<='z'; i++){
		printf("%c : %d\n", i, counter[i]);
	}
	return 0;
	}

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

int main() {
 string S;
 cin >> S;
  
 int A = (S[0] - '0') * 10 + (S[1] - '0');
 int B = (S[2] - '0') * 10 + (S[3] - '0');
 
 bool YYMM = (1 <= B && B <= 12);
 bool MMYY = (1 <= A && A <= 12);
   
 if(YYMM){
  if(MMYY) puts("AMBIGUOUS");
  else puts("YYMM");
  }
  else {
  if(MMYY) puts("MMYY");
  else puts("NA");
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<unordered_set>
using namespace std;

int par[100000];
int rnk[100000];

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		par[i] = i;
		rnk[i] = 0;
	}
	int x, y, z;
	for (int i = 0; i < m; ++i) {
		cin >> x >> y >> z;
		--x; --y;
		x = find(x);
		y = find(y);
		if (x == y)continue;
		if (rnk[x] < rnk[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rnk[x] == rnk[y]) ++rnk[x];
		}
	}
	unordered_set<int> ans;
	for (int i = 0; i < n; ++i) {
		ans.insert(find(i));
	}
	cout << ans.size() << endl;

	
}

Measured memory_bytes: 5156