akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 998244353;

const int N = 1e6 + 10;
int sum[N];

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

bool flag[N];
int F[N], A[N];
vector<int> prime;

void prime_gen(int n) {
  fill(flag, flag + n, false);
  F[1] = 1;
  for (int i = 2; i < n; ++i) {
    if (!flag[i]) {
      prime.push_back(i);
      F[i] = MOD + 1 - i;
    }
    for (int j = 0, k; j < prime.size() && (k = prime[j] * i) < n; ++j) {
      flag[k] = true;
      if (i % prime[j]) {
        F[k] = (int64)F[i] * (MOD + 1 - prime[j]) % MOD;
      } else {
        F[k] = F[i];
        break;
      }
    }
  }
  // printf("%lu\n", prime.size());
}

void init(int n) {
  A[1] = 1;
  for (int i = 2; i < n; ++i) {
    A[i] = (MOD - MOD / i) * (int64)A[MOD % i] % MOD;
  }
}

int main() {
  init(N);
  prime_gen(N);
  for (int i = 1; i < N; ++i) {
    F[i] = (int64)F[i] * A[i] % MOD;
  }
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    for (int k = 1; k * k <= a[i]; ++k) {
      if (a[i] % k == 0) {
        add(sum[k], a[i]);
        int u = a[i] / k;
        if (u != k) add(sum[u], a[i]);
      }
    }
  }
  for (int k = 1; k < N; ++k) F[k] = (int64)F[k] * sum[k] % MOD;
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int cur = 0;
    for (int k = 1; k * k <= a[i]; ++k) {
      if (a[i] % k == 0) {
        add(cur, F[k]);
        int u = a[i] / k;
        if (u != k) {
          add(cur, F[u]);
        }
      }
    }
    add(ret, (int64)cur * a[i] % MOD);
  }
  for (int i = 0; i < n; ++i) {
    add(ret, MOD - a[i]);
  }
  if (ret % 2 == 0) {
    ret /= 2;
  } else {
    ret = (ret + MOD) / 2;
  }
  printf("%d\n", ret);
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  for(int k=1; k<=n; k++){
    int s=0;
    for(int x=1; x*x<=n; x++){
      for(int y=1; y*y+x*x<=n; y++){
        for(int z=1; z<=n; z++){
          int p=x*x+y*y+z*z+x*y+y*z+z*x;
          if(p>k) break;
          else if(p==k) s++;
        }
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n,d,x;
  std::cin >> n >> d >> x;
  vt<int> a(n);
  rep(i,n)
    std::cin >> a[i];

  int cnt = 0;
  rep(i,n){
    int day = 1, times = 1;
    while(day <= d){
      cnt++;
      day = a[i]*times + 1;
      times++;
    }
  }

  std::cout << cnt + x << '\n';
  return 0;
}


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

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] L = S.Split(' ');
            int[] X = new int[11];
            int R = int.Parse(L[0]);
            int D = int.Parse(L[1]);
            X[0] = int.Parse(L[2]);
            for(int i=1; i<=10; i++)
            {
                X[i] = R * X[i - 1] - D;
                Console.WriteLine(X[i]);
            }


        }
    }
}

Measured memory_bytes: 11092
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int a,b; cin >> a >> b;
        for(int i = 1; i<=10000; i++){
            int res = (i*8)/100;
            int res1 = (i*10)/100;
            if(res==a and res1==b){
                cout<<i<<endl;
                return 0;
            }
        }
        cout<<-1<<endl;



return 0;
}




Measured memory_bytes: 256
s = input()
pre = int(s[:2])
post = int(s[2:])

if 1 <= pre <= 12 and 1 <= post <= 12:
    print('AMBIGUOUS ')
elif 0 <= pre <= 99 and 1 <= post <= 12:
    print('YYMM')
elif 1 <= pre <= 12 and 0 <= post <= 99:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

int main()
{
    string str;
    while(cin>>str,!cin.eof()){
        int block[str.length()],num=0;
        for(int i=0;i<str.length();i++){
            switch(str[i]){
                case 'M' :
                    block[i]=1000;
                    break;
                case 'D' :
                    block[i]=500;
                    break;
                case 'C' :
                    block[i]=100;
                    break;
                case 'L' :
                    block[i]=50;
                    break;
                case 'X' :
                    block[i]=10;
                    break;
                case 'V' :
                    block[i]=5;
                    break;
                case 'I' :
                    block[i]=1;
                    break;
            }
        }
        for(int i=0;i<str.length();i++){
            if(block[i]<block[i+1] && i!=str.length()-1){
                num += block[i+1]-block[i];
                i++;
            }
            else{
                num += block[i];
            }
        }
        cout<<num<<endl;
    }
    return 0;
}

Measured memory_bytes: 1180
fun main(args: Array<String>) {
    nikkei2019qual_c()
}

fun nikkei2019qual_c() {
    val n = readLine()!!.toInt()
    val abList = (1..n).map { readLine()!!.split(' ').map { it.toLong() } }
        .map { Pair(it[0], it[1]) }

    val answer = abList.sortedByDescending { it.first + it.second }
        .mapIndexed { index, pair -> if (index % 2 == 0) pair.first else -pair.second }.sum()

    println(answer)
}


Measured memory_bytes: 66604
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a[200005];
ll b[200005];
int main()
{
	ll n,m,k;cin>>n>>m>>k;
	ll t,ans=0;
	ll tmp=0;
	for (ll i = 1; i<=n; i++)
	{
		cin>>t;a[i]=a[i-1]+t;
		if(a[i]<=k) tmp=i;
	}
	for (ll i = 1; i <=m; i++)
	{
		cin>>t;b[i]=b[i-1]+t;
	}
	for (ll i = 0,j=m; i<=tmp; i++)
	{
		while(a[i]+b[j]>k) j--;
		ans=max(ans,i+j);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6728
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
    double a,b,c,degree,S;
    scanf("%lf %lf %lf",&a,&b,&degree);
    S = (0.5)*a*b*sin(M_PI*degree/180);
    c = sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
    printf("%.8lf\n",S);
    printf("%.8lf\n",a+b+c);
    printf("%.8lf\n",2*S/a);
}


Measured memory_bytes: 3124
//Frog 2

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define fi first
#define se second
template<class T>inline bool chmin(T& a,T b,bool f){
    if(f==1){if(a>b){a=b;return true;}return false;}
    else if(f==0){if(a<b){a=b;return true;}return false;}return false;
}
const int inf = 2147483647;
const ll INF = 9223372036854775807;

int main (){
    ll n,k;cin>>n>>k;
    vector<ll> ar(n+k,inf),dp(n+k,inf);
    rep(i,k,n+k)cin>>ar[i];
    dp[k]=0;
    rep(i,k+1,n+k){
        ll c;
        rep(j,i-k,i){
            c=dp[j]+abs(ar[i]-ar[j]);
            chmin(dp[i],c,1);
        }
    }
    cout << dp[n+k-1] << nnn;
    return 0;
}

Measured memory_bytes: 1792
def solve():
    K, N = map(int, input().split())
    As = list(map(int, input().split()))

    dis = 0
    point = 0
    for i in range(1, N):
        tmp = As[i]-As[i-1]
        if tmp > dis:
            dis = tmp
            point = i

    if As[N-1]-As[0] < K-As[point]+As[point-1]:
        print(As[N-1]-As[0])
    else:
        print(K-As[point]+As[point-1])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 78412
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n,m;
  cin>>n>>m;
  if(n==m){
    cout<<"Yes"<<endl;}
  else{
    cout<<"No"<<endl;}


}

Measured memory_bytes: 256
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var o = [intShift(),intShift(),intShift(),intShift(),intShift()];
  o = o.sort((a,b)=>a-b);
  return o[4] - o[0] <= intShift()?"Yay!":":("
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
1
2
4
8
17
15
`);

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) { cin >> A[i]; }
    // i < i+1かは
    // i-(K-1)
    // i+1の比較
    REP(i, N - K) {
        ll j = K + i;
        if(A[j - K] < A[j]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4844
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int s,h=1000000000; cin>>s; 
    int x2= (s+h-1)/h;
    int y2=h*x2-s;
    cout << "0 0 1 1000000000 " << x2 << " " << y2 << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
const int M = 1000005;
void solve() {
	int64 N; cin >> N;
	map<int64, int64> cnt_num;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < N; ++i) {
		cnt_num[a[i]]++;
		if (cnt_num[a[i]] == 1) {
			for (int j = a[i] * 2; j < M; j+=a[i]) {
				cnt_num[j]++;
			}
		}
	}
	int64 ans = 0;
	for (int i = 0; i < N; ++i) {
		if (cnt_num[a[i]] == 1) ans++;
	}	
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

using namespace std;

using ll = long long;


struct Point {
    ll x, y, h;
    Point() {};
    Point(ll _x, ll _y, ll _h) : x(_x), y(_y), h(_h) {}
};

Point c;

inline ll Dist(const Point &p1, const Point &p2) {
    return abs(p1.x - p2.x) + abs(p1.y - p2.y);
}

void Solve() {
    int n;
    cin >> n;
    vector<Point> p(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i].x >> p[i].y >> p[i].h;

    for (ll y = 0; y <= 100; ++y) {
        for (ll x = 0; x <= 100; ++x) {
            c.x = x; c.y = y;
            c.h = p[0].h + Dist(c, p[0]);
            if (c.h < 1) continue;

            bool flag = true;
            for (int i = 0; i < n; ++i) {
                ll d = Dist(c, p[i]), h = max(c.h - d, (ll)0);;
                if (p[i].h != h) {
                    flag = false;
                    break;
                }
            }

            if (flag) return;
        }
    }

    for (int h = 1; h <= 200; ++h) {
        for (int x = 0; x <= 100; ++x) {
            for (int y = 0; y <= 100; ++y) {
                bool flag = true;
                c.x = x; c.y = y; c.h = h;
                for (int i = 0; i < n; ++i) {
                    ll d = Dist(c, p[i]), hh = max(c.h - d, (ll)0);
                    if (p[i].h != hh) {
                        flag = false;
                        break;
                    }
                }
                if (flag) return ;
            }
        }
    }
}

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

    Solve();
    cout << c.x << ' ' << c.y << ' ' << c.h << '\n';

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
    ll x;
    cin >> x;
    int up;
    if (x % 11 == 0)
        up = 0;
    else if (x % 11 < 7)
        up = 1;
    else if (x % 11 >= 7)
        up = 2;
    cout << (x / 11) * 2 + up << endl;
}

Measured memory_bytes: 256
<?php
    # 整数の入力
    fscanf(STDIN, "%d %d %d",$a, $b, $c );

	$zanyou = $a - $b;

	$ans = $c - $zanyou;
	if ($ans < 0){
     $ans = 0;
    }

    # 出力
    echo ($ans)."\n";
    ?>

Measured memory_bytes: 3576
#include<stdio.h>
#include<algorithm>
using namespace std;
double dp[1<<15][15];
int rev[1<<15][15];
int ans[20];
int b[20];
int c[20];
int d[20];
int ABS(int a){
	return max(a,-a);
}
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d%d%d",b+i,c+i,d+i);
	for(int i=0;i<(1<<a);i++)for(int j=0;j<a;j++)dp[i][j]=99999999999.99;
	for(int i=0;i<a;i++)dp[1<<i][i]=0;
	for(int i=0;i<(1<<a);i++){
		int w=0;
		for(int j=0;j<a;j++)if(i&(1<<j))w+=20*d[j];
		for(int j=0;j<a;j++){
			for(int k=0;k<a;k++){
				if(i&(1<<k))continue;
				double t=dp[i][j]+(70.0+w)*(double)ABS(c[j]-c[k])/2000;
				if(t<dp[i+(1<<k)][k]){
					dp[i+(1<<k)][k]=t;
					rev[i+(1<<k)][k]=j;
				}
			}
		}
	}
	int now=0;
	for(int i=1;i<a;i++)if(dp[(1<<a)-1][now]>dp[(1<<a)-1][i])now=i;
	int at=(1<<a)-1;
	int ind=a-1;
	while(at){
		ans[ind]=now;
		int to=rev[at][now];
		at-=(1<<now);
		now=to;
		ind--;
	}
	for(int i=0;i<a;i++){
		if(i)printf(" ");
		printf("%d",b[ans[i]]);
	}
	printf("\n");
}

Measured memory_bytes: 6768
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

char arr[107][107];
int main(){
	Lancer();
	ll h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			cin >> arr[i][j];
	for (int i = 0; i < h+2; i++){
		arr[i][0] = '#';
		arr[i][w+1] = '#';
	}
	for (int i = 0; i < w + 2; i++){
		arr[0][i] = '#';
		arr[h+1][i] = '#';
	}
	for (int i = 0; i < h + 2; i++){
		for (int j = 0; j < w + 2; j++)
			cout << arr[i][j];
		cout << endl;
	}

	//cout << endl;
	return 0;
}


Measured memory_bytes: 3624
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let s: String = read();
    let t: String = read();
    let mut ans = 2 * N;
    for i in 0..N {
        if &s[(N - i - 1)..] == &t[0..i + 1] {
            ans = 2 * N - (i + 1);
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long ans = 0;

        for(int i=1;i<=n;i++) {
            long amari = n%i;
            long syou = n/i;
            
            ans+=(i+n-amari)*syou/2;
        }
        
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 35828
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 1000005;
const int mod = 998244353;

int main(){
    int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
    for(int i=1;;i++){
        c-=b;
        if(c<=0) break;
        a-=d;
        if(a<=0) break;
    }
    if(a<=0) printf("No\n");
    else printf("Yes\n");
    return 0;
}




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

int main() {
  map<int,bool> mp;
  int a;
  scanf("%d", &a);
  mp[a] = true;

  int cnt = 1;
  while (true) {
    cnt += 1;
    if (a % 2 == 0) {
      a = a / 2;
    }
    else {
      a = 3 * a + 1;
    }

    auto itr = mp.find(a);
    if (itr != mp.end()) break;

    mp[a] = true;
  }

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


Measured memory_bytes: 256
# 条件より絶対5桁
A, B = map(int, input().split())

cnt = 0

for i in  range(A, B+1):
    num = i
    res = []
    res_append = res.append
    while num > 0:
        q, mod = divmod(num, 10)
        res_append(mod)
        num = q
    if (res[0] == res[-1]) and (res[1] == res[-2]):
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())

    for i in range(1, 10):
        for j in range(1, 10):
            if i * j == N:
                print('Yes')
                exit()

    print('No')



if __name__ == '__main__':
    solve()


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

using namespace std;
typedef long long ll;

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

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

  int ans = 0;
  for (int i = 0; i + 1 < n; i++) {
    if (p[i] != i + 1) continue;
    ans++;
    swap(p[i], p[i + 1]);
  }
  ans += p[n - 1] == n;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n,a,b;
    cin >> n >> a >> b; 
    vector<int> p(3);
    rep(i,n) {
        int pin;
        cin >> pin;
        if (pin<=a) ++p[0];
        else if (pin<=b) ++p[1];
        else ++p[2];
    }
    sort(p.begin(),p.end());
    cout << p[0] << endl;
     
    return 0;   
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
int main(void){int ans,num[15][15],w,h,i,j,map[15][15];while (1){scanf("%d%d", &w, &h);if (w + h == 0){break;}memset(map, -1, sizeof(map));for (i = 0; i < h; i++){for (j = 0; j < w; j++){scanf("%d", &map[i][j]);}}memset(num, 0, sizeof(num));for (i = 0; i < w; i++){if (map[0][i] != 1){num[0][i] = 1;}}for (i = 1; i < h; i++){for (j = 0; j < w; j++){if (j > 0 && map[i - 1][j - 1] == 0 && map[i][j] != 2){num[i][j] += num[i - 1][j - 1];}if (map[i - 1][j] == 0){num[i][j] += num[i - 1][j];}if (j < w - 1 && map[i - 1][j + 1] == 0 && map[i][j] != 2){num[i][j] += num[i - 1][j + 1];}if (i > 1 && map[i - 2][j] == 2){num[i][j] += num[i - 2][j];}}}ans = 0;for (j = 0; j < w; j++){if (map[h - 1][j] != 1){ans += num[h - 1][j];}if (h > 1 && map[h - 2][j] == 2){ans += num[h - 2][j];}}printf("%d\n", ans);}return (0);}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 10010
int a[N],b[N],c[N];
int main()
{
    long long s1,s2;
    int i,j,k,n;
    s1=0;
    s2=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(i=1;i<=n;i++)
        c[i]=a[i]-b[i];
    sort(c+1,c+n+1);
    for(i=1;i<=n;i++)
    {
        if(c[i]>0)
            break;
        s1=s1+c[i]/2;
    }
    for(;i<=n;i++)
        s2=s2+c[i];
    s1=fabs(s1);
    if(s1<s2)
        printf("No\n");
    else
        printf("Yes\n");
    //printf("%lld %lld\n",s1,s2);
    return 0;
}

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

using namespace std;

int N, M;
string A[55], B[55];

bool check(int i, int j)
{
	for(int di = 0; di < M; di++){
		for(int dj = 0; dj < M; dj++){
			if(A[i+di][j+dj] != B[di][dj]) return false;
		}
	}
	return true;
}

int main(void)
{
	cin >> N >> M;
	if(M > N){
		cout << "No" << endl;
		return 0;
	}
	
	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < M; i++) cin >> B[i];
	
	for(int i = 0; i <= N-M; i++){
		for(int j = 0; j <= N-M; j++){
			if(check(i, j)){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>G[100005];
int u,v,n;
vector<int> Takahashi(100005,100005);
vector<int> Aoki(100005,100005);
void dfs1(int curr,int last,int step){
  Aoki[curr] = step;
  for(auto i:G[curr]){
    if(i!=last){
      dfs1(i,curr,step+1);
    }
  }
}
void dfs2(int curr,int last,int step){
  if(curr == v){
    return ;
  }
  Takahashi[curr] = step;
  for(auto i:G[curr]){
    if(i!=last){
      dfs2(i,curr,step+1);
    }
  }  
}
int main(){
  cin>>n>>u>>v;
  for(int i=0;i<n-1;++i){
    int f,t;cin>>f>>t;
    G[f].push_back(t);
    G[t].push_back(f);
  }
  if(u==v){cout<<0<<endl;return 0;}
  dfs1(v,-1,0);
  dfs2(u,-1,0);
  int res = 0;
  for(int i=1;i<=n;++i){
    if(Aoki[i] > Takahashi[i]){
      res = max(res,Aoki[i]-1);
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 10368
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;
#define TENS(n) int(1e##n + n)

// dp[i][j] : i番目までにj回表が出る
double dp[3000][3000];
// とおくと,
// dp[i][j] = dp[i-1][j] + dp[i-1][j-1] * p_i

void solve()
{
    int N;
    cin >> N;
    vector<double> p(N + 1);
    REP1(i, N)
    {
        cin >> p[i];
    }

    dp[1][0] = (1 - p[1]);
    dp[1][1] = p[1];

    FOR(i, 2, N+1)
    {
        dp[i][0] = dp[i - 1][0] * (1 - p[i]);
        dp[i][i] = dp[i - 1][i - 1] * p[i];
        REP1(j, i-1)
        {
            dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
        }
    }

    double ans = 0;
    FOR(i, N / 2 + 1, N + 1)
    {
        ans += dp[N][i];
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 68992
import java.util.Scanner;

public class Main {
		public static void main (String[] args) throws java.lang.Exception {
			Scanner sc = new Scanner(System.in);
			while(true) {
				String s = sc.next();
				if(s.equals("0")) break;
				int ret = 0;
				for(int i = 0; i < s.length(); i++) ret += s.charAt(i) - 48;
				System.out.println(ret);
			}
		}
}



Measured memory_bytes: 26396
#include<stdio.h>
int main(void){
  int N,l,i;
  scanf("%d",&N);
  int A[N],E[N+1];
  for(i=0;i<=N-1;i++){scanf("%d",&A[i]);E[A[i]]=i+1;}
  for(l=1;l<=N;l++)printf("%d ",E[l]);
  return 0;}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    string s; cin>>s;
    int n=s.size();

    for(char cha='a'; cha<='z'; cha++){
        bool f=false;
        for(int i=0; i<n; i++){
            if(s[i]==cha) f=true;
        }

        if(!f){
            cout << s << cha << endl;
            return 0;
        }
    }

    int m;
    char tail='0';
    for(int i=n-1; i>0; i--){
        if(s[i-1]<s[i]){
            tail=s[i-1];
            m=i;
            break;
        }
    }

    if(tail=='0'){
        cout << -1 << endl;
        return 0;
    }

    char change='z';
    for(int i=n-1; i>=m; i--){
        if(tail<s[i] && s[i]<change) change=s[i];
    }

    for(int i=0; i<m-1; i++){
        cout << s[i];
    }
    cout << change << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, val;
    cin >> n;
    int satify = 0;
    for(int i = 0; i < n; i++) {
        cin >> val;
        if (val == satify+1) {
            satify += 1;
        }
    }
    if (satify == 0)
        cout << -1 << endl;
    else
        cout << n-satify << endl;

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
int cnt[100010];
main(){
    int N,A;
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> A;
        cnt[A]++;
    }
    int maxn = cnt[0] + cnt[1];
    for(int i = 1;i < 100000;i++){
        maxn = max(maxn,cnt[i] + cnt[i-1] + cnt[i+1]);
    }
    cout << maxn << endl;
}

Measured memory_bytes: 640
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0

    ans = 1 if sorted(list(set(str(s)))) == ['0', '3', '5', '7'] else 0
    for i in '753':
        ans += dfs(s + i)

    return ans


print(dfs('0'))


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int SIZE = 212345;
ll a0[SIZE];
ll a1[SIZE];

// 範囲add : [l, r] それぞれに x を加える
void add(int l, int r, ll x) {
  l++;
  r++;
  a0[l] += -x*(l-1);
  a1[l] += x;
  a0[r+1] += x*r;
  a1[r+1] += -x;
}
// sum[0, i]
ll get(int i) {
  i++;
  return a1[i] * i + a0[i];
}
 
const int MAX_N = 112345;
int a[MAX_N];
 
int main2() {
  CLR(a0, 0);
  CLR(a1, 0);
 
  int N = nextInt();
  int M = nextInt(); 
  REP(i, N) a[i] = nextInt() -1;
 
  ll ans = 0;
  for (int i = 0; i + 1 < N; i++) {
    const int L = (a[i] <= a[i+1] ? a[i+1] - a[i] : a[i+1] - a[i] + M);
    ans += L;
    if (L >= 2) {
      if (a[i] < a[i+1]) {
        add(a[i]+2, a[i+1], 1); add(a[i+1]+1, a[i+1]+1, -(L-1));
      } else {
        if (a[i]+2 <= M-1) {
          add(a[i]+2, M-1, 1);
          add(M, M, -(M-a[i]-2));
          add(0, 0, M-a[i]-2);
          add(0, a[i+1], 1);
          add(a[i+1]+1, a[i+1]+1, -(L-1));
        } else {
          add(a[i]+2-M, a[i+1], 1);
          add(a[i+1]+1, a[i+1]+1, -(L-1));
        }
      }
      // for (int x = 0; x <= M; x++) cout << get(x) << " "; cout << endl;
    }
  }

  for (int i = 1; i < MAX_N; i++) a0[i] += a0[i-1];
  for (int i = 1; i < MAX_N; i++) a1[i] += a1[i-1];

  ll ma = 0;
  for (int x = 0; x <= M; x++) {chmax(ma, get(x));}
  ans -= ma;
  cout << ans << endl;
  return 0;
}

int main() { 
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N,K;
    cin >> N >> K;
    int A[N];
    REP(i,N){
        cin >> A[i];
    }
    sort(A,A+N);
    int ans = 0;
    REP(i,K){
        ans += A[i];
    }
    fin(ans);
    return 0;
}

Measured memory_bytes: 3160
import itertools

N = int(input())
PS = list(map(int, input().split()))
PSS = sorted(PS)

RES ='NO'
if PS != PSS:
    for i, j in itertools.combinations(range(N), 2):
        PC = PS[:]
        PC[j], PC[i] = PC[i], PC[j]
        if PSS == PC:
            RES = 'YES'
            break
else:
    RES ='YES'

print(RES)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int N = Integer.parseInt(s[0]);
        int A = Integer.parseInt(s[1]);
        int B = Integer.parseInt(s[2]);
        int num = 0;
        for(int i = 1 ; i <= N; i++) {
            String str = String.valueOf(i);
            int count = 0;
            for(int j = 0 ; j < str.length(); j++) {
                count += Character.digit(str.charAt(j), 10);
            }
            if(A <= count && count <= B) num+=i;
        }
        System.out.println(num);
    }
}


Measured memory_bytes: 23636
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let tentou (xs: int64 list) =
    let rec aux acc = function
        | [] -> acc
        | x :: xs ->
            let d = List.filter (fun y -> y < x) xs |> List.length
            aux (acc + d) xs
    aux 0 xs |> int64

let lower (xs: int64 list) =
    let rec aux acc = function
        | [] -> acc
        | y :: ys ->
            let d = List.filter (fun x -> x < y) xs |> List.length
            aux (acc + d) ys
    aux 0 xs |> int64

[<EntryPoint>]
let main _ =
    let [N;K] = reads int64
    let K = int64 K
    let AS = reads int64
    let INF = 1000000007L

    let t1 = tentou AS
    let t2 = lower AS
    // eprintfn "*%A" (t1, t2)
    let a1 = (t1 * K) % INF
    let a2 = ((K * (K - 1L) / 2L) % INF) * t2
    // eprintfn "*%A" (a1, a2)
    let ans = (a1 + a2) % INF
    printfn "%i" ans
    0

Measured memory_bytes: 19748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
using ll = long long;

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

	vector<ll> ans;
	rep(i, a, a + k) {
		if (i > b) break;
		ans.pb(i);
	}
	rem(i, b, b - k) {
		if (i < a || binary_search(all(ans), i)) break;
		ans.pb(i);
	}
	SORT(ans);

	for (auto& x : ans) cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

 
int main(){
    string s[3];
    rep(i, 3) cin >> s[i];

    cout << s[0][0] << s[1][1] << s[2][2] << ln;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int k,s,a=0,i,j;
    scanf("%d%d",&k,&s);
    for(i=0;i<=k;i++){
        for(j=0;j<=k;j++){
            if(i+j>s)break;
            if(k>=s-i-j)a++;
        }
    }
    printf("%d",a);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int k,x;
cin >> k >> x;
500*k >= x ? fin("Yes") : fin("No");

//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 892
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        HashMap<Pair, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            long d = Math.round(Double.parseDouble(scanner.nextLine()) * 1e9);
            int two = 0, five = 0;
            while (d % 2 == 0) {
                two++;
                d /= 2;
            }
            while (d % 5 == 0) {
                five++;
                d /= 5;
            }
            Pair pair = new Pair(two, five);
            map.compute(pair, (key, val) -> val == null ? 1 : val + 1);
        }
        long ans = 0;
        for (Map.Entry<Pair, Integer> p1 : map.entrySet()) {
            for (Map.Entry<Pair, Integer> p2 : map.entrySet()) {
                if (p1.getKey().two + p2.getKey().two >= 18 && p1.getKey().five + p2.getKey().five >= 18) {
                    if (p1 == p2) ans += (long) p1.getValue() * (p1.getValue() - 1);
                    else ans+=(long) p1.getValue()*p2.getValue();
                }
            }
        }
        System.out.println(ans/2);
    }

    private static class Pair {
        private final int two, five;

        private Pair(int two, int five) {
            this.two = two;
            this.five = five;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair pair = (Pair) o;
            return two == pair.two &&
                    five == pair.five;
        }

        @Override
        public int hashCode() {
            return Objects.hash(two, five);
        }
    }
}


Measured memory_bytes: 67012
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int x,y,z;
  cin >> x >> y >> z;
  swap(x,y);
  swap(x,z);
  cout << x << " " << y << " " << z;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
def CountBomb(s, i, j, h, w)
  cnt = 0
  x = [1,1,0,-1,-1,-1,0,1]
  y = [0,1,1,1,0,-1,-1,-1]
  8.times do |k|
    if( (i+y[k]>=0) && (j+x[k]>=0) && (i+y[k]<=h-1) && (j+x[k]<=w-1) )
      if( s[i+y[k]][j+x[k]] == "#")
        cnt = cnt + 1
      end
    end
  end
  cnt
end

h, w = gets.split.map(&:to_i)
s = []
h.times do |i|
  s[i] = gets.chomp
end

h.times do |i|
  w.times do |j|
    if not s[i][j] == "#"
      s[i][j] = CountBomb(s, i, j, h, w).to_s
    end
  end
end

puts s

Measured memory_bytes: 3836
import sys
input=lambda: sys.stdin.readline().rstrip()
A=input()
B=input()
C=input()

a,b,c=len(A),len(B),len(C)

def f(X,Y):
  XY=[True]*(10**4)
  x,y=len(X),len(Y)
  for i in range(5000-y+1,5000+x):
    ret=True
    if i<=5000:
      for j in range(min(x,y+i-5000)):
        if X[j]=="?" or Y[j-i+5000]=="?" or X[j]==Y[j-i+5000]:
          continue
        else:
          ret=False
    else:
      for j in range(min(y,x-i+5000)):
        if Y[j]=="?" or X[j+i-5000]=="?" or Y[j]==X[j+i-5000]:
          continue
        else:
          ret=False
    XY[i]=ret
  return XY
AB=f(A,B)
BC=f(B,C)
AC=f(A,C)
ans=a+b+c
for i in range(5000-b-c,5000+a+c):
  for j in range(5000-b-c,5000+a+b):
    if -4000<=j-i<=4000:
      if AB[i] and AC[j] and BC[j-i+5000]:
        l=min(5000,i,j)
        r=max(i+b,j+c,5000+a)
        ans=min(ans,r-l)
    else:
      if AB[i] and AC[j]:
        l=min(5000,i,j)
        r=max(i+b,j+c,5000+a)
        ans=min(ans,r-l)
print(ans)


Measured memory_bytes: 55004
#include <bits/stdc++.h>
#define p(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)   for(int i=a;i<=b;i++)


using namespace std;

void solve()
{
int a;
string s;
cin>>a;

cin>>s;


 if(a>=2800 and a < 3200) cout<<"red";
 else if(a<5000)
    cout<<s<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;

     //  cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main(){
    int N; cin >> N;
    vector<int> A(N); for(int i = 0; i < N; ++i) cin >> A[i];

    int max_n = *max_element(A.begin(), A.end());
    int min_n = *min_element(A.begin(), A.end());

    cout << abs(max_n - min_n) << endl;
}

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

void rec(std::string s, int cur_max, int depth){
    if(!depth){
        std::cout << s << '\n';
        return;
    }
    for (int next_node = 0; next_node < 26; ++next_node) {
        if(next_node > cur_max + 1) break;
        std::string new_s = s;
        new_s.push_back('a'+next_node);
        rec(new_s, std::max(cur_max, next_node), depth-1);
    }
}

int main(){
    std::string s;
    int k;
    std::cin >> k;
    rec(s, -1, k);
}

Measured memory_bytes: 1536
n,h,w=gets.split.map(&:to_i)
x=[]
n.times do
	x << gets.split.map(&:to_i)
end
count=0
for i in 0..x.count - 1 do
	count+=1 if x[i][0] >= h && x[i][1] >= w
end
puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
int64_t INF = 1LL<<60;


void YN(bool x){
  if(x) cout<<"Yes";
  else cout<<"No";
}

int main() {
  int K; cin>>K;
  rep(i,K) cout<<"ACL";
}

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


using namespace std;

int main()
{
    int n; cin >> n;
    int a[n];
    for(int i=0;i<n-1;i++)
    {
        cin >> a[i];
    } int sum=0;

    sum+=a[0];

    for(int i=1;i<n-1;i++)
    {
        sum+=min(a[i-1],a[i]);
    } sum+=a[n-2];

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Test {
	static void Main(string[] args) {
      long N = long.Parse(System.Console.ReadLine());
      var A = System.Console.ReadLine()
    	.Split(' ')
    	.Select(s => long.Parse(s))
    	.ToArray();
      long max = A[0];
      long cnt = 0;
      
      for(int i = 1; i < N; i++){
        if(max > A[i]){
          cnt = cnt + max - A[i];
        }else{
          max = A[i];
        }
      }
      Console.WriteLine(cnt);
	}
}


Measured memory_bytes: 44524
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define debug(x) #x << "=" << (x)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//

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

    int i = 1;
    set<ll> st;
    while(true) {
        ll mod = (A * i) % B;
        if (mod == C) {
            cout << "YES" << "\n";
            return 0;
        }
        if (st.count(mod)) {
            cout << "NO" << "\n";
            return 0;
        }
        st.insert(mod);
        i++;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (abs(a - c) <= d)
    {
        printf("Yes\n");
        return 0;
    }
    if (abs(a - b) <= d && abs(b - c) <= d)
    {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"

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

int main() {

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

//write code hare

	int k;
	int a, b;
	int f = 0;
	cin >> k >> a >> b;



	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			f = 1;
			break;
		}
	}


	if (f == 1) {
		cout << "OK";
	}
	else {
		cout << "NG";
	}
}

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

Measured memory_bytes: 256