akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int n;
  cin>>n;

  if(n==3){
    cout << "2 5 63" << endl;
    return 0;
  }

  cout << "2 3 4 9";
  n-=4;

  if(n%2==1) {
    cout << " 30000"; 
    n--;
  }

  n/=2;

  repo(i,5000){
    if(n==0) break;
    cout << " " << 6*i+2 << " " << 6*i+4;
    n--;
  }

  repo(i,2500){
    if(n==0) break;
    cout << " " << 12*i+3 << " " << 12*i+9;
    n--;
  }

  rep(i,2500){
    if(n==0) break;
    cout << " " << 12*i+6 << " " << 12*i+12;
    n--;
  }

  cout << endl;
}

Measured memory_bytes: 3628
N, M = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(M)]  #sの各要素のはじめはk
p = list(map(int, input().split()))
ans = 0

# 0をoffとして2進数でパターンを表現

for i in range(2 ** N):
	ptn = bin(i)[2:].rjust(N, "0")  # N桁の2進表現にする
	light = True  # 着目している電球が点灯していないときはこれがFalseになる
	for j in range(M):
		tmp = 0  # 着目している電球について、スイッチのonの個数をカウントする
		for n in range(1, s[j][0] + 1):
			if ptn[s[j][n] - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			light = False
	if light:
		ans += 1

print(ans)


Measured memory_bytes: 3064
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int h, a;
  cin >> h >> a;
  cout << (h/a) + (h%a != 0) << endl;
}


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

int main()
{
  string S;
  cin >> S;
  int64_t N = S.size();
  reverse(S.begin(), S.end());
  vector<int64_t> Count(2019, 0);
  Count[0]++;
  int64_t num = 1, cur = 0, ans = 0;
  for (int i = 1; i <= N; i++)
  {
    int sint = S[i - 1] - '0';
    cur = (cur + sint * num) % 2019;
    Count[cur]++;
    num *= 10;
    num %= 2019;
  }
  for (int64_t c : Count)
  {
    ans += c * (c - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,n,i,j,c=0;
    //string s,ss;
    ll s[9];
    for(i=0; i<5; i++)
    {
        cin>>s[i];
    }
    for(i=0; i<5; i++)
    {
        if(s[i]==0)
        {
            cout<<i+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
import copy
N,K = map(int, input().split())
a = list(map(int, input().split()))

ans=float('inf')
for i in range(2**N):
    b=copy.deepcopy(a)
    num=0
    for j in range(N):
        if i>>j&1:
            num+=max(b[:j+1])+1-b[j]
            b[j]=max(b[:j+1])+1
    o=1
    #print(b)
    for y in range(1,N):
        if max(b[:y])<b[y]:
            o+=1
    if o>=K:
        
        ans=min(num,ans)
        #print(ans,b)
print(ans)

Measured memory_bytes: 77004
#include <iostream>
#include <algorithm>
#include <queue>
#define N 100
using namespace std;

int color[N], d[N];
int M[N][N],n;


void bfs(int s) {
	queue<int> Q;
	for (int i = 0;i < n;i++) d[i] = -1;
	d[s] = 0;
	Q.push(s);
	color[s] = 1;
	while (!Q.empty()) {
	  for (int i = 0;i < n;i++)
		  if (M[Q.front()][i] == 1) {
			  if (color[i] == 0) {
				  d[i] = d[Q.front()] + 1;
				  color[i] = 1;
				  Q.push(i);
			  }
		  }
		  Q.pop();
	}
	for (int i = 0;i < n;i++)
		cout << i + 1 << " " << d[i] << endl;
}


int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		int u; cin >> u;
		int k; cin >> k;
		for (int j = 0;j < k;j++) {
			int v; cin >> v;
			M[u-1][v-1] = 1;
		}
	}

	bfs(0);

}

Measured memory_bytes: 3076
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
  ta,tb=map(int,input().split())
  if ta>=a:
    a=ta
  else:
    if a%ta!=0:
      a=(a//ta+1)*ta
  if tb>=b:
    b=tb
  else:
    if b%tb!=0:
      b=(b//tb+1)*tb
  qa,qb=a//ta,b//tb
  if qa!=qb:
    if qa>qb:
      b=b*qa//qb
    elif qb>qa:
      a=a*qb//qa
print(a+b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
FO
void solve(){
    int X;
    cin>>X;
    int K=1;
    while((K*X)%360!=0) K++;
    cout<<K;
    return;
}
int main(){
    //IO FO
    //TEST
    solve();

    return(0);
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;

  rep(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
    	Scanner scan = new Scanner(System.in);
    	while(true){
	    	int a = scan.nextInt();
	    	String op = scan.next();
	        int b = scan.nextInt();
	        if(op.equals("?")){
	        	break;
	        }else{
	        	if(op.equals("+")) System.out.println(a+b);
	        	else if(op.equals("-")) System.out.println(a-b);
	        	else if(op.equals("*")) System.out.println(a*b);
	        	else if(op.equals("/")) System.out.println(a/b);
	        }
		}
	}
}

Measured memory_bytes: 17328
import math
h , w = map(int, input().split())
dh, dw = [], []
rh, rw = h, w
area = []
for i in range(3,0,-1):
    dh.append(rh//i)
    rh -= dh[3-i]
    dw.append(rw//i)
    rw -= dw[3-i]

for i in range(3):
    area.append(dw[i]*h)
ans = max(area)-min(area)

area=[]
for i in range(3):
    area.append(dh[i]*w)
ans = min(ans,max(area)-min(area))

for i in range(0,3,2):
    area = []
    area.append(dw[i]*h)
    area.append((w-dw[i])*math.ceil(h/2))
    area.append((w-dw[i])*math.floor(h/2))
    ans = min(ans, (max(area)-min(area)))

for i in range(0,3,2):
    area = []
    area.append(dh[i]*w)
    area.append((h-dh[i])*math.ceil(w/2))
    area.append((h-dh[i])*math.floor(w/2))
    ans = min(ans, (max(area)-min(area)))
print(ans)


Measured memory_bytes: 38384
import math

a, b, h, m = map(int, input().split())
total_min = h * 60 + m
h_rad = math.radians((total_min/720)*360)
m_rad = math.radians((m/60)*360)
anssquare = a**2 + b**2 - 2*a*b*math.cos(abs(h_rad - m_rad))
print(math.sqrt(anssquare))


Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

struct Node {
    int key;
    Node *parent, *lc, *rc;
};

Node *root, *NIL;

void pre(Node *n) { // 先行順巡回
    if (n == NIL) return;
    cout << " " << n->key;
    pre(n->lc);
    pre(n->rc);
}

void in(Node *n) { // 中間順巡回
    if (n == NIL) return;
    in(n->lc);
    cout << " " << n->key;
    in(n->rc);
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;

    Node *z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->lc = NIL;
    z->rc = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->lc;
        } else {
            x = x->rc;
        }
    }
    z->parent = y;

    if (y == NIL) {
        root = z;
    } else if (z->key < y->key) {
        y->lc = z;
    } else {
        y->rc = z;
    }
}

bool find(Node *r, int k) {
    if (r == NIL) return false;
    if (r->key == k) {
        return true;
    } else {
        if (r->key < k) {
            return find(r->rc, k);
        } else { // r->key > k
            return find(r->lc, k);
        }
    }
}

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

    string op;
    int input;
    rep(i, n) {
        cin >> op;
        if (op == "insert") {
            cin >> input;
            insert(input);
        } else if (op == "print") {
            in(root);
            cout << endl;
            pre(root);
            cout << endl;
        } else if (op == "find") {
            cin >> input;
            if (find(root, input)) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 21864
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

long long int pow_mod(long long int p_a,long long int p_n,long long int p_p=1e9+7){
	//p_a^p_n mod p_p
	long long int p_b=1,p_t=1;
	for(;p_b<=p_n;p_b<<=1);
	for(p_b>>=1;p_b>0;p_b>>=1){
		p_t*=p_t;
		if(p_t>=p_p)p_t%=p_p;
		if(p_n&p_b)p_t*=p_a;
		if(p_t>=p_p)p_t%=p_p;
	}
	return p_t;
}

LL divide_mod(LL a,LL n,LL mod=1e9+7){//a/n
	if(a<0)a+=((-a)/mod+1)*mod;
	if(a>=mod)a%=mod;
	if(n<0)n+=((-n)/mod+1)*mod;
	if(n>=mod)n%=mod;
	a*=pow_mod(n,mod-2,mod);
	return a%mod;
}

int main(){
	LL a,b,c,d,e;
	LL i,j,k;
	LL p,q;
	cin>>p>>q;
	a=1,b=0,c=0,d=0,e=0;
	for(i=0;i<p+q;i++,a*=(LL)2){
		if(a>=MAX)a%=MAX;
		if(i==q){
			b=1,c=1;
			for(j=0;j<q-1;j++){
				c*=divide_mod(i-1-j,j+1);
				if(c>=MAX)c%=MAX;
			}
		}
		if(i>q){
			c*=divide_mod(i-1,i-q);
			if(c>=MAX)c%=MAX;
			b=b*2+c;
			if(b>=MAX)b%=MAX;
		}
		if(i==p){
			d=1,e=1;
			for(j=0;j<p-1;j++){
				e*=divide_mod(i-1-j,j+1);
				if(e>=MAX)e%=MAX;
			}
		}
		if(i>p){
			e*=divide_mod(i-1,i-p);
			if(e>=MAX)e%=MAX;
			d=d*2+e;
			if(d>=MAX)d%=MAX;
		}
		cout<<divide_mod(a+b-d,a*2)<<endl;
	}
}


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

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

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

int main() {
    ll H, W, N;
    cin >> H >> W >> N;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    map<P, ll> ma;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 9; j++) {
            ll nx = a[i] + dx[j], ny = b[i] + dy[j];
            if (0 < nx && nx < H - 1 && 0 < ny && ny < W - 1) {
                ma[P(nx, ny)]++;
            }
        }
    }

    ll cnt[10] = {0};
    for (auto o : ma) {
        cnt[o.second]++;
    }
    ll sum = 0;
    for (int i = 0; i < 10; i++) {
        sum += cnt[i];
    }
    cout << (H - 2) * (W - 2) - sum << endl;
    for (int i = 1; i < 10; i++) {
        cout << cnt[i] << endl;
    }
}

Measured memory_bytes: 58112
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    ll ma,mb;
    cin>>ma>>mb;
    vector<vector<vector<ll> > >dp(n+1,vector<vector<ll> >(411,vector<ll>(411,inf)));
    vector<ll>a(n),b(n),c(n);
    dp[0][0][0]=0;
    rep(i,n){
        cin>>a[i]>>b[i]>>c[i];
    }
    rep(i,n){
        rep(j,401){
            rep(k,401){
                if(dp[i][j][k]==inf)continue;
                dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
                dp[i+1][j+a[i]][k+b[i]]=min(dp[i][j][k]+c[i],dp[i+1][j+a[i]][k+b[i]]);
            }
        }
    }
    ll mi=inf;
    ll k=1;
    while(k*max(ma,mb)<=401){
        mi=min(dp[n][k*ma][k*mb],mi);
        k++;
    }
    cout<<(mi==inf?-1:mi)<<endl;
}

Measured memory_bytes: 56192
#include<bits/stdc++.h>
#define N 505
using namespace std;
int n,m;
char dt[2][N][N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char b=getchar();
			while(b!='.'&&b!='#') b=getchar();
			dt[0][i][j]=dt[1][i][j]='.';
			if(b=='#') dt[0][i][j]=dt[1][i][j]='#';
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=2;j<m;j++){
			if(i&1) dt[0][i][j]='#';
			else dt[1][i][j]='#';
		}
	}
	for(int i=1;i<=n;i++) dt[0][i][1]='#',dt[1][i][m]='#';
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%c",dt[0][i][j]);
		}
		puts("");
	}
	puts("");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%c",dt[1][i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1280
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int64_t A[100020];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	A[0] = A[N+1] = 0;
	for (int32_t i = 1; i <=N; i++)
	{
		in >> A[i];
	}

	int64_t sum = 0;
	for (int32_t i = 0; i <= N; i++)
	{
		sum+=std::abs(A[i+1]-A[i]);
	}
	for (int32_t i = 1; i <= N; i++)
	{
		out << sum - std::abs(A[i + 1] - A[i]) - std::abs(A[i - 1] - A[i]) + std::abs(A[i + 1] - A[i - 1]) << endl;;
	}

	return 0;
}
#endif


Measured memory_bytes: 2048
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=1e18;
const long double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
const double pi=acos(-1);

vector<int> v;

char s[203040];
int n,k,c,len;
bool vis[0];
int f[203040];
vector<int> q;
vector<int> ans;
unordered_map<int,int> mp;
int main(){
    TB
    cin>>n>>k>>c;
    cin>>s;
    len=strlen(s);
    int i=0,flag=0,flog=0;
    f[0]=(s[0]=='o');
    if(s[0]=='o'){
        flag+=c;
        flog++;
        mp[0]=1;
        v.push_back(0);
        q.push_back(0);
    }
    fdd(1,len){
        //f[i]+=f[i-1];
        if(s[i]=='o'){
            //f[i]++;
            //q.push_back(0-i);
            //deg(flag)
            if(i>flag){
                mp[i]=1;
                flag=i+c;
                flog++;
            }
        }
    }
    //sort(q.begin(),q.end());
    //f[len]=f[len-1];
    if(flog>k) return 0;
    flag=len;
    for(int i=len-1;i>=0;i--){
        if(s[i]=='o'){
            if(i<flag){
                //vector<int>::iterator it = find(v.begin(), v.end(), i);
                if(mp[i])
                    ans.push_back(i);
                flag=i-c;
                flog++;
            }
        }
    }
//    flog=len-1;
//    deg(v[1])deg(flog)
//    deg(v[0])
//    for(int i=v.size()-1;i>=0;i--){
//        if(f[flog]-f[v[i]]==0||flog-v[i]==c+1){
//            ans.push_back(v[i]);
//        }else{
//            int g=0-(flog-c);
//            int j=upper_bound(q.begin(),q.end(),g)-q.begin();
//            flog=-(q[j]);
//        }
//    }
    if(ans.size()){
        for(int i=ans.size()-1;i>=0;i--)
            cout<<ans[i]+1<<'\n';
    }
    return 0;
}


Measured memory_bytes: 11848
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
   
int main() {
    int n , a , b;
    cin >> n >> a >> b;
    cout << min( n * a , b );
}

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

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

    int n,t;cin>>n>>t;

    int ans=0;

    int bt;
    cin>>bt;

    for(int i=1;i<n;i++)
    {
        int it;cin>>it;
        ans+=min(it-bt,t);
        bt=it;
    }

    ans+=t;

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

/////////////         UnionFind
//    バラバラの要素を結合してグループにまとめる際に使える構造。
//    グループ番号、要素数の取得が可能だが、グループに属する要素の列挙はO(N)かかる。

class UnionFindClass {
public:
	UnionFindClass() {
		N = 0;
		parent = NULL;
		size = NULL;
	}
	~UnionFindClass() {
		if (parent != NULL) {
			delete[] parent;
		}
		if (size != NULL) {
			delete[] size;
		}
	}

	void activate(int n) {// 要素の数N
		N = n;
		parent = new int[N];
		size = new int[N];
		for (int i = 0; i < N; i++) {
			parent[i] = -1;
			size[i] = 1;
		}
	}

	int getParent(int x) {// グループの親の番号を得る
		if (parent[x] == -1) {
			return x;
		}
		else {
			int y = getParent(parent[x]);
			parent[x] = y;
			return y;
		}
	}
	int getSize(int x) {// 自分が属するグループのサイズを得る
		x = getParent(x);
		return size[x];
	}
	bool connect(int x, int y) {// 二つの要素を結ぶ。２グループ間を繋いだ場合trueを返す
		x = getParent(x);
		y = getParent(y);
		if (x == y) { return false; }
		int xsize = getSize(x), ysize = getSize(y);
		if (xsize < ysize) {
			parent[x] = y;
			size[y] += size[x];
			size[x] = 0;
		}
		else {
			parent[y] = x;
			size[x] += size[y];
			size[y] = 0;
		}
		return true;
	}

	//データ
	int N;// 個数
	int* parent;// 親の番号。自分自身が親なら-1。
	int* size;// 親のみ有効。自分のグループのサイズ。
};

int main() {
	int N, M; cin >> N >> M;
	UnionFindClass uf;
	uf.activate(N);
	for (int i = 0; i < M; i++) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		uf.connect(a, b);
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (uf.parent[i] == -1) {
			count++;
		}
	}

	cout << count << endl;
	return 0;
}


Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
  } else if (H * W % 2) {
    cout << H * W - (W * H / 2) << endl;
  } else {
    cout << H * W / 2 << endl;
  }
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
#define per(i,a,b) for (int i = a ; i >= b ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>
#define int long long
#define pb push_back

using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;

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

int n , ans , p ;

signed main (int argc , char * argv[] ) {
    n = rint () ;
    printf ("%lld\n" ,  n * ( n - 1 ) / 2 ) ;
    return 0 ;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int answer =0;
    if(N>=2){
      answer = answer + N*(N-1)/2;
    }
    if(M>=2){
      answer = answer + M*(M-1)/2;
    }
    System.out.println(answer);
  }
  

  
}

Measured memory_bytes: 23892
#include<stdio.h>
#include<iostream>

using namespace std;

bool Judge(int n){
    if(n<=1)
        return false;
    for(int i=2; i*i<=n; i++){
        if(n%i==0)
            return false;
    }
    return true;
}

int main(){
    int N, cnt=0;
    scanf("%d", &N);
    while(N--){
        int n;
        scanf("%d", &n);
        if(Judge(n))
            cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 3208
from itertools import combinations
n,*s=map(str,open(0).read().split())
a=[0]*5
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
print(sum([a[x]*a[y]*a[z] for x,y,z in combinations(range(5),3)]))

Measured memory_bytes: 10860
import java.io.BufferedReader;
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Node[] node = input();
		print(node);
	}
	
	public static Node[] input() throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Node[] node = new Node[n];
		for(int i = 0; i < n; ++i) {
			node[i] = new Node(i);
		}
		for(int i = 0; i < n; ++i) {
			String[] t = br.readLine().split(" ");
			int id = Integer.parseInt(t[0]);
			int k = Integer.parseInt(t[1]);
			for(int j = 0; j < k; ++j) {
				int c = Integer.parseInt(t[j+2]);
				node[id].child.add(node[c]);
				node[c].parent = node[id];
			}
		}
		return node;
	}
	
	public static void print(Node[] node){
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < node.length; ++i) {
			// example
			// node 0: parent = -1, depth = 0, root, [1, 4, 10]
			sb.append("node " + node[i].id);
			sb.append(": parent = " + node[i].parent.id);
			sb.append(", depth = " + node[i].getDepth());
			sb.append(", " + node[i].getType());
			sb.append(", [");
			int c = node[i].child.size();
			for(int j = 0; j < c; ++j) {
				if(j != 0){
					sb.append(", ");
				}
				sb.append(node[i].child.get(j).id);
			}
			sb.append("]\n");

		}
		System.out.print(sb);
	}
}

class Node {
	public int id;
	public Node parent;
	public ArrayList<Node> child = new ArrayList<Node>();
	public Node(int id){
		this.id = id;
		if(id != -1){
			parent = new Node(-1);
		}
	}

	public int getDepth(){
		if(parent.id == -1){
			return 0;
		}else{
			return parent.getDepth() + 1;
		}
	}
	
	public String getType(){
		if(parent.id == -1){
			return "root";
		}else if(child.size() == 0){
			return "leaf";
		}else{
			return "internal node";
		}
		
	}
}

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

using namespace std;

#define il inline
#define re register int
#define Rep(i, s, e) for (re i = s; i <= e; ++i)
#define Dep(i, s, e) for (re i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)

il int read() {
	int x = 0; bool f = true; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f ? x : -x;
}

int h, a;
int main() {
	h = read(), a = read();
	cout << ceil(1.0 * h / a);
	return 0;
}

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

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(C >= A and C <= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-6;
const ll MOD = 1000000007;
const ll INF = 1e15;

int main() {
	ll N, C;
	cin >> N >> C;
	vector<ll> x(N + 1);
	vector<ll> v(N + 1);
	vector<ll> imos(N + 3);
	x[0] = 0;
	v[0] = 0;
	for (int i = 1;i <= N;i++) {
		cin >> x[i] >> v[i];
	}
	x.push_back(C);
	v.push_back(0);
	for (int i = 1;i <= N + 2;i++)
		imos[i] += imos[i - 1] + v[i - 1];
	vector<ll> migi(1, 0);
	ll point = 0;
	for (int i = 1;i <= N + 1;i++) {
		if (imos[i + 1] - x[i] > point) {
			point = imos[i + 1] - x[i];
			migi.push_back(i);
		}
	}

	vector<ll> hidariv(1, N + 1);
	point = 0;
	for (int i = N;i >= 0;i--) {
		if (imos[N + 2] - imos[i] - (C - x[i]) > point) {
			point = imos[N + 1] - imos[i] - (C - x[i]);
			hidariv.push_back(i);
		}
	}
	ll ans = 0;
	for (int hidari = N;hidari >= 1;hidari--) {
		ans = max(ans, imos[N + 2] - imos[hidari] - (C - x[hidari]));
		while (migi.back() >= hidari)
			migi.pop_back();
		ans = max(ans, imos[N + 2] - imos[hidari] - (C - x[hidari]) * 2 + imos[migi.back() + 1] - x[migi.back()]);
	}
	for (int r = 0;r <= N;r++) {
		ans = max(ans, imos[r + 1] - x[r]);
		while (hidariv.back() <= r)
			hidariv.pop_back();
		ans = max(ans, imos[N + 2] - imos[hidariv.back()] - (C - x[hidariv.back()]) + imos[r + 1] - x[r] * 2);
	}

	cout << ans << endl;
	/*for (int i = 0;i <= N+1;i++) {
	ans = max(ans, imos[i + 1] - x[i]); // 右回り
	if (i <= migi && i < hidari)
	ans = max(ans, imos[i + 1] - x[i] * 2 + imos[N + 2] - imos[hidari] - (C - x[hidari]));
	ans = max(ans, imos[N + 1] - imos[i] - (C - x[i])); // 左回り
	if(i > migi && i >= hidari)
	ans = max(ans, imos[migi + 1] - x[migi] + imos[N + 2] - imos[i] - (C - x[i]) * 2);
	}
	ll bigdiff = 0;
	for (int i = 1;i < x.size();i++)
	bigdiff = max(bigdiff, x[i] - x[i - 1]);
	ans = max(ans, imos.back() + bigdiff);
	cout << ans << endl;*/
	return 0;
}


Measured memory_bytes: 5216
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
prob_1 = 0
prob_2 = 0
prob_3 = 0
for i in range(n):
  if p[i] <= a:
    prob_1 += 1
  elif p[i] <= b:
    prob_2 += 1
  else:
    prob_3 += 1
ans = min(prob_1, prob_2, prob_3)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
  int sima = 0;
  int binn = 0;
  cin >> sima >> binn;
  vector<int> tyuukei(sima);
  for(int i = 0;i <= sima - 1;i++){
    tyuukei[i] = 0;
  }
  int kotae = 0;
  for(int i = 0;i <= binn - 1;i++){
    int from,to;
    cin >> from >> to;
    if(from == 1){
      tyuukei[to - 1]++;
      if(tyuukei[to - 1] == 2){
        kotae = 1;
        i = binn;
      }
    }
    else if(to == sima){
      tyuukei[from - 1]++;
      if(tyuukei[from - 1] == 2){
        kotae = 1;
        i = binn;
      }
    }
  }
  if(kotae == 0){
    cout << "IMPOSSIBLE" << endl;
  }
  else{
    cout << "POSSIBLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
h,w=map(int,input().split())
a=[input()for _ in range(h)]
b=[]
v=list(map(int,'0'*w))
for i,r in enumerate(a):
  if r=='.'*w:
    b.append(i)
  for j in range(w):
    v[j]+=r[j]=='.'
f=[j for j in range(w)if v[j]==h]
for i,r in enumerate(a):
  if i not in b:
    t=list(map(str,a[i]))
    for j in f:
      t[j]=''
    print(''.join(t))


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

using i64 = int64_t;

constexpr i64 MAX_N = 100005;

i64 prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1];   // is_prime[i]がtrueならばiは素数

// n以下の素数の数を返す
i64 sieve(i64 n) {
    i64 p = 0;
    for (i64 i = 0; i <= n; i++)
        is_prime[i] = true;
    is_prime[0] = false;
    is_prime[1] = false;
    for (i64 i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (i64 j = 2 * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return p;
}

i64 like_2017[MAX_N] = {};

int main(){
    i64 q;
    cin >> q;
    sieve(MAX_N);
    for(i64 i=1;i<MAX_N;i+=2){
        if(is_prime[i] && is_prime[(i+1)/2])like_2017[i] = 1;
    }
    for(i64 i=1;i<MAX_N;++i){
        like_2017[i] += like_2017[i-1];
    }

    for(int i=0;i<q;++i){
        i64 l, r;
        cin >> l >> r;
        cout << like_2017[r] - like_2017[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,k,n,m;
double tab[150][150],len[150][150],ans;

int main(){
	while(scanf("%d %d",&n,&m)*n*m){
		for(i=0;i<n;i++){
			len[0][i]=1;
			for(j=0;j<n;j++){
				scanf("%lf",&tab[i][j]);
			}
		}

		if(m==1){printf("1.00\n");continue;}

		for(k=1;k<m;k++){
			for(i=0;i<n;i++){
				len[k][i]=0;
				for(j=0;j<n;j++){
					if(len[k][i]<len[k-1][j]*tab[j][i])len[k][i]=len[k-1][j]*tab[j][i];
				}
			}
		}

		ans=0;
		for(i=0;i<n;i++){if(ans<len[m-1][i])ans=len[m-1][i];}

		printf("%.2lf\n",floor(ans*100+0.5)/100);

	}
	return 0;
}

Measured memory_bytes: 912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+7;
ll dp[N][2];
ll arr[N];
int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)  cin>>arr[i];

	dp[2][0]=arr[1];
	dp[2][1]=arr[2];
	for(ll i=3;i<=n;i++){
		if(i&1){
			dp[i][1]=max({dp[i-2][1],dp[i-2][0],dp[i-3][1],dp[i-3][0]})+arr[i];
			dp[i][0]=max({dp[i-1][0],dp[i-1][1],arr[i-2]+dp[i-3][0]});
		}
		else {
			dp[i][1]=max({dp[i-2][1],dp[i-2][0],dp[i-1][0]})+arr[i];
			dp[i][0]=arr[i-1]+dp[i-2][0];
		}
	}
	cout<<max(dp[n][0],dp[n][1])<<endl;
	return 0;
}

Measured memory_bytes: 8272
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    char s[4];
    scanf("%s",s);
    printf("%d\n",s[0]+s[1]+s[2]-3*'0');
    return 0;
}

Measured memory_bytes: 128
import * as fs from "fs";

let s = fs.readFileSync("/dev/stdin", "utf8").trim();

let aCount = 0;
let answer = 0;
let i = 0;

while (i < s.length) {
    if (s.substr(i, 1) == 'A') {
        aCount += 1;
        i += 1;
    } else if (s.substr(i, 2) == 'BC') {
        answer += aCount;
        i += 2;
    } else {
        aCount = 0;
        i += 1;
    }
}

console.log(answer);
// ABCABC


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

vector<vector<int>>a, dis;
vector<vector<bool>>vis;
int n, m, k, x1, x2, t, y2;

void bfs() {
  queue<pair<int, int>>q;
  dis[x1][t] = 0;
  q.push({x1, t});
  while(!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    vis[x][y] = 1;
    int k1 = 0;
    for (int i = x - 1; i >= 0 && k1 < k && a[i][y] == 0 && dis[i][y] >= dis[x][y] + 1; i--) {
      if(!vis[i][y]) {
        q.push({i, y});
        dis[i][y] = dis[x][y] + 1;
        vis[i][y] = 1;
      }
      k1++;
    }
    k1 = 0;
    for (int i = x + 1;  i < n && k1 < k && a[i][y] == 0 && dis[i][y] >= dis[x][y] + 1; i++) {
      if(!vis[i][y]) {
        q.push({i, y});
        dis[i][y] = dis[x][y] + 1;
        vis[i][y] = 1;
      }
      k1++;
    }
    k1 = 0;
    for (int i = y - 1; k1 < k && i >= 0 && a[x][i] == 0 && dis[x][i] >= dis[x][y] + 1; i--) {
      if(!vis[x][i]) {
        q.push({x, i});
        dis[x][i] = dis[x][y] + 1;
        vis[x][i] = 1;
      }
      k1++;
    }
    k1 = 0;
    for (int i = y + 1; k1 < k && i < m && a[x][i] == 0 && dis[x][i] >= dis[x][y] + 1; i++) {
      if(!vis[x][i]) {
        q.push({x, i});
        dis[x][i] = dis[x][y] + 1;
        vis[x][i] = 1;
      }
      k1++;
    }
    k1 = 0;
  }
}
int main () {
  cin >> n >> m >> k;
  cin >> x1 >> t >> x2 >> y2;
  x1--;
  t--;
  x2--;
  y2--;
  char s;
  a.resize(n + 1, vector<int>(m + 1));
  dis.resize(n + 1, vector<int>(m + 1));
  vis.resize(n + 1, vector<bool>(m + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> s;
      if (s == '.') {
        a[i][j] = 0;
      }
      else {
        a[i][j] = 1;
      }
    }
  }
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) {
      dis[i][j] = 1e7 + 1;
    }
  }
  bfs();
  if (dis[x2][y2] == 1e7 + 1) {
    cout << -1 << endl;
  }
  else {
    cout << dis[x2][y2] << endl;
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < m; j++) {
  //     cout << dis[i][j] << " ";
  //   }
  //   cout << endl;
  // }
}


Measured memory_bytes: 22780
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

struct Point{
	double x;
	double y;
};

bool is_inter(struct Point p1,struct Point p2,
	struct Point p3, struct Point p4)
{
	if(((p1.x-p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x))
		* ((p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x)) < 0){
			return true;
	}

	return false;
}

int main()
{
	double xa, ya, xb, yb, xc, yc, xd, yd;
	Point a,b,c,d;
	while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
		&xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd)){
			a.x = xa;
			a.y = ya;
			b.x = xb;
			b.y = yb;
			c.x = xc;
			c.y = yc;
			d.x = xd;
			d.y = yd;

			printf("%s\n",is_inter(a,c,b,d) && is_inter(b,d,a,c) ? "YES" : "NO");
	}
}

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

int main() {
  vector<char>word(6);
  for(int i=0;i<6;i++)
  {cin>>word.at(i);}
  if(word.at(2)==word.at(3)&&word.at(4)==word.at(5))
  {cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int m, f, r;
    cin >> m >> f >> r;

    while (!(m < 0 && f < 0 && r < 1))
    {
        if (m < 0 || f < 0)
            cout << "F";
        else if (m + f >= 80)
            cout << "A";
        else if (m + f >= 65)
            cout << "B";
        else if (m + f >= 50)
            cout << "C";
        else if (m + f >= 30)
            if (r >= 50)
                cout << "C";
            else
                cout << "D";
        else
            cout << "F";


        cout << endl;
        cin >> m >> f >> r;
    }
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
//pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>   using orderedSet =tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
//BFS+DFS
#define boundary(i,j) (i>=0 && i<n && j>=0 && j<m)
int X[]={-1,1,0,0};
int Y[]={0,0,1,-1};

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int x;
     cin>>x;
     if(x>=30) cout<<"Yes"<<endl;
     else cout<<"No"<<endl;

}




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

using namespace std;

typedef long long LL;


const int N = 55;

int n, m, Q, a[N], b[N], c[N], d[N], x[N];

int ans = 0;

void dfs(int u) {
	if (u > n) {
		int s = 0;
		for (int i = 1; i <= Q; i++)
			if (x[b[i]] - x[a[i]] == c[i]) s += d[i];
		ans = max(ans, s);
		return ;
	}
	for (int i = x[u - 1]; i <= m; i++) {
		x[u] = i;
		dfs(u + 1);
	}
}

int main() {
	scanf("%d%d%d", &n, &m, &Q);
	for (int i = 1; i <= Q; i++)
		scanf("%d%d%d%d", a + i, b + i, c + i, d + i);
	x[0] = 1;
	dfs(1);
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

ll N, K;

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

  cin >> N >> K;
  vector< pair< ll, ll > > a(N);
  REP(i, N) {
    CIN(p, q);
    a[i] = make_pair(p, q);
  }

  sort(ALL(a));

  ll cnt = 0;
  ll ans = a[0].first;
  REP(i, N) {
    cnt += a[i].second;
    if (cnt >= K) {
      ans = a[i].first;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x+r<=w&&y+r<=h&&x>=r&&y>=r)
        puts("Yes");
    else
        puts("No");
    return 0;
}


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

using namespace std;
typedef long long ll;

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

    vector<int> row(M, 0);
    vector<vector<int> > prefs(N, row);
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> prefs[i][j];
            prefs[i][j]--;
        }
    }

    int best = N;
    vector<int> inds(N, 0);
    vector<int> curs(M, 0);
    vector<bool> removed(M, false);

    for(int i=0;i<N;i++){
        curs[prefs[i][0]]++;
    }
    for(int k=0;k<M;k++){
        int curbestind = 0;
        for(int i=0;i<M;i++){
            if(curs[i] > curs[curbestind]) curbestind = i;
        }

        if(curs[curbestind] < best) best = curs[curbestind];

        // remove sport curbestind
        removed[curbestind] = true;
        curs[curbestind] = 0;
        for(int i=0;i<N;i++){
            curs[prefs[i][inds[i]]] --;
            while(removed[prefs[i][inds[i]]]){
                inds[i]++;
            }
            if(inds[i] < M) curs[prefs[i][inds[i]]] ++;
        }
    }
    
    cout << best << endl;
    
    return 0;
}


Measured memory_bytes: 640
PROGRAM ATCODER

implicit none
integer :: k,s,x,y,z,ans,i,j

read(*,*) k,s

ans = 0
do i = 0, k, 1
  x = i
  do j = 0, k, 1
    y = j
    z = s - x - y
    if ( z>=0 .and. z<=k ) then
      ans = ans + 1
    end if
  end do
end do

print'(i0)', ans

END PROGRAM ATCODER

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll N; cin >> N;
    ll ans = 0;
    FOR(i,1,sqrt(N)+1){
        if(N%i == 0){
            ll p = i;
            ll m = N/p-1;
            if(N/p == N%p) ans += p;
            if(m>0 && N/m == N%m) ans += m;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define rep_itr(it, M) for (auto it = M.begin(); it != M.end(); ++it)
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, K;

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

  cin >> N >> K;
  int idx = 1;
  while(N/K>0) {
    idx++;
    N /= K;
  }

  cout << idx << "\n";
  return 0;
}

Measured memory_bytes: 256