akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
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;
}
int main() {
    ll a;
    long double b;
    cin >> a >> b;
    cout << ll(floor(a * b+0.001)) << endl;
}


Measured memory_bytes: 3744
#include "bits/stdc++.h" // 提出時こちらで問題なし
//#include <iostream>
//#include <string>
//#include <typeinfo>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define REP2(i, s, n) for (int i=(int)(s); i<(int)(n); i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
#define SORT(c) sort((c).begin(),(c).end())
#define R_SORT(c) sort((c).begin(),(c).end(),greater<>())
using G = vector<vector<int>>;
using M = map<int, int>;
using P = pair<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
using V = vector<int>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;


// B - 
//int main()
//{
//
//	cout << ans << endl;
//	system("pause");
//	return 0;
//}

// A - Takoyaki
int main()
{
	int n, x, t; cin >> n >> x >> t;
	int ans = 0;

	while (n > 0) {
		ans += t;
		n -= x;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>

constexpr auto PI = 3.14159265359;

using namespace std;

class binary_tree {
public:
	binary_tree(int N) {
		_node.resize(N);
	}

	void set_node(int p, int l, int r) {
		_node[p].nodeID = p;
		_node[p].left = l;
		_node[p].right = r;

		if (l == -1) {
			//pass;
		}
		else {
			_node[l].parent = p;
		}

		if (r == -1) {
			//pass;
		}
		else {
			_node[r].parent = p;
		}
	}

	void PreorderTreeWalk(int id) {//先行順巡回
		if (id == -1)return;
		printf(" %d", _node[id].nodeID);
		PreorderTreeWalk(_node[id].left);
		PreorderTreeWalk(_node[id].right);
	}

	void InorderTreeWalk(int id) {//中間順巡回
		if (id == -1)return;
		InorderTreeWalk(_node[id].left);
		printf(" %d", _node[id].nodeID);
		InorderTreeWalk(_node[id].right);
	}

	void PostorderTreeWalk(int id) {//後行順巡回
		if (id == -1)return;
		PostorderTreeWalk(_node[id].left);
		PostorderTreeWalk(_node[id].right);
		printf(" %d", _node[id].nodeID);
	}

	void set_node_type() {
		for (int i = 0; i < _node.size(); ++i) {
			if (_node[i].parent == -1) {
				_node[i].type = "root";
				rootedNode = i;
			}
			else if (_node[i].right == -1 && _node[i].left == -1) {
				_node[i].type = "internal node";
			}
			else {
				_node[i].type = "leaf";
			}
		}
	}

	struct tree {
		int nodeID = -1;
		int parent = -1;
		int left = -1;
		int right = -1;
		string type = "";
	};
	vector<tree> _node;
	int rootedNode;
};

int main() {
	int N;
	scanf("%d", &N);
	binary_tree tree(N);

	for (int i = 0; i < N; ++i) {
		int id, l, r;
		scanf("%d %d %d", &id, &l, &r);
		tree.set_node(id, l, r);
	}

	tree.set_node_type();

	printf("Preorder\n");
	tree.PreorderTreeWalk(tree.rootedNode);
	printf("\nInorder\n");
	tree.InorderTreeWalk(tree.rootedNode);
	printf("\nPostorder\n");
	tree.PostorderTreeWalk(tree.rootedNode);
	printf("\n");

	return 0;
}


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

int main(){
    ll L, R;
    cin >> L >> R;
    ll mod = 2019;
    if (R-L+1 < mod) {
        R %= mod;
        L %= mod;
    }
    else {
        L = 0;
        R = mod - 1;
    }
    ll min_ij = 2e9 + 1;
    for (ll i=L; i<=R-1; i++) {
        for (ll j=i+1; j<=R; j++) {
            if ((i*j)%mod < min_ij) min_ij = (i*j)%mod;
        }
    }
    cout << min_ij << endl;
}

Measured memory_bytes: 256
/*約数を75個持つということは、
75 → n^74
3*25 → n^2 * m^24
3*5*5 → n^2 * m^4 * l^4
5*15 → n^4 * m^14 */

#include <bits/stdc++.h>
using namespace std;

int ilo(int x,int y){
  if(y==0) return 0;
  int cnt=0;
  while(x>0){
    x/=y;
    cnt+=x;
  }
  return cnt;
}

int main(){
  int N; cin>>N;
  //2...97
  //3...48
  //5...24
  //7...16
  //11...9
  //13...7
  //17~23 は4個 29~47は2個
  vector<int> pri50 = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
  int k,c2=0,c4=0,c14=0,c24=0,c74=0;
  for(int i=0;i<15;i++){
    k=ilo(N,pri50[i]);
    if(k>=74)
      c74++;
    if(k>=24)
      c24++;
    if(k>=14)
      c14++;
    if(k>=4)
      c4++;
    if(k>=2)
      c2++;
  }
  int alla=0;
  alla+=c74;
  alla+=c24*(c2-1);
  alla+=c14*(c4-1);
  alla+=max(0,c4*(c4-1)/2*(c2-2));
  cout<<alla<<endl;
}

Measured memory_bytes: 256
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	int[] discover;
	int[] finish;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		discover = new int[totalVertex];
		finish = new int[totalVertex];
		for(int i = 0; i < discover.length; i++) {
			discover[i] = -1;
			finish[i] = -1;
		}
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		//complete the following
		for(int i = 0; i < totalVertex; i++) {
			for(int j = 0; j < totalVertex; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		for(int i = 0; i < totalVertex; i++) {
			for(int j = 0; j < adjList.get(i).size(); j++) {
					adjMatrix[i][adjList.get(i).get(j)] = 1;
			}
		}
		for(int i = 0; i < totalVertex; i++) {
			for(int j = 0; j < totalVertex - 1; j++) {
				System.out.print(adjMatrix[i][j] + " ");
			}
			System.out.println(adjMatrix[i][totalVertex - 1]);
		}
	}
	
	public int dfs(int t, int n) {
		discover[n] = t;
		LinkedList<Integer> nb = adjList.get(n);
		Iterator<Integer> it = nb.iterator();
		int time = t;
		while(it.hasNext()) {
			int w = it.next();
			if(discover[w] == -1) {
				time ++; //one forward step
				time = dfs(time, w);
			}
		}
		finish[n] = time + 1; //+1 for backtrack step
		return time + 1;
		
	}
	
}

public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.dfs(0, 0);
		int time = 0;
		for(int i = 0; i < g.finish.length; i++) {
			if(g.finish[i] > time) {
				time = g.finish[i] + 1;
			}
		}
		for(int i = 0; i < g.discover.length; i++) {
			if(g.discover[i] == -1) {
				time = g.dfs(time, i);
				time ++;
			}
				System.out.print((i + 1) + " " + (g.discover[i] + 1) + " " +  (g.finish[i] + 1));
				System.out.println();
		}
	}

}


Measured memory_bytes: 28204
x0,y0,x1,y1 = map(int, input().split())
p0=complex(x0,y0)
p1=complex(x1,y1)
q = int(input())

CCW = {1: 'COUNTER_CLOCKWISE',
       -1: 'CLOCKWISE',
       2: 'ONLINE_BACK',
       -2: 'ONLINE_FRONT',
       0: 'ON_SEGMENT',}

def dot(a, b):
  return a.real * b.real + a.imag * b.imag

def cross(a, b):
  return a.real * b.imag - a.imag * b.real

def ccw(p0, p1, p2):
  a = p1-p0
  b = p2-p0
  if cross(a,b) > 0:
    return 1 #couner_clockwise
  elif cross(a,b) <0:
    return -1 #clockwise
  elif dot(a,b) < 0:
    return 2 #online_back
  elif abs(a) < abs(b):
    return -2 #online_front
  else:
    return 0 #on_segment

for i in range(q):
  p2=complex(*map(int,input().split()))
  print(CCW[ccw(p0,p1,p2)])


Measured memory_bytes: 5628
#!/usr/bin/env python3
#ABC61 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Bellman_Ford(edges,start):
    dist = [-inf for _ in range(n)]
    dist[start] = 0
    for cnt in range(n+1):
        for edge in edges:
            e_from, e_to, e_cost = edge
            if dist[e_to] < dist[e_from] + e_cost:
                dist[e_to] = dist[e_from] + e_cost
        if cnt == n - 1:
            d = dist[:]
    if d[-1] < dist[-1]:
        print('inf')
        quit()
    else:
        return d[-1]

n,m = LI()
edges = []
for _ in range(m):
    a,b,c = LI()
    edges.append([a-1,b-1,c])

ans = Bellman_Ford(edges,0)
print(ans)


Measured memory_bytes: 3828
/*
 * ITP1_4D.c
 *
 *  Created on: 2016/05/28
 *      Author: TakaakiShogaki
 */
#include<stdio.h>

int main(){
	int n,i,x,min,max;
	double sum=0;
	min=1000000;
	max=-1000000;

	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&x);
		if(min>x)
			min=x;
		if(max<x)
			max=x;
		sum+=x;
	}
	printf("%d %d %.f\n",min,max,sum);

return 0;
}

Measured memory_bytes: 632
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n){ int ret = 1; for(int i = 1; i < n + 1; ++i) { ret = ret * i; } return ret; }

/* 最大公約数 */
template <typename T>T gcd(T x, T y){ return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>T lcm_n(vector<T> &numbers) { T l; l = numbers[0]; for(int i = 1; i < numbers.size(); ++i) { l = lcm(l, numbers[i]); } return l; }

/*
 * DP向け
 */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*
 * グラフ
 */
class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;
 
    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }
 
    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }
 
        int res = 0;
 
        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }
 
        return dp[v] = res;
    }
};



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

  if( N % 2 == 0){
    mpint ans = 0;
    mpint d = 1;
    for(int i = 1; i <= 18; ++i){
      d *= 10;
      ans += N/d;
    }
    d = 5;
    mpint e = 2;
    for(int i = 1; i <= 90; ++i){
      d *= 5;
      e *= 2;
      ans += N/d/2 - N/(d*e);
    }
    cout << ans << endl;
  } else{
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in get

let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ass = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  let dp = memoize (h * w) @@ fun dp -> function
    | (0, 0) -> 1
    | (i, 0) -> if ass.(i).[0] = '.' then dp (i - 1, 0) else 0
    | (0, j) -> if ass.(0).[j] = '.' then dp (0, j - 1) else 0
    | (i, j) -> if ass.(i).[j] = '.' then (dp (i - 1, j) + dp (i, j - 1)) mod 1000000007 else 0 in
  Printf.printf "%d\n" @@ dp (h - 1, w - 1)
    



Measured memory_bytes: 72440
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>

using namespace std;

int dp[10][10001];
int ds[10]={0,2,5,5,4,5,6,3,7,6};

int main() {
	// your code goes here
	memset(dp,0,sizeof(dp));
	int as[10]={0};
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int t;
		cin>>t;
		as[t]=1;
	}
	for(int i=1;i<10;i++)dp[i][0]=1;
	
	for(int i=1;i<10;i++){
		if(as[i]==0)continue;
		for(int j=0;j<n;j++){
			for(int k=1;k<10;k++){
				if(as[k]==0)continue;
				int p=ds[k]+j;
				if(p>n)continue;
				if(dp[i][j]==0)continue;
				dp[k][p]=max(dp[k][p],dp[i][j]+1);
			}
		}
	}
	int t=0;
	int t2=0;
	for(int i=9;i>0;i--){
		if(t<dp[i][n]){
			t=dp[i][n];
			t2=i;
		}
	}
	int p=n;
	vector<int> ans;
	while(p>0){
		for(int i=t2;i>=0;i--){
			if(i==0){
				cout<<" bad"<<p<<" "<<t2<<"\n";
				p--;
			}
			if(as[i]==0)continue;
			int p3=p-ds[t2];
			if(p3<0)continue;
			if(dp[i][p3]==dp[t2][p]-1){
				ans.push_back(t2);
				p=p3;
				t2=i;
				break;
			}
		}
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i];
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;
long long getAns(long long m,long long n)
{
    if(m == 1 && n == 1)
        return 1;
    if(m == 1 || n == 1)
        return m*n-2;
    return (m-2)*(n-2);
}
int main()
{
    long long n,m;
    while(scanf("%lld%lld",&n,&m) == 2)
        printf("%lld\n",getAns(m,n));
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#include<unordered_map>
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const double PI = 3.1415926536;

using namespace std;

string s;

int main()
{
	io;
	double n;
	cin >> n;
	cout << fixed << pow(n / 3, 3);
	return 0;
}


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

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

    pair<int, int> p[m];
    for(int i = 0; i < m; i++){
        cin >> p[i].first >> p[i].second;
        p[i].first--;
        p[i].second--;
    }

    int box[n];
    int flag[n];
    for(int i = 0; i < n; i++){
        box[i] = 1;
        flag[i] = 0;
    }
    flag[0] = 1;

    for(int i = 0; i < m; i++){
        if(flag[p[i].first] == 1){
            if(box[p[i].first] == 1){
                flag[p[i].first] = 0;
                flag[p[i].second] = 1;
            }else{
                flag[p[i].second] = 1;
            }
        }
        box[p[i].first]--;
        box[p[i].second]++;
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(flag[i] == 1){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
# O(sqrt(N))solution

def solve(n):
    ans = 0
    r = n
    for c in range(1, n + 1):
        l = n // (c + 1)
        if r - l == 1: break
        ans += (l + 1 + r) * (r - l) // 2 * c * (c + 1) // 2
        r = l
    for d in range(1, r + 1):
        c = n // d
        ans += (c + 1) * c // 2 * d
    return ans

n=int(input())
print(solve(n))


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

int main() {
    int a,b,c,d ;
    cin >> a >> b >> c >> d;
    if ((a + b) > (c + d)){
        cout << "Left" << endl;
    }
    else if ((a + b) < (c + d)){
        cout << "Right" << endl;
    }
    else{
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)

def dfs(v,d):
    memo[v] = d
    for i in graph[v]:
        if memo[i[0]] != -1:continue
        dfs(i[0],d+i[1])
        
n = int(input())
graph = [[] for _ in range(n)]
memo = [-1]*n
for i in range(n-1):
    x,y,z = map(int,input().split())
    graph[x-1].append([y-1,z])
    graph[y-1].append([x-1,z])
q,k = map(int,input().split())
ary = [list(map(int,input().split())) for _ in range(q)]
dfs(k-1,0)
print(*[memo[x-1]+memo[y-1] for x,y in ary],sep="\n")


Measured memory_bytes: 163924
main = do
  _ <- read <$> getLine :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  print $ solve as 0

solve [] accum = accum 
solve (a:as) accum =
  if (a `mod` 2 == 0) then
    solve (div a 2 : as) $ accum+1
  else solve as accum


Measured memory_bytes: 4988
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
long long f[26];

void prepare(){
    f[0]=1;//5の0乗
    rep(i,25){
        //f[i]:=5のi乗
        f[i+1]=f[i]*5;
    }
    return ;
}


long long  solve(long long N){
long long res=0;
int p=25;
    while(p>0){
        res+=N/(f[p]);
        p--;
    }

return res;
}

int main(){

long long N;
cin>>N;

if(N%2==1 || N<2){
    cout<<"0"<<endl;
    return 0;
}

else{
    prepare();
    long long ans=solve(N/2);
    cout<<ans<<endl;
    return 0;
}


/*
long long five;
five;

while(five<=1e18 && five>0){
    //cout<<i<<" ";
    five*=5;
    i++;
}
cout<<i;
*/



return 0;

}
/*
12

1

5

0

1000000000000000000

124999999999999995

*/


Measured memory_bytes: 256
#include<stdio.h>
int selectionSort(int *,int);
int main(){
    int A[100],N,i,sw;
    scanf("%d",&N);
    for(i=0;i<N;i++)scanf("%d",&A[i]);
    sw=selectionSort(A,N);
        for(i=0;i<N;i++){
            if(i>0)printf(" ");
            printf("%d",A[i]);
        }
        printf("\n");
        printf("%d\n",sw);
        return 0;
}
int selectionSort(int A[],int N){
    int i,j,t,sw = 0,minj;
    for(i=0;i<N-1;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(A[j]<A[minj])minj=j;
        }
        t=A[i];A[i]=A[minj];A[minj]=t;
        if(i!=minj)sw++;
    }
    return sw;
}


Measured memory_bytes: 2144
h,w=map(int, input().split())
ch,cw=map(int, input().split())
dh,dw=map(int, input().split())
ch-=1;cw-=1
dh-=1;dw-=1

s=[input() for _ in range(h)]


cnt=[[-1]*w for _ in range(h)]
cnt[ch][cw]=0
from collections import deque

q=deque()
q2=deque()
q.append((ch,cw))
d=[(1,0),(-1,0),(0,1),(0,-1)]
d2=[(i-2,j-2) for i in range(5) for j in range(5)]
tmp=0
while q2 or q:
    while q:
        y,x=q.popleft()
        q2.append((y,x))
        for dx,dy in d:
            if 0<=y+dy<=h-1 and 0<=x+dx<=w-1 and  s[y+dy][x+dx]=="." and cnt[y+dy][x+dx]<0:
                cnt[y+dy][x+dx]=cnt[y][x]
                q.append((y+dy,x+dx))
    y,x=q2.popleft()
    tmp+=1
    for dx,dy in d2:
        #print(y,x,dx,dy,s[y+dy][x+dx],cnt[y+dy][x+dx])
        if 0<=y+dy<=h-1 and 0<=x+dx<=w-1 and  s[y+dy][x+dx]=="." and cnt[y+dy][x+dx]<0:
            cnt[y+dy][x+dx]=cnt[y][x]+1
            q.append((y+dy,x+dx))

print(cnt[dh][dw])
        


Measured memory_bytes: 92684
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int N ,M;
  cin >> N >> M;
  int allN = 0, allM = 0;
  if (N >= 2) {
    allN = (N * (N - 1)) / 2;
  }
  if (M >= 2) {
    allM = (M * (M - 1)) / 2;
  }
  cout << allN + allM << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long K = Long.parseLong(sc.next());
        long m = 100;
        int r = 0;
        while (m<K) {
            m += m * 0.01;
            r++;
        }
        System.out.println(r);
    }
}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return (minus ? -n : n);
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return (int) (minus ? -n : n);
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

Measured memory_bytes: 25344
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <stack>
using namespace std;
int main(void){
string str;
cin >> str;
cout << str.substr(0,4) << " " << str.substr(4,8) << endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

#define bzero(m)  memset(m,0,sizeof(m))
#define REP(i,n) for(int i=0; i<n; ++i)

typedef unsigned long long u64;
typedef long long i64;


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

        string s;
        u64 r = 0;

        cin >> s;

again:
        REP(i, (int)s.length()-1) {
                if (s[i] != s[i+1]) {
                        s.erase(s.begin()+i+1);
                        s.erase(s.begin()+i);
                        r += 2;
                        goto again;
                }
        }

        cout << r << endl;

        return 0;
}


Measured memory_bytes: 512
def main():
    from bisect import bisect_left, bisect_right
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in b:
        j = bisect_left(a, i)
        k = n - bisect_right(c, i)
        ans += j * k

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 36340
//2017-12-03
//LZYeah
//
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Forr(i,a,b) for(register int i=a;i>=b;i--)
using namespace std;
inline void File()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
inline void read(int &x)
{
	int p=1;
	x=0;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+(c^'0');c=getchar();}
	x*=p;
}
int a,b,c;
int main()
{
//	File();
	read(a),read(b),read(c);
	printf("%d\n",min(a*b,c));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
int N;

int flag = 0;
int ans = 100;
int main(void) {
	cin >> N;
	for (int i = 0; i < N; i++) {
		ll a;
		cin >> a;
		int cnt = 0;
		while (1) {
			if (a % 2 == 0) {
				cnt++;
				a /= 2;
			}
			else break;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  
  bool flag = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) flag = true;
  }
  if (flag) cout << "OK" << endl;
  else cout << "NG" << endl;
  
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> ac(n+1, 0);
    FOR(i, 1, n){
        if(s[i-1] == 'A' && s[i] == 'C') ac[i] = ac[i-1] + 1;
        else ac[i] = ac[i-1];
    }
    REP(i, q)
    {
        int l, r;
        cin >> l >> r;
        cout << ac[r-1] - ac[l-1] << endl;
    }
}

Measured memory_bytes: 1488
S = input()
K = int(input())
OK = True
for i in range(min(K, len(S))):
    if S[i] != '1':
        OK = False
if OK:
    print('1')
    exit()
for i in range(len(S)):
    if S[i] != '1':
        print(S[i])
        exit()

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    int e,y;
    cin>>e>>y;
    if(e==0){
        if(1868<=y&&y<1912){
            cout<<"M"<<y-1868+1<<endl;
        }else if(1912<=y&&y<1926){
            cout<<"T"<<y-1912+1<<endl;
        }else if(1926<=y&&y<1989){
            cout<<"S"<<y-1926+1<<endl;
        }else{
            cout<<"H"<<y-1989+1<<endl;
        }
    }else if(e==1){
        cout<<y+1868-1<<endl;
    }else if(e==2){
        cout<<y+1912-1<<endl;
    }else if(e==3){
        cout<<y+1926-1<<endl;
    }else{
        cout<<y+1989-1<<endl;
    }
}

Measured memory_bytes: 3112
import Data.List
main = do
  _ <- getLine
  numList <- sort . map read . words <$> getLine
  if (head numList)==0 
    then print 0
    else let result = foldr1 (\acc x -> if acc*x > 10^18 then 0 else acc*x) numList in print $ if (result==0) then -1 else result

Measured memory_bytes: 68132
import sys
sys.setrecursionlimit(10 ** 6)


def calc_dist(x, y):
    dist = 0
    for xi, yi in zip(x, y):
        dist += (yi - xi) ** 2
    return dist ** (1/2)


def main():
    N, D = map(int, sys.stdin.readline().rstrip().split())
    X = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            dist = calc_dist(X[i], X[j])
            if dist.is_integer():
                ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=5e3;
ll pw(ll x, ll p){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=mod;
        }
        x*=x;
        x%=mod;
        p>>=1;
    }
    return ret;
}
ll inv(ll x){
    return pw(x, mod-2);
}
int n; 
vector<string> ans;
void bt(string cur, int siz, char mx){
    if (siz>=n-1){
        ans.pb(cur);
        return;
    }
    for (char i='a';i<=mx+1; i++){
        char nw;
        if (i>mx) nw=i;
        else nw=mx;

        bt(cur+i, siz+1, nw);
    }
    


}
signed main(){
    IOS()
    cin>>n;
    bt("a", 0, 'a');
    REP(i,SZ(ans)){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 7340
input = gets.to_s.split("")

kisuu = input.each_slice(2).map(&:first)
guusuu = input.each_slice(2).map(&:last)

kisuu_a = kisuu.join("")
guusuu_a = guusuu.join("")

unless kisuu_a.include?("L") || guusuu_a.include?("R")
    puts "Yes"
  else
    puts "No"
end


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

typedef long long ll;
typedef long double ld;

const int MAX_N = 3002;
int N, q[MAX_N];
ll dp[MAX_N][MAX_N][2];
bool solved[MAX_N][MAX_N][2];

ll calc(int start, int end, bool turn) {
    if(start > end) return 0;
    if(solved[start][end][turn]) return dp[start][end][turn];

    if(turn)
        dp[start][end][turn] = max(q[start] + calc(start + 1, end, 0), q[end] + calc(start, end - 1, 0));
    else
        dp[start][end][turn] = min(-q[start] + calc(start + 1, end, 1), -q[end] + calc(start, end - 1, 1));

    solved[start][end][turn] = true;
    //cout << dp[start][end][turn] << endl;
    return dp[start][end][turn];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    ll sum = 0;

    for(int i = 0; i < N; i++) {
        cin >> q[i];
        sum += q[i];
    }
        
    cout << calc(0, N - 1, 1) << "\n";

    return 0;
}


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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(bu.readLine()),i;
        HashMap<String,Integer> hm=new HashMap<>();
        for(i=0;i<n;i++)
        {
            String s=bu.readLine();
            if(hm.get(s)==null) hm.put(s,1);
            else hm.put(s,hm.get(s)+1);
        }
        System.out.print(hm.size());
    }
}


Measured memory_bytes: 65964
def main():
    h, w = map(int, input().split())
    if min(h % 3, w % 3) == 0:
        print(0)
        return
    # if [h, w] == [2, 2]:
    #     print(1)
    #     return
    s = h * w
    ans = min(h, w)
    for wcut in range(1, w // 2 + 1):
        s1 = wcut * h
        s2 = (w - wcut) * (h // 2)
        s3 = s - s1 - s2
        ans = min(ans, max(s1, s3) - min(s1, s2))
    for hcut in range(1, h // 2 + 1):
        s1 = hcut * w
        s2 = (h - hcut) * (w // 2)
        s3 = s - s1 - s2
        ans = min(ans, max(s1, s3) - min(s1, s2))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

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

    int n, k;
    std :: cin >> n >> k;

    uint64_t arr[n];
    uint64_t prefix = 1;

    for(int i = 0 ; i < n ; i++) std :: cin >> arr[i];

    for(int i = k ; i < n ; i++) {
        if(arr[i] > arr[i - k]) std :: cout << "Yes\n";
        else std :: cout << "No\n";
    }
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
int main () {
  int K, S;
  cin >> K >> S;
  int count = 0;
  for(int i = 0; i <= K; i++) {
    for(int j = 0; j <= K; j++) {
      if (S - i - j <= K && S - i - j >= 0) count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

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


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}

#pragma endregion



//ABC 096 C - Grid Repainting 2
static char s[52][53];
int main(void) {

	int i,j,h, w;
 

//	memset(s, 0x20, sizeof(s));
	scanf("%d %d",&h,&w);

	for (i = 1; i <= h; i++) {
		scanf("%s", &s[i][1]);
//		s[i][w + 1] = 0x00;
	}

//	for (i = 1; i <= h; i++)
//		printf("%s\n", s[i]);
	

	for (i = 1; i <= h; i++) {
		for (j = 1; j <= w; j++) {
			if (s[i][j] == '.') continue;
//			printf("%d %d %c:%c %c %c %c\n",i,j,s[i][j],
//				s[i - 1][j], s[i + 1][j],
//				s[i][j - 1], s[i][j + 1]);

			if (s[i - 1][j] != '#' &&
				s[i + 1][j] != '#' &&
				s[i][j - 1] != '#' &&
				s[i][j + 1] != '#')
			{
				printf("No\n"); return 0;
			}
		}
	}
	
	printf("Yes\n");
	return 0;
}




Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 1;
        while(sc.hasNext()) {
            int x = Integer.parseInt(sc.nextLine());
            if (x == 0) {
                break;
            }
            System.out.println("Case " + i++ + ": " + x);
        }
    }
}


Measured memory_bytes: 66380
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define mod 1000000007
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(), (x).end()
void make_unique(vector<ll> vec)
{
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
}


int main() 
{   ios;
    int t=1;
    //cin>>t;
    //cin.ignore(numeric_limits<streamsize>::max(),'\n');
    while(t--)
    {ll sum=0,ans=0,x,y,k,h,a,c,n,t,m,i,j,flag=0,count=0,moves=0;
     cin>>n;
     ll A[n];
     for(i=0;i<n;i++)
     cin>>A[i];
     if(n<3)
     cout<<0<<endl;
     else
     {
         for(i=0;i<n-2;i++)
         {for(j=i+1;j<n-1;j++)
           {for(k=j+1;k<n;k++)
               if(A[i]!=A[j]&&A[j]!=A[k]&&A[k]!=A[i])
                {if(A[i]+A[j]>A[k]&&A[i]+A[k]>A[j]&&A[j]+A[k]>A[i])
                    count++;
                }
           }
             
         }
         cout<<count<<endl;
     }
     
     
     
    }
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
inline long long read(){
	register long long x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200];int tt;
inline void print(register long long x,register char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
long long n,m;
bool flag;
void dfs(int now,int c,int lim){
	m=m*10+now;
	//cout<<now<<" "<<c<<" "<<lim<<" "<<m<<endl;
	if(flag) return;
	if(c>lim){
		n--;
		if(!n){
			flag=1;
			print(m);
			return;
		}
		m/=10;
		return;
	}
	if(flag) return;
	if(now!=0) dfs(now-1,c+1,lim);
	if(flag) return;
	dfs(now,c+1,lim);
	if(flag) return;
	if(now!=9)dfs(now+1,c+1,lim);
	m/=10;
}
int main(){
	n=read();
	for(int lim=0;lim<=20;lim++){
		if(flag) return 0;
		for(int i=1;i<=9;i++){
			if(flag) return 0;
			dfs(i,1,lim);
		}
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
L = [None]+list(input().split())
even = []
odd = []
if n % 2 == 0:
    for i in range(1,1+n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = even[::-1] + odd
else:
    for i in range(1,1+n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = odd[::-1] + even
for i in range(n):
    if i == n - 1:
        print(ans[i])
    else:
        print(ans[i],end=' ')

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

#define MAXN 1048577
#define mod 924844033

int n,fac[MAXN],inv[MAXN],size[MAXN],a[MAXN],b[MAXN],rev[MAXN],t[MAXN],l;
vector<int> edge[MAXN];

int qpow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=(long long)res*a%mod;
		a=(long long)a*a%mod;
		b>>=1;
	}
	return res;
}

void dfs(int u,int fa)
{
	size[u]=1;
	for(auto v : edge[u])
	{
		if(v==fa)continue;
		dfs(v,u);
		size[u]+=size[v];
	}
	if(u^1)
	{
		++a[size[u]];
		++a[n-size[u]];
	}
}

void init()
{
	fac[0]=1;
	for(int i=1;i<=n;++i)fac[i]=(long long)fac[i-1]*i%mod;
	dfs(1,0);
	for(int i=1;i<n;++i)a[i]=(long long)a[i]*fac[i]%mod;
	for(int i=0;i<=n;++i)inv[i]=qpow(fac[i],mod-2);
	for(int i=0;i<=n;++i)b[n-i]=inv[i];
}

void dft(int *a)
{
	for(int i=0;i<l;++i)if(rev[i]<i)swap(a[i],a[rev[i]]);
	for(int i=1;i<l;i<<=1)
		for(int j=0;j<l;j+=(i<<1))
			for(int k=0;k<i;++k)
			{
				int w=(long long)a[i+j+k]*t[i+k]%mod;
				a[i+j+k]=a[j+k]-w;
				if(a[i+j+k]<0)a[i+j+k]+=mod;
				a[j+k]+=w;
				if(a[j+k]>=mod)a[j+k]-=mod;
			}
}

void idft(int *a)
{
	dft(a);
	int w=qpow(l,mod-2);
	for(int i=1;i<(l>>1);++i)swap(a[i],a[l-i]);
	for(int i=0;i<l;++i)a[i]=(long long)a[i]*w%mod;
}

void solve()
{
	l=1;
	while(l<=2*n)l<<=1;
	for(int i=0;i<l;++i)rev[i]=(rev[i>>1]>>1)|((i&1)?(l>>1):0);
	for(int i=1;i<l;i<<=1)
		for(int j=0,nw=1,w=qpow(5,(mod-1)/(i<<1));j<i;++j,nw=(long long)nw*w%mod)t[i+j]=nw;
	dft(a);
	dft(b);
	for(int i=0;i<l;++i)a[i]=(long long)a[i]*b[i]%mod;
	idft(a);
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	init();
	solve();
	for(int i=1;i<=n;++i)printf("%d\n",((long long)n*fac[n]%mod*inv[i]%mod*inv[n-i]%mod-(long long)inv[i]*a[n+i]%mod+mod)%mod);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

// can be applied to string type
#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T>
void Debug(const T &val) { cerr << val << End; }
template<typename T, typename... Args>
void Debug(const T &val, Args... args) {
    cerr << val << ' ';
	Debug(std::forward<Args>(args)...);
}

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

// can be applied to string type
#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
// array sorters
#define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), std::greater<__typeof(a[0])>())

#define pb push_back
#define mp make_pair
#define a first
#define b second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

	int n;

	cin >> n;

    int c = 1;
	int prev, cur;
	int ans = 0;

	int i;

    cin >> prev;

	repi(i, n, 1) {
		cin >> cur;

		if (prev == cur) {
			c++;
		} else {
			ans += c / 2;
			c = 1;
		}

		prev = cur;
	}

	ans += c / 2;

	Out(ans);
	
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int k,a,b;
        k=s.nextInt();
        a=s.nextInt();
        b=s.nextInt();
        int flag=0;
        if(k==1)
            System.out.println("OK");
        else if(b-a>=k)
            System.out.println("OK");
        else{
            for(int i=a;i<=b;i++){
                if(i%k==0)
                {
                    System.out.println("OK");
                    flag=1;
                    break;
                }
            }
            if(flag==0)
                System.out.println("NG");
        }

    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 25404
import sys
import itertools
import numpy as np

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N = int(readline())
A = [[-1] + [int(x) - 1 for x in row.split()][::-1] for row in readlines()]

# A.append([-1])

def f(cand):
    cand1 = set()
    can_use = []
    for n in cand:
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
        cand1.add(n)
        if A[n][-1] != -1:
            cand1.add(A[n][-1])
    return len(can_use), cand1

answer = 0
rest = N*(N-1)
cand = set(range(N))
while True:
    answer += 1
    x, cand = f(cand)
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break

print(answer)

Measured memory_bytes: 47344
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
 
int main() 
{
  unsigned long long N, A, B, C, D, E, m, t = 0;
  cin >> N >> A >> B >> C >> D >> E;
  m = min({A,B,C,D,E});
  cout << 4 + N / m + (N % m != 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int N,C[26]={},c=0,ans=0;
	string S;
	cin>>N;
	cin>>S;
	for(int i=1;i<N;i++)
	{
		int C[26]={};
		c=0;
		for(int j=0;j<i;j++)
		{
			C[S[j]-'a']++;
		}
		for(int j=i;j<N;j++)
		{
			if(C[S[j]-'a']>0){
				C[S[j]-'a']=0;
				c++;
			}
		}
		ans=max(ans,c);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,k;
    long h[100000];
    cin>>n>>k;
    for (size_t i = 0; i < n; i++) {
        cin>>h[i];
    }
    sort(h,h+n);
    int min=10000000000;
    int sub;
for (size_t i = 0; i < n-k+1; i++) {
    sub = h[i+k-1] - h[i];
    if(min>sub)min=sub;
}
cout<<min;
}


Measured memory_bytes: 1024