akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[m];
		for(int i = 0 ; i < m ; i++) a[i] = sc.nextInt();
		int first = 0;
		int last = 0;
		int now = x;
		while(now != 0) {
			now--;
			for(int i = 0 ; i < m ; i++) {
				if(a[i] == now) first++;
			}
		}
		now = x;
		while(now != n) {
			now++;
			for(int i = 0 ; i < m ; i++) {
				if(a[i] == now) last++;
			}
		}
		System.out.println(Math.min(first, last));
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] in = new int[n];
        int[] ans = new int[n];
        for(int i = 0; i < n; i++) in[i] = sc.nextInt();
        sc.close();

        for(int i=0; i < n; i++) ans[in[i] - 1] = i+1;

        StringBuilder sb = new StringBuilder();
        sb.append(ans[0]);

        for(int i = 1; i < ans.length; i++) sb.append(" ").append(ans[i]);
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 50852
#include <cstdio>

using namespace std;

int main() {
    int n;
    int a[300][300];

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

    bool r[300][300] = {};

    bool valid = true;
    for(int k=0;k<n;k++) {
        for(int i=0;i<n-1;i++) {
            if(i==k) continue;
            for(int j=i+1;j<n;j++) {
                if(j==k) continue;
                if(a[i][j] == a[i][k] + a[k][j]) {
                    r[i][j] = true;
                } else if (a[i][j] > a[i][k] + a[k][j]) {
                    valid = false;
                    break;
                }
            }
        }
    }
    for(int i=0;i<n-1;i++) {
        for(int j=i+1;j<n;j++) {
            if(!r[i][j])
            sumRoad += a[i][j];
        }
    }

    if(!valid) {
        sumRoad = -1;
    }

    printf("%lld\n", sumRoad);

    return 0;
}


Measured memory_bytes: 640
<?php
# 入力部
// fscanf(STDIN, "%s %s", $s, $t);
fscanf(STDIN, "%d %d", $n, $m);
// fscanf(STDIN, "%s", $u);
// fscanf(STDIN, "%d %d", $n, $r);
// $s1 = fgets(STDIN); //"\n"の2文字
// $s2 = fgets(STDIN);
// fscanf(STDIN, "%d", $n);
// fscanf(STDIN, "%s", $s);
// fscanf(STDIN, "%s", $s2);
// fscanf(STDIN, "%d %d %d", $a, $b, $c);


# 処理部
// $arr = str_split($s);
// $arr2 = str_split($s2);
// $arr1 = explode(" ", $s1);
// $arr2 = explode(" ", $s2);
// for ($i = 0; $n > $x * $i; $i++) {
// }
// if (strpos($s, 'RRR') !== false) {
//   $r = 3;
// } elseif (strpos($s, 'RR') !== false) {
//   $r = 2;
// } elseif (strpos($s, 'R') !== false) {
//   $r = 1;
// } else {
//   $r = 0;
// }
// $s = "No";
// if ($x >= 30) {
//   $s = "Yes";
// }
// for ($i = 0; $i * 1000 < $n; $i++) {
// }
// $c = "a";
// if (ctype_upper($a)) {
//   $c = "A";
// }
// $s = "Yes";
// echo count($arr1);
// for ($i = 0; $i < strlen($s1); $i++) {
//   if ($arr1[$i] != $arr2[$i]) {
//     $s = "No";
//   }
// }
// $unit;
// switch ($n % 10) {
//   case 0:
//   case 1:
//   case 6:
//   case 8:
//     $unit = "pon";
//     break;
//   case 3:
//     $unit = "bon";
//     break;
//   default:
//     $unit = "hon";
//     break;
// }
// if ($s == "ABC") {
//   $r = "ARC";
// } else {
//   $r = "ABC";
// }
// $r = "NG";
// for ($i = $a; $i <= $b; $i++) {
//   if ($i % $k == 0) {
//     $r = "OK";
//   }
// }
// $r = "safe";
// if ($s <= $w) {
//   $r = "unsafe";
// }
// $r = "No";
// if (strpos($n, "7") !== false) {
//   $r = "Yes";
// }
// $r = "No";
// if ($arr[2] == $arr[3] && $arr[4] == $arr[5]) {
//   $r = "Yes";
// }
// $r = "Yes";
// if ($s == "AAA" || $s == "BBB") {
//   $r = "No";
// }
// if ($n % 2 == 0) {
//   $r = $n / 2;
// } else {
//   $r = ($n + 1) / 2;
// }
// if ($n < 10) {
//   $r += (10 - $n) * 100;
// }
// $arr = array($a, $b, $c);
// $arr = array_unique($arr);
// if (count($arr) == 2) {
//   $r = "Yes";
// } else {
//   $r = "No";
// }
// if ($s == $u) {
//   $a--;
// } else {
//   $b--;
// }
// for ($i = 0; $h > 0; $i++) {
//   $h -= $a;
// }
$r = "No";
if ($n == $m) {
  $r = "Yes";
}

# 出力部
// echo ($n * ($n - 1) / 2) + ($m * ($m - 1) / 2) . "\n";
// echo $z . " " . $x . " " . $y . "\n";
// echo ($i * 1000) - $n . "\n";
// echo json_encode($arr) . "\n";
echo $r . "\n";
// echo $a . " " . $b . "\n";


Measured memory_bytes: 16172
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e6 + 6, mod = (int) 0;
int mark[N];
vector<int> adj[N];
int main() {
	int n, m;
	cin >> n >> m;
	for (int j = 0; j < m; ++j) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector<int> a, b;
	a.push_back(0);
	mark[0] = 1;
	int cur = 0;
	while (true) {
		int flag = 1;
		for (int u : adj[cur]) if (!mark[u]) {
			mark[u] = 1;
			a.push_back(u);
			cur = u;
			flag = 0;
			break;
		}
		if (flag) break;
	}
	cur = 0;
	while (true) {
		int flag = 1;
		for (int u : adj[cur]) if (!mark[u]) {
			mark[u] = 1;
			b.push_back(u);
			cur = u;
			flag = 0;
			break;
		}
		if (flag) break;
	}
	reverse(b.begin(), b.end());
	for (int x : a) b.push_back(x);
	cout << SZ(b) << endl;
	for (int x : b) cout << x + 1 << ' ';
	cout << endl;

}


Measured memory_bytes: 29432
N,M=map(int,input().split())
A=list(map(int,input().split()))
D=[]
for i in range(N):
    D.append((A[i],1))
for i in range(M):
    B,C=map(int,input().split())
    D.append((C,B))
D.sort()
ans=0
num=0
for i in range(N+M)[::-1]:
    ans=ans+D[i][0]*D[i][1]
    num=num+D[i][1]
    if N<=num:
        a=num-N
        ans=ans-D[i][0]*a
        break
print(ans)

Measured memory_bytes: 28852
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	s;
	cin >> k;
	cin >> s;

	if (s.size()> k) {
		for(i=0;i<k;i++) cout << s[i];
		cout << "..." << endl;
	} else {
		cout << s << endl;
	}

	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int a, b;
	cin >> a >> b;
	cout << max({a + b, a - b, a * b}) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 300005
#define M 200005
#define seed 23333

using namespace std;
struct Ques{
	 int pos,sum;
}A[N];
int i,j,m,n,p,k,Q[N],r=0,r1=0,a[N],id[N],l,ID[N];
long long f[N],g[N],Ans[N],sum[N],S[N],Max[N];
void ins(int x)
{
	 while (r>1&&(S[x]-S[Q[r]])*(Q[r]-Q[r-1])>=(S[Q[r]]-S[Q[r-1]])*(x-Q[r])) --r;
	 r1=min(r1,r);
	 if (r1==0) r1=1;
	 Q[++r]=x;
	 if (r1==r-1&&(S[Q[r]]-S[Q[r-1]])>=i*(Q[r]-Q[r-1])) ++r1;
	 while (r1>1&&(S[Q[r1]]-S[Q[r1-1]])<i*(Q[r1]-Q[r1-1])) --r1;
}
void Ins(int x)
{
	 S[x]=1ll*x*(x-1)/2+f[x]+sum[x];
	 while (r>1&&(S[x]-S[Q[r]])*(Q[r]-Q[r-1])>=(S[Q[r]]-S[Q[r-1]])*(x-Q[r])) --r;
	 Q[++r]=x;
}
void insert(int x)
{
	 S[x]=g[x]+1ll*x*(x+1)/2-sum[x-1];
	 while (r>1&&(S[x]-S[Q[r]])*(Q[r]-Q[r-1])>=(S[Q[r]]-S[Q[r-1]])*(x-Q[r])) --r;
	 Q[++r]=x;
}
void work(long long *f)
{
	  for (i=1;i<=n;++i) sum[i]=sum[i-1]+a[i];
	  r=0,r1=1;
	  for (i=1;i<=n;++i)
	  {
	  		S[i-1]=f[i-1]+1ll*(i-1-1)*(i-1)/2+sum[i-1];
	  		ins(i-1);
	  		int id=Q[r1];
	  		f[i]=f[id]+1ll*(i-id)*(i-id+1)/2-sum[i]+sum[id];
	  		f[i]=max(f[i],f[i-1]);
	  }
}
void Fen(int sl,int sr,int ql,int qr)
{
		if (ql>qr||sl==sr) return;
		int mid=(sl+sr)>>1,i;
		r=0;
		for (i=sl-1;i<=mid;++i) Ins(i);
		r1=r;
		for (i=mid+1;i<=sr;++i) 
		{
				while (r1>1&&(S[Q[r1]]-S[Q[r1-1]])<i*(Q[r1]-Q[r1-1])) --r1;
				int id=Q[r1];
				Max[i]=f[id]+1ll*(i-id)*(i-id+1)/2-sum[i]+sum[id]+g[i+1];
		}
		for (i=sr-1;i>mid;--i) Max[i]=max(Max[i],Max[i+1]);
		l=1,r=0;
		for (i=mid+1;i<=sr+1;++i) insert(i);
		for (i=sl;i<=mid;++i)
		{
				while (l<r&&(S[Q[l+1]]-S[Q[l]])>=i*(Q[l+1]-Q[l])) ++l;
				int id=Q[l];
				Max[i]=g[id]+1ll*(id-i)*(id-i+1)/2-sum[id-1]+sum[i-1]+f[i-1];
		}
		for (i=sl+1;i<=mid;++i) Max[i]=max(Max[i],Max[i-1]);
		for (i=ql;i<=qr;++i) 
		Ans[id[i]]=max(Ans[id[i]],Max[A[id[i]].pos]+a[A[id[i]].pos]-A[id[i]].sum);
		int nowr=ql-1,nowl=qr+1;
		for (i=ql;i<=qr;++i)
			if (A[id[i]].pos<=mid) ID[++nowr]=id[i];
			else ID[--nowl]=id[i];
		for (i=ql;i<=qr;++i)
			id[i]=ID[i];
		Fen(sl,mid,ql,nowr);
		Fen(mid+1,sr,nowl,qr);
}
int main()
{
		scanf("%d",&n);
		for (i=1;i<=n;++i)	scanf("%d",&a[i]);
		work(f);
		for (i=1;i<=n;++i) if (i<n-i+1) swap(a[i],a[n-i+1]);
		work(g);
		for (i=1;i<=n;++i) if (i<n-i+1) swap(g[i],g[n-i+1]),
										swap(a[i],a[n-i+1]);
		for (i=1;i<=n;++i) sum[i]=sum[i-1]+a[i];
		scanf("%d",&m);
		for (i=1;i<=m;++i) 
			scanf("%d%d",&A[i].pos,&A[i].sum),id[i]=i,
			Ans[i]=f[A[i].pos-1]+g[A[i].pos+1]; 
		Fen(1,n,1,m);
		for (i=1;i<=m;++i) cout<<Ans[i]<<endl;
}

Measured memory_bytes: 22528
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    if(s=="AAA"||s=="BBB") cout<<"No";
    else cout<<"Yes";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
ll arr[100005];
ll dp[100005];
ll ans(ll pos,ll x)
{
    if(pos==x-1){
        return 0;
    }
    if(pos>=x){
        return 10000;
    }
    if(dp[pos]!=-1){
        return dp[pos];
    }
    return dp[pos]=min((abs(arr[pos]-arr[pos+1])+ans(pos+1,x)),(abs(arr[pos]-arr[pos+2])+ans(pos+2,x)));
}
int main()
{
    memset(dp,-1,sizeof(dp));
	FastIO;
	int test, tc=0;
	test=1;
	while(test--) {
        int n;
        cin>>n;
        for(ll i=0;i<n;i++){
            cin>>arr[i];
        }
        ll pp=ans(0,n);
        cout<<pp<<"\n";
	}
	return 0;
}



Measured memory_bytes: 4224
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1700

struct Info{
	int a,b;
};

int V;
int N;
vector<int> G[NUM];
int match[NUM];
bool used[NUM];
Info info[800];

void add_edge(int from,int to){
	G[from].push_back(to);
	G[to].push_back(from);
}

int dfs(int node_id){
	used[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
		if((pair_id < 0)||
				(used[pair_id] == false && dfs(pair_id) == true)){

			match[node_id] = adj_node_id;
			match[adj_node_id] = node_id;

			return true;
		}
	}
	return false;
}


int bipartie_matching(){
	int ret = 0;
	for(int i = 0; i < V; i++)match[i] = -1;
	for(int node_id = 0; node_id < V; node_id++){
		if(match[node_id] < 0){
			for(int i = 0; i < V; i++)used[i] = false;
			if(dfs(node_id)){
				ret++;
			}
		}
	}
	return ret;
}


int main(){

	int A,B;
	scanf("%d %d %d",&N,&A,&B);

	bool check[N];
	int tmp,ans = 0;

	for(int i = 0; i < N; i++){
		check[i] = false;

		scanf("%d %d",&info[i].a,&info[i].b);
		tmp = abs(info[i].a-info[i].b);
		if(tmp <= A || (tmp >= B && tmp <= 2*A)){
			ans++;
			check[i] = true;
		}
	}

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		for(int k = i+1; k < N; k++){
			if(k == i || check[k] == true)continue;
			tmp = abs((info[i].a+info[k].a)-(info[i].b+info[k].b));
			if(tmp <= A || (tmp >= B && tmp <= 2*A)){
				add_edge(i,k);
			}
		}
	}

	V = N;

	printf("%d\n", ans+bipartie_matching());

	return 0;
}



Measured memory_bytes: 3552
main = do
    n <- readLn
    s <- getLine
    print $ editorial n s


editorial :: Int -> String -> Int
editorial n s = let cntW = length $ filter (=='.') s
    in minimum $ trav (0,cntW) s

trav :: (Int,Int) -> String -> [Int]
trav (lb,rw) [] = [lb+rw]
trav (lb,rw) (h:t) =
        let p = if h=='#' then (lb+1,rw) else (lb,rw-1)
        in (lb+rw):(trav p t)

Measured memory_bytes: 14204
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

require 'pp'

A,B=gets.chomp.split(' ').map{|n| n.to_i}
M=Array.new(100){Array.new(100){'.'}}

0.upto(99){|i|
	0.upto(49){|j|
		M[i][j] = '#'
	}
}
a = A-1
b = B-1

0.step(99,2){|i|
	0.step(49,2){|j|
		if(a > 0)
			M[i][j] = "."
			a -= 1
		end
	}
}
0.step(99,2){|i|
	51.step(99,2){|j|
		if(b > 0)
			M[i][j] = "#"
			b -= 1
		end
	}
}
puts "100 100"
0.upto(99){|i|
	puts M[i].join("")
}


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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back


int main(void){
  string str;
  string c = "CODEFESTIVAL2016";
  int ans = 0;
  cin >> str;
  rep(i,str.size()){
    if(str[i] != c[i])ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

card = {}

for i in range(N):
    s = input()
    if s in card:
        card[s] += 1
    else:
        card[s] = 1

M = int(input())
for i in range(M):
    t = input()
    if t in card:
        card[t] -= 1
    else:
        card[t] = -1

print(max(max(card.values()), 0))


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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1;
	while (b) {
		while (!(b & 1))
			b >>= 1, a = (a * a) % MOD;
		--b;
		ans = (ans * a) % MOD;
	}
	return ans;
}
*/

char a[2100];
char b[2100];

int n;

int gt(int x) {
	while (x < 0)
		x += n;
	while (x >= n)
		x -= n;
	return x;
}

int mx[2100];

pair<int, int> bs[2100];

int main() {
	scanf("%s %s", a, b);
	if (strcmp(a, b) == 0) {
		cout << 0 << "\n";
		return 0;
	}
	n = strlen(a);
	int fl = 0;
	for (int i = 0; i < n; ++i)
		if (b[i] == '1')
			fl = 1;
	if (!fl) {
		cout << -1 << "\n";
		return 0;
	}
	for (int i = 0; i < n; ++i) {
		int l = n;
		int r = n;
		for (int j = 0; j < n; ++j) {
			if (b[j] == '1') {
				r = min(r, gt(j - i));
				l = min(l, gt(i - j));
			}
		}
		bs[i] = make_pair(l, r);
	}
	int ans = n * 100;
	for (int sh = 0; sh < n; ++sh) {
		int now = sh;
		vector<pair<int, int> > vv;
		for (int i = 0; i < n; ++i) {
			if (a[i] != b[gt(i + sh)]) {
				++now;
				if (bs[i].second <= sh)
					continue;
				vv.push_back(make_pair(bs[i].first, bs[i].second - sh));
			}
		}
		sort(vv.begin(), vv.end());
		mx[0] = 0;
		for (int i = 0; i < vv.size(); ++i)
			mx[i + 1] = max(mx[i], vv[i].first);
		int cm = 0;
		ans = min(ans, now + mx[vv.size()] * 2);
		for (int i = (int)vv.size() - 1; i >= 0; --i) {
			cm = max(cm, vv[i].second);
			ans = min(ans, now + mx[i] * 2 + cm * 2);
		}
	}
	for (int sh = 0; sh < n; ++sh) {
		int now = sh;
		vector<pair<int, int> > vv;
		for (int i = 0; i < n; ++i) {
			if (a[i] != b[gt(i - sh)]) {
				++now;
				if (bs[i].first <= sh)
					continue;
				vv.push_back(make_pair(bs[i].first - sh, bs[i].second));
			}
		}
		sort(vv.begin(), vv.end());
		mx[0] = 0;
		for (int i = 0; i < vv.size(); ++i)
			mx[i + 1] = max(mx[i], vv[i].first);
		int cm = 0;
		ans = min(ans, now + mx[vv.size()] * 2);
		for (int i = (int)vv.size() - 1; i >= 0; --i) {
			cm = max(cm, vv[i].second);
			ans = min(ans, now + mx[i] * 2 + cm * 2);
		}
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 384
<?php
$input = STDIN;

list($n, $q) = explode(" ", trim(fgets($input)));
$n = (int)$n;
$q = (int)$q;

for ($i = 0; $i < $n; $i++) {
    list($name_i, $time_i) = explode(" ", trim(fgets($input)));
    $time_i = (int)$time_i;
    $queue[] = [$name_i, $time_i];
}

$head = 0;
$tail = $n;
$elapsed = 0;
$ans = "";

while ($head != $tail) {
    // dequeue
    list($p_name, $remaining) = $queue[$head];
    if ($head == $n) $head = 0;
    else $head++;

    if ($remaining <= $q) {
        $elapsed += $remaining;
        $ans .= "{$p_name} {$elapsed}\n";
    } else {
        $elapsed += $q;
        $remaining -= $q;

        //enqueue
        $queue[$tail] = [$p_name, $remaining];
        if ($tail == $n) $tail = 0;
        else $tail++;
    }
}

print $ans;




Measured memory_bytes: 40500
#include <algorithm>
#include <array>
#include <climits> // INT, LONG, LLONG, UINT, ULONG, ULLONG
#include <cmath>
#include <cstdint>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define INF (INT_MAX >> 1)

using namespace std;

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

    map<int, int> m;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        m[a]++;
        m[a - 1]++;
        m[a + 1]++;
    }

    int maxCount = 0;
    for (auto i : m)
        maxCount = max(maxCount, i.second);

    cout << maxCount << endl;
    
    return 0;
}


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

int hiki(int mi, int ma){
  return (ma - mi + 1);
}

int main(){
  int N, ans = 0;
  int l, r;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    ans += hiki(l, r);
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(7);

    string s;
    while (cin >> s)
    {

        int n = s.size();
        vector<int> ans;

        for (int i = 0; i < n; ++i)
        {
            ans.push_back(s[i] - '0');
        }
        while (1)
        {
            vector<int> v;
            for (int i = 0; i < ans.size() - 1; ++i)
            {
                v.push_back((ans[i] + ans[i + 1]) % 10);
            }
            ans = v;
            if (v.size() == 1)
                break;
        }
        cout << ans[0] << endl;
        if (cin.eof())
            break;
    }
    return 0;
}


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

#define fastio std::ios::sync_with_stdio(false);
#define ll long long
#define scann(n) scanf("%d",&n)
#define scand(n) scanf("%lf",&n)
#define scans(s) scanf("%s",&s)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define full v.begin(),v.end()
#define debug cout<<"Bug! Vag! Bagh!"<<endl;
#define pi acos(-1)
#define mx 10010
#define inf 10e10

int main()
{
    ll n;
    cin>>n;
    if(n==1) cout<<0<<endl;
    else if(n==0) cout<<1<<endl;
    return 0;
}
///arBishal_2017331022


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(ll (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}
#define YES cout<<"YES"<<ln
#define NO cout<<"NO"<<ln
#define Yes cout<<"Yes"<<ln
#define No cout<<"No"<<ln

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b, c, n, m, p[114514], q[114514];
string s, t;

signed main() {
	cin >> n >> a;
	n %= 500;
	if (a>=n) Yes;
	else No;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll DP[100001][4];
    DP[0][0]=1;
    string S;
    cin>>S;
    ll N=S.size();
    for(ll i=0;i<N;i++){
        if(S[i]=='A'){
            DP[i+1][0]=DP[i][0];
            DP[i+1][1]=DP[i][0]+DP[i][1];
            DP[i+1][2]=DP[i][2];
            DP[i+1][3]=DP[i][3];
        }
        else if(S[i]=='B'){
            DP[i+1][0]=DP[i][0];
            DP[i+1][1]=DP[i][1];
            DP[i+1][2]=DP[i][2]+DP[i][1];
            DP[i+1][3]=DP[i][3];
        }
        else if(S[i]=='C'){
            DP[i+1][0]=DP[i][0];
            DP[i+1][1]=DP[i][1];
            DP[i+1][2]=DP[i][2];
            DP[i+1][3]=DP[i][3]+DP[i][2];
        }
        else{
            DP[i+1][0]=3*DP[i][0];
            DP[i+1][1]=3*DP[i][1]+DP[i][0];
            DP[i+1][2]=3*DP[i][2]+DP[i][1];
            DP[i+1][3]=3*DP[i][3]+DP[i][2];
        }
        DP[i+1][0]%=MOD;
        DP[i+1][1]%=MOD;
        DP[i+1][2]%=MOD;
        DP[i+1][3]%=MOD;
    }
    cout<<DP[N][3]<<endl;
}

Measured memory_bytes: 3664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Wolfgang Beyer
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DigitsInMultiplication solver = new DigitsInMultiplication();
        solver.solve(1, in, out);
        out.close();
    }

    static class DigitsInMultiplication {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            // double x = Math.sqrt(n);
            // long j = (long) Math.floor(x);
            long i = (long) Math.floor(Math.sqrt(n));
            while (n % i > 0) i--;
            long j = n / i;
            // out.println(i + " * " + j);
            out.println((long) Math.floor(Math.log10(j)) + 1);
        }

    }

    static class InputReader {
        private static BufferedReader in;
        private static StringTokenizer tok;

        public InputReader(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
        }

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

        public String next() {
            try {
                while (tok == null || !tok.hasMoreTokens()) {
                    tok = new StringTokenizer(in.readLine());
                }
            } catch (IOException ex) {
                System.err.println("An IOException was caught :" + ex.getMessage());
            }
            return tok.nextToken();
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    string s;
    cin >> s;

    REP(i,s.size()){
        if((i +1)% 2 == 0){
            if(!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String e[] = sc.nextLine().split("");
    int count = 0;
    for (int i = 0 ; i < e.length; i++){
        if(e[i].equals("+"))  count++;    
    }
    System.out.println(2*count-4);
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    int i;
    for(i = 0;i < n;++i){
        cin >> x.at(i);
    }
    int ans = 0;
    for(i = 0;i < n;++i){
        if(x.at(i) < k){
            ans += 2*min(x.at(i),k-x.at(i));
        }else{
            ans += 2*(k-x.at(i));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N,K=MI()
d=[0]*K
A=[0]*K

for i in range(K):
    d[i] = II()
    A[i] = LI()

s=set()
for a in A:
    for z in a:
        s.add(z)
ans=0
for i in range(1,N+1):
    if not i in s:
        ans+=1
print(ans)

Measured memory_bytes: 10456
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int N,W;
    cin>>N>>W;
    int w[N];
    int v[N];
    int dp[N+1][10001];
    for(int i=0;i<N;i++)cin>>v[i]>>w[i];
    for(int i=0;i<N+1;i++){
        for(int j=0;j<10001;j++){
            if(i==0) dp[i][j]=0;
            else{
                if(j<w[i-1])dp[i][j]=dp[i-1][j];
                else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
            }
        }
    }
    
    cout<<dp[N][W]<<endl;
}


Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();

        int[] p2 = {1,2,4,8,16,32,64,128};
        int sss = 0;
        String[][] c = new String[h][w] ; 
        String tmp = "";
        for(int i=0;i<h;i++){
            tmp = sc.next();
            for(int j=0;j<w;j++){
                c[i][j] = String.valueOf(tmp.charAt(j));
            }

        }

        for(int i=0;i<p2[h];i++){
            for(int j=0;j<p2[w];j++){
                String[][] aaa = new String[c.length][];
                for(int r=0; r < c.length; r++) {   //(3)
                    aaa[r] = new String[c[r].length];
                    //該当するfrom2Stringの上位配列の要素を
                    //to2Stringへコピーする。
                    System.arraycopy(c[r], 0,
                        aaa[r], 0, c[r].length);
                }
                for (int a =0;a<h;a++ ) {
                    if((p2[a] & i) != 0) {
                        for(int x =0;x<w;x++) {
                            aaa[a][x] = "r";
                        }
                    }
                }
                for (int a =0;a<w;a++ ) {
                    if((p2[a] & j) != 0) {
                        for(int x =0;x<h;x++) {
                            aaa[x][a] = "r";
                        }
                    }
                }

                int as = 0;


                for (int a =0;a<h;a++ ) {
                    for (int b =0;b<w;b++ ) {
                        // System.out.print(aaa[a][b]);
                        if(aaa[a][b].equals("#")) {
                            as++;
                        }
                    }
                    // System.out.print("\n");
                }
                // System.out.print("\n");


                if(as == k){
                    sss++;
                }
            }
        }

        System.out.println(sss);
    }
}


Measured memory_bytes: 38820
#include<iostream>
using namespace std;
int main() {
	int n;
	int count = 0;
	int count2 = 0;
	int data[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &data[i]);
	}
	for (int i = 0; i < n; i++) {
		if (data[i] % 2 == 0){
			count++;
		
		if (data[i] % 3 == 0 || data[i] % 5 == 0) {
				count2++;
			}
		}
	}
	if (count == count2) {
		cout << "APPROVED";
	}
	else {
		cout << "DENIED";
	}
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
PY = []
for i in range(M):
    p, y = map(int, input().split())
    PY.append([p, y, i])

PY.sort()

n = 1
now = PY[0][0]
for py in PY:
    if now != py[0]:
        now = py[0]
        n = 1
    py[1] = n
    n += 1

PY.sort(key=lambda val: val[2])

for py in PY:
    print('{:0>6}'.format(py[0]) + '{:0>6}'.format(py[1]))


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

VVI adj;
VB visited;
// 0 : black 1 : white  -1 : uncoloured
VI colour;
int n;

void dfs(int here, int col)
{
	colour[here] = col;
	visited[here] = true;
	for(auto there : adj[here])
		if((colour[there] == -1 || colour[there] == col) 
		&& !visited[there])
			dfs(there, col);
}

const int INF = (int)1e9;
void bfs(int start, VI& parent, VI& dist)
{
	parent = VI(n, -1);
	dist = VI(n, INF);
	queue<int> q;

	dist[start] = 0;
	parent[start] = start;
	q.push(start);

	while(q.empty() == false)
	{
		int here = q.front();
		q.pop();

		for(int there : adj[here])
		{
			if(parent[there] == -1)
			{
				parent[there] = here;
				dist[there] = dist[here] + 1;
				q.push(there);
			}
		}
	}
}

bool FennecWins()
{
	VI parent, dist;
	bfs(0, parent, dist);

	int dest = n - 1;
	VI order(1, dest);
	while(parent[dest] != dest)
	{
		dest = parent[dest];
		order.emplace_back(dest);
	} 

	reverse(ALL(order));

	colour.assign(n, -1);
	colour[0] = 0, colour[n - 1] = 1;
	for(int i = 0, j = sz(order) - 1; i <= j; ++i, --j)
	{
		colour[order[i]] = 0;
		if(colour[order[j]] == -1)
			colour[order[j]] = 1;
	}

	visited = VB(n, false);
	dfs(0, 0);
	visited = VB(n, false);
	dfs(n - 1, 1);

	int fennec = 0, snuke = 0;
	for(int col : colour)
	{
		fennec += col == 0;
		snuke += col == 1;
	}

	assert(snuke + fennec == n);
	return snuke < fennec;
}

VI bfs2(int start)
{
	VI dist(n, INF);
	queue<int> q;
	dist[start] = 0;
	q.push(start);

	while(q.empty() == false)
	{
		int here = q.front();
		q.pop();

		for(int there : adj[here])
		{
			if(dist[there] == INF)
			{
				dist[there] = dist[here] + 1;
				q.push(there);
			}
		}
	}
	return dist;
}

bool solve()
{
	VI d1 = bfs2(0), d2 = bfs2(n - 1);

	int fennec = 0, snuke = 0;
	for(int i = 0; i < n; ++i)
	{
		if(d1[i] <= d2[i]) ++fennec;
		else ++snuke;
	}
	return fennec > snuke;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	adj.resize(n);
	REP(i, 0, n - 1) {
		int u, v;
		cin >> u >> v;

		--u; --v;
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}

	if(solve() == true)
		 cout << "Fennec" << endl;
	else
		 cout << "Snuke" << endl;

	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  vector <int> a(3);
  a[0] = abs(A[0]-A[1]);
  a[1] = abs(A[0]-A[2]);
  a[2] = abs(A[1]-A[2]);
  sort(a.begin(), a.end());
  cout << a[0]+a[1] << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

int main(){
  int N,M;
  long a[55],b[55],c[55],d[55];
  long distance = 0;
  int check = 0;
  long min;

  cin >> N >> M;
  for(int i=0;i<N;++i){
    cin >> a[i] >> b[i];
  }
  for(int i=0;i<M;++i){
    cin >> c[i] >> d[i];
  }

  for(int i=0;i<N;++i){
    min = 999999999;
    for(int j=0;j<M;++j){
      distance = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(min > distance){
        min = distance;
        check = j+1;
      }
    }
    cout << check << endl;
  }
  return 0;
}


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

int main() {
   int A , B ;
  cin >> A >> B ;
  if(A==1 && B==2 || A==2 && B==1) cout << 3 << endl;
  if(A==1 && B==3 || A==3 && B==1) cout << 2 << endl;
  if(A==2 && B==3 || A==3 && B==2) cout << 1 << endl;
  return 0 ;
}

Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
a = inp
ans = 1e20
now = 0
(-100..100).each do |d1|
  now = 0
  a.each do |d2|
    now += (d1-d2)**2
  end
  ans = [now,ans].min
end
p ans

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

ll N,M,A,B,C,D,E,ANS;
string S,T,U;
double n,m,a,b,c,ans;

int main() {
	cin>>N>>M;
  cout<<(M>=N?"unsafe":"safe")<<endl;
	return 0;
}

Measured memory_bytes: 3616
MOD = 1_000_000_007

FACT = [1]
(1..2000).each do |k|
  FACT << FACT[-1] * k % MOD
end

def exp(n, k)
  x = 1
  r = n
  while k > 0
    x *= r if k & 1 == 1
    r *= r
    x %= MOD
    r %= MOD
    k >>= 1
  end
  x
end

def inv(n)
  exp(n, MOD - 2)
end

def perm(n, k)
  n >= k ? FACT[n] * inv(FACT[n - k]) % MOD : 0
end

def comb(n, k)
  perm(n, k) * inv(FACT[k]) % MOD
end

n, k = gets.split.map(&:to_i)
p comb(k, n)


Measured memory_bytes: 6888
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define orderd_set tree<pair<int, int>, null_type,greater<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)
//order_of_key(k)
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const int N = 2e3+69;
#define ALL(x) begin(x),end(x)
#define sz(x) (ll)x.size()
const int OO = 0x3f3f3f3f;
const int mod = 1000000007;

int n, m, k,xs, ys ,xt ,yt;
string grid[N];
vector<vector<ll>>dis;
int mvx[] = {1, -1, 0, 0};
int mvy[] = {0, 0, 1, -1};



bool valid(int x, int y)
{
    return x < n && x >= 0 && y < m && y >= 0 && grid[x][y] == '.';
}


void bfs(int sx, int sy)
{
    queue<pair<int, int>> q;
    q.push({sx, sy});
    dis[sx][sy] = 0;
    while(sz(q))
    {
        int ux = q.front().first;
        int uy = q.front().second;
        q.pop();
        if(ux == xt && uy == yt)
            return;
        for(int i = 0; i< 4; i++)
        {
            for(int j = 1; j<= k; j++)
            {
                int vx = ux + mvx[i]*j;
                int vy = uy + mvy[i]*j;
                if(valid(vx, vy))
                {
                    if(dis[vx][vy] == OO)
                    {
                        dis[vx][vy] = dis[ux][uy]+1;
                        q.push({vx, vy});
                    }
                    else if(dis[vx][vy] >= dis[ux][uy]+1)
                    {
                        dis[vx][vy] = dis[ux][uy]+1;
                    }
                    else
                        break;
                }
                else
                    break;
            }
        }
    }
}



int main()
{
    FIO
    cin >> n >> m >> k >> xs >> ys >> xt >> yt;
    dis=vector<vector<ll>>(n+69,vector<ll>(m+69,OO));
    for(int i = 0; i< n; i++)
    {
        cin >> grid[i];
    }
    xs--;xt--;yt--;ys--;
    bfs(xs, ys);
//    for(int i = 0; i< n; i++)
//    {
//        for(int j = 0; j< m; j++)
//        {
//            cout << dis[i][j] << "          ";
//        }
//        cout << "\n";
//    }
    if(dis[xt][yt] == OO)
        cout << -1 << "\n";
    else
        cout << dis[xt][yt] << "\n";
    return 0;
}


Measured memory_bytes: 558004
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

char s[MAX];
int cnt[MAX];
int main()
{
    int n, q;
    cin >> n >> q;
    scanf("%s", s+1);
    for(int i = 1; i <= n; i++){
        cnt[i] = cnt[i-1];
        if(s[i-1] == 'A' && s[i] == 'C')
            cnt[i]++;
    }
    rep(i, q){
        int l, r;
        cin >> l >> r;
        while(s[l] == 'C')  l++;
        cout << cnt[r]-cnt[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i, n, k) for(long long int i=k; i<n; ++i)
#define drep(i, n, k) for(long long int i=k; i>=n; --i)
using namespace std;

int main(){
  long long int a, b;
  cin >> a >> b;
  int ans;
  if(b - a >= 2019) ans = 0;
  else{
    int fl = 2019;
    rep(i,b,a){
      rep(j,b+1,i+1){
        if((i*j) % 2019 < fl) fl = (i*j) % 2019;
      }
    }
    ans = fl;
  }
  cout << ans << endl;
}

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

int main() {
    long n, a;
    cin >> n >> a;
    for (int i = 1; i < 5; i++) {
        long b;
        cin >> b;
        a = min(a, b);
    }
    cout << 5 + (n - 1) / a << endl;
    return 0;
}


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

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

    if (A == B && A != C){
        cout << "Yes" << endl;
    } else if (A == C && A != B){
        cout << "Yes" << endl;
    } else if (B == C && A != B){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
using namespace std;
int n,m;
char mp[55][55];
bool vis[55][55];
int fx[4][2]= {1,0,-1,0,0,1,0,-1};
struct node
{
    int x,y;
    int b;
};
int bfs(int x,int y)
{
    memset(vis,false,sizeof(vis));
    vis[x][y]=true;
    queue<node>q;
    node qc,now,next;
    qc.x=x;
    qc.y=y;
    qc.b=1;
    q.push(qc);
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        if(now.x==(n-1)&&now.y==(m-1))
            return now.b;
        for(int k=0; k<4; k++)
        {
            next.x=now.x+fx[k][0];
            next.y=now.y+fx[k][1];
            if(next.x<0||next.y<0||next.x>=n||next.y>=m||vis[next.x][next.y]||mp[next.x][next.y]=='#')
                continue;
            next.b=now.b+1;
            vis[next.x][next.y]=true;
            q.push(next);
        }
    }
    return -1;
}
int main()
{
    scanf("%d%d",&n,&m);
    int z=0;
    for(int i=0; i<n; i++)
    {
        scanf("%s",mp[i]);
        for(int j=0; j<m; j++)
        {

            if(mp[i][j]=='.')
                z++;
        }
    }

    int a=bfs(0,0);
    if(a==-1)
        printf("-1\n");
    else
        printf("%d",z-a);
    return 0;
}
/*#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
//#define MAX_INT 0x3f3f3f3f
//#define MIN_INT -MAX_INT
using namespace std;
int main()
{
   int t;
   scanf("%d",&t);
   char a[105];
   int n;
   getchar();
   while(t--)
   {
     scanf("%s %d",a,&n);
     int len=strlen(a);
     int b;
     for(int i=0;i<len;i++)
         if(a[i]=='.')
            b=i;
    if(n+b<len)
        printf("%d\n",a[n+b]-'0');
    else
        printf("0\n");
   }
    return 0;
}*/



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

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

    char s[1001];
    cin >> s;
    int n = strlen(s);
    cout << s ;
    cout << (s[n-1] == 's' ? "es" : "s");

    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const int z = 1000000007;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main() {
    llong n;
    cin >> n;
    vector<string> vec;
    string tmp_str;
    while (n > 0) {
        if ((n % 26) == 0) {
            char tmp_char = 'z';
            tmp_str = { tmp_char };
            vec.push_back(tmp_str);
            n--;
            n = (n - 1) / 26;
        }
        else {
            char tmp_char = 'a' + ((n % 26) - 1);
            tmp_str = { tmp_char };
            vec.push_back(tmp_str);
            n /= 26;
        }
    }
    /*while (n > 0) {
        char tmp_char = 'a' + ((n % 26) - 1);
        tmp_str = { tmp_char };
        vec.push_back(tmp_str);
        n /= 26;
    }*/
    string ans="";
    REP(i, vec.size()) {
        ans = vec[i] + ans;
    }
    cout << ans << endl;;
    return 0;
}


Measured memory_bytes: 3604
/*
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$
**/

#include <bits/stdc++.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <cmath>

using namespace std;

//typedef
typedef string STR;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef priority_queue<int> PQI;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
typedef vector<STR> VS;
typedef vector<char> VC;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<STR,int> PSI;
typedef pair<int,STR> PIS;
typedef vector<PII> VII;
typedef map<int,int> MII;
typedef map<LL,LL> MLL;
typedef map<STR,int> MSI;
typedef map<char,int> MCI;
typedef map<int,STR> MIS;
typedef set<STR> SS;
typedef set<int> SI;
typedef set<LL> SLL;

//symbolic const
#define MOD 1000000007
#define MAXN 1e9
#define SIZE 10000

//STL keywords
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
#define all(v) v.begin(), v.end()

//functions
#define dec(n) cout<<fixed<<setprecision(n);
#define f(i, n)   for(LL i=0; i<n; i++)
#define fa(i,a,n) for(LL i=a; i<n; i++)

//IO
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test int t;cin>>t;while(t--){solve();}

LL maxLL(LL a, LL b){return (a>b?a:b);}
LL minLL(LL a, LL b){return (a<b?a:b);}

void solve() {
  string s;
  cin>>s;
  string a, b;
  int ca=0, cb=0;
  a+='0'; b+='1';
  if(s[0]=='0')ca++;
  else cb++;
  fa(i, 1, s.size()){
      if(a.back()=='0') a+='1';
      else a+='0';
      if(b.back()=='0') b+='1';
      else b+='1';

      if(s[i]==a[i]) ca++;
      else cb++;
  }
   cout<<min(s.size()-ca, s.size()-cb);
}

int main() {
    sync;
    //test;
    solve();
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (b == 1){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    while(b > a){
        b -= a - 1;
        ans++;
    }
    if (b > 0)
        ans++;
    cout << ans << endl;

    return 0;


}


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

int main() {
    int H, W, A, B; cin >> H >> W >> A >> B;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i < B ^ j < A) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280