akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  string s;
  cin >> s;

  if(s == "Sunny") cout << "Cloudy" << endl;
  else if(s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;

  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
ans=0
baisuu=n//k
ans+=baisuu**3
if k%2==0:
    if baisuu*k+k//2<=n:
      hanbun=baisuu+1
    else:
      hanbun=baisuu
    ans+=hanbun**3
print(ans)

Measured memory_bytes: 61724
using System;
using System.Text;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        //System.Diagnostics.Debug.WriteLine("-----TextFile1");
        //System.Diagnostics.Debug.WriteLine(process("../TextFile1.txt"));

        //System.Diagnostics.Debug.WriteLine("-----TextFile2");
        //System.Diagnostics.Debug.WriteLine(process("../TextFile2.txt"));

        //System.Diagnostics.Debug.WriteLine("-----TextFile3");
        //System.Diagnostics.Debug.WriteLine(process("../TextFile3.txt"));


        String ret = process(new System.IO.StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
    }

    static string processText(string input) {
        return process(new System.IO.StringReader(input));
    }

    static string process(string filePath) {
        using (var input = new System.IO.StreamReader(filePath)) {
            return process(input);
        }
    }

    static string process(System.IO.TextReader input) {
        var s     = input.ReadLine();
        var spl   = s.Split(' ');
        int n     = int.Parse(spl[0]);
        int d     = int.Parse(spl[1]);

        int[][] ary  = new int[n][];

        for(int i=0; i<n; i++) {
            ary[i] = ToIntArray(input.ReadLine(), d);
        }

        int count = 0;
        for(int i=0; i<n; i++) {
            for(int j=i; j<n; j++) {
                if (i == j) continue;
                if (calc(ary[i], ary[j], d)) count++;
            }
        }

        return count.ToString();
    }

    static bool calc(int[] xi, int[] xj, int size) {
        int v = 0;
        for(int i=0; i<size; i++) {
            int k = xi[i] - xj[i];
            v += k * k;
        }
        for(int i=0; ; i++) {
            int ii = i * i;
            if (ii == v) return true;
            if (ii > v) return false;
        }
    }
    
    static int[] ToIntArray(string strs, int n) {
        int[] ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 13268
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int M = Int32.Parse(args[1]);

		int[] a = new int[M];
		int[] b = new int[M];
		for(int i = 0; i < M; i++)
		{
			args = Console.ReadLine().Split(' ');
			a[i] = Int32.Parse(args[0]) - 1;  // 0-index
			b[i] = Int32.Parse(args[1]) - 1;  // 0-index
		}

		Solver solver = new Solver(N, M, a, b);
		Console.WriteLine(solver.solve());
	}
}


public class Solver
{
	public int N { get; private set; }
	public int M { get; private set; }
	public int[] A { get; private set; }
	public int[] B { get; private set; }

	private int[,] m_graph = null;
	private bool[] m_visited = null;
	private int m_numVisited = 0;

	public Solver(int n, int m, int[] a, int[] b)
	{
		N = n;
		M = m;
		A = a;
		B = b;
	}

	public int solve()
	{
		int numBridges = 0;
		for(int ignoreEdge = 0; ignoreEdge < M; ignoreEdge++)
		{
			m_graph = new int[N,N];
			for(int edge = 0; edge < M; edge++)
			{
				if(edge == ignoreEdge)
					continue;

				m_graph[A[edge], B[edge]] = 1;
				m_graph[B[edge], A[edge]] = 1;
			}
			
			m_visited = new bool[N];
			m_numVisited = 0;
			dfs(0);
			if(m_numVisited < N)
				numBridges++;
		}

		return numBridges;
	}


	private void dfs(int vertex)
	{
		m_visited[vertex] = true;
		m_numVisited++;
		for(int i = 0; i < N; i++)
		{
			if((m_graph[vertex, i] == 1) && (!m_visited[i]))
				dfs(i); 
		}
	}
}





Measured memory_bytes: 13140
<?php
    fscanf(STDIN,'%s',$str);

    $a = (int)substr($str,0,2);
    $b = (int)substr($str,2,2);

    $c =false;
    $d = false;
    if($a > 0 && $a <= 12){
      $c = true;
    }
    if($b > 0 && $b <= 12){
      $d = true;
    }
    if($c){
      if($d){
        echo 'AMBIGUOUS';
      }else{
        echo 'MMYY';
      }
    }else{
      if($d){
        echo 'YYMM';
      }else{
        echo 'NA';
      }
    }
?>


Measured memory_bytes: 3700
n = int(input())
h = list(map(int, input().split()))

c = 0
for i in range(n-1):
    if h[i] <= h[i+1]-1:
        h[i+1] = h[i+1]-1
    elif h[i] == h[i+1]:
        continue
    else:
        c = 1
if c == 1:
    print('No')
else:
    print('Yes')


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

int main() {
string S;cin>>S;
    int N=S.size();
    int ans=0,hoge=999;
    for(int i = 0; i< S.size()-2;i++)
    {
       hoge=min(hoge,abs(753-stoi(S.substr(i,3))));
    }
    cout<<hoge<<endl;
}

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

namespace cs
{
    public class Program
    {
        public static void Main(string[] args)
        {
            
            var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var inputMin = input[0];
            var inputMax = input[1];
            var divA = input[2];
            var divB = input[3];
            var divC = (divA > divB) ? LCD(divB, divA) : LCD(divA, divB);

            var range = inputMax - inputMin + 1;
            long divACount;
            long divBCount;
            long divCCount;

			divACount = (inputMax / divA) - (inputMin / divA);
            if(inputMin % divA==0){
                divACount +=1;
            }
			divBCount = (inputMax / divB) - (inputMin / divB);
            if(inputMin % divB==0){
                divBCount +=1;
            }
			divCCount = (inputMax / divC) - (inputMin / divC);
            if(inputMin % divC==0){
                divCCount +=1;
            }

            Console.WriteLine(range - (divACount + divBCount - divCCount));

        }

        public static long GCD(long n, long m){
            
            if(m % n == 0) return n;
            else return GCD(m%n, n);

        }

        public static long LCD(long n, long m){

            return m * n / GCD(n,m);
        }
    }
}



Measured memory_bytes: 11092
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<vector<int>>input(int N) {
	vector<vector<int>>v(N,vector<int>(N));
	for (int i = 0; i < N; ++i) {
		string st;cin>>st;
		for (int j = 0; j < N; ++j) {
			v[i][j]=st[j]=='.';
		}
	}
	return v;
}
vector<vector<int>>rotate(vector<vector<int>>v) {
	int N=v.size();
	vector<vector<int>>nv(v.size(),vector<int>(v.size()));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			nv[i][j]=v[j][N-1-i];
		}
	}
	return nv;
}
bool operator<(const vector<int>&l, const vector<int>&r) {
	for (int i = 0; i < l.size(); ++i) {
		if(l[i]<r[i])return true;
		else if(l[i]>r[i])return false;
	}
	return false;
}


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

pair<int, vector<int>>solve(pair<int, vector<int>>p, vector<vector<int>>field) {
	int dx[] = { -1,0,1,0 };
	int dy[] = { 0,1,0,-1 };

	const int start_id=p.first;
	const vector<int> v=p.second;

	int N=field.size();
	UnionFind uf(N*(N+1)+1);

	for (int i = 0; i < N; ++i) {
		if (v[i] == start_id) {
			uf.unionSet(i,N*(N+1));
		}
		for (int j = 0; j < N; ++j) {
			if (v[i] == v[j]) {
				uf.unionSet(i,j);
			}
		}
		if (p.second[i]&&field[i][0]) {
			uf.unionSet(i,i+N);
		}
	}
	for (int y = 0; y < N; ++y) {
		for (int x = 0; x < N; ++x) {
			for (int way = 0; way < 4; ++way) {
				int nx=x+dx[way];
				int ny=y+dy[way];
				if (nx >= 0 && nx < N&&ny >= 0 && ny < N) {
					if(field[y][x]&&field[ny][nx])uf.unionSet(x*N+N+y,nx*N+N+ny);
				}
			}
		}
	}

	vector<int>right_v(N);
	const int right_start=uf.root(N*(N+1));
	for (int i = 0; i < N; ++i) {
		right_v[i]=uf.root(N*N+i);
	}
	
	map<int,int>mp;

	vector<int>right_nv(N);
	int id=1;
	for (int i = 0; i < N; ++i) {
		if (field[i][N - 1]) {
			if (mp.find(right_v[i]) == mp.end()) {
				mp[right_v[i]]=id++;
			}
			right_nv[i]=mp[right_v[i]];
		}
		else {
			right_nv[i]=0;
		}
	}
	if (mp.find(right_start) == mp.end()) {
		return make_pair(-1,right_nv);
	}
	else {
		return make_pair(mp[right_start],right_nv);
	}
}

int main()
{
	string st;cin>>st;
	int ans=0;
	char now('A');

	for (auto ch : st) {
		if (ch > now) {
			now=ch;
		}
		else {
			ans++;
			now=ch;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {

    static int n;
    static int m;
    static int q;

    static int[] a;
    static int[] b;
    static int[] c;
    static int[] d;

    static int ans = 0;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = Integer.parseInt(scan.next());
        m = Integer.parseInt(scan.next());
        m--;
        q = Integer.parseInt(scan.next());
        a = new int[q];
        b = new int[q];
        c = new int[q];
        d = new int[q];
        for (int i = 0; i < q; i++) {
            a[i] = Integer.parseInt(scan.next());
            b[i] = Integer.parseInt(scan.next());
            c[i] = Integer.parseInt(scan.next());
            d[i] = Integer.parseInt(scan.next());
            a[i]--;
            b[i]--;
        }
        scan.close();

        dfs("0");

        System.out.println(ans);
    }

    private static void dfs(String s) {
        if (s.length() == n) {
            int score = 0;
            for (int i = 0; i < q; i++) {
                if (s.charAt(b[i]) - s.charAt(a[i]) == c[i]) {
                    score += d[i];
                }
            }
            ans = Math.max(ans, score);
            return;
        }

        String[] sArray = s.split("");
        int last = Integer.parseInt(sArray[s.length() - 1]);
        for (int i = last; i <= m; i++) {
            dfs(s + String.valueOf(i));
        }
    }

}


Measured memory_bytes: 61184
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

const int MAXN = 1e5 + 10;
int n, m, first[MAXN], tot, d[MAXN], s, t;

struct edge { int from, v, w; } e[20 * MAXN];
struct Node
{
	int x, d;
	bool operator <(const Node &b)const
	{
		return d > b.d;
	}
}cyc;
priority_queue<Node> q;
inline void insert(int u, int v, int w)
{
	tot++; e[tot].v = v; e[tot].w = w; e[tot].from = first[u]; first[u] = tot;
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (register int i = 1; i <= n; i++)
		for (register int j = 0; j <= 9; j++)insert(i, ((i - 1) * 10 + j) % n + 1, j);
	for (register int j = 1; j <= 9; j++) insert(0, j + 1, j);
	s = 0; t = 1;
	memset(d, 0x3f, sizeof d);
	d[s] = 0; q.push((Node) { s, d[s] });
	while (!q.empty())
	{
		cyc = q.top(); q.pop();
		if (cyc.d != d[cyc.x])continue;
		register int x = cyc.x;
		for (register int i = first[x]; i; i = e[i].from)
			if (d[e[i].v] > d[x] + e[i].w)
			{
				d[e[i].v] = d[x] + e[i].w;
				q.push((Node) { e[i].v, d[e[i].v] });
			}
	}
	return cout << d[t], 0;
}

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

const int maxn=100010;
int n;
int a[maxn];
int cnt[maxn], ans;

int main(){

	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x; scanf("%d",&x);
		if(x>n){ ans++; continue; }
		cnt[x]++;
	}
	for(int i=1;i<=n;i++){
		if(cnt[i]<i) ans+=cnt[i];
		else ans+=cnt[i]-i;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int N;
  cin >> N;
  int n[4];
  for(int i = 3; i >= 0 ; i--){
    n[i] = N%10;
    N /= 10;
  }
  //  for(int i = 0; i < 4; i++){
  //    cout << n[i] << endl;
  //  }

  bool flag = false;
  int sign[4] = {1};
  int sum;
  for(int i = 0; i < 2; i++){
    if(i == 0) sign[1] = 1;
    else sign[1] = -1;
    for(int j = 0; j < 2; j++){
      if(j == 0) sign[2] = 1;
      else sign[2] = -1;
      for(int k = 0; k < 2; k++){
	if(k == 0) sign[3] = 1;
	else sign[3] = -1;
	sum = n[0] + sign[1]*n[1] + sign[2]*n[2] + sign[3]*n[3];
	if(sum == 7){
	  //	  cout << "check" << "\n";
	  //	  cout << sign[1] << ", " << sign[2] << ", " << sign[3] << ", " << endl;
	  flag = true;
	  break;
	}
      }
      if(flag == true) break;
    }
    if(flag == true) break;
  }

  char op[4];
  for(int i = 1; i < 4; i++) op[i] = -1*sign[i]+',';

  cout << n[0] 
       << op[1]
       << n[1]
       << op[2]
       << n[2]
       << op[3]
       << n[3]
       << "=7\n";

  /******Ref. ASCII code
	 43 = '+';
	 44 = ',';
	 45 = '-';
	 Ref. ASCII code******/

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	int a[2][n];
	int i, j;
	for (i = 0; i < 2; i++)
		for (j = 0; j < n; j++)
			scanf("%d", &a[i][j]);
	int ans = a[0][0];
	int k;
	for (k = 0; k < n; k++) {
		ans += a[1][k];
	}
	for (k = 1; k < n; k++) {
		int t = 0;
		int l;
		for (l = 0; l < k; l++)
			t += a[0][l];
		for (l = k - 1; l < n; l++)
			t += a[1][l];
		if (t > ans)
			ans = t;
	}
	printf("%d", ans);
}

Measured memory_bytes: 128
S=input()
T=input()

max_ans=0
for i in range(len(S)):
  max_n = 0
  for j in range(len(T)):
    if len(S) >= i + len(T):
      if S[i+j]==T[j]:
      	max_n=max_n+1
  
  if max_ans <= max_n:
    max_ans=max_n

print(len(T)-max_ans)

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

int main(){
	string w;
	cin >> w;
	map<char,int> cnt;
	rep(i,w.size()){
		cnt[w[i]]++;
	}
	int counts = 0;
	for(auto x: cnt){
		auto k = x.first;
		auto v = x.second;
		if(v%2 == 0) counts++;
	}
	if(counts == cnt.size()) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll long long

using namespace std;
const int MAXN = 100005;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n; cin >> n;
	ll ans = n/11 * 2;
	n = n - n/11 * 11;
	if(n > 0) n -= 6, ans++;
	if(n > 0) n -= 5, ans++;
	cout << ans << '\n';
	return 0;
}


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

int c[10][10];

void setPower(void){
	int minimumcost;
	for (int i = 1; i <= 8; ++i) {
		for (int row = 0; row <= 9; ++row) {
			for (int column = 0; column <= 9; ++column) {
				minimumcost = c[row][column];
				for (int vianumber = 0; vianumber <= 9; ++vianumber)
					minimumcost = min(minimumcost, c[row][vianumber] + c[vianumber][column]);
				c[row][column] = minimumcost;
			}
		}
	}
}

int main(void){
	int H, W, tmp, totalcost = 0;
	scanf("%d %d", &H, &W);
	for (int row_c = 0; row_c <= 9; ++row_c) {
		for (int column_c = 0; column_c <= 9; ++column_c)
			scanf("%d", &c[row_c][column_c]);
	}
	setPower();
	for (int row_wall = 0; row_wall < H; ++row_wall) {
		for (int column_wall = 0; column_wall < W; ++column_wall) {
			scanf("%d", &tmp);
			if(tmp != -1)
				totalcost += c[tmp][1];
		}
	}
	printf("%d\n", totalcost);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int a[100010];

int main()
{
    int n,k,s;
    cin >> n >> k >> s;
    for(int i=1;i<=k;i++)   a[i]=s;
    for(int i=k+1;i<=n;i++) a[i]=(s==1000000000)?1:s+1;
    cout << a[1];
    for(int i=2;i<=n;i++)
        cout << " " << a[i];
    cout << endl;
    return 0;
}

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

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;}

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int a, b;
  cin >> a >> b;
  int s = a*b;
  int l = a*2 + b*2;
  printf("%d %d\n", s, l);
}





Measured memory_bytes: 3152
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

n, a, b = gets_i_list

ans = 0
1.upto(n) do |i|
  sum = i.to_s.chars.map(&:to_i).sum
  if sum >= a && sum <= b
    ans += i
  end
end

puts ans


Measured memory_bytes: 14508
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp1, tmp2;
    string S;
    bool flag=true;
    
    cin >> A >> B >>C;

    if(A<=C && C<=B)
	puts("Yes");
    else
	puts("No");
   
 

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a=0,b=0;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}else if(a<b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}



Measured memory_bytes: 2624
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b){
  ll p=1;
  for(int i=0;i<b;i++){
    p*=a;
  }
  return p;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll binom1(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i)/(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int h[n*1];
  for(i=1;i<=n;i++)cin>>h[i];
  int d[n+1];d[1]=0;d[2]=abs1(h[2]-h[1]);
  for(i=3;i<=n;i++){
    d[i]=min(d[i-1]+abs1(h[i]-h[i-1]),d[i-2]+abs1(h[i]-h[i-2]));
  }
  cout<<d[n]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <climits>
using namespace std;
long long max (long long a, long long b) {if (a > b) return a; return b;}
 
int main()
{
    int N;
    int a[200005] = {0};
    long long dp4[200005][3] = {0};
    long long sum = 0;
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];
    long long ans = LLONG_MIN;
        dp4[0][0] = a[0]; dp4[0][1] = INT_MIN;  dp4[0][2] = INT_MIN;
        dp4[1][1] = a[1]; 
        dp4[1][2] = INT_MIN; 
        dp4[1][0] = INT_MIN; 
        dp4[2][2] = a[2]; 
        for (int i = 2; i < N; i++) {
            dp4[i][0] = dp4[i-2][0] + a[i];
            dp4[i][1] = dp4[i-2][1]+a[i];
            if (i - 3 >= 0) dp4[i][1] = max(dp4[i][1], dp4[i-3][0] + a[i]); 
            else dp4[i][1] = max(dp4[i][1], a[i]);
            dp4[i][2] = dp4[i-2][2]+a[i];
            if (i - 3 >= 0) dp4[i][2] = max(dp4[i][2], dp4[i-3][1] + a[i]); 
            if (i - 4 >= 0) dp4[i][2] = max(dp4[i][2], dp4[i-4][0] + a[i]); 
            else dp4[i][2] = max(dp4[i][2], a[i]);
        }
        if (N % 2 == 0){
            if (N - 1 >= 0)ans = max(ans, dp4[N-1][1]);
            if (N - 2 >= 0)ans = max(ans, dp4[N-2][0]);
        }else {
            if (N - 1 >= 0)ans = max(ans, dp4[N-1][2]);
            if (N - 2 >= 0)ans = max(ans, dp4[N-2][1]);
            if (N - 3 >= 0)ans = max(ans, dp4[N-3][0]);
        }
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9032
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String[] input_n_m = br.readLine().split(" ");

        int N = Integer.parseInt(input_n_m[0]);
        int M = Integer.parseInt(input_n_m[1]);

        int[] height = new int[N];
        int[] result = new int[N];
        Arrays.fill(height, 0);
        Arrays.fill(result, 0);
        String[] input_h = br.readLine().split(" ");

        for(int i = 0; i < N; i++){
          height[i] = Integer.parseInt(input_h[i]);
        }

        int count = 0;
        int A, B = 0;

        for(int i = 0; i < M; i++){
          String[] tmp = br.readLine().split(" ");
          A = Integer.parseInt(tmp[0]);
          B = Integer.parseInt(tmp[1]);

          if(result[A-1] == 0){
            result[A-1] = height[B-1];
          }else{
            if(result[A-1] < height[B-1]){
              result[A-1] = height[B-1];
            }
          }

          if(result[B-1] == 0){
            result[B-1] = height[A-1];
          }else{
            if(result[B-1] < height[A-1]){
              result[B-1] = height[A-1];
            }
          }
        }

        for(int i = 0; i < N; i++){
          if(result[i] < height[i]){
            count++;
          }
        }
        
        System.out.println(count);
      }
    }
}

Measured memory_bytes: 56244
# input
N, M = map(int, input().split())

SC = []
for _ in range(M):
    SC.append(tuple(map(int, input().split())))

# process
ans = 0

A = [-1 for _ in range(N)]

for s, c in SC:
    s -= 1
    if s == 0 and c == 0 and N > 1:
        ans = -1
        break
    elif A[s] == -1:
        A[s] = c
    elif A[s] != c:
        ans = -1
        break

if ans != -1:
    if A[0] == -1 and N > 1:
        A[0] = 1
    for i in range(0, N):
        if A[i] == -1:
            A[i] = 0

    A = A[::-1]
    for i in range(N):
        ans += A[i]*(10**i)

# output
print(ans)


Measured memory_bytes: 3064
from functools import reduce
from itertools import combinations
from fractions import gcd

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


Left = [0] * (N + 1)
Right = [0] * (N + 1)

for i in range(N):
    Left[i + 1] = gcd(Left[i], A[i])
    Right[N - i - 1] = gcd(Right[N - i], A[N - i - 1])
ans = 0
for i in range(N):
    ans = max(ans, gcd(Left[i], Right[i + 1]))
    
print(ans)

Measured memory_bytes: 16068
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
  int a , b;
  scanf("%d%d",&a,&b);
  printf("%.12f\n",1./(1./a+1./b));
  return 0;
}


Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

b = input()
if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
elif b == 'G':
    print('C')


Measured memory_bytes: 8136
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;



int main(void){
	string S;
	ll a=0,b=0,c=0;
	cin>>S;
	rep(i,S.size()){
		if(S[i]=='a'){
			a++;
		}else if(S[i]=='b'){
			b++;
		}else{
			c++;
		}
	}
	if(abs(a-b)<=1 && abs(c-b)<=1 && abs(a-c)<=1){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int target = sc.nextInt();
    int miniCoin = sc.nextInt();
    
    if(target%500 <= miniCoin){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }
    }
}


Measured memory_bytes: 23764
#pragma GCC optimize("Ofast")
#include<stdio.h>
int x;
char c;
inline int read()
{
    x=0; c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
    return x;
}
int main(void)
{
    long n = read() + 1, ans = n - 1;
    for (int i = 2; i < n; ++i)
    {
        int u = read(), v = read();
        switch(u > v)
        {
            case true: ans += n * (u - v);
            default: ans += i * (n - i) - u * (n - v);
        }
    }
    printf("%ld", ans);
    return 0;
}


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

#ifdef LOCAL 
string to_string(char a) { return string(1,a); }
string to_string(bool a) { return a ? "1" : "0"; }
string to_string(const char* a) { return (string)a; }
string to_string(string a) { return a; }
string to_string(vector<bool> v) {
	string s = "["; for(unsigned i=0;i<v.size();i++){ s += ((i>0)?" ":"");
    s += char('0'+v[i]); } 	s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) {
	bool b = 1; string s = "["; for (const auto& x: v) {
		if (!b) {s += ", ";} b = 0; s += to_string(x); } s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void dbgf() { cerr << endl; }
template<class H, class... T> void dbgf(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	dbgf(t...); }
#define dbg(...) cerr << #__VA_ARGS__ << " = ", dbgf(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#define boolout(x) cout<<(x?"YES":"NO")<<endl;
typedef long long ll;


void solve()
{
    int n, W;
    cin >> n >> W;
    vector<int> w(n);
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(W+1));

    ll res = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= W; ++j) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j+w[i]<=W) {
                dp[i+1][j+w[i]] = max(dp[i][j+w[i]], dp[i][j] + v[i]);
                res = max(res, (ll) dp[i+1][j+w[i]]);
            }
        }
    }
    //dbg(dp);

    cout << res << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t; // read t. cin knows that t is an int, so it reads it as such.
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}



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

ll arraySum(ll arr[], ll n)  
{ 
    ll initial_sum  = 0;  
    return accumulate(arr, arr+n, initial_sum); 
} 

int main(){
	ll n,q,b,c;
	cin>>n;
	ll arr[n];ll sum=0;
	unordered_map<ll, ll> m;
	for(ll i=0; i<n; i++){
		cin>>arr[i];
		m[arr[i]]++;sum+=arr[i];
	}
	cin>>q;
	while(q--){
		cin>>b>>c;
		if(m[b]){
			ll x=m[b];
			sum-=x*b;
			sum+=c*x;
			m[b]=0;
			m[c]+=x;
		}
		cout<<sum<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 7648
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;
const int MAXN = 1000;
const int MOD = 1000000007;
char map[MAXN][MAXN];
long long dp[MAXN][MAXN];

int main()
{
    int H, W;
    cin >> H >> W;
    for(int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for(int j = 0; j < W; j++) map[i][j] = s.at(j);
    }
    dp[H-1][W-1] = 1;
    for(int i = H-1; i >= 0; i--)
    {
        for(int j = W-1; j >= 0; j--)
        {
            long long val = 0;
            if(i==H-1&&j==W-1) continue;
            if(map[i][j]=='#')
            {
                dp[i][j] = 0;
                continue;
            }
            if(i!=H-1) val += dp[i+1][j];
            if(j!=W-1) val += dp[i][j+1];
            dp[i][j] = val%MOD;
        }
    }
    cout << dp[0][0];
}

Measured memory_bytes: 9088
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	ll X;
	cin >> X;
	ll n = 0;
	ll sum = 0;
	while (sum < X) sum += ++n;
	cout << n << "\n";

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            if (n == 1)
            {
                WriteLine(ReadLine());
                return;
            }
            long ans = Lcm(long.Parse(ReadLine()), long.Parse(ReadLine()));
            for (int i = 2; i < n; i++)
            {
                ans = Lcm(ans, long.Parse(ReadLine()));
            }
            WriteLine(ans);
        }

        /*
         * Gcd (Gross Common Dividing) 最大公約数
         * 
        */
        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }

        /*
        * Lcm (Last Common Multiple) 最小公倍数 
        * Gcdライブラリの仕様が前提
       */

        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mem(a, s) memset(a, s, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
#define MAX 8000000000000000064LL
#define MIN -8000000000000000064LL
typedef vector<int> vi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;
const int mod = 1e9 + 7;
ll add(ll a, ll b) { return (a % mod + b % mod + ((MAX) / mod) * mod) % mod; }
ll sub(ll a, ll b) { return (a % mod - b % mod + ((MAX) / mod) * mod) % mod; }
ll mul(ll a, ll b) {
    return ((a % mod) * (b % mod) + ((MAX) / mod) * mod) % mod;
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
ll fact[1000007] = {0};
ll expo(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    while (y > 0) {
        if (y & 1)
            res = (1ll * res * x) % mod;
        y = y >> 1;
        x = (1ll * x * x) % mod;
    }
    return res;
}
void facto() {
    fact[0] = 1;
    fact[1] = 1;
    for (ll i = 2; i < 1000007; i++)
        fact[i] = (fact[i - 1] * i) % mod;
}
ll ncr(ll n, ll r) {
    ll res = 1;
    res = fact[n];
    res = (res * (expo(fact[r], mod - 2))) % mod;
    res = (res * (expo(fact[n - r], mod - 2))) % mod;
    return res;
}
ll npr(ll n, ll r) {
    facto();
    ll res = 1;
    res = fact[n];
    res = (res * (expo(fact[n - r], mod - 2))) % mod;
    return res;
}
int _x[] = {0, 0, -1, 1, -1, 1, -1, 1};
int _y[] = {-1, 1, 0, 0, 1, -1, -1, 1};
void solve();
void pre();
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    int t = 1;
    // cin >> t;
    rep(i, 1, t) { solve(); }
    return 0;
}

const int mxn = 1e5 + 10;
int vis[mxn] = {};
int ans[mxn] = {};

void pre() {}
void solve() {
    int n, x, m;
    cin >> n >> x >> m;
    x %= m;
    ans[1] = x;
    vis[x] = 1;
    int r = -1, d;
    rep(i, 2, n) {
        x = x * x % m;
        ans[i] = ans[i - 1] + x;
        if (vis[x]) {
            r = vis[x];
            d = i - vis[x];
            break;
        }
        vis[x] = i;
    }
    if (r == -1)
        cout << ans[n] << '\n';
    else {
        int f = (n - r) / d, rr = (n - r) % d;
        cout << ans[r + rr] + (ans[r + d] - ans[r]) * f << '\n';
    }
}

Measured memory_bytes: 4720
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ret = 0
prev = N
for i in range(N):
    a = A[i] - 1
    ret += B[a]
    if a == prev + 1:
        ret += C[prev]
    prev = a
print(ret)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    int b[n] = {}, w[n] = {};
    for (int i = 0; i < n; i++) b[i] = (s[i] == '#') + (i ? b[i-1]: 0);
    for (int i = n-1; i >= 0; i--) w[i] = (s[i] == '.') + (i==n-1 ? 0 : w[i+1]);
    int ans = n;
    for (int i = 0; i <= n; i++) ans = min(ans, (i?b[i-1]:0) + (i==n?0:w[i]));
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    int a, x;

    cin >> x >> a;

    if (x < a) {
        cout << 0 << endl;
    }
    else {
        cout << 10 << endl;
    }
}


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

#define For(i, j, k) for(int i = j; i <= k; i++)

typedef long long LL;

using namespace std;

const int N = 1010;
const int Mod = 1e9 + 7;

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

int mul(long long x, int y){
	return x * y % Mod;
}

struct Matrix{

	const static int n = 2;

	int M[n][n];

	Matrix(int id = 0){
		memset(M, 0, sizeof M);
		if(id == 1) For(i, 0, n - 1) M[i][i] = 1;
	}

	Matrix operator * (const Matrix& B) const{
		Matrix C;
		For(k, 0, n - 1) For(i, 0, n - 1) For(j, 0, n - 1)
			add(C.M[i][j], mul(M[i][k], B.M[k][j]));
		return C;
	}

	Matrix operator ^ (LL e) const{
		Matrix ret(1), x = *this;
		while(e){
			if(e & 1) ret = ret * x;
			x = x * x;
			e >>= 1;
		}
		return ret;
	}

};

LL k;
int n, m;
char S[N][N];
int sum, cntr, cntc;

int mult, adj;

int main(){

	scanf("%d%d%lld", &n, &m, &k);
	For(i, 1, n) scanf("%s", S[i] + 1);
	For(i, 1, n) For(j, 1, m) sum += S[i][j] == '#';
	For(i, 1, n) cntr += S[i][1] == '#' && S[i][m] == '#';
	For(i, 1, m) cntc += S[1][i] == '#' && S[n][i] == '#';

	if(cntr && cntc){
		puts("1");
		return 0;
	}
	
	if(cntc){
		mult = cntc;
		For(i, 2, n) For(j, 1, m) adj += S[i - 1][j] == '#' && S[i][j] == '#';
	}
	else if(cntr){
		mult = cntr;
		For(i, 1, n) For(j, 2, m) adj += S[i][j] == '#' && S[i][j - 1] == '#';
	}

	Matrix A, B;
	A.M[0][0] = A.M[0][1] = 1;
	B.M[0][0] = sum, B.M[1][0] = Mod - adj;
	B.M[1][1] = mult;

	A = A * (B ^ (k - 1));
	printf("%d\n", A.M[0][0]);
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
string S[2020];
int L[2020][2020];
int R[2020][2020];
int U[2020][2020];
int D[2020][2020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	
	FOR(y,H) {
		FOR(x,W) if(S[y][x]=='.') {
			L[y][x]=1;
			if(x) L[y][x]+=L[y][x-1];
		}
		for(x=W-1;x>=0;x--) if(S[y][x]=='.') {
			R[y][x]=1;
			R[y][x]+=R[y][x+1];
		}
	}
	FOR(x,W) {
		FOR(y,H) if(S[y][x]=='.') {
			U[y][x]=1;
			if(y) U[y][x]+=U[y-1][x];
		}
		for(y=H-1;y>=0;y--) if(S[y][x]=='.') {
			D[y][x]=1;
			D[y][x]+=D[y+1][x];
		}
	}
	
	int ma=0;
	FOR(y,H) FOR(x,W) if(S[y][x]=='.') ma=max(ma,L[y][x]+R[y][x]+U[y][x]+D[y][x]-3);
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 68096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,D;cin>>N>>D;
    int ans=0;
    for(int i=0;i<N;i++){
        ll x,y;cin>>x>>y;
        if(x*x+y*y<=D*D) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3656
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
//const input = fs.readFileSync('./input.txt', 'utf8');

_d(input);

function _d(input: string) {
  const [N, c] = input.split('\n');

  // 特殊ケース（全ての色が同じ）
  const top = c[0];
  let sameAll = true;
  for (const color of c) {
    if (top !== color) {
      sameAll = false;
      break;
    }
  }
  if (sameAll) {
    console.log(0);
    return;
  }

  let redCursor = 0;
  let whiteCursor = c.length - 1;
  let swapped = 0;
  main: while (true) {
    // 左から順に見て白があればカウントアップ
    while (c[redCursor] === 'R') {
      redCursor++;
      // 最後まで到達した
      if (redCursor >= whiteCursor) {
        // console.log('[red] no swap needed');
        break main;
      }
    }

    // 右から順に見て赤があれば続ける
    while (c[whiteCursor] === 'W') {
      whiteCursor--;
      // 最後まで到達した
      if (redCursor >= whiteCursor) {
        // console.log('[white] red found, but no swap needed');
        break main;
      }
    }

    swapped++; // 反転が１回必要
    // console.log(`swap ${redCursor} ${whiteCursor}`);

    redCursor++; // カーソルを進めておく
    whiteCursor--; // カーソルを勧めておく
  }

  console.log(swapped);
}


Measured memory_bytes: 35712
from decimal import Decimal
import sys
input=sys.stdin.readline

    
def w(i,m):
    cnt=0
    while(i>0 and i%m==0):
        i//=m
        cnt+=1
    return cnt

N=int(input())
A=[int(Decimal(input())*Decimal(1000000000)) for i in range(N)]
dic=[None for i in range(N)]
dp=[[0]*51 for i in range(51)]

for i in range(N):
    d={}
    d[2],d[5]=w(A[i],2),w(A[i],5)
    dp[d[2]][d[5]]+=1
    dic[i]=d

for i in reversed(range(51)):
    for j in reversed(range(51)):
        if i==50 and j==50:
            continue
        if i==50:
            dp[i][j]+=dp[i][j+1]
        elif j==50:
            dp[i][j]+=dp[i+1][j]
        else:
            dp[i][j]+=dp[i][j+1]+dp[i+1][j]-dp[i+1][j+1]
ans=0

for i in range(N):
    d=dic[i]
    a,b=d[2],d[5]
    t,f=max(18-a,0),max(18-b,0)
    res=dp[t][f]
    if t<=a and f<=b:
        res-=1
    ans+=res
print(ans//2)

Measured memory_bytes: 286224
from collections import Counter
def main():
    mod=2019
    S=input().strip()
    l=len(S)
    M=[0]*(l+1)
    p=1
    for i in range(1,l+1):
        x=int(S[l-i])
        M[i]=(M[i-1]+x*p)%mod
        p*=10
        p%=mod
    print(sum(m*(m-1)//2 for m in Counter(M).values()))
if __name__=='__main__':
    main()

Measured memory_bytes: 70720
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>

using namespace std;

long long M = 1000000007;

int appearences[26];
int main(){
    int N;
    string S;
    cin >> N >> S;
    for(int i = 0; i < N; i++){
        appearences[S[i] - 'a'] ++;
    }

    long long ans = 1;
    for(int i = 0; i < 26; i++){
        if(appearences[i] == 0){
            continue;
        }
        ans = ans * (appearences[i] + 1) % M;
    }
    ans --;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int n;
  int b1[3];
  int b2[3];
  int b3[3];
  int t[3];
  int a[3][3];
  for(int i = 0;i < 3;i++){
    for(int j = 0;j < 3;j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0;i < 3;i++){
    b1[i] = a[i][0]-a[i][1];
    b2[i] = a[i][1]-a[i][2];
    b3[i] = a[i][2]-a[i][0];
//    t[i] = b1[i]+b2[i]+b3[i];
  }
//  cout << b3[0] << b3[1] << b3[2] << '\n';
//  cout << t[0] << t[1] << t[2] << '\n';
  if(b1[0] == b1[1]&&b1[1] == b1[2]&&b1[2] == b1[0])
  {
    if(b2[0] == b2[1]&&b2[1] == b2[2]&&b2[2] == b2[0])
    {
      if(b3[0] == b3[1]&&b3[1] == b3[2]&&b3[2] == b3[0]){
          cout << "Yes" <<'\n';
      }else
        cout << "No" <<'\n';
    }else
      cout << "No" <<'\n';
  }else
    cout << "No" <<'\n';
  return 0;
}


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

int helper(vector<vector<int>> &graph,vector<int> &dp,int n,int v)
{
    if(graph[v].size()==0)
     return 0;

    if(dp[v]!=-1)
     return dp[v];

    int gmax=0;
    for(int i=0;i<graph[v].size();i++)
    {
      int lmax=helper(graph,dp,n,graph[v][i]);
      if(lmax>gmax)
       gmax=lmax;
    } 
    dp[v]=gmax+1;
    return gmax+1;
}
int main() {
    int n,m;
    cin>>n>>m;

    vector<vector<int>> graph(n+1);
    vector<int> dp(n+1,-1);

    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
    }
    int gmax=0;
    for(int i=1;i<=n;i++)
    {
        // cout<<dp[i]<<endl;
       int lmax=helper(graph,dp,n,i);
       gmax=max(gmax,lmax);
    }
    
    cout<<gmax;
 return 0;
}


Measured memory_bytes: 9472
import java.util.*;
import java.io.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
    static long mod=1000000007;
    // static int dx[]={1,-1,0,0};
    // static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
    //ArrayList<Integer> lis = new ArrayList<Integer>();
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int m=sc.nextInt();
        long ans=1,mm=1,nn=1;
        if(n==m)ans=2;
        for( int i=1; i<=n; i++ ){nn*=i; nn%=mod;}
        for( int i=1; i<=m; i++ ){mm*=i; mm%=mod;}
        if( abs(n-m)<=1 ){
            ans*=nn*mm%mod;
            ans%=mod;
        }
        else ans=0;
        out.println(ans);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }
}


class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}

class P implements Comparable<P>{
    int x,y;
    P(int x, int y) {
        this.x=x;
        this.y=y;
    } 
      
    public int compareTo(P p){
        return x - p.x;
    } 
}



class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 23252
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(void){
	for(int i=1;i<10;++i){
		for(int j=1;j<10;++j){
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116